Exemplo n.º 1
0
            private GameObject GetPrefabObject()
            {
                GameObject gameObject   = null;
                GameObject sourceObject = _sourceObject;

#if UNITY_EDITOR
                if (_sourceObject == null)
                {
                    //In the editor find asset from the editor prefab field
                    sourceObject = _prefab._editorAsset;
                }
#endif
                GameObject prefabObject = PrefabRoot.GetPrefabRoot(sourceObject);

                if (prefabObject != null && !string.IsNullOrEmpty(_objectName))
                {
                    if (prefabObject.name == _objectName || prefabObject.name == _objectName + "(Clone)")
                    {
                        gameObject = prefabObject;
                    }
                    else
                    {
                        Transform child = prefabObject.transform.Find(_objectName);
                        if (child != null)
                        {
                            gameObject = child.gameObject;
                        }
                    }
                }

                return(gameObject);
            }
Exemplo n.º 2
0
 private void LoadPrefab(RoleInfo roleInfo)
 {
     if (this.modelPath != roleInfo.ModelPath || objModel == null)
     {
         DestoryModel();
         this.modelPath = roleInfo.ModelPath;
         if (roleInfo.IsLocal)
         {
             this.objModel = PrefabRoot.GetGameObject("Role", this.modelPath);
             if (this.objModel != null)
             {
                 this.PetName = roleInfo.Name;
                 this.objModel.transform.SetParent(this.roleRoot, false);
                 this.objModel.tag = this.GetTag();
                 animator          = objModel.GetComponent <Animator>();
                 this.LocalPetAccessoryAgent.LoadData();
             }
         }
         else
         {
             this.AssetBundleUtils.LoadAssetAsync(roleInfo.AB, roleInfo.ModelPath, (gameObject) =>
             {
                 if (gameObject != null)
                 {
                     this.PetName = roleInfo.Name;
                     gameObject.SetActive(true);
                     gameObject.AddComponent <FixShader>();
                     this.objModel = gameObject;
                     this.objModel.transform.SetParent(this.roleRoot, false);
                     this.objModel.tag = this.GetTag();
                     animator          = objModel.GetComponent <Animator>();
                     this.LocalPetAccessoryAgent.LoadData();
                 }
                 else
                 {
                     this.StopAllCoroutines();
                     this.StartCoroutine(this.CircleInspect(roleInfo));
                 }
             },
                                                  (errorText) =>
             {
                 this.StopAllCoroutines();
                 this.StartCoroutine(this.CircleInspect(roleInfo));
                 Debug.LogErrorFormat("<><PetPlayer.LoadPrefab>Error: {0}", errorText);
             });
         }
     }
 }
Exemplo n.º 3
0
 protected virtual void LoadPrefab(string prefabPath)
 {
     if (this.modelPath != prefabPath || objModel == null)
     {
         DestoryModel();
         this.modelPath = prefabPath;
         this.objModel  = PrefabRoot.GetGameObject("Role", this.modelPath);
         if (this.objModel != null)
         {
             this.objModel.transform.SetParent(this.roleRoot, false);
             this.objModel.tag = this.GetTag();
             animator          = objModel.GetComponent <Animator>();
             this.LocalPetAccessoryAgent.LoadData();
         }
     }
 }
Exemplo n.º 4
0
            public static GameObject GetPrefabRoot(GameObject gameObject)
            {
                if (gameObject != null)
                {
                    PrefabRoot root = gameObject.GetComponent <PrefabRoot>();

                    if (root == null)
                    {
                        root = GameObjectUtils.GetComponentInParents <PrefabRoot>(gameObject, true);
                    }

                    if (root != null)
                    {
                        return(root.gameObject);
                    }
                    else
                    {
                        throw new Exception("No PrefabRoot root component found in prefab - did you forget to add one?");
                    }
                }

                return(null);
            }