角色选择组件
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(); } }