Beispiel #1
0
 public void OnDestroy()
 {
     if (Application.isEditor && PrefabStageUtility.GetCurrentPrefabStage() != null)
     {
         if (persistentObject == null)
         {
             PersistenceController.UnregisterPrefab(persistentObject);
         }
     }
 }
        void Start()
        {
            // Created from a prefab
            if (_isPrefab && Application.isPlaying)
            {
                if (_uidSet == false)
                {
                    Debug.Log($"SETTING NEW ID FOR {gameObject.name}");
                    _persistenceUid  = PersistentUid.NewUid();
                    _isPrefab        = false;
                    _linkedPrefabUid = _prefabUid;
                }
            }

            PersistenceController.RegisterPersistentObject(Uid, this);
        }
Beispiel #3
0
        private void UpdatePrefabMap()
        {
            string [] guids = AssetDatabase.FindAssets("t:prefab");

            PersistentObject[]      allFoundScripts = Resources.FindObjectsOfTypeAll <PersistentObject>();
            List <PersistentObject> prefabs         = new List <PersistentObject>();

            foreach (string guid in guids)
            {
                string           path         = AssetDatabase.GUIDToAssetPath(guid);
                PersistentObject persisnteObj = AssetDatabase.LoadAssetAtPath(path, typeof(PersistentObject)) as PersistentObject;
                if (persisnteObj == null)
                {
                    continue;
                }

                if (persisnteObj.IsPrefab)
                {
                    prefabs.Add(persisnteObj);
                }
            }

            PersistenceController.OverridePrefabs(prefabs);
        }
 void OnDestroy()
 {
     PersistenceController.UnregisterPersistentObject(Uid);
 }
Beispiel #5
0
        public override void OnInspectorGUI()
        {
            GUILayout.Label($"Prefab status: {PrefabUtility.GetPrefabInstanceStatus(persistentObject)}");

            EditorGUI.BeginChangeCheck();

            if (isPrefab && prevPrefab == null)
            {
                prevPrefab = GetPrefab();

                if (prevPrefab)
                {
                    PersistenceController.RegisterPrefab(prevPrefab);
                }
            }

            EditorGUILayout.PropertyField(isPrefabProp);

            if (EditorGUI.EndChangeCheck())
            {
                isPrefab = isPrefabProp.boolValue;
                if (isPrefab)
                {
                    PersistentObject prefab = GetPrefab();

                    if (prefab != null)
                    {
                        PersistenceController.RegisterPrefab(prefab);

                        prevPrefab = prefab;
                    }

                    if (prefabUidIdProp.stringValue == "")
                    {
                        prefabUidIdProp.stringValue = PersistentUid.NewUid().Value;
                    }
                }
                else
                {
                    if (prevPrefab)
                    {
                        PersistenceController.UnregisterPrefab(prevPrefab);
                    }

                    if (persistenceUidIdProp.stringValue == "")
                    {
                        persistenceUidIdProp.stringValue = PersistentUid.NewUid().Value;
                    }
                }
            }

            if (isPrefab && prevPrefab == null)
            {
                EditorGUILayout.HelpBox("Is Prefab property was set to true, but no corresponding prefab was found", MessageType.Warning);
            }

            if (isPrefab)
            {
                EditorGUILayout.PropertyField(prefabUidProp);
            }
            else
            {
                EditorGUILayout.PropertyField(persistenceUidProp);

                if (linkedPrefabUidIdProp.stringValue != "")
                {
                    EditorGUILayout.PropertyField(linkedPrefabUidProp);
                }
            }

            EditorGUILayout.PropertyField(componentsToSerializeProp, true);

            serializedObject.ApplyModifiedProperties();

            if (GUILayout.Button("Update prefab map"))
            {
                UpdatePrefabMap();
            }
        }