private void AnimateAttitudeChange() { float passedSecs = Time.time - attitudeAnimationStartTime; float animSpeed = passedSecs/ATTITUDE_INDICATOR_SHOW_TIME; switch(attitudeAnimState) { case ATTITUDE_ANIM_STATE.FADE_IN: attitudeFade += ATTITUDE_ANIMATION_FADE_STEP; if(attitudeFade > 1.0f) { attitudeAnimationStartTime = Time.time; attitudeFade = 1.0f; if(attitude == oldAttitude) { attitudeAnimState = ATTITUDE_ANIM_STATE.VISIBLE; } else if(attitude < oldAttitude) { attitudeAnimState = ATTITUDE_ANIM_STATE.SHOW_DECREASE; } else { attitudeAnimState = ATTITUDE_ANIM_STATE.SHOW_INCREASE; } } animateThis.SetFloat("_Blend", attitudeFade); break; case ATTITUDE_ANIM_STATE.SHOW_INCREASE: if(passedSecs > ATTITUDE_INDICATOR_SHOW_TIME) { attitudeAnimState = ATTITUDE_ANIM_STATE.FADE_OUT; } transform.localScale = new Vector3(Mathf.Lerp(defaultScale.x, defaultScale.x + ATTITUDE_DISPLAY_SCALE_CHANGE, animSpeed), Mathf.Lerp(defaultScale.y, defaultScale.y + ATTITUDE_DISPLAY_SCALE_CHANGE, animSpeed), defaultScale.z); break; case ATTITUDE_ANIM_STATE.SHOW_DECREASE: if(passedSecs > ATTITUDE_INDICATOR_SHOW_TIME) { attitudeAnimState = ATTITUDE_ANIM_STATE.FADE_OUT; } transform.localScale = new Vector3(Mathf.Lerp(defaultScale.x, defaultScale.x - ATTITUDE_DISPLAY_SCALE_CHANGE, animSpeed), Mathf.Lerp(defaultScale.y, defaultScale.y - ATTITUDE_DISPLAY_SCALE_CHANGE, animSpeed), defaultScale.z); break; case ATTITUDE_ANIM_STATE.VISIBLE: if(passedSecs > ATTITUDE_INDICATOR_SHOW_TIME) { attitudeAnimState = ATTITUDE_ANIM_STATE.FADE_OUT; } break; case ATTITUDE_ANIM_STATE.FADE_OUT: attitudeFade -= ATTITUDE_ANIMATION_FADE_STEP; if(attitudeFade < 0) { attitudeAnimState = ATTITUDE_ANIM_STATE.NONE; CancelInvoke(); InitDrunknessAnimation(); attitudeFade = 0.0f; } animateThis.SetFloat("_Blend", attitudeFade); break; } }
private void InitAttitudeAnimations() { CancelInvoke(); // lets make sure that there are no other animations playing attitudeFade=0; enabled = true; renderer.enabled = true; attitudeAnimState = ATTITUDE_ANIM_STATE.FADE_IN; showState = SHOW_STATE.SHOWING_ATTITUDE; animateThis.SetTexture("_MainTex", GetAttitudeTexture()); animateThis.SetFloat("_Blend", 0); transform.localScale = new Vector3(billboardDefSize.x, billboardDefSize.y, billboardDefSize.z); }
/************************************************************** * * PRIVATE METHODS * **************************************************************/ private void AnimateAttitude() { switch(attitudeAnimState) { case ATTITUDE_ANIM_STATE.FADE_IN: attitudeFade += ATTITUDE_ANIMATION_FADE_STEP; if(attitudeFade > 1.0f) { attitudeAnimState = ATTITUDE_ANIM_STATE.VISIBLE; attitudeAnimationStartTime = Time.time; attitudeFade = 1.0f; } animateThis.SetFloat("_Blend", attitudeFade); break; case ATTITUDE_ANIM_STATE.VISIBLE: if(Time.time - attitudeAnimationStartTime > ATTITUDE_INDICATOR_SHOW_TIME) { attitudeAnimState = ATTITUDE_ANIM_STATE.FADE_OUT; } break; case ATTITUDE_ANIM_STATE.FADE_OUT: attitudeFade -= ATTITUDE_ANIMATION_FADE_STEP; if(attitudeFade < 0) { attitudeAnimState = ATTITUDE_ANIM_STATE.NONE; CancelInvoke(); InitDrunknessAnimation(); attitudeFade = 0.0f; //Debug.Log("StatusIndicatorBillboard.AnimateAttitude(): terminating animation of " + character.name); } animateThis.SetFloat("_Blend", attitudeFade); break; } }