public RuntimeStateGraph(RuntimeStateGraph parent, StateGraph graph, Entity entity) { GlobalTriggers = parent.GlobalTriggers; Variables = parent.Variables; OriginalGraph = graph; ParentGraph = parent; Entity = entity; SetupGraph(); }
public RuntimeStateGraph(StateGraph graph, Entity entity) { GlobalTriggers = new Dictionary <string, GraphTrigger>(); Variables = new Dictionary <string, System.Object>(); OriginalGraph = graph; ParentGraph = null; Entity = entity; SetupGraph(); }
public override bool DrawGui(GUIStyle textStyle, GUIStyle buttonStyle) { #if UNITY_EDITOR GUILayout.BeginHorizontal(); GUILayout.Space(20); ExternalGraph = UnityEditor.EditorGUILayout.ObjectField(ExternalGraph, typeof(StateGraph), false) as StateGraph; GUILayout.Space(20); GUILayout.EndHorizontal(); #endif return(false); }
public void Set(Vector2 position, int id, StateGraph graph) { Rect = new Rect(position.x, position.y, GetNodeSize.x, GetNodeSize.y); Id = id; Graph = graph; int connectionId = MinConnectionId; if (InPoints.Count < InputMin) { for (int i = 0; i < InputMin; i++) { InPoints.Add(new ConnectionInPoint(this, connectionId)); connectionId++; } } if (OutPoints.Count < OutputMin) { for (int i = 0; i < OutputMin; i++) { OutPoints.Add(new ConnectionOutPoint(this, connectionId)); connectionId++; } } }
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 void Set(StateGraph graph) { _graph = graph; }