2024-11-18 15:46:45 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
2024-12-20 11:33:06 +08:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using UnityEngine;
|
2024-11-18 15:46:45 +08:00
|
|
|
|
using DG.Tweening;
|
2024-12-20 11:33:06 +08:00
|
|
|
|
using Debug = UnityEngine.Debug;
|
2024-11-18 15:46:45 +08:00
|
|
|
|
|
|
|
|
|
|
2024-12-20 11:33:06 +08:00
|
|
|
|
public enum minerState
|
2024-11-18 15:46:45 +08:00
|
|
|
|
{
|
|
|
|
|
stand,
|
|
|
|
|
move,
|
|
|
|
|
dig
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class minerControl : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
[Header("<22><>find<6E><64>Ҫ<EFBFBD><D2AA>")]
|
|
|
|
|
public SpriteAniationpro myAni;
|
|
|
|
|
[Header("<22><>find")]
|
|
|
|
|
public List<Path> paths;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
[Header("<22><>·ʱ<C2B7><CAB1>,<2C><>find")]
|
|
|
|
|
public float pathsNeedTimer = 30f;
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|
|
|
|
[Header("<22>ڿ<EFBFBD>ʱ<EFBFBD><CAB1>,<2C><>find")]
|
|
|
|
|
public float fishingNeedTimer = 30f;
|
|
|
|
|
//<2F><>Ϣʱ<CFA2><CAB1>
|
|
|
|
|
[Header("<22><>Ϣʱ<CFA2><CAB1>,<2C><>find")]
|
|
|
|
|
public float restTimer = 5f;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɵ<EFBFBD>,<2C><>find")]
|
|
|
|
|
public Transform startPos;
|
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD>,<2C><>find")]
|
|
|
|
|
public Transform endPos;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[Range(0f, 1f)]
|
|
|
|
|
public float probabilityOfStand = 0.2f;//վ<><D5BE>״̬
|
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD>")]
|
|
|
|
|
[Range(0f, 1f)]
|
|
|
|
|
public float probabilityOfWalk = 0.3f;//<2F><>·״̬
|
|
|
|
|
[Header("<22><><EFBFBD><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF>ĸ<EFBFBD><C4B8><EFBFBD>")]
|
|
|
|
|
[Range(0f, 1f)]
|
|
|
|
|
public float probabilityOfDig = 0.5f;//<2F>ڿ<EFBFBD>״̬
|
|
|
|
|
|
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Awake()
|
|
|
|
|
{
|
|
|
|
|
myAni = transform.GetComponent<SpriteAniationpro>();
|
|
|
|
|
if (myAni==null)
|
|
|
|
|
{
|
|
|
|
|
Debug.LogError("myAni==null");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void init(List<Path> path,float pathsNeedTimer,float fishingNeedTimer,float restTimer,Transform startPos,Transform endPos)
|
|
|
|
|
{
|
|
|
|
|
this.paths = path;
|
|
|
|
|
this.pathsNeedTimer = pathsNeedTimer;
|
|
|
|
|
this.fishingNeedTimer = fishingNeedTimer;
|
|
|
|
|
this.restTimer = restTimer;
|
|
|
|
|
this.startPos = startPos;
|
|
|
|
|
this.endPos = endPos;
|
2024-12-20 11:33:06 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (Vector3.Distance(this.transform.position, startPos.position) <= 0.01f)
|
|
|
|
|
{
|
|
|
|
|
//Debug.LogWarning("11111111111111");
|
|
|
|
|
MoveToFishingPos();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// Debug.LogWarning("22222222222222222");
|
|
|
|
|
dig();
|
|
|
|
|
}
|
2024-11-18 15:46:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SetState(minerState newState)
|
|
|
|
|
{
|
|
|
|
|
switch (newState)
|
|
|
|
|
{
|
|
|
|
|
case minerState.stand:
|
|
|
|
|
myAni.SetAni(0);
|
|
|
|
|
break;
|
|
|
|
|
case minerState.move:
|
|
|
|
|
myAni.SetAni(1);
|
|
|
|
|
break;
|
|
|
|
|
case minerState.dig:
|
|
|
|
|
myAni.SetAni(2);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void MoveToFishingPos()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
// <20><><EFBFBD><EFBFBD>ѡ<EFBFBD><D1A1>һ<EFBFBD><D2BB>·<EFBFBD><C2B7>
|
|
|
|
|
Path selectedPath = paths[Random.Range(0, paths.Count)];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// <20>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD>ڿ<EFBFBD><DABF><EFBFBD>
|
|
|
|
|
StartCoroutine(MoveToFishingPoint(selectedPath.pathPoints));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
IEnumerator MoveToFishingPoint(List<Transform> path)
|
|
|
|
|
{
|
|
|
|
|
// <20><>·<EFBFBD><C2B7><EFBFBD><EFBFBD>ת<EFBFBD><D7AA>Ϊ Vector3 <20><><EFBFBD><EFBFBD>
|
|
|
|
|
Vector3[] pathPoints = new Vector3[path.Count];
|
|
|
|
|
for (int i = 0; i < path.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
pathPoints[i] = path[i].position;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//<2F>ı䳯<C4B1><E4B3AF>
|
|
|
|
|
ChangeShipLook(pathPoints[0], pathPoints[path.Count - 1]);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>仯,<2C>ƶ<EFBFBD>
|
|
|
|
|
//fishManShipContorl.SetAni(1);
|
|
|
|
|
SetState(minerState.move);
|
|
|
|
|
|
|
|
|
|
// ʹ<><CAB9> DOPath <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>仯
|
|
|
|
|
yield return transform.DOPath(pathPoints, pathsNeedTimer, PathType.CatmullRom)
|
|
|
|
|
.SetOptions(false) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
|
|
|
|
|
.SetEase(Ease.InOutSine)
|
|
|
|
|
.WaitForCompletion();
|
|
|
|
|
//<2F>ڿ<EFBFBD>
|
|
|
|
|
dig();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void dig()
|
|
|
|
|
{
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD>仯,<2C><><EFBFBD><EFBFBD>
|
|
|
|
|
//fishManShipContorl.SetAni(2);
|
|
|
|
|
SetState(minerState.dig);
|
|
|
|
|
StartCoroutine(movetoStatrPos());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator movetoStatrPos()
|
|
|
|
|
{
|
|
|
|
|
yield return new WaitForSeconds(3);
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
transform.rotation = Quaternion.Euler(0, 180, 0);
|
|
|
|
|
SetState(minerState.move);
|
|
|
|
|
Vector3[] ve = { endPos.position, startPos.position };
|
|
|
|
|
// ʹ<><CAB9> DOPath <20><><EFBFBD><EFBFBD>·<EFBFBD><C2B7><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>㣬<EFBFBD><E3A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>仯
|
|
|
|
|
yield return transform.DOPath(ve, pathsNeedTimer, PathType.CatmullRom)
|
|
|
|
|
.SetOptions(false) // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ת
|
|
|
|
|
.SetEase(Ease.InOutSine)
|
|
|
|
|
.WaitForCompletion();
|
|
|
|
|
|
|
|
|
|
SetState(minerState.stand);
|
|
|
|
|
yield return new WaitForSeconds(3);
|
|
|
|
|
MoveToFishingPos();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//<2F><><EFBFBD><EFBFBD>ǰ<EFBFBD><C7B0>λ<EFBFBD>øı䳯<C4B1><E4B3AF>
|
|
|
|
|
void ChangeShipLook(Vector3 _startpos, Vector3 _endpos)
|
|
|
|
|
{
|
|
|
|
|
if (_startpos.x > _endpos.x)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>");
|
|
|
|
|
transform.rotation = Quaternion.Euler(0, 180, 0);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("<22><><EFBFBD><EFBFBD><EFBFBD>ұ<EFBFBD>");
|
|
|
|
|
transform.rotation = Quaternion.Euler(0, 0, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|