361 lines
12 KiB
C#
361 lines
12 KiB
C#
#region AI优化
|
|
#endregion
|
|
|
|
|
|
#region zijixie
|
|
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 enum type
|
|
public class MonsterContral : MonoBehaviour
|
|
{
|
|
public string guid;
|
|
public MonsterDataBase monsterData = new MonsterDataBase(new MonsterHealthBase());
|
|
public SkeletonAnimation skeleton;
|
|
public bool isSpine = true;
|
|
public string fishTypeID;
|
|
public Dictionary<CharacterAnimationType, string> dic_AnimKeyAnimName = new Dictionary<CharacterAnimationType, string>();
|
|
public CharacterStateType currState;
|
|
public int HP = 5;
|
|
public GameObject effect_Die;//删除
|
|
GameObject hurt;
|
|
public bool isMove = true;
|
|
public bool is3D = false;
|
|
public string forwordXYZ;
|
|
public virtual void DieFish(object obj=null)
|
|
{
|
|
Destroy(gameObject);
|
|
}
|
|
//递归查找子物体
|
|
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 virtual void Init(string pathId, float Time, bool isyuzhen = false, string yzID = "")
|
|
{
|
|
BezierCurveData bezierCurveData;
|
|
if (isyuzhen)
|
|
{
|
|
bezierCurveData = MonsterMoveLine.dic_BezierCurveDatas["鱼阵" + pathId];
|
|
}
|
|
else
|
|
{
|
|
bezierCurveData = MonsterMoveLine.dic_BezierCurveDatas["曲线" + pathId];
|
|
}
|
|
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);
|
|
}
|
|
public virtual 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()
|
|
{
|
|
|
|
}
|
|
public 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<RectTransform>(), 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<RectTransform>(), Camera.main);
|
|
//Debug.Log("movestart:" + movestart);
|
|
{
|
|
Vector2 v2 = movestart + (Vector2)(-1 * transform.up * moveTime * monsterData.moveLine.moveTime);
|
|
transform.position = v2;
|
|
}
|
|
|
|
break;
|
|
case "702":
|
|
case "710":
|
|
moveTime += Time.deltaTime;
|
|
{
|
|
//Vector2 v2 = monsterData.moveLine.GetBezierPoint(moveTime);
|
|
Vector2 v2 = monsterData.moveLine.GetBezierPointJob(moveTime);
|
|
|
|
if ((FishTypeEnum)monsterData.fishTypeConfig.fishType != FishTypeEnum.Boss鱼)
|
|
{
|
|
switch (forwordXYZ)
|
|
{
|
|
case "X":
|
|
transform.right = (v2 - (Vector2)transform.position).normalized;
|
|
break;
|
|
case "Y":
|
|
transform.up = (v2 - (Vector2)transform.position).normalized;
|
|
break;
|
|
case "Z":
|
|
|
|
|
|
transform.forward = (v2 - (Vector2)transform.position).normalized;
|
|
break;
|
|
case "-X":
|
|
transform.right = ((Vector2)transform.position - v2).normalized;
|
|
break;
|
|
case "-Y":
|
|
transform.up = ((Vector2)transform.position - v2).normalized;
|
|
break;
|
|
case "-Z":
|
|
transform.forward = ((Vector2)transform.position - v2).normalized;
|
|
break;
|
|
|
|
default:
|
|
transform.up = ((Vector2)transform.position - v2).normalized;
|
|
break;
|
|
}
|
|
//transform.up = ((Vector2)transform.position - v2).normalized;
|
|
}
|
|
transform.position = v2;
|
|
}
|
|
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
|
|
moveTime += Time.deltaTime;
|
|
Vector2 v2 = monsterData.moveLine.GetBezierPointJob(moveTime);
|
|
|
|
if ((FishTypeEnum)monsterData.fishTypeConfig.fishType != FishTypeEnum.Boss鱼)
|
|
{
|
|
if (forwordXYZ == "" || forwordXYZ == null)
|
|
{
|
|
if (!is3D)
|
|
{
|
|
transform.up = ((Vector2)transform.position - v2).normalized;
|
|
}
|
|
else
|
|
{
|
|
transform.forward = (v2 - (Vector2)transform.position).normalized;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
switch (forwordXYZ)
|
|
{
|
|
case "X":
|
|
transform.right = (v2 - (Vector2)transform.position).normalized;
|
|
break;
|
|
case "Y":
|
|
transform.up = (v2 - (Vector2)transform.position).normalized;
|
|
break;
|
|
case "Z":
|
|
transform.forward = (v2 - (Vector2)transform.position).normalized;
|
|
break;
|
|
case "-X":
|
|
transform.right = ((Vector2)transform.position - v2).normalized;
|
|
break;
|
|
case "-Y":
|
|
transform.up = ((Vector2)transform.position - v2).normalized;
|
|
break;
|
|
case "-Z":
|
|
transform.forward = ((Vector2)transform.position - v2).normalized;
|
|
break;
|
|
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
#endregion |