Ejemplo n.º 1
0
    public void Press(bool press)
    {
        pressed = press;
        if (releaseTime <= 0)
        {
            currentReleaseTime = releaseTime;
            //if (press) {
            //    GetComponent<Animator>().Play("ButtonDown");
            //} else {
            //    GetComponent<Animator>().Play("ButtonUp");
            //}
        }
        else
        {
            if (press == true)
            {
                //if (!timerPressed) {
                //    GetComponent<Animator>().Play("ButtonDown");
                //}
                timerPressed       = true;
                currentReleaseTime = releaseTime;
            }
        }

        // Activate like normally if this button isn't connected to a combinator (logic gate)
        if (combinator == null)
        {
            if (pressed)
            {
                foreach (GameObject listener in onListeners)
                {
                    // All types of listeners go here to keep things nice n tidy
                    MovingPlatform mp = listener.GetComponent <MovingPlatform>();
                    ObjectChute    oc = listener.GetComponent <ObjectChute>();
                    Teleporter     tp = listener.GetComponent <Teleporter>();

                    if (mp != null)
                    {
                        mp.activated = true;
                    }
                    if (oc != null)
                    {
                        oc.SpawnObject(true);
                    }
                    if (tp != null)
                    {
                        tp.DoTeleport();
                    }
                }
            }
            else
            {
                foreach (GameObject listener in offListeners)
                {
                    // All types of listeners go here to keep things nice n tidy
                    MovingPlatform mp = listener.GetComponent <MovingPlatform>();
                    ObjectChute    oc = listener.GetComponent <ObjectChute>();
                    Teleporter     tp = listener.GetComponent <Teleporter>();

                    if (mp != null)
                    {
                        mp.activated = false;
                    }
                    if (oc != null)
                    {
                        oc.SpawnObject(true);
                    }
                    if (tp != null)
                    {
                        tp.DoTeleport();
                    }
                }
            }
        }
        else
        {
            // No need to notify the combinator or anything -- it's always listening. <_<
        }
    }
    void Update()
    {
        bool allActivated = true;
        bool oneActivated = false;

        foreach (GameObject activator in activators)
        {
            PushButton button = activator.GetComponent <PushButton>();
            if (button != null)
            {
                if (button.pressed)
                {
                    oneActivated = true;
                }
                else
                {
                    allActivated = false;
                }
            }
        }

        activatedPreviously = activated;

        switch (gateType)
        {
        case CombinationGateType.AND:
            if (allActivated)
            {
                activated = true;
            }
            break;

        case CombinationGateType.OR:
            if (oneActivated)
            {
                activated = true;
            }
            break;

        case CombinationGateType.XOR:
            if (oneActivated && !allActivated)
            {
                activated = true;
            }
            break;
        }

        // Check to see if a change happened
        if (activated != activatedPreviously)
        {
            if (activated)
            {
                foreach (GameObject listener in onListeners)
                {
                    // All types of listeners go here to keep things nice n tidy
                    MovingPlatform mp = listener.GetComponent <MovingPlatform>();
                    ObjectChute    oc = listener.GetComponent <ObjectChute>();
                    Teleporter     tp = listener.GetComponent <Teleporter>();

                    if (mp != null)
                    {
                        mp.activated = true;
                    }
                    if (oc != null)
                    {
                        oc.SpawnObject(true);
                    }
                    if (tp != null)
                    {
                        tp.DoTeleport();
                    }
                }
            }
            else
            {
                foreach (GameObject listener in offListeners)
                {
                    // All types of listeners go here to keep things nice n tidy
                    MovingPlatform mp = listener.GetComponent <MovingPlatform>();
                    ObjectChute    oc = listener.GetComponent <ObjectChute>();
                    Teleporter     tp = listener.GetComponent <Teleporter>();

                    if (mp != null)
                    {
                        mp.activated = false;
                    }
                    if (oc != null)
                    {
                        oc.SpawnObject(true);
                    }
                    if (tp != null)
                    {
                        tp.DoTeleport();
                    }
                }
            }
        }
    }