private void OnEnable() { minSize = new Vector2(800f, 290f); if (model == null) { model = ScriptableObject.CreateInstance <MB_ReplacePrefabsSettings>(); // Set the Hide flags so that this windows data not destroyed when entering playmode or a new scene. model.hideFlags = HideFlags.DontSave; } InitModel(); }
private void OnGUI() { EditorGUILayout.BeginHorizontal(); MB_ReplacePrefabsSettings newModel = (MB_ReplacePrefabsSettings)EditorGUILayout.ObjectField("Settings", model, typeof(MB_ReplacePrefabsSettings), false); if (newModel != model) { if (newModel != null) { model = newModel; } else { if (model == null) { model = ScriptableObject.CreateInstance <MB_ReplacePrefabsSettings>(); } // Set the Hide flags so that this windows data not destroyed when entering playmode or a new scene. model.hideFlags = HideFlags.DontSave; } InitModel(); } if (model != null) { if (GUILayout.Button("Save Settings", GUILayout.Width(200))) { string path = EditorUtility.SaveFilePanel("Save Settings", Application.dataPath, "ReplacePrefabSettings", "asset"); if (path != null) { model.hideFlags = HideFlags.None; string relativepath = "Assets" + path.Substring(Application.dataPath.Length); Debug.Log("Saved: " + relativepath); AssetDatabase.CreateAsset(model, relativepath); } } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); soModel.Update(); if (GUILayout.Button(GUI_replacePefabsInScene)) { if (EditorUtility.DisplayDialog("Replace Prefabs In Scene", "Are you sure you want to replace all source prefab instances with the target prefab instances in this scene? \n\n" + "It is highly recommended that you back up your scene before doing this.", "OK", "Cancel")) { ReplacePrefabsInScene(); } } float labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 300f; EditorGUILayout.PropertyField(reverseSrcAndTarg, GUI_switchSrcAndTarget); EditorGUILayout.PropertyField(enforceSrcAndTargHaveSameStructure, GUI_enforceSrcAndTargetHaveSameStructure); EditorGUIUtility.labelWidth = labelWidth; if (infoMessages != "" || errorMessages != "") { EditorGUILayout.HelpBox(errorMessages + "\n" + infoMessages, errorMessages == "" ? MessageType.Info : MessageType.Error); } scrollViewPos = EditorGUILayout.BeginScrollView(scrollViewPos); EditorGUILayout.PropertyField(prefabPairs, true); EditorGUILayout.EndScrollView(); soModel.ApplyModifiedProperties(); }