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); }
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(); } }