Exemplo n.º 1
0
        public void GeneratePrefabReferences()
        {
            if (this.gameObject.scene.name != null)
            {
                return;
            }

            // Create a new reference list so that any objects which are no longer dependencies are removed.
            var tempLocalRefs = new ES3RefIdDictionary();

            // Add the GameObject's dependencies to the reference list.
            foreach (var obj in ES3ReferenceMgr.CollectDependencies(this.gameObject))
            {
                var dependency = (UnityEngine.Object)obj;
                if (obj == null || !ES3ReferenceMgr.CanBeSaved(dependency))
                {
                    continue;
                }

                var id = Get(dependency);
                // If we're adding a new reference, do an Undo.RecordObject to ensure it persists.
                if (id == -1)
                {
                    Undo.RecordObject(this, "Update Easy Save 3 Prefab");
                    EditorUtility.SetDirty(this);
                }
                tempLocalRefs.Add(dependency, id == -1 ? GetNewRefID() : id);
            }

            localRefs = tempLocalRefs;
        }
Exemplo n.º 2
0
        public void GeneratePrefabReferences()
        {
                        #if UNITY_2018_3_OR_NEWER
            var prefabType = PrefabUtility.GetPrefabInstanceStatus(this.gameObject);
            if (prefabType != PrefabInstanceStatus.NotAPrefab && prefabType != PrefabInstanceStatus.MissingAsset)
            {
                return;
            }
                        #else
            var prefabType = PrefabUtility.GetPrefabType(this.gameObject);
            if (prefabType != PrefabType.Prefab && prefabType != PrefabType.MissingPrefabInstance)
            {
                return;
            }
                        #endif


            // Get GameObject and it's children and add them to the reference list.
            foreach (var obj in EditorUtility.CollectDependencies(new UnityEngine.Object[] { this }))
            {
                if (obj == null || !ES3ReferenceMgr.CanBeSaved(obj))
                {
                    continue;
                }

                if (this.Get(obj) == -1)
                {
                    Undo.RecordObject(this, "Update Easy Save 3 Prefab");
                    EditorUtility.SetDirty(this);
                    Add(obj);
                }
            }
        }
 static void AddGameObjectsAndComponentsToManager()
 {
     if (refMgr != null)
     {
         foreach (var obj in EditorUtility.CollectDeepHierarchy(SceneManager.GetActiveScene().GetRootGameObjects()))
         {
             // If this object can be saved, add it to the reference manager.
             if (ES3ReferenceMgr.CanBeSaved(obj))
             {
                 refMgr.Add(obj);
             }
         }
         refMgr.AddPrefabsToManager();
     }
 }
Exemplo n.º 4
0
        public void GeneratePrefabReferences()
        {
#if UNITY_2018_3_OR_NEWER
            if (this.gameObject.scene.name != null || UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage() != null)
#else
            if (this.gameObject.scene.name != null)
#endif
            { return; }

            // Create a new reference list so that any objects which are no longer dependencies are removed.
            var tempLocalRefs = new ES3RefIdDictionary();

            // Get dependencies of children also.
            var transforms = GetComponentsInChildren <Transform>();
            var gos        = new GameObject[transforms.Length];
            for (int i = 0; i < transforms.Length; i++)
            {
                gos[i] = transforms[i].gameObject;
            }

            bool addedNewReference = false;

            // Add the GameObject's dependencies to the reference list.
            foreach (var obj in ES3ReferenceMgr.CollectDependencies(gos))
            {
                var dependency = (UnityEngine.Object)obj;
                if (obj == null || !ES3ReferenceMgr.CanBeSaved(dependency))
                {
                    continue;
                }

                var id = Get(dependency);
                // If we're adding a new reference, do an Undo.RecordObject to ensure it persists.
                if (id == -1)
                {
                    addedNewReference = true;
                    Undo.RecordObject(this, "Update Easy Save 3 Prefab");
                    EditorUtility.SetDirty(this);
                }
                tempLocalRefs.Add(dependency, id == -1 ? GetNewRefID() : id);
            }

            if (addedNewReference || tempLocalRefs.Count != localRefs.Count)
            {
                localRefs = tempLocalRefs;
            }
        }
Exemplo n.º 5
0
        public long Add(UnityEngine.Object obj)
        {
            long id;

            if (localRefs.TryGetValue(obj, out id))
            {
                return(id);
            }

            if (!ES3ReferenceMgr.CanBeSaved(obj))
            {
                return(-1);
            }
            id = GetNewRefID();
            localRefs.Add(obj, id);
            return(id);
        }
Exemplo n.º 6
0
        public long GetOrAdd(UnityEngine.Object obj)
        {
            if (Application.isPlaying)
            {
                ES3Debug.LogError("GetOrAdd can only be called in the Editor, not during runtime");
                return(-1);
            }

            var id = Get(obj);

            if (id == -1 && UnityEditor.AssetDatabase.Contains(obj) && ES3ReferenceMgr.CanBeSaved(obj))
            {
                id = ES3ReferenceMgrBase.GetNewRefID();
                refId.Add(obj, id);

                UnityEditor.EditorUtility.SetDirty(this);
            }

            return(id);
        }
Exemplo n.º 7
0
 static UndoPropertyModification[] PostProcessModifications(UndoPropertyModification[] modifications)
 {
     if (refMgr != null)
     {
         // For each property which has had an Undo registered ...
         foreach (var mod in modifications)
         {
             // If this property change is an object reference, and the Component this change has been made to is in the scene, not in Assets ...
             if (mod.currentValue != null && mod.currentValue.objectReference != null && mod.currentValue.target != null && !AssetDatabase.Contains(mod.currentValue.target))
             {
                 // If this object reference can be saved ...
                 if (ES3ReferenceMgr.CanBeSaved(mod.currentValue.objectReference))
                 {
                     // Add it to the reference manager
                     refMgr.Add(mod.currentValue.objectReference);
                 }
             }
         }
     }
     return(modifications);
 }
Exemplo n.º 8
0
        public void GeneratePrefabReferences()
        {
                        #if UNITY_2018_3_OR_NEWER
            var prefabType = PrefabUtility.GetPrefabInstanceStatus(this.gameObject);
            if (prefabType != PrefabInstanceStatus.NotAPrefab && prefabType != PrefabInstanceStatus.MissingAsset)
            {
                return;
            }
#else
            var prefabType = PrefabUtility.GetPrefabType(this.gameObject);
            if (prefabType != PrefabType.Prefab && prefabType != PrefabType.MissingPrefabInstance)
            {
                return;
            }
#endif
            // Create a new reference list so that any objects which are no longer dependencies are removed.
            var tempLocalRefs = new ES3RefIdDictionary();

            // Add the GameObject's dependencies to the reference list.
            foreach (var obj in ES3ReferenceMgr.CollectDependencies(this.gameObject))
            {
                var dependency = (UnityEngine.Object)obj;
                if (obj == null || !ES3ReferenceMgr.CanBeSaved(dependency))
                {
                    continue;
                }

                var id = Get(dependency);
                // If we're adding a new reference, do an Undo.RecordObject to ensure it persists.
                if (id == -1)
                {
                    Undo.RecordObject(this, "Update Easy Save 3 Prefab");
                    EditorUtility.SetDirty(this);
                }
                tempLocalRefs.Add(dependency, id == -1 ? GetNewRefID() : id);
            }

            localRefs = tempLocalRefs;
        }
Exemplo n.º 9
0
        public long GetOrAdd(UnityEngine.Object obj)
        {
            var id = Get(obj);

            // Only add items to global references when it's not playing.
            if (!Application.isPlaying && id == -1 && UnityEditor.AssetDatabase.Contains(obj) && ES3ReferenceMgr.CanBeSaved(obj))
            {
                id = ES3ReferenceMgrBase.GetNewRefID();
                refId.Add(obj, id);

                UnityEditor.EditorUtility.SetDirty(this);
            }

            return(id);
        }