public void SetProjectPath(string inProjectID) { projectID = inProjectID; #if UNITY_IPHONE || UNITY_IOS projectPath = projectID + "/IOS/"; commonPath = "common2/IOS/"; serverProjectInfoFinalUrl = projectInfoServerUrl + projectInfoAddUrl + projectID; imageFinalUrl = projectInfoServerUrl + imageAddUrl; serverAssetBundlePath = assetBundleServerUrl + assetBundleAddUrl + projectPath; serverCommonAssetBundlePath = assetBundleServerUrl + assetBundleAddUrl + commonPath; #elif UNITY_ANDROID projectPath = projectID + "/Andriod/"; commonPath = "common2/Andriod/"; serverProjectInfoFinalUrl = projectInfoServerUrl + projectInfoAddUrl + projectID; imageFinalUrl = projectInfoServerUrl + imageAddUrl; serverAssetBundlePath = assetBundleServerUrl + assetBundleAddUrl + projectPath; serverCommonAssetBundlePath = assetBundleServerUrl + assetBundleAddUrl + commonPath; #endif if (!Directory.Exists(Application.persistentDataPath + "/" + projectID.ToString())) { Directory.CreateDirectory(Application.persistentDataPath + "/" + projectID.ToString()); } if (!Directory.Exists(Application.persistentDataPath + "/" + projectID.ToString() + "/imageCache")) { Directory.CreateDirectory(Application.persistentDataPath + "/" + projectID.ToString() + "/imageCache"); } localProjectInfoPath = Application.persistentDataPath + "/" + projectID.ToString() + "/ProjectInfo.txt"; localProjectAssetBundlesInfoPath = Application.persistentDataPath + "/" + projectID.ToString() + "/ProjectAssetBundlesInfo.txt"; localImageCachePath = Application.persistentDataPath + "/" + projectID.ToString() + "/imageCache"; localHXinfoCachePath = Application.persistentDataPath + "/HXinfoCache"; serverProjectAssetBundlesInfoPath = serverAssetBundlePath + "ProjectAssetBundlesInfo.txt"; GlobalDebug.ReplaceLine("Loacl PersistentDataPath: " + Application.persistentDataPath, 8); GlobalDebug.ReplaceLine("CacheCount:" + Caching.cacheCount.ToString(), 9); GlobalDebug.ReplaceLine(Caching.GetCacheAt(0).path, 10); GlobalDebug.ReplaceLine("Loacl " + localProjectAssetBundlesInfoPath, 11); GlobalDebug.ReplaceLine("Servrl " + serverProjectAssetBundlesInfoPath, 12); }
void Update() { if (globalDebug) { GlobalDebug.ReplaceLine("inTouch:" + inTouch.ToString(), 0); GlobalDebug.ReplaceLine("inZoom:" + inZoom.ToString(), 1); GlobalDebug.ReplaceLine("firstPosition:" + firstPosition.ToString(), 2); GlobalDebug.ReplaceLine("disVec2_first:" + disVec2_first.ToString(), 3); GlobalDebug.ReplaceLine("disVec2:" + disVec2.ToString(), 4); GlobalDebug.ReplaceLine("dpi:" + Screen.dpi.ToString(), 5); } #if UNITY_EDITOR || UNITY_STANDALONE_WIN if (cameraCenter != null && cameraCenter.currentCamera != null) { cameraCenter.currentCamera.MouseScroll(-Input.mouseScrollDelta.y); } #endif }
// Update is called once per frame void Update() { if (cameraUniversal != null) { gyroQ = GyroToUnity(Quaternion.Euler(-90, 0, 0) * Input.gyro.attitude); gyroscopeProxy.transform.rotation = Quaternion.Slerp(gyroscopeProxy.transform.rotation, gyroQ, 0.33f); Vector3 f = gyroscopeProxy.transform.forward; cameraUniversal.Ycount = LookFlowGryo(f); cameraUniversal.SetYSmooth(cameraUniversal.Ycount); ray = new Ray(rotX.position, rotX.forward); if (moveCollider.Raycast(ray, out hit, 20)) { Debug.DrawLine(ray.origin, hit.point); Vector3 toPos = new Vector3(hit.point.x, hit.point.y, hit.point.z); GlobalDebug.ReplaceLine(toPos.ToString(), 9); moveImage.color = new Color(0, 0.5f, 1f); cameraUniversal.vrMoveForward = true; // GlobalDebug.ReplaceLine("True", 10); } else { moveImage.color = new Color(1f, 1f, 1f); cameraUniversal.vrMoveForward = false; GlobalDebug.ReplaceLine("False", 10); } rotX.localEulerAngles = new Vector3((f.y > 0 ? -1 : 1) * Vector3.Angle(f, new Vector3(f.x, 0, f.z)), 0, 0); GlobalDebug.ReplaceLine("VR X: " + rotX.localEulerAngles.ToString(), 7); GlobalDebug.ReplaceLine("VR Y: " + cameraUniversal.Ycount.ToString(), 8); } }
public void LoadProjcetAssetBundles(string inProjectID) { // Debug.Log("PersistentDataPath: "+Application.persistentDataPath); // SetProjectPath(inProjectID); Loading loading = loadingManager.AddALoading(0); bool checkFile = false; if (checkFile = File.Exists(pathAndURL.localProjectAssetBundlesInfoPath)) { string jsonStr = File.ReadAllText(pathAndURL.localProjectAssetBundlesInfoPath); localProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(jsonStr); netCtrlManager.WebRequest( "同步服务器", pathAndURL.serverProjectAssetBundlesInfoPath, loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); // if (globalDebug) GlobalDebug.ReplaceLine(t.text, 15); //判断两个资源的生成时间,如果时间不一样表示资源以过期,要删去旧的资源以便重新下载 if (serverProjectAssetBundlesInfo.buildTime != localProjectAssetBundlesInfo.buildTime) { File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); for (int i = 0; i < serverProjectAssetBundlesInfo.sceneAssetBundle.Length; i++) { Caching.ClearOtherCachedVersions(pathAndURL.projectPath + serverProjectAssetBundlesInfo.sceneAssetBundle[i], Hash128.Parse(serverProjectAssetBundlesInfo.sceneAssetBundleHash[i])); } } StartLoadAssetBundle(serverProjectAssetBundlesInfo); }, null, null ); } else { netCtrlManager.WebRequest( "同步服务器", pathAndURL.serverProjectAssetBundlesInfoPath, loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { // if (globalDebug) GlobalDebug.ReplaceLine(t.text, 15); serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); StartLoadAssetBundle(serverProjectAssetBundlesInfo); }, null, null ); } // if(globalDebug) GlobalDebug.ReplaceLine("HasLoaclInfo.txt:" + checkFile.ToString(), 16); }
void Update() { if (mfqTcpClient != null && mfqTcpClient.hasInit) { GlobalDebug.ReplaceLine("NeedProcessEvents: " + RemoteGather.needProcessMessages.Count.ToString(), 15); GlobalDebug.ReplaceLine("NeedSendEvents: " + RemoteGather.needSendBtnCtrlMessages.Count.ToString(), 16); GlobalDebug.ReplaceLine("IsEnterRoom: " + isEnterRoom.ToString(), 17); GlobalDebug.ReplaceLine("IsOtherSideOnline: " + isOtherSideOnline.ToString(), 18); GlobalDebug.ReplaceLine("waitingAck: " + waitingAck.ToString(), 19); if (sceneInteractiveManger.currentActiveSenceInteractiveInfo != null) { RemoteGather.currentCameraUniversal = sceneInteractiveManger.currentActiveSenceInteractiveInfo.cameraUniversalCenter.currentCamera; } //等待Ack if (waitingAck) { waitingAckPastTime += Time.deltaTime; if (waitingAckPastTime > maxTimeWaitAck) { if (!isEnterRoom) { if (currentRetryCount < maxRetryCount) { string log = "重试进入房间次数:" + currentRetryCount; GlobalDebug.Addline(log); Debug.Log(log); waitingAckPastTime = 0; waitingAck = false; currentRetryCount = 0; DisConnect(); StartMFQTcpClient(runAtType, remoteID, userID); EnterRoom(); } else { string log = "重试进入房间达到最大次数,请检查网络连接!"; GlobalDebug.Addline(log); Debug.Log(log); Debug.LogWarning(log); Debug.LogError(log); waitingAckPastTime = 0; waitingAck = false; currentRetryCount++; // DisConnect(); LostConnect(); } }//以下是操作传输重试 else { if (currentRetryCount < maxRetryCount) { waitingAckPastTime = 0; waitingAck = false; currentRetryCount++; string log = "重试发送信息次数:" + currentRetryCount; GlobalDebug.Addline(log); Debug.Log(log); } else { string log = "重试发送信息达到最大次数,准备重新连接讲盘网络!"; GlobalDebug.Addline(log); Debug.Log(log); Debug.LogWarning(log); Debug.LogError(log); waitingAck = false; waitingAckPastTime = 0; currentRetryCount = 0; //断开连接重新尝试进入房间 DisConnect(); StartMFQTcpClient(runAtType, remoteID, userID); EnterRoom(); } } } } else if (isEnterRoom) { if (isOtherSideOnline) { //判断10内有没有收到对方消息,如果没有收到消息,判定对方掉线重新发送AreYouReady消息; lastMessageReceiveFromOtherSidePastTime += Time.deltaTime; if (lastMessageReceiveFromOtherSidePastTime > 15) { isOtherSideOnline = false; } } if (RemoteGather.needProcessMessages.Count > 0) { ProcessMessage(RemoteGather.needProcessMessages[0]); } //判断对方是否在线,由slave每2秒进行发送验证消息,Master接收后确认Slave在线.Master开始发送当前状态. else if (!isOtherSideOnline) { if (runAtType == RunAtType.Slave) { SendCtrlMessage(new RemoteGather.RemoteMessage(51).GetBytesData()); //设置成无限尝试 currentRetryCount = 0; //起始时间设置为3秒,这样两秒后就能重试 waitingAckPastTime = 3; } }//下面的if暂时没有使用上 else if (isOtherSideOnline && RemoteGather.needSendAckMessages.Count > 0) { SendCtrlMessage(RemoteGather.needSendAckMessages[0].GetBytesData(), false); RemoteGather.needSendAckMessages.RemoveAt(0); } else if (isOtherSideOnline && runAtType == RunAtType.Master && RemoteGather.needSendBtnCtrlMessages.Count > 0) { SendCtrlMessage(RemoteGather.needSendBtnCtrlMessages[0].GetBytesData()); } else if (isOtherSideOnline && NeedSendCameraState()) { //目前的问题:在等待CameraState Ack的时候会收到对方的其它类型的信息,以至于没有收到CameraState Ack,一直处于等待Ack的状态. //本想实现,master和slave相互之间的操作,有问题,先实现Master控制Slave // cameraStateWhenSendMessage = RemoteGather.currentCameraUniversal.GetCameraState(); SendCtrlMessage(new RemoteGather.RemoteMessage(49, "", false, RemoteGather.currentCameraUniversal).GetBytesData()); } else if (isOtherSideOnline && NeedSendScaleImageState()) { scaleImageWhenSendMessage = RemoteGather.currentCtrlScaleImage.GetState(); SendCtrlMessage(new RemoteGather.RemoteMessage(52, RemoteGather.currentCtrlScaleImage.btnNameForRemote, false, null, RemoteGather.currentCtrlScaleImage).GetBytesData()); } } } }
void Update() { if (mfqTcpClient != null && mfqTcpClient.hasInit) { GlobalDebug.ReplaceLine("NeedProcessEvents: " + RemoteGather.needProcessMessages.Count.ToString(), 15); GlobalDebug.ReplaceLine("NeedSendEvents: " + RemoteGather.needSendBtnCtrlMessages.Count.ToString(), 16); GlobalDebug.ReplaceLine("IsEnterRoom: " + isEnterRoom.ToString(), 17); GlobalDebug.ReplaceLine("IsOtherSideOnline: " + isOtherSideOnline.ToString(), 18); GlobalDebug.ReplaceLine("waitingAck: " + waitingAck.ToString(), 19); if (sceneInteractiveManger.currentActiveSenceInteractiveInfo != null) { RemoteGather.currentCameraUniversal = sceneInteractiveManger.currentActiveSenceInteractiveInfo.cameraUniversalCenter.currentCamera; } if (sceneInteractiveManger.currentThumbnailCamera != null) { RemoteGather.currentCameraUniversal = sceneInteractiveManger.currentThumbnailCamera; } //等待Ack if (waitingAck) { waitingAckPastTime += Time.deltaTime; if (waitingAckPastTime > maxTimeWaitAck) { if (!isEnterRoom) { if (currentRetryCount < maxRetryCount) { string log = "重试进入房间次数:" + currentRetryCount; GlobalDebug.Addline(log); Debug.Log(log); waitingAckPastTime = 0; waitingAck = false; currentRetryCount = 0; DisConnect(); StartMFQTcpClient(runAtType, remoteID, userID); EnterRoom(); } else { string log = "重试进入房间达到最大次数,请检查网络连接!"; GlobalDebug.Addline(log); Debug.Log(log); Debug.LogWarning(log); Debug.LogError(log); waitingAckPastTime = 0; waitingAck = false; currentRetryCount++; //网络连接断开,这是由于网络造成的被动断开 remoteGUI.FinishOnLineTalk("网络连接失败"); } }//以下是操作传输重试 else { if (currentRetryCount < maxRetryCount) { waitingAckPastTime = 0; waitingAck = false; currentRetryCount++; string log = "重试发送信息次数:" + currentRetryCount; GlobalDebug.Addline(log); Debug.Log(log); } else { string log = "重试发送信息达到最大次数,准备重新连接讲盘网络!"; // string log = "重试发送信息达到最大次数,结束讲盘!"; GlobalDebug.Addline(log); Debug.Log(log); Debug.LogWarning(log); Debug.LogError(log); waitingAck = false; waitingAckPastTime = 0; currentRetryCount = 0; //重试达到最大数还没成功就断开房间,重新连接 ReEnterRoom(); } } } } else if (isEnterRoom) { if (isOtherSideOnline) { lastMessageReceiveFromOtherSidePastTime += Time.deltaTime; //判断5秒内有没有收到对方消息,发送StillOnline信息确定对方是否在线,由控制方发送, if (runAtType == RunAtType.Master && lastMessageReceiveFromOtherSidePastTime > 5) { //如果没有收到对方的应答,会以每3秒重试3次,9+5=14秒。超过14秒将会执行断开。 SendCtrlMessage(new RemoteGather.RemoteMessage(98).GetBytesData()); } //判断14秒有没有收到Master消息,如果没有收到消息,判定掉线,执行断开。 if (runAtType == RunAtType.Slave && lastMessageReceiveFromOtherSidePastTime > 14) { ReEnterRoom(); // string logStr = "超时 Close InvokeFrom: 被操作者"; } } if (RemoteGather.needProcessMessages.Count > 0) { ProcessMessage(RemoteGather.needProcessMessages[0]); } //判断对方是否在线,由slave每2秒进行发送验证消息,Master接收后确认Slave在线.Master开始发送当前状态. else if (!isOtherSideOnline) { if (runAtType == RunAtType.Slave) { SendCtrlMessage(new RemoteGather.RemoteMessage(51).GetBytesData()); //设置成无限尝试 currentRetryCount = 0; //起始时间设置为3秒,这样两秒后就能重试 waitingAckPastTime = 1; } }//下面的if暂时没有使用上,needSendAckMessages未使用 else if (isOtherSideOnline && RemoteGather.needSendAckMessages.Count > 0) { SendCtrlMessage(RemoteGather.needSendAckMessages[0].GetBytesData(), false); RemoteGather.needSendAckMessages.RemoveAt(0); } else if (isOtherSideOnline && runAtType == RunAtType.Master && RemoteGather.needSendBtnCtrlMessages.Count > 0) { SendCtrlMessage(RemoteGather.needSendBtnCtrlMessages[0].GetBytesData()); } else if (isOtherSideOnline && NeedSendCameraState()) { //目前的问题:在等待CameraState Ack的时候会收到对方的其它类型的信息,以至于没有收到CameraState Ack,一直处于等待Ack的状态. //本想实现,master和slave相互之间的操作,有问题,先实现Master控制Slave // cameraStateWhenSendMessage = RemoteGather.currentCameraUniversal.GetCameraState(); SendCtrlMessage(new RemoteGather.RemoteMessage(49, "", false, RemoteGather.currentCameraUniversal).GetBytesData()); } else if (isOtherSideOnline && NeedSendScaleImageState()) { scaleImageWhenSendMessage = RemoteGather.currentCtrlScaleImage.GetState(); SendCtrlMessage(new RemoteGather.RemoteMessage(52, RemoteGather.currentCtrlScaleImage.btnNameForRemote, false, null, RemoteGather.currentCtrlScaleImage).GetBytesData()); } } } }
//如果OnCached非空,只会缓存AssetBundles,且调用OnCached public void LoadProjcetAssetBundlesCache(string inProjectID, UnityAction <ProjectAssetBundlesInfo, string, string> OnCached = null, string hxAssetBundleName = null) { //Debug.Log("PersistentDataPath: "+Application.persistentDataPath); Loading loading = loadingManager.AddALoading(0); bool checkFile = false; if (checkFile = File.Exists(pathAndURL.localProjectAssetBundlesInfoPath)) { string log = "有本地ProjectAssetBundlesInfo.txt"; GlobalDebug.Addline(log); Debug.Log(log); string jsonStr = File.ReadAllText(pathAndURL.localProjectAssetBundlesInfoPath); localProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(jsonStr); Debug.Log(pathAndURL.serverProjectAssetBundlesInfoPath); GlobalDebug.Addline(pathAndURL.serverProjectAssetBundlesInfoPath); Debug.Log(netCtrlManager); //"?"+DateTime.Now.ToString() 添加时间防止ios读取http缓存 netCtrlManager.WebRequest( "同步AssetBundle服务器", pathAndURL.serverProjectAssetBundlesInfoPath + "?" + DateTime.Now.ToString(), loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); // if (globalDebug) GlobalDebug.ReplaceLine(t.text, 15); Debug.Log(t.text); string log2 = "ServerTime:" + serverProjectAssetBundlesInfo.buildTime + " LocalTime:" + localProjectAssetBundlesInfo.buildTime; GlobalDebug.Addline(log2); Debug.Log(log2); //判断两个资源的生成时间,如果时间不一样表示资源以过期,要删去旧的资源以便重新下载 if (serverProjectAssetBundlesInfo.buildTime != localProjectAssetBundlesInfo.buildTime) { string log3 = "删除老资源,替换新资源"; GlobalDebug.Addline(log3); Debug.Log(log3); File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); for (int i = 0; i < serverProjectAssetBundlesInfo.sceneAssetBundle.Length; i++) { Caching.ClearOtherCachedVersions(pathAndURL.projectPath + serverProjectAssetBundlesInfo.sceneAssetBundle[i], Hash128.Parse(serverProjectAssetBundlesInfo.sceneAssetBundleHash[i])); } } if (OnCached != null) { OnCached.Invoke(serverProjectAssetBundlesInfo, inProjectID, hxAssetBundleName); } else { StartLoadAssetBundle(serverProjectAssetBundlesInfo); } }, null, null ); } else { string log = "无本地ProjectAssetBundlesInfo.txt"; GlobalDebug.Addline(log); Debug.Log(log); netCtrlManager.WebRequest( "同步AssetBundle服务器", pathAndURL.serverProjectAssetBundlesInfoPath, loading.LoadingAnimation, (NetCtrlManager.RequestHandler r, UnityWebRequestAsyncOperation a, string info) => { Debug.Log("ServerProjectAssetBundlesInfo Load Failed!"); }, (DownloadHandler t) => { string log2 = "获取到Server的ProjectAssetBundlesInfo.txt"; GlobalDebug.Addline(log2); Debug.Log(log2); GlobalDebug.ReplaceLine(t.text, 15); serverProjectAssetBundlesInfo = JsonUtility.FromJson <ProjectAssetBundlesInfo>(t.text); File.WriteAllText(pathAndURL.localProjectAssetBundlesInfoPath, t.text); if (OnCached != null) { OnCached.Invoke(serverProjectAssetBundlesInfo, inProjectID, hxAssetBundleName); } else { StartLoadAssetBundle(serverProjectAssetBundlesInfo); } }, null, null ); } // if(globalDebug) GlobalDebug.ReplaceLine("HasLoaclInfo.txt:" + checkFile.ToString(), 16); }