一、框架視圖
二系草、關(guān)鍵代碼
CameraMode
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Vuforia;
/// <summary>
/// 自動(dòng)對(duì)焦功能
/// </summary>
public class CameraMode : MonoBehaviour
{
void Start()
{
//一開(kāi)始自動(dòng)對(duì)焦
//Vuforia.CameraDevice.Instance.SetFocusMode(Vuforia.CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
VuforiaARController.Instance.RegisterVuforiaStartedCallback(OnVuforiaStarted);
VuforiaARController.Instance.RegisterOnPauseCallback(OnPaused);
}
void Update()
{
//觸碰的時(shí)候?qū)? //if (Input.GetMouseButtonUp(0))
//{
// if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began)
// {
// Vuforia.CameraDevice.Instance.SetFocusMode(Vuforia.CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
// }
//}
}
private void OnVuforiaStarted()
{
CameraDevice.Instance.SetFocusMode(
CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
private void OnPaused(bool paused)
{
if (!paused)
{ // resumed
// Set again autofocus mode when app is resumed
CameraDevice.Instance.SetFocusMode(
CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO);
}
}
}
IntoOrOutside_Button
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
//引用場(chǎng)景管理器命名空間
public class IntoOrOutside_Button : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
//進(jìn)入房間
public void In_Button(){
SceneManager.LoadScene ("IntoHouse");
}
//退出房間
public void Out_Button()
{
SceneManager.LoadScene("Main");
}
public void Vr_Button() {
SceneManager.LoadScene("vr1");
}
}
Load_Mark
using UnityEngine;
using System.Collections;
using UnityEngine.SceneManagement;
public class Load_Mark : MonoBehaviour {
public Texture[] Load_Textures;
//申請(qǐng)貼圖類(lèi)型的數(shù)組儲(chǔ)存每一張進(jìn)度條圖片
public float Load_Speed = 0.2f;
//圓形進(jìn)度條每張圖片切換的時(shí)間 進(jìn)度條的讀取速度
public float Load_Time;
//記錄進(jìn)度條所使用的時(shí)間
public int Load_Count;
//記錄當(dāng)前進(jìn)度條該播放哪張圖片
public Texture Alpha;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Load_Count>16){
//當(dāng)圖片超過(guò)16張時(shí)
SceneManager.LoadScene ("vr2");
//跳轉(zhuǎn)到場(chǎng)景二
}
Load_Time += Time.deltaTime;
//每一幀增加 幀所使用的時(shí)間 即進(jìn)度條經(jīng)過(guò)的時(shí)間
Load_Count = (int)Mathf.Floor (Load_Time / Load_Speed);
//計(jì)算出當(dāng)前應(yīng)該播放哪張圖片 用所經(jīng)過(guò)的時(shí)間除以每張圖片切換的速度
//Mathf.Floor() 向下取正
if (Load_Count<16)
{
gameObject.GetComponent<Renderer>().material.mainTexture = Load_Textures[Load_Count];
//把當(dāng)前所對(duì)應(yīng)的進(jìn)度條圖片顯示出來(lái)
}
}
// OnDisable函數(shù) 在該腳本被取消的時(shí)候會(huì)執(zhí)行一次
void OnDisable(){
Load_Count = 0;
Load_Time = 0;
gameObject.GetComponent<Renderer> ().material.mainTexture = Alpha;
}
}
MobileGyro
using UnityEngine;
using System.Collections;
//攝像機(jī) 陀螺儀轉(zhuǎn)動(dòng)
public class MobileGyro : MonoBehaviour
{
Gyroscope gyro;
Quaternion quatMult;
Quaternion quatMap;
GameObject player;
GameObject camParent;
void Awake()
{
player = GameObject.Find("Player");
// find the current parent of the camera's transform
Transform currentParent = transform.parent;
// instantiate a new transform
camParent = new GameObject("camParent");
// match the transform to the camera position
camParent.transform.position = transform.position;
// make the new transform the parent of the camera transform
transform.parent = camParent.transform;
// make the original parent the grandparent of the camera transform
//camParent.transform.parent = currentParent;
// instantiate a new transform
GameObject camGrandparent = new GameObject("camGrandParent");
// match the transform to the camera position
camGrandparent.transform.position = transform.position;
// make the new transform the parent of the camera transform
camParent.transform.parent = camGrandparent.transform;
// make the original parent the grandparent of the camera transform
camGrandparent.transform.parent = currentParent;
Input.gyro.enabled=true;
gyro = Input.gyro;
gyro.enabled = true;
//camParent.transform.eulerAngles = new Vector3(90, 0, 0);
camParent.transform.eulerAngles = new Vector3(90,-135, 0);
//camParent.transform.eulerAngles = new Vector3(90, 0, 180);
//quatMult = new Quaternion(0, 0, 1, 0);
quatMult = new Quaternion(0, 0, 1, 0);
}
void Update()
{
quatMap = new Quaternion(gyro.attitude.x, gyro.attitude.y, gyro.attitude.z, gyro.attitude.w);
Quaternion qt=quatMap * quatMult;
transform.localRotation =qt;
}
}
Rotate
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Rotate : MonoBehaviour {
//記錄上一幀手指的位置闲昭;
private Vector3 PreviousPosition;
//記錄手指的偏移值决采;
private Vector3 Offset;
void Start () {
}
void Update () {
//判斷是否觸屏;
if (Input.GetMouseButtonDown(0))
{
//記錄手指的偏移值
Offset = Input.mousePosition - PreviousPosition;
//記錄上一幀的手指的位置昆汹;
PreviousPosition = Input.mousePosition;
//通過(guò)手指的偏移值來(lái)控制物體的旋轉(zhuǎn)明刷;
transform.Rotate(Vector3.Cross(Offset*0.01f,Vector3.up).normalized,Offset.magnitude,Space.Self);
}
}
}
SRay
using UnityEngine;
using System.Collections;
public class SRay : MonoBehaviour {
public RaycastHit HitInfo;
public Transform HitPoint;
public GameObject LoadPlane;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
SendRay ();
Debug.Log (HitInfo.collider.gameObject.name);
}
void SendRay() {
if (Physics.Raycast (HitPoint.position, HitPoint.forward, out HitInfo)) {
if (HitInfo.collider.gameObject.tag == "A") {
Debug.Log("111");
LoadPlane.GetComponent<Load_Mark> ().enabled = true;
//如果射線撞擊的位置標(biāo)簽是否為“face” 則
}else{
Debug.Log("222");
LoadPlane.GetComponent<Load_Mark> ().enabled = false;
}
}
}
}
SX
using UnityEngine;
using System.Collections;
public class SX : MonoBehaviour {
public GameObject Load_Obj;
//儲(chǔ)存附有進(jìn)度條腳本的物體
private RaycastHit HitIfo;
//申請(qǐng)變量記錄碰撞的信息
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
SendRay ();
}
//發(fā)射射線的函數(shù)
public void SendRay(){
if (Physics.Raycast (transform.position, transform.forward, out HitIfo)) {
//發(fā)射射線固定格式Physics.Raycast (發(fā)射射線的位置, 發(fā)射射線的方向, 射線的返回信息)
if(HitIfo.collider.tag=="Door"){
//如果碰到的碰撞器的標(biāo)簽是Door
Load_Obj.GetComponent<Load_Mark>().enabled=true;
//啟用進(jìn)度條腳本
}else{
Load_Obj.GetComponent<Load_Mark>().enabled=false;
//禁用進(jìn)度條腳本
}
}
}
}
TransformChange
using UnityEngine;
using System.Collections;
public class TransformChange : MonoBehaviour {
public Transform EndPosition;
//儲(chǔ)存第一人稱控制器攝像機(jī)的位置
public float CostTime=0.2f;
//攝像機(jī)移動(dòng)所經(jīng)過(guò)的時(shí)間
public GameObject FPSCtrl;
//儲(chǔ)存第一人稱控制器
public GameObject UICtrl;
//儲(chǔ)存虛擬搖桿
//退出房間
public GameObject Close_Btn;
//切換VR場(chǎng)景
public GameObject Vr_Btn;
// Use this for initialization
void Start () {
StartCoroutine(CameraMove ());
//攝像機(jī)移動(dòng)
StartCoroutine (Show());
//延遲執(zhí)行激活 第一人稱控制器與虛擬搖桿的函數(shù)
// Vector3 qua = EndPosition.gameObject.transform.eulerAngles;
}
// Update is called once per frame
void Update () {
}
IEnumerator CameraMove(){
yield return new WaitForSeconds (0.5f);
iTween.MoveTo (gameObject,EndPosition.position,CostTime); //iTween 調(diào)不出來(lái)的話吧編輯器關(guān)閉再打開(kāi)
//從攝像機(jī)起始位置 經(jīng)過(guò)CostTime這段時(shí)間 移動(dòng)到EndPosition.position的位置
iTween.RotateTo(gameObject,EndPosition.rotation.eulerAngles,CostTime);
//從攝像機(jī)起始位置 經(jīng)過(guò)CostTime這段時(shí)間 移動(dòng)到EndPosition.position的角度
}
IEnumerator Show(){
yield return new WaitForSeconds (4.7f);
//延遲函數(shù)
FPSCtrl.SetActive(true);
//激活第一人稱控制器
UICtrl.SetActive(true);
//激活虛擬搖桿
//激活關(guān)閉按鈕
Close_Btn.SetActive(true);
//激活Vr場(chǎng)景按鈕
Vr_Btn.SetActive(true);
}
}
UI_Manager
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class UI_Manager : MonoBehaviour {
//儲(chǔ)存信息面板
public GameObject Info_Panel;
//二級(jí)面板引用;
public GameObject Inside_Panel;
//貯存外部模型满粗;
public GameObject Building;
//儲(chǔ)存戶型1辈末;
public GameObject Plan1;
//儲(chǔ)存戶型2;
public GameObject Plan2;
//儲(chǔ)存戶型3映皆;
public GameObject Plan3;
//記錄二級(jí)菜單狀態(tài)挤聘;
// public int Inside_Ctrl = 0;
private bool isShow = true;
//記錄面板的信息
private bool Info_P_State = true;
//貯存案例的面板
public GameObject Example_Panel;
//儲(chǔ)存案例名稱的Text組件
public Text Example_Content_Text;
//儲(chǔ)存顯示案例圖片的Image組件
public Image Example_Content_Image;
//申請(qǐng)整型int變量來(lái)作為案例顯示的順序
public int Example_Count = 0;
//儲(chǔ)存案例圖片的數(shù)組;
public Sprite[] SpriteChange;
//申請(qǐng)字符串來(lái)儲(chǔ)存案例的名稱
public string[] NameChange;
//記錄面板的狀態(tài)
public bool Example_P_State = false;
void Start() {
}
void Update() {
}
/// <summary>
/// 顯示二級(jí)面板
/// </summary>
public void Inside_Button() {
Example_Panel.SetActive(false);
Example_P_State = false;
if (isShow)
{
Inside_Panel.SetActive(true);
}
else
{
Inside_Panel.SetActive(false);
}
isShow = !isShow;
}
//方案1按鈕
public void Plan1_Button() {
//隱藏二級(jí)面板
Inside_Panel.SetActive(false);
Plan1.SetActive(true);
Plan2.SetActive(false);
Plan3.SetActive(false);
Building.SetActive(false);
isShow = !isShow;
}
//方案2按鈕
public void Plan2_Button()
{
//隱藏二級(jí)面板
Inside_Panel.SetActive(false);
Plan1.SetActive(false);
Plan2.SetActive(true);
Plan3.SetActive(false);
Building.SetActive(false);
isShow = !isShow;
}
//方案3按鈕
public void Plan3_Button()
{
//隱藏二級(jí)面板
Inside_Panel.SetActive(false);
Plan1.SetActive(false);
Plan2.SetActive(false);
Plan3.SetActive(true);
Building.SetActive(false);
isShow = !isShow;
}
//外部效果按鈕
public void Outside_Button() {
Plan1.SetActive(false);
Plan2.SetActive(false);
Plan3.SetActive(false);
Building.SetActive(true);
}
//關(guān)于我們的按鈕
public void Info_Button() {
//讓成功案例面板處于隱藏
Example_Panel.SetActive(false);
//成功案例面板狀態(tài)設(shè)置為false
Example_P_State = false;
if (Info_P_State)
{
Info_Panel.SetActive(true);
}
else
{
Info_Panel.SetActive(false);
}
//沒(méi)點(diǎn)擊一次改變一次值捅彻;
Info_P_State = !Info_P_State;
}
//信息面板中的關(guān)閉按鈕檬洞;
public void Info_Close_Button() {
Info_Panel.SetActive(false);
Info_P_State = true;
}
//成功案例的按鈕
public void Example_Button() {
//關(guān)閉信息面板
Info_Close_Button();
if (Example_P_State==false)
{
Example_Panel.SetActive(true);
Example_P_State = true;
}
else
{
Example_Panel.SetActive(false);
Example_P_State = false;
}
}
//成功案例面板中的關(guān)閉按鈕;
public void Example_Close_Button() {
Example_Panel.SetActive(false);
}
/*
//成功案例面板中的向右按鈕沟饥;
public void Right_Button() {
//第一種判斷方法;
if (Example_Count == 0)
{
Example_Content_Image.sprite = SpriteChange[1];
Example_Content_Text.text = "金字塔";
Example_Count = 1;
}
else if (Example_Count == 1)
{
Example_Content_Image.sprite = SpriteChange[2];
Example_Content_Text.text = "吳哥窟";
Example_Count = 2;
}
else if (Example_Count == 2)
{
Example_Content_Image.sprite = SpriteChange[0];
Example_Content_Text.text = "長(zhǎng)城";
Example_Count = 0;
}
//第二種判斷方法湾戳;
//switch (Example_Count)
//{
// case 0:
// Example_Content_Image.sprite = SpriteChange[++Example_Count];
// Example_Content_Text.text = "金字塔";
// break;
// case 1:
// Example_Content_Image.sprite = SpriteChange[++Example_Count];
// Example_Content_Text.text = "吳哥窟";
// break;
// case 2:
// Example_Content_Image.sprite = SpriteChange[Example_Count=0];
// Example_Content_Text.text = "長(zhǎng)城";
// break;
// default:
// break;
//}
}
//成功案例面板中的向左按鈕贤旷;
public void Left_Button()
{
//switch (Example_Count)
//{
// case 0:
// Example_Content_Image.sprite = SpriteChange[SpriteChange.Length-(++Example_Count)];
// Example_Content_Text.text = "吳哥窟";
// break;
// case 1:
// Example_Content_Image.sprite = SpriteChange[SpriteChange.Length-(++Example_Count)];
// Example_Content_Text.text = "金字塔";
// break;
// case 2:
// Example_Content_Image.sprite = SpriteChange[Example_Count = 0];
// Example_Content_Text.text = "長(zhǎng)城";
// break;
// default:
// break;
//}
if (Example_Count == 0)
{
Example_Content_Image.sprite = SpriteChange[2];
Example_Content_Text.text = "吳哥窟";
Example_Count = 2;
}
else if (Example_Count == 2)
{
Example_Content_Image.sprite = SpriteChange[1];
Example_Content_Text.text = "金字塔";
Example_Count = 1;
}
else if (Example_Count == 1)
{
Example_Content_Image.sprite = SpriteChange[0];
Example_Content_Text.text = "長(zhǎng)城";
Example_Count = 0;
}
}
*/
//通過(guò)序號(hào)加減來(lái)切換案例圖片和名稱
//右鍵
public void Right_Button() {
//向右最后一張圖片的時(shí)候跳回第一張
if (Example_Count== SpriteChange.Length - 1)
{
Example_Count =0;
Example_Content_Image.sprite = SpriteChange[Example_Count];
Example_Content_Text.text = NameChange[Example_Count];
}
else
{
Example_Count++;
Example_Content_Image.sprite = SpriteChange[Example_Count];
Example_Content_Text.text = NameChange[Example_Count];
}
}
//左鍵
public void Left_Button() {
if (Example_Count == 0)
{
Example_Count = SpriteChange.Length - 1;
Example_Content_Image.sprite = SpriteChange[Example_Count];
Example_Content_Text.text = NameChange[Example_Count];
}
else
{
Example_Count--;
Example_Content_Image.sprite = SpriteChange[Example_Count];
Example_Content_Text.text = NameChange[Example_Count];
}
}
//AR看房
public void ARScene_Button()
{
SceneManager.LoadScene("AScene");
}
//AR視頻
public void ARVideo_Button()
{
SceneManager.LoadScene("Movie");
}
}
VedioCtrl
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class VedioCtrl : MonoBehaviour {
public MediaPlayerCtrl scrMedia;
public bool m_bFinish = false;
// Use this for initialization
void Start()
{
scrMedia.OnEnd += OnEnd;
}
// Update is called once per frame
void Update()
{
}
//播放視頻1
public void Vedio_01() {
scrMedia.Load("k3.mp4");
m_bFinish = false;
//開(kāi)啟協(xié)程;
//StartCoroutine("PlayVedio");
StartCoroutine(PlayVedio());
}
public void Vedio_02()
{
scrMedia.Load("Demo.mp4");
m_bFinish = false;
//開(kāi)啟協(xié)程砾脑;
//StartCoroutine("PlayVedio");
StartCoroutine(PlayVedio());
}
//停止加載
public void UnLoad(){
scrMedia.UnLoad();
}
//協(xié)程函數(shù)
IEnumerator PlayVedio() {
yield return new WaitForSeconds(0.3f);
scrMedia.Play();
m_bFinish = false;
}
/* void OnGUI()
{
if (GUI.Button(new Rect(50, 50, 100, 100), "Load"))
{
scrMedia.Load("EasyMovieTexture.mp4");
m_bFinish = false;
}
if (GUI.Button(new Rect(50, 200, 100, 100), "Play"))
{
scrMedia.Play();
m_bFinish = false;
}
if (GUI.Button(new Rect(50, 350, 100, 100), "stop"))
{
scrMedia.Stop();
}
if (GUI.Button(new Rect(50, 500, 100, 100), "pause"))
{
scrMedia.Pause();
}
if (GUI.Button(new Rect(50, 650, 100, 100), "Unload"))
{
scrMedia.UnLoad();
}
if (GUI.Button(new Rect(50, 800, 100, 100), " " + m_bFinish))
{
}
if (GUI.Button(new Rect(200, 50, 100, 100), "SeekTo"))
{
scrMedia.SeekTo(10000);
}
if (scrMedia.GetCurrentState() == MediaPlayerCtrl.MEDIAPLAYER_STATE.PLAYING)
{
if (GUI.Button(new Rect(200, 200, 100, 100), scrMedia.GetSeekPosition().ToString()))
{
}
if (GUI.Button(new Rect(200, 350, 100, 100), scrMedia.GetDuration().ToString()))
{
}
if (GUI.Button(new Rect(200, 450, 100, 100), scrMedia.GetVideoWidth().ToString()))
{
}
if (GUI.Button(new Rect(200, 550, 100, 100), scrMedia.GetVideoHeight().ToString()))
{
}
}
if (GUI.Button(new Rect(200, 650, 100, 100), scrMedia.GetCurrentSeekPercent().ToString()))
{
}
}
*/
void OnEnd()
{
m_bFinish = true;
}
//退出房間
public void Out_Button()
{
SceneManager.LoadScene("Main");
}
}