public static void OnGUI(UnityEngine.Object targetObject) { EditorGUI.BeginChangeCheck(); SerializedObject serializedObject = new SerializedObject(targetObject); serializedObject.Update(); FieldInfo[] fields; if (!fieldsLookup.TryGetValue(targetObject.GetType(), out fields)) { fields = targetObject.GetPublicFields().OrderBy(field => field.MetadataToken).ToArray(); fieldsLookup.Add(targetObject.GetType(), fields); } if (PreferencesEditor.GetBool(Preference.ShowActionTooltips) && !string.IsNullOrEmpty(targetObject.GetTooltip())) { GUILayout.BeginVertical((GUIStyle)"hostview"); GUILayout.Label(targetObject.GetTooltip(), FsmEditorStyles.wrappedLabelLeft); GUILayout.EndVertical(); } for (int i = 0; i < fields.Length; i++) { FieldInfo field = fields[i]; if (field.HasAttribute(typeof(HideInInspector))) { continue; } PropertyDrawer drawer = GUIDrawer.GetDrawer(field); GUIContent content = field.GetInspectorGUIContent(); SerializedProperty property = serializedObject.FindProperty(field.Name); if (PreferencesEditor.GetBool(Preference.ShowVariableTooltips) && !string.IsNullOrEmpty(field.GetTooltip())) { GUILayout.BeginVertical("box"); GUILayout.Label(field.GetTooltip(), FsmEditorStyles.wrappedLabelLeft); GUILayout.EndVertical(); } if (drawer != null) { drawer.fieldInfo = field; drawer.OnGUI(property, content); } else { int indentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = typeof(IList).IsAssignableFrom(field.FieldType)?indentLevel + 1:indentLevel; EditorGUILayout.PropertyField(property, content, true); EditorGUI.indentLevel = indentLevel; } } if (EditorGUI.EndChangeCheck()) { serializedObject.ApplyModifiedProperties(); ErrorChecker.CheckForErrors(); } }
private void OnConditionElement(int index, bool selected) { Condition condition = transition.Conditions [index]; bool enabled = condition.IsEnabled; condition.IsOpen = GUIDrawer.ObjectTitlebar(condition, condition.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(condition, node)); condition.IsEnabled = enabled; if (condition.IsOpen) { GUIDrawer.OnGUI(condition); } }
private void OnActionElement(int index, bool selected) { StateAction action = actions [index]; bool enabled = action.IsEnabled; action.IsOpen = GUIDrawer.ObjectTitlebar(action, action.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(action, state)); action.IsEnabled = enabled; if (action.IsOpen) { GUIDrawer.OnGUI(action); } }
protected virtual void OnPreviewGUI(ExecutableNode node) { GUIStyle style = new GUIStyle("IN BigTitle"); style.padding.top = 0; GUILayout.BeginVertical(style); GUILayout.BeginHorizontal(); GUILayout.Label(node.name, EditorStyles.boldLabel); GUILayout.FlexibleSpace(); GUIStyle labelStyle = new GUIStyle("label"); labelStyle.contentOffset = new Vector2(0, 5); if (!string.IsNullOrEmpty(node.GetHelpUrl()) && GUILayout.Button(FsmEditorStyles.helpIcon, labelStyle, GUILayout.Width(20))) { Application.OpenURL(node.GetHelpUrl()); } GUILayout.EndHorizontal(); GUILayout.Space(3f); GUILayout.Label(node.GetTooltip(), FsmEditorStyles.wrappedLabel); GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); Node selectedNode = FsmEditor.SelectionCount > 0? FsmEditor.SelectedNodes [0]:null; if (GUILayout.Button(selectedNode != null? "Add to state" : "Select one state to add") && selectedNode != null) { OnAddNode(selectedNode, node.GetType()); NodeInspector.Dirty(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); if (PreferencesEditor.GetBool(Preference.ActionBrowserShowPreview, true)) { EditorGUI.BeginDisabledGroup(true); GUIDrawer.OnGUI(node); EditorGUI.EndDisabledGroup(); GUILayout.Space(5); } }
private void ResetActionList() { SerializedObject obj = new SerializedObject(state); SerializedProperty elements = obj.FindProperty("actions"); actionList = new ReorderableObjectList(obj, elements); actionList.drawHeaderCallback = delegate(Rect rect) { EditorGUI.LabelField(rect, "Actions"); }; actionList.onAddCallback = delegate(ReorderableObjectList list) { FsmGUIUtility.SubclassMenu <StateAction> (delegate(Type type){ StateAction action = (StateAction)ScriptableObject.CreateInstance(type); action.name = type.GetCategory() + "." + type.Name; action.hideFlags = HideFlags.HideInHierarchy; state.Actions = ArrayUtility.Add <StateAction> (state.Actions, action); if (EditorUtility.IsPersistent(state)) { AssetDatabase.AddObjectToAsset(action, state); AssetDatabase.SaveAssets(); } list.index = list.count; EditorUtility.SetDirty(state); }); }; actionList.drawElementCallback = delegate(int index, bool selected) { StateAction action = state.Actions [index]; bool enabled = action.IsEnabled; if (selected) { GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead") { stretchHeight = false, }; selectBackground.overflow = new RectOffset(-1, -2, -2, 2); GUILayout.BeginVertical(selectBackground); } action.IsOpen = GUIDrawer.ObjectTitlebar(action, action.IsOpen, ref enabled, FsmGUIUtility.ExecutableContextMenu(action, state)); if (selected) { GUILayout.EndVertical(); } action.IsEnabled = enabled; if (action.IsOpen) { GUIDrawer.OnGUI(action); } }; actionList.onRemoveCallback = delegate(ReorderableObjectList list) { StateAction action = state.Actions[list.index]; state.Actions = ArrayUtility.Remove <StateAction> (state.Actions, action); FsmEditorUtility.DestroyImmediate(action); list.index = list.index - 1; ErrorChecker.CheckForErrors(); EditorUtility.SetDirty(state); }; actionList.onContextClick = delegate(int index) { FsmGUIUtility.ExecutableContextMenu(state.Actions [index], state).ShowAsContext(); }; actionList.onHeaderContextClick = delegate() { GenericMenu menu = new GenericMenu(); if (state.Actions.Length > 0) { menu.AddItem(new GUIContent("Copy"), false, delegate { copy = new List <StateAction>(state.Actions); copyState = state; }); } else { menu.AddDisabledItem(new GUIContent("Copy")); } if (copy == null) { copy = new List <StateAction>(); } copy.RemoveAll(x => x == null); if (copy.Count > 0) { menu.AddItem(new GUIContent("Paste After"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); menu.AddItem(new GUIContent("Paste Before"), false, delegate() { for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Insert <StateAction>(state.Actions, (StateAction)dest, 0); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); if (copyState != state) { menu.AddItem(new GUIContent("Replace"), false, delegate() { for (int i = 0; i < state.Actions.Length; i++) { FsmEditorUtility.DestroyImmediate(state.Actions[i]); } state.Actions = new StateAction[0]; ResetActionList(); for (int i = 0; i < copy.Count; i++) { ExecutableNode dest = FsmUtility.Copy(copy[i]); state.Actions = ArrayUtility.Add <StateAction>(state.Actions, (StateAction)dest); FsmEditorUtility.ParentChilds(state); EditorUtility.SetDirty(state); // NodeInspector.Dirty(); ErrorChecker.CheckForErrors(); } }); } else { menu.AddDisabledItem(new GUIContent("Replace")); } } else { menu.AddDisabledItem(new GUIContent("Paste After")); menu.AddDisabledItem(new GUIContent("Paste Before")); menu.AddDisabledItem(new GUIContent("Replace")); } menu.ShowAsContext(); }; this.host.Repaint(); if (FsmEditor.instance != null) { FsmEditor.instance.Repaint(); } }