角色選擇組件

using UnityEngine;
using System.Collections;
/// <summary>
/// 角色選擇組件
/// </summary>
public class CharacterChoise : MonoBehaviour {
	
	public Occupation occupation;//職業信息
	public Character character;//角色信息
	public Transform perspective;//相機視角
	public Transform look;//視點
	Animator animator;//當前動畫組件
	
	#region 高光組件
	public HighlightableObject highLight;//高光組件
	public Color highColor;//高光顏色
	#endregion
	
	void Start() {
		//獲取移動點
		perspective = GameObject.Find(occupation.ToString() + "_perspective").transform;
		look = transform.Find("look");
		
		//初始化角色信息
		if(character == null){
			switch(occupation){
				case Occupation.Assassin: character = new Assassin();initHighLight(Color.magenta); break;
				case Occupation.Berserker: character = new Berserker();initHighLight(Color.blue); break;
				case Occupation.Enchanter: character = new Enchanter();initHighLight(Color.yellow); break;
				case Occupation.Paladin: character = new Paladin();initHighLight(Color.green); break;
			}
			character.initAtt();
		}
		animator = GetComponent<Animator>();
	}
	
	/// <summary>
	/// 擺姿式(選中)
	/// </summary>
	public void Pose(){
		if(animator != null){
			animator.SetBool("IsIdle",false);
			animator.SetBool("IsPose",true);
		}else{
			animation.CrossFade("Attack");
		}
	}
	
	/// <summary>
	/// 空閒(未選中)
	/// </summary>
	public void Idle(){
		if(animator != null){
			animator.SetBool("IsIdle",true);
			animator.SetBool("IsPose",false);
		}else{
			animation.CrossFade("Idle");
		}
	}
	
	/// <summary>
	/// 初始化高光組件
	/// </summary>
	void initHighLight(Color color){
		highLight = gameObject.AddComponent<HighlightableObject>();
		highColor = color;
	}
	
	/// <summary>
	/// 鼠標進入:高光
	/// </summary>
	void OnMouseEnter(){
		highLight.ConstantOn(highColor);
	}
	
	/// <summary>
	/// 鼠標離開:無光
	/// </summary>
	void OnMouseExit(){
		highLight.ConstantOff();
	}
}
相關文章
相關標籤/搜索