备份CatanBuilding瘦身独立工程

This commit is contained in:
JSD\13999
2026-05-26 16:15:54 +08:00
commit 2d0e6a61b7
12001 changed files with 2431925 additions and 0 deletions

View File

@@ -0,0 +1,640 @@
using asap.core;
using System;
using DG.Tweening;
using Game;
using GameCore;
using UnityEngine;
using Random = UnityEngine.Random;
using cfg;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.AddressableAssets;
public partial class FishingBehaviorB : MonoBehaviour
{
#region
float OldFishPos = -3f;
float jumpoutMaxCD = 0.2f;
float jumpoutCD = 0f;
public void JumpWater()
{
if (jumpoutCD > jumpoutMaxCD)
{
jumpoutCD = 0;
float newFishPos = GetFishPos().y;
if ((newFishPos - _waterHeight) * (OldFishPos - _waterHeight) < 0)
{
//进出水面
if (newFishPos > _waterHeight - 0.00001f)
{
Vector3 vector = _fish.transform.position;
vector.y = _waterHeight;
if (fx_fishing_water != null)
{
fx_fishing_water.transform.position = vector;
fx_fishing_water.gameObject.SetActive(false);
fx_fishing_water.gameObject.SetActive(true);
}
else if (fx_fishing_jumpout != null)
{
fx_fishing_jumpout.transform.position = vector;
fx_fishing_jumpout.gameObject.SetActive(false);
fx_fishing_jumpout.gameObject.SetActive(true);
}
//播音效
GContext.Publish(new EventFishingSound(SoundType.audio_fishing_jumpout));
}
else if (newFishPos < _waterHeight + 0.00001f)
{
Vector3 vector = _fish.transform.position;
vector.y = _waterHeight;
//进水面
if (fx_fishing_water != null)
{
fx_fishing_water.transform.position = vector;
fx_fishing_water.gameObject.SetActive(false);
fx_fishing_water.gameObject.SetActive(true);
}
else if (fx_fishing_jumpinto != null)
{
fx_fishing_jumpinto.transform.position = vector;
fx_fishing_jumpinto.gameObject.SetActive(false);
fx_fishing_jumpinto.gameObject.SetActive(true);
}
//播音效
GContext.Publish(new EventFishingSound(SoundType.audio_fishing_jumpinto));
}
}
OldFishPos = newFishPos;
}
jumpoutCD += Time.deltaTime;
}
#endregion
//跳跃相关
bool isJumping = false;
float JumpDistance = 1;
GameObject fx_fishing_water;
//GameObject fxWaterSplash;
GameObject fxHeadFishSkill;
GameObject fxFishJumpWaterSkill;
GameObject fxFishStruggleSkill;
GameObject fxAppendFishSkill;
public async void PlayFxFishSkill(IFishSpSkillData fishSpSkillData)
{
string fxFish = "";
string fxFishJumpWater = "";
string fxFishStruggle = "";
switch (fishSpSkillData.fishSkill.PerformanceType)
{
case FishPerformanceType.Jump:
//技能表现
fxFish = fishSpSkillData.FxFishJump();
fxFishJumpWater = fishSpSkillData.FxFishJumpWater();
break;
//case FishPerformanceType.Dash:
// break;
case FishPerformanceType.Struggle:
fxFishStruggle = fishSpSkillData.FxFishStruggle();
break;
}
string rootFx = fishSpSkillData.FxFishSkillAppend();
string fxWater = fishSpSkillData.FxWater();
//string fxWaterSplashName = fishSpSkillData.FxWaterSplash();
if (!string.IsNullOrEmpty(fxWater) && fx_fishing_water == null)
{
fx_fishing_water = await Addressables.InstantiateAsync(fxWater, transform, true).Task;
fx_fishing_water?.SetActive(false);
}
//if (!string.IsNullOrEmpty(fxWaterSplashName) && fxWaterSplash == null)
//{
// fxWaterSplash = await Addressables.InstantiateAsync(fxWater, transform).Task;
// fxWaterSplash?.SetActive(true);
//}
if (!string.IsNullOrEmpty(fxFishJumpWater) && fxFishJumpWaterSkill == null)
{
fxFishJumpWaterSkill = await Addressables.InstantiateAsync(fxFishJumpWater, transform).Task;
}
if (!string.IsNullOrEmpty(fxFishStruggle) && fxFishStruggleSkill == null && FishBehaviour != null)
{
fxFishStruggleSkill = await Addressables.InstantiateAsync(fxFishStruggle, FishBehaviour.transform).Task;
}
if (!string.IsNullOrEmpty(fxFish) && fxHeadFishSkill == null && FishBehaviour != null && FishBehaviour.Head != null)
{
fxHeadFishSkill = await Addressables.InstantiateAsync(fxFish, FishBehaviour.Head).Task;
}
if (!string.IsNullOrEmpty(rootFx) && fxAppendFishSkill == null && FishBehaviour != null && FishBehaviour.Root != null)
{
fxAppendFishSkill = await Addressables.InstantiateAsync(rootFx, FishBehaviour.Head).Task;
}
fxHeadFishSkill?.SetActive(false);
fxHeadFishSkill?.SetActive(true);
fxAppendFishSkill?.SetActive(false);
fxAppendFishSkill?.SetActive(true);
fxFishStruggleSkill?.SetActive(false);
fxFishStruggleSkill?.SetActive(true);
fxFishJumpWaterSkill?.SetActive(true);
}
public void StopFxFishSkill()
{
fxHeadFishSkill?.SetActive(false);
}
public void SkillRelease()
{
if (fxHeadFishSkill != null)
{
Addressables.ReleaseInstance(fxHeadFishSkill);
fxHeadFishSkill = null;
}
if (fxAppendFishSkill != null)
{
Addressables.ReleaseInstance(fxAppendFishSkill);
fxAppendFishSkill = null;
}
if (fx_fishing_water != null)
{
Addressables.ReleaseInstance(fx_fishing_water);
fx_fishing_water = null;
}
if (fxFishStruggleSkill != null)
{
Addressables.ReleaseInstance(fxFishStruggleSkill);
fxFishStruggleSkill = null;
}
if (fxFishJumpWaterSkill != null)
{
Addressables.ReleaseInstance(fxFishJumpWaterSkill);
fxFishJumpWaterSkill = null;
}
//if (fxWaterSplash != null)
//{
// Addressables.ReleaseInstance(fxWaterSplash);
// fxWaterSplash = null;
//}
}
public async void PlayJump()
{
FishData curFishData = fishingData.curFishData;
isJumping = true;
fishAnimator.SetTrigger($"_jumping0{fishingData.FishJump.AnimatorState}");
fishAnimator.SetTrigger("_jumping");
fishAnimator.SetTrigger($"_drawing0{curFishData.ShowAnimation}");
if (FishBehaviour != null)
{
FishBehaviour.SetSkillInt(fishingData.FishJump.SkillIndex);
FishBehaviour.SetTrigger("Skill");
}
FishJump fishJump = fishingData.FishJump;
if (fishJump != null)
{
_ = StartCoroutine(PlayerJumpOutDelay(fishJump.FxJumpOutDelay, fishJump.JumpDistance));
_ = StartCoroutine(PlayerJumpIntoDelay(fishJump.FxJumpIntoDelay));
float jumpEndTime = fishJump.JumpEndTime;
await Awaiters.Seconds(jumpEndTime);
}
isJumping = false;
JumpDistance = 1;
if (fxFishJumpWaterSkill != null)
{
fxFishJumpWaterSkill.SetActive(true);
}
//if (fxWaterSplash != null)
//{
// fxWaterSplash.transform.localScale = Vector3.one * fishingData.curFishData.SlashFxScale;
// fxWaterSplash.SetActive(true);
//}
//else
if (fx_fishing_splashloop != null)
{
fx_fishing_splashloop.transform.localScale = Vector3.one * fishingData.curFishData.SlashFxScale;
fx_fishing_splashloop.SetActive(true);
}
if (fx_fishing_splashwaveloop != null)
{
fx_fishing_splashwaveloop.transform.localScale = Vector3.one * fishingData.curFishData.SlashFxScale;
fx_fishing_splashwaveloop.SetActive(true);
}
}
IEnumerator PlayerJumpOutDelay(float fxJumpOutDelay, float jumpDistance)
{
//if (fxWaterSplash != null)
//{
// fxWaterSplash.transform.DOScale(Vector3.zero, fxJumpOutDelay).SetEase(Ease.Linear);
//}
if (fx_fishing_splashloop != null)
{
fx_fishing_splashloop.transform.DOScale(Vector3.zero, fxJumpOutDelay).SetEase(Ease.Linear);
}
if (fx_fishing_splashwaveloop != null)
{
fx_fishing_splashwaveloop.transform.DOScale(Vector3.zero, fxJumpOutDelay).SetEase(Ease.Linear);
}
yield return new WaitForSeconds(fxJumpOutDelay);
GContext.Publish(new EventFishingSound(SoundType.HPEvent));
CloseBaitDoTween();
JumpDistance = jumpDistance;
//if (fx_fishing_splashpull != null)
//{
// Vector3 vector = _fish.transform.position;
// vector.y = _waterHeight;
// fx_fishing_splashpull.transform.position = vector;
// fx_fishing_splashpull.SetActive(false);
// fx_fishing_splashpull.SetActive(true);
//}
//if (fx_fishing_water != null)
//{
// fx_fishing_water.SetActive(false);
//}
if (fx_fishing_splashloop != null)
{
fx_fishing_splashloop.SetActive(false);
}
if (fx_fishing_splashwaveloop != null)
{
fx_fishing_splashwaveloop.SetActive(false);
}
if (fxFishJumpWaterSkill != null)
{
fxFishJumpWaterSkill.SetActive(false);
}
}
IEnumerator PlayerJumpIntoDelay(float fxJumpIntoDelay)
{
yield return new WaitForSeconds(fxJumpIntoDelay);
GContext.Publish(new EventFishingSound(SoundType.HPEvent));
CloseBaitDoTween();
JumpDistance = 1;
//if (fx_fishing_splashpull != null)
//{
// Vector3 vector = _fish.transform.position;
// vector.y = _waterHeight;
// fx_fishing_splashpull.transform.position = vector;
// fx_fishing_splashpull.SetActive(false);
// fx_fishing_splashpull.SetActive(true);
//}
}
public void StartSplashloopScale()
{
Vector3 localScale = Vector3.one * fishingData.curFishData.SlashFxScale * 1.5f;
if (fx_fishing_splashloop != null)
{
fx_fishing_splashloop.transform.DOKill();
fx_fishing_splashloop.transform.localScale = localScale;
}
if (fx_fishing_splashwaveloop != null)
{
fx_fishing_splashwaveloop.transform.DOKill();
fx_fishing_splashwaveloop.transform.localScale = localScale;
}
}
public void EndSplashloopScale()
{
Vector3 localScale = Vector3.one * fishingData.curFishData.SlashFxScale;
if (fx_fishing_splashloop != null)
{
fx_fishing_splashwaveloop.transform.DOKill();
fx_fishing_splashloop.transform.DOScale(localScale, 1).SetEase(Ease.Linear);
}
if (fx_fishing_splashwaveloop != null)
{
fx_fishing_splashwaveloop.transform.DOKill();
fx_fishing_splashwaveloop.transform.DOScale(localScale, 1).SetEase(Ease.Linear);
}
}
//====跳跃相关
//=====================鱼移动算法挪位置
private float timer = 1f;
float dashTime = 0f;
private float moveTimer = 0f;
private Vector3 _strugglePoint;
private Vector3 _startPos;
private Vector3 _curStartPos;
Tweener baitDoTween;
//X轴偏移
float _nearDistance = 1;
float _farDistance = 1;
float distance = 1;
float fishSpeed = 1;
public bool Far => _fish.transform.position.z >= _farDistance;
void SetBaitStartPos()
{
_nearDistance = _fishSwimAreaZNear;
_nearDistance = Mathf.Clamp(_nearDistance, _fishSwimAreaZNear, _fishSwimAreaZFar);
_farDistance = _fishSwimAreaZFar;
_farDistance = Mathf.Clamp(_farDistance, _fishSwimAreaZNear, _fishSwimAreaZFar);
_startPos = _fish.transform.position;
_curStartPos = _startPos;
float z = Random.Range(_nearDistance, _farDistance);
_strugglePoint = GeneratePoint(z, 0) / 2;
timer = 10;
}
public async void OnFail(float z, float speed)
{
EscapeFish(z);
var targetPos = Vector3.Lerp(_curStartPos, _strugglePoint, fishSpeed / distance);
_fish.transform.DOMove(targetPos, 1);
await Awaiters.Seconds(1);
GetFish.gameObject.SetActive(false);
if (fx_fishing_splashloop != null)
{
fx_fishing_splashloop.SetActive(false);
}
if (fx_fishing_splashwaveloop != null)
{
fx_fishing_splashwaveloop.SetActive(false);
}
}
//往安全区域外移动
public void EscapeFish(float z)
{
moveTimer = 0;
_strugglePoint.z = z;
_strugglePoint.x = 0;
_curStartPos = _fish.transform.position;
distance = Vector3.Distance(_curStartPos, _strugglePoint);
FishTurn();
}
void SimulateFishEscape(float fishSpeed)
{
moveTimer += Time.deltaTime * fishSpeed;
if (moveTimer / distance < 1)
{
_fish.transform.position = Vector3.Lerp(_curStartPos, _strugglePoint, moveTimer / distance);
Debug.Log("moveTimer / distance:" + _strugglePoint);
}
}
//停止正常的移动贝塞尔DoTween
public void CloseBaitDoTween()
{
if (baitDoTween != null)
{
baitDoTween.Kill();
baitDoTween = null;
timer = 10;
}
}
public void DashStayTime()
{
SetFishDash();
dashTime = fishingData.DashStayTime + 1;
timer = 10;
}
void SetFishDash()
{
fishingData.DashStay = GetFishDash();
if (FishBehaviour != null && fishingData.DashStay != null)
{
FishBehaviour.SetSkillInt(fishingData.DashStay.SkillIndex);
}
}
public void SetStruggle()
{
if (FishBehaviour != null && fishingData.FishStruggle != null)
{
FishBehaviour.SetSkillInt(fishingData.FishStruggle.SkillIndex);
FishBehaviour.SetTrigger("Skill");
}
}
public void StartMoveFish()
{
timer = 10;
}
//能随时修改速度的移动轨迹
void SimulateFish(float fishSpeed, float nearDistance, float farDistance)
{
this.fishSpeed = fishSpeed;
if (NotMove)
{
CloseBaitDoTween();
return;
}
_nearDistance = nearDistance * (_fishSwimAreaZFar - _fishSwimAreaZNear) + _fishSwimAreaZNear;
_nearDistance = Mathf.Clamp(_nearDistance, _fishSwimAreaZNear, _fishSwimAreaZFar);
_farDistance = farDistance * (_fishSwimAreaZFar - _fishSwimAreaZNear) + _fishSwimAreaZFar;
_farDistance = Mathf.Clamp(_farDistance, _fishSwimAreaZNear, _fishSwimAreaZFar);
timer += Time.deltaTime;
moveTimer += Time.deltaTime * fishSpeed;
if (timer > Random.Range(5f, 10f) || Vector3.Distance(_fish.transform.position, _strugglePoint) < 1)
{
CloseBaitDoTween();
float escapeDistanceMag = GContext.container.Resolve<PlayerData>().GrtEscapeDistanceMag();
if (fishingData.DashStay != null)
{
if (!DashMove())
{
return;
}
}
else
{
isDashMove = false;
float z = Random.Range(_nearDistance, _farDistance);
if (fishingData.MaxZEscape > 0.001f)
{
z = fishingData.MaxZEscape * escapeDistanceMag;
}
_strugglePoint = GeneratePoint(z, _fish.transform.position.x);
}
timer = 0;
moveTimer = 0;
_strugglePoint.y = GetFishUnderwaterOffset();
if (fishingData.MaxYEscape > 0.001f)
{
_strugglePoint.y = fishingData.MaxYEscape * escapeDistanceMag;
}
if (fishingData.MaxZEscape > 0.001f)
{
_strugglePoint.z = fishingData.MaxZEscape * escapeDistanceMag;
if (_strugglePoint.z < _fishSwimAreaZFar)
{
_strugglePoint.z = _fishSwimAreaZFar;
}
if (fishingData.DashStayTime <= 0 &&
!isJumping &&
_fish.transform.position.z < _strugglePoint.z - 5)
{
_strugglePoint.x = 0;
}
}
_curStartPos = _fish.transform.position;
_curStartPos.y = GetFishUnderwaterOffset();
distance = Vector3.Distance(_curStartPos, _strugglePoint);
//开始转向
FishTurn();
Vector3 offset = _strugglePoint - _curStartPos;
Vector3 mid = (_strugglePoint + _curStartPos) / 2;
float x;
if (Math.Abs(offset.x) > Math.Abs(offset.z))
{
x = offset.x * Random.Range(0, 0.25f);
mid.z += offset.x * Random.Range(-0.25f, 0.25f);
}
else
{
//z轴比较长
x = offset.z * Random.Range(0, 0.25f);
mid.z += offset.z * Random.Range(-0.25f, 0.25f);
}
if (mid.x * x > 0)
{
mid.x -= x;
}
else
{
mid.x += x;
}
float turnTime = 0;
Vector3 fishPos = _fish.transform.position;
Vector3[] path = new Vector3[] { _curStartPos, mid, _strugglePoint };// GetBezierCurvePoints(_curStartPos, mid, _strugglePoint, 10);
baitDoTween = _fish.transform.DOPath(path, fishSpeed, PathType.CatmullRom).SetSpeedBased(true)
.OnUpdate((() =>
{
if (turnTime > GetTurnTime() + 0.2)
{
Quaternion rotation = Quaternion.LookRotation(fishPos - _fish.transform.position);
_fish.transform.rotation = rotation;
}
else if (turnTime > GetTurnTime())
{
Quaternion rotation = Quaternion.LookRotation(fishPos - _fish.transform.position);
_fish.transform.rotation = Quaternion.Lerp(_fish.transform.rotation, rotation, (turnTime - GetTurnTime()) * 5);
}
fishPos = _fish.transform.position;
turnTime += Time.deltaTime;
}));
if (fishingData.DashStayTime > 0.001f)
{
baitDoTween.SetEase(Ease.OutCubic);
}
else
{
baitDoTween.SetEase(Ease.Linear);
}
}
}
public void FishTurn()
{
FishingPanel_Advanced.Instance?.SetFishIconDir(_fish.transform.position.x > _strugglePoint.x);
Quaternion rotation = Quaternion.LookRotation(_fish.transform.position - _strugglePoint);
_fish.transform.DORotateQuaternion(rotation, GetTurnTime())/*.SetEase(Ease.InOutSine);*/;
}
Vector3 GeneratePoint(float z, float curX)
{
float x1 = (_fishSwimAreaXNear - _fishSwimAreaXFar) / (_fishSwimAreaZNear - _fishSwimAreaZFar) * (z - _fishSwimAreaZFar) + _fishSwimAreaXFar;
//float x = Random.Range(_fishSwimAreaXNear, x1);
float min = curX - (x1 * XAxisMaxProportion * 2);
float max = curX + (x1 * XAxisMaxProportion * 2);
if (min < -x1)
{
min = -x1;
}
if (max > x1)
{
max = x1;
}
float x = Random.Range(min, max);
return new Vector3(x, 0, z);
}
bool isDashMove;
bool DashMove()
{
fx_fishing_splashloopreeling.SetActive(false);
if (!isDashMove)
{
isDashMove = true;
StartSplashloopScale();
FishBehaviour.SetTrigger("Skill");
}
dashTime += Time.deltaTime;
if (dashTime < fishingData.DashStayTime)
{
fishingData.SetFishSkillPerformSpeed(dashTime / fishingData.DashStayTime);
return false;
}
isDashMove = false;
EndSplashloopScale();
if (fishingData.DashStayTime < 0)
{
fishingData.DashStay = null;
}
else
{
SetFishDash();
}
if (FishBehaviour)
{
FishBehaviour.PlaySwim01();
}
fishingData.FishSkillPerformSpeed = 1 / fishingData.FishSkillIncPerform;
DOTween.To(() => fishingData.FishSkillPerformSpeed,
x => fishingData.FishSkillPerformSpeed = x, 1, Random.Range(5f, 10f)).SetId("FishSkillPerformSpeed");
fishingData.FishSkillPerformBack = 1;
dashTime = 0;
_strugglePoint = DashPoint(_fish.transform.position.x);
GContext.Publish(new EventFishingSound(SoundType.audio_fishing_dash));
fx_fishing_splashloopreeling.SetActive(true);
return true;
}
FishDash GetFishDash()
{
List<int> animationTypeList = fishingData.curFishData.AnimationTypeList;
if (animationTypeList.Count <= 1)
{
return _tables.TbFishDash.GetOrDefault(animationTypeList[0]);
}
List<FishDash> fishDashes = new List<FishDash>();
int weight = 0;
foreach (var item in animationTypeList)
{
FishDash fishDash = _tables.TbFishDash.GetOrDefault(item);
if (fishDash != null)
{
fishDashes.Add(fishDash);
weight += fishDash.Weight;
}
}
if (fishDashes.Count == 1)
{
return fishDashes[0];
}
int random = Random.Range(0, weight);
foreach (var item in fishDashes)
{
random -= item.Weight;
if (random <= 0)
{
return item;
}
}
Debug.LogError("Not FishDash FishDataID =" + fishingData.curFishData.ID);
return null;
}
Vector3 DashPoint(float curX)
{
float z = Random.Range(_nearDistance, _farDistance);
float x1 = (_fishSwimAreaXNear - _fishSwimAreaXFar) / (_nearDistance - _farDistance) * (z - _farDistance) + _fishSwimAreaXFar;
float point = Mathf.Abs(curX) + x1;
float nextPointNear = point * fishingData.NextPointNearDistance;
float nextPointFar = point * fishingData.NextPointFarDistance;
point = Random.Range(nextPointNear, nextPointFar);
float x = curX + point;
if (curX > 0)
{
x = curX - point;
}
return new Vector3(x, 0, z);
}
}