private void OnTrackingFound() { ModelManager._instance.ModelCountPlusOne(); //发现的模型数目+1 //在发现模型之后,应该重置手机的休息时间。 CountDown._instance.ResetTime(); if (ModelManager._instance.isOffCard && (ModelManager._instance.offCardTargetTransform && ModelManager._instance.offCardTargetTransform == this.transform)) { Utility.LogPrint("refound"); // ModelManager._instance.offCardModelIsMoving = false; // ModelManager._instance.ModelCountPlusOne();//发现的模型数目+1 // float disY = ModelManager._instance.offCardModelTransform.GetComponent<ModelSelfManager> ().tooTall ? Screen.height / 4 : Screen.height / 2; // Vector3 position = new Vector3 (Screen.width/2, disY, ModelManager._instance.zAxisDis); // position = ModelManager._instance.offCardCamera.ScreenToWorldPoint (position); // ModelManager._instance.offCardModelTransform.position = position; // ModelManager._instance.offCardModelTransform.localRotation = Quaternion.Euler(new Vector3(29,151,-8)); // Utility.LogPrint ("Refound --" + mTrackableBehaviour.TrackableName); return; } //如果模型没有加载,去加载。 if (!isModelLoaded) { StartCoroutine(LoadModel()); } else { //这里先触发了Trigger,然后才调用的SetActive(true),这样应该能避免自己也收到关闭音效的事件。待测试 (没问题) if (ModelManager._instance.modelCount > 1) { EventManager.TriggerEvent("Found"); } if (ModelManager._instance.modelCount == 1) { Utility.PrepareForSendMessage("FoundTarget", "1"); } if (this.transform.childCount >= 1) { this.transform.GetChild(0).gameObject.SetActive(true); //这行代码是方便测试用的,正式使用应该要用LoadModel方法中的。 if (isFirstFound) { AssMemoryManager.AddGOToMemoryManager(mTrackableBehaviour.TrackableName, this.gameObject); } ModelManager._instance.currentRotationTransform = this.transform.GetChild(0); } else { Utility.LogPrint(mTrackableBehaviour.TrackableName + "--child count is 0"); } //每次扫描过后,更新model的Index值,后面AssMemoryManager会根据这个值来管理这些模型 AssMemoryManager.UpdateModelIndex(mTrackableBehaviour.TrackableName); if (ModelManager._instance.isOffCard) { EventManager.TriggerEvent("OffCard"); } //Utility.LogPrint ("-- "+Vector3.Distance (transform.position, Camera.main.transform.position)); } Utility.LogPrint("Trackable " + mTrackableBehaviour.TrackableName + " --- found"); }
private IEnumerator LoadModel() { string path = modelSource; Utility.LogPrint("DynamicModelTrackableEventHandler LoadModel " + path); if (File.Exists(path)) { Utility.PrepareForSendMessage("LoadAssetBundle", "0", mTrackableBehaviour.TrackableName); string path1 = "file://" + modelSource; WWW bundle = new WWW(path1); yield return(bundle); GameObject [] gos = bundle.assetBundle.LoadAllAssets <GameObject>(); for (int i = 0; i < gos.Length; ++i) { GameObject go; yield return(go = Instantiate(gos [i])); if (go) { go.transform.position = this.transform.position; go.transform.SetParent(this.gameObject.transform); ModelSelfManager modelSelfManager = go.GetComponent <ModelSelfManager> (); modelSelfManager.modelOriginLocalPos = go.transform.localPosition; modelSelfManager.modelOriginLocalQua = go.transform.localRotation; modelSelfManager.modelOriginScale = go.transform.localScale; if (i == 0) { continue; } // the first gameobject needn't hidden go.SetActive(false); } else { Utility.LogPrint(mTrackableBehaviour.TrackableName + "--model loaded but instantiate fail"); } } bundle.assetBundle.Unload(false); isModelLoaded = true; Utility.LogPrint(mTrackableBehaviour.TrackableName + "--Model Created"); //------------------ //这里先触发了Trigger,然后才调用的SetActive(true),这样应该能避免自己也收到关闭音效的事件。待测试 (没问题) if (ModelManager._instance.modelCount > 1) { EventManager.TriggerEvent("Found"); } if (ModelManager._instance.modelCount == 1) { Utility.PrepareForSendMessage("FoundTarget", "1"); } if (this.transform.childCount >= 1) { this.transform.GetChild(0).gameObject.SetActive(true); //这行代码是方便测试用的,正式使用应该要用LoadModel方法中的。 if (isFirstFound) { AssMemoryManager.AddGOToMemoryManager(mTrackableBehaviour.TrackableName, this.gameObject); } ModelManager._instance.currentRotationTransform = this.transform.GetChild(0); } else { Utility.LogPrint(mTrackableBehaviour.TrackableName + "--child count is 0"); } //每次扫描过后,更新model的Index值,后面AssMemoryManager会根据这个值来管理这些模型 AssMemoryManager.UpdateModelIndex(mTrackableBehaviour.TrackableName); if (ModelManager._instance.isOffCard) { EventManager.TriggerEvent("OffCard"); } //----------------------- #region ass memorymanager /* * 这里AssetBundle的管理形式是:当程序中已经加载的AssetBundle已经超过一定数目时(现在暂定5个),就从中删除一个index最小的模型,此时在对应加载最新的模型 */ if (AssMemoryManager.instance.dicCount >= 5) { Utility.LogPrint("when load " + mTrackableBehaviour.TrackableName + "--need to delete some model from memory"); AssMemoryManager.RemoveGoFromMemoryManager(); } AssMemoryManager.AddGOToMemoryManager(mTrackableBehaviour.TrackableName, this.gameObject); Utility.LogPrint("add gameobject to target,the trackName is--" + mTrackableBehaviour.TrackableName); #endregion //memorymanager end //notify mobile load ass success Utility.PrepareForSendMessage("LoadAssetBundle", "1", mTrackableBehaviour.TrackableName); } else { //file not exist,notify mobile to load the ass; Utility.LogPrint(mTrackableBehaviour.TrackableName + "--load model error,because the file path is not exist"); Utility.PrepareForSendMessage("DownAssetBundle", "1", targetInfo); } }