Example #1
0
        public override bool DrawGui(GUIStyle textStyle, GUIStyle buttonStyle)
        {
#if UNITY_EDITOR
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label("Variable: ");
            var graphLabels = GraphVariables.GetValues();
            var index       = System.Array.IndexOf(graphLabels, VariableName);
            var newVar      = UnityEditor.EditorGUILayout.Popup(
                index, graphLabels, buttonStyle, new[] {
                GUILayout.MaxWidth
                    (StateGraphNode.DefaultNodeSize.x * 0.5f)
            });
            if (newVar != index)
            {
                VariableName = graphLabels[newVar];
            }
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
            for (int i = 0; i < OutPoints.Count; i++)
            {
                if (Values.Count <= i)
                {
                    Values.Add("");
                    CheckSize();
                }
                GUILayout.BeginHorizontal();
                GUILayout.Space(20);
                GUILayout.Label("Case: ");
                Values[i] = GUILayout.TextField(Values[i], textStyle);
                GUILayout.Label(" Exit " + i.ToString());
                GUILayout.Space(20);
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label("Else Exit ", textStyle);
            var indices = new string[OutPoints.Count];
            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = i.ToString();
            }
            DefaultExit = UnityEditor.EditorGUILayout.Popup(DefaultExit, indices, textStyle);
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
#endif
            return(false);
        }
Example #2
0
        public bool DrawType(StateGraph graph, GUIStyle textStyle, GUIStyle buttonStyle)
        {
            bool changed = false;

#if UNITY_EDITOR
            switch (Type)
            {
            case ConditionType.Trigger:
            case ConditionType.EntityTag:
                break;

            case ConditionType.IsAttacking:
                GUILayout.Label("IsAttacking", textStyle);
                break;

            default:
                var graphLabels = GraphVariables.GetValues();
                var index       = System.Array.IndexOf(graphLabels, VariableName);
                var newVar      = UnityEditor.EditorGUILayout.Popup(index, graphLabels, buttonStyle, new [] { GUILayout.MaxWidth
                                                                                                                  (StateGraphNode.DefaultNodeSize.x * 0.5f) });
                if (newVar != index)
                {
                    VariableName = graphLabels[newVar];
                }
                break;
            }
            switch (Type)
            {
            case ConditionType.IsAttacking:
                bool.TryParse(Value, out bool oldBool);
                if (GUILayout.Button(oldBool.ToString(), buttonStyle))
                {
                    Value = (!oldBool).ToString();
                }
                break;

            case ConditionType.Trigger:
                var labels   = graph.GlobalTriggers.Select(t => t.Key).ToArray();
                var index    = System.Array.IndexOf(labels, Value);
                var newIndex = UnityEditor.EditorGUILayout.Popup(index, labels, buttonStyle);
                if (newIndex >= 0)
                {
                    Value   = labels[newIndex];
                    changed = true;
                }
                break;

            case ConditionType.StringVariable:
                Value = GUILayout.TextField(Value, buttonStyle);
                break;

            case ConditionType.BoolVariable:
                bool.TryParse(Value, out bool oldValue);
                if (GUILayout.Button(oldValue.ToString()))
                {
                    Value = (!oldValue).ToString();
                }
                break;

            case ConditionType.EntityTag:
                int.TryParse(Value, out int oldTagInt);
                var animationLabels = AnimationEvents.GetValues();
                var newTag          = UnityEditor.EditorGUILayout.Popup(oldTagInt, animationLabels);
                if (newTag != oldTagInt)
                {
                    Value = newTag.ToString();
                }
                break;

            case ConditionType.FloatVariable:
                float.TryParse(Value, out float oldFloat);
                var newFloatStr = GUILayout.TextField(Value, buttonStyle);
                if (float.TryParse(newFloatStr, out var newFloat) && Math.Abs(newFloat - oldFloat) > 0.001f)
                {
                    Value = newFloatStr;
                }
                break;

            case ConditionType.IntVariable:
                int.TryParse(Value, out int oldInt);
                var newIntStr = GUILayout.TextField(Value, buttonStyle);
                if (int.TryParse(newIntStr, out var newInt) && newInt != oldInt)
                {
                    Value = newIntStr;
                }
                break;
            }
#endif
            return(changed);
        }
        public override bool DrawGui(GUIStyle textStyle, GUIStyle buttonStyle)
        {
#if UNITY_EDITOR
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label("Variable: ");
            var graphLabels = GraphVariables.GetValues();
            var index       = System.Array.IndexOf(graphLabels, VariableName);
            var newVar      = UnityEditor.EditorGUILayout.Popup(
                index, graphLabels, buttonStyle, new[] {
                GUILayout.MaxWidth(StateGraphNode.DefaultNodeSize.x * 0.5f)
            });
            if (newVar != index)
            {
                VariableName = graphLabels[newVar];
            }
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
            for (int i = 0; i < Graphs.Length; i++)
            {
                if (Values.Count <= i)
                {
                    Values.Add("");
                    CheckSize();
                }
                GUILayout.BeginHorizontal();
                GUILayout.Space(20);
                GUILayout.Label("Case: ");
                Values[i] = GUILayout.TextField(Values[i], textStyle);
                Graphs[i] = UnityEditor.EditorGUILayout.ObjectField(Graphs[i], typeof(StateGraph), false, GUILayout.MaxWidth(
                                                                        StateGraphNode.DefaultNodeSize.x * 0.5f)) as
                            StateGraph;
                GUILayout.Space(20);
                GUILayout.EndHorizontal();
            }

            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label("Else Pick ", textStyle);
            var indices = new string[Values.Count];
            for (int i = 0; i < indices.Length; i++)
            {
                indices[i] = i.ToString();
            }
            DefaultIndex = UnityEditor.EditorGUILayout.Popup(DefaultIndex, indices, textStyle);
            GUILayout.Space(20);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            if (GUILayout.Button("Add Case"))
            {
                Values.Add("");
                System.Array.Resize(ref Graphs, Graphs.Length + 1);
                CheckSize();
            }
            if (Graphs.Length > 0 && GUILayout.Button("Remove Case"))
            {
                Values.RemoveLast();
                System.Array.Resize(ref Graphs, Graphs.Length - 1);
                CheckSize();
            }
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
#endif
            return(false);
        }
Example #4
0
        public override bool DrawGui(GUIStyle textStyle, GUIStyle buttonStyle)
        {
#if UNITY_EDITOR
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            GUILayout.Label("Default: ");
            Default = UnityEditor.EditorGUILayout.ObjectField(Default, typeof(MusclePose), false) as MusclePose;
            Curve   = UnityEditor.EditorGUILayout.CurveField(Curve);
            GUILayout.Space(20);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            Duration = UnityEditor.EditorGUILayout.Slider(Duration, 0, 2);
            GUILayout.Label("Variable: ");
            var graphLabels = GraphVariables.GetValues();
            var index       = System.Array.IndexOf(graphLabels, VariableName);
            var newVar      = UnityEditor.EditorGUILayout.Popup(
                index, graphLabels, buttonStyle, new[] {
                GUILayout.MaxWidth
                    (StateGraphNode.DefaultNodeSize.x * 0.5f)
            });
            if (newVar != index)
            {
                VariableName = graphLabels[newVar];
            }
            GUILayout.Space(20);
            GUILayout.EndHorizontal();

            for (int i = 0; i < TargetPoses.Count; i++)
            {
                if (Values.Count <= i)
                {
                    Values.Add("");
                    Rect.size = GetNodeSize;
                }
                GUILayout.BeginHorizontal();
                GUILayout.Space(20);
                GUILayout.Label("Case:");
                Values[i]      = GUILayout.TextField(Values[i], textStyle);
                TargetPoses[i] = UnityEditor.EditorGUILayout.ObjectField(TargetPoses[i], typeof(MusclePose), false) as MusclePose;
                if (GUILayout.Button("X"))
                {
                    TargetPoses.RemoveAt(i);
                    Values.RemoveAt(i);
                    CheckSize();
                    GUILayout.Space(20);
                    GUILayout.EndHorizontal();
                    break;
                }
                GUILayout.Space(20);
                GUILayout.EndHorizontal();
            }
            GUILayout.BeginHorizontal();
            GUILayout.Space(20);
            if (GUILayout.Button("Add Pose"))
            {
                TargetPoses.Add(null);
                CheckSize();
            }
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
#endif
            return(false);
        }