Ejemplo n.º 1
0
		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");
			}	

		}
Ejemplo n.º 2
0
        static void HierarchyWindowItemCallback(int pID, Rect pRect)
        {
            GameObject go = EditorUtility.InstanceIDToObject(pID) as GameObject;

            if (go != null && go.GetComponent <ICodeBehaviour>() != null)
            {
                Rect rect = new Rect(pRect.x + pRect.width - 25, pRect.y - 3, 25, 25);
                GUI.DrawTexture(rect, FsmEditorStyles.iCodeLogo);
                ICodeBehaviour[] behaviours = go.GetComponents <ICodeBehaviour>();
                for (int i = 0; i < behaviours.Length; i++)
                {
                    ICodeBehaviour behaviour = behaviours[i];
                    ErrorChecker.CheckForErrors(behaviour.stateMachine);
                    if (ErrorChecker.HasErrors(behaviour.stateMachine) || behaviour.stateMachine == null)
                    {
                        Rect rect1 = new Rect(pRect.x + pRect.width - 25 - rect.width, pRect.y - 3, 25, 25);
                        GUI.DrawTexture(rect1, EditorGUIUtility.FindTexture("d_console.erroricon"));
                    }
                }
            }

            Event ev = Event.current;

            if (ev.type == EventType.DragPerform)
            {
                DragAndDrop.AcceptDrag();
                var selectedObjects = new List <GameObject>();
                foreach (var objectRef in DragAndDrop.objectReferences)
                {
                    if (objectRef is StateMachine)
                    {
                        if (pRect.Contains(ev.mousePosition))
                        {
                            var gameObject = (GameObject)EditorUtility.InstanceIDToObject(pID);
                            var componentX = gameObject.AddComponent <ICodeBehaviour>();
                            componentX.stateMachine = objectRef as StateMachine;
                            selectedObjects.Add(gameObject);
                        }
                    }
                }

                if (selectedObjects.Count == 0)
                {
                    return;
                }
                Selection.objects = selectedObjects.ToArray();
                ev.Use();
            }
        }
Ejemplo n.º 3
0
        public override void OnGUI(SerializedProperty property, GUIContent label)
        {
            if (property.objectReferenceValue == null)
            {
                CreateVariable(property);
            }
            if (property.objectReferenceValue == null)
            {
                return;
            }
            SerializedObject serializedObject = new SerializedObject(property.objectReferenceValue);

            serializedObject.Update();
            GUILayout.BeginHorizontal();

            SerializedProperty nameProperty   = serializedObject.FindProperty("name");
            SerializedProperty valueProperty  = serializedObject.FindProperty("value");
            SerializedProperty sharedProperty = serializedObject.FindProperty("isShared");

            if (EditorUtility.IsPersistent(property.objectReferenceValue) && fieldInfo.HasAttribute(typeof(SharedPersistentAttribute)) || fieldInfo.FieldType == typeof(FsmArray))
            {
                sharedProperty.boolValue = true;
            }

            Color color = GUI.backgroundColor;

            if (ErrorChecker.HasErrors(property.objectReferenceValue))
            {
                GUI.backgroundColor = Color.red;
            }

            if (sharedProperty.boolValue)
            {
                DrawSharedVariable(label, nameProperty);
            }
            else
            {
                OnPropertyField(valueProperty, label);
            }
            GUI.backgroundColor = color;

            if (DoSharedToggle(property))
            {
                DrawSharedToggle(sharedProperty);
            }
            GUILayout.EndHorizontal();
            serializedObject.ApplyModifiedProperties();
        }
Ejemplo n.º 4
0
        public static bool NodeTitlebar(ExecutableNode executable, Node node)
        {
            int        controlID = EditorGUIUtility.GetControlID(FocusType.Passive);
            GUIContent content   = new GUIContent(executable.name.Replace("/", "."), executable.GetType().GetTooltip());

            Rect position = GUILayoutUtility.GetRect(GUIContent.none, FsmEditorStyles.inspectorTitle);
            Rect rect     = new Rect(position.x + (float)FsmEditorStyles.inspectorTitle.padding.left, position.y + (float)FsmEditorStyles.inspectorTitle.padding.top, 16f, 16f);
            Rect rect1    = new Rect(position.xMax - (float)FsmEditorStyles.inspectorTitle.padding.right - 2f - 16f, rect.y, 16f, 16f);
            Rect rect4    = rect1;

            rect4.x = rect4.x - 18f;

            Rect rect2 = new Rect(position.x + 2f + 2f + 16f * 2, rect.y, 100f, rect.height)
            {
                xMax = rect4.xMin - 2f
            };
            Rect rect3 = new Rect(position.x + 16f, rect.y, 16f, 16f);

            executable.IsEnabled = GUI.Toggle(rect3, executable.IsEnabled, GUIContent.none);
            string url = executable.GetType().GetHelpUrl();

            if (ErrorChecker.HasErrors(executable))
            {
                Rect rect5 = rect4;
                rect5.y += 1.0f;
                if (!string.IsNullOrEmpty(url))
                {
                    rect5.x    = rect5.x - 18f;
                    rect2.xMax = rect5.x;
                }

                GUI.Label(rect5, FsmEditorStyles.errorIcon, FsmEditorStyles.inspectorTitleText);
            }

            if (GUI.Button(rect1, FsmEditorStyles.popupIcon, FsmEditorStyles.inspectorTitleText))
            {
                ExecutableContextMenu(executable, node).ShowAsContext();
            }

            if (!string.IsNullOrEmpty(url) && GUI.Button(rect4, FsmEditorStyles.helpIcon, FsmEditorStyles.inspectorTitleText))
            {
                Application.OpenURL(url);
            }

            EventType eventType = Event.current.type;

            if (eventType != EventType.MouseDown)
            {
                if (eventType == EventType.Repaint)
                {
                    FsmEditorStyles.inspectorTitle.Draw(position, GUIContent.none, controlID, executable.IsOpen);
                    FsmEditorStyles.inspectorTitleText.Draw(rect2, content, controlID, executable.IsOpen);
                }
            }
            position.width = 15;
            bool flag = DoToggleForward(position, controlID, executable.IsOpen, GUIContent.none, GUIStyle.none);

            if (flag != executable.IsOpen)
            {
                executable.IsOpen = flag;
            }
            return(flag);
        }
Ejemplo n.º 5
0
        public static bool ObjectTitlebar(UnityEngine.Object targetObject, bool foldout, ref bool enabled, GenericMenu settings)
        {
            int        controlID = EditorGUIUtility.GetControlID(FocusType.Passive);
            GUIContent content   = new GUIContent(targetObject.name.Replace("/", "."), targetObject.GetTooltip());

            Debug.Log(FsmEditorStyles.inspectorTitle.fixedWidth);
            Rect position = GUILayoutUtility.GetRect(GUIContent.none, FsmEditorStyles.inspectorTitle);

            position.x     += 1f;
            position.width -= 3f;
            Rect rect  = new Rect(position.x + (float)FsmEditorStyles.inspectorTitle.padding.left, position.y + (float)FsmEditorStyles.inspectorTitle.padding.top, 16f, 16f);
            Rect rect1 = new Rect(position.xMax - (float)FsmEditorStyles.inspectorTitle.padding.right - 2f - 16f, rect.y, 16f, 16f);
            Rect rect4 = rect1;

            rect4.x = rect4.x - 18f;

            Rect rect2 = new Rect(position.x + 2f + 2f + 16f * 2, rect.y, 100f, rect.height)
            {
                xMax = rect4.xMin - 2f
            };
            Rect rect3 = new Rect(position.x + 16f, rect.y, 16f, 16f);

            enabled = GUI.Toggle(rect3, enabled, GUIContent.none);
            string url = targetObject.GetHelpUrl();

            if (ErrorChecker.HasErrors(targetObject))
            {
                Rect rect5 = rect4;
                rect5.y += 1.0f;
                if (!string.IsNullOrEmpty(url))
                {
                    rect5.x    = rect5.x - 18f;
                    rect2.xMax = rect5.x;
                }

                GUI.Label(rect5, FsmEditorStyles.errorIcon, FsmEditorStyles.inspectorTitleText);
            }

            if (GUI.Button(rect1, FsmEditorStyles.popupIcon, FsmEditorStyles.inspectorTitleText))
            {
                settings.ShowAsContext();
            }

            if (!string.IsNullOrEmpty(url) && GUI.Button(rect4, FsmEditorStyles.helpIcon, FsmEditorStyles.inspectorTitleText))
            {
                Application.OpenURL(url);
            }

            EventType eventType = Event.current.type;

            if (eventType != EventType.MouseDown)
            {
                if (eventType == EventType.Repaint)
                {
                    FsmEditorStyles.inspectorTitle.Draw(position, GUIContent.none, controlID, foldout);
                    Color color = GUI.contentColor;
                    if (FsmEditor.Active != null && FsmEditor.Active.Owner != null)
                    {
                        ICodeBehaviour behaviour = FsmEditor.Active.Owner;
                        if (behaviour.ActiveNode is State && (behaviour.ActiveNode as State).ActiveAction == targetObject)
                        {
                            GUI.contentColor = Color.green;
                        }
                    }
                    FsmEditorStyles.inspectorTitleText.Draw(rect2, content, controlID, foldout);
                    GUI.contentColor = color;
                }
            }
            position.width = 15;

            bool flag = FsmGUIUtility.DoToggleForward(position, controlID, foldout, GUIContent.none, GUIStyle.none);

            return(flag);
        }
        public void ResetTransitionList()
        {
            SerializedObject   obj      = new SerializedObject(node);
            SerializedProperty elements = obj.FindProperty("transitions");

            transitionList = new ReorderableObjectList(obj, elements);
            transitionList.drawHeaderCallback = delegate(Rect rect) {
                EditorGUI.LabelField(rect, "Transitions");
                EditorGUI.LabelField(new Rect(rect.width - 25, rect.y, 50, 20), "Mute");
            };

            transitionList.onSelectCallback = delegate(int index) {
                if (node.Transitions.Length > 0)
                {
                    FsmEditor.SelectTransition(this.node.Transitions[index]);
                    this.ResetConditionList();
                }
            };

            transitionList.onRemoveCallback = delegate(ReorderableObjectList list) {
                Transition transition = node.Transitions[list.index];
                node.Transitions = ArrayUtility.Remove(node.Transitions, transition);
                FsmEditorUtility.DestroyImmediate(transition);
                list.index = Mathf.Clamp(list.index - 1, 0, list.count - 1);
                ErrorChecker.CheckForErrors();
                EditorUtility.SetDirty(node);
            };
            transitionList.drawElementCallback = delegate(int index, bool selected) {
                Transition transition = node.Transitions [index];
                if (selected)
                {
                    GUIStyle selectBackground = new GUIStyle("MeTransitionSelectHead")
                    {
                        stretchHeight = false,
                    };
                    selectBackground.overflow = new RectOffset(-1, -2, -2, 2);
                    GUILayout.BeginVertical(selectBackground);
                }
                GUILayout.BeginHorizontal();
                for (int i = 0; i < transition.Conditions.Length; i++)
                {
                    Condition condition = transition.Conditions[i];
                    if (ErrorChecker.HasErrors(condition))
                    {
                        GUILayout.Label(FsmEditorStyles.errorIcon);
                        break;
                    }
                }
                GUILayout.Label(transition.FromNode.Name + " -> " + transition.ToNode.Name, selected?EditorStyles.whiteLabel:EditorStyles.label);
                GUILayout.FlexibleSpace();
                transition.Mute = GUILayout.Toggle(transition.Mute, GUIContent.none, GUILayout.Width(15));
                GUILayout.Space(22f);
                GUILayout.EndHorizontal();
                if (selected)
                {
                    GUILayout.EndVertical();
                }
            };

            transitionList.onReorderCallback = delegate(ReorderableObjectList list) {
                FsmEditor.SelectTransition(this.node.Transitions[list.index]);
                this.ResetConditionList();
            };
            transitionList.onContextClick = delegate(int index) {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Remove"), false, delegate() {
                    Transition transition = node.Transitions[index];
                    node.Transitions      = ArrayUtility.Remove(node.Transitions, transition);
                    FsmEditorUtility.DestroyImmediate(transition);

                    transitionList.index = Mathf.Clamp((index == transitionList.index?index - 1:(index < transitionList.index?transitionList.index - 1:transitionList.index)), 0, node.Transitions.Length - 1);
                    ErrorChecker.CheckForErrors();
                    EditorUtility.SetDirty(node);
                });
                menu.ShowAsContext();
            };

            this.ResetConditionList();
            this.host.Repaint();
            if (FsmEditor.instance != null)
            {
                FsmEditor.instance.Repaint();
            }
        }