Exemplo n.º 1
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
    }
Exemplo n.º 2
0
 private void TurnOn()
 {
     timeUntilToggle += DurOn;
     myProp.SetIsOn(true);
 }