73 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			73 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System.Collections; | |||
|  | using System.Collections.Generic; | |||
|  | using UnityEngine; | |||
|  | 
 | |||
|  | public class PetAvatar : MonoBehaviour | |||
|  | { | |||
|  |     private Animator mAnimator; | |||
|  |     private TimerUnit mIdleTimer; | |||
|  | 
 | |||
|  |     private void Awake() | |||
|  |     { | |||
|  |         mAnimator = GetComponentInChildren<Animator>(); | |||
|  |         mIdleTimer = TimerManager.Instance.CreateTimerUnit(); | |||
|  |         SwitchPose(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnDestroy() | |||
|  |     { | |||
|  |         if (mIdleTimer != null) | |||
|  |         { | |||
|  |             mIdleTimer.Destroy(); | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     public void Happy() | |||
|  |     { | |||
|  |         PlayAnimation("Happy"); | |||
|  |         SwitchPose(); | |||
|  |     } | |||
|  | 
 | |||
|  |     public void Courage() | |||
|  |     { | |||
|  |         PlayAnimation("Courage"); | |||
|  |         mIdleTimer.CancelTimer(); | |||
|  |     } | |||
|  | 
 | |||
|  |     public void Win() | |||
|  |     { | |||
|  |         PlayAnimation("Win"); | |||
|  |         mIdleTimer.CancelTimer(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void SwitchPose() | |||
|  |     { | |||
|  |         mIdleTimer.StartTimer(RandomPose, Random.Range(5f, 10f)); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void PlayAnimation(string pAniName) | |||
|  |     { | |||
|  |         mAnimator.CrossFade(pAniName, 0.2f); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void RandomPose() | |||
|  |     { | |||
|  |         int tRandomIndex = Random.Range(0, 4); | |||
|  |         if (tRandomIndex == 0) | |||
|  |         { | |||
|  |             PlayAnimation("Idle"); | |||
|  |         } | |||
|  |         else | |||
|  |         { | |||
|  |             PlayAnimation("Random" + tRandomIndex); | |||
|  |         } | |||
|  | 
 | |||
|  |         SwitchPose(); | |||
|  |     } | |||
|  | 
 | |||
|  |     private void OnMouseUpAsButton() | |||
|  |     { | |||
|  |         PlayAnimation("Tap" + Random.Range(1, 4)); | |||
|  |         SwitchPose(); | |||
|  |     } | |||
|  | } |