using Assets.MyGame.Scripts.Net.API.GameConfig_SubClass; using Assets.MyGame.Scripts.Net.APIResponses.Enum; using Spine; using Spine.Unity; using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; using static MonsterMoveLine; public class MonsterContral : MonoBehaviour { public string guid; public MonsterDataBase monsterData = new MonsterDataBase(new MonsterHealthBase()); public SkeletonAnimation skeleton; public bool isSpine = true; public Dictionary dic_AnimKeyAnimName = new Dictionary(); public CharacterStateType currState; public GameObject effect_Hurt;//遮罩闪烁 public int HP = 5; public GameObject effect_Die;//删除 GameObject hurt; public bool isMove = true; //递归查找子物体 Transform FindDeepChild(Transform parent, string name) { foreach (Transform child in parent) { if (child.name == name) return child; var result = FindDeepChild(child, name); if (result != null) return result; } return null; } public void Init(BezierCurveData bezierCurveData, float Time, bool isyuzhen = false, string yzID = "") { monsterData.moveLine.Init(bezierCurveData, Time); isyz = isyuzhen; this.yzID = yzID; if (yzID != "") switch (yzID.Substring(0, 3)) { case "700": if (bezierCurveData.start.y < 0) { //float z = transform.localEulerAngles.z; transform.localEulerAngles = new Vector3(0, 0, z + 180); //transform.rotation= Quaternion.Euler(Vector3.forward*180+transform.eulerAngles); var v = transform.localScale; v.y *= -1; transform.localScale = v; } break; case "701": break; default: break; } switch ((FishTypeEnum)monsterData.fishTypeConfig.fishType) { case FishTypeEnum.普通鱼: Destroy(gameObject, Time); break; case FishTypeEnum.Boss鱼: Destroy(gameObject, Time); break; case FishTypeEnum.黄金鱼: Destroy(gameObject, Time); break; case FishTypeEnum.特殊鱼: Destroy(gameObject, Time); break; default: break; } } public void OnDestroy() { CreateFishManager.Instance.fishDatas_hashCodekey.Remove(guid); } private void Awake() { var t = FindDeepChild(transform, "HitEffect"); if (t != null) { hurt = t.gameObject; hurt.SetActive(false); } } public void OnHurt() { if (hurt != null) { StartCoroutine(Hurt()); } } //受击闪烁 IEnumerator Hurt() { hurt.SetActive(true); yield return new WaitForSeconds(0.2f); hurt.SetActive(false); } public void InitAnimList() { dic_AnimKeyAnimName.Add(CharacterAnimationType.move, "stand2"); } //这里捕鱼的结构很简单可以穿模直接写移动 void Update() { OnUpdate(currState); } public void Start() { InitAnimList(); ChangeState(CharacterStateType.move); } public virtual void OnMoveEnter() { PlayAnim(CharacterAnimationType.move); //播放动画 //skeleton.AnimationState.SetAnimation(0, dic_AnimKeyAnimName[CharacterAnimationType.move], true); } public virtual void OnMoveExit() { } float moveTime = 0; public bool isyz = false; public string yzID = ""; public virtual void OnMoveUpdata() { if (isyz) { switch (yzID.Substring(0, 3)) { //向正前方移动 case "700": moveTime += Time.deltaTime; //可优化 var movestart = monsterData.moveLine.bezierCurveData.start; movestart = CoordinateTransformation.CanvasToWorld(movestart, UIManager.Instance.uiRoot.GetComponent(), Camera.main); //Debug.Log("movestart:"+movestart); if (monsterData.moveLine.bezierCurveData.start.y > 0) { Vector2 v2 = movestart + (Vector2)(-1 * transform.up * moveTime * monsterData.moveLine.moveTime); transform.position = v2; } else { Vector2 v2 = movestart + (Vector2)(transform.up * moveTime * monsterData.moveLine.moveTime); transform.position = v2; } //Vector2 v2 = movestart+(Vector2)(-1*transform.up*moveTime* monsterData.moveLine.moveTime); //transform.position = v2; break; case "701": moveTime += Time.deltaTime; //可优化 movestart = monsterData.moveLine.bezierCurveData.start; movestart = CoordinateTransformation.CanvasToWorld(movestart, UIManager.Instance.uiRoot.GetComponent(), Camera.main); //Debug.Log("movestart:" + movestart); { Vector2 v2 = movestart + (Vector2)(-1 * transform.up * moveTime * monsterData.moveLine.moveTime); transform.position = v2; } break; case "702": moveTime += Time.deltaTime; { Vector2 v2 = monsterData.moveLine.GetBezierPoint(moveTime); if ( (FishTypeEnum)monsterData.fishTypeConfig.fishType != FishTypeEnum.Boss鱼) { transform.up = ((Vector2)transform.position - v2).normalized; } transform.position = v2; } break; default: break; } } else { moveTime += Time.deltaTime; Vector2 v2 = monsterData.moveLine.GetBezierPoint(moveTime); if ((FishTypeEnum)monsterData.fishTypeConfig.fishType != FishTypeEnum.Boss鱼) { transform.up = ((Vector2)transform.position - v2).normalized; } transform.position = v2; } } public void PlayAnim(CharacterAnimationType animType, bool loop = true) { if (skeleton != null) skeleton.AnimationState.SetAnimation(0, dic_AnimKeyAnimName[animType], loop); } public void OnEnter(CharacterStateType stateType) { switch (stateType) { case CharacterStateType.move: OnMoveEnter(); break; case CharacterStateType.idle: break; default: break; } } public void OnUpdate(CharacterStateType stateType) { if (!isMove) { return; } switch (stateType) { case CharacterStateType.move: OnMoveUpdata(); break; case CharacterStateType.idle: break; default: break; } } public void OnExit(CharacterStateType stateType) { switch (stateType) { case CharacterStateType.move: break; case CharacterStateType.idle: break; default: break; } } public void ChangeState(CharacterStateType stateType) { OnExit(currState); currState = stateType; OnEnter(currState); } }