// Returns unique identifier incase one wasn't provided
        public int AddInteractable(IInteractable a_interactable, InteractionEventType a_eventType = null,
                                   InteractableTypeReference a_identifier = null)
        {
            int finalIdentifier;

            if (a_identifier == null)
            {
                finalIdentifier = finalIdentifier = GenerateUniqueIdentifier();
            }
            else
            {
                finalIdentifier = a_identifier.GUID;
            }

    #if DEBUG
            if (m_interactables.ContainsKey(finalIdentifier))
            {
                throw new System.InvalidOperationException("identifier already registered: " + finalIdentifier);
            }
    #endif
            m_interactables.Add(finalIdentifier, a_interactable);
            m_registeredIdentifiers.Add(finalIdentifier);

            // add eventType filter
            if (a_eventType != null)
            {
                m_interactablesEventTypeFilter.Add(finalIdentifier, a_eventType);
            }
            return(finalIdentifier);
        }
示例#2
0
 public void TriggerOnDeEquip(InteractableCollection a_interactableCollection,
                              InteractableCollection a_invokerInteractableCollection,
                              InteractionEventType a_eventType = null,
                              int a_identifier = int.MinValue)
 {
     for (int i = 0; i < m_onDeEquip.Count; i++)
     {
         m_onDeEquip[i].Invoke(a_interactableCollection, a_eventType, a_identifier, a_invokerInteractableCollection);
     }
 }
示例#3
0
        public void TriggerOnUpdate(InteractableCollection a_interactableCollection,
                                    InteractableCollection a_invokerInteractableCollection,
                                    InteractionEventType a_eventType = null,
                                    int a_identifier = int.MinValue)
        {
            for (int i = 0; i < m_onUpdate.Count; i++)
            {
                m_onUpdate[i].Invoke(a_interactableCollection, a_eventType, a_identifier, a_invokerInteractableCollection);
            }

            m_effectRemoval.Update();
        }
        public T LocateInteractable <T>(System.Type a_type = null, InteractionEventType a_eventType = null,
                                        int a_identifier   = int.MinValue)
            where T : class, IInteractable
        {
            System.Type findType = a_type;
            if (findType == null)
            {
                findType = typeof(T);
            }

            KeyValuePair <int, IInteractable> interactablePair;

            // Filter by only type or ALSO identifier
            if (a_identifier == int.MinValue)
            {
                interactablePair = m_interactables.FirstOrDefault(p => findType == p.Value.GetType());
            }
            else
            {
                interactablePair = m_interactables.FirstOrDefault(p => findType == p.Value.GetType() && p.Key == a_identifier);
            }

            // remove in case it's filtered out of the event type
            if (a_eventType != null)
            {
                int interactableIndex = interactablePair.Key;
                // a filter exists
                if (m_interactablesEventTypeFilter.ContainsKey(interactableIndex))
                {
                    InteractionEventType filteredEventType;
                    m_interactablesEventTypeFilter.TryGetValue(interactableIndex, out filteredEventType);
                    if (filteredEventType != null && filteredEventType.GUID == a_eventType.GUID)
                    {
                        return(null);
                    }
                }
            }
            return(interactablePair.Value as T);
        }