Esempio n. 1
0
        /// <summary>
        /// Fills the editor with updates nodes.
        /// </summary>
        public void UpdateNodes()
        {
            parentHFSM.Clear();

            if (Selection.activeTransform == null)
            {
                currentMode = NodeEditorMode.Empty;
                return;
            }

            Behaviour bc = Selection.activeTransform.gameObject.GetComponent <Behaviour>();

            //Stop if no active transform or behaviour on active object.
            if (bc == null)
            {
                currentMode = NodeEditorMode.Empty;
                return;
            }

            //Set to editing mode.
            if (currentMode == NodeEditorMode.Empty)
            {
                currentMode = NodeEditorMode.Editing;
            }
            // bc.GetHFSM().Reset();
            currentHFSM = null;
            //currentHFSM = bc.GetHFSM();
            if (bc.TopHFSM == null)
            {
                bc.TopHFSM           = Selection.activeGameObject.AddComponent <HFSM>();
                bc.TopHFSM.hideFlags = HideFlags.HideInInspector;
            }
            FillFromHFSM(bc.TopHFSM);
            Repaint();
        }
Esempio n. 2
0
 void OnEnable()
 {
     if (stateHFSM == null)
     {
         stateHFSM          = gameObject.AddComponent <HFSM>();
         stateHFSM.hfsmName = stateName;
     }
 }
Esempio n. 3
0
 void DestroyHFSM(HFSM hfsm)
 {
     foreach (State s in hfsm.States)
     {
         if (s is ParentState)
         {
             DestroyHFSM(((ParentState)s).StateHFSM);
         }
         DestroyImmediate(s);
     }
     foreach (Transition t in hfsm.Transitions)
     {
         DestroyImmediate(t);
     }
     hfsms.Remove(hfsm);
     DestroyImmediate(hfsm);
 }
Esempio n. 4
0
        /// <summary>
        /// Fill the node editor from a behaviour Game Object.
        /// </summary>
        private void FillFromHFSM(HFSM hfsm)
        {
            //Clear the space for new behaviour.
            Clear();

            if (hfsm != Selection.activeGameObject.GetComponent <Behaviour>().TopHFSM)
            {
                selectedTab += 1;
                hfsms.Add(Selection.activeGameObject.GetComponent <Behaviour>().TopHFSM);
                if (currentHFSM == Selection.activeGameObject.GetComponent <Behaviour>().TopHFSM)
                {
                    currentHFSM = null;
                }
                if (parentHFSM.Count != 0 && hfsm == parentHFSM.Peek())
                {
                    parentHFSM.Pop();
                    currentHFSM = parentHFSM.Peek();
                }
                else
                {
                    parentHFSM.Push(currentHFSM);
                }
                if (currentHFSM != null)
                {
                    hfsms.Add(currentHFSM);
                    selectedTab += 1;
                }
            }
            else
            {
                parentHFSM.Clear();
            }

            hfsms.Add(hfsm);
            currentHFSM = hfsm;
            //Make nodes from HFSM states.
            for (int i = 0; i < hfsm.States.Count; i++)
            {
                Vector2 stateLocation = hfsm.States[i].nodeEditorLoc;

                Rect rect = new Rect(stateLocation.x, stateLocation.y, 100, 100);

                Node node = CreateNode(hfsm.States[i], rect);

                if (hfsm.States[i] is ParentState)
                {
                    hfsms.Add(((ParentState)hfsm.States[i]).StateHFSM);
                }

                nodes.Add(node);
            }

            //Make connections between each node;
            for (int i = 0; i < nodes.Count; i++)
            {
                for (int j = nodes[i].NodeState.Transitions.Count - 1; j >= 0; j--)
                {
                    //Iterating backwards to remove transitions leftover from
                    //inter hierarchical transitions
                    if (nodes[i].NodeState.Transitions[j] == null)
                    {
                        nodes[i].NodeState.Transitions.RemoveAt(j);
                        continue;
                    }
                    if (nodes[i].NodeState.Transitions[j].ToState == null)
                    {
                        nodes[i].NodeState.Transitions.RemoveAt(j);
                        continue;
                    }

                    Node toNode = nodes.Find(obj => obj.NodeState == nodes[i].NodeState.Transitions[j].ToState);
                    if (toNode == null)
                    {
                        toNode = GetOutsiderNode();
                        toOutside++;
                    }

                    AddConnection(nodes[i], toNode, nodes[i].NodeState.Transitions[j]);
                }
            }

            //Make connections for transitions coming from outside

            /*var enumerator = currentHFSM.OutsideTransitions.GetEnumerator();
             * while (enumerator.MoveNext())
             * {
             *  KeyValuePair<Transition, State> p = enumerator.Current;
             *
             *  if (p.Key == null)
             *  {
             *      continue;
             *  }
             *
             *  Node toNode = nodes.Find(obj => obj.NodeState == p.Key.ToState);
             *
             *  if (toNode == null)
             *      Debug.LogError("Null state, shouldn't be.");
             *
             *  AddConnection(GetOutsiderNode(), toNode, p.Key);
             * }
             */
        }