Ejemplo n.º 1
0
    void OnTriggerExit(Collider other)
    {
        Script_ReliableOnTriggerExit.NotifyTriggerExit(other, gameObject);
        print("onTriggerExit other.tag" + other.tag);
        print("onTriggerExit gameObject" + gameObject);
        if (
            other.tag == Const_Tags.ItemObject &&
            other.transform.parent.GetComponent <Script_CollectibleObject>() != null
            )
        {
            print("onTriggerExit other.transform.parent.GetComponent<Script_CollectibleObject>(): "
                  + other.transform.parent.GetComponent <Script_CollectibleObject>());
            isOn = false;
            collectibles.Remove(other.transform.parent.GetComponent <Script_CollectibleObject>());

            /// Don't notify if the deactivation is a result of tearing down level
            if (!isDisabled)
            {
                triggerPuzzleController.TriggerDeactivated(Id, other);
            }

            foreach (Script_CollectibleObject obj in collectibles)
            {
                Debug.Log(obj);
            }
        }
    }
Ejemplo n.º 2
0
    public static void NotifyTriggerExit(Collider c, GameObject caller)
    {
        if (c == null)
        {
            return;
        }

        Script_ReliableOnTriggerExit thisComponent = null;

        Script_ReliableOnTriggerExit[] ftncs = c.gameObject.GetComponents <Script_ReliableOnTriggerExit>();
        foreach (Script_ReliableOnTriggerExit ftnc in ftncs)
        {
            if (ftnc.thisCollider == c)
            {
                thisComponent = ftnc;
                break;
            }
        }
        if (thisComponent != null && thisComponent.ignoreNotifyTriggerExit == false)
        {
            thisComponent.waitingForOnTriggerExit.Remove(caller);
            if (thisComponent.waitingForOnTriggerExit.Count == 0)
            {
                thisComponent.enabled = false;
            }
        }
    }
Ejemplo n.º 3
0
    void OnTriggerEnter(Collider other)
    {
        Script_ReliableOnTriggerExit.NotifyTriggerEnter(other, gameObject, OnTriggerExit);
        if (
            other.tag == Const_Tags.ItemObject
            // check for if its a collectible
            && other.transform.parent.GetComponent <Script_CollectibleObject>() != null &&
            !isOn
            )
        {
            isOn = true;
            collectibles.Add(other.transform.parent.GetComponent <Script_CollectibleObject>());
            foreach (Script_CollectibleObject obj in collectibles)
            {
                print(obj);
            }

            if (!isInitializing && !isDisabled)
            {
                print("activating trigger: " + Id);
                triggerPuzzleController.TriggerActivated(Id, other);
            }
            else
            {
                Debug.Log($"reactivating trigger: {Id} on initialization");
                triggerPuzzleController.TriggerReactivated(Id, other);
            }
        }
    }
Ejemplo n.º 4
0
    public static void NotifyTriggerEnter(Collider c, GameObject caller, _OnTriggerExit onTriggerExit)
    {
        Script_ReliableOnTriggerExit thisComponent = null;

        Script_ReliableOnTriggerExit[] ftncs = c.gameObject.GetComponents <Script_ReliableOnTriggerExit>();
        foreach (Script_ReliableOnTriggerExit ftnc in ftncs)
        {
            if (ftnc.thisCollider == c)
            {
                thisComponent = ftnc;
                break;
            }
        }
        if (thisComponent == null)
        {
            thisComponent = c.gameObject.AddComponent <Script_ReliableOnTriggerExit>();
            thisComponent.thisCollider = c;
        }
        // Unity bug? (!!!!): Removing a Rigidbody while the collider is in contact will call OnTriggerEnter twice, so I need to check to make sure it isn't in the list twice
        // In addition, force a call to NotifyTriggerExit so the number of calls to OnTriggerEnter and OnTriggerExit match up
        if (thisComponent.waitingForOnTriggerExit.ContainsKey(caller) == false)
        {
            thisComponent.waitingForOnTriggerExit.Add(caller, onTriggerExit);
            thisComponent.enabled = true;
        }
        else
        {
            thisComponent.ignoreNotifyTriggerExit = true;
            thisComponent.waitingForOnTriggerExit[caller].Invoke(c);
            thisComponent.ignoreNotifyTriggerExit = false;
        }
    }