示例#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;
        }
示例#2
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;
            }
        }
示例#3
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;
        }