protected override void OnEnable() { base.OnEnable(); var prefabScripts = this.targets.OfType<GameObject>().Select(t => t.GetComponent<PEPrefabScript>()).Where(t => t != null).ToArray(); if (prefabScripts.Any()) exposedPropertiesEditor = new PEExposedPropertiesEditor(prefabScripts); }
static public void OnRemove(PEExposedPropertiesEditor editor, int propertyId) { editor.targets.Foreach(t => t.Properties.Remove(propertyId)); editor.Build(true); Event.current.Use(); Resources.FindObjectsOfTypeAll <Editor>()[0].Repaint(); GUIUtility.ExitGUI(); }
protected override void OnEnable() { base.OnEnable(); var prefabScripts = this.targets.OfType <GameObject>().Select(t => t.GetComponent <PEPrefabScript>()).Where(t => t != null).ToArray(); if (prefabScripts.Any()) { exposedPropertiesEditor = new PEExposedPropertiesEditor(prefabScripts); } }
static public void OnAdd(PEExposedPropertiesEditor editor, int parentId = 0) { var lr = GUILayoutUtility.GetLastRect(); if (lr.min == Vector2.zero) { lr.center = Event.current.mousePosition; } lr.center = GUIUtility.GUIToScreenPoint(lr.center); var menu = new GenericMenu(); menu.AddItem(new GUIContent("Property"), false, () => { PEPropertyPickerWindow.OnPropertyPickerDelegate onChanged = property => { var newProperty = new ExposedProperty(); newProperty.Label = property.GetDisplayName(); newProperty.PropertyPath = property.propertyPath; newProperty.Target = property.serializedObject.targetObject; newProperty.ParentId = parentId; editor.targets[0].Properties.Add(newProperty); newProperty.Order = editor.targets[0].Properties.OrderedItems.Any() ? editor.targets[0].Properties.OrderedItems.Max(i => i.Order + 10) : 0; editor.Build(true); Event.current.Use(); Resources.FindObjectsOfTypeAll <Editor>()[0].Repaint(); GUIUtility.ExitGUI(); }; EditorApplication.delayCall += () => PEPropertyPickerWindow.Show(editor.targets[0].gameObject, onChanged, lr); }); menu.AddItem(new GUIContent("Group"), false, () => EditorApplication.delayCall += () => { editor.targets[0].Properties.Add(new ExposedPropertyGroup { Label = "Property Group", ParentId = parentId, Order = editor.targets[0].Properties.OrderedItems.Any() ? editor.targets[0].Properties.OrderedItems.Max(i => i.Order + 10) : 0 }); editor.Build(true); }); menu.ShowAsContext(); }
public void Draw() { IsDrawing = true; current = this; var rect = EditorGUILayout.GetControlRect(); if (editMode) { var r = new Rect(rect); r.x += r.width - 33; r.width = r.height = 16; if (GUI.Button(r, PEResources.addIcon, PEUtils.emptyStyle)) { OnAdd(this); } } DrawLock(rect); Expanded = EditorGUI.Foldout(rect, Expanded, "Prefab Properties", false); if (Expanded) { EditorGUI.indentLevel++; rootDrawers.ForEach(d => d.Draw()); EditorGUI.indentLevel--; } if (needRepaint) { needRepaint = false; Event.current.Use(); } if (needRebuild && Event.current.type == EventType.Repaint) { needRebuild = false; this.Build(true); } IsDrawing = false; }
static public void OnEdit(PEExposedPropertiesEditor editor, ItemDrawer propertyToEdit) { var lr = GUILayoutUtility.GetLastRect(); if (lr.min == Vector2.zero) { lr.center = Event.current.mousePosition; } var p = propertyToEdit.ExposedData.First() as ExposedProperty; lr.center = GUIUtility.GUIToScreenPoint(lr.center); PEPropertyPickerWindow.OnPropertyPickerDelegate onChanged = property => { var newProperty = p; newProperty.Label = property.GetDisplayName(); newProperty.PropertyPath = property.propertyPath; newProperty.Target = property.serializedObject.targetObject; editor.Build(true); }; EditorApplication.delayCall += () => PEPropertyPickerWindow.Show(editor.targets[0].gameObject, onChanged, lr, null, propertyToEdit.Property); }
static public void OnEdit(PEExposedPropertiesEditor editor, ItemDrawer propertyToEdit) { var lr = GUILayoutUtility.GetLastRect(); if (lr.min == Vector2.zero) lr.center = Event.current.mousePosition; var p = propertyToEdit.ExposedData.First() as ExposedProperty; lr.center = GUIUtility.GUIToScreenPoint(lr.center); PEPropertyPickerWindow.OnPropertyPickerDelegate onChanged = property => { var newProperty = p; newProperty.Label = property.GetDisplayName(); newProperty.PropertyPath = property.propertyPath; newProperty.Target = property.serializedObject.targetObject; editor.Build(true); }; EditorApplication.delayCall += () => PEPropertyPickerWindow.Show(editor.targets[0].gameObject, onChanged, lr, null, propertyToEdit.Property); }
static public void OnAdd(PEExposedPropertiesEditor editor, int parentId = 0) { var lr = GUILayoutUtility.GetLastRect(); if (lr.min == Vector2.zero) lr.center = Event.current.mousePosition; lr.center = GUIUtility.GUIToScreenPoint(lr.center); var menu = new GenericMenu(); menu.AddItem(new GUIContent("Property"), false, () => { PEPropertyPickerWindow.OnPropertyPickerDelegate onChanged = property => { var newProperty = new ExposedProperty(); newProperty.Label = property.GetDisplayName(); newProperty.PropertyPath = property.propertyPath; newProperty.Target = property.serializedObject.targetObject; newProperty.ParentId = parentId; editor.targets[0].Properties.Add(newProperty); newProperty.Order = editor.targets[0].Properties.OrderedItems.Any() ? editor.targets[0].Properties.OrderedItems.Max(i => i.Order + 10) : 0; editor.Build(true); Event.current.Use(); Resources.FindObjectsOfTypeAll<Editor>()[0].Repaint(); GUIUtility.ExitGUI(); }; EditorApplication.delayCall += () => PEPropertyPickerWindow.Show(editor.targets[0].gameObject, onChanged, lr); }); menu.AddItem(new GUIContent("Group"), false, () => EditorApplication.delayCall += () => { editor.targets[0].Properties.Add(new ExposedPropertyGroup { Label = "Property Group", ParentId = parentId, Order = editor.targets[0].Properties.OrderedItems.Any() ? editor.targets[0].Properties.OrderedItems.Max(i => i.Order + 10) : 0 }); editor.Build(true); }); menu.ShowAsContext(); }
static public void OnRemove(PEExposedPropertiesEditor editor, int propertyId) { editor.targets.Foreach(t => t.Properties.Remove(propertyId)); editor.Build(true); Event.current.Use(); Resources.FindObjectsOfTypeAll<Editor>()[0].Repaint(); GUIUtility.ExitGUI(); }
public void Draw() { current = this; var rect = EditorGUILayout.GetControlRect(); if (editMode) { var r = new Rect(rect); r.x += r.width - 33; r.width = r.height = 16; if (GUI.Button(r, PEResources.addIcon, PEUtils.emptyStyle)) OnAdd(this); } DrawLock(rect); Expanded = EditorGUI.Foldout(rect, Expanded, "Prefab Properties", false); if (Expanded) { EditorGUI.indentLevel++; rootDrawers.ForEach(d => d.Draw()); EditorGUI.indentLevel--; } if (needRepaint) { needRepaint = false; Event.current.Use(); } if (needRebuild) { needRebuild = false; this.Build(true); } }
void DrawEdit(Rect rect) { var exposedProperty = ExposedData.First() as ExposedProperty; if (exposedProperty != null) { if (!exposedProperty.IsValid) { EditorGUI.DrawRect(rect, new Color(1, 0, 0, 0.3f)); } } UpdateDrag(rect); var guiEnabled = GUI.enabled; if (this.Inherited) { GUI.enabled = false; } var label = ExposedData.First().Label; var labelRect = new Rect(rect) { x = rect.x - 1, width = rect.width - 48 }; EditorGUI.BeginChangeCheck(); label = EditorGUI.TextField(labelRect, label); if (EditorGUI.EndChangeCheck()) { this.Label.text = label; this.ExposedData.Foreach(d => d.Label = label); } labelRect.x += labelRect.width; labelRect.width = 16; GUI.tooltip = "Remove"; if (GUI.Button(labelRect, PEResources.removeIcon, PEUtils.emptyStyle)) { PEExposedPropertiesEditor.OnRemove(PEExposedPropertiesEditor.current, this.Id); } labelRect.x += labelRect.width; if (!IsGroup) { GUI.tooltip = "Edit"; if (GUI.Button(labelRect, PEResources.editIcon, PEUtils.emptyStyle)) { PEExposedPropertiesEditor.OnEdit(PEExposedPropertiesEditor.current, this); } } GUI.enabled = guiEnabled; if (IsGroup) { GUI.tooltip = "Add"; if (GUI.Button(labelRect, PEResources.addIcon, PEUtils.emptyStyle)) { PEExposedPropertiesEditor.OnAdd(PEExposedPropertiesEditor.current, this.Id); } } labelRect.x += labelRect.width + 4; if (this.Inherited) { var lw = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0; labelRect.y -= 1; GUI.tooltip = "Visible"; var result = !GUI.Toggle(labelRect, !this.ExposedData.First().Hidden, "Show"); if (result != this.ExposedData.First().Hidden) { this.ExposedData.First().Hidden = result; EditorApplication.delayCall += PEExposedPropertiesEditor.current.Build; } EditorGUIUtility.labelWidth = lw; } DrawHighlight(rect); }
private static void OnPropertyContextMenu(GenericMenu menu, SerializedProperty property) { var component = property.serializedObject.targetObject as Component; var gameObject = property.serializedObject.targetObject as GameObject; GameObject targetGameObject = null; if (component != null) { targetGameObject = component.gameObject; } if (gameObject != null) { targetGameObject = gameObject; } if (targetGameObject == null) { return; } var prefabRoot = PEUtils.FindRootPrefab(targetGameObject); if (prefabRoot == null) { return; } var prefabScript = prefabRoot.GetComponent <PEPrefabScript>(); if (prefabScript == null) { return; } if (!PEExposedPropertiesEditor.CanEditProperties(new[] { prefabScript })) { return; } var exposed = prefabScript.Properties.HasProperty(property.serializedObject.targetObject, property.propertyPath); property = property.Copy(); menu.AddItem(new GUIContent("Expose Property"), exposed, () => { if (!exposed) { prefabScript.Properties.Add(new ExposedProperty() { Label = property.displayName, PropertyPath = property.propertyPath, Target = property.serializedObject.targetObject }); PEExposedPropertiesEditor.current.needRebuild = true; EditorUtility.SetDirty(prefabScript); } else { prefabScript.Properties.Remove(property.serializedObject.targetObject, property.propertyPath); PEExposedPropertiesEditor.current.needRebuild = true; EditorUtility.SetDirty(prefabScript); } }); }