public void OnDestroy() { if (Application.isEditor && PrefabStageUtility.GetCurrentPrefabStage() != null) { if (persistentObject == null) { PersistenceController.UnregisterPrefab(persistentObject); } } }
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(); } }