首次提交
This commit is contained in:
3
Assets/Scripts/Fishing~/Data.meta
Normal file
3
Assets/Scripts/Fishing~/Data.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bacf82b53c5f4764b384a94c6cf91bdd
|
||||
timeCreated: 1744029436
|
||||
3
Assets/Scripts/Fishing~/Data/Datasource.meta
Normal file
3
Assets/Scripts/Fishing~/Data/Datasource.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a1247222af84a66be775a4fe0af9a57
|
||||
timeCreated: 1744041263
|
||||
199
Assets/Scripts/Fishing~/Data/Datasource/FishingDatasource.cs
Normal file
199
Assets/Scripts/Fishing~/Data/Datasource/FishingDatasource.cs
Normal file
@@ -0,0 +1,199 @@
|
||||
using System.Collections.Generic;
|
||||
using Unity.Mathematics;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 钓鱼数据源基类
|
||||
/// </summary>
|
||||
public class FishingDatasource
|
||||
{
|
||||
public readonly Dictionary<int, FPlayerData> Players = new Dictionary<int, FPlayerData>();
|
||||
|
||||
public void Init()
|
||||
{
|
||||
for (int i = 0; i < 1; i++)
|
||||
{
|
||||
var p = GetTestPlayer(i);
|
||||
AddPlayer(p);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void AddPlayer(FPlayerData player)
|
||||
{
|
||||
Players[player.PlayerID] = player;
|
||||
}
|
||||
|
||||
public FPlayerData GetPlayer(int playerID)
|
||||
{
|
||||
return Players.GetValueOrDefault(playerID);
|
||||
}
|
||||
|
||||
public FPlayerData GetSelfPlayer()
|
||||
{
|
||||
return GetPlayer(GameModel.RoleID);
|
||||
}
|
||||
|
||||
|
||||
#region 测试数据
|
||||
|
||||
public void SetSelfTestGear(int slot)
|
||||
{
|
||||
var player = GetSelfPlayer();
|
||||
if (player != null)
|
||||
{
|
||||
player.currentGear = new FPlayerGearData();
|
||||
var gear = player.currentGear;
|
||||
|
||||
if (slot == 1)
|
||||
{
|
||||
player.lineLength = 3.6f;
|
||||
gear.Type = GearType.Pole;
|
||||
gear.rod = new FRodData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 100001,
|
||||
};
|
||||
gear.line = new FLineData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 400001
|
||||
};
|
||||
gear.bobber = new FBobberData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 300001
|
||||
};
|
||||
gear.hook = new FHookData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 700001
|
||||
};
|
||||
gear.bait = new FBaitData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 500002
|
||||
};
|
||||
gear.weight = new FWeightData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 800001
|
||||
};
|
||||
gear.reel = null;
|
||||
}
|
||||
else if (slot == 2)
|
||||
{
|
||||
player.lineLength = 0.4f;
|
||||
gear.Type = GearType.SpinningFloat;
|
||||
gear.rod = new FRodData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 100002
|
||||
};
|
||||
gear.reel = new FReelData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 200001
|
||||
};
|
||||
gear.line = new FLineData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 400001
|
||||
};
|
||||
gear.bait = new FBaitData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 500002
|
||||
};
|
||||
gear.bobber = new FBobberData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 300001
|
||||
};
|
||||
gear.hook = new FHookData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 700001
|
||||
};
|
||||
gear.weight = new FWeightData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 800001
|
||||
};
|
||||
}
|
||||
else if (slot == 3)
|
||||
{
|
||||
player.lineLength = 0.4f;
|
||||
gear.Type = GearType.Spinning;
|
||||
gear.bobber = null;
|
||||
gear.rod = new FRodData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 100003,
|
||||
};
|
||||
gear.reel = new FReelData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 200001
|
||||
};
|
||||
gear.line = new FLineData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 400001
|
||||
};
|
||||
gear.leader = new FLeaderData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 0
|
||||
};
|
||||
gear.lure = new FLureData()
|
||||
{
|
||||
id = Random.Range(1, 100000),
|
||||
configId = 600001
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FPlayerData GetTestPlayer(int index)
|
||||
{
|
||||
FPlayerData player = new FPlayerData
|
||||
{
|
||||
PlayerID = 100 + index
|
||||
};
|
||||
|
||||
var add = 0;//Random.Range(0, 5f) + index * 0.5f;
|
||||
|
||||
player.position = new Vector3(325.04f + add, 11, 606.28f);
|
||||
player.rotation = quaternion.identity;
|
||||
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
player.currentGear = new FPlayerGearData();
|
||||
}
|
||||
else if (index == 1)
|
||||
{
|
||||
}
|
||||
else if (index == 2)
|
||||
{
|
||||
player.currentGear = new FPlayerGearData();
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
return player;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b5a6200eb494c0ea9cb0bbe8345046c
|
||||
timeCreated: 1744041274
|
||||
316
Assets/Scripts/Fishing~/Data/FPlayerData.cs
Normal file
316
Assets/Scripts/Fishing~/Data/FPlayerData.cs
Normal file
@@ -0,0 +1,316 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[Serializable]
|
||||
public class FPlayerData
|
||||
{
|
||||
public int PlayerID;
|
||||
|
||||
/// <summary>
|
||||
/// 玩家当前装备的钓组
|
||||
/// </summary>
|
||||
public FPlayerGearData currentGear;
|
||||
|
||||
/// <summary>
|
||||
/// 玩家位置
|
||||
/// </summary>
|
||||
public Vector3 position;
|
||||
|
||||
/// <summary>
|
||||
/// 玩家角度
|
||||
/// </summary>
|
||||
public Quaternion rotation;
|
||||
|
||||
public float currentReelingSpeed;
|
||||
public bool isHandOnHandle;
|
||||
|
||||
/// <summary>
|
||||
/// 线长度
|
||||
/// </summary>
|
||||
public float lineLength;
|
||||
|
||||
/// <summary>
|
||||
/// 收线速度
|
||||
/// </summary>
|
||||
public float reelSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// 打开手电筒
|
||||
/// </summary>
|
||||
public bool openLight;
|
||||
|
||||
/// <summary>
|
||||
/// 打开望远镜
|
||||
/// </summary>
|
||||
public bool openTelescope;
|
||||
|
||||
|
||||
public SelectorRodSetting selectorRodSetting = SelectorRodSetting.Speed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 玩家钓组数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FPlayerGearData
|
||||
{
|
||||
public GearType Type = GearType.Spinning;
|
||||
|
||||
public FRodData rod;
|
||||
public FReelData reel;
|
||||
public FBobberData bobber;
|
||||
public FHookData hook;
|
||||
public FBaitData bait;
|
||||
public FLureData lure;
|
||||
public FWeightData weight;
|
||||
public FLineData line;
|
||||
public FLeaderData leader;
|
||||
public FFeederData feeder;
|
||||
|
||||
/// <summary>
|
||||
/// 获得唯一id
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetUnitId()
|
||||
{
|
||||
int result = 0;
|
||||
if (rod != null)
|
||||
{
|
||||
result += rod.configId;
|
||||
}
|
||||
|
||||
if (reel != null)
|
||||
{
|
||||
result += reel.configId;
|
||||
}
|
||||
|
||||
if (bobber != null)
|
||||
{
|
||||
result += bobber.configId;
|
||||
}
|
||||
|
||||
if (hook != null)
|
||||
{
|
||||
result += hook.configId;
|
||||
}
|
||||
|
||||
if (bait != null)
|
||||
{
|
||||
result += bait.configId;
|
||||
}
|
||||
|
||||
if (lure != null)
|
||||
{
|
||||
result += lure.configId;
|
||||
}
|
||||
|
||||
if (weight != null)
|
||||
{
|
||||
result += weight.configId;
|
||||
}
|
||||
|
||||
if (line != null)
|
||||
{
|
||||
result += line.configId;
|
||||
}
|
||||
|
||||
if (leader != null)
|
||||
{
|
||||
result += leader.configId;
|
||||
}
|
||||
|
||||
if (feeder != null)
|
||||
{
|
||||
result += feeder.configId;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public void SetBobberLastSetGroundValue(float value)
|
||||
{
|
||||
bobber.lastSetGroundValue = value;
|
||||
}
|
||||
|
||||
public void SetReelSettings(int setType, float val, bool saveToPrefs = false)
|
||||
{
|
||||
if (setType == 0)
|
||||
{
|
||||
reel.currentSpeed = val;
|
||||
}
|
||||
|
||||
if (setType == 1)
|
||||
{
|
||||
reel.currentDrag = val;
|
||||
}
|
||||
|
||||
if (saveToPrefs)
|
||||
{
|
||||
// Instance._playerData.SaveEquipment(ItemType.Reel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public abstract class FGearData
|
||||
{
|
||||
/// <summary>
|
||||
/// 唯一id
|
||||
/// </summary>
|
||||
public int id;
|
||||
|
||||
/// <summary>
|
||||
/// 配置id
|
||||
/// </summary>
|
||||
public int configId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鱼竿数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FRodData : FGearData
|
||||
{
|
||||
private GameRods _config;
|
||||
|
||||
public GameRods Config
|
||||
{
|
||||
get { return _config ??= GameRods.Get(configId); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 线轴数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FReelData : FGearData
|
||||
{
|
||||
private GameReels _config;
|
||||
|
||||
public GameReels Config
|
||||
{
|
||||
get { return _config ??= GameReels.Get(configId); }
|
||||
}
|
||||
|
||||
public float currentSpeed = 0.5f;
|
||||
|
||||
public float currentDrag = 0.7f;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 浮漂数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FBobberData : FGearData
|
||||
{
|
||||
private GameFloats _config;
|
||||
|
||||
public GameFloats Config
|
||||
{
|
||||
get { return _config ??= GameFloats.Get(configId); }
|
||||
}
|
||||
|
||||
public float lastSetGroundValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鱼钩数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FHookData : FGearData
|
||||
{
|
||||
private GameHooks _config;
|
||||
|
||||
public GameHooks Config
|
||||
{
|
||||
get { return _config ??= GameHooks.Get(configId); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鱼饵数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FBaitData : FGearData
|
||||
{
|
||||
private GameBaits _config;
|
||||
|
||||
public GameBaits Config
|
||||
{
|
||||
get { return _config ??= GameBaits.Get(configId); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 鱼饵数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FLureData : FGearData
|
||||
{
|
||||
private GameLures _config;
|
||||
|
||||
public GameLures Config
|
||||
{
|
||||
get { return _config ??= GameLures.Get(configId); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 沉子数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FWeightData : FGearData
|
||||
{
|
||||
private GameWeights _config;
|
||||
|
||||
public GameWeights Config
|
||||
{
|
||||
get { return _config ??= GameWeights.Get(configId); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 线数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FLineData : FGearData
|
||||
{
|
||||
private GameLines _config;
|
||||
|
||||
public GameLines Config
|
||||
{
|
||||
get { return _config ??= GameLines.Get(configId); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 引线数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FLeaderData : FGearData
|
||||
{
|
||||
private GameLeaders _config;
|
||||
|
||||
public GameLeaders Config
|
||||
{
|
||||
get { return _config ??= GameLeaders.Get(configId); }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 菲德数据
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class FFeederData : FGearData
|
||||
{
|
||||
private GameFeeders _config;
|
||||
|
||||
public GameFeeders Config
|
||||
{
|
||||
get { return _config ??= GameFeeders.Get(configId); }
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Data/FPlayerData.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Data/FPlayerData.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e64ae505cdc344f5acedf6e55ba67a89
|
||||
timeCreated: 1744029443
|
||||
11
Assets/Scripts/Fishing~/Data/RodType.cs
Normal file
11
Assets/Scripts/Fishing~/Data/RodType.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
namespace NBF
|
||||
{
|
||||
public enum GearType
|
||||
{
|
||||
SpinningFloat = 0,
|
||||
Spinning = 1,
|
||||
Feeder = 2,
|
||||
Pole = 4
|
||||
}
|
||||
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Data/RodType.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Data/RodType.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e9c20d631da449c943671224a8f56f1
|
||||
timeCreated: 1744637252
|
||||
3
Assets/Scripts/Fishing~/DatasourcePlayer.meta
Normal file
3
Assets/Scripts/Fishing~/DatasourcePlayer.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 03e80f6925b44b3dbfd52a46c766b08b
|
||||
timeCreated: 1744116926
|
||||
121
Assets/Scripts/Fishing~/DatasourcePlayer/FishingPlay.cs
Normal file
121
Assets/Scripts/Fishing~/DatasourcePlayer/FishingPlay.cs
Normal file
@@ -0,0 +1,121 @@
|
||||
using System;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class FishingPlay
|
||||
{
|
||||
public FishingDatasource Data { get; private set; }
|
||||
|
||||
public FishingPlay(FishingDatasource datasource)
|
||||
{
|
||||
Data = datasource;
|
||||
}
|
||||
|
||||
public FPlayer SelfPlayer;
|
||||
|
||||
public void Init()
|
||||
{
|
||||
// FishingData = fishingData;
|
||||
LoadLevel();
|
||||
}
|
||||
|
||||
#region Loading UnLoading
|
||||
|
||||
private SequenceTaskCollection _battleLoadingTasks;
|
||||
|
||||
private SequenceTaskCollection _battleUnLoadingTasks;
|
||||
|
||||
protected void ClearLoadingTasks()
|
||||
{
|
||||
if (_battleLoadingTasks == null) return;
|
||||
_battleLoadingTasks.Stop();
|
||||
_battleLoadingTasks.Clear();
|
||||
_battleLoadingTasks = null;
|
||||
}
|
||||
|
||||
protected void ClearUnLoadingTasks()
|
||||
{
|
||||
if (_battleUnLoadingTasks == null) return;
|
||||
_battleUnLoadingTasks.Stop();
|
||||
_battleUnLoadingTasks.Clear();
|
||||
_battleUnLoadingTasks = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Load and Unload
|
||||
|
||||
protected void LoadLevel()
|
||||
{
|
||||
_battleLoadingTasks = new SequenceTaskCollection();
|
||||
_battleLoadingTasks.AddTask(LoadBattleTask());
|
||||
_battleLoadingTasks.AddTask(LoadObjects());
|
||||
_battleLoadingTasks.OnCompleted(_ => { OnLoadBattleDone(); });
|
||||
Loading.Show(_battleLoadingTasks);
|
||||
_battleLoadingTasks.Run(DefRunner.Scheduler);
|
||||
}
|
||||
|
||||
public void UnLoadLevel(Action callback)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载场景需要资源
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private ParallelTaskCollection LoadBattleTask()
|
||||
{
|
||||
ParallelTaskCollection subTask1 = new();
|
||||
subTask1.AddTask(new LoadSceneTask("Map4"));
|
||||
|
||||
return subTask1;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 加载实例化场景对象
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
private ParallelTaskCollection LoadObjects()
|
||||
{
|
||||
ParallelTaskCollection subTask1 = new();
|
||||
subTask1.AddTask(new InitPlayersTask(this));
|
||||
subTask1.AddTask(new RunFunTask(AddCameraStack));
|
||||
subTask1.AddTask(new RunFunTask(FindSceneObjects));
|
||||
return subTask1;
|
||||
}
|
||||
|
||||
private void FindSceneObjects()
|
||||
{
|
||||
// WaterObject = GameObject.FindWithTag("Water").transform;
|
||||
}
|
||||
|
||||
private void AddCameraStack()
|
||||
{
|
||||
// MainPlayer.m_Camera.AddStack(StageCamera.main);
|
||||
}
|
||||
|
||||
private void RemoveCameraStack()
|
||||
{
|
||||
// MainPlayer.m_Camera.RemoveStack(StageCamera.main);
|
||||
}
|
||||
|
||||
private void OnLoadBattleDone()
|
||||
{
|
||||
Debug.LogError("加载关卡结束===");
|
||||
FishingPanel.Show();
|
||||
|
||||
|
||||
// BaseCamera.AddStack(StageCamera.main);
|
||||
Loading.Hide();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void Update()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ce4368f9da864c3fb9ff7ebe7322fec6
|
||||
timeCreated: 1742567951
|
||||
82
Assets/Scripts/Fishing~/FFishRagDoll.cs
Normal file
82
Assets/Scripts/Fishing~/FFishRagDoll.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
public class FFishRagDoll : MonoBehaviour
|
||||
{
|
||||
private Transform TailRag;
|
||||
|
||||
[HideInInspector]
|
||||
public CCDIK _ccidk;
|
||||
|
||||
private FFish fish;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
fish = GetComponent<FFish>();
|
||||
_ccidk = GetComponent<CCDIK>();
|
||||
TailRag = _ccidk.solver.target;
|
||||
if (TailRag == null)
|
||||
{
|
||||
Debug.LogError("Ryba nie ma podczepionego TailRag: " + transform.name);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetupTailRag();
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupTailRag()
|
||||
{
|
||||
TailRag.GetComponent<SpringJoint>().maxDistance = transform.localScale.z * 0.2f;
|
||||
TailRag.GetComponent<SpringJoint>().connectedBody = GetComponent<Rigidbody>();
|
||||
TailRag.GetComponent<Rigidbody>().linearDamping = 0.2f;
|
||||
_ccidk.enabled = false;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (TailRag == null)
|
||||
{
|
||||
if (_ccidk == null || _ccidk.solver.target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
TailRag = _ccidk.solver.target;
|
||||
SetupTailRag();
|
||||
}
|
||||
if (fish.isGetFish && TailRag.parent == transform)
|
||||
{
|
||||
TailRag.transform.SetParent(transform.parent);
|
||||
}
|
||||
if (transform.position.y > 0f)
|
||||
{
|
||||
_ccidk.enabled = true;
|
||||
if (fish.isFishView)
|
||||
{
|
||||
_ccidk.solver.IKPositionWeight = 0.05f * transform.localScale.z;
|
||||
}
|
||||
else
|
||||
{
|
||||
_ccidk.solver.IKPositionWeight = Mathf.Clamp(transform.position.y, 0f, 1f);
|
||||
}
|
||||
TailRag.gameObject.SetActive(value: true);
|
||||
}
|
||||
else if (transform.position.y < 0f && TailRag.gameObject.activeSelf)
|
||||
{
|
||||
_ccidk.enabled = false;
|
||||
if (TailRag.parent != transform)
|
||||
{
|
||||
TailRag.transform.SetParent(transform);
|
||||
}
|
||||
TailRag.gameObject.SetActive(value: false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if (!(TailRag == null))
|
||||
{
|
||||
Destroy(TailRag.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/FFishRagDoll.cs.meta
Normal file
3
Assets/Scripts/Fishing~/FFishRagDoll.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c3a57096c6a4f2c8ffa9ba4269ee8b2
|
||||
timeCreated: 1742387706
|
||||
43
Assets/Scripts/Fishing~/FReelEvents.cs
Normal file
43
Assets/Scripts/Fishing~/FReelEvents.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FReelEvents : MonoBehaviour
|
||||
{
|
||||
private FReel reel;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
reel = base.transform.parent.GetComponent<FReel>();
|
||||
}
|
||||
|
||||
public void JoinHandKablak()
|
||||
{
|
||||
// if (reel.reelAsset.animator.GetFloat("Reeling") > 0f)
|
||||
// {
|
||||
// reel.kablagOpenState = false;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// reel.Owner.InteractiveMainHand(reel.reelAsset.koblagHandle);
|
||||
// }
|
||||
}
|
||||
|
||||
public void UnjoinHandKablak()
|
||||
{
|
||||
// if (!reel.isHandOnHandle)
|
||||
// {
|
||||
// reel.Owner.InteractiveMainHand(null);
|
||||
// if (reel.reelAsset.animator.GetBool("Unlock"))
|
||||
// {
|
||||
// reel.kablagOpenState = true;
|
||||
// }
|
||||
//
|
||||
// if (reel.reelAsset.animator.GetBool("Lock"))
|
||||
// {
|
||||
// reel.kablagOpenState = false;
|
||||
// }
|
||||
//
|
||||
// reel.reelAsset.animator.SetBool("Unlock", false);
|
||||
// reel.reelAsset.animator.SetBool("Lock", false);
|
||||
// }
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/FReelEvents.cs.meta
Normal file
3
Assets/Scripts/Fishing~/FReelEvents.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 63de63adeff447b7acc5a6b4bdd24107
|
||||
timeCreated: 1742722875
|
||||
289
Assets/Scripts/Fishing~/FWaterDisplacement.cs
Normal file
289
Assets/Scripts/Fishing~/FWaterDisplacement.cs
Normal file
@@ -0,0 +1,289 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FWaterDisplacement : MonoBehaviour
|
||||
{
|
||||
public enum MoveCharacteristic
|
||||
{
|
||||
Custom = 0,
|
||||
MoveUp_StopDown = 1,
|
||||
MoveDown_100cm = 2,
|
||||
MoveDown_150cm = 3,
|
||||
TopWater = 4,
|
||||
MoveDown = 5,
|
||||
MoveUp_StopDown_Twisters = 6
|
||||
}
|
||||
|
||||
public MoveCharacteristic moveCharacteristic;
|
||||
|
||||
public float objectDisplacement = 1f;
|
||||
|
||||
public float waterDrag = 3f;
|
||||
|
||||
public float waterMass = 3f;
|
||||
|
||||
public float outwaterMass = 6f;
|
||||
|
||||
public bool isInWater;
|
||||
public bool isInTerrain;
|
||||
|
||||
public bool resetVelocityEnterToWater = true;
|
||||
|
||||
private float normalDrag;
|
||||
|
||||
public bool isFreeze;
|
||||
|
||||
public bool useSplashes = true;
|
||||
|
||||
public bool useSplashesOnlyInThrow;
|
||||
|
||||
public bool useWaterCurrent;
|
||||
|
||||
[HideInInspector] public Rigidbody rigidbody;
|
||||
|
||||
[HideInInspector] public Collider collider;
|
||||
|
||||
[HideInInspector] public float waterHeightPosition;
|
||||
|
||||
[HideInInspector] public float depth;
|
||||
|
||||
private FFishSystem fFishSystem;
|
||||
|
||||
public List<FFish> fishListCreated;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
fFishSystem = FindObjectOfType<FFishSystem>();
|
||||
rigidbody = GetComponent<Rigidbody>();
|
||||
collider = GetComponent<Collider>();
|
||||
normalDrag = rigidbody.linearDamping;
|
||||
fishListCreated = new List<FFish>();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (isInWater)
|
||||
{
|
||||
depth = Mathf.Abs(transform.position.y);
|
||||
}
|
||||
else
|
||||
{
|
||||
depth = 0f;
|
||||
}
|
||||
|
||||
AffectCharacteristic();
|
||||
AffectCharacteristicNew();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void AffectCharacteristic()
|
||||
{
|
||||
if (moveCharacteristic == MoveCharacteristic.Custom && !isFreeze && isInWater && transform.position.y < 0f &&
|
||||
objectDisplacement > 0f)
|
||||
{
|
||||
transform.position = Vector3.MoveTowards(transform.position,
|
||||
new Vector3(transform.position.x, waterHeightPosition, transform.position.z),
|
||||
Time.deltaTime * objectDisplacement);
|
||||
}
|
||||
}
|
||||
|
||||
private void AffectCharacteristicNew()
|
||||
{
|
||||
if (isFreeze || !isInWater || transform.position.y >= -0.01f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = Vector3.Dot(rigidbody.linearVelocity, transform.forward);
|
||||
Quaternion b = Quaternion.Euler(0f, rigidbody.transform.localEulerAngles.y, 0f);
|
||||
rigidbody.rotation = Quaternion.Slerp(rigidbody.rotation, b, Time.deltaTime * 2f);
|
||||
switch (moveCharacteristic)
|
||||
{
|
||||
case MoveCharacteristic.MoveDown:
|
||||
if (num > 0.2f)
|
||||
{
|
||||
rigidbody.AddForce(-Vector3.up * Time.deltaTime * Mathf.Clamp01(num) * 2f,
|
||||
ForceMode.VelocityChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
rigidbody.AddForce(Vector3.up * Time.deltaTime * 1f, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
rigidbody.freezeRotation = true;
|
||||
break;
|
||||
case MoveCharacteristic.MoveUp_StopDown:
|
||||
if (num > 0.2f)
|
||||
{
|
||||
rigidbody.AddForce(Vector3.up * Time.deltaTime * Mathf.Clamp01(num), ForceMode.VelocityChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
rigidbody.AddForce(-Vector3.up * Time.deltaTime * 3f, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
rigidbody.freezeRotation = true;
|
||||
break;
|
||||
case MoveCharacteristic.MoveUp_StopDown_Twisters:
|
||||
if (num > 0.2f)
|
||||
{
|
||||
rigidbody.AddForce(Vector3.up * Time.deltaTime * Mathf.Clamp01(num), ForceMode.VelocityChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
rigidbody.AddForce(-Vector3.up * Time.deltaTime * 2.5f, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
rigidbody.freezeRotation = true;
|
||||
break;
|
||||
case MoveCharacteristic.TopWater:
|
||||
if (num > 0.2f && transform.position.y >= -0.03f)
|
||||
{
|
||||
rigidbody.AddForce(-Vector3.up * Time.deltaTime * 1f, ForceMode.VelocityChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
rigidbody.AddForce(Vector3.up * Time.deltaTime * 1f, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
rigidbody.freezeRotation = true;
|
||||
break;
|
||||
case MoveCharacteristic.MoveDown_150cm:
|
||||
if (num > 0.2f && transform.position.y > -1.5f)
|
||||
{
|
||||
rigidbody.AddForce(-Vector3.up * Time.deltaTime * Mathf.Clamp01(num) * 2f,
|
||||
ForceMode.VelocityChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
rigidbody.AddForce(Vector3.up * Time.deltaTime * 1f, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
rigidbody.freezeRotation = true;
|
||||
break;
|
||||
case MoveCharacteristic.MoveDown_100cm:
|
||||
if (num > 0.2f && transform.position.y > -1f)
|
||||
{
|
||||
rigidbody.AddForce(-Vector3.up * Time.deltaTime * Mathf.Clamp01(num) * 2f,
|
||||
ForceMode.VelocityChange);
|
||||
}
|
||||
else
|
||||
{
|
||||
rigidbody.AddForce(Vector3.up * Time.deltaTime * 1f, ForceMode.VelocityChange);
|
||||
}
|
||||
|
||||
rigidbody.freezeRotation = true;
|
||||
break;
|
||||
case MoveCharacteristic.Custom:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerStay(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Water"))
|
||||
{
|
||||
isInWater = true;
|
||||
rigidbody.mass = waterMass;
|
||||
waterHeightPosition = other.transform.position.y;
|
||||
if (rigidbody.useGravity)
|
||||
{
|
||||
EnableDisableGravity(value: false);
|
||||
}
|
||||
|
||||
if (rigidbody.linearDamping != waterDrag)
|
||||
{
|
||||
SetDragRigidbody(waterDrag);
|
||||
}
|
||||
|
||||
if ((bool)fFishSystem)
|
||||
{
|
||||
fFishSystem.AddInwaterObject(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnTriggerExit(Collider other)
|
||||
{
|
||||
if (other.CompareTag("Water"))
|
||||
{
|
||||
rigidbody.freezeRotation = false;
|
||||
isInWater = false;
|
||||
rigidbody.mass = outwaterMass;
|
||||
EnableDisableGravity(value: true);
|
||||
SetDragRigidbody(normalDrag);
|
||||
if ((bool)fFishSystem)
|
||||
{
|
||||
fFishSystem.DeleteInwaterObject(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void EnableDisableGravity(bool value)
|
||||
{
|
||||
if (resetVelocityEnterToWater)
|
||||
{
|
||||
rigidbody.linearVelocity = Vector3.zero;
|
||||
}
|
||||
|
||||
Rigidbody[] componentsInChildren = gameObject.GetComponentsInChildren<Rigidbody>();
|
||||
for (int i = 0; i < componentsInChildren.Length; i++)
|
||||
{
|
||||
componentsInChildren[i].useGravity = value;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetDragRigidbody(float value)
|
||||
{
|
||||
Rigidbody[] componentsInChildren = gameObject.GetComponentsInChildren<Rigidbody>();
|
||||
for (int i = 0; i < componentsInChildren.Length; i++)
|
||||
{
|
||||
componentsInChildren[i].linearDamping = value;
|
||||
}
|
||||
}
|
||||
|
||||
public void ForceByWaterCurrent(Vector3 direction, float powerForce)
|
||||
{
|
||||
if (useWaterCurrent && isInWater)
|
||||
{
|
||||
rigidbody.AddForce(direction * powerForce, ForceMode.Acceleration);
|
||||
}
|
||||
}
|
||||
|
||||
private void BuildSplash(Vector3 contactPosition)
|
||||
{
|
||||
// if (useSplashes && !(rigidbody.linearVelocity.magnitude < 3f) &&
|
||||
// (!FScriptsHandler.Instance.m_PlayerMain.currentRod || !useSplashesOnlyInThrow ||
|
||||
// FScriptsHandler.Instance.m_PlayerMain.currentRod.currentReel.kablagOpenState) &&
|
||||
// !(rigidbody.linearVelocity.y > 0f))
|
||||
// {
|
||||
// Vector3 vector = Vector3.one * (0.02f * Mathf.Abs(rigidbody.linearVelocity.y)) * transform.localScale.x;
|
||||
// int num = 0;
|
||||
// GameObject obj = Instantiate(FScriptsHandler.Instance.waterFishSplash[num]);
|
||||
// obj.transform.position = new Vector3(contactPosition.x, 0.05f, contactPosition.z);
|
||||
// obj.GetComponent<AudioSource>().volume = 0.5f * vector.x;
|
||||
// vector = Vector3.ClampMagnitude(vector, 1f);
|
||||
// obj.transform.localScale = vector;
|
||||
// }
|
||||
}
|
||||
|
||||
private void OnTriggerEnter(Collider col)
|
||||
{
|
||||
if (col.transform.CompareTag("Water"))
|
||||
{
|
||||
BuildSplash(new Vector3(transform.position.x, SceneSettings.Instance.WaterObject.transform.position.y,
|
||||
transform.position.z));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if ((bool)fFishSystem)
|
||||
{
|
||||
fFishSystem.DeleteInwaterObject(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/FWaterDisplacement.cs.meta
Normal file
3
Assets/Scripts/Fishing~/FWaterDisplacement.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5109f1ab72f9463b892a49f6f309a485
|
||||
timeCreated: 1742313602
|
||||
78
Assets/Scripts/Fishing~/Fishing.cs
Normal file
78
Assets/Scripts/Fishing~/Fishing.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Fishing
|
||||
{
|
||||
Fishing()
|
||||
{
|
||||
App.OnUpdate += Update;
|
||||
}
|
||||
|
||||
private static Fishing _inst;
|
||||
|
||||
public static Fishing Inst => _inst ??= new Fishing();
|
||||
|
||||
public int Map { get; private set; }
|
||||
|
||||
|
||||
public FishingPlay Player { get; private set; }
|
||||
|
||||
public FishingDatasource Datasource { get; private set; }
|
||||
|
||||
public void Go(int map)
|
||||
{
|
||||
Map = map;
|
||||
EnterMap();
|
||||
}
|
||||
|
||||
#region Load
|
||||
|
||||
private void EnterMap()
|
||||
{
|
||||
EnterDone();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
Datasource?.Update();
|
||||
Player?.Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 进入地图成功
|
||||
/// </summary>
|
||||
private void EnterDone()
|
||||
{
|
||||
DataInit();
|
||||
PlayerInit();
|
||||
}
|
||||
|
||||
private void DataInit()
|
||||
{
|
||||
Datasource = new FishingDatasource();
|
||||
Datasource.Init();
|
||||
}
|
||||
|
||||
private void PlayerInit()
|
||||
{
|
||||
if (Player != null)
|
||||
{
|
||||
Player.UnLoadLevel(NewBattlePlayInit);
|
||||
}
|
||||
else
|
||||
{
|
||||
NewBattlePlayInit();
|
||||
}
|
||||
}
|
||||
|
||||
private void NewBattlePlayInit()
|
||||
{
|
||||
Player = new FishingPlay(Datasource);
|
||||
Player.Init();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Fishing.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Fishing.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 158a88fb17104b1fa7818e84197d4eee
|
||||
timeCreated: 1742567921
|
||||
58
Assets/Scripts/Fishing~/PlayArm.cs
Normal file
58
Assets/Scripts/Fishing~/PlayArm.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerArm : MonoBehaviour
|
||||
{
|
||||
public bool IsLeft;
|
||||
public LimbIK IK;
|
||||
public Transform RodContainer;
|
||||
public Transform LeftRigMagnet;
|
||||
public FingerRig FingerRig;
|
||||
public PlayerShoulder Shoulder;//PlayerShoulder
|
||||
|
||||
[HideInInspector] public float interactionTargetWeight;
|
||||
|
||||
|
||||
public void SetReelHandle(ReelAsset asset)
|
||||
{
|
||||
IK.solver.target = asset.handle;
|
||||
IK.enabled = true;
|
||||
|
||||
// var fingers = FingerRig.fingers;
|
||||
// foreach (var finger in fingers)
|
||||
// {
|
||||
// finger.target = asset.handleEnd;
|
||||
// }
|
||||
|
||||
// // 启用整体控制
|
||||
// FingerRig.weight = 1f;
|
||||
//
|
||||
// // 绑定大拇指和食指的目标
|
||||
// FingerRig.fingers[0].target = asset.handleEnd; // Thumb
|
||||
// FingerRig.fingers[1].target = asset.handleEnd; // Index
|
||||
//
|
||||
// FingerRig.fingers[0].weight = 1f;
|
||||
// FingerRig.fingers[1].weight = 1f;
|
||||
|
||||
// 其余手指握拳(不绑定 target)
|
||||
for (int i = 2; i < 5; i++)
|
||||
{
|
||||
FingerRig.fingers[i].target = null;
|
||||
FingerRig.fingers[i].weight = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
public void MoveTowardsInteraction()
|
||||
{
|
||||
if (!IK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
IK.solver.SetIKPositionWeight(Mathf.MoveTowards(IK.solver.IKPositionWeight,
|
||||
interactionTargetWeight, Time.deltaTime * 2f));
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/PlayArm.cs.meta
Normal file
3
Assets/Scripts/Fishing~/PlayArm.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99467c6c370b440d8bdb517bbbcf22cf
|
||||
timeCreated: 1743435628
|
||||
3
Assets/Scripts/Fishing~/Player.meta
Normal file
3
Assets/Scripts/Fishing~/Player.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d76792b34ac4ab3a90df08baa109590
|
||||
timeCreated: 1742387763
|
||||
3
Assets/Scripts/Fishing~/Player/Animations.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Animations.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18d7c6328d5d4b6ea508b7b6d05d8a31
|
||||
timeCreated: 1746449694
|
||||
17
Assets/Scripts/Fishing~/Player/Animations/BobThrowAnim.cs
Normal file
17
Assets/Scripts/Fishing~/Player/Animations/BobThrowAnim.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using NBC;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 浮漂
|
||||
/// </summary>
|
||||
public class BobThrowAnim : NTask
|
||||
{
|
||||
private FPlayer _player;
|
||||
|
||||
public BobThrowAnim(FPlayer player)
|
||||
{
|
||||
_player = player;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e061352cd04e482090828b12acb7920f
|
||||
timeCreated: 1746449734
|
||||
312
Assets/Scripts/Fishing~/Player/Animations/LureThrowAnim.cs
Normal file
312
Assets/Scripts/Fishing~/Player/Animations/LureThrowAnim.cs
Normal file
@@ -0,0 +1,312 @@
|
||||
using System.Collections.Generic;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
[System.Serializable]
|
||||
public struct FishingLureCastInput
|
||||
{
|
||||
[Range(0, 1)] public float power;
|
||||
[Range(0, 50)] public float windStrength; // 单位 m/s
|
||||
public Vector3 windDirection;
|
||||
[Range(5, 30)] public float lureWeight; // 单位 g
|
||||
[Range(0.1f, 1f)] public float lineDiameter; // 单位:毫米,0.1mm ~ 1mm
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 路亚抛竿轨迹动画
|
||||
/// </summary>
|
||||
public class LureThrowAnim : NTask
|
||||
{
|
||||
private FPlayer _player;
|
||||
|
||||
[Header("基础参数")] public int maxSimulationSteps = 1000;
|
||||
public float simulationDuration = 10f;
|
||||
public float timeStep = 0.02f;
|
||||
|
||||
[Header("抛投力度")] public float minThrowPower = 15f;
|
||||
public float maxThrowPower = 45f;
|
||||
|
||||
[Header("空气阻力参数")] [Tooltip("阻力系数,非流线钓饵建议 0.8~1.2")]
|
||||
public float dragCoefficient = 0.2f;
|
||||
|
||||
[Tooltip("迎风面积,0.005m² ≈ 5cm²")] public float lureArea = 0.001f;
|
||||
|
||||
|
||||
private FWaterDisplacement _lureHookWaterDisplacement;
|
||||
|
||||
private List<Vector3> _trajectory;
|
||||
|
||||
public float totalDuration = 1.5f; // 总飞行时间
|
||||
public float arriveThreshold = 0.01f;
|
||||
|
||||
private float elapsedTime = 0f;
|
||||
private bool isMoving = false;
|
||||
private Vector3 startOffset = Vector3.zero;
|
||||
|
||||
private Transform _transform;
|
||||
|
||||
public float CurrentDistanceTraveled { get; private set; } = 0f;
|
||||
|
||||
private float _throwStartLineLenght = 0f;
|
||||
|
||||
|
||||
public LureThrowAnim(FPlayer player)
|
||||
{
|
||||
_player = player;
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
_throwStartLineLenght = _player.Data.lineLength;
|
||||
_lureHookWaterDisplacement = _player.Gears.Rod.LureHookWaterDisplacement;
|
||||
float angle = 25f;
|
||||
float radians = angle * Mathf.Deg2Rad;
|
||||
Vector3 forwardUp = _player.transform.forward * Mathf.Cos(radians) +
|
||||
_player.transform.up * Mathf.Sin(radians);
|
||||
// // 施加力
|
||||
// lureHookWaterDisplacement.rigidbody.AddForce(forwardUpDirection * 500, ForceMode.Impulse);
|
||||
_transform = _lureHookWaterDisplacement.transform;
|
||||
_lureHookWaterDisplacement.rigidbody.isKinematic = true;
|
||||
_lureHookWaterDisplacement.rigidbody.useGravity = false;
|
||||
FishingLureCastInput baseInput = new FishingLureCastInput
|
||||
{
|
||||
power = 1f,
|
||||
lureWeight = 2.2f,
|
||||
windStrength = 0f, // 风力大小
|
||||
lineDiameter = 0.14f
|
||||
};
|
||||
|
||||
Vector3 startPos = _player.transform.position + Vector3.up * 2.5f;
|
||||
// Vector3 startPos = _player.Gears.Rod.rodAsset.lineConnector.position;
|
||||
Vector3 throwDir = forwardUp.normalized;
|
||||
var trajectory = CalculateTrajectory(baseInput, startPos, throwDir);
|
||||
_trajectory = trajectory;
|
||||
_trajectory = SimplifyTrajectoryRDP(trajectory, 0.1f);
|
||||
// SceneSettings.Instance.LineRenderer.startWidth = 0.1f;
|
||||
// SceneSettings.Instance.LineRenderer.endWidth = 0.1f;
|
||||
// SceneSettings.Instance.LineRenderer.positionCount = _trajectory.Count;
|
||||
// SceneSettings.Instance.LineRenderer.useWorldSpace = true;
|
||||
// SceneSettings.Instance.LineRenderer.SetPositions(_trajectory.ToArray());
|
||||
|
||||
elapsedTime = 0f;
|
||||
isMoving = true;
|
||||
CurrentDistanceTraveled = 0f;
|
||||
|
||||
// 如果不在起点,先移动过去
|
||||
if ((_transform.position - _trajectory[0]).magnitude > arriveThreshold)
|
||||
{
|
||||
startOffset = _trajectory[0] - _transform.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
startOffset = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
protected override NTaskStatus OnProcess()
|
||||
{
|
||||
OnMove();
|
||||
return base.OnProcess();
|
||||
}
|
||||
|
||||
|
||||
private void MoveDone()
|
||||
{
|
||||
var rb = _lureHookWaterDisplacement.rigidbody;
|
||||
|
||||
// 强制同步位置和朝向
|
||||
rb.position = rb.transform.position;
|
||||
rb.rotation = rb.transform.rotation;
|
||||
rb.isKinematic = false;
|
||||
// 停止物理残留影响
|
||||
rb.linearVelocity = Vector3.zero;
|
||||
rb.angularVelocity = Vector3.zero;
|
||||
rb.useGravity = true;
|
||||
Finish();
|
||||
}
|
||||
|
||||
private void OnMove()
|
||||
{
|
||||
if (!isMoving || _trajectory == null || _trajectory.Count < 2) return;
|
||||
// Debug.LogError("OnMove");
|
||||
// 初始补位阶段(瞬移或平滑补过去)
|
||||
if (startOffset.magnitude > arriveThreshold)
|
||||
{
|
||||
float moveSpeed = startOffset.magnitude / 0.1f;
|
||||
Vector3 move = startOffset.normalized * moveSpeed * Time.deltaTime;
|
||||
if (move.magnitude >= startOffset.magnitude)
|
||||
{
|
||||
_transform.position = _trajectory[0];
|
||||
startOffset = Vector3.zero;
|
||||
}
|
||||
else
|
||||
{
|
||||
_transform.position += move;
|
||||
startOffset -= move;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
elapsedTime += Time.deltaTime;
|
||||
float t = Mathf.Clamp01(elapsedTime / totalDuration);
|
||||
|
||||
// 插值路径
|
||||
int segmentCount = _trajectory.Count - 1;
|
||||
float totalSegmentLength = segmentCount;
|
||||
float pathT = t * totalSegmentLength;
|
||||
int index = Mathf.FloorToInt(pathT);
|
||||
|
||||
if (index >= _trajectory.Count - 1)
|
||||
{
|
||||
_transform.position = _trajectory[^1];
|
||||
isMoving = false;
|
||||
CurrentDistanceTraveled = CalculateTotalDistance(_trajectory);
|
||||
MoveDone();
|
||||
return;
|
||||
}
|
||||
|
||||
float localT = pathT - index;
|
||||
Vector3 p0 = _trajectory[index];
|
||||
Vector3 p1 = _trajectory[index + 1];
|
||||
_transform.position = Vector3.Lerp(p0, p1, localT);
|
||||
|
||||
var distance = Vector3.Distance(_lureHookWaterDisplacement.transform.position,
|
||||
_player.Gears.Rod.rodAsset.lineConnector.position);
|
||||
if (distance > _throwStartLineLenght)
|
||||
{
|
||||
_throwStartLineLenght = distance;
|
||||
_player.Data.lineLength = _throwStartLineLenght + 0.5f;
|
||||
}
|
||||
// _throwStartLineLenght
|
||||
}
|
||||
|
||||
float CalculateTotalDistance(List<Vector3> points)
|
||||
{
|
||||
float dist = 0f;
|
||||
for (int i = 1; i < points.Count; i++)
|
||||
dist += Vector3.Distance(points[i - 1], points[i]);
|
||||
return dist;
|
||||
}
|
||||
|
||||
public List<Vector3> CalculateTrajectory(FishingLureCastInput input, Vector3 startPosition,
|
||||
Vector3 castDirection)
|
||||
{
|
||||
List<Vector3> trajectory = new List<Vector3>();
|
||||
|
||||
Vector3 position = startPosition;
|
||||
Vector3 direction = castDirection.normalized;
|
||||
float throwPower = Mathf.Lerp(minThrowPower, maxThrowPower, input.power);
|
||||
Vector3 velocity = direction * throwPower;
|
||||
|
||||
float lureMass = input.lureWeight / 1000f; // 转 kg
|
||||
Vector3 windDir = input.windDirection.normalized;
|
||||
float windStrength = input.windStrength;
|
||||
|
||||
float currentTime = 0f;
|
||||
int steps = 0;
|
||||
totalDuration = 0;
|
||||
while (currentTime < simulationDuration && steps < maxSimulationSteps)
|
||||
{
|
||||
if (position.y <= 0f) break;
|
||||
|
||||
// 模拟风力逐渐生效
|
||||
float windInfluenceFactor = Mathf.Clamp01(currentTime / 1.5f); // 1.5秒内增长
|
||||
Vector3 windVelocity = windDir * windStrength * windInfluenceFactor;
|
||||
|
||||
// 真实空气阻力模型
|
||||
Vector3 relVelocity = velocity - windVelocity;
|
||||
|
||||
// 空气阻力
|
||||
float dragMag = 0.5f * PhysicsHelper.AirDensity *
|
||||
relVelocity.sqrMagnitude *
|
||||
dragCoefficient * lureArea;
|
||||
|
||||
// --- 钓线空气阻力模拟 ---
|
||||
// 假设飞行中展开的线长度近似为当前位置的XZ平面长度
|
||||
float lineLength = Vector3.Distance(new Vector3(position.x, 0, position.z),
|
||||
new Vector3(startPosition.x, 0, startPosition.z));
|
||||
float lineRadius = input.lineDiameter / 2000f; // mm转m再除以2得到半径
|
||||
|
||||
// 钓线的迎风面积估算:长度 * 直径
|
||||
float lineArea = lineLength * (lineRadius * 2f); // 近似为圆柱体侧面积的一部分
|
||||
|
||||
// 简化模型:线的附加空气阻力方向与当前速度方向相反
|
||||
float lineDragMag = 0.5f * PhysicsHelper.AirDensity * velocity.sqrMagnitude * dragCoefficient *
|
||||
lineArea;
|
||||
Vector3 lineDragForce = -velocity.normalized * lineDragMag;
|
||||
|
||||
|
||||
Vector3 dragForce = -relVelocity.normalized * dragMag;
|
||||
|
||||
// 合力 = 重力 + 空气阻力
|
||||
// Vector3 acceleration = (Physics.gravity + dragForce / lureMass);
|
||||
Vector3 totalForce = dragForce + lineDragForce;
|
||||
// 合力 = 重力 + 空气阻力 + 线阻力
|
||||
Vector3 acceleration = (Physics.gravity + totalForce / lureMass);
|
||||
|
||||
|
||||
velocity += acceleration * timeStep;
|
||||
position += velocity * timeStep;
|
||||
|
||||
trajectory.Add(position);
|
||||
currentTime += timeStep;
|
||||
steps++;
|
||||
}
|
||||
|
||||
totalDuration = currentTime;
|
||||
return trajectory;
|
||||
}
|
||||
|
||||
|
||||
public static List<Vector3> SimplifyTrajectoryRDP(List<Vector3> points, float tolerance)
|
||||
{
|
||||
if (points == null || points.Count < 3)
|
||||
return new List<Vector3>(points);
|
||||
|
||||
List<Vector3> result = new List<Vector3>();
|
||||
SimplifySection(points, 0, points.Count - 1, tolerance, result);
|
||||
result.Add(points[points.Count - 1]);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void SimplifySection(List<Vector3> points, int start, int end, float tolerance,
|
||||
List<Vector3> result)
|
||||
{
|
||||
if (end <= start + 1)
|
||||
return;
|
||||
|
||||
float maxDistance = -1f;
|
||||
int index = -1;
|
||||
Vector3 startPoint = points[start];
|
||||
Vector3 endPoint = points[end];
|
||||
|
||||
for (int i = start + 1; i < end; i++)
|
||||
{
|
||||
float distance = PerpendicularDistance(points[i], startPoint, endPoint);
|
||||
if (distance > maxDistance)
|
||||
{
|
||||
maxDistance = distance;
|
||||
index = i;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxDistance > tolerance)
|
||||
{
|
||||
SimplifySection(points, start, index, tolerance, result);
|
||||
result.Add(points[index]);
|
||||
SimplifySection(points, index, end, tolerance, result);
|
||||
}
|
||||
}
|
||||
|
||||
private static float PerpendicularDistance(Vector3 point, Vector3 lineStart, Vector3 lineEnd)
|
||||
{
|
||||
if (lineStart == lineEnd) return Vector3.Distance(point, lineStart);
|
||||
Vector3 projected = Vector3.Project(point - lineStart, lineEnd - lineStart);
|
||||
Vector3 closest = lineStart + projected;
|
||||
return Vector3.Distance(point, closest);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b1397324abdd458495e11ac971167bbc
|
||||
timeCreated: 1746449919
|
||||
3
Assets/Scripts/Fishing~/Player/AnimatorCtrl.meta
Normal file
3
Assets/Scripts/Fishing~/Player/AnimatorCtrl.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8f1c5daea61a4a4094251c75e92dc438
|
||||
timeCreated: 1745922726
|
||||
353
Assets/Scripts/Fishing~/Player/AnimatorCtrl/PlayerAnimator.cs
Normal file
353
Assets/Scripts/Fishing~/Player/AnimatorCtrl/PlayerAnimator.cs
Normal file
@@ -0,0 +1,353 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public enum ThrowModeEnum : int
|
||||
{
|
||||
Spin = 0,
|
||||
Float = 1,
|
||||
}
|
||||
|
||||
public enum HandItemType
|
||||
{
|
||||
Default = 0,
|
||||
HandRod = 1,
|
||||
SpinRod = 2,
|
||||
}
|
||||
|
||||
public class PlayerAnimator : MonoBehaviour
|
||||
{
|
||||
#region 参数定义
|
||||
|
||||
private static readonly int StartThrowHash = Animator.StringToHash("startThrow");
|
||||
private static readonly int LureThrownHash = Animator.StringToHash("lureThrown");
|
||||
private static readonly int PrepareThrowHash = Animator.StringToHash("prepareThrow");
|
||||
private static readonly int LeftHandHash = Animator.StringToHash("leftHand");
|
||||
private static readonly int MoveSpeedHash = Animator.StringToHash("moveSpeed");
|
||||
private static readonly int BoatVelocityHash = Animator.StringToHash("boatVelocity");
|
||||
private static readonly int BoatDirHash = Animator.StringToHash("boatDir");
|
||||
private static readonly int BoatHash = Animator.StringToHash("boat");
|
||||
private static readonly int CastingHash = Animator.StringToHash("casting");
|
||||
private static readonly int TelestickHash = Animator.StringToHash("telestick");
|
||||
private static readonly int TelestickPullHash = Animator.StringToHash("telestick_pull");
|
||||
private static readonly int UseRodPodHash = Animator.StringToHash("use_rod_pod");
|
||||
private static readonly int ItemSourceHash = Animator.StringToHash("item_source");
|
||||
private static readonly int ItemDestHash = Animator.StringToHash("item_dest");
|
||||
private static readonly int RodReadyHash = Animator.StringToHash("rod_ready");
|
||||
private static readonly int HitchRecoverDirHash = Animator.StringToHash("hitchRecoverDir");
|
||||
private static readonly int HitchRecoverHash = Animator.StringToHash("hitchRecover");
|
||||
private static readonly int SitOrStandHash = Animator.StringToHash("sitOrStand");
|
||||
private static readonly int ShtekerHash = Animator.StringToHash("shteker");
|
||||
private static readonly int ItemInHandsHash = Animator.StringToHash("item_in_hands");
|
||||
private static readonly int ChangeItemHash = Animator.StringToHash("change_item");
|
||||
private static readonly int ItemTypeHash = Animator.StringToHash("item_type");
|
||||
private static readonly int ItemActionHash = Animator.StringToHash("item_action");
|
||||
private static readonly int ItemActionPowerHash = Animator.StringToHash("item_action_power");
|
||||
private static readonly int PodsakActionHash = Animator.StringToHash("podsak_action");
|
||||
private static readonly int FishingFinalHash = Animator.StringToHash("fishing_final");
|
||||
private static readonly int SpinOrTeleHash = Animator.StringToHash("spin_or_tele");
|
||||
private static readonly int TwitchHash = Animator.StringToHash("twitch");
|
||||
private static readonly int TwitchDirHash = Animator.StringToHash("twitch_dir");
|
||||
private static readonly int ThrowSpeedMultHash = Animator.StringToHash("throw_speed_mult");
|
||||
private static readonly int ConvTestHash = Animator.StringToHash("conv_test");
|
||||
private static readonly int BoatPoseHash = Animator.StringToHash("boat_pose");
|
||||
private static readonly int QuadDirectionHash = Animator.StringToHash("quad_direction");
|
||||
private static readonly int StretchMaxHash = Animator.StringToHash("stretch_max");
|
||||
private static readonly int ExamineItemHash = Animator.StringToHash("examine_item");
|
||||
private static readonly int TillerDirectionHash = Animator.StringToHash("tiller_direction");
|
||||
private static readonly int TestTriggerHash = Animator.StringToHash("test_trigger");
|
||||
private static readonly int ThrowModeHash = Animator.StringToHash("throw_mode");
|
||||
private static readonly int PullUpRodHash = Animator.StringToHash("pull_up_rod");
|
||||
|
||||
public bool StartThrow
|
||||
{
|
||||
get => animator.GetBool(StartThrowHash);
|
||||
set => animator.SetBool(StartThrowHash, value);
|
||||
}
|
||||
|
||||
public bool LureThrown
|
||||
{
|
||||
get => animator.GetBool(LureThrownHash);
|
||||
set => animator.SetBool(LureThrownHash, value);
|
||||
}
|
||||
|
||||
public bool PrepareThrow
|
||||
{
|
||||
get => animator.GetBool(PrepareThrowHash);
|
||||
set => animator.SetBool(PrepareThrowHash, value);
|
||||
}
|
||||
|
||||
public bool LeftHand
|
||||
{
|
||||
get => animator.GetBool(LeftHandHash);
|
||||
set => animator.SetBool(LeftHandHash, value);
|
||||
}
|
||||
|
||||
public float MoveSpeed
|
||||
{
|
||||
get => animator.GetFloat(MoveSpeedHash);
|
||||
set => animator.SetFloat(MoveSpeedHash, value);
|
||||
}
|
||||
|
||||
public float BoatVelocity
|
||||
{
|
||||
get => animator.GetFloat(BoatVelocityHash);
|
||||
set => animator.SetFloat(BoatVelocityHash, value);
|
||||
}
|
||||
|
||||
public float BoatDir
|
||||
{
|
||||
get => animator.GetFloat(BoatDirHash);
|
||||
set => animator.SetFloat(BoatDirHash, value);
|
||||
}
|
||||
|
||||
public bool Boat
|
||||
{
|
||||
get => animator.GetBool(BoatHash);
|
||||
set => animator.SetBool(BoatHash, value);
|
||||
}
|
||||
|
||||
public bool Casting
|
||||
{
|
||||
get => animator.GetBool(CastingHash);
|
||||
set => animator.SetBool(CastingHash, value);
|
||||
}
|
||||
|
||||
public bool Telestick
|
||||
{
|
||||
get => animator.GetBool(TelestickHash);
|
||||
set => animator.SetBool(TelestickHash, value);
|
||||
}
|
||||
|
||||
public bool TelestickPull
|
||||
{
|
||||
get => animator.GetBool(TelestickPullHash);
|
||||
set => animator.SetBool(TelestickPullHash, value);
|
||||
}
|
||||
|
||||
public bool UseRodPod
|
||||
{
|
||||
get => animator.GetBool(UseRodPodHash);
|
||||
set => animator.SetBool(UseRodPodHash, value);
|
||||
}
|
||||
|
||||
public int ItemSource
|
||||
{
|
||||
get => animator.GetInteger(ItemSourceHash);
|
||||
set => animator.SetInteger(ItemSourceHash, value);
|
||||
}
|
||||
|
||||
public int ItemDest
|
||||
{
|
||||
get => animator.GetInteger(ItemDestHash);
|
||||
set => animator.SetInteger(ItemDestHash, value);
|
||||
}
|
||||
|
||||
public bool RodReady
|
||||
{
|
||||
get => animator.GetBool(RodReadyHash);
|
||||
set => animator.SetBool(RodReadyHash, value);
|
||||
}
|
||||
|
||||
public float HitchRecoverDir
|
||||
{
|
||||
get => animator.GetFloat(HitchRecoverDirHash);
|
||||
set => animator.SetFloat(HitchRecoverDirHash, value);
|
||||
}
|
||||
|
||||
public void SetHitchRecoverTrigger()
|
||||
{
|
||||
animator.SetTrigger(HitchRecoverHash);
|
||||
}
|
||||
|
||||
public void ResetHitchRecoverTrigger()
|
||||
{
|
||||
animator.ResetTrigger(HitchRecoverHash);
|
||||
}
|
||||
|
||||
public float SitOrStand
|
||||
{
|
||||
get => animator.GetFloat(SitOrStandHash);
|
||||
set => animator.SetFloat(SitOrStandHash, value);
|
||||
}
|
||||
|
||||
public bool Shteker
|
||||
{
|
||||
get => animator.GetBool(ShtekerHash);
|
||||
set => animator.SetBool(ShtekerHash, value);
|
||||
}
|
||||
|
||||
public bool ItemInHands
|
||||
{
|
||||
get => animator.GetBool(ItemInHandsHash);
|
||||
set => animator.SetBool(ItemInHandsHash, value);
|
||||
}
|
||||
|
||||
public bool ChangeItem
|
||||
{
|
||||
get => animator.GetBool(ChangeItemHash);
|
||||
set => animator.SetBool(ChangeItemHash, value);
|
||||
}
|
||||
|
||||
public HandItemType ItemType
|
||||
{
|
||||
get => (HandItemType)animator.GetInteger(ItemTypeHash);
|
||||
set => animator.SetInteger(ItemTypeHash, (int)value);
|
||||
}
|
||||
|
||||
public void SetItemActionTrigger()
|
||||
{
|
||||
animator.SetTrigger(ItemActionHash);
|
||||
}
|
||||
|
||||
public void ResetItemActionTrigger()
|
||||
{
|
||||
animator.ResetTrigger(ItemActionHash);
|
||||
}
|
||||
|
||||
public float ItemActionPower
|
||||
{
|
||||
get => animator.GetFloat(ItemActionPowerHash);
|
||||
set => animator.SetFloat(ItemActionPowerHash, value);
|
||||
}
|
||||
|
||||
public bool PodsakAction
|
||||
{
|
||||
get => animator.GetBool(PodsakActionHash);
|
||||
set => animator.SetBool(PodsakActionHash, value);
|
||||
}
|
||||
|
||||
public bool PullUpRod
|
||||
{
|
||||
get => animator.GetBool(PullUpRodHash);
|
||||
set => animator.SetBool(PullUpRodHash, value);
|
||||
}
|
||||
|
||||
public float FishingFinal
|
||||
{
|
||||
get => animator.GetFloat(FishingFinalHash);
|
||||
set => animator.SetFloat(FishingFinalHash, value);
|
||||
}
|
||||
|
||||
public float SpinOrTele
|
||||
{
|
||||
get => animator.GetFloat(SpinOrTeleHash);
|
||||
set => animator.SetFloat(SpinOrTeleHash, value);
|
||||
}
|
||||
|
||||
public void SetTwitchTrigger()
|
||||
{
|
||||
animator.SetTrigger(TwitchHash);
|
||||
}
|
||||
|
||||
public void ResetTwitchTrigger()
|
||||
{
|
||||
animator.ResetTrigger(TwitchHash);
|
||||
}
|
||||
|
||||
public float TwitchDir
|
||||
{
|
||||
get => animator.GetFloat(TwitchDirHash);
|
||||
set => animator.SetFloat(TwitchDirHash, value);
|
||||
}
|
||||
|
||||
public float ThrowSpeedMult
|
||||
{
|
||||
get => animator.GetFloat(ThrowSpeedMultHash);
|
||||
set => animator.SetFloat(ThrowSpeedMultHash, value);
|
||||
}
|
||||
|
||||
public void SetConvTestTrigger()
|
||||
{
|
||||
animator.SetTrigger(ConvTestHash);
|
||||
}
|
||||
|
||||
public void ResetConvTestTrigger()
|
||||
{
|
||||
animator.ResetTrigger(ConvTestHash);
|
||||
}
|
||||
|
||||
public int BoatPose
|
||||
{
|
||||
get => animator.GetInteger(BoatPoseHash);
|
||||
set => animator.SetInteger(BoatPoseHash, value);
|
||||
}
|
||||
|
||||
public float QuadDirection
|
||||
{
|
||||
get => animator.GetFloat(QuadDirectionHash);
|
||||
set => animator.SetFloat(QuadDirectionHash, value);
|
||||
}
|
||||
|
||||
public bool StretchMax
|
||||
{
|
||||
get => animator.GetBool(StretchMaxHash);
|
||||
set => animator.SetBool(StretchMaxHash, value);
|
||||
}
|
||||
|
||||
public void SetExamineItemTrigger()
|
||||
{
|
||||
animator.SetTrigger(ExamineItemHash);
|
||||
}
|
||||
|
||||
public void ResetExamineItemTrigger()
|
||||
{
|
||||
animator.ResetTrigger(ExamineItemHash);
|
||||
}
|
||||
|
||||
public float TillerDirection
|
||||
{
|
||||
get => animator.GetFloat(TillerDirectionHash);
|
||||
set => animator.SetFloat(TillerDirectionHash, value);
|
||||
}
|
||||
|
||||
public void SetTestTrigger()
|
||||
{
|
||||
animator.SetTrigger(TestTriggerHash);
|
||||
}
|
||||
|
||||
public void ResetTestTrigger()
|
||||
{
|
||||
animator.ResetTrigger(TestTriggerHash);
|
||||
}
|
||||
|
||||
public ThrowModeEnum ThrowMode
|
||||
{
|
||||
get
|
||||
{
|
||||
var val = animator.GetInteger(ThrowModeHash);
|
||||
return (ThrowModeEnum)val;
|
||||
}
|
||||
set => animator.SetInteger(ThrowModeHash, (int)value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public FPlayer Player;
|
||||
|
||||
public Animator animator;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
animator = GetComponent<Animator>();
|
||||
}
|
||||
|
||||
|
||||
#region 动画事件回调
|
||||
|
||||
/// <summary>
|
||||
/// 抛竿开始
|
||||
/// </summary>
|
||||
public void RodForceThrowStart()
|
||||
{
|
||||
if (Player.Fsm.CurrentState is PlayerThrow playerThrow)
|
||||
{
|
||||
playerThrow.RodForceThrowStart();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd3b33ae0a9148e09ab618b222f8def5
|
||||
timeCreated: 1743435615
|
||||
55
Assets/Scripts/Fishing~/Player/AnimatorCtrl/ReelAnimator.cs
Normal file
55
Assets/Scripts/Fishing~/Player/AnimatorCtrl/ReelAnimator.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class ReelAnimator : MonoBehaviour
|
||||
{
|
||||
public FReel Reel;
|
||||
|
||||
private Animator _animator;
|
||||
|
||||
#region 参数定义
|
||||
|
||||
private static readonly int ReelingHash = Animator.StringToHash("Reeling");
|
||||
private static readonly int LineOutHash = Animator.StringToHash("LineOut");
|
||||
private static readonly int UnlockHash = Animator.StringToHash("Unlock");
|
||||
private static readonly int LineOutUnlockHash = Animator.StringToHash("LineOutUnlock");
|
||||
|
||||
public float Reeling
|
||||
{
|
||||
get => _animator.GetFloat(ReelingHash);
|
||||
set => _animator.SetFloat(ReelingHash, value);
|
||||
}
|
||||
|
||||
public float Reeling2
|
||||
{
|
||||
get => _animator.GetFloat(ReelingHash);
|
||||
set => _animator.SetFloat(ReelingHash, value);
|
||||
}
|
||||
|
||||
public float LineOut
|
||||
{
|
||||
get => _animator.GetFloat(LineOutHash);
|
||||
set => _animator.SetFloat(LineOutHash, value);
|
||||
}
|
||||
|
||||
public bool Unlock
|
||||
{
|
||||
get => _animator.GetBool(UnlockHash);
|
||||
set => _animator.SetBool(UnlockHash, value);
|
||||
}
|
||||
|
||||
public bool LineOutUnlock
|
||||
{
|
||||
get => _animator.GetBool(LineOutUnlockHash);
|
||||
set => _animator.SetBool(LineOutUnlockHash, value);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_animator = GetComponent<Animator>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fc6fc8d0372240f19de917e50d56edfb
|
||||
timeCreated: 1745922779
|
||||
3
Assets/Scripts/Fishing~/Player/Boat.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Boat.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e465891621384ba890e69d4f2ee3ec27
|
||||
timeCreated: 1748265766
|
||||
104
Assets/Scripts/Fishing~/Player/Boat/Boat.cs
Normal file
104
Assets/Scripts/Fishing~/Player/Boat/Boat.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
// using WaveHarmonic.Crest;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class Boat : MonoBehaviour
|
||||
{
|
||||
private Collider boatCollider;
|
||||
|
||||
[Tooltip("移动力应施加于质心的垂直偏移量。")] [SerializeField]
|
||||
float _ForceHeightOffset;
|
||||
|
||||
[Tooltip("推力")] [SerializeField] float _ThrustPower = 10f;
|
||||
|
||||
[Tooltip("加速推力")] [SerializeField] float _ThrustMaxPower = 10f;
|
||||
|
||||
[Tooltip("转向速度")] [SerializeField] float _SteerPower = 1f;
|
||||
|
||||
[Tooltip("转弯时要转动船只。")] [Range(0, 1)] [SerializeField]
|
||||
float _TurningHeel = 0.35f;
|
||||
|
||||
[Tooltip("对浮力变化应用曲线处理。")] [SerializeField]
|
||||
AnimationCurve _BuoyancyCurveFactor = new(new Keyframe[]
|
||||
{
|
||||
new(0, 0, 0.01267637f, 0.01267637f),
|
||||
new(0.6626424f, 0.1791001f, 0.8680198f, 0.8680198f), new(1, 1, 3.38758f, 3.38758f)
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// 船坐下位置
|
||||
/// </summary>
|
||||
public Transform Place;
|
||||
|
||||
/// <summary>
|
||||
/// 船站立位置
|
||||
/// </summary>
|
||||
public Transform standPlace;
|
||||
|
||||
// /// <summary>
|
||||
// /// 浮力组件
|
||||
// /// </summary>
|
||||
// private FloatingObject _floatingObject;
|
||||
|
||||
private float _BuoyancyFactor = 1f;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
boatCollider = GetComponent<Collider>();
|
||||
// if (_floatingObject == null) _floatingObject = GetComponent<FloatingObject>();
|
||||
}
|
||||
|
||||
|
||||
public void Use(FPlayer player)
|
||||
{
|
||||
boatCollider.enabled = false;
|
||||
}
|
||||
|
||||
public void UnUse()
|
||||
{
|
||||
boatCollider.enabled = true;
|
||||
}
|
||||
|
||||
public void BoatInput(Vector2 moveInput, bool isRun = false)
|
||||
{
|
||||
// if (!_floatingObject.InWater) return;
|
||||
//
|
||||
// var input = Vector3.zero;
|
||||
// input.x = moveInput.x; // 水平转向(x轴)
|
||||
// input.z = moveInput.y; // 前后移动(y轴映射到z轴)
|
||||
//
|
||||
// var rb = _floatingObject.RigidBody;
|
||||
//
|
||||
// var power = isRun ? _ThrustMaxPower : _ThrustPower;
|
||||
//
|
||||
// // Thrust
|
||||
// var forcePosition = rb.worldCenterOfMass + _ForceHeightOffset * Vector3.up;
|
||||
// rb.AddForceAtPosition(power * input.z * transform.forward, forcePosition, ForceMode.Acceleration);
|
||||
//
|
||||
// // Steer
|
||||
// var rotation = transform.up + _TurningHeel * transform.forward;
|
||||
// rb.AddTorque(_SteerPower * input.x * rotation, ForceMode.Acceleration);
|
||||
//
|
||||
// if (input.y > 0f)
|
||||
// {
|
||||
// if (_BuoyancyFactor < 1f)
|
||||
// {
|
||||
// _BuoyancyFactor += Time.deltaTime * 0.1f;
|
||||
// _BuoyancyFactor = Mathf.Clamp(_BuoyancyFactor, 0f, 1f);
|
||||
// _floatingObject.BuoyancyForceStrength = _BuoyancyCurveFactor.Evaluate(_BuoyancyFactor);
|
||||
// }
|
||||
// }
|
||||
// else if (input.y < 0f)
|
||||
// {
|
||||
// if (_BuoyancyFactor > 0f)
|
||||
// {
|
||||
// _BuoyancyFactor -= Time.deltaTime * 0.1f;
|
||||
// _BuoyancyFactor = Mathf.Clamp(_BuoyancyFactor, 0f, 1f);
|
||||
// _floatingObject.BuoyancyForceStrength = _BuoyancyCurveFactor.Evaluate(_BuoyancyFactor);
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Boat/Boat.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Boat/Boat.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 206cf1531b7445518ce30ec8ecb0ad2a
|
||||
timeCreated: 1748265785
|
||||
119
Assets/Scripts/Fishing~/Player/FPlayer.Hand.cs
Normal file
119
Assets/Scripts/Fishing~/Player/FPlayer.Hand.cs
Normal file
@@ -0,0 +1,119 @@
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
public partial class FPlayer
|
||||
{
|
||||
/// <summary>
|
||||
/// 把鱼线放手上
|
||||
/// </summary>
|
||||
/// <param name="lHandPoint"></param>
|
||||
/// <param name="speed"></param>
|
||||
public bool PutLineToLeftHandHelper(Transform lHandPoint, float speed = 1f)
|
||||
{
|
||||
var pin = Gears.Rod.lineHandler.pinchController;
|
||||
if (!pin.isPinched)
|
||||
{
|
||||
pin.StartPinch(lHandPoint, speed);
|
||||
}
|
||||
|
||||
if (pin.isPinched && Vector3.Distance(pin.transform.position, lHandPoint.position) < 0.1f)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public float GetPlayerHandPower()
|
||||
{
|
||||
if (!Gears.Rod)
|
||||
{
|
||||
return 1f;
|
||||
}
|
||||
|
||||
if (!Gears.Rod.lineHandler)
|
||||
{
|
||||
return 1f;
|
||||
}
|
||||
|
||||
float num2 = 0f;
|
||||
|
||||
float value = 0.85f + num2;
|
||||
value = Mathf.Clamp(value, 0.5f, 1.2f);
|
||||
var num = (Gears.Rod.currentFish
|
||||
? (1f - Mathf.Clamp01(Gears.Rod.currentLineTension * value))
|
||||
: (1f - Mathf.Clamp01(Gears.Rod.linelenghtDiferent * 0.2f)));
|
||||
return Mathf.Clamp(num, 0.2f, 1.2f);
|
||||
}
|
||||
|
||||
private void MoveTowardsInteraction()
|
||||
{
|
||||
if (!interactionCCDIK)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
interactionCCDIK.solver.SetIKPositionWeight(Mathf.MoveTowards(interactionCCDIK.solver.IKPositionWeight,
|
||||
interactionTargetWeight, Time.deltaTime * 2f));
|
||||
if (Mathf.Approximately(interactionCCDIK.solver.IKPositionWeight, interactionTargetWeight))
|
||||
{
|
||||
if (interactionTargetWeight == 0f)
|
||||
{
|
||||
interactionCCDIK.solver.target = null;
|
||||
// SetHandArmature(lHandPlayer, armatureLHandPosterIdle);
|
||||
}
|
||||
|
||||
interactionCCDIK = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 控制手和线轴交互
|
||||
/// </summary>
|
||||
/// <param name="interactiveObject"></param>
|
||||
public void InteractiveMainHand(Transform interactiveObject)
|
||||
{
|
||||
if (!MainArm.TryGetComponent<CCDIK>(out var component))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (interactiveObject == null)
|
||||
{
|
||||
interactionTargetWeight = 0f;
|
||||
interactionCCDIK = component;
|
||||
if (Gears.Reel)
|
||||
{
|
||||
Data.isHandOnHandle = false;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (interactiveObject.tag)
|
||||
{
|
||||
case "Reel":
|
||||
component.solver.target = Gears.Reel.reelAsset.handle;
|
||||
interactionTargetWeight = 1f;
|
||||
interactionCCDIK = component;
|
||||
if ((bool)Gears.Rod && (bool)Gears.Reel)
|
||||
{
|
||||
Data.isHandOnHandle = true;
|
||||
}
|
||||
|
||||
break;
|
||||
case "ReelUnlock":
|
||||
// SetHandArmature(lHandPlayer, Gears.Reel.armatureLHandUnlockPoster);
|
||||
// component.solver.target = Gears.Reel.reelAsset.koblagHandle;
|
||||
interactionTargetWeight = 1f;
|
||||
interactionCCDIK = component;
|
||||
if ((bool)Gears.Rod && (bool)Gears.Reel)
|
||||
{
|
||||
Data.isHandOnHandle = false;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/FPlayer.Hand.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/FPlayer.Hand.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2ded975fdd44246a7009d06371195b2
|
||||
timeCreated: 1743521899
|
||||
214
Assets/Scripts/Fishing~/Player/FPlayer.cs
Normal file
214
Assets/Scripts/Fishing~/Player/FPlayer.cs
Normal file
@@ -0,0 +1,214 @@
|
||||
using DG.Tweening;
|
||||
using NBC;
|
||||
using NBF;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
public partial class FPlayer : MonoBehaviour
|
||||
{
|
||||
public FPlayerData Data;
|
||||
|
||||
/// <summary>
|
||||
/// 相机挂点
|
||||
/// </summary>
|
||||
public Transform CameraRoot;
|
||||
|
||||
private CCDIK interactionCCDIK;
|
||||
|
||||
private float interactionTargetWeight;
|
||||
|
||||
public Fsm<FPlayer> Fsm { get; private set; }
|
||||
|
||||
private PlayerArm[] Arms;
|
||||
public PlayerArm MainArm { get; private set; }
|
||||
|
||||
public PlayerArm MinorArm { get; private set; }
|
||||
|
||||
public PlayerAnimator PlayerAnimatorCtrl;
|
||||
|
||||
public FPlayerUseGear Gears;
|
||||
|
||||
public LureTrajectorySimulator LureTrajectorySimulator;
|
||||
|
||||
public Transform Light;
|
||||
|
||||
public Transform BackSpine;
|
||||
|
||||
public Rigidbody Rigidbody;
|
||||
|
||||
|
||||
public PlayerCharacter Character;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Character = GetComponent<PlayerCharacter>();
|
||||
PlayerAnimatorCtrl = gameObject.GetComponent<PlayerAnimator>();
|
||||
if (PlayerAnimatorCtrl == null)
|
||||
{
|
||||
PlayerAnimatorCtrl = gameObject.AddComponent<PlayerAnimator>();
|
||||
}
|
||||
|
||||
Gears = gameObject.GetComponent<FPlayerUseGear>();
|
||||
if (Gears == null)
|
||||
{
|
||||
Gears = gameObject.AddComponent<FPlayerUseGear>();
|
||||
}
|
||||
|
||||
LureTrajectorySimulator = gameObject.AddComponent<LureTrajectorySimulator>();
|
||||
|
||||
PlayerAnimatorCtrl.Player = this;
|
||||
Arms = GetComponentsInChildren<PlayerArm>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
ChangeArm();
|
||||
|
||||
InteractiveMainHand(null);
|
||||
|
||||
Init();
|
||||
}
|
||||
|
||||
|
||||
public void InitData(FPlayerData data)
|
||||
{
|
||||
Data = data;
|
||||
|
||||
|
||||
if (data.PlayerID == GameModel.RoleID)
|
||||
{
|
||||
Fishing.Inst.Player.SelfPlayer = this;
|
||||
BaseCamera.Main.transform.SetParent(CameraRoot);
|
||||
BaseCamera.Main.transform.localPosition = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
#region 初始化相关
|
||||
|
||||
private void Init()
|
||||
{
|
||||
InitFsm();
|
||||
}
|
||||
|
||||
private void InitFsm()
|
||||
{
|
||||
Fsm = new Fsm<FPlayer>("Player", this, true);
|
||||
Fsm.RegisterState<PlayerIdle>();
|
||||
Fsm.RegisterState<PlayerThrow>();
|
||||
Fsm.RegisterState<PlayerFishing>();
|
||||
Fsm.RegisterState<PlayerFight>();
|
||||
Fsm.RegisterState<PlayerShowFish>();
|
||||
Fsm.RegisterState<PlayerWaitThrow>();
|
||||
Fsm.Start<PlayerIdle>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public void ChangeArm()
|
||||
{
|
||||
var isLeftHand = PlayerAnimatorCtrl.LeftHand;
|
||||
foreach (var arm in Arms)
|
||||
{
|
||||
if (isLeftHand)
|
||||
{
|
||||
if (arm.IsLeft)
|
||||
{
|
||||
MainArm = arm;
|
||||
}
|
||||
else
|
||||
{
|
||||
MinorArm = arm;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!arm.IsLeft)
|
||||
{
|
||||
MainArm = arm;
|
||||
}
|
||||
else
|
||||
{
|
||||
MinorArm = arm;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
Fsm?.Update();
|
||||
|
||||
// CheckAndConnectRod();
|
||||
MoveTowardsInteraction();
|
||||
|
||||
if (CanChangeGear())
|
||||
{
|
||||
Gears?.Update();
|
||||
}
|
||||
|
||||
SyncLight();
|
||||
}
|
||||
|
||||
private void SyncLight()
|
||||
{
|
||||
if (Light)
|
||||
{
|
||||
if (Light.gameObject.activeSelf != Data.openLight)
|
||||
{
|
||||
Light.gameObject.SetActive(Data.openLight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Tween _fovTween; // 存储当前的Tween动画,方便中断
|
||||
private float _zoomDuration = 0.2f; // 缩放动画时间
|
||||
|
||||
public Boat NowBoat { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 切换望远镜效果(打开/关闭)
|
||||
/// </summary>
|
||||
/// <param name="isZoomIn">true=打开望远镜,false=关闭望远镜</param>
|
||||
public void ToggleTelescope()
|
||||
{
|
||||
// 如果已经有动画在运行,先停止
|
||||
_fovTween?.Kill();
|
||||
|
||||
// 根据传入的参数决定目标FOV
|
||||
float targetFOV = Data.openTelescope ? GameDef.ZoomedFOV : GameDef.NormalFOV;
|
||||
|
||||
// 使用DoTween平滑过渡FOV
|
||||
_fovTween = DOTween.To(
|
||||
() => BaseCamera.Main.fieldOfView, // 获取当前FOV
|
||||
x => BaseCamera.Main.fieldOfView = x, // 设置新FOV
|
||||
targetFOV, // 目标FOV
|
||||
_zoomDuration // 动画时间
|
||||
).SetEase(Ease.InOutQuad); // 使用缓动函数让动画更平滑
|
||||
}
|
||||
|
||||
public bool CanChangeGear()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public void EnterBoat(Boat boat)
|
||||
{
|
||||
NowBoat = boat;
|
||||
boat.Use(this);
|
||||
PlayerAnimatorCtrl.Boat = true;
|
||||
transform.parent = boat.Place;
|
||||
transform.localPosition = Vector3.zero;
|
||||
transform.localRotation = Quaternion.identity;
|
||||
Rigidbody.isKinematic = true;
|
||||
Character.CharacterController.enabled = false;
|
||||
}
|
||||
|
||||
public void ExitBoat()
|
||||
{
|
||||
NowBoat.UnUse();
|
||||
NowBoat = null;
|
||||
Rigidbody.isKinematic = true;
|
||||
Character.CharacterController.enabled = true;
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/FPlayer.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/FPlayer.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 492fca36d1134a788a47e5bf6f2fdc1e
|
||||
timeCreated: 1742313418
|
||||
81
Assets/Scripts/Fishing~/Player/FPlayerGear.cs
Normal file
81
Assets/Scripts/Fishing~/Player/FPlayerGear.cs
Normal file
@@ -0,0 +1,81 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public abstract class FPlayerGear : MonoBehaviour
|
||||
{
|
||||
private bool _isInit;
|
||||
public FPlayer Owner { get; protected set; }
|
||||
|
||||
public FGearData GearData { get; protected set; }
|
||||
|
||||
|
||||
public FRod Rod { get; protected set; }
|
||||
|
||||
public void Start()
|
||||
{
|
||||
// OnStart();
|
||||
}
|
||||
|
||||
public void Initialize(FPlayer player, FGearData gearData = null)
|
||||
{
|
||||
Owner = player;
|
||||
Rod = Owner.Gears.Rod;
|
||||
GearData = gearData;
|
||||
OnStart();
|
||||
_isInit = true;
|
||||
}
|
||||
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (!_isInit) return;
|
||||
if (!Owner || Owner.Data == null) return;
|
||||
if (!Owner.Gears) return;
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (!_isInit) return;
|
||||
OnFixedUpdate();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
if (!_isInit) return;
|
||||
OnLateUpdate();
|
||||
}
|
||||
|
||||
protected virtual void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnFixedUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnLateUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
#region 工具方法
|
||||
|
||||
protected void CheckDistance(Transform target, float distance = 0.01f)
|
||||
{
|
||||
var dis = Vector3.Distance(transform.position, target.position);
|
||||
if (dis > distance)
|
||||
{
|
||||
// transform.position = target.position;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/FPlayerGear.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/FPlayerGear.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a083c4569ab147b4b2ce8ec20ad64cba
|
||||
timeCreated: 1744029092
|
||||
345
Assets/Scripts/Fishing~/Player/FPlayerUseGear.cs
Normal file
345
Assets/Scripts/Fishing~/Player/FPlayerUseGear.cs
Normal file
@@ -0,0 +1,345 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class FPlayerUseGear : MonoBehaviour
|
||||
{
|
||||
/// <summary>
|
||||
/// 可用的
|
||||
/// </summary>
|
||||
public bool Usable { get; private set; }
|
||||
|
||||
public int UseGearId { get; private set; }
|
||||
public FPlayer Player { get; set; }
|
||||
|
||||
public FRod Rod;
|
||||
public FReel Reel;
|
||||
public FHook Hook;
|
||||
public FFloat Bobber;
|
||||
public FBait Bait;
|
||||
public FLure Lure;
|
||||
public FWeight Weight;
|
||||
public FLine Line;
|
||||
|
||||
|
||||
public Transform GearParent { get; private set; }
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Player = GetComponentInParent<FPlayer>();
|
||||
var obj = new GameObject(Player.Data.PlayerID.ToString());
|
||||
GearParent = obj.transform;
|
||||
GearParent.SetParent(SceneSettings.Instance.GearNode);
|
||||
GearParent.localPosition = Vector3.zero;
|
||||
GearParent.position = Player.transform.position;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (CheckGear())
|
||||
{
|
||||
StartCoroutine(CreateOrHideGear());
|
||||
}
|
||||
}
|
||||
|
||||
private bool CheckGear()
|
||||
{
|
||||
var nowGearId = 0;
|
||||
if (Player != null && Player.Data != null && Player.Data.currentGear != null)
|
||||
{
|
||||
nowGearId = Player.Data.currentGear.GetUnitId();
|
||||
}
|
||||
|
||||
if (UseGearId != nowGearId)
|
||||
{
|
||||
UseGearId = nowGearId;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public IEnumerator CreateOrHideGear()
|
||||
{
|
||||
if (Player.PlayerAnimatorCtrl.ItemInHands)
|
||||
{
|
||||
Player.PlayerAnimatorCtrl.ItemInHands = false;
|
||||
}
|
||||
|
||||
if (Rod != null)
|
||||
{
|
||||
yield return HideGear();
|
||||
}
|
||||
|
||||
yield return new WaitForSeconds(0.1f);
|
||||
if (Player.Data == null || Player.Data.currentGear == null) yield break;
|
||||
|
||||
var parent = GearParent;
|
||||
parent.position = Player.transform.position;
|
||||
|
||||
var data = Player.Data.currentGear;
|
||||
var rodConfig = data.rod.Config;
|
||||
var cloneObj = rodConfig.Instantiate(parent, Vector3.zero, Player.MainArm.RodContainer.rotation);
|
||||
if (cloneObj == null)
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
Rod = cloneObj.GetComponent<FRod>();
|
||||
if (Rod == null)
|
||||
{
|
||||
Rod = cloneObj.AddComponent<FRod>();
|
||||
}
|
||||
|
||||
|
||||
if (Rod)
|
||||
{
|
||||
Rod.transform.localPosition = Vector3.zero;
|
||||
Rod.transform.rotation = Player.MainArm.RodContainer.rotation;
|
||||
|
||||
if (rodConfig.ring > 0)
|
||||
{
|
||||
var ringConfig = GameRings.Get(rodConfig.ring);
|
||||
var ringObject = ringConfig.Instantiate(Rod.transform);
|
||||
ringObject.SetActive(false);
|
||||
Rod.SetRing(ringObject.GetComponent<RodRingAsset>());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (data.line != null)
|
||||
{
|
||||
var linePrefab = data.line.Config.Instantiate(parent);
|
||||
Line = linePrefab.GetComponent<FLine>();
|
||||
}
|
||||
|
||||
if (data.reel != null)
|
||||
{
|
||||
var reelPrefab = data.reel.Config.Create(parent);
|
||||
Reel = reelPrefab.GetComponent<FReel>();
|
||||
}
|
||||
|
||||
if (data.bobber != null)
|
||||
{
|
||||
var bobberPrefab = data.bobber.Config.Create(parent);
|
||||
Bobber = bobberPrefab.GetComponent<FFloat>();
|
||||
}
|
||||
|
||||
if (data.hook != null)
|
||||
{
|
||||
var hookPrefab = data.hook.Config.Create(parent);
|
||||
Hook = hookPrefab.GetComponent<FHook>();
|
||||
}
|
||||
|
||||
if (data.bait != null)
|
||||
{
|
||||
var baitPrefab = data.bait.Config.Create(parent);
|
||||
|
||||
if (baitPrefab.TryGetComponent<FBait>(out var bait))
|
||||
{
|
||||
Bait = bait;
|
||||
}
|
||||
}
|
||||
|
||||
if (data.lure != null)
|
||||
{
|
||||
var baitPrefab = data.lure.Config.Create(parent);
|
||||
if (baitPrefab.TryGetComponent<FLure>(out var lure))
|
||||
{
|
||||
Lure = lure;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (data.weight != null)
|
||||
{
|
||||
var weightPrefab = data.weight.Config.Instantiate(parent);
|
||||
Weight = weightPrefab.GetComponent<FWeight>();
|
||||
}
|
||||
|
||||
Debug.LogError("CreateOrHideGear");
|
||||
yield return 1;
|
||||
Rod.Initialize(Player, data.rod);
|
||||
Rod.CreateFishingHandler();
|
||||
|
||||
if (Line)
|
||||
{
|
||||
Line.Initialize(Player, data.line);
|
||||
|
||||
|
||||
if ((bool)Rod.lineHandler.obiRopeSegment_1)
|
||||
{
|
||||
Rod.lineHandler.obiRopeSegment_1.GetComponent<MeshRenderer>().material =
|
||||
Line.lineMat;
|
||||
}
|
||||
|
||||
if ((bool)Rod.lineHandler.obiRopeSegment_2)
|
||||
{
|
||||
Rod.lineHandler.obiRopeSegment_2.GetComponent<MeshRenderer>().material =
|
||||
Line.lineMat;
|
||||
}
|
||||
|
||||
if ((bool)Rod.lineHandler.obiRopeSegment_3)
|
||||
{
|
||||
Rod.lineHandler.obiRopeSegment_3.GetComponent<MeshRenderer>().material =
|
||||
Line.lineMat;
|
||||
}
|
||||
}
|
||||
|
||||
if (Reel)
|
||||
{
|
||||
// Reel.maxReelStrength = data.reel.Config.strength;
|
||||
// Reel.reelingSpeed = 0.5f; //slotsEquip.reel.currentSpeed;
|
||||
Reel.reelingDrag = 0.699f; //slotsEquip.reel.currentDrag;
|
||||
Reel.transform.SetParent(Rod.rodAsset.ReelConnector);
|
||||
Reel.transform.localPosition = Vector3.zero;
|
||||
Reel.transform.localEulerAngles = Vector3.zero;
|
||||
// Reel.reelAsset.szpulaObject.GetComponent<MeshRenderer>().material = Line.szpulaMat;
|
||||
Reel.Initialize(Player, data.reel);
|
||||
}
|
||||
|
||||
if (Bobber)
|
||||
{
|
||||
Bobber.floatDisplacement = data.bobber.Config.displacement;
|
||||
// if ((double)slotsEquip.ffloat.lastSetGroundValue > 0.2)
|
||||
// {
|
||||
// Bobber.newDeepth = slotsEquip.ffloat.lastSetGroundValue;
|
||||
// }
|
||||
|
||||
Bobber.newDeepth = 0.5f;
|
||||
|
||||
Bobber.Initialize(Player, data.bobber);
|
||||
Bobber.transform.position = Rod.lineHandler.LineConnector_1.transform.position;
|
||||
Bobber.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
|
||||
Rod.lineHandler.LineConnector_1.GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
|
||||
if (Hook)
|
||||
{
|
||||
Hook.Initialize(Player, data.hook);
|
||||
|
||||
Hook.transform.position = Rod.lineHandler.LineConnector_2.transform.position;
|
||||
Hook.transform.rotation = Rod.lineHandler.LineConnector_2.transform.rotation; // 确保旋转也同步
|
||||
var target = Rod.lineHandler.LineConnector_2.GetComponent<Rigidbody>();
|
||||
var joint = Hook.gameObject.GetComponent<ConfigurableJoint>();
|
||||
// // 关键设置:关闭自动锚点计算,手动设置锚点
|
||||
// joint.autoConfigureConnectedAnchor = false;
|
||||
// joint.anchor = Vector3.zero; // 以 Hook 自身中心为锚点
|
||||
// joint.connectedAnchor = Vector3.zero; // 以目标物体的中心为锚点
|
||||
joint.connectedBody = target;
|
||||
// // 强制物理引擎立即更新变换(避免1帧延迟)
|
||||
// Physics.SyncTransforms();
|
||||
// joint.autoConfigureConnectedAnchor = false;
|
||||
// joint.anchor = Vector3.zero;
|
||||
// joint.connectedAnchor = Vector3.zero;
|
||||
Rod.LureHookWaterDisplacement = Hook.GetComponent<FWaterDisplacement>();
|
||||
}
|
||||
|
||||
if (Bait)
|
||||
{
|
||||
Bait.Initialize(Player, data.bait);
|
||||
Bait.transform.position = Hook.hookAsset.baitConnector.position;
|
||||
Bait.transform.SetParent(Hook.hookAsset.baitConnector);
|
||||
}
|
||||
|
||||
if (Lure)
|
||||
{
|
||||
Lure.Initialize(Player, data.bait);
|
||||
Lure.transform.position = Rod.lineHandler.LineConnector_1.transform.position;
|
||||
Lure.gameObject.GetComponent<ConfigurableJoint>().connectedBody =
|
||||
Rod.lineHandler.LineConnector_1.GetComponent<Rigidbody>();
|
||||
Rod.LureHookWaterDisplacement = Lure.GetComponent<FWaterDisplacement>();
|
||||
}
|
||||
|
||||
if (Weight)
|
||||
{
|
||||
Weight.weight = data.weight.Config.weight;
|
||||
Weight.Initialize(Player, data.weight);
|
||||
}
|
||||
// Player.PlayerAnimatorCtrl.ItemInHands = true;
|
||||
|
||||
Player.PlayerAnimatorCtrl.ItemInHands = true;
|
||||
Player.PlayerAnimatorCtrl.ThrowMode = ThrowModeEnum.Spin;
|
||||
Player.PlayerAnimatorCtrl.ItemType = HandItemType.SpinRod;
|
||||
if (data.Type == GearType.Pole)
|
||||
{
|
||||
Player.PlayerAnimatorCtrl.ItemType = HandItemType.HandRod;
|
||||
Player.PlayerAnimatorCtrl.ThrowMode = ThrowModeEnum.Float;
|
||||
}
|
||||
|
||||
yield return 1; //等待1帧
|
||||
Rod.transform.SetParent(Player.MainArm.RodContainer);
|
||||
Rod.transform.localPosition = Vector3.zero;
|
||||
Rod.transform.rotation = Player.MainArm.RodContainer.rotation;
|
||||
// yield return 1; //等待1帧
|
||||
// Rod.lineHandler.SetStartPosition();
|
||||
// yield return 5; //等待1帧
|
||||
// Rod.lineHandler.SetStartPosition2();
|
||||
Usable = true;
|
||||
}
|
||||
|
||||
public IEnumerator HideGear()
|
||||
{
|
||||
Usable = false;
|
||||
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
DestroyGear();
|
||||
}
|
||||
|
||||
private void DestroyGear()
|
||||
{
|
||||
if (Rod != null)
|
||||
{
|
||||
if (Rod.lineHandler != null)
|
||||
{
|
||||
Destroy(Rod.lineHandler.gameObject);
|
||||
}
|
||||
|
||||
Destroy(Rod.gameObject);
|
||||
}
|
||||
|
||||
if (Reel != null)
|
||||
{
|
||||
Destroy(Reel.gameObject);
|
||||
}
|
||||
|
||||
if (Hook != null)
|
||||
{
|
||||
Destroy(Hook.gameObject);
|
||||
}
|
||||
|
||||
if (Bobber != null)
|
||||
{
|
||||
Destroy(Bobber.gameObject);
|
||||
}
|
||||
|
||||
if (Bait != null)
|
||||
{
|
||||
Destroy(Bait.gameObject);
|
||||
}
|
||||
|
||||
if (Lure != null)
|
||||
{
|
||||
Destroy(Lure.gameObject);
|
||||
}
|
||||
|
||||
if (Weight != null)
|
||||
{
|
||||
Destroy(Weight.gameObject);
|
||||
}
|
||||
|
||||
if (Line != null)
|
||||
{
|
||||
Destroy(Line.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/FPlayerUseGear.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/FPlayerUseGear.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8206f172fd9466ab462d87a0734a62c
|
||||
timeCreated: 1744208607
|
||||
3
Assets/Scripts/Fishing~/Player/Fish.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Fish.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6641d04cdbda4cf9b8b40d8e79288ff9
|
||||
timeCreated: 1742313505
|
||||
1236
Assets/Scripts/Fishing~/Player/Fish/FFish.cs
Normal file
1236
Assets/Scripts/Fishing~/Player/Fish/FFish.cs
Normal file
File diff suppressed because it is too large
Load Diff
3
Assets/Scripts/Fishing~/Player/Fish/FFish.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Fish/FFish.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: afcccd0318924ebf9adc736ea2251c81
|
||||
timeCreated: 1742313546
|
||||
625
Assets/Scripts/Fishing~/Player/Fish/FFishSystem.cs
Normal file
625
Assets/Scripts/Fishing~/Player/Fish/FFishSystem.cs
Normal file
@@ -0,0 +1,625 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class FFishSystem : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
public class FeedingZoneGroup
|
||||
{
|
||||
public enum FishMoveType
|
||||
{
|
||||
None = 0,
|
||||
Random = 1,
|
||||
Loop = 2,
|
||||
OneWay = 3
|
||||
}
|
||||
|
||||
public List<FishFeedingZone> fishFeedingZones;
|
||||
|
||||
public FishMoveType fishMoveType;
|
||||
|
||||
public bool isRandom;
|
||||
|
||||
public bool isLoop;
|
||||
|
||||
public bool isNoRepeat;
|
||||
|
||||
public Color connectLineGizmos = Color.red;
|
||||
}
|
||||
|
||||
public bool isNewSpawnerSystem = true;
|
||||
|
||||
public List<FWaterDisplacement> inwaterObjects;
|
||||
|
||||
public List<FWaterDisplacement> baitsObjects;
|
||||
|
||||
public List<FFish> inwaterFishObjects;
|
||||
|
||||
public List<FFish> inwaterFishObjectsSpawner;
|
||||
|
||||
public List<FeedingZoneGroup> feedingZoneGroup;
|
||||
|
||||
public bool viewDebugFish = true;
|
||||
|
||||
public int maxVievFishAmount = 15;
|
||||
|
||||
public int currentFishViewAmount;
|
||||
|
||||
[SerializeField] private int fishToSpawnAmount;
|
||||
|
||||
|
||||
[SerializeField] public bool isReadySetup;
|
||||
|
||||
private int maximumFishPoints = 20;
|
||||
|
||||
private float timerToReady;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
isReadySetup = false;
|
||||
if (!isNewSpawnerSystem)
|
||||
{
|
||||
SetupFeedingZones();
|
||||
}
|
||||
else
|
||||
{
|
||||
InvokeRepeating("ReSpawnerSystem", 1f, 1f);
|
||||
}
|
||||
|
||||
inwaterFishObjectsSpawner = new List<FFish>();
|
||||
InvokeRepeating("RefreshCurrentFishView", 30f, 30f);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!isNewSpawnerSystem)
|
||||
{
|
||||
if (!isReadySetup && fishToSpawnAmount == inwaterFishObjects.Count)
|
||||
{
|
||||
if (!isReadySetup)
|
||||
{
|
||||
Debug.Log("Zakończono spawnowania ryb: " + inwaterFishObjects.Count);
|
||||
}
|
||||
|
||||
isReadySetup = true;
|
||||
InvokeRepeating("RefreshFishOptimize", 2f, 2f);
|
||||
}
|
||||
}
|
||||
else if (!isReadySetup)
|
||||
{
|
||||
isReadySetup = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
if (isReadySetup)
|
||||
{
|
||||
if (!isNewSpawnerSystem)
|
||||
{
|
||||
FishDisabledMovement();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReSpawnerSystem()
|
||||
{
|
||||
// if (eagleEyes.isFishView)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
baitsObjects.Clear();
|
||||
FWaterDisplacement[] array = FindObjectsOfType<FWaterDisplacement>();
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
if (array[i].CompareTag("BaitLure"))
|
||||
{
|
||||
baitsObjects.Add(array[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (baitsObjects.Count > 0)
|
||||
{
|
||||
ReassignFishOrDestroyHookObject();
|
||||
fishToSpawnAmount = Mathf.RoundToInt(maximumFishPoints / baitsObjects.Count);
|
||||
DeleteFishOffRange();
|
||||
for (int j = 0; j < baitsObjects.Count; j++)
|
||||
{
|
||||
GenerateOnFish(baitsObjects[j].transform.position, baitsObjects[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DeleteFishOffRange()
|
||||
{
|
||||
// for (int i = 0;
|
||||
// i < inwaterFishObjectsSpawner.Count && (!(Vector3.Distance(inwaterFishObjectsSpawner[i].transform.position,
|
||||
// FScriptsHandler.Instance.m_PlayerMain.currentCameraView
|
||||
// .transform.position) < 15f));
|
||||
// i++)
|
||||
// {
|
||||
// for (int j = 0; j < baitsObjects.Count; j++)
|
||||
// {
|
||||
// if (baitsObjects[j].fishListCreated.Contains(inwaterFishObjectsSpawner[i]) &&
|
||||
// Vector3.Distance(inwaterFishObjectsSpawner[i].transform.position,
|
||||
// baitsObjects[j].transform.position) > 30f &&
|
||||
// inwaterFishObjectsSpawner[i].transform.position.y < 0f &&
|
||||
// inwaterFishObjectsSpawner[i].joiner == null)
|
||||
// {
|
||||
// baitsObjects[j].fishListCreated.Remove(inwaterFishObjectsSpawner[i]);
|
||||
// Destroy(inwaterFishObjectsSpawner[i].gameObject);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
private void DeleteOneFishFromHookObject(FWaterDisplacement hookObject)
|
||||
{
|
||||
// for (int i = 0; i < hookObject.fishListCreated.Count; i++)
|
||||
// {
|
||||
// if (Vector3.Distance(hookObject.fishListCreated[i].transform.position, hookObject.transform.position) >
|
||||
// 10f && hookObject.fishListCreated[i].joiner == null &&
|
||||
// hookObject.fishListCreated[i].currentSearchBaitLure == null && !hookObject.fishListCreated[i].isGetFish)
|
||||
// {
|
||||
// if (!(Vector3.Distance(hookObject.fishListCreated[i].transform.position,
|
||||
// FScriptsHandler.Instance.m_PlayerMain.currentCameraView.transform.position) < 15f))
|
||||
// {
|
||||
// Destroy(hookObject.fishListCreated[i].gameObject);
|
||||
// }
|
||||
//
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
public void RemoveFishFromCurrentHook(FFish fish)
|
||||
{
|
||||
for (int i = 0; i < baitsObjects.Count; i++)
|
||||
{
|
||||
if (baitsObjects[i].fishListCreated.Contains(fish))
|
||||
{
|
||||
baitsObjects[i].fishListCreated.Remove(fish);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ReassignFishOrDestroyHookObject()
|
||||
{
|
||||
for (int i = 0; i < inwaterFishObjectsSpawner.Count; i++)
|
||||
{
|
||||
bool flag = false;
|
||||
for (int j = 0; j < baitsObjects.Count; j++)
|
||||
{
|
||||
if (baitsObjects[j].fishListCreated.Contains(inwaterFishObjectsSpawner[i]))
|
||||
{
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
baitsObjects[UnityEngine.Random.Range(0, baitsObjects.Count - 1)].fishListCreated
|
||||
.Add(inwaterFishObjectsSpawner[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void GenerateOnFish(Vector3 currPosition, FWaterDisplacement hookObject = null)
|
||||
{
|
||||
if (feedingZoneGroup.Count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((bool)hookObject)
|
||||
{
|
||||
if (fishToSpawnAmount < hookObject.fishListCreated.Count)
|
||||
{
|
||||
DeleteOneFishFromHookObject(hookObject);
|
||||
return;
|
||||
}
|
||||
|
||||
if (fishToSpawnAmount == hookObject.fishListCreated.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
bool flag = false;
|
||||
Vector3 vector = currPosition + UnityEngine.Random.onUnitSphere * UnityEngine.Random.Range(20f, 25f);
|
||||
if (Vector3.Distance(vector, currPosition) < 15f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float num = ProbeDeepToTerenFromWater(vector);
|
||||
if (num < 0.3f || num == 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
vector.y = UnityEngine.Random.Range(0f - num, 0f - num * 0.5f);
|
||||
for (int i = 0; i < feedingZoneGroup.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < feedingZoneGroup[i].fishFeedingZones.Count; j++)
|
||||
{
|
||||
if (Vector3.Distance(currPosition, feedingZoneGroup[i].fishFeedingZones[j].transform.position) <
|
||||
feedingZoneGroup[i].fishFeedingZones[j].rangeZone && ProbeDeepToTerenBottom(vector))
|
||||
{
|
||||
StartCoroutine(feedingZoneGroup[i].fishFeedingZones[j].GenerateOneFish(vector, hookObject));
|
||||
flag = true;
|
||||
Debug.Log("Generate fish in zone");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag && ProbeDeepToTerenBottom(vector))
|
||||
{
|
||||
StartCoroutine(feedingZoneGroup[0].fishFeedingZones[0].GenerateOneFish(vector, hookObject));
|
||||
Debug.Log("Generate fish first zone");
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshFishOptimize()
|
||||
{
|
||||
// if (!eagleEyes.isFishView)
|
||||
// {
|
||||
// StartCoroutine(FishOptimize());
|
||||
// }
|
||||
}
|
||||
|
||||
private void SetupFeedingZones()
|
||||
{
|
||||
for (int i = 0; i < feedingZoneGroup.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < feedingZoneGroup[i].fishFeedingZones.Count; j++)
|
||||
{
|
||||
for (int k = 0; k < feedingZoneGroup[i].fishFeedingZones[j].fishPopulation.Length; k++)
|
||||
{
|
||||
fishToSpawnAmount += feedingZoneGroup[i].fishFeedingZones[j].fishPopulation[k].AmountPopulationZone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int l = 0; l < feedingZoneGroup.Count; l++)
|
||||
{
|
||||
for (int m = 0; m < feedingZoneGroup[l].fishFeedingZones.Count; m++)
|
||||
{
|
||||
feedingZoneGroup[l].fishFeedingZones[m].fFishSystem = this;
|
||||
feedingZoneGroup[l].fishFeedingZones[m].Inedex = m;
|
||||
feedingZoneGroup[l].fishFeedingZones[m].InedexOfGroup = l;
|
||||
StartCoroutine(feedingZoneGroup[l].fishFeedingZones[m].GenerateFishPopulationOnStart());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void FishDisabledMovement()
|
||||
{
|
||||
for (int i = 0; i < feedingZoneGroup.Count; i++)
|
||||
{
|
||||
for (int j = 0; j < feedingZoneGroup[i].fishFeedingZones.Count; j++)
|
||||
{
|
||||
for (int k = 0; k < feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone.Count; k++)
|
||||
{
|
||||
if (feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k] != null && !feedingZoneGroup[i]
|
||||
.fishFeedingZones[j].fishesOnZone[k].gameObject.activeSelf)
|
||||
{
|
||||
Vector3 targetPoint = feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].TargetPoint;
|
||||
feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].transform.position =
|
||||
Vector3.MoveTowards(
|
||||
feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].transform.position, targetPoint,
|
||||
Time.deltaTime * 0.8f);
|
||||
if (feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].transform.position == targetPoint)
|
||||
{
|
||||
feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].currentFeedingZone =
|
||||
GetNewTargetFeedingZone(feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k]);
|
||||
feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].TargetPoint =
|
||||
feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].currentFeedingZone.transform
|
||||
.position + new Vector3(
|
||||
UnityEngine.Random.Range(
|
||||
0f - feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].currentFeedingZone
|
||||
.rangeZone,
|
||||
feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].currentFeedingZone
|
||||
.rangeZone), UnityEngine.Random.Range(-1f, -0.2f),
|
||||
UnityEngine.Random.Range(
|
||||
0f - feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].currentFeedingZone
|
||||
.rangeZone,
|
||||
feedingZoneGroup[i].fishFeedingZones[j].fishesOnZone[k].currentFeedingZone
|
||||
.rangeZone));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public FishFeedingZone GetNewTargetFeedingZone(FFish currentFish)
|
||||
{
|
||||
int inedexOfGroup = currentFish.currentFeedingZone.InedexOfGroup;
|
||||
int inedex = currentFish.currentFeedingZone.Inedex;
|
||||
int count = feedingZoneGroup[inedexOfGroup].fishFeedingZones.Count;
|
||||
FishFeedingZone result = null;
|
||||
int num = 0;
|
||||
switch (feedingZoneGroup[inedexOfGroup].fishMoveType)
|
||||
{
|
||||
case FeedingZoneGroup.FishMoveType.None:
|
||||
if (currentFish.feedingZoneMoveState == 0)
|
||||
{
|
||||
num = inedex + 1;
|
||||
if (num >= count)
|
||||
{
|
||||
currentFish.feedingZoneMoveState = 1;
|
||||
num = inedex - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (currentFish.feedingZoneMoveState == 1)
|
||||
{
|
||||
num = inedex - 1;
|
||||
if (num < 0)
|
||||
{
|
||||
currentFish.feedingZoneMoveState = 0;
|
||||
num = inedex + 1;
|
||||
}
|
||||
}
|
||||
|
||||
result = feedingZoneGroup[inedexOfGroup].fishFeedingZones[num];
|
||||
break;
|
||||
case FeedingZoneGroup.FishMoveType.Loop:
|
||||
num = inedex + 1;
|
||||
if (num >= count)
|
||||
{
|
||||
currentFish.feedingZoneMoveState = 0;
|
||||
num = 0;
|
||||
}
|
||||
|
||||
result = feedingZoneGroup[inedexOfGroup].fishFeedingZones[num];
|
||||
break;
|
||||
case FeedingZoneGroup.FishMoveType.Random:
|
||||
num = UnityEngine.Random.Range(0, count);
|
||||
result = feedingZoneGroup[inedexOfGroup].fishFeedingZones[num];
|
||||
break;
|
||||
case FeedingZoneGroup.FishMoveType.OneWay:
|
||||
num = inedex + 1;
|
||||
if (num >= count)
|
||||
{
|
||||
currentFish.transform.position =
|
||||
feedingZoneGroup[inedexOfGroup].fishFeedingZones[0].transform.position + new Vector3(
|
||||
UnityEngine.Random.Range(0f - feedingZoneGroup[inedexOfGroup].fishFeedingZones[0].rangeZone,
|
||||
feedingZoneGroup[inedexOfGroup].fishFeedingZones[0].rangeZone),
|
||||
UnityEngine.Random.Range(-1f, -0.2f),
|
||||
UnityEngine.Random.Range(0f - feedingZoneGroup[inedexOfGroup].fishFeedingZones[0].rangeZone,
|
||||
feedingZoneGroup[inedexOfGroup].fishFeedingZones[0].rangeZone));
|
||||
num = 1;
|
||||
}
|
||||
|
||||
result = feedingZoneGroup[inedexOfGroup].fishFeedingZones[num];
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void OnDrawGizmos()
|
||||
{
|
||||
for (int i = 0; i < feedingZoneGroup.Count; i++)
|
||||
{
|
||||
switch (feedingZoneGroup[i].fishMoveType)
|
||||
{
|
||||
case FeedingZoneGroup.FishMoveType.None:
|
||||
{
|
||||
for (int k = 0; k < feedingZoneGroup[i].fishFeedingZones.Count - 1; k++)
|
||||
{
|
||||
Gizmos.color = feedingZoneGroup[i].connectLineGizmos;
|
||||
Gizmos.DrawLine(feedingZoneGroup[i].fishFeedingZones[k].transform.position,
|
||||
feedingZoneGroup[i].fishFeedingZones[k + 1].transform.position);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case FeedingZoneGroup.FishMoveType.Loop:
|
||||
{
|
||||
for (int l = 0; l < feedingZoneGroup[i].fishFeedingZones.Count - 1; l++)
|
||||
{
|
||||
Gizmos.color = feedingZoneGroup[i].connectLineGizmos;
|
||||
Gizmos.DrawLine(feedingZoneGroup[i].fishFeedingZones[l].transform.position,
|
||||
feedingZoneGroup[i].fishFeedingZones[l + 1].transform.position);
|
||||
}
|
||||
|
||||
Gizmos.DrawLine(
|
||||
feedingZoneGroup[i].fishFeedingZones[feedingZoneGroup[i].fishFeedingZones.Count - 1].transform
|
||||
.position, feedingZoneGroup[i].fishFeedingZones[0].transform.position);
|
||||
break;
|
||||
}
|
||||
case FeedingZoneGroup.FishMoveType.Random:
|
||||
{
|
||||
for (int m = 0; m < feedingZoneGroup[i].fishFeedingZones.Count; m++)
|
||||
{
|
||||
for (int n = 0; n < feedingZoneGroup[i].fishFeedingZones.Count; n++)
|
||||
{
|
||||
Gizmos.color = feedingZoneGroup[i].connectLineGizmos;
|
||||
Gizmos.DrawLine(feedingZoneGroup[i].fishFeedingZones[m].transform.position,
|
||||
feedingZoneGroup[i].fishFeedingZones[n].transform.position);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
case FeedingZoneGroup.FishMoveType.OneWay:
|
||||
{
|
||||
for (int j = 0; j < feedingZoneGroup[i].fishFeedingZones.Count - 1; j++)
|
||||
{
|
||||
Gizmos.color = feedingZoneGroup[i].connectLineGizmos;
|
||||
Gizmos.DrawLine(feedingZoneGroup[i].fishFeedingZones[j].transform.position,
|
||||
feedingZoneGroup[i].fishFeedingZones[j + 1].transform.position);
|
||||
}
|
||||
|
||||
Gizmos.color = Color.black;
|
||||
Gizmos.DrawSphere(
|
||||
feedingZoneGroup[i].fishFeedingZones[feedingZoneGroup[i].fishFeedingZones.Count - 1].transform
|
||||
.position, 0.3f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!viewDebugFish)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int num = 0; num < feedingZoneGroup[i].fishFeedingZones.Count; num++)
|
||||
{
|
||||
for (int num2 = 0; num2 < feedingZoneGroup[i].fishFeedingZones[num].fishesOnZone.Count; num2++)
|
||||
{
|
||||
if (feedingZoneGroup[i].fishFeedingZones[num].fishesOnZone[num2] != null)
|
||||
{
|
||||
Gizmos.color = feedingZoneGroup[i].connectLineGizmos;
|
||||
Gizmos.DrawSphere(
|
||||
feedingZoneGroup[i].fishFeedingZones[num].fishesOnZone[num2].transform.position, 0.2f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshCurrentFishView()
|
||||
{
|
||||
currentFishViewAmount = 0;
|
||||
for (int i = 0; i < inwaterFishObjects.Count; i++)
|
||||
{
|
||||
if (inwaterFishObjects[i].gameObject.activeSelf)
|
||||
{
|
||||
currentFishViewAmount++;
|
||||
}
|
||||
}
|
||||
|
||||
Debug.Log("RefreshCurrentFishView: " + currentFishViewAmount);
|
||||
}
|
||||
|
||||
private IEnumerator FishOptimize()
|
||||
{
|
||||
// for (int i = 0; i < inwaterFishObjects.Count; i++)
|
||||
// {
|
||||
// if (!(inwaterFishObjects[i] != null) || (bool)inwaterFishObjects[i].currentSearchBaitLure ||
|
||||
// (bool)inwaterFishObjects[i].currentBaitLure)
|
||||
// {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// float num = Vector3.Distance(FScriptsHandler.Instance.m_PlayerMain.currentCameraView.transform.position,
|
||||
// inwaterFishObjects[i].transform.position);
|
||||
// float num2 = 0f;
|
||||
// bool flag = false;
|
||||
// for (int j = 0; j < inwaterObjects.Count; j++)
|
||||
// {
|
||||
// if (inwaterObjects[j].tag == "BaitLure")
|
||||
// {
|
||||
// num2 = Vector3.Distance(inwaterObjects[j].transform.position,
|
||||
// inwaterFishObjects[i].transform.position);
|
||||
// if (inwaterObjects[j].isInWater)
|
||||
// {
|
||||
// flag = true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// Vector3.Angle(
|
||||
// inwaterFishObjects[i].transform.position -
|
||||
// FScriptsHandler.Instance.m_PlayerMain.currentCameraView.transform.position,
|
||||
// FScriptsHandler.Instance.m_PlayerMain.m_Camera.transform.forward);
|
||||
// if (flag || num < 15f)
|
||||
// {
|
||||
// if (flag && num2 < 15f && num2 > 10f)
|
||||
// {
|
||||
// if (!inwaterFishObjects[i].gameObject.activeSelf && currentFishViewAmount < maxVievFishAmount &&
|
||||
// inwaterFishObjects[i].transform.position.y < -0.5f &&
|
||||
// ProbeDeepToTerenBottom(inwaterFishObjects[i].transform.position))
|
||||
// {
|
||||
// inwaterFishObjects[i].EnableFish();
|
||||
// inwaterFishObjects[i].TimerToDisable = 5f;
|
||||
// currentFishViewAmount++;
|
||||
// yield return null;
|
||||
// }
|
||||
// }
|
||||
// // else if (num < 15f && num > 10f && (bool)FScriptsHandler.Instance.playerManager.freeCamera && !inwaterFishObjects[i].gameObject.activeSelf && currentFishViewAmount < maxVievFishAmount && inwaterFishObjects[i].transform.position.y < -0.5f && ProbeDeepToTerenBottom(inwaterFishObjects[i].transform.position))
|
||||
// else if (num < 15f && num > 10f &&
|
||||
// !inwaterFishObjects[i].gameObject.activeSelf && currentFishViewAmount < maxVievFishAmount &&
|
||||
// inwaterFishObjects[i].transform.position.y < -0.5f &&
|
||||
// ProbeDeepToTerenBottom(inwaterFishObjects[i].transform.position))
|
||||
// {
|
||||
// inwaterFishObjects[i].EnableFish();
|
||||
// inwaterFishObjects[i].TimerToDisable = 5f;
|
||||
// currentFishViewAmount++;
|
||||
// yield return null;
|
||||
// }
|
||||
// }
|
||||
// else if (inwaterFishObjects[i].gameObject.activeSelf && inwaterFishObjects[i].TimerToDisable == 0f &&
|
||||
// currentFishViewAmount > 0)
|
||||
// {
|
||||
// inwaterFishObjects[i].gameObject.SetActive(value: false);
|
||||
// currentFishViewAmount--;
|
||||
// }
|
||||
// }
|
||||
yield break;
|
||||
}
|
||||
|
||||
private bool ProbeDeepToTerenBottom(Vector3 probeObject)
|
||||
{
|
||||
int layerMask = LayerMask.GetMask("Terrain") | LayerMask.GetMask("UnderwaterObject");
|
||||
if (Physics.Raycast(probeObject, -Vector3.up, out var _, float.PositiveInfinity, layerMask))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private float ProbeDeepToTerenFromWater(Vector3 probeObject)
|
||||
{
|
||||
probeObject.y = 0f;
|
||||
int layerMask = LayerMask.GetMask("Terrain") | LayerMask.GetMask("UnderwaterObject");
|
||||
if (Physics.Raycast(probeObject, -Vector3.up, out var hitInfo, float.PositiveInfinity, layerMask))
|
||||
{
|
||||
return hitInfo.distance;
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public void AddInwaterObject(FWaterDisplacement wIobj)
|
||||
{
|
||||
if (!inwaterObjects.Contains(wIobj))
|
||||
{
|
||||
inwaterObjects.Add(wIobj);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteInwaterObject(FWaterDisplacement wIobj)
|
||||
{
|
||||
if (inwaterObjects.Contains(wIobj))
|
||||
{
|
||||
inwaterObjects.Remove(wIobj);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddInwaterFishObject(FFish wIobj)
|
||||
{
|
||||
if (!inwaterFishObjects.Contains(wIobj))
|
||||
{
|
||||
inwaterFishObjects.Add(wIobj);
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteInwaterFishObject(FFish wIobj)
|
||||
{
|
||||
if (inwaterFishObjects.Contains(wIobj))
|
||||
{
|
||||
inwaterFishObjects.Remove(wIobj);
|
||||
}
|
||||
|
||||
RemoveFishFromCurrentHook(wIobj);
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Fish/FFishSystem.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Fish/FFishSystem.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78d24bf91a0247faa2e24ec050100161
|
||||
timeCreated: 1742313889
|
||||
160
Assets/Scripts/Fishing~/Player/Fish/FishFeedingZone.cs
Normal file
160
Assets/Scripts/Fishing~/Player/Fish/FishFeedingZone.cs
Normal file
@@ -0,0 +1,160 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using NBF;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class FishFeedingZone : MonoBehaviour
|
||||
{
|
||||
[Serializable]
|
||||
public class FishPopulation
|
||||
{
|
||||
public FishSpecies FishSpecies;
|
||||
|
||||
public int AmountPopulationZone = 1;
|
||||
|
||||
public Vector2 weightRange;
|
||||
}
|
||||
|
||||
public bool fishTakeTesting;
|
||||
|
||||
public int Inedex;
|
||||
|
||||
public int InedexOfGroup;
|
||||
|
||||
public float rangeZone = 5f;
|
||||
|
||||
public FishPopulation[] fishPopulation;
|
||||
|
||||
public List<FFish> fishesOnZone;
|
||||
|
||||
public FFishSystem fFishSystem;
|
||||
public Vector3 selfV3;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
fFishSystem = FindObjectOfType<FFishSystem>();
|
||||
fishesOnZone = new List<FFish>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (!fFishSystem.isNewSpawnerSystem)
|
||||
{
|
||||
checkAndUpdateFishPopulation();
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GenerateOneFish(Vector3 startPos, FWaterDisplacement hookObject)
|
||||
{
|
||||
yield return null;
|
||||
if (fishPopulation.Length != 0)
|
||||
{
|
||||
int num = UnityEngine.Random.Range(0, fishPopulation.Length);
|
||||
float num2 = RandWeight(new Vector2(fishPopulation[num].weightRange.x, fishPopulation[num].weightRange.y));
|
||||
try
|
||||
{
|
||||
var path = GameFish.Get(t => t.speciesName == fishPopulation[num].FishSpecies).GetFishModel(num2);
|
||||
FFish component = Instantiate(path, SceneSettings.Instance.transform).GetComponent<FFish>();
|
||||
if (component == null)
|
||||
{
|
||||
int i = 0;
|
||||
}
|
||||
|
||||
component.fFishSystem = fFishSystem;
|
||||
component.fishWeight = num2;
|
||||
component.fishSpecies = fishPopulation[num].FishSpecies;
|
||||
component.transform.localScale = GameFish.Get(t => t.speciesName == fishPopulation[num].FishSpecies)
|
||||
.GetFishScale(num2);
|
||||
component.transform.position = startPos;
|
||||
component.currentFeedingZone = this;
|
||||
fishesOnZone.Add(component);
|
||||
component.EnableFish();
|
||||
fFishSystem.inwaterFishObjectsSpawner.Add(component);
|
||||
if ((bool)hookObject)
|
||||
{
|
||||
hookObject.fishListCreated.Add(component);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator GenerateFishPopulationOnStart()
|
||||
{
|
||||
yield return null;
|
||||
for (int i = 0; i < fishPopulation.Length; i++)
|
||||
{
|
||||
for (int j = 0; j < fishPopulation[i].AmountPopulationZone; j++)
|
||||
{
|
||||
Vector3 position = transform.position + UnityEngine.Random.insideUnitSphere * rangeZone;
|
||||
position.y = transform.position.y - 0.2f;
|
||||
float num = RandWeight(new Vector2(fishPopulation[i].weightRange.x, fishPopulation[i].weightRange.y));
|
||||
FFish component = Instantiate(
|
||||
GameFish.Get(t => t.speciesName == fishPopulation[i].FishSpecies).GetFishModel(num),
|
||||
SceneSettings.Instance.transform).GetComponent<FFish>();
|
||||
component.fFishSystem = fFishSystem;
|
||||
component.fishWeight = num;
|
||||
component.fishSpecies = fishPopulation[i].FishSpecies;
|
||||
component.transform.localScale = GameFish.Get(t => t.speciesName == fishPopulation[i].FishSpecies)
|
||||
.GetFishScale(num);
|
||||
component.transform.position = position;
|
||||
component.currentFeedingZone = this;
|
||||
fishesOnZone.Add(component);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkAndUpdateFishPopulation()
|
||||
{
|
||||
for (int i = 0; i < fishesOnZone.Count; i++)
|
||||
{
|
||||
if (fishesOnZone[i] == null)
|
||||
{
|
||||
int num = UnityEngine.Random.Range(0, fishPopulation.Length - 1);
|
||||
if (fishPopulation[num].AmountPopulationZone > fishesOnZone.Count)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
Vector3 position = transform.position + UnityEngine.Random.insideUnitSphere * 1f;
|
||||
position.y = transform.position.y - 0.2f;
|
||||
float num2 =
|
||||
RandWeight(new Vector2(fishPopulation[num].weightRange.x, fishPopulation[num].weightRange.y));
|
||||
FFish component = Instantiate(
|
||||
GameFish.Get(t => t.speciesName == fishPopulation[num].FishSpecies).GetFishModel(num2),
|
||||
SceneSettings.Instance.transform).GetComponent<FFish>();
|
||||
component.fFishSystem = fFishSystem;
|
||||
component.fishWeight = num2;
|
||||
component.fishSpecies = fishPopulation[num].FishSpecies;
|
||||
component.transform.localScale = GameFish.Get(t => t.speciesName == fishPopulation[num].FishSpecies)
|
||||
.GetFishScale(num2);
|
||||
component.transform.position = position;
|
||||
component.currentFeedingZone = this;
|
||||
fishesOnZone[i] = component;
|
||||
Debug.Log("Replace fish " + component.name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float RandWeight(Vector2 range)
|
||||
{
|
||||
float result = range.x;
|
||||
for (int i = 0; (float)i < 10f; i++)
|
||||
{
|
||||
result = UnityEngine.Random.Range(range.x, range.y);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void OnDrawGizmosSelected()
|
||||
{
|
||||
Gizmos.DrawWireSphere(transform.position, rangeZone);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2cb732c064e54c6aa1fbbf8fa94fa7dd
|
||||
timeCreated: 1742313898
|
||||
32
Assets/Scripts/Fishing~/Player/FixedLine.cs
Normal file
32
Assets/Scripts/Fishing~/Player/FixedLine.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class FixedLine : MonoBehaviour
|
||||
{
|
||||
public Transform target;
|
||||
private Rigidbody _rigidbody;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_rigidbody = GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
FixLine();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
FixLine();
|
||||
}
|
||||
|
||||
private void FixLine()
|
||||
{
|
||||
if (!target) return;
|
||||
_rigidbody.MovePosition(target.position);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/FixedLine.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/FixedLine.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 112f7ad42d8149c1944bb51067ef1966
|
||||
timeCreated: 1747411443
|
||||
3
Assets/Scripts/Fishing~/Player/Gear.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff517d5448b2471486bb8a6e524447d8
|
||||
timeCreated: 1743936635
|
||||
31
Assets/Scripts/Fishing~/Player/Gear/FBait.cs
Normal file
31
Assets/Scripts/Fishing~/Player/Gear/FBait.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class FBait : FPlayerGear
|
||||
{
|
||||
// private float takeRange = 5f;
|
||||
public BaitAsset baitAsset;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
baitAsset = GetComponent<BaitAsset>();
|
||||
}
|
||||
|
||||
// public bool CheckBaitEfficacy(float distanceToFish)
|
||||
// {
|
||||
// float num = 0f;
|
||||
//
|
||||
// float num2 = 100f;
|
||||
// takeRange = 1f + num2 * 0.5f;
|
||||
// int num3 = Random.Range(0, 1);
|
||||
// Debug.Log("Bait efficacy range: " + (takeRange + takeRange * num) + " Bait current efficacy < rand: " + num2 +
|
||||
// "/" + num3);
|
||||
// if ((float)num3 > num2)
|
||||
// {
|
||||
// Debug.Log("Bait efficacy is too low");
|
||||
// return false;
|
||||
// }
|
||||
//
|
||||
// return true;
|
||||
// }
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FBait.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FBait.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b3aaf527fc746ea93d9233dc8ec7ca0
|
||||
timeCreated: 1742313561
|
||||
57
Assets/Scripts/Fishing~/Player/Gear/FFeeder.cs
Normal file
57
Assets/Scripts/Fishing~/Player/Gear/FFeeder.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class FFeeder : FPlayerGear
|
||||
{
|
||||
[HideInInspector]
|
||||
public Rigidbody rigidbody;
|
||||
|
||||
[HideInInspector]
|
||||
public FWaterDisplacement waterDisplacement;
|
||||
|
||||
public ParticleSystem smuuggeParticle;
|
||||
|
||||
[HideInInspector]
|
||||
public FRod currentRod;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
rigidbody = GetComponent<Rigidbody>();
|
||||
waterDisplacement = GetComponent<FWaterDisplacement>();
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
ShowWaterFX();
|
||||
if ((bool)currentRod)
|
||||
{
|
||||
if ((bool)currentRod.currentFish)
|
||||
{
|
||||
waterDisplacement.isFreeze = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
waterDisplacement.isFreeze = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowWaterFX()
|
||||
{
|
||||
if (smuuggeParticle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (waterDisplacement.waterHeightPosition - 0.1f <= transform.position.y && waterDisplacement.waterHeightPosition + 0.1f > transform.position.y)
|
||||
{
|
||||
if (!smuuggeParticle.isEmitting)
|
||||
{
|
||||
smuuggeParticle.Play();
|
||||
}
|
||||
}
|
||||
else if (smuuggeParticle.isPlaying)
|
||||
{
|
||||
smuuggeParticle.Stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FFeeder.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FFeeder.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b9877b136184e20a98cd45d0e067a2b
|
||||
timeCreated: 1742313572
|
||||
248
Assets/Scripts/Fishing~/Player/Gear/FFloat.cs
Normal file
248
Assets/Scripts/Fishing~/Player/Gear/FFloat.cs
Normal file
@@ -0,0 +1,248 @@
|
||||
// using UltimateWater;
|
||||
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class FFloat : FPlayerGear
|
||||
{
|
||||
[HideInInspector] public Rigidbody rigidbody;
|
||||
|
||||
[HideInInspector] public FWaterDisplacement waterDisplacement;
|
||||
|
||||
public float currentFloatDeepth = 0.2f;
|
||||
|
||||
public float newDeepth { get; set; } = 0.21f;
|
||||
|
||||
public float floatDisplacement;
|
||||
|
||||
// private BoxCollider collider;
|
||||
|
||||
private float startWaterInteractiveMultiple = 5f;
|
||||
|
||||
private Transform currentWaterDrop;
|
||||
|
||||
// [SerializeField] public Transform scallingObject;
|
||||
|
||||
private bool destroyDropFx;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
rigidbody = GetComponent<Rigidbody>();
|
||||
waterDisplacement = GetComponent<FWaterDisplacement>();
|
||||
waterDisplacement.objectDisplacement = floatDisplacement;
|
||||
// collider = GetComponent<BoxCollider>();
|
||||
if (Owner.Gears.Rod)
|
||||
{
|
||||
Owner.Gears.Rod.lineHandler.SetSegmentTwoLenght(currentFloatDeepth);
|
||||
}
|
||||
|
||||
// if ((bool)waterInteractive)
|
||||
// {
|
||||
// waterInteractive.enabled = false;
|
||||
// startWaterInteractiveMultiple = waterInteractive.Multiplier;
|
||||
// }
|
||||
|
||||
Invoke("EnableWaterInteractive", 3f);
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if ((bool)Owner.Gears.Rod)
|
||||
{
|
||||
if ((bool)Owner.Gears.Rod.currentFish)
|
||||
{
|
||||
waterDisplacement.isFreeze = true;
|
||||
waterDisplacement.useSplashes = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
waterDisplacement.isFreeze = false;
|
||||
waterDisplacement.useSplashes = true;
|
||||
}
|
||||
|
||||
ShowWaterFX();
|
||||
SetDeepth();
|
||||
// Scalling();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnFixedUpdate()
|
||||
{
|
||||
DisplcementController();
|
||||
}
|
||||
|
||||
// private void Scalling()
|
||||
// {
|
||||
// if ((bool)Owner.Gears.Rod.lineHandler &&
|
||||
// (bool)Owner.Gears.Rod.lineHandler.EndLineRigidbody_0)
|
||||
// {
|
||||
// // float floatSize = GameManager.Instance._playerData
|
||||
// // .Player[GameManager.Instance._playerData.currentPlayerProfileIndex].floatSize;
|
||||
//
|
||||
// float floatSize = 1; //Owner.Data.currentGear.bobber.Config.weight;
|
||||
// float num = Vector3.Distance(
|
||||
// Owner.Gears.Rod.lineHandler.EndLineRigidbody_0.transform.position,
|
||||
// scallingObject.transform.position);
|
||||
// // if ((bool)waterInteractive)
|
||||
// // {
|
||||
// // waterInteractive.Multiplier = startWaterInteractiveMultiple / (scallingObject.localScale.x * 2f);
|
||||
// // }
|
||||
//
|
||||
// // if (FScriptsHandler.Instance.m_PlayerMain.currentCameraView !=
|
||||
// // FScriptsHandler.Instance.m_PlayerMain.m_Camera)
|
||||
// // {
|
||||
// // scallingObject.localScale = Vector3.one;
|
||||
// // }
|
||||
// // else
|
||||
// if (waterDisplacement.isInWater && !Owner.Gears.Rod.currentFish)
|
||||
// {
|
||||
// float value = 1f + num * 0.4f / floatSize * floatSize;
|
||||
// value = Mathf.Clamp(value, 0f, floatSize);
|
||||
// scallingObject.localScale =
|
||||
// Vector3.MoveTowards(scallingObject.localScale, Vector3.one * value, Time.deltaTime * 5f);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// scallingObject.localScale =
|
||||
// Vector3.MoveTowards(scallingObject.localScale, Vector3.one, Time.deltaTime * 10f);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
private void EnableWaterInteractive()
|
||||
{
|
||||
// if ((bool)waterInteractive)
|
||||
// {
|
||||
// waterInteractive.enabled = true;
|
||||
// }
|
||||
}
|
||||
|
||||
private void DisplcementController()
|
||||
{
|
||||
if (!Owner.Gears.Rod || !Owner.Gears.Weight)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (waterDisplacement.isInWater)
|
||||
{
|
||||
float value = floatDisplacement - Owner.Gears.Weight.weight + 1f;
|
||||
value = Mathf.Clamp(value, -1f, 2f);
|
||||
waterDisplacement.objectDisplacement = value;
|
||||
// if ((value > 1.5f && rigidbody.linearVelocity.magnitude < 1f) || ProbeDeep(transform) < currentFloatDeepth)
|
||||
// {
|
||||
// collider.center = new Vector3(0f, collider.center.y, 0.07f);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// collider.center = new Vector3(0f, collider.center.y, 0f);
|
||||
// }
|
||||
}
|
||||
else
|
||||
{
|
||||
// collider.center = new Vector3(0f, collider.center.y, 0f);
|
||||
}
|
||||
}
|
||||
|
||||
private float ProbeDeep(Transform probeObject)
|
||||
{
|
||||
int mask = LayerMask.GetMask("Terrain");
|
||||
float result = 0f;
|
||||
if (Physics.Raycast(probeObject.transform.position, -Vector3.up, out var hitInfo, float.PositiveInfinity, mask))
|
||||
{
|
||||
result = hitInfo.distance;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private void SetDeepth()
|
||||
{
|
||||
if ((bool)Owner.Gears.Rod && (bool)Owner.Gears.Hook &&
|
||||
!(Owner.Data.lineLength > 2f) && !Owner.Gears.Rod.currentFish)
|
||||
{
|
||||
if (newDeepth != currentFloatDeepth)
|
||||
{
|
||||
Owner.Gears.Rod.lineHandler.SetSegmentTwoLenght(newDeepth);
|
||||
currentFloatDeepth = newDeepth;
|
||||
}
|
||||
|
||||
// if (InputManager.isDeepthFloatUp)
|
||||
// {
|
||||
// newDeepth += 0.1f;
|
||||
// newDeepth = Mathf.Clamp(newDeepth, 0.15f, 2.5f);
|
||||
// Owner.Data.currentGear.SetBobberLastSetGroundValue(newDeepth);
|
||||
// // GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + newDeepth.ToString("F2") + " m", FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
|
||||
// }
|
||||
//
|
||||
// if (InputManager.isDeepthFloatDown)
|
||||
// {
|
||||
// newDeepth -= 0.1f;
|
||||
// newDeepth = Mathf.Clamp(newDeepth, 0.15f, 2.5f);
|
||||
//
|
||||
// Owner.Data.currentGear.SetBobberLastSetGroundValue(newDeepth);
|
||||
// // GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + newDeepth.ToString("F2") + " m", FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
|
||||
// }
|
||||
|
||||
if (Owner.Data.selectorRodSetting == SelectorRodSetting.Leeder &&
|
||||
Input.mouseScrollDelta.y != 0f && Time.timeScale != 0f)
|
||||
{
|
||||
newDeepth += Input.mouseScrollDelta.y * 0.02f;
|
||||
newDeepth = Mathf.Clamp(newDeepth, 0.15f, 2.5f);
|
||||
Owner.Data.currentGear.SetBobberLastSetGroundValue(newDeepth);
|
||||
// GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("SET_FLOAT_DEEPTH_TO") + newDeepth.ToString("F2") + " m", FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DestroyDelayFxDrop()
|
||||
{
|
||||
if ((bool)currentWaterDrop)
|
||||
{
|
||||
Destroy(currentWaterDrop.gameObject);
|
||||
destroyDropFx = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowWaterFX()
|
||||
{
|
||||
// float num = 0f - transform.position.y;
|
||||
// if (num < 0.1f && num > -0.1f)
|
||||
// {
|
||||
// if (!currentWaterDrop)
|
||||
// {
|
||||
// currentWaterDrop = Instantiate(FScriptsHandler.Instance.waterFishSplash[2],
|
||||
// transform.position, Quaternion.identity, transform.parent).transform;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// currentWaterDrop.position = new Vector3(transform.position.x, 0f, transform.position.z);
|
||||
// }
|
||||
// }
|
||||
// else if ((bool)currentWaterDrop)
|
||||
// {
|
||||
// if (!destroyDropFx)
|
||||
// {
|
||||
// Invoke("DestroyDelayFxDrop", 4f);
|
||||
// }
|
||||
//
|
||||
// destroyDropFx = true;
|
||||
// }
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if ((bool)currentWaterDrop)
|
||||
{
|
||||
Destroy(currentWaterDrop.gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
#region Test
|
||||
|
||||
public void Test(int type)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FFloat.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FFloat.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe65a4c7c8124d9eaaee85e579b4d341
|
||||
timeCreated: 1742313491
|
||||
114
Assets/Scripts/Fishing~/Player/Gear/FHook.cs
Normal file
114
Assets/Scripts/Fishing~/Player/Gear/FHook.cs
Normal file
@@ -0,0 +1,114 @@
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class FHook : FPlayerGear
|
||||
{
|
||||
[HideInInspector] public Rigidbody rigidbody;
|
||||
|
||||
[HideInInspector] public FWaterDisplacement waterDisplacement;
|
||||
|
||||
// [HideInInspector] public FRod currentRod;
|
||||
|
||||
[Tooltip("Punkt połaczenia z rybą")] public Rigidbody fishJoiner;
|
||||
|
||||
public Vector3 rotationInFishJaw = Vector3.zero;
|
||||
|
||||
public bool isLookingDisable;
|
||||
|
||||
private float hookTimer;
|
||||
|
||||
public int hookNotAcceptFishCounter;
|
||||
|
||||
|
||||
public HookAsset hookAsset;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
hookAsset = GetComponent<HookAsset>();
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
rigidbody = GetComponent<Rigidbody>();
|
||||
waterDisplacement = GetComponent<FWaterDisplacement>();
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
if (!Owner.Gears.Rod)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if ((bool)Owner.Gears.Rod.currentFish)
|
||||
{
|
||||
waterDisplacement.isFreeze = true;
|
||||
waterDisplacement.useSplashes = false;
|
||||
AddHookNotAcceptedCount(reset: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
waterDisplacement.isFreeze = false;
|
||||
waterDisplacement.useSplashes = true;
|
||||
if (waterDisplacement.isInWater)
|
||||
{
|
||||
Quaternion b = Quaternion.Euler(0f, rigidbody.transform.localEulerAngles.y,
|
||||
rigidbody.linearVelocity.x - 1f);
|
||||
rigidbody.rotation = Quaternion.Slerp(rigidbody.rotation, b, Time.deltaTime * 1f);
|
||||
if ((bool)Owner.Gears.Rod.takeFish)
|
||||
{
|
||||
AddHookNotAcceptedCount(reset: true);
|
||||
}
|
||||
else
|
||||
{
|
||||
AddHookNotAcceptedCount(reset: false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
AddHookNotAcceptedCount(reset: true);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Owner.Gears.Rod.takeFish && !Owner.Gears.Rod.currentFish && isLookingDisable)
|
||||
{
|
||||
isLookingDisable = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddHookNotAcceptedCount(bool reset)
|
||||
{
|
||||
// if (GameManager.Instance._playerData.Player[GameManager.Instance._playerData.currentPlayerProfileIndex]
|
||||
// .gameMode == GameManager.PlayerData.CPlayer.GameMode.Realistic ||
|
||||
// FScriptsHandler.Instance.m_PlayerMain.currentRod != currentRod)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
|
||||
if (reset)
|
||||
{
|
||||
hookTimer = 0f;
|
||||
hookNotAcceptFishCounter = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
hookTimer += Time.deltaTime;
|
||||
if (hookTimer >= 300f && hookNotAcceptFishCounter > 5)
|
||||
{
|
||||
hookTimer = 0f;
|
||||
hookNotAcceptFishCounter = 0;
|
||||
// GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("HOOK_NOT_ACCEPT_FISH_INFO"), FScriptsHandler.Instance.m_Canvas.transform);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollisionEnter(Collision collision)
|
||||
{
|
||||
// if (!waterDisplacement.isInWater && (bool)Owner.Gears.Rod &&
|
||||
// (bool)Owner.Gears.Rod.lineHandler && !Owner.Gears.Rod.currentFish &&
|
||||
// Owner.Data.lineLength > 5f &&
|
||||
// Vector3.Distance(transform.position, Owner.Gears.Rod.transform.position) > 5f)
|
||||
// {
|
||||
// GameManager.Instance.ShowMessagePopup(LanguageManager.Instance.GetText("HOOK_ON_THE_GROUND"), FScriptsHandler.Instance.m_Canvas.transform, deleteLast: true);
|
||||
// }
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FHook.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FHook.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8caddc7ca53a49f488f61f5ab8475cdb
|
||||
timeCreated: 1742313498
|
||||
17
Assets/Scripts/Fishing~/Player/Gear/FLine.cs
Normal file
17
Assets/Scripts/Fishing~/Player/Gear/FLine.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class FLine : FPlayerGear
|
||||
{
|
||||
public Material szpulaMat;
|
||||
|
||||
public Material lineMat;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FLine.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FLine.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c385b627bfeb489fa629ea1a77730b8e
|
||||
timeCreated: 1742313472
|
||||
190
Assets/Scripts/Fishing~/Player/Gear/FLineHandler.cs
Normal file
190
Assets/Scripts/Fishing~/Player/Gear/FLineHandler.cs
Normal file
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using NBF;
|
||||
using Obi;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
public class FLineHandler : MonoBehaviour
|
||||
{
|
||||
public enum LineType
|
||||
{
|
||||
None = 0,
|
||||
OneSegment = 1,
|
||||
TwoSegment = 2,
|
||||
ThereSegment = 3
|
||||
}
|
||||
|
||||
public LineType lineType = LineType.TwoSegment;
|
||||
|
||||
public ObiRope obiRopeSegment_1;
|
||||
|
||||
public ObiRope obiRopeSegment_2;
|
||||
|
||||
public ObiRope obiRopeSegment_3;
|
||||
|
||||
public FixedLine LineConnector_0;
|
||||
|
||||
public SpringJoint LineConnector_1;
|
||||
|
||||
public SpringJoint LineConnector_2;
|
||||
|
||||
public SpringJoint LineConnector_3;
|
||||
|
||||
// [HideInInspector] public FFishingLine currentRodFishingLineComponent;
|
||||
|
||||
// public ObiParticleAttachment toRodConnector;
|
||||
|
||||
// public float PhisicsLineOut { get; set; }
|
||||
|
||||
public float ObiLineOut;
|
||||
|
||||
[HideInInspector] public Rigidbody EndLineRigidbody_0;
|
||||
|
||||
[HideInInspector] public Rigidbody EndLineRigidbody_1;
|
||||
|
||||
[HideInInspector] public Rigidbody EndLineRigidbody_2;
|
||||
|
||||
[HideInInspector] public Rigidbody EndLineRigidbody_3;
|
||||
|
||||
public JointPinchController pinchController;
|
||||
|
||||
public FRod Rod;
|
||||
|
||||
private Transform waterPlane;
|
||||
|
||||
|
||||
// public float ropeToHookDistance;
|
||||
|
||||
void Start()
|
||||
{
|
||||
ObiLineOut = obiRopeSegment_1.stretchingScale;
|
||||
if ((bool)LineConnector_0)
|
||||
{
|
||||
EndLineRigidbody_0 = LineConnector_0.GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
if ((bool)LineConnector_1)
|
||||
{
|
||||
EndLineRigidbody_1 = LineConnector_1.GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
if ((bool)LineConnector_2)
|
||||
{
|
||||
EndLineRigidbody_2 = LineConnector_2.GetComponent<Rigidbody>();
|
||||
// var fixedJoint = LineConnector_2.GetComponent<FixedJoint>();
|
||||
pinchController = LineConnector_2.gameObject.AddComponent<JointPinchController>();
|
||||
}
|
||||
|
||||
if ((bool)LineConnector_3)
|
||||
{
|
||||
EndLineRigidbody_3 = LineConnector_3.GetComponent<Rigidbody>();
|
||||
}
|
||||
|
||||
waterPlane = GameObject.FindGameObjectWithTag("Water").transform;
|
||||
|
||||
Debug.LogError($"rope.restLength={obiRopeSegment_1.restLength} LineConnector_1={LineConnector_1.maxDistance}");
|
||||
}
|
||||
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!Rod) return;
|
||||
|
||||
|
||||
// ropeToHookDistance = Vector3.Distance(toRodConnector.transform.position, LineConnector_1.transform.position);
|
||||
|
||||
ObiLineOut = 0.1f + Rod.Owner.Data.lineLength;
|
||||
float target = (0f - Mathf.Clamp(Rod.linelenghtDiferent, -1f, 0f)) * 0.1f;
|
||||
if (Rod.linelenghtDiferent >= 0f)
|
||||
{
|
||||
obiRopeSegment_1.stretchCompliance = Mathf.MoveTowards(obiRopeSegment_1.stretchCompliance, target,
|
||||
Time.smoothDeltaTime * (1f * Rod.linelenghtDiferent));
|
||||
}
|
||||
else
|
||||
{
|
||||
obiRopeSegment_1.stretchCompliance = Mathf.MoveTowards(obiRopeSegment_1.stretchCompliance, target,
|
||||
Time.smoothDeltaTime * 0.1f);
|
||||
}
|
||||
|
||||
if (Rod.Owner.Data.lineLength == 0f)
|
||||
{
|
||||
obiRopeSegment_1.stretchCompliance = 0f;
|
||||
}
|
||||
|
||||
if ((bool)obiRopeSegment_2)
|
||||
{
|
||||
if (!Rod.currentFish)
|
||||
{
|
||||
obiRopeSegment_2.stretchCompliance = obiRopeSegment_2.stretchingScale * 0.004f;
|
||||
}
|
||||
else
|
||||
{
|
||||
obiRopeSegment_2.stretchCompliance = 0f;
|
||||
}
|
||||
|
||||
//TODO:TEST
|
||||
obiRopeSegment_2.stretchingScale = 0.13F;
|
||||
}
|
||||
|
||||
obiRopeSegment_1.stretchingScale = ObiLineOut;
|
||||
obiRopeSegment_1.stretchingScale = 1;
|
||||
LineConnector_1.maxDistance = 0.1f + Rod.Owner.Data.lineLength;
|
||||
if (Input.GetKey(KeyCode.E))
|
||||
{
|
||||
// var speed = 1;
|
||||
// obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
|
||||
// Debug.Log(obiRopeSegment_1.restLength);
|
||||
}
|
||||
|
||||
// var addLength = LineConnector_1.maxDistance - obiRopeSegment_1.restLength;
|
||||
// if (Mathf.Abs(addLength) > 0.001f)
|
||||
// {
|
||||
// obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
|
||||
// }
|
||||
|
||||
// if (!Mathf.Approximately(LineConnector_1.maxDistance, obiRopeSegment_1.restLength))
|
||||
// {
|
||||
// obiRopeCursor_1.ChangeLength(LineConnector_1.maxDistance);
|
||||
// }
|
||||
|
||||
// obiRopeCursor_1.pos
|
||||
|
||||
|
||||
// LineConnector_1.minDistance = LineConnector_1.maxDistance;
|
||||
}
|
||||
|
||||
public void SetSegmentTwoLenght(float lenght)
|
||||
{
|
||||
LineConnector_2.maxDistance = lenght;
|
||||
// obiRopeCursor_2.ChangeLength(lenght);
|
||||
// LineConnector_2.minDistance = LineConnector_2.maxDistance;
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
// BindRod();
|
||||
LineWaterDisplacement();
|
||||
}
|
||||
|
||||
private void BindRod()
|
||||
{
|
||||
if (!Rod || !Rod.rodAsset) return;
|
||||
LineConnector_0.transform.position = Rod.rodAsset.lineConnector.position;
|
||||
}
|
||||
|
||||
private void LineWaterDisplacement()
|
||||
{
|
||||
if (!waterPlane)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < obiRopeSegment_1.activeParticleCount; i++)
|
||||
{
|
||||
if (obiRopeSegment_1.GetParticlePosition(i).y < waterPlane.position.y)
|
||||
{
|
||||
// obiRopeSegment_1.AddForceParticle(i, Vector3.up * 10f, ForceMode.Acceleration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FLineHandler.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FLineHandler.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7a4deeedd2674b1ca2aad8d40f519ceb
|
||||
timeCreated: 1742313668
|
||||
248
Assets/Scripts/Fishing~/Player/Gear/FLure.cs
Normal file
248
Assets/Scripts/Fishing~/Player/Gear/FLure.cs
Normal file
@@ -0,0 +1,248 @@
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class FLure : FPlayerGear
|
||||
{
|
||||
public enum MoveType
|
||||
{
|
||||
None = 0,
|
||||
PowolnyWleczony = 1,
|
||||
Wleczony = 2,
|
||||
Opadający = 3,
|
||||
PowolnyOpadający = 4
|
||||
}
|
||||
|
||||
|
||||
[HideInInspector] public Rigidbody rigidbody;
|
||||
|
||||
[HideInInspector] public FWaterDisplacement waterDisplacement;
|
||||
|
||||
public Rigidbody fishJoiner;
|
||||
|
||||
public bool isLookingDisable;
|
||||
|
||||
// private Animator animator;
|
||||
|
||||
[HideInInspector] public FFish currentFish;
|
||||
|
||||
[HideInInspector] public float percentEfficacy;
|
||||
|
||||
public MoveType LureMoveType = MoveType.Wleczony;
|
||||
|
||||
[HideInInspector] public MoveType currentMoveType;
|
||||
|
||||
private MoveType newMoveType;
|
||||
|
||||
private float delayMoveTypeTimer;
|
||||
|
||||
private float moveTowardsFactor;
|
||||
|
||||
private float moveUpperFactor;
|
||||
|
||||
private float waterHeightPosition;
|
||||
|
||||
private Transform currentWaterDrop;
|
||||
|
||||
private float rotateVelo;
|
||||
|
||||
private bool destroyDropFx;
|
||||
|
||||
public LureAsset lureAsset;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
lureAsset = GetComponent<LureAsset>();
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
rigidbody = GetComponent<Rigidbody>();
|
||||
waterDisplacement = GetComponent<FWaterDisplacement>();
|
||||
// animator = GetComponent<Animator>();
|
||||
waterHeightPosition = SceneSettings.Instance.WaterObject.position.y;
|
||||
if (!fishJoiner)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FixedJoint component = fishJoiner.GetComponent<FixedJoint>();
|
||||
if ((bool)component && !component.connectedBody)
|
||||
{
|
||||
if ((bool)component.transform.parent.GetComponent<Rigidbody>())
|
||||
{
|
||||
component.connectedBody = component.transform.parent.GetComponent<Rigidbody>();
|
||||
}
|
||||
else
|
||||
{
|
||||
component.connectedBody = transform.GetComponent<Rigidbody>();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
// transform.position = Rod.lineHandler.LineConnector_1.transform.position;
|
||||
RotationToVelocity();
|
||||
// ShowWaterFX();
|
||||
MoveTypeController();
|
||||
if ((bool)currentFish)
|
||||
{
|
||||
waterDisplacement.isFreeze = true;
|
||||
if (fishJoiner) fishJoiner.gameObject.SetActive(true);
|
||||
if (!currentFish.isGetFish && transform.parent == currentFish.baitContainer)
|
||||
{
|
||||
transform.localPosition = Vector3.zero;
|
||||
transform.localEulerAngles = lureAsset.rotationInFishJaw;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
waterDisplacement.isFreeze = false;
|
||||
if (fishJoiner) fishJoiner.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (!Rod.takeFish && !Rod.currentFish && isLookingDisable)
|
||||
{
|
||||
isLookingDisable = false;
|
||||
}
|
||||
|
||||
// if ((bool)animator && transform.position.y < 0.2f && animator.runtimeAnimatorController != null)
|
||||
// {
|
||||
// animator.SetFloat("Speed", rigidbody.linearVelocity.magnitude);
|
||||
// }
|
||||
|
||||
// CheckDistance(Rod.lineHandler.LineConnector_1.transform);
|
||||
}
|
||||
|
||||
private void RotationToVelocity()
|
||||
{
|
||||
if (!waterDisplacement)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (transform.position.y > 0.02f)
|
||||
{
|
||||
// if (transform.position.y > 0.2f && (bool)animator)
|
||||
// {
|
||||
// animator.SetFloat("Speed", 0f);
|
||||
// }
|
||||
|
||||
rigidbody.freezeRotation = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Rod.linelenghtDiferent <= 0f)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
rigidbody.freezeRotation = true;
|
||||
Vector3 vector = new Vector3(rigidbody.linearVelocity.x, 0f, rigidbody.linearVelocity.z);
|
||||
if (vector != Vector3.zero)
|
||||
{
|
||||
Quaternion b = Quaternion.LookRotation(vector, Vector3.up);
|
||||
transform.rotation = Quaternion.Slerp(transform.rotation, b,
|
||||
rigidbody.linearVelocity.magnitude * 5f * Time.deltaTime);
|
||||
}
|
||||
|
||||
if (lureAsset.rotateVeloMaxAngle > 0f)
|
||||
{
|
||||
rotateVelo = lureAsset.rotateVeloMaxAngle *
|
||||
(1f - Mathf.PingPong(
|
||||
Time.time * rigidbody.linearVelocity.normalized.magnitude *
|
||||
lureAsset.rotateVeloMaxSpeed, 2f));
|
||||
}
|
||||
else if (lureAsset.rotateVeloMaxAngle == 0f)
|
||||
{
|
||||
rotateVelo = Time.time * rigidbody.linearVelocity.normalized.magnitude * lureAsset.rotateVeloMaxSpeed;
|
||||
}
|
||||
|
||||
if (rigidbody.linearVelocity.magnitude > 0f)
|
||||
{
|
||||
if (lureAsset.rotateVeloMaxAngle == 0f)
|
||||
{
|
||||
transform.Rotate(Vector3.forward, rotateVelo);
|
||||
return;
|
||||
}
|
||||
|
||||
transform.Rotate(Vector3.up, rotateVelo);
|
||||
rigidbody.AddForce(transform.right * rotateVelo, ForceMode.Acceleration);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void MoveTypeController()
|
||||
{
|
||||
if (transform.position.y > waterHeightPosition + 0.1f ||
|
||||
Vector3.Distance(Rod.transform.position, transform.position) < 5f)
|
||||
{
|
||||
moveTowardsFactor = 0f;
|
||||
moveUpperFactor = 0f;
|
||||
percentEfficacy = 0f;
|
||||
currentMoveType = MoveType.None;
|
||||
newMoveType = MoveType.None;
|
||||
return;
|
||||
}
|
||||
|
||||
float num = (Mathf.Abs(rigidbody.linearVelocity.x) + Mathf.Abs(rigidbody.linearVelocity.z)) * 0.5f;
|
||||
moveTowardsFactor = Mathf.MoveTowards(moveTowardsFactor, Mathf.Clamp01(num * 1.5f), Time.deltaTime * 0.5f);
|
||||
moveUpperFactor = Mathf.MoveTowards(moveUpperFactor, Mathf.Clamp01((0f - rigidbody.linearVelocity.y) * 1.3f),
|
||||
Time.deltaTime * 0.5f);
|
||||
if (moveTowardsFactor > 0.01f && moveTowardsFactor < 0.5f)
|
||||
{
|
||||
newMoveType = MoveType.PowolnyWleczony;
|
||||
}
|
||||
else if (moveTowardsFactor >= 0.5f && moveTowardsFactor < 1f)
|
||||
{
|
||||
newMoveType = MoveType.Wleczony;
|
||||
}
|
||||
else if (moveTowardsFactor <= 0.1f)
|
||||
{
|
||||
if (moveUpperFactor > 0f && moveUpperFactor < 0.4f)
|
||||
{
|
||||
newMoveType = MoveType.PowolnyOpadający;
|
||||
}
|
||||
else if (moveUpperFactor >= 0.4f && moveUpperFactor < 0.8f)
|
||||
{
|
||||
newMoveType = MoveType.Opadający;
|
||||
}
|
||||
else
|
||||
{
|
||||
newMoveType = MoveType.None;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
newMoveType = MoveType.None;
|
||||
}
|
||||
|
||||
if (currentMoveType == LureMoveType)
|
||||
{
|
||||
percentEfficacy = Mathf.MoveTowards(percentEfficacy, 1f, Time.deltaTime * 0.4f);
|
||||
}
|
||||
else
|
||||
{
|
||||
percentEfficacy = Mathf.MoveTowards(percentEfficacy, 0f, Time.deltaTime * 0.2f);
|
||||
}
|
||||
|
||||
if (newMoveType != currentMoveType)
|
||||
{
|
||||
delayMoveTypeTimer += Time.deltaTime;
|
||||
if (delayMoveTypeTimer > 1f)
|
||||
{
|
||||
currentMoveType = newMoveType;
|
||||
delayMoveTypeTimer = 0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
if ((bool)currentWaterDrop)
|
||||
{
|
||||
Destroy(currentWaterDrop.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FLure.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FLure.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 50530999eb5a4f0299ebc5a90e94b229
|
||||
timeCreated: 1742313444
|
||||
53
Assets/Scripts/Fishing~/Player/Gear/FReel.cs
Normal file
53
Assets/Scripts/Fishing~/Player/Gear/FReel.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
public class FReel : FPlayerGear
|
||||
{
|
||||
public bool isBlockLineByFinger { get; set; }
|
||||
|
||||
|
||||
[SerializeField] public float reelingDrag = 1f;
|
||||
|
||||
|
||||
public ReelAsset reelAsset;
|
||||
|
||||
public ReelAnimator AnimatorCtrl;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
reelAsset = GetComponent<ReelAsset>();
|
||||
AnimatorCtrl = reelAsset.animator.gameObject.GetComponent<ReelAnimator>();
|
||||
if (AnimatorCtrl == null)
|
||||
{
|
||||
AnimatorCtrl = reelAsset.animator.gameObject.AddComponent<ReelAnimator>();
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
AnimatorCtrl.Reeling = Owner.Data.reelSpeed;
|
||||
if (Owner.Data.reelSpeed > 0)
|
||||
{
|
||||
Unlock();
|
||||
}
|
||||
// Reeling();
|
||||
}
|
||||
|
||||
public void Unlock(bool unlock = true)
|
||||
{
|
||||
if (unlock)
|
||||
{
|
||||
AnimatorCtrl.Unlock = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
AnimatorCtrl.Unlock = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FReel.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FReel.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a31a2780ddb4a7890a8d8769ed0ff5e
|
||||
timeCreated: 1742313407
|
||||
324
Assets/Scripts/Fishing~/Player/Gear/FRod.cs
Normal file
324
Assets/Scripts/Fishing~/Player/Gear/FRod.cs
Normal file
@@ -0,0 +1,324 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using NBC;
|
||||
using NBF;
|
||||
using Obi;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
public class FRod : FPlayerGear
|
||||
{
|
||||
private CCDIK _ccdik;
|
||||
|
||||
[HideInInspector] public float throwPowerForSounds;
|
||||
|
||||
public bool isThrowing { get; set; }
|
||||
|
||||
public FWaterDisplacement LureHookWaterDisplacement;
|
||||
|
||||
[HideInInspector] public FFish currentFish;
|
||||
|
||||
[HideInInspector] public FFish takeFish;
|
||||
|
||||
|
||||
private float bendSmooth;
|
||||
|
||||
public FRodData RodData { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 鱼竿资产组件
|
||||
/// </summary>
|
||||
public RodAsset rodAsset;
|
||||
|
||||
// public RodRingAsset RodRingAsset { get; private set; }
|
||||
|
||||
public RodRingNode[] rings;
|
||||
|
||||
/// <summary>
|
||||
/// 鱼线处理器
|
||||
/// </summary>
|
||||
public FLineHandler lineHandler;
|
||||
|
||||
|
||||
public float currentLineTension;
|
||||
public float linelenghtDiferent;
|
||||
public float currentLineStrenght;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
rodAsset = GetComponent<RodAsset>();
|
||||
_ccdik = GetComponent<CCDIK>();
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
RodData = GearData as FRodData;
|
||||
IKSolverCCD solver = _ccdik.solver;
|
||||
solver.OnPostUpdate =
|
||||
(IKSolver.UpdateDelegate)Delegate.Combine(solver.OnPostUpdate, new IKSolver.UpdateDelegate(OnPostUpdate));
|
||||
// fishingLine = GetComponent<FFishingLine>();
|
||||
// fishingLine.Initialize(Owner);
|
||||
for (int i = 0; i < _ccdik.solver.bones.Length; i++)
|
||||
{
|
||||
_ccdik.solver.bones[i].weight = 0.06f;
|
||||
}
|
||||
|
||||
// CheckCreateFishingHandler();
|
||||
}
|
||||
|
||||
public void SetRing(RodRingAsset ringAsset)
|
||||
{
|
||||
if (rodAsset.rings == null || rodAsset.rings.Length < 1) return;
|
||||
|
||||
var trans = ringAsset.rings;
|
||||
RodRingNode lastRingNode = null;
|
||||
List<RodRingNode> list = new List<RodRingNode>();
|
||||
for (int i = 0; i < rodAsset.rings.Length; i++)
|
||||
{
|
||||
var ring = rodAsset.rings[i];
|
||||
if (ring == null)
|
||||
{
|
||||
Log.Error($"ring is null,index={i}");
|
||||
continue;
|
||||
}
|
||||
|
||||
var lastName = ring.name.GetLastString();
|
||||
foreach (var tran in trans)
|
||||
{
|
||||
var ringNode = tran.ring;
|
||||
var lastName2 = ringNode.name.GetLastString();
|
||||
if (lastName != lastName2) continue;
|
||||
list.Add(tran);
|
||||
ringNode.SetParent(ring);
|
||||
ringNode.localPosition = Vector3.zero;
|
||||
ringNode.localRotation = Quaternion.identity;
|
||||
lastRingNode = tran;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (lastRingNode != null)
|
||||
{
|
||||
rodAsset.lineConnector = lastRingNode.point;
|
||||
}
|
||||
|
||||
rings = list.ToArray();
|
||||
}
|
||||
|
||||
|
||||
private void OnPostUpdate()
|
||||
{
|
||||
BendControll();
|
||||
RenderLine();
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
linelenghtDiferent = getLineDiferent();
|
||||
|
||||
float num = RodData.Config.strength * 0.01f;
|
||||
currentLineStrenght = Mathf.Clamp01(linelenghtDiferent) * (Owner.Data.currentGear.line.Config.strength + num);
|
||||
|
||||
if ((bool)currentFish)
|
||||
{
|
||||
currentLineTension = linelenghtDiferent * (currentFish.fishWeight * currentFish.fishStamina);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentLineTension = Mathf.Clamp(linelenghtDiferent, 0f, 50f) * 0.3f;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void BendControll()
|
||||
{
|
||||
_ccdik.solver.SetIKPositionWeight(0f);
|
||||
return;
|
||||
|
||||
if (lineHandler == null)
|
||||
{
|
||||
_ccdik.solver.target = null;
|
||||
_ccdik.solver.SetIKPositionWeight(0f);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!_ccdik.solver.target)
|
||||
{
|
||||
_ccdik.solver.target = lineHandler.LineConnector_1.transform;
|
||||
return;
|
||||
}
|
||||
|
||||
float num = 0.15f;
|
||||
float max = 0.3f;
|
||||
if ((bool)takeFish)
|
||||
{
|
||||
num = 10f;
|
||||
max = 1f;
|
||||
}
|
||||
else if ((bool)currentFish)
|
||||
{
|
||||
num = 0.5f + currentLineTension * currentFish.fishWeight * 0.3f;
|
||||
max = 1f;
|
||||
}
|
||||
else if (Owner.Gears.Reel && Owner.Data.currentReelingSpeed > 0f)
|
||||
{
|
||||
num = Owner.Data.currentReelingSpeed * 0.3f;
|
||||
max = 0.3f;
|
||||
}
|
||||
|
||||
float num2 = Mathf.Clamp01(Mathf.Clamp01(getLineDiferent()) * num);
|
||||
if (num2 < 0.05f)
|
||||
{
|
||||
num2 = 0f;
|
||||
}
|
||||
|
||||
bendSmooth = Mathf.MoveTowards(bendSmooth, num2,
|
||||
Time.deltaTime * (1f - Mathf.Clamp01(getLineDiferent())));
|
||||
if ((bool)currentFish && currentFish.isGetFish)
|
||||
{
|
||||
bendSmooth = 0f;
|
||||
}
|
||||
|
||||
bendSmooth = Mathf.Clamp(bendSmooth, 0.001f, max);
|
||||
_ccdik.solver.SetIKPositionWeight(Mathf.MoveTowards(_ccdik.solver.IKPositionWeight, bendSmooth,
|
||||
Time.deltaTime * 0.5f));
|
||||
}
|
||||
|
||||
|
||||
public float getLineDiferent()
|
||||
{
|
||||
if (!lineHandler)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
return Vector3.Distance(lineHandler.LineConnector_1.transform.position,
|
||||
rodAsset.lineConnector.position) - Owner.Data.lineLength;
|
||||
}
|
||||
|
||||
public void DestroyCurrentFish()
|
||||
{
|
||||
Debug.Log("Destroy fish frod");
|
||||
// if ((bool)currentPlayer.currentChwytak)
|
||||
// {
|
||||
// Destroy(currentPlayer.currentChwytak.gameObject);
|
||||
// currentPlayer.currentChwytak = null;
|
||||
// Debug.Log("Destroy chwytak");
|
||||
// }
|
||||
|
||||
if ((bool)currentFish)
|
||||
{
|
||||
Destroy(currentFish.gameObject);
|
||||
currentFish = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// GameManager.Instance._playerData.PlayerSlotsEquip[indexOfslot].rod.status =
|
||||
// GameManager.PlayerData.CRods.Status.InEquip;
|
||||
|
||||
if ((bool)lineHandler)
|
||||
{
|
||||
ObiSolver component = lineHandler.GetComponent<ObiSolver>();
|
||||
SceneSettings.Instance.obiFixedUpdater.solvers.Remove(component);
|
||||
Destroy(lineHandler.gameObject);
|
||||
lineHandler = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void CreateFishingHandler()
|
||||
{
|
||||
if (lineHandler == null)
|
||||
{
|
||||
if (Owner.Data.currentGear != null && Owner.Data.currentGear.rod != null)
|
||||
{
|
||||
Debug.LogError("创建钓组=====");
|
||||
var rodType = Owner.Data.currentGear.Type;
|
||||
if (rodType == GearType.Pole || rodType == GearType.SpinningFloat)
|
||||
{
|
||||
CreateObiFishingLine(0);
|
||||
}
|
||||
else if (rodType == GearType.Spinning)
|
||||
{
|
||||
CreateObiFishingLine(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void CreateObiFishingLine(int currentLineTypeIndex)
|
||||
{
|
||||
// if ((bool)Owner.Gears.Reel && !currentLineHandler)
|
||||
if (!lineHandler)
|
||||
{
|
||||
var indexNames = new[] { "FFishingLine_0", "FFishingLine_1", "FFishingLine_3" };
|
||||
var path = $"GameItemsPrefabs/Lines/{indexNames[currentLineTypeIndex]}";
|
||||
var prefab = Resources.Load<GameObject>(path);
|
||||
|
||||
// var toRodConnector = rodAsset.lineConnector.GetComponent<Rigidbody>();
|
||||
GameObject obj = Instantiate(prefab, Owner.Gears.GearParent.position,
|
||||
Quaternion.identity, Owner.Gears.GearParent);
|
||||
|
||||
lineHandler = obj.GetComponent<FLineHandler>();
|
||||
// lineHandler.transform.SetParent(toRodConnector.transform);
|
||||
lineHandler.transform.position = rodAsset.lineConnector.position;
|
||||
lineHandler.LineConnector_0.target = rodAsset.lineConnector;//.GetComponent<Rigidbody>();
|
||||
// lineHandler.toRodConnector.target = rodAsset.lineConnector;
|
||||
lineHandler.Rod = this;
|
||||
var obiSolver = lineHandler.GetComponent<ObiSolver>();
|
||||
SceneSettings.Instance.obiFixedUpdater.solvers.Add(obiSolver);
|
||||
}
|
||||
}
|
||||
|
||||
public void RenderLine()
|
||||
{
|
||||
if (!lineHandler)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Owner.Gears.Reel) return;
|
||||
if (!rodAsset.lineRenderer) return;
|
||||
|
||||
var reel = Owner.Gears.Reel;
|
||||
int num = 0;
|
||||
bool isBlockLineByFinger = reel.isBlockLineByFinger;
|
||||
if (reel.AnimatorCtrl.Unlock && isBlockLineByFinger && reel.reelAsset.type == ReelAsset.Type.Normal)
|
||||
{
|
||||
rodAsset.lineRenderer.positionCount = rings.Length + 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
rodAsset.lineRenderer.positionCount = rings.Length + 2;
|
||||
}
|
||||
|
||||
rodAsset.lineRenderer.SetPosition(num, reel.reelAsset.lineIntersectHelper.position);
|
||||
num++;
|
||||
if (reel.AnimatorCtrl.Unlock && reel.reelAsset.type == ReelAsset.Type.Normal)
|
||||
{
|
||||
rodAsset.lineRenderer.SetPosition(num, reel.reelAsset.lineIntersect.position);
|
||||
num++;
|
||||
if (isBlockLineByFinger)
|
||||
{
|
||||
// rodAsset.lineRenderer.SetPosition(num, reel.reelAsset.lineFingerPoint.position);
|
||||
// num++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rodAsset.lineRenderer.SetPosition(num, reel.reelAsset.lineConnector.position);
|
||||
num++;
|
||||
}
|
||||
|
||||
for (int num2 = 0; num2 < rings.Length; num2++)
|
||||
{
|
||||
rodAsset.lineRenderer.SetPosition(num, rings[num2].point.position);
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FRod.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FRod.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 06ad550de17c4d38a067e55dab08ab76
|
||||
timeCreated: 1742313397
|
||||
18
Assets/Scripts/Fishing~/Player/Gear/FWeight.cs
Normal file
18
Assets/Scripts/Fishing~/Player/Gear/FWeight.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using NBF;
|
||||
using UnityEngine;
|
||||
|
||||
public class FWeight : FPlayerGear
|
||||
{
|
||||
public GameObject[] weightObjects;
|
||||
|
||||
[HideInInspector]
|
||||
public float weight;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/Gear/FWeight.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/Gear/FWeight.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fb488c96da0743448485e27c40bd889f
|
||||
timeCreated: 1742313433
|
||||
@@ -0,0 +1,81 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class JointPinchController : MonoBehaviour
|
||||
{
|
||||
// 配置参数
|
||||
[SerializeField] private float moveSpeed = 5f;
|
||||
[SerializeField] private float snapDistance = 0.1f;
|
||||
|
||||
// 组件引用
|
||||
private SpringJoint originalSpringJoint;
|
||||
private FixedJoint pinchJoint;
|
||||
private Rigidbody rb;
|
||||
|
||||
|
||||
private Transform targetTransform;
|
||||
private float originalSpring;
|
||||
|
||||
public bool isPinched { get; private set; }
|
||||
|
||||
|
||||
private bool moveToTargetDone;
|
||||
private float _speed;
|
||||
|
||||
void Start()
|
||||
{
|
||||
rb = GetComponent<Rigidbody>();
|
||||
originalSpringJoint = GetComponent<SpringJoint>();
|
||||
}
|
||||
|
||||
void FixedUpdate()
|
||||
{
|
||||
if (isPinched && targetTransform != null)
|
||||
{
|
||||
transform.position =
|
||||
Vector3.MoveTowards(transform.position, targetTransform.position, Time.deltaTime * _speed);
|
||||
if (!moveToTargetDone)
|
||||
{
|
||||
if (Vector3.Distance(transform.position, targetTransform.position) < 0.1f)
|
||||
{
|
||||
moveToTargetDone = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (moveToTargetDone)
|
||||
{
|
||||
transform.position = targetTransform.position;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 外部调用:开始捏住流程
|
||||
public void StartPinch(Transform fingerTransform, float speed = 3)
|
||||
{
|
||||
_speed = speed;
|
||||
Rigidbody fingerRb = fingerTransform.GetComponent<Rigidbody>();
|
||||
if (fingerRb == null)
|
||||
{
|
||||
Debug.LogError("目标必须带有Rigidbody");
|
||||
return;
|
||||
}
|
||||
|
||||
isPinched = true;
|
||||
rb.useGravity = false;
|
||||
rb.isKinematic = true;
|
||||
moveToTargetDone = false;
|
||||
targetTransform = fingerTransform;
|
||||
}
|
||||
|
||||
|
||||
// 外部调用:释放捏住
|
||||
public void ReleasePinch()
|
||||
{
|
||||
isPinched = false;
|
||||
rb.useGravity = true;
|
||||
rb.isKinematic = false;
|
||||
targetTransform = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: be4c06ad8ef348508e21a2b926e71823
|
||||
timeCreated: 1743941434
|
||||
103
Assets/Scripts/Fishing~/Player/HandsAnimEvents.cs
Normal file
103
Assets/Scripts/Fishing~/Player/HandsAnimEvents.cs
Normal file
@@ -0,0 +1,103 @@
|
||||
// using UnityEngine;
|
||||
//
|
||||
// public class HandsAnimEvents : MonoBehaviour
|
||||
// {
|
||||
// public FPlayer player;
|
||||
//
|
||||
// private void Start()
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// private void Update()
|
||||
// {
|
||||
// }
|
||||
//
|
||||
// public void UnlockReel()
|
||||
// {
|
||||
// if ((bool)player)
|
||||
// {
|
||||
// player.currentRod.currentReel.LockUnlock();
|
||||
// GetComponent<Animator>().SetBool("RHandReelUnlock", value: false);
|
||||
// GetComponent<Animator>().SetBool("RHandReelLock", value: false);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void UnlockReelWithHandAnimation()
|
||||
// {
|
||||
// if ((bool)player)
|
||||
// {
|
||||
// player.UnlockLockReel();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void ResetThrow()
|
||||
// {
|
||||
// GetComponent<Animator>().SetBool("RHandThrowFar", value: false);
|
||||
// GetComponent<Animator>().SetBool("RHandThrowNear", value: false);
|
||||
// }
|
||||
//
|
||||
// public void BlockLineByFinger()
|
||||
// {
|
||||
// if ((bool)player && (bool)player.currentRod && player.fishingMode != 0)
|
||||
// {
|
||||
// player.currentRod.currentReel.isBlockLineByFinger = true;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void UnBlockLineByFinger()
|
||||
// {
|
||||
// if ((bool)player && player.fishingMode != 0 && (bool)player.currentRod)
|
||||
// {
|
||||
// if (player.currentRod.throwForcePower > 0f)
|
||||
// {
|
||||
// player.currentRod.ForceThrow();
|
||||
// }
|
||||
// player.currentRod.currentReel.isBlockLineByFinger = false;
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void UnBlockLineByFingerNear()
|
||||
// {
|
||||
// if ((bool)player && player.fishingMode != 0 && (bool)player.currentRod)
|
||||
// {
|
||||
// if (player.currentRod.throwForcePower > 0f)
|
||||
// {
|
||||
// player.currentRod.ForceThrow(isNear: true);
|
||||
// }
|
||||
// player.currentRod.currentReel.isBlockLineByFinger = false;
|
||||
// player.OutLineFromLeftHandHelper(player.currentRod.fishingLine.currentLineHandler.LineConnector_1.transform);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void PutHandOnReel()
|
||||
// {
|
||||
// if ((bool)player && player.currentRod.fishingLine.currentLineHandler.PhisicsLineOut > 0f && !player.currentRod.currentReel.isHandOnHandle)
|
||||
// {
|
||||
// player.InteractiveLeftHand(player.currentRod.currentReel.handle);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// public void CatchFish()
|
||||
// {
|
||||
// player.currentRod.CastFish();
|
||||
// }
|
||||
//
|
||||
// public void DestroyCurrentFish()
|
||||
// {
|
||||
// player.currentRod.DestroyCurrentFish();
|
||||
// }
|
||||
//
|
||||
// public void ShowFishPanel()
|
||||
// {
|
||||
// // FScriptsHandler.Instance.m_HudManager.ShowHideFishCatchPanel();
|
||||
// }
|
||||
//
|
||||
// public void DestroyRod()
|
||||
// {
|
||||
// if ((bool)player && (bool)player.currentRod)
|
||||
// {
|
||||
// Destroy(player.currentRod.gameObject);
|
||||
// player.currentRod = null;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
3
Assets/Scripts/Fishing~/Player/HandsAnimEvents.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/HandsAnimEvents.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3bc384105af54121bff47a2effca1cf2
|
||||
timeCreated: 1742477883
|
||||
3
Assets/Scripts/Fishing~/Player/PlayerCharacter.meta
Normal file
3
Assets/Scripts/Fishing~/Player/PlayerCharacter.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 26646598ef364c52809720f314858335
|
||||
timeCreated: 1747495726
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94625758064a489da77a94a8a9f4b8ad
|
||||
timeCreated: 1748789414
|
||||
@@ -0,0 +1,50 @@
|
||||
namespace NBF
|
||||
{
|
||||
public abstract class PlayerDriveBase
|
||||
{
|
||||
protected PlayerCharacter Character;
|
||||
protected FPlayer Player;
|
||||
|
||||
public void Start(PlayerCharacter character)
|
||||
{
|
||||
Player = character.gameObject.GetComponent<FPlayer>();
|
||||
Character = character;
|
||||
OnStart();
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
OnUpdate();
|
||||
}
|
||||
|
||||
public void LateUpdate()
|
||||
{
|
||||
OnLateUpdate();
|
||||
}
|
||||
|
||||
public void FixedUpdate()
|
||||
{
|
||||
OnFixedUpdate();
|
||||
}
|
||||
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnStart()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnLateUpdate()
|
||||
{
|
||||
}
|
||||
|
||||
protected virtual void OnFixedUpdate()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 34da0e66b0594f83aa4c431917aa7944
|
||||
timeCreated: 1748789429
|
||||
@@ -0,0 +1,303 @@
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public class PlayerLocalMover : PlayerDriveBase
|
||||
{
|
||||
public LayerMask interactableLayer;
|
||||
|
||||
public LookAtIK lookAtIK; // 挂在背部上的 LookAtIK 脚本
|
||||
public float aimDistance = 1.5f; // 目标点离相机多远
|
||||
|
||||
private Transform lookTarget; // 实际目标点
|
||||
[Header("限制角度(单位:度)")] public float maxUpAngle = 20f; // 相机抬头最多20°
|
||||
public float maxDownAngle = 40f; // 相机低头最多40°
|
||||
|
||||
/// <summary>
|
||||
/// 基础移动速度
|
||||
/// </summary>
|
||||
private const float MoveSpeed = 3f;
|
||||
|
||||
/// <summary>
|
||||
/// 冲刺速度
|
||||
/// </summary>
|
||||
private const float SprintSpeed = 5f;
|
||||
|
||||
private float acceleration = 10f; // 加速度
|
||||
|
||||
/// <summary>
|
||||
/// 重力加速度
|
||||
/// </summary>
|
||||
private float gravity = 9.81f;
|
||||
|
||||
private float groundedGravity = -0.5f; // 小的向下力确保角色保持在地面
|
||||
private float airControl = 0.5f; // 空中控制系数
|
||||
|
||||
|
||||
private float verticalVelocity = 0f;
|
||||
private Vector3 currentVelocity = Vector3.zero;
|
||||
private float currentSpeed = 0f;
|
||||
|
||||
[Tooltip("视角旋转敏感度")] public Vector2 sensitivity = new Vector2(0.015f, 0.015f);
|
||||
public float minPitch = -40.0f;
|
||||
public float maxPitch = 75.0f;
|
||||
public float boatMaxPitch = 60;
|
||||
private float _cameraPitch;
|
||||
private Vector3 _rotationInput = Vector3.zero;
|
||||
private bool _isRun;
|
||||
|
||||
[HideInInspector] public int nextShowSlotIndex = -1;
|
||||
|
||||
protected override void OnStart()
|
||||
{
|
||||
lookAtIK = Character.gameObject.GetComponent<LookAtIK>();
|
||||
lookTarget = new GameObject("SpineLookTarget").transform;
|
||||
lookTarget.SetParent(Character.transform);
|
||||
interactableLayer = LayerMask.GetMask("Interactive");
|
||||
|
||||
InputManager.OnPlayerCanceled += OnPlayerCanceled;
|
||||
InputManager.OnPlayerPerformed += OnPlayerPerformed;
|
||||
}
|
||||
|
||||
protected override void OnUpdate()
|
||||
{
|
||||
UpdateGear();
|
||||
InteractiveCheck();
|
||||
}
|
||||
|
||||
protected override void OnLateUpdate()
|
||||
{
|
||||
UpdatePlayerHandView();
|
||||
}
|
||||
|
||||
protected override void OnFixedUpdate()
|
||||
{
|
||||
UpdatePlayerPosition();
|
||||
UpdatePlayerRotation();
|
||||
}
|
||||
|
||||
public override void OnDestroy()
|
||||
{
|
||||
InputManager.OnPlayerCanceled -= OnPlayerCanceled;
|
||||
InputManager.OnPlayerPerformed -= OnPlayerPerformed;
|
||||
}
|
||||
|
||||
#region 钓组控制
|
||||
|
||||
private void UpdateGear()
|
||||
{
|
||||
if (Player.CanChangeGear())
|
||||
{
|
||||
if (nextShowSlotIndex > 0)
|
||||
{
|
||||
var data = Fishing.Inst.Datasource;
|
||||
data.SetSelfTestGear(nextShowSlotIndex);
|
||||
nextShowSlotIndex = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 事件输入
|
||||
|
||||
private void OnPlayerPerformed(string action)
|
||||
{
|
||||
if (action == "Run")
|
||||
{
|
||||
_isRun = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerCanceled(string action)
|
||||
{
|
||||
if (action == "Run")
|
||||
{
|
||||
_isRun = false;
|
||||
}
|
||||
else if (action.StartsWith("Quick"))
|
||||
{
|
||||
nextShowSlotIndex = int.Parse(action.Substring("Quick".Length));
|
||||
}
|
||||
else if (action == "UseTorch")
|
||||
{
|
||||
Player.Data.openLight = !Player.Data.openLight;
|
||||
}
|
||||
else if (action == "UseTelescope")
|
||||
{
|
||||
Player.Data.openTelescope = !Player.Data.openTelescope;
|
||||
Player.ToggleTelescope();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 交互检测
|
||||
|
||||
private RaycastHit hitInfo;
|
||||
private bool isHit;
|
||||
private readonly float _interactionDistance = 8f;
|
||||
private InteractiveObject _lastInteractiveObject;
|
||||
|
||||
private void InteractiveCheck()
|
||||
{
|
||||
if (Player.NowBoat)
|
||||
{
|
||||
SetInteractiveObject(null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (Player && Player.Fsm.CurrentStateId == States.Player.Idle)
|
||||
{
|
||||
// 从屏幕中心发射射线
|
||||
Ray ray = BaseCamera.Main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0));
|
||||
isHit = Physics.Raycast(ray, out hitInfo, _interactionDistance, interactableLayer);
|
||||
|
||||
// 检测到可交互物体时
|
||||
if (isHit)
|
||||
{
|
||||
var interactiveObject = hitInfo.transform.gameObject.GetComponent<InteractiveObject>();
|
||||
if (interactiveObject != null)
|
||||
{
|
||||
SetInteractiveObject(interactiveObject);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
SetInteractiveObject(null);
|
||||
}
|
||||
|
||||
private void SetInteractiveObject(InteractiveObject interactiveObject)
|
||||
{
|
||||
if (_lastInteractiveObject != interactiveObject)
|
||||
{
|
||||
_lastInteractiveObject = interactiveObject;
|
||||
InputManager.Instance.OnInteractiveObject(_lastInteractiveObject);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 肩膀控制
|
||||
|
||||
private void UpdatePlayerHandView()
|
||||
{
|
||||
var cameraTransform = BaseCamera.Main.transform;
|
||||
Vector3 cameraForward = cameraTransform.forward;
|
||||
Vector3 flatForward = Vector3.ProjectOnPlane(cameraForward, Vector3.up).normalized;
|
||||
|
||||
// 获取相机 pitch 角度(负值是上看,正值是下看)
|
||||
float pitchAngle = Vector3.SignedAngle(flatForward, cameraForward, cameraTransform.right);
|
||||
|
||||
// 限制 pitch 角度
|
||||
pitchAngle = Mathf.Clamp(pitchAngle, -maxUpAngle, maxDownAngle);
|
||||
|
||||
// 重新构造限制后的目标方向
|
||||
Quaternion limitedPitch = Quaternion.AngleAxis(pitchAngle, cameraTransform.right);
|
||||
Vector3 limitedDirection = limitedPitch * flatForward;
|
||||
|
||||
// 设置目标点
|
||||
lookTarget.position = cameraTransform.position + limitedDirection * aimDistance;
|
||||
lookAtIK.solver.target = lookTarget;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 位移和旋转控制
|
||||
|
||||
private void UpdatePlayerPosition()
|
||||
{
|
||||
Vector2 movementInput = InputManager.GetMovementInput();
|
||||
if (Player.NowBoat)
|
||||
{
|
||||
Player.NowBoat.BoatInput(movementInput);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector3 movementDirection = Vector3.zero;
|
||||
|
||||
movementDirection += Vector3.forward * movementInput.y;
|
||||
movementDirection += Vector3.right * movementInput.x;
|
||||
|
||||
movementDirection = movementDirection.relativeTo(BaseCamera.Main.transform, Character.transform.up);
|
||||
|
||||
// 计算目标速度
|
||||
float targetSpeed = _isRun ? SprintSpeed : MoveSpeed;
|
||||
|
||||
// 平滑加速
|
||||
if (movementDirection.magnitude > 0.1f)
|
||||
{
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, targetSpeed, acceleration * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
currentSpeed = Mathf.Lerp(currentSpeed, 0f, acceleration * 2f * Time.deltaTime);
|
||||
}
|
||||
|
||||
// 处理重力
|
||||
if (Character.CharacterController.isGrounded)
|
||||
{
|
||||
verticalVelocity = groundedGravity;
|
||||
|
||||
// 地面移动 - 完全控制
|
||||
currentVelocity = Vector3.Lerp(currentVelocity, movementDirection.normalized * currentSpeed,
|
||||
acceleration * Time.deltaTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
verticalVelocity -= gravity * Time.deltaTime;
|
||||
|
||||
// 空中移动 - 有限控制
|
||||
Vector3 targetAirVelocity = movementDirection.normalized * currentSpeed * airControl;
|
||||
currentVelocity = Vector3.Lerp(currentVelocity,
|
||||
new Vector3(targetAirVelocity.x, currentVelocity.y, targetAirVelocity.z),
|
||||
acceleration * Time.deltaTime);
|
||||
}
|
||||
|
||||
// 组合移动
|
||||
Vector3 totalMovement = currentVelocity * Time.deltaTime;
|
||||
totalMovement.y = verticalVelocity * Time.deltaTime;
|
||||
|
||||
Character.CollisionFlags = Character.CharacterController.Move(totalMovement);
|
||||
}
|
||||
|
||||
private void UpdatePlayerRotation()
|
||||
{
|
||||
// Look
|
||||
Vector2 lookInput = InputManager.GetLookInput() * sensitivity;
|
||||
|
||||
if (lookInput.x != 0.0f)
|
||||
{
|
||||
_rotationInput.y += lookInput.x;
|
||||
}
|
||||
|
||||
AddControlPitchInput(-lookInput.y, minPitch, Player.NowBoat ? boatMaxPitch : maxPitch);
|
||||
|
||||
Player.CameraRoot.transform.localRotation = Quaternion.Euler(_cameraPitch, 0.0f, 0.0f);
|
||||
if (_rotationInput != Vector3.zero)
|
||||
{
|
||||
Character.CharacterController.transform.rotation *= Quaternion.Euler(_rotationInput);
|
||||
_rotationInput = Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 添加输入(影响俯仰)。
|
||||
/// 此操作应用于相机父级的本地旋转。
|
||||
/// </summary>
|
||||
private void AddControlPitchInput(float value, float minPitch = -40.0f, float maxPitch = 70.0f)
|
||||
{
|
||||
if (value != 0.0f)
|
||||
_cameraPitch = VectorUtil.ClampAngle(_cameraPitch + value, minPitch, maxPitch);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 61e2cfa0aab6449293763de9e9a60261
|
||||
timeCreated: 1748789613
|
||||
@@ -0,0 +1,49 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerCharacter : MonoBehaviour
|
||||
{
|
||||
public CharacterController CharacterController;
|
||||
public CollisionFlags CollisionFlags;
|
||||
|
||||
private FPlayer _player;
|
||||
|
||||
public bool IsSelf;
|
||||
|
||||
private PlayerDriveBase _moverDrive;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
CharacterController = GetComponent<CharacterController>();
|
||||
_player = GetComponent<FPlayer>();
|
||||
|
||||
IsSelf = _player.Data.PlayerID == GameModel.RoleID;
|
||||
|
||||
CharacterController.enabled = false;
|
||||
transform.position = _player.Data.position;
|
||||
transform.rotation = _player.Data.rotation;
|
||||
CharacterController.enabled = true;
|
||||
|
||||
_moverDrive = new PlayerLocalMover();
|
||||
_moverDrive.Start(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
_moverDrive?.Update();
|
||||
}
|
||||
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
_moverDrive?.LateUpdate();
|
||||
}
|
||||
|
||||
private void FixedUpdate()
|
||||
{
|
||||
_moverDrive?.FixedUpdate();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5cf18b87277f477ab6a9b59759ee17cb
|
||||
timeCreated: 1748446764
|
||||
3
Assets/Scripts/Fishing~/Player/States.meta
Normal file
3
Assets/Scripts/Fishing~/Player/States.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 27fb01f0606f4fe1b2f76bcfc60546b1
|
||||
timeCreated: 1743521858
|
||||
7
Assets/Scripts/Fishing~/Player/States/PlayerFight.cs
Normal file
7
Assets/Scripts/Fishing~/Player/States/PlayerFight.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerFight : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => States.Player.Fight;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 270296b331144c239f35a1c94c1d158c
|
||||
timeCreated: 1733200075
|
||||
135
Assets/Scripts/Fishing~/Player/States/PlayerFishing.cs
Normal file
135
Assets/Scripts/Fishing~/Player/States/PlayerFishing.cs
Normal file
@@ -0,0 +1,135 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerFishing : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => States.Player.Fishing;
|
||||
|
||||
|
||||
protected override void onExit()
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.PodsakAction = false;
|
||||
}
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
Debug.Log("进入钓鱼中");
|
||||
|
||||
if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Spin)
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.PodsakAction = true;
|
||||
_owner.PlayerAnimatorCtrl.Telestick = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.PodsakAction = false;
|
||||
_owner.PlayerAnimatorCtrl.Telestick = true;
|
||||
}
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
var ret = States.None;
|
||||
var isUpRod = false;
|
||||
var isSubLine = false;
|
||||
|
||||
if (Input.GetKeyDown(KeyCode.P))
|
||||
{
|
||||
return States.Player.Idle;
|
||||
}
|
||||
|
||||
if (InputManager.IsOp1)
|
||||
{
|
||||
if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Float)
|
||||
{
|
||||
//抬杆
|
||||
isUpRod = true;
|
||||
}
|
||||
else if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Spin)
|
||||
{
|
||||
//收线
|
||||
isSubLine = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (InputManager.IsOp2)
|
||||
{
|
||||
if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Spin)
|
||||
{
|
||||
//抬杆
|
||||
isUpRod = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isUpRod || _owner.PlayerAnimatorCtrl.FishingFinal > 0)
|
||||
{
|
||||
var upForce = 1;
|
||||
var addNum = upForce * Time.deltaTime;
|
||||
if (!isUpRod)
|
||||
{
|
||||
addNum *= -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
addNum *= 0.5f;
|
||||
}
|
||||
|
||||
// Debug.Log($"addNum={addNum}");
|
||||
_owner.PlayerAnimatorCtrl.FishingFinal += addNum;
|
||||
Debug.LogError($"ishingFinal={_owner.PlayerAnimatorCtrl.FishingFinal}");
|
||||
if (_owner.PlayerAnimatorCtrl.FishingFinal >= 1)
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.FishingFinal = 1;
|
||||
}
|
||||
else if (_owner.PlayerAnimatorCtrl.FishingFinal < 0)
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.FishingFinal = 0;
|
||||
}
|
||||
|
||||
if (_owner.PlayerAnimatorCtrl.FishingFinal >= 0.8f)
|
||||
{
|
||||
ret = CheckTackFish();
|
||||
}
|
||||
|
||||
_owner.PlayerAnimatorCtrl.PullUpRod = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.PullUpRod = false;
|
||||
}
|
||||
|
||||
if (isSubLine)
|
||||
{
|
||||
var subLineSpeed = 2;
|
||||
var addNum = subLineSpeed * Time.deltaTime;
|
||||
if (_owner.Data.lineLength > 0.4f)
|
||||
{
|
||||
_owner.Data.lineLength -= addNum;
|
||||
}
|
||||
|
||||
_owner.Data.reelSpeed = 1;
|
||||
if (_owner.Data.lineLength <= 0.4f)
|
||||
{
|
||||
_owner.Data.lineLength = 0.4f;
|
||||
ret = CheckTackFish();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_owner.Data.reelSpeed = 0;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
#region 检查上鱼或者返回待机
|
||||
|
||||
private uint CheckTackFish()
|
||||
{
|
||||
return States.Player.Idle;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a7b4c15a41e54f1fa6241d0ed1841154
|
||||
timeCreated: 1733200048
|
||||
117
Assets/Scripts/Fishing~/Player/States/PlayerIdle.cs
Normal file
117
Assets/Scripts/Fishing~/Player/States/PlayerIdle.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 闲置状态
|
||||
/// </summary>
|
||||
public class PlayerIdle : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => States.Player.Idle;
|
||||
|
||||
public enum Phase
|
||||
{
|
||||
/// <summary>
|
||||
/// 完全闲置的
|
||||
/// </summary>
|
||||
Idle,
|
||||
|
||||
/// <summary>
|
||||
/// 准备拿东西
|
||||
/// </summary>
|
||||
PrepareTake,
|
||||
|
||||
/// <summary>
|
||||
/// 拿着东西
|
||||
/// </summary>
|
||||
TakeItem,
|
||||
}
|
||||
|
||||
public Phase Stage = Phase.Idle;
|
||||
|
||||
private bool _nextState = false;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
_nextState = false;
|
||||
_owner.Data.reelSpeed = 0;
|
||||
_owner.PlayerAnimatorCtrl.LureThrown = false;
|
||||
_owner.MinorArm.IK.enabled = false;
|
||||
if (_owner.Gears.Rod && _owner.Gears.Reel)
|
||||
{
|
||||
_owner.Gears.Reel.Unlock(false);
|
||||
}
|
||||
|
||||
|
||||
Stage = Phase.Idle;
|
||||
|
||||
InputManager.OnOp1Action += OnOp1Action;
|
||||
}
|
||||
|
||||
protected override void onExit()
|
||||
{
|
||||
base.onExit();
|
||||
InputManager.OnOp1Action -= OnOp1Action;
|
||||
}
|
||||
|
||||
private void OnOp1Action(bool performed)
|
||||
{
|
||||
if (Stage == Phase.TakeItem)
|
||||
{
|
||||
if (_owner.Gears.Rod)
|
||||
{
|
||||
//如果准备好了杆子,则可进入抛竿
|
||||
if (performed)
|
||||
{
|
||||
_nextState = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
if (Stage == Phase.Idle)
|
||||
{
|
||||
if (_owner && _owner.Gears.Rod)
|
||||
{
|
||||
Stage = Phase.PrepareTake;
|
||||
}
|
||||
}
|
||||
else if (Stage == Phase.PrepareTake)
|
||||
{
|
||||
if (_owner.Data.currentGear.Type == GearType.Pole)
|
||||
{
|
||||
var handPoint = _owner.MinorArm.LeftRigMagnet;
|
||||
var ret = _owner.PutLineToLeftHandHelper(handPoint, 3f);
|
||||
|
||||
if (ret)
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.RodReady = true;
|
||||
Stage = Phase.TakeItem;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.RodReady = true;
|
||||
Stage = Phase.TakeItem;
|
||||
}
|
||||
}
|
||||
else if (Stage == Phase.TakeItem)
|
||||
{
|
||||
if (_owner.Gears.Rod)
|
||||
{
|
||||
//如果准备好了杆子,则可进入抛竿
|
||||
// if (_nextState)
|
||||
// {
|
||||
// return States.Player.WaitThrow;
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return States.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Fishing~/Player/States/PlayerIdle.cs.meta
Normal file
3
Assets/Scripts/Fishing~/Player/States/PlayerIdle.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 894c08d7fbf442adae3342038110aa6a
|
||||
timeCreated: 1733198057
|
||||
7
Assets/Scripts/Fishing~/Player/States/PlayerShowFish.cs
Normal file
7
Assets/Scripts/Fishing~/Player/States/PlayerShowFish.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace NBF
|
||||
{
|
||||
public class PlayerShowFish : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => States.Player.ShowFish;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 043b3856636e4706a2382a544bec14c8
|
||||
timeCreated: 1733199961
|
||||
57
Assets/Scripts/Fishing~/Player/States/PlayerStateBase.cs
Normal file
57
Assets/Scripts/Fishing~/Player/States/PlayerStateBase.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
public abstract class PlayerStateBase : FsmBaseState<FPlayer>
|
||||
{
|
||||
protected FPlayer Fish => _owner;
|
||||
|
||||
|
||||
protected void SetArm()
|
||||
{
|
||||
if (_owner.Gears.Reel)
|
||||
{
|
||||
_owner.MinorArm.SetReelHandle(_owner.Gears.Reel.reelAsset);
|
||||
// _owner.MinorArm.IK.solver.target = _owner.Gears.Reel.reelAsset.handle;
|
||||
// _owner.MinorArm.IK.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查状态超时
|
||||
/// </summary>
|
||||
public void CheckStateTimeout(float time)
|
||||
{
|
||||
if (Time.time - EnterTime >= time)
|
||||
{
|
||||
Root.Start<PlayerIdle>();
|
||||
}
|
||||
}
|
||||
|
||||
protected void TakeLineToHand()
|
||||
{
|
||||
// GameInput.isPullUpRod = true;
|
||||
// // if(_owner.HandsAnimator.GetCurrentAnimatorClipInfo().)
|
||||
// _owner.HandsAnimator.SetBool(Anim.RightFingersOnRodPowered, true);
|
||||
// _owner.HandsAnimator.SetBool(Anim.LHandPreCast, true);
|
||||
|
||||
|
||||
// if (_owner.handPullUp >= 1)
|
||||
// {
|
||||
// // var connector = _owner.currentRod.currentLine.currentLineHandler.LineConnector_1.transform;
|
||||
// // var handPoint = _owner.lHandPlayerHelperLinePoint;
|
||||
//
|
||||
// // _owner.PutLineToLeftHandHelper(connector, handPoint, 3f);
|
||||
// }
|
||||
}
|
||||
|
||||
// protected void OutLineToHand()
|
||||
// {
|
||||
// // GameInput.isPullUpRod = false;
|
||||
//
|
||||
// var connector = _owner.currentRod.currentLine.currentLineHandler.LineConnector_1.transform;
|
||||
// _owner.OutLineFromLeftHandHelper(connector);
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e5ecd3ff4134eec876e22cd708a9615
|
||||
timeCreated: 1732849520
|
||||
154
Assets/Scripts/Fishing~/Player/States/PlayerThrow.cs
Normal file
154
Assets/Scripts/Fishing~/Player/States/PlayerThrow.cs
Normal file
@@ -0,0 +1,154 @@
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 抛竿中
|
||||
/// </summary>
|
||||
public class PlayerThrow : PlayerStateBase
|
||||
{
|
||||
public override uint StateId => States.Player.Throw;
|
||||
|
||||
public enum Phase
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待动画事件回调
|
||||
/// </summary>
|
||||
Waiting,
|
||||
|
||||
/// <summary>
|
||||
/// 前摇动画
|
||||
/// </summary>
|
||||
AnimBegin,
|
||||
|
||||
/// <summary>
|
||||
/// 抛线动画
|
||||
/// </summary>
|
||||
ThrowAnim,
|
||||
|
||||
/// <summary>
|
||||
/// 结束
|
||||
/// </summary>
|
||||
Done,
|
||||
ErrorDone
|
||||
}
|
||||
|
||||
public Phase Stage = Phase.Waiting;
|
||||
|
||||
public float ChargedProgress;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.StartThrow = true;
|
||||
|
||||
ChargedProgress = (float)Params.Get(0);
|
||||
Debug.Log($"PlayerThrow ChargedProgress={ChargedProgress}");
|
||||
Stage = Phase.Waiting;
|
||||
|
||||
_owner.Gears.Reel?.Unlock();
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
CheckStateTimeout(10);
|
||||
if (Stage == Phase.AnimBegin)
|
||||
{
|
||||
AnimBegin();
|
||||
ThrowPosition();
|
||||
}
|
||||
else if (Stage == Phase.ThrowAnim)
|
||||
{
|
||||
ThrowAnim();
|
||||
}
|
||||
else if (Stage == Phase.Done)
|
||||
{
|
||||
return States.Player.Fishing;
|
||||
}
|
||||
else if (Stage == Phase.ErrorDone)
|
||||
{
|
||||
return States.Player.Idle;
|
||||
}
|
||||
|
||||
return base.onUpdate();
|
||||
}
|
||||
|
||||
#region 动画回调
|
||||
|
||||
/// <summary>
|
||||
/// 抛竿动画事件
|
||||
/// </summary>
|
||||
public void RodForceThrowStart()
|
||||
{
|
||||
// Debug.LogError($"RodForceThrowStart==");
|
||||
_owner.PlayerAnimatorCtrl.PrepareThrow = false;
|
||||
_owner.PlayerAnimatorCtrl.StartThrow = false;
|
||||
Stage = Phase.AnimBegin;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 抛线前摇动画
|
||||
|
||||
private void AnimBegin()
|
||||
{
|
||||
_owner.PlayerAnimatorCtrl.PrepareThrow = false;
|
||||
_owner.PlayerAnimatorCtrl.StartThrow = false;
|
||||
_owner.PlayerAnimatorCtrl.LureThrown = true;
|
||||
Stage = Phase.ThrowAnim;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 抛竿线飞出相关动画
|
||||
|
||||
private NTask _throwAnim;
|
||||
|
||||
private void ThrowPosition()
|
||||
{
|
||||
if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Float)
|
||||
{
|
||||
_owner.Gears.Rod.lineHandler.pinchController?.ReleasePinch();
|
||||
_throwAnim = new BobThrowAnim(_owner);
|
||||
_throwAnim.Run(DefRunner.Scheduler);
|
||||
// var lureHookWaterDisplacement = _owner.Gears.Rod.LureHookWaterDisplacement;
|
||||
// var angle = 25;
|
||||
// Vector3 forward = _owner.transform.forward; // 角色的前方向
|
||||
// Vector3 up = _owner.transform.up; // 角色的上方向
|
||||
// Vector3 forwardUpDirection =
|
||||
// (forward * Mathf.Cos(angle * Mathf.Deg2Rad) + up * Mathf.Sin(angle * Mathf.Deg2Rad)).normalized;
|
||||
//
|
||||
// // 施加力
|
||||
// lureHookWaterDisplacement.rigidbody.AddForce(forwardUpDirection * 320, ForceMode.Impulse);
|
||||
}
|
||||
else
|
||||
{
|
||||
_throwAnim = new LureThrowAnim(_owner);
|
||||
_throwAnim.Run(DefRunner.Scheduler);
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowAnim()
|
||||
{
|
||||
if (_throwAnim.IsDone)
|
||||
{
|
||||
if (_throwAnim.Status == NTaskStatus.Success)
|
||||
{
|
||||
if (_owner.PlayerAnimatorCtrl.ThrowMode == ThrowModeEnum.Spin)
|
||||
{
|
||||
SetArm();
|
||||
}
|
||||
|
||||
Stage = Phase.Done;
|
||||
Debug.LogError($"抛线后,线长度={_owner.Data.lineLength}");
|
||||
}
|
||||
else
|
||||
{
|
||||
Stage = Phase.ErrorDone;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ace9df53d3743589fe68b456596eda9
|
||||
timeCreated: 1733199798
|
||||
76
Assets/Scripts/Fishing~/Player/States/PlayerWaitThrow.cs
Normal file
76
Assets/Scripts/Fishing~/Player/States/PlayerWaitThrow.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF
|
||||
{
|
||||
/// <summary>
|
||||
/// 等待抛竿,蓄力中
|
||||
/// </summary>
|
||||
public class PlayerWaitThrow : PlayerStateBase
|
||||
{
|
||||
public enum Phase
|
||||
{
|
||||
/// <summary>
|
||||
/// 蓄力
|
||||
/// </summary>
|
||||
Charged,
|
||||
|
||||
/// <summary>
|
||||
/// 确认蓄力结果
|
||||
/// </summary>
|
||||
Confirm,
|
||||
}
|
||||
|
||||
public Phase Stage = Phase.Charged;
|
||||
|
||||
public override uint StateId => States.Player.WaitThrow;
|
||||
|
||||
|
||||
public float ChargedProgress;
|
||||
|
||||
protected override void onEnter()
|
||||
{
|
||||
Stage = Phase.Charged;
|
||||
_owner.PlayerAnimatorCtrl.PrepareThrow = true;
|
||||
_owner.PlayerAnimatorCtrl.FishingFinal = 0;
|
||||
}
|
||||
|
||||
protected override uint onUpdate()
|
||||
{
|
||||
if (Stage == Phase.Charged)
|
||||
{
|
||||
ThrowPowerCharged();
|
||||
}
|
||||
else if (Stage == Phase.Confirm)
|
||||
{
|
||||
//确认蓄力结果,
|
||||
Debug.Log($"确认蓄力结果,ChargedProgress={ChargedProgress}");
|
||||
Params.Add(ChargedProgress);
|
||||
return States.Player.Throw;
|
||||
}
|
||||
|
||||
return base.onUpdate();
|
||||
}
|
||||
|
||||
|
||||
#region 蓄力中
|
||||
|
||||
private void ThrowPowerCharged()
|
||||
{
|
||||
if (ChargedProgress < 1)
|
||||
{
|
||||
ChargedProgress += Time.deltaTime;
|
||||
}
|
||||
else if (ChargedProgress > 1)
|
||||
{
|
||||
ChargedProgress = 1;
|
||||
}
|
||||
|
||||
if (!InputManager.IsOp1)
|
||||
{
|
||||
Stage = Phase.Confirm;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8fad82651b44492eaad947108a421c36
|
||||
timeCreated: 1743687572
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user