Exemplo n.º 1
0
    void OnSwitchItemRequest(SwitchItemRequest request)
    {
        if (!enabled)
        {
            return;
        }

        request.WaitForResponse = true;
        IsActive = false;

        // Forbid to reactivate this item.
        IsSwitchingOut     = true;
        SwitchOutRequestor = request.Sender;
    }
Exemplo n.º 2
0
    void FixedUpdate()
    {
        // Delay everything else when waiting for switch-out response.
        if (waitingForResponse)
        {
            if (transform.childCount == 0)
            {
                // Item was destroyed while we waited a response message from it.
                waitingForResponse = false;
                PerformSwitch();
            }
            else
            {
                return;
            }
        }

        // Item activation/deactivation.
        if (CarriedItemIsActive != prevCarriedItemIsActive || !itemActivationInitialized)
        {
            if (CarriedItemIsActive)
            {
                carriedItemActivatedTimestamp = Time.fixedTime;
                waitingForActivationDelay     = true;
            }
            else
            {
                SetItemActive(false);
            }

            prevCarriedItemIsActive   = CarriedItemIsActive;
            itemActivationInitialized = true;
        }

        if (CarriedItemIsActive && waitingForActivationDelay && Time.fixedTime - carriedItemActivatedTimestamp >= ItemActivationDelay)
        {
            SetItemActive(true);
            waitingForActivationDelay = false;
        }

        /* TODO: develop switching to nothing. Currently it is not possible
         * because NextItemPrefab set to null signals that no switch was requested. */
        // Initiate switch message sequence if needed.
        if (NextItemPrefab != CurrentItemPrefab && NextItemPrefab != null)
        {
            if (!CarriedItemIsActive && DelaySwitchTillActive)
            {
                return;
            }

            if (SwitchingPermitted)
            {
                var switchRequest = new SwitchItemRequest(this);
                BroadcastMessage(SwitchItemRequest.MessageName, switchRequest, SendMessageOptions.DontRequireReceiver);

                if (!switchRequest.WaitForResponse)
                {
                    // No need to wait, switch immediately.
                    PerformSwitch();
                }
                else
                {
                    waitingForResponse = true;
                }
            }
            else
            {
                NextItemPrefab = null;
            }
        }
    }