Exemplo n.º 1
0
    /// <summary>
    /// Creates a copy of this <see cref="UtilityNode"/>
    /// </summary>
    /// <param name="args"></param>
    /// <returns></returns>
    public override GUIElement CopyElement(params object[] args)
    {
        UtilitySystem parent = (UtilitySystem)args[0];

        UtilityNode result = CreateInstance <UtilityNode>();

        result.identificator = this.identificator;
        result.nodeName      = this.nodeName;
        result.parent        = parent;
        result.windowRect    = new Rect(this.windowRect);
        result.type          = this.type;
        result.fusionType    = this.fusionType;
        result.curveType     = this.curveType;
        result.variableMax   = this.variableMax;
        result.variableMin   = this.variableMin;
        result.slope         = this.slope;
        result.exp           = this.exp;
        result.displX        = this.displX;
        result.displY        = this.displY;
        result.points        = this.points;

        if (this.subElem)
        {
            result.subElem = (ClickableElement)this.subElem.CopyElement(parent);
        }

        return(result);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Creates and returns the <see cref="StateNode"/> corresponding to this <see cref="XMLElement"/>
    /// </summary>
    /// <returns></returns>
    public UtilityNode ToUtilityNode(UtilitySystem parent)
    {
        UtilityNode node = ScriptableObject.CreateInstance <UtilityNode>();

        node.InitUtilityNodeFromXML(parent, (utilityType)Enum.Parse(typeof(utilityType), this.secondType),
                                    (fusionType)Enum.Parse(typeof(fusionType), this.thirdType),
                                    (curveType)Enum.Parse(typeof(curveType), this.fourthType),
                                    this.windowPosX, this.windowPosY, this.Id, this.name, this.variableMax, this.variableMin, this.slope, this.exp, this.displX, this.displY, this.points);

        return(node);
    }
Exemplo n.º 3
0
 public override void OnBodyGUI()
 {
     if (_utilityNode == null)
     {
         _utilityNode = (UtilityNode)target;
     }
     NodeEditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_utilityNode.MinX)));
     NodeEditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_utilityNode.X)));
     NodeEditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(_utilityNode.MaxX)));
     _utilityNode.MaxY = EditorGUILayout.IntField("Max Rank", _utilityNode.MaxY);
     EditorGUILayout.CurveField(GUIContent.none, _utilityNode.Function, GUILayout.Height(50));
     NodeEditorGUILayout.AddPortField(_utilityNode.GetPort(nameof(_utilityNode.Rank)));
     _utilityNode.MinY = EditorGUILayout.IntField("Min Rank", _utilityNode.MinY);
 }
Exemplo n.º 4
0
    void Setup()
    {
        int counter = 0;

        for (int i = 0; i < Size; i++)
        {
            for (int j = 0; j < Size; j++)
            {
                Vector3     node_offset = new Vector3(i * Space, 0, j * Space) + Offset;
                Vector3     pos         = Center + node_offset;
                UtilityNode node        = new UtilityNode(pos, Space, i, j, node_offset.magnitude / MaxMagnitude, NotWalkable);
                nodes[counter] = node;
                counter++;
            }
        }
    }
Exemplo n.º 5
0
    /// <summary>
    /// Checks wether <paramref name="start"/> could ever reach <paramref name="end"/> in the <see cref="UtilitySystem"/> execution
    /// </summary>
    /// <param name="start"></param>
    /// <param name="end"></param>
    /// <returns></returns>
    public bool ConnectedCheck(UtilityNode start, UtilityNode end)
    {
        foreach (TransitionGUI transition in transitions.FindAll(t => !t.isExit && start.Equals(t.toNode)))
        {
            if (end.Equals((UtilityNode)transition.fromNode))
            {
                return(true);
            }
            if (ConnectedCheck((UtilityNode)transition.fromNode, end))
            {
                return(true);
            }
        }

        return(false);
    }
Exemplo n.º 6
0
    /// <summary>
    /// Deletes the <paramref name="node"/>
    /// </summary>
    /// <param name="node"></param>
    public void DeleteNode(UtilityNode node, bool deleteTransitions = true)
    {
        if (nodes.Remove(node))
        {
            if (deleteTransitions)
            {
                foreach (TransitionGUI transition in transitions.FindAll(t => node.Equals(t.fromNode) || node.Equals(t.toNode)))
                {
                    DeleteConnection(transition);
                }
            }

            if (node.subElem == null)
            {
                elementNamer.RemoveName(node.identificator);
            }
            else
            {
                elementNamer.RemoveName(node.subElem.identificator);
            }
        }
    }
Exemplo n.º 7
0
 internal void AddChoice(UtilityNode choice)
 {
     choices.Add(choice);
 }
Exemplo n.º 8
0
    /// <summary>
    /// Creates and returns the <see cref="FSM"/> corresponding to this <see cref="XMLElement"/>
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="selectedNode"></param>
    /// <returns></returns>
    public UtilitySystem ToUtilitySystem(ClickableElement parent, BaseNode selectedNode = null)
    {
        UtilitySystem utilSystem = ScriptableObject.CreateInstance <UtilitySystem>();

        utilSystem.InitUtilitySystemFromXML(parent, this.windowPosX, this.windowPosY, this.Id, this.name);

        foreach (XMLElement node in this.nodes)
        {
            switch (node.elemType)
            {
            case nameof(FSM):
                node.ToFSM(utilSystem, null);
                break;

            case nameof(BehaviourTree):
                node.ToBehaviourTree(utilSystem, null);
                break;

            case nameof(UtilitySystem):
                node.ToUtilitySystem(utilSystem, null);
                break;

            case nameof(UtilityNode):
                UtilityNode state = node.ToUtilityNode(utilSystem);

                utilSystem.nodes.Add(state);
                break;

            default:
                Debug.LogError("Wrong content in saved data");
                break;
            }
        }

        foreach (XMLElement trans in this.transitions)
        {
            BaseNode node1 = utilSystem.nodes.Where(n => n.identificator == trans.fromId || n.subElem?.identificator == trans.fromId).FirstOrDefault();
            BaseNode node2 = utilSystem.nodes.Where(n => n.identificator == trans.toId || n.subElem?.identificator == trans.toId).FirstOrDefault();
            if (node1 != null && node2 != null)
            {
                utilSystem.transitions.Add(trans.ToTransitionGUI(utilSystem, node1, node2));
            }
        }

        if (parent)
        {
            switch (parent.GetType().ToString())
            {
            case nameof(FSM):
                StateNode state = ScriptableObject.CreateInstance <StateNode>();
                state.InitStateNodeFromXML(parent, stateType.Unconnected, utilSystem.windowRect.position.x, utilSystem.windowRect.position.y, this.Id, this.name, utilSystem);

                if (this.secondType.Equals(stateType.Entry.ToString()))
                {
                    ((FSM)parent).AddEntryState(state);
                }
                else
                {
                    parent.nodes.Add(state);
                }
                break;

            case nameof(BehaviourTree):
                BehaviourNode node = ScriptableObject.CreateInstance <BehaviourNode>();
                node.InitBehaviourNode(parent, behaviourType.Leaf, utilSystem.windowRect.x, utilSystem.windowRect.y, utilSystem);

                parent.nodes.Add(node);

                if (selectedNode != null)
                {
                    TransitionGUI transition = ScriptableObject.CreateInstance <TransitionGUI>();
                    transition.InitTransitionGUI(parent, selectedNode, node);

                    parent.transitions.Add(transition);

                    selectedNode = node;
                }
                break;

            case nameof(UtilitySystem):
                UtilityNode utilNode = ScriptableObject.CreateInstance <UtilityNode>();
                utilNode.InitUtilityNode(parent, utilityType.Action, utilSystem.windowRect.position.x, utilSystem.windowRect.position.y, utilSystem);

                parent.nodes.Add(utilNode);
                break;
            }
        }

        return(utilSystem);
    }