Ejemplo n.º 1
0
        /// <summary>
        /// Load function that unpacks <see cref="Rule"/> from corresponding <see cref="SerializedProperty"/>.
        /// </summary>
        private void LoadRule(bool inSet)
        {
            if (inSet)
            {
                string setName   = SubjectRule.propertyPath.Remove(SubjectRule.propertyPath.IndexOf(".Array")).Replace("Profile.", "");
                int    ruleIndex = int.Parse(SubjectRule.propertyPath.Substring(SubjectRule.propertyPath.IndexOf("[") + 1).Replace("]", ""));

                deserializedRule = RuleSystemUtil.DeserializeRule(SubjectRule, setName, ruleIndex);
            }
            else
            {
                deserializedRule = RuleSystemUtil.DeserializeRule(SubjectRule);
            }
            rootNode = RuleCreator.CreateRoot(deserializedRule.RootGridPosition, OnNodePortContact, OnUpdateRootRequest, OnRemoveAThread, deserializedRule.MandatoryId, deserializedRule.QualityId, deserializedRule.MyAction, NodeSkin);
            if (deserializedRule.MyAction != null)
            {
                actionNode = RuleCreator.CreateActionNode(deserializedRule.ActionGridPosition, OnNodePortContact, OnUpdateActionRequest, OnRemoveNode, OnRemoveAThread, deserializedRule.MyAction, NodeSkin);
            }
            foreach (Decision decision in deserializedRule.MyDecisions)
            {
                ruleDecisions.Add(decision);
                NodeShell rawNode = RuleCreator.CreateNewDecisionNode(decision.identifier, decision.Operator, OnUpdateRuleRequest, OnNodePortContact, OnRemoveNode, OnRemoveAThread, NodeSkin);
                rawNode.Container = new NodeShell.Data
                {
                    FloatValue = decision.FlatValue
                };
                rawNode.Inputs        = decision.inputID;
                rawNode.Rect.position = decision.GridPosition;
                rawNode.activated     = true;
                ruleNodes.Add(rawNode);
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Creates an Action node.
 /// </summary>
 /// <param name="position">Grid position. </param>
 /// <param name="OnPortClick">Event-handle for <see cref="Port"/> clicks. </param>
 /// <param name="OnActionUpdate">Event-hanlde for updating <see cref="Action"/> data. </param>
 /// <param name="OnRemoveNode">Event-handle for removing this node. </param>
 /// <param name="action">Action asset represented by this node. </param>
 /// <param name="skin"><see cref="GUISkin"/> of nodes. </param>
 /// <returns></returns>
 public static ActionShell CreateActionNode(Vector2 position, Action<Port> OnPortClick, Action<Action, Vector2> OnActionUpdate, Action<NodeShell> OnRemoveNode, Action<Thread> OnRemoveThread, Action action, GUISkin skin)
 {
     ActionStyle style = new ActionStyle(action.Name);
     ActionShell crAct = new ActionShell
     {
         Id = -1,
         Action = action,
         OnUpdateAction = OnActionUpdate,
         OnRemoveNode = OnRemoveNode,
         Skin = skin,
         Style = style,
         Rect = style.Rect
     };
     crAct.Rect.position = position;
     crAct.Port0 = new Port
     {
         Name = action.Name,
         type = PortType.Output,
         MyNode = crAct,
         nodeSkin = skin,
         OnClickPort = OnPortClick,
         OnRemoveThread = OnRemoveThread,
         rect = new Rect(0, 0, skin.button.fixedWidth, skin.button.fixedHeight),
         isDecision = false
     };
     return crAct;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Event handle for nodes that are being created.
        /// </summary>
        /// <param name="e">Current Unity Event. </param>
        private void ProcessCreatedNode(Event e)
        {
            if (createdNode != null)
            {
                createdNode.Rect.position = e.mousePosition;
                createdNode.Draw();
                switch (e.type)
                {
                case EventType.MouseUp:
                    if (e.button == 0)
                    {
                        if (createdNode != null)
                        {
                            ruleDecisions.Add(createdDecision);
                            ruleNodes.Add(createdNode);
                            createdNode.activated = true;
                            createdNode           = null;
                            createdDecision       = null;
                        }
                    }
                    else if (e.button == 1)
                    {
                        createdNode = null;
                    }
                    break;
                }
            }
            if (createdActionNode != null)
            {
                createdActionNode.Rect.position = e.mousePosition;
                createdActionNode.Draw();

                switch (e.type)
                {
                case EventType.MouseUp:
                    if (e.button == 0)
                    {
                        if (createdActionNode != null)
                        {
                            actionNode = createdActionNode;

                            actionNode.activated = true;
                            createdActionNode    = null;
                        }
                    }
                    else if (e.button == 1)
                    {
                        createdActionNode = null;
                    }
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Action-event handles <see cref="NodeShell"/> remove from  rule requests.
        /// </summary>
        /// <param name="node">Node that requests to be removed.</param>
        private void OnRemoveNode(NodeShell node)
        {
            if (ruleNodes.Remove(node))
            {
                var decision = GetDecisionById(node.Id);
                ruleDecisions.Remove(decision);

                for (int i = Yarn.Count - 1; i > 0; i--)
                {
                    if (Yarn[i].inputPort.MyNode == node || Yarn[i].outputPort.MyNode == node)
                    {
                        OnRemoveAThread(Yarn[i]);
                    }
                }
            }
            else if (actionNode == node)
            {
                actionNode = null;
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Action-event handles <see cref="ActionShell"/> instantiation.
 /// </summary>
 /// <param name="action"><see cref="Action"/> that needs a node. </param>
 private void OnRequestActionNode(Action action)
 {
     createdActionNode = RuleCreator.CreateActionNode(deserializedRule.ActionGridPosition, OnNodePortContact, OnUpdateActionRequest, OnRemoveNode, OnRemoveAThread, action, NodeSkin);
     createdActionNode.Rect.position = mousePos;
 }