Exemplo n.º 1
0
    // ----------------------------------------------------------------
    //  Update
    // ----------------------------------------------------------------
    private void Update()
    {
        // Safety check for edit-mode.
        if (myProp == null)
        {
            myProp = GetComponent <IOnOffable>();
        }

        timeUntilToggle -= GameTimeController.RoomDeltaTime;
        // ALMOST back ON?
        if (!myProp.IsOn() && timeUntilToggle < 0.25f)
        {
            myProp.UpdateAlmostOn(timeUntilToggle);
        }
        // Time to toggle?
        if (timeUntilToggle <= 0)
        {
            if (myProp.IsOn())
            {
                TurnOff();
            }
            else
            {
                TurnOn();
            }
        }
    }
Exemplo n.º 2
0
    // ----------------------------------------------------------------
    //  Initialize
    // ----------------------------------------------------------------
    public void Initialize(IOnOffable myProp, OnOfferData data)
    {
        this.myProp = myProp;
        DurOn       = data.durOn;
        DurOff      = data.durOff;
        StartOffset = data.startOffset;

        // Make appliedOffset, which is StartOffset between 0 and total-dur.
        float durTotal      = DurOn + DurOff;
        float appliedOffset = StartOffset;

        if (appliedOffset < 0)
        {
            appliedOffset += durTotal;
        }
        appliedOffset = appliedOffset % (durTotal);

        // Use StartOffset!
        timeUntilToggle  = DurOn;
        timeUntilToggle -= appliedOffset;
        if (timeUntilToggle >= 0)   // start ON with this much time left.
        {
            myProp.SetIsOn(true);
        }
        else   // start OFF with this much time left.
        {
            timeUntilToggle += DurOff;
            myProp.SetIsOn(false);
        }

        // Move OnOffer component just under my Script, for easiness.
        #if UNITY_EDITOR
        UnityEditorInternal.ComponentUtility.MoveComponentUp(this);
        UnityEditorInternal.ComponentUtility.MoveComponentUp(this);
        UnityEditorInternal.ComponentUtility.MoveComponentUp(this);
        UnityEditorInternal.ComponentUtility.MoveComponentUp(this);
        UnityEditorInternal.ComponentUtility.MoveComponentUp(this);
        UnityEditorInternal.ComponentUtility.MoveComponentUp(this);
        UnityEditorInternal.ComponentUtility.MoveComponentDown(this);
        #endif
    }