void OnPrefabChange(GameObject newPrefab) { DestroyPreview(); if (newPrefab == null) { return; } PrefabPainterPrefab p = newPrefab.GetComponent <PrefabPainterPrefab>(); if (p != null) { painterValues = new PrefabPainterPrefabValues(p.painterValues); } preview = CreateNewPreview(newPrefab); UpdatePreviewRandom(); }
void OnGUI() { GUITools.Space(3); bool changedPrefab = DrawPrefabSelect(); if (changedPrefab) { change = true; return; } GameObject prefab = GetPrefab(); if (change) { change = false; OnPrefabChange(prefab); } DrawOffsetOptions(); if (GUILayout.Button("Save Offset Options")) { if (prefab != null) { if (AssetDatabase.Contains(prefab)) { using (var scope = new EditPrefab(prefab)) { PrefabPainterPrefab p = scope.root.GetComponent <PrefabPainterPrefab>(); if (p == null) { p = scope.root.AddComponent <PrefabPainterPrefab>(); } p.painterValues = new PrefabPainterPrefabValues(painterValues); } } } } if (drawMode == DrawMode.Field) { density = EditorGUILayout.Slider("Density", density, 0, 1); frequency = EditorGUILayout.Slider("Frequency", frequency, .25f, radius); } else if (drawMode == DrawMode.RandomArea) { amount = EditorGUILayout.IntField("Draw Amount", amount); } EditorGUILayout.Space(); EditorGUILayout.Space(); if (GUITools.Button(new GUIContent((drawing ? "Exit " : "") + "Draw Mode"), drawing ? GUITools.red : GUITools.white, GUITools.button, GUITools.black)) { drawing = !drawing; } if (prefab != null) { if (previewEditor == null) { previewEditor = UnityEditor.Editor.CreateEditor(prefab); } previewEditor.OnPreviewGUI(GUILayoutUtility.GetRect(position.width, 200), EditorStyles.helpBox); } }