コード例 #1
0
    /// <summary>
    /// subscribe an event.
    /// </summary>
    /// <param name="name">Event Name.</param>
    /// <param name="handler">Event Handler.</param>
    public static ISubscriber Subscribe(SCEvent name, Handler handler = null)
    {
        List <Subscriber> sublist;

        if (!m_subscribers.TryGetValue(name, out sublist))
        {
            sublist = new List <Subscriber> ();
            m_subscribers.Add(name, sublist);
        }
        // 重复注册
        if (handler != null)
        {
            Subscriber sub = null;
            for (int n = 0; n < sublist.Count; ++n)
            {
                sub = sublist[n];

                if (sub.Handler == handler)
                {
                    Debug.LogWarning("重复注册事件: " + name);
                    return(sub);
                }
            }
        }
        // 新注册
        Subscriber newSub = new Subscriber(name, handler);

        sublist.Add(newSub);
        return(newSub);
    }
コード例 #2
0
    public void AddEvent(SCEvent e)
    {
        status.events.Add(e);

#if SC_LOG_FUNCTIONALITY
        Debug.Log("Added event \"" + e.ToString() + "\" to statechart " + this);
#endif

        if (machine.GetMode() == Statechart.Mode.On_Event)
        {
            SuperStep();
        }
    }
コード例 #3
0
    public static void Notify(SCEvent name, params object[] args)
    {
        List <Subscriber> sublist = null;

        if (m_subscribers.TryGetValue(name, out sublist))
        {
            //Debug.Log ("Notify:" + name);
            Subscriber[] subs = sublist.ToArray();
            Subscriber   sub  = null;
            for (int n = 0; n < subs.Length; ++n)
            {
                sub = subs[n];
                sub.Notify(args);
            }
        }
    }
コード例 #4
0
    public static void UnSubscribe(SCEvent name, Handler handler)
    {
        if (handler == null)
        {
            return;
        }
        List <Subscriber> sublist;

        if (m_subscribers.TryGetValue(name, out sublist))
        {
            for (int i = sublist.Count; i > 0;)
            {
                if (sublist[--i].Handler == handler)
                {
                    sublist.RemoveAt(i);
                }
            }
            if (sublist.Count == 0)
            {
                m_subscribers.Remove(name);
            }
        }
    }
コード例 #5
0
    void ParseTransitions(XmlNode node)
    {
        if (node.Name == "state" ||
            node.Name == "parallel" ||
            node.Name == "pseudo")
        {
            int index = name_to_node[node.Attributes["id"].Value];

            // Transitions
            int transitions_start = transitions.Count;

            nodes[index] = new Node(nodes[index].type,
                                    nodes[index].superstate,
                                    nodes[index].components,
                                    nodes[index].data,
                                    transitions_start);

            foreach (XmlNode n in node.ChildNodes)
            {
                ParseTransitions(n);
            }
        }
        else if (node.Name == "transition")
        {
            if (node.Attributes["priority"] == null)
            {
                Debug.LogError("Error: Missing priority in transition in " + scxml.name);
            }
            if (node.Attributes["target"] == null)
            {
                Debug.LogError("Error: Missing target in transition in " + scxml.name);
            }
            if (node.Attributes["event"] == null)
            {
                Debug.LogError("Error: Missing trigger in transition in " + scxml.name);
            }

            var trigger = new SCEvent(node.Attributes["event"].Value);

            Guard guard = new Guard(-1);
            if (node.Attributes["cond"] != null)
            {
                var guard_info = ParseGuard(node.Attributes["cond"].Value);

                if (!name_to_property.TryGetValue(guard_info, out int property))
                {
                    property = name_to_property.Count;
                    name_to_property[guard_info] = property;
                }

                guard = new Guard(property);
            }

            int destination = name_to_node[node.Attributes["target"].Value];

            transitions.Add(new Transition(trigger, guard, destination));
            transition_to_name.Add(
                node_to_name[name_to_node[node.ParentNode.Attributes["id"].Value]]
                + "->"
                + node_to_name[destination]);
            name_to_transition[transition_to_name[transitions.Count - 1]] = transitions.Count - 1;
        }
        else
        {
            Debug.LogError("Error: Unsupported XML name in statechart document: \"" + node.Name + "\"");
        }
    }
コード例 #6
0
 public bool ContainsEvent(SCEvent ev)
 {
     return(events.Contains(ev));
 }
コード例 #7
0
 public Transition(SCEvent trigger, Guard guard, int destination)
 {
     this.trigger     = trigger;
     this.guard       = guard;
     this.destination = destination;
 }
コード例 #8
0
 public Subscriber(SCEvent key, Handler handler)
 {
     m_name    = key;
     m_handler = handler;
 }