185 lines
4.8 KiB
C#
185 lines
4.8 KiB
C#
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 hashCode;
|
|
public MonsterDataBase monsterData = new MonsterDataBase(new MonsterHealthBase());
|
|
public SkeletonAnimation skeleton;
|
|
public bool isSpine = true;
|
|
|
|
public Dictionary<CharacterAnimationType, string> dic_AnimKeyAnimName = new Dictionary<CharacterAnimationType, string>();
|
|
public CharacterStateType currState;
|
|
public GameObject effect_Hurt;//遮罩闪烁
|
|
public int HP = 5;
|
|
public GameObject effect_Die;//删除
|
|
GameObject hurt;
|
|
public FishTypeEnum fishType=FishTypeEnum.普通鱼;
|
|
//递归查找子物体
|
|
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)
|
|
{
|
|
monsterData.moveLine.Init(bezierCurveData, 10);
|
|
isyz = isyuzhen;
|
|
if (bezierCurveData.start.y>0)
|
|
{
|
|
transform.Rotate(Vector3.forward * 180);
|
|
}
|
|
}
|
|
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)
|
|
{
|
|
case "30001":
|
|
moveTime += Time.deltaTime;
|
|
var movestart=monsterData.moveLine.bezierCurveData.start;
|
|
Vector2 v2 = movestart+(Vector2)(transform.up*moveTime* monsterData.moveLine.moveTime);
|
|
transform.position = v2;
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
moveTime += Time.deltaTime;
|
|
Vector2 v2 = monsterData.moveLine.GetBezierPoint(moveTime);
|
|
if (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)
|
|
{
|
|
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);
|
|
}
|
|
|
|
|
|
|
|
}
|