Browse Source

修復基礎版本的重複物體的BUG

胡佳骏 1 year ago
parent
commit
e83bfb3ce0

+ 2 - 0
Assets/2.0/Tools/LoadManager.cs

@@ -90,6 +90,8 @@ public class LoadManager : Singleton<LoadManager>
                     }else if(model.prefabModel==null)
                     {
                         model.prefabModel = new GameObject("空物体"+ downList[dName].id);
+
+                      //  model.initFrist();
                     }
                     callback.Invoke(model.prefabModel);
                 }

+ 26 - 11
Assets/2.0/User/Model/ModelItem.cs

@@ -19,7 +19,7 @@ public enum ModelType
     vuforial = -2,
 
 }
-public class ModelItem 
+public class ModelItem : System.ICloneable
 {
 
     public int updateTime { get; set; }
@@ -35,13 +35,13 @@ public class ModelItem
     //模型数据
     public GameObject Model
     {
-        get { 
-            if(_model==null)
+        get {
+            if (_model == null)
             {
                 _model = new GameObject(name);
                 _model.transform.parent = modelList.transform;
-               // _model.transform.localPosition = getInfoPos();
-              //  _model.transform.localEulerAngles = getInfoEul();
+                // _model.transform.localPosition = getInfoPos();
+                //  _model.transform.localEulerAngles = getInfoEul();
 
                 Debug.Log(" ModelName>>>>  " + name + "   Type    " + type);
 
@@ -53,7 +53,7 @@ public class ModelItem
     public void init()
     {
         Debug.LogError("ModelItem Init");
-       if (modelType != ModelType.Text)
+        if (modelType != ModelType.Text)
             LoadManager.Instance.load(this, (float f) =>
             {
 
@@ -63,15 +63,15 @@ public class ModelItem
             }, (GameObject obj) =>
             {
                 _model = prefabModel;
-                obj.name ="加载出来的模型-----"+ obj.name;
+                obj.name = "加载出来的模型-----" + obj.name;
                 // obj.transform.parent = _model.transform;
                 //   obj.transform.localPosition = getInfoPos(); 
                 //  obj.transform.localEulerAngles = getInfoEul(); 
 
 
             });
-      //  else
-       //     SetData(null);
+        //  else
+        //     SetData(null);
     }
 
 
@@ -89,10 +89,18 @@ public class ModelItem
 
     Vector3 getInfoPos()
     {
-        Debug.Log("初始化坐标===》"+ prefabModel.transform.localPosition);
+        Debug.Log("DGJ2   ====> " + name + "_" + prefabModel.transform.localPosition + "_" + prefabModel.transform.name);
         if (prefabModel.transform.localPosition != Vector3.zero)
         {
-            return prefabModel.transform.localPosition;
+            YangShiTextItem ysi = prefabModel.GetComponent<YangShiTextItem>();
+
+            if (ysi&&((prefabModel.transform.localPosition.y == ysi.buttomf)|| (prefabModel.transform.localPosition.y == ysi.topf)) && prefabModel.transform.localPosition.x == 0 && prefabModel.transform.localPosition.z == 0)
+            {
+                Debug.Log("objectTransform.nowPos===>" + objectTransform.nowPos);
+            }else
+            {
+                return prefabModel.transform.localPosition;
+            }
         }
 
         if (prefabModel == null || objectTransform.nowPos==null)
@@ -208,6 +216,12 @@ public class ModelItem
       //      Debug.Log(" 添加模型 " + name);
     }
 
+    public object Clone()
+    {
+        ModelItem clonedObject = (ModelItem)this.MemberwiseClone();
+
+        return clonedObject;
+    }
     public void SetData(byte[] data)
     {
         if(data ==null && modelType!= ModelType.Video)
@@ -258,6 +272,7 @@ public class ModelItem
       
     }
 
+
     public void initModelObj()
     {
         if (getInfoPos() != Vector3.zero)

+ 6 - 3
Assets/2.0/User/Model/ModelList.cs

@@ -265,10 +265,12 @@ public class ModelList: System.ICloneable
                             go.transform.localPosition = new Vector3(0, -0.3f, 0);
                         }
                     }
-                    mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
+                    //mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
                  
                 }
                 mat.prefabModel = go;
+
+               // mat.initFrist();
             }           
         }
     }
@@ -353,11 +355,13 @@ public class ModelList: System.ICloneable
                             go.transform.localPosition = new Vector3(0.3f, 0f, 0);
                         }
                     }
-                    mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
+                  //  mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
                 }
                 ObjectValue objectValue = CreateMatObjectValue(i, material.id, go, mat);
                 objects.Add(objectValue);
                 mat.prefabModel = go;
+
+             //   mat.initFrist();
             }
            
 
@@ -462,7 +466,6 @@ public class ModelList: System.ICloneable
     public object Clone()
     {
         ModelList clonedObject = (ModelList)this.MemberwiseClone();
-
         return clonedObject;
     }
 

+ 70 - 18
Assets/2.0/User/Spots/SpotsItem.cs

@@ -1,4 +1,5 @@
 using LitJson;
+using Newtonsoft.Json;
 using SC.XR.Unity.Module_InputSystem;
 using System.Collections;
 using System.Collections.Generic;
@@ -72,7 +73,15 @@ public class SpotsItem
         obj.transform.parent = imageaction.transform;
         obj.transform.localEulerAngles = new Vector3(90, 0, 0);
         obj.transform.localPosition = Vector3.zero;
-
+        foreach (var mlkeys in modelList.Keys)
+        {
+            ModelList ml = modelList[mlkeys];
+            for (int i = 0; i < ml.materialList.Count; i++)
+            {
+                Debug.Log("DGJ2   ====> ml.materialList[i]." + ml.materialList[i].name);
+                Debug.Log("DGJ2   ====> ml.materialList[i]." + obVuforia.TargetName);
+            }
+        }
     }
     GameObject obj;
 
@@ -85,13 +94,20 @@ public class SpotsItem
             {
                 foreach (var item in usi.SpotsList.Keys)
                 {
-                    if (usi.SpotsList[item].VuforiaItem.activeSelf&& usi.SpotsList[item].id!=id)
+                    if (usi.SpotsList[item].obVuforia.TargetName == behaviour.TargetName)
                     {
-                        usi.SpotsList[item].VuforiaItem.SetActive(false);
+                        if (usi.SpotsList[item].VuforiaItem.activeSelf&& usi.SpotsList[item].id!=id )
+                        {
+                            usi.SpotsList[item].VuforiaItem.SetActive(false);
+                        }
+                        else if(usi.SpotsList[item].id == id)
+                        {
+                        VuforiaItem.SetActive(true);
+                        }
                     }
-                    else if(usi.SpotsList[item].id == id)
+                    else
                     {
-                        VuforiaItem.SetActive(true);
+                        usi.SpotsList[item].VuforiaItem.SetActive(false);
                     }
 
                 }
@@ -100,15 +116,43 @@ public class SpotsItem
                 TimerMgr.Instance.CreateTimer(()=> {
                     VuforiaItem.transform.position = obj.transform.position;
                     VuforiaItem.transform.eulerAngles = obj.transform.eulerAngles;
+                    VuforiaItem.transform.eulerAngles = new Vector3(0, VuforiaItem.transform.eulerAngles.y, 0);
                     Debug.Log("OnTargetStatusChanged ·¢ÏÖ " + obj.transform.position + "status ==>" + obj.transform.eulerAngles);
                 }, 0.1f,10);
-                if(!isInitModel)
+                if (!isInitModel)
                 {
-                     Dictionary<string, ModelList> NewmodelList = new Dictionary<string, ModelList>();
+                    Dictionary<string, ModelList> NewmodelList = new Dictionary<string, ModelList>();
                     foreach (var mlkeys in modelList.Keys)
                     {
                         ModelList ml = modelList[mlkeys];
                         ml._model = GameObject.Instantiate<GameObject>(ml.Model);
+                        JsonData msg = UserSceneManager.smsg;
+
+                        for (int i = 0; i < msg["listSpoit"].Count; i++)
+                        {
+                            Debug.Log("DGJ2   ==New1==> " + this.id + "_" + msg["listSpoit"][i]["id"].ToString());
+
+                            if (this.id == msg["listSpoit"][i]["id"].ToString())
+                            {
+                                for (int j = 0; j < msg["listSpoit"][i]["material"].Count; j++)
+                                {
+                                    if (msg["listSpoit"][i]["material"][j]["materialList"] != null && msg["listSpoit"][i]["material"][j]["materialList"].IsArray)
+                                    {
+                                            for (int z = 0; z < msg["listSpoit"][i]["material"][j]["materialList"].Count; z++)
+                                            {
+                                                Debug.Log("DGJ2   ==New1==> " + this.triggerImage + "_" + msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson() + "_" + (msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson()));
+                                                ml.materialList[z].objectTransform = JsonConvert.DeserializeObject<ObjectTransform>(msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson());
+                                                //modellist.materialList[z].initModelObj();
+                                                Debug.Log("DGJ2   ==New1==> " + ml.materialList[z].id + "_" + msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson());
+                                                ml.materialList[z].name = this.triggerImage;
+                                                //  GameManager.Instance.StartCoroutine(modellist.materialList[z].initFrist());
+                                            }
+                                    }
+                                }
+
+                            }
+                        }
+
                         NewmodelList.Add(mlkeys, ml);
                         for (int i = 0; i < ml.materialList.Count; i++)
                         {
@@ -119,17 +163,24 @@ public class SpotsItem
 
                                     ml.materialList[i]._model = ml._model.transform.GetChild(0).GetComponent<YangShiManager>().yangshiList[i].useObj;
                                     ml.materialList[i].prefabModel = ml.materialList[i]._model;
-                                }else
+                                    
+                                    //  ml.materialList[i].initFrist();
+                                }
+                                else
                                 {
 
                                     ml.materialList[i]._model = ml._model.transform.GetChild(0).GetComponent<YangShiManager>().yangshiText.gameObject;
                                     ml.materialList[i].prefabModel = ml.materialList[i]._model;
+                                    
+                                    //   ml.materialList[i].initFrist();
                                 }
                             }
                             else
                             {
                                 ml.materialList[i]._model = ml._model.transform.GetChild(i).gameObject;
                                 ml.materialList[i].prefabModel = ml._model.transform.GetChild(i).gameObject;
+                                
+                                //  ml.materialList[i].initFrist();
                             }
                         }
                         ml.Model.SetActive(true);
@@ -159,16 +210,17 @@ public class SpotsItem
                         bb = modelList2.AddComponent<BoundingBox>();
                         bb.FlattenAxis = BoundingBox.FlattenModeType.FlattenZ;
                         bb.ActiveHandle = BoundingBox.HandleType.Rotation | BoundingBox.HandleType.Scale;
-                        ng= modelList2.AddComponent<NearInterationGrabbable>();
-                        mh= modelList2.AddComponent<ManipulationHandler>();
-                        TimerMgr.Instance.CreateTimer(() => {
-                                
-                                bb.enabled = GameManager.m_IsStartEditorzu;
-                                if (modelList2.transform.Find("BoundingBox") && modelList2.transform.Find("BoundingBox").gameObject != null)
-                                    modelList2.transform.Find("BoundingBox").gameObject.SetActive(GameManager.m_IsStartEditorzu);
-                                if (bc)
-                                {
-                                    bc.enabled = GameManager.m_IsStartEditorzu;
+                        ng = modelList2.AddComponent<NearInterationGrabbable>();
+                        mh = modelList2.AddComponent<ManipulationHandler>();
+                        TimerMgr.Instance.CreateTimer(() =>
+                        {
+
+                            bb.enabled = GameManager.m_IsStartEditorzu;
+                            if (modelList2.transform.Find("BoundingBox") && modelList2.transform.Find("BoundingBox").gameObject != null)
+                                modelList2.transform.Find("BoundingBox").gameObject.SetActive(GameManager.m_IsStartEditorzu);
+                            if (bc)
+                            {
+                                bc.enabled = GameManager.m_IsStartEditorzu;
                             }
                             if (mh)
                                 mh.enabled = GameManager.m_IsStartEditorzu;

+ 14 - 0
Assets/2.0/User/Trigger/VufroiaTrigger.cs

@@ -64,6 +64,19 @@ public class VufroiaTrigger
 
         if(observer !=null)
         {
+
+            foreach (string item2 in usi.SpotsList.Keys)
+            {
+                foreach (var item111 in usi.SpotsList[item2].modelList.Keys)
+                {
+                    for (int ij = 0; ij < usi.SpotsList[item2].modelList[item111].materialList.Count; ij++)
+                    {
+                        Debug.Log("測試===2=》" + usi.SpotsList[item2].modelList[item111].materialList[ij].name);
+                        Debug.Log("測試===2=》" + usi.SpotsList[item2].id + "_" + DataManager.Instance.ProjectID.ToString() + "_" + usi.id);
+                        Debug.Log("測試===2=》" + usi.SpotsList[item2].triggerImageMark);
+                    }
+                }
+            }
             foreach (ObserverBehaviour item in observer)
             {
 
@@ -76,6 +89,7 @@ public class VufroiaTrigger
                         usi.SpotsList[item2].setObVuforia(item);
                     }
                 }
+
             }
 
         }

+ 31 - 5
Assets/2.0/User/UserScene/UserSceneManager.cs

@@ -3,6 +3,7 @@ using Newtonsoft.Json;
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
+using XRTool.Util;
 
 public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
 {
@@ -74,9 +75,12 @@ public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
 
         }));
     }
+    Dictionary<string,JsonData> msglist = new Dictionary<string,JsonData>();
+    public static JsonData smsg;
     void CreateItem(JsonData msg,string id)
     {
-     //   JsonConvert.DeserializeObject<UserSceneItem>(msg.ToJson());
+        msglist.Add(id,msg);
+        //   JsonConvert.DeserializeObject<UserSceneItem>(msg.ToJson());
 
         UserSceneItem usi = new UserSceneItem();//
         usi.id = id;
@@ -131,6 +135,7 @@ public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
                             if(ModelManager.Instance.modellist.ContainsKey(int.Parse(msg["listSpoit"][i]["material"][j]["id"].ToString())))
                             {
                                 ModelList modellist = ModelManager.Instance.GetModelList(int.Parse(msg["listSpoit"][i]["material"][j]["id"].ToString()));
+
                                 Debug.Log("DGJ   ====> "+ msg["listSpoit"][i]["material"][j]["id"].ToString() + "_" +(msg["listSpoit"][i]["material"][j]["objectTransform"].ToJson()));
                                 modellist.objectTransform = JsonConvert.DeserializeObject<ObjectTransform>(msg["listSpoit"][i]["material"][j]["objectTransform"].ToJson());
                                // modellist._model.transform.parent = si.SpotsObj.transform;
@@ -139,6 +144,7 @@ public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
                                 modellist.init(false); 
                                 for (int l = 0; l < modellist.materialList.Count; l++)
                                 {
+                                    Debug.Log("DGJ New  ====> " + modellist.materialList[l].name);
                                     modellist.materialList[l].modelList = modellist.Model;
                                 }
                                 si.modelList.Add(msg["listSpoit"][i]["material"][j]["id"].ToString(), modellist);
@@ -147,11 +153,13 @@ public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
                                 {
                                     for (int z = 0; z < msg["listSpoit"][i]["material"][j]["materialList"].Count; z++)
                                     {
-                                        Debug.Log("DGJ2   ====> " + msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson() + "_" + (msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson()));
+                                        Debug.Log("DGJ2   ====> "+ si.triggerImage + "_" + msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson() + "_" + (msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson()));
                                         modellist.materialList[z].objectTransform = JsonConvert.DeserializeObject<ObjectTransform>(msg["listSpoit"][i]["material"][j]["materialList"][z]["objectTransform"].ToJson());
                                         //modellist.materialList[z].initModelObj();
-                                        if (modellist.materialList[z].objectTransform.nowPos != Vector3.zero)
-                                            modellist.materialList[z].prefabModel.transform.localPosition = modellist.materialList[z].objectTransform.nowPos;
+                                        Debug.Log("DGJ2   ====> " + indexa+"_" + modellist.materialList[z].id+"_"+ msg["listSpoit"][i]["material"][j]["materialList"][z]["id"].ToJson());
+                                        modellist.materialList[z].name = si.triggerImage;
+                                        indexa++;
+                                        //  GameManager.Instance.StartCoroutine(modellist.materialList[z].initFrist());
                                     }
                                 }
                                 si.init();
@@ -176,6 +184,20 @@ public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
         usi.vufroiaTrigger.usi = usi;
       
         SceneList.Add(usi.id, usi);
+        foreach (var usi2 in UserSceneManager.Instance.SceneList.Values)
+        {
+            foreach (var si in usi2.SpotsList.Values)
+            {
+                foreach (var item in si.modelList.Keys)
+                {
+                    for (int ij = 0; ij < si.modelList[item].materialList.Count; ij++)
+                    {
+
+                        Debug.Log("測試====》" + si.modelList[item].materialList[ij].name+"_" + si.triggerImageMark);
+                    }
+                }
+            }
+        }
         Debug.Log("UI   Data   添加场景===>"+ usi.id);
         now++;
         if(max<=now)
@@ -183,6 +205,7 @@ public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
             callback?.Invoke(true);
         }
     }
+    public static int indexa=0;
     public string nowId;
     public void gotoScene(string id)
     {
@@ -191,9 +214,12 @@ public class UserSceneManager : XRTool.Util.Singleton<UserSceneManager>
         SceneList[id].load();
         DataManager.Instance.ProjectID = int.Parse(id);
 
+        JsonData msg = UserSceneManager.smsg;
+
+        smsg = msglist[id];
     }
 
-    public Dictionary<string, UserSceneItem> GetScenes()
+        public Dictionary<string, UserSceneItem> GetScenes()
     {
         return SceneList;
     }

+ 1 - 1
Assets/Resources/VuforiaConfiguration.asset

@@ -39,7 +39,7 @@ MonoBehaviour:
     unlitShader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
     videoBackgroundEnabled: 1
   deviceTracker:
-    autoStartTracker: 1
+    autoStartTracker: 0
     arcoreRequirement: 1
     autoImportArcore: 1
     thirdPartyARCoreClientDetected: 1

+ 1 - 6
Assets/Scripts/Config/DataConfig.cs

@@ -57,20 +57,15 @@ public class ObjectTransform
     {
         Debug.Log("设置初始值");
         startPos = _startPos;
-        if(nowPos !=Vector3.zero)
-        nowPos = _startPos;
 
         startRot = _StartRot;
-        if (nowPos != Vector3.zero)
-            nowRot = _StartRot;
 
         startScale = _startScale;
-        if (nowPos != Vector3.one)
-            nowScale = _startScale;
     }
 
     public void SavePos(Vector3 _startPos, Vector3 _StartRot, Vector3 _startScale)
     {
+        Debug.Log("SavePosSavePosSavePosSavePos");
         nowPos = _startPos;
         nowRot = _StartRot;
         nowScale = _startScale;

+ 1 - 0
Assets/Scripts/LayoutGroup/DRFanLayout.cs

@@ -212,6 +212,7 @@ public class DRFanLayout : MonoBehaviour
                 objectValues.Add(objectValue);
                 mat.prefabModel = go;
 
+             //   mat.initFrist();
             }
         }
 

+ 2 - 0
Assets/Scripts/LayoutGroup/DRTitleLayout.cs

@@ -241,6 +241,8 @@ public class DRTitleLayout : MonoBehaviour
                     objectValues.Add(objectValue);
 
                     mat.prefabModel = go;
+
+                  //  mat.initFrist();
                 }
             }
 

+ 1 - 0
Assets/Scripts/LayoutGroup/SRSectorLayout.cs

@@ -236,6 +236,7 @@ public class SRSectorLayout : MonoBehaviour
                 ObjectValue objectValue = new ObjectValue(i, materialObls.id, mat.name, go);
                 objectValues.Add(objectValue);
                 mat.prefabModel = go;
+               // mat.initFrist();
             }
         }
 

+ 2 - 0
Assets/Scripts/LayoutGroup/SRTitleLayout.cs

@@ -239,6 +239,8 @@ public class SRTitleLayout : MonoBehaviour
                     mat.objectTransform.SetStartValue(go.transform.localPosition, go.transform.localEulerAngles, go.transform.localScale);
                 }
                 mat.prefabModel = go;
+
+             //   mat.initFrist();
             }
         }
 

+ 3 - 3
ProjectSettings/ProjectSettings.asset

@@ -935,7 +935,6 @@ PlayerSettings:
   metroSplashScreenUseBackgroundColor: 1
   platformCapabilities:
     WindowsStoreApps:
-      EnterpriseAuthentication: False
       OfflineMapsManagement: False
       HumanInterfaceDevice: False
       Location: False
@@ -948,6 +947,7 @@ PlayerSettings:
       InternetClientServer: False
       VideosLibrary: False
       Objects3D: False
+      InternetClient: True
       RemoteSystem: False
       BlockedChatMessages: False
       PhoneCall: False
@@ -968,10 +968,10 @@ PlayerSettings:
       PointOfService: False
       RecordedCallsFolder: False
       Contacts: False
-      InternetClient: True
+      Proximity: False
       CodeGeneration: False
       BackgroundMediaPlayback: False
-      Proximity: False
+      EnterpriseAuthentication: False
   metroTargetDeviceFamilies: {}
   metroFTAName: 
   metroFTAFileTypes: []