예제 #1
0
        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();
            }
        }
예제 #2
0
        protected override void OnAddNode(Node node, Type type)
        {
            if (!typeof(State).IsAssignableFrom(node.GetType()))
            {
                EditorUtility.DisplayDialog("Could not add node " + type.Name + "!", "You can only add actions to a state.", "Cancel");
                return;
            }

            State       state  = node as State;
            StateAction action = (StateAction)ScriptableObject.CreateInstance(type);

            action.hideFlags = HideFlags.HideInHierarchy;
            action.name      = type.GetCategory() + "." + type.Name;
            state.Actions    = ArrayUtility.Add <StateAction> (state.Actions, action);
            if (EditorUtility.IsPersistent(state))
            {
                AssetDatabase.AddObjectToAsset(action, state);
                AssetDatabase.SaveAssets();
            }

            if (PreferencesEditor.GetBool(Preference.CloseActionBrowserOnAdd, false))
            {
                base.Close();
            }
        }
예제 #3
0
        protected override void OnAddNode(Node node, Type type)
        {
            if (FsmEditor.SelectedTransition == null)
            {
                EditorUtility.DisplayDialog("Could not add node " + type.Name + "!", "Select a transition before you add a condition.", "Cancel");
                return;
            }
            Condition condition = (Condition)ScriptableObject.CreateInstance(type);

            condition.hideFlags = HideFlags.HideInHierarchy;
            condition.name      = type.GetCategory() + "." + type.Name;

            FsmEditor.SelectedTransition.Conditions = ArrayUtility.Add <Condition> (FsmEditor.SelectedTransition.Conditions, condition);

            if (EditorUtility.IsPersistent(FsmEditor.SelectedTransition))
            {
                AssetDatabase.AddObjectToAsset(condition, FsmEditor.SelectedTransition);
                AssetDatabase.SaveAssets();
            }

            if (PreferencesEditor.GetBool(Preference.CloseConditionBrowserOnAdd, false))
            {
                base.Close();
            }
        }
예제 #4
0
        public static bool ToggleBool(Preference preference)
        {
            bool state = PreferencesEditor.GetBool(preference);

            PreferencesEditor.SetBool(preference, !state);
            return(!state);
        }
예제 #5
0
        public void OnGUI()
        {
            lockSelection   = PreferencesEditor.GetBool(Preference.LockSelection);
            showPreferences = PreferencesEditor.GetBool(Preference.ShowPreference);

            GUILayout.BeginHorizontal(EditorStyles.toolbar);
            SelectGameObject();
            SelectStateMachine();

            if (GUILayout.Button("Lock", (lockSelection?(GUIStyle)"TE toolbarbutton" : EditorStyles.toolbarButton), GUILayout.Width(50)))
            {
                lockSelection = !lockSelection;
                PreferencesEditor.SetBool(Preference.LockSelection, lockSelection);
            }

            if (GUILayout.Button("Tools", EditorStyles.toolbarDropDown, GUILayout.Width(50)))
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Welcome Screen"), false, delegate() {
                    WelcomeWindow.ShowWindow();
                });
                menu.AddItem(new GUIContent("Global Variables"), false, delegate() {
                    GlobalVariablesEditor.ShowWindow();
                });
                menu.AddItem(new GUIContent("Action Browser"), false, delegate() {
                    ActionBrowser.ShowWindow();
                });
                menu.AddItem(new GUIContent("Condition Browser"), false, delegate() {
                    ConditionBrowser.ShowWindow();
                });
                menu.AddItem(new GUIContent("Error Console"), false, delegate() {
                    ErrorEditor.ShowWindow();
                });
                menu.AddItem(new GUIContent("Setup Shortcuts"), false, delegate() {
                    SetupShortcutsEditor.ShowWindow();
                });

                menu.AddItem(new GUIContent("Fsm Tool"), false, delegate() {
                    FsmTool.ShowWindow();
                });
                menu.AddItem(new GUIContent("MonoBehaviour Converter"), false, delegate() {
                    MonoBehaviourConverter.ShowWindow();
                });
                menu.AddItem(new GUIContent("Integrations"), false, delegate() {
                    //IntegrationWindow.ShowWindow ();
                });
                menu.ShowAsContext();
            }

            GUILayout.FlexibleSpace();
            if (GUILayout.Button(FsmEditorStyles.popupIcon, (showPreferences?(GUIStyle)"TE toolbarbutton" : EditorStyles.toolbarButton)))
            {
                showPreferences = !showPreferences;
                PreferencesEditor.SetBool(Preference.ShowPreference, showPreferences);
            }


            GUILayout.EndHorizontal();
        }
예제 #6
0
파일: FsmEditor.cs 프로젝트: Alan-Baylis/11
		public static FsmEditor ShowWindow()
		{
			if(PreferencesEditor.GetBool(Preference.ShowWelcomeWindow) && Resources.FindObjectsOfTypeAll<FsmEditor>().Length == 0){
				WelcomeWindow.ShowWindow();
			}
			FsmEditor window = EditorWindow.GetWindow<FsmEditor>("FSM");
			return window;
		}
예제 #7
0
파일: FsmEditor.cs 프로젝트: Alan-Baylis/11
		protected override Rect GetCanvasSize ()
		{
			float variableHeight = Mathf.Clamp(variableEditor.GetEditorHeight (),0,canvasSize.height*0.5f);
			variableEditorRect = new Rect (-EditorStyles.inspectorDefaultMargins.padding.left, canvasSize.height - variableHeight+canvasSize.y, 250, variableHeight);
			fsmSelectionRect = new Rect (variableEditorRect.width-EditorStyles.inspectorDefaultMargins.padding.left-4f,canvasSize.height,canvasSize.width,22f);
			preferencesRect = PreferencesEditor.GetBool(Preference.ShowPreference)?new Rect (canvasSize.width - 202f, 18f, 200f, PreferencesEditor.GetHeight()):new Rect();
			shortcutRect = new Rect (canvasSize.width - 250, 0, 250, canvasSize.height);
			return new Rect(0,17f,position.width,position.height-17f);
		}
예제 #8
0
파일: FsmEditor.cs 프로젝트: Alan-Baylis/11
		public static void SelectGameObject(GameObject gameObject){
			if (FsmEditor.instance == null){ //|| FsmEditor.ActiveGameObject == gameObject) {
				return;			
			}

			if (!PreferencesEditor.GetBool(Preference.LockSelection) && gameObject != null) {
				ICodeBehaviour behaviour = gameObject.GetComponent<ICodeBehaviour> ();
				if(behaviour !=  null && behaviour.stateMachine != null){
					FsmEditor.instance.activeGameObject=behaviour.gameObject;
					FsmEditor.SelectStateMachine(behaviour.stateMachine);
				}	
			}
		}
		private void DoNode (Node node)
		{
			GUIStyle style = FsmEditorStyles.GetNodeStyle (node.color, selection.Contains (node), node.GetType () == typeof(StateMachine));
			string state = string.Empty;
			if (FsmEditor.Active.Owner != null && FsmEditor.Active.Owner.ActiveNode && (node == FsmEditor.Active.Owner.ActiveNode || node == FsmEditor.Active.Owner.AnyState || node == FsmEditor.Active.Owner.ActiveNode.Parent) && EditorApplication.isPlaying) {
				if (!FsmEditor.Active.Owner.IsPaused && !FsmEditor.Active.Owner.IsDisabled) {
					state = "[Active]";
				} else if (FsmEditor.Active.Owner.IsPaused) {
					state = "[Paused]";
				} else if (FsmEditor.Active.Owner.IsDisabled) {
					state = "[Disabled]";
				}

			}

			GUI.Box (node.position, node.Name + state, style);

			if (ErrorChecker.HasErrors (node) && Event.current.type != EventType.Layout) {
				Rect rect = node.position;
				if (node is StateMachine) {
					rect.x += 10;
					rect.y += 6;
				}
				GUI.Label (rect, "", "CN EntryError");
			}

			if (node is State && (node as State).IsSequence) {
				Rect rect = node.position;
				rect.x += 25;
				rect.y += 3;
				GUI.Label (rect, EditorGUIUtility.FindTexture ("d_PlayButtonProfile"));			
			} 

			if (PreferencesEditor.GetBool (Preference.ShowStateDescription)) {
				GUILayout.BeginArea (new Rect (node.position.x, node.position.y + node.position.height, node.position.width, 500));
				GUILayout.Label (node.comment, FsmEditorStyles.wrappedLabel);
				GUILayout.EndArea ();
			}

			if (DisplayProgress (node)) {
				Rect rect = new Rect (node.position.x + 5, node.position.y + 20, debugProgress, 5);

				if (node == FsmEditor.Active.Owner.ActiveNode.Parent) {
					rect.y += 5;
					rect.x += 15;
					rect.width *= 0.8f;
				}
				GUI.Box (rect, "", "MeLivePlayBar");
			}	

		}
예제 #10
0
        protected override void OnGUI()
        {
            mainToolbar.OnGUI();
            EventType eventType = FsmEditorUtility.ReserveEvent(variableEditorRect, fsmSelectionRect, preferencesRect);

            ZoomableArea.Begin(new Rect(0f, 0f, scaledCanvasSize.width, scaledCanvasSize.height + 21), scale, IsDocked);
            Begin();

            shortcutEditor.HandleKeyEvents();
            if (FsmEditor.Active != null)
            {
                DoNodes();
            }
            else
            {
                ZoomableArea.End();
            }
            AcceptDragAndDrop();
            End();

            FsmEditorUtility.ReleaseEvent(eventType);
            PreferencesEditor.DoGUI(preferencesRect);
            shortcutEditor.DoGUI(shortcutRect);
            DoFsmSelection(fsmSelectionRect);
            variableEditor.DoGUI(variableEditorRect);
            if (centerView)
            {
                CenterView();
                centerView = false;
            }
            if (FsmEditor.Active != null)
            {
                GUI.Label(new Rect(5, 20, 300, 200), FsmEditor.Active.comment, FsmEditorStyles.instructionLabel);
            }
            else
            {
                GUI.Label(new Rect(5, 20, 300, 200), "Right click to create a state machine.", FsmEditorStyles.instructionLabel);
            }
            Event ev = Event.current;

            if (SelectedNodes.Count == 1 && ev.rawType == EventType.KeyDown && ev.keyCode == KeyCode.Delete && FsmEditor.SelectedTransition != null && EditorUtility.DisplayDialog("Delete selected transition?", FsmEditor.SelectedTransition.FromNode.Name + " -> " + FsmEditor.SelectedTransition.ToNode.Name + "\r\n\r\nYou cannot undo this action.", "Delete", "Cancel"))
            {
                Node node = SelectedTransition.FromNode;
                node.Transitions = ArrayUtility.Remove(node.Transitions, FsmEditor.SelectedTransition);
                FsmEditorUtility.DestroyImmediate(FsmEditor.SelectedTransition);
                ErrorChecker.CheckForErrors();
                EditorUtility.SetDirty(node);
            }
        }
예제 #11
0
 public void DoGUI(Rect position)
 {
     if (PreferencesEditor.GetBool(Preference.ShowShortcuts))
     {
         GUILayout.BeginArea(position);
         GUILayout.FlexibleSpace();
         GUILayout.BeginVertical((GUIStyle)"U2D.createRect");
         ShortcutGUI("Show Help", "showHelp", KeyCode.F1);
         ShortcutGUI("Select All", "selectAll", KeyCode.F2);
         ShortcutGUI("Create State", "createState", KeyCode.F3);
         ShortcutGUI("Center View", "centerView", KeyCode.Tab);
         ShortcutGUI("Action Browser", "actionBrowser", KeyCode.F4);
         ShortcutGUI("Condition Browser", "conditionBrowser", KeyCode.F5);
         GUILayout.EndVertical();
         GUILayout.EndArea();
     }
 }
예제 #12
0
        public void HandleKeyEvents()
        {
            if (FsmEditor.instance == null || !PreferencesEditor.GetBool(Preference.EnableShortcuts))
            {
                return;
            }
            Event ev = Event.current;

            switch (ev.type)
            {
            case EventType.KeyUp:
                DoEvents(ev, false);
                break;

            case EventType.MouseUp:
                DoEvents(ev, true);
                break;
            }
        }
예제 #13
0
        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);
            }
        }
예제 #14
0
        private void DoEvents(Event ev, bool isMouse)
        {
            if (Validate("showHelp", KeyCode.F1, isMouse))
            {
                PreferencesEditor.ToggleBool(Preference.ShowShortcuts);
                ev.Use();
            }

            if (Validate("centerView", KeyCode.Tab, isMouse))
            {
                FsmEditor.instance.CenterView();
            }

            if (Validate("selectAll", KeyCode.F2, isMouse))
            {
                FsmEditor.instance.ToggleSelection();
                ev.Use();
            }

            if (Validate("createState", KeyCode.F3, isMouse) && FsmEditor.instance != null)
            {
                FsmEditorUtility.AddNode <State>(ev.mousePosition, FsmEditor.Active);
                if (FsmEditor.instance != null)
                {
                    FsmEditor.instance.Repaint();
                }
                ev.Use();
            }

            if (Validate("actionBrowser", KeyCode.F4, isMouse))
            {
                ActionBrowser.ShowWindow();
                ev.Use();
            }

            if (Validate("conditionBrowser", KeyCode.F5, isMouse))
            {
                ConditionBrowser.ShowWindow();
                ev.Use();
            }
        }
예제 #15
0
파일: FsmEditor.cs 프로젝트: Alan-Baylis/11
		protected override void OnGUI ()
		{
			mainToolbar.OnGUI ();
			EventType eventType = FsmEditorUtility.ReserveEvent (variableEditorRect,fsmSelectionRect, preferencesRect);
			Begin ();
			shortcutEditor.HandleKeyEvents ();
			if(FsmEditor.Active != null)
			DoNodes ();
			End ();
			FsmEditorUtility.ReleaseEvent (eventType);
			PreferencesEditor.DoGUI (preferencesRect);
			shortcutEditor.DoGUI (shortcutRect);
			DoFsmSelection (fsmSelectionRect);
			variableEditor.DoGUI (variableEditorRect);

			if (centerView) {
				CenterView();	
				centerView=false;
			}
			if (FsmEditor.Active != null) {
				GUI.Label (new Rect (5, 20, 300, 200), FsmEditor.Active.comment, FsmEditorStyles.instructionLabel);
			}
		}
예제 #16
0
 public MainToolbar()
 {
     lockSelection   = PreferencesEditor.GetBool(Preference.LockSelection);
     showPreferences = PreferencesEditor.GetBool(Preference.ShowPreference);
 }
        private void OnGUI()
        {
            GUI.DrawTexture(this.contactIconRect, this.contactIcon);
            GUI.Label(this.contactHeaderRect, "Contact", HeaderStyle);
            GUI.Label(this.contactTextRect, "Contact us in private, we are here to help.", TextStyle);

            GUI.DrawTexture(this.downloadIconRect, this.downloadIcon);
            GUI.Label(this.downloadHeaderRect, "Examples", HeaderStyle);
            GUI.Label(this.downloadTextRect, "Download sample projects and presets.", TextStyle);

            GUI.DrawTexture(this.documentationIconRect, this.documentationIcon);
            GUI.Label(this.documentationHeaderRect, "Documentation", HeaderStyle);
            GUI.Label(this.documenationTextRect, "Checkout our written and video documentation.", TextStyle);

            GUI.DrawTexture(this.forumIconRect, this.forumIcon);
            GUI.Label(this.forumHeaderRect, "Forums", HeaderStyle);
            GUI.Label(this.forumTextRect, "Join our forums to get support and make suggestions.", TextStyle);

            GUI.DrawTexture(this.addonIconRect, this.addonIcon);
            GUI.Label(this.addonHeaderRect, "Add-ons", HeaderStyle);
            GUI.Label(this.addonTextRect, "Download assets that extend the core functionality.", TextStyle);

            bool state = PreferencesEditor.GetBool(Preference.ShowWelcomeWindow, true);

            state = GUI.Toggle(this.showOnStartRect, state, "Show at Startup");
            PreferencesEditor.SetBool(Preference.ShowWelcomeWindow, state);

            EditorGUIUtility.AddCursorRect(this.contactIconRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.contactHeaderRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.contactTextRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.downloadIconRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.downloadHeaderRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.downloadTextRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.documentationIconRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.documentationHeaderRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.documenationTextRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.forumIconRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.forumHeaderRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.forumTextRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.addonIconRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.addonHeaderRect, MouseCursor.Link);
            EditorGUIUtility.AddCursorRect(this.addonTextRect, MouseCursor.Link);

            if (Event.current.type == EventType.MouseDown)
            {
                Vector2 mousePosition = Event.current.mousePosition;
                if (this.contactIconRect.Contains(mousePosition) || this.contactHeaderRect.Contains(mousePosition) || this.contactTextRect.Contains(mousePosition))
                {
                    Application.OpenURL("http://unitycoding.com/contact/");
                    return;
                }
                if (this.downloadIconRect.Contains(mousePosition) || this.downloadHeaderRect.Contains(mousePosition) || this.downloadTextRect.Contains(mousePosition))
                {
                    Application.OpenURL("http://unitycoding.com/icode/examples/");
                    return;
                }
                if (this.documentationIconRect.Contains(mousePosition) || this.documentationHeaderRect.Contains(mousePosition) || this.documenationTextRect.Contains(mousePosition))
                {
                    Application.OpenURL("http://unitycoding.com/icode/");
                    return;
                }
                if (this.forumIconRect.Contains(mousePosition) || this.forumHeaderRect.Contains(mousePosition) || this.forumTextRect.Contains(mousePosition))
                {
                    Application.OpenURL("http://unitycoding.com/phpbb/");
                    return;
                }
                if (this.addonIconRect.Contains(mousePosition) || this.addonHeaderRect.Contains(mousePosition) || this.addonTextRect.Contains(mousePosition))
                {
                    IntegrationWindow.ShowWindow();
                    return;
                }
            }
        }