示例#1
0
    public void AddTriggerCallback(string tag, InteractionType type, List <UnityAction <Collider> > callbacks)
    {
        if (triggersCallbacks == null)
        {
            triggersCallbacks = new Dictionary <string, Dictionary <InteractionType, UnityEvent <Collider> > >();
        }

        if (triggersCallbacks.ContainsKey(tag))
        {
            if (triggersCallbacks[tag].ContainsKey(type))
            {
                foreach (var callback in callbacks)
                {
                    triggersCallbacks[tag][type].AddListener(callback);
                }
            }
            else
            {
                UnityEvent <Collider> unityEvent = new UnityEventCollider();
                foreach (var callback in callbacks)
                {
                    unityEvent.AddListener(callback);
                }
                triggersCallbacks[tag].Add(type, unityEvent);
            }
        }
        else
        {
            UnityEvent <Collider> unityEvent = new UnityEventCollider();
            foreach (var callback in callbacks)
            {
                unityEvent.AddListener(callback);
            }
            Dictionary <InteractionType, UnityEvent <Collider> > dictionary = new Dictionary <InteractionType, UnityEvent <Collider> >();
            dictionary.Add(type, unityEvent);
            triggersCallbacks.Add(tag, dictionary);
        }
    }