备份CatanBuilding瘦身独立工程
This commit is contained in:
306
Assets/Scripts/GampPlay/Fishing/CollectingData.cs
Normal file
306
Assets/Scripts/GampPlay/Fishing/CollectingData.cs
Normal file
@@ -0,0 +1,306 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
public class DropAfterDrop
|
||||
{
|
||||
public string Mode;
|
||||
public string Bone;
|
||||
public string Fx;
|
||||
public DropAfterDrop(string mode, string bone, string fx)
|
||||
{
|
||||
Mode = mode;
|
||||
Bone = bone;
|
||||
Fx = fx;
|
||||
}
|
||||
}
|
||||
public class PlayNewItemFxEvent
|
||||
{
|
||||
public string fxName;
|
||||
public string audioName;
|
||||
public bool IsDarkness;
|
||||
public float PerformanceDelay;
|
||||
//==0=>start ==1=>stopFX ==2=>stopAudio or all
|
||||
public int type;
|
||||
}
|
||||
public class CollectingData
|
||||
{
|
||||
ETDropAfterDrop etDropAfterDrop;
|
||||
ETChangeMaterial eTChangeMaterial;
|
||||
ETNewItem etNewItem;
|
||||
ETKeepsake eTKeepsake;
|
||||
ETDropByFish eTDropByFish;
|
||||
|
||||
private MapFishList mapFishList = null;
|
||||
int addCollecting = 0;
|
||||
int extraCashDrop = 0;
|
||||
public FishingData fishingData;
|
||||
//获取额外掉落id
|
||||
int GetExtraDropID()
|
||||
{
|
||||
if (!fishingData.IsEventGameFish())
|
||||
{
|
||||
if (etDropAfterDrop != null)
|
||||
{
|
||||
//根据鱼的品质获取掉落id
|
||||
int Quality = fishingData.fishItem.Quality - 1;
|
||||
if (Quality >= etDropAfterDrop.ExtraDropList.Count)
|
||||
{
|
||||
Quality = etDropAfterDrop.ExtraDropList.Count - 1;
|
||||
}
|
||||
extraCashDrop = etDropAfterDrop.ExtraCashDropList[Quality];
|
||||
return etDropAfterDrop.ExtraDropList[Quality];
|
||||
}
|
||||
else if (eTChangeMaterial != null)
|
||||
{
|
||||
extraCashDrop = eTChangeMaterial.ExtraCashDropList;
|
||||
return eTChangeMaterial.ExtraDropList;
|
||||
}
|
||||
else if (mapFishList != null)
|
||||
{
|
||||
//根据鱼的编号获取掉落id
|
||||
int index = mapFishList.FishIDList.IndexOf(fishingData.fishItem.RedirectID);
|
||||
if (index != -1)
|
||||
{
|
||||
return mapFishList.DropIDList[index];
|
||||
}
|
||||
}
|
||||
else if (eTKeepsake != null)
|
||||
{
|
||||
if (fishingData.NewIndex >= eTKeepsake.FishExtraDropList.Count)
|
||||
{
|
||||
Debug.LogError($"Keepsake FishExtraDropList == {eTKeepsake.FishExtraDropList.Count} Not Index {fishingData.NewIndex}");
|
||||
return eTKeepsake.FishExtraDropList[0];
|
||||
}
|
||||
return eTKeepsake.FishExtraDropList[fishingData.NewIndex];
|
||||
}
|
||||
else if (etNewItem != null)
|
||||
{
|
||||
if (fishingData.NewIndex >= etNewItem.ExtraDropList.Count)
|
||||
{
|
||||
Debug.LogError($"NewItem ExtraDropList == {etNewItem.ExtraDropList.Count} Not Index {fishingData.NewIndex}");
|
||||
|
||||
return etNewItem.ExtraDropList[0];
|
||||
}
|
||||
return etNewItem.ExtraDropList[fishingData.NewIndex];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/// <summary>
|
||||
/// 最后钓上来的鱼是否有装饰
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DropAfterDrop OnChangeFishData()
|
||||
{
|
||||
var collectingTargetInit = GContext.container.Resolve<FishingEventData>().collectingTargetInit;
|
||||
if (collectingTargetInit == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
DropAfterDrop afterDrop = null;
|
||||
if (etDropAfterDrop != null)
|
||||
{
|
||||
afterDrop = new DropAfterDrop(etDropAfterDrop.Mode, etDropAfterDrop.Bone, etDropAfterDrop.Fx);
|
||||
}
|
||||
else if (eTDropByFish != null)
|
||||
{
|
||||
afterDrop = new DropAfterDrop(eTDropByFish.Mode, eTDropByFish.Bone, eTDropByFish.Fx);
|
||||
}
|
||||
//有相关装饰活动,并且有代币掉落
|
||||
return addCollecting > 0 ? afterDrop : null;
|
||||
}
|
||||
public ETChangeMaterial MaterialChange()
|
||||
{
|
||||
return addCollecting > 0 ? eTChangeMaterial : null;
|
||||
}
|
||||
|
||||
public float StatsChange(int index)
|
||||
{
|
||||
if (addCollecting == 0)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
if (eTChangeMaterial != null)
|
||||
{
|
||||
int Quality = fishingData.curFishData.Quality - 1;
|
||||
if (Quality >= eTChangeMaterial.StatsChange.Count)
|
||||
{
|
||||
Quality = eTChangeMaterial.StatsChange.Count - 1;
|
||||
}
|
||||
|
||||
List<float> statsChange = eTChangeMaterial.StatsChange[Quality];
|
||||
if (index < statsChange.Count)
|
||||
{
|
||||
return statsChange[index];
|
||||
}
|
||||
}
|
||||
if (etDropAfterDrop != null && index < etDropAfterDrop.StatsChange.Count)
|
||||
{
|
||||
return etDropAfterDrop.StatsChange[index];
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
public ETNewItem ETNewItemFx()
|
||||
{
|
||||
return etNewItem;
|
||||
}
|
||||
/// <summary>
|
||||
/// 掉落活动代币数量
|
||||
/// </summary>
|
||||
public void ExtraDrop()
|
||||
{
|
||||
addCollecting = 0;
|
||||
extraCashDrop = 0;
|
||||
//鱼的品质或者编号
|
||||
int dropID = GetExtraDropID();
|
||||
if (dropID != 0)
|
||||
{
|
||||
List<ItemData> itemData = GContext.container.Resolve<PlayerItemData>().GetItemDataByDropIdAndType(dropID);
|
||||
if (itemData is { Count: > 0 })
|
||||
{
|
||||
addCollecting = itemData[0].count;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Reset()
|
||||
{
|
||||
eTDropByFish = null;
|
||||
etDropAfterDrop = null;
|
||||
etNewItem = null;
|
||||
eTKeepsake = null;
|
||||
eTChangeMaterial = null;
|
||||
|
||||
mapFishList = null;
|
||||
addCollecting = 0;
|
||||
}
|
||||
public void GetFishByWeight()
|
||||
{
|
||||
var collectingTargetInit = GContext.container.Resolve<FishingEventData>().collectingTargetInit;
|
||||
if (collectingTargetInit != null)
|
||||
{
|
||||
FishBuffTimeData fishBuffTimeData = GContext.container.Resolve<BuffDataCenter>().GetBuffData<CollectionTargetWeight>();
|
||||
float BasicProb = collectingTargetInit.BasicProb;
|
||||
CollectionTargetWeight collectionTargetWeight = null;
|
||||
if (fishBuffTimeData != null)
|
||||
{
|
||||
FishBuff fishBuff = GContext.container.Resolve<Tables>().TbFishBuff.GetOrDefault(fishBuffTimeData.buffID);
|
||||
collectionTargetWeight = fishBuff.BuffParam as CollectionTargetWeight;
|
||||
BasicProb = collectionTargetWeight.NewTargetFishProb;
|
||||
}
|
||||
if (Random.Range(0, 1f) <= BasicProb + 0.0001f)
|
||||
{
|
||||
EventTargetExtraDrop eventTargetExtraDrop = GContext.container.Resolve<FishingEventData>().GetEventTargetExtraDrop();
|
||||
if (eventTargetExtraDrop != null)
|
||||
{
|
||||
if (eventTargetExtraDrop is ETDropByFish)
|
||||
{
|
||||
var eTDropByFishCur = (ETDropByFish)eventTargetExtraDrop;
|
||||
List<MapFishList> _mapFishList = eTDropByFishCur.ExtraDropList;
|
||||
for (int i = 0; i < _mapFishList.Count; i++)
|
||||
{
|
||||
if (_mapFishList[i].MapID == fishingData.MapId)
|
||||
{
|
||||
eTDropByFish = eTDropByFishCur;
|
||||
mapFishList = _mapFishList[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (eventTargetExtraDrop is ETDropAfterDrop)
|
||||
{
|
||||
etDropAfterDrop = (ETDropAfterDrop)eventTargetExtraDrop;
|
||||
}
|
||||
else if (eventTargetExtraDrop is ETChangeMaterial)
|
||||
{
|
||||
eTChangeMaterial = (ETChangeMaterial)eventTargetExtraDrop;
|
||||
}
|
||||
else if (eventTargetExtraDrop is ETNewItem)
|
||||
{
|
||||
fishingData.NewIndex = 0;
|
||||
etNewItem = (ETNewItem)eventTargetExtraDrop;
|
||||
fishingData.NewItemID = etNewItem.NewItemID[fishingData.NewIndex];
|
||||
fishingData.fishItem = GContext.container.Resolve<Tables>().GetItemData(fishingData.NewItemID);
|
||||
return;
|
||||
}
|
||||
else if (eventTargetExtraDrop is ETKeepsake)
|
||||
{
|
||||
eTKeepsake = (ETKeepsake)eventTargetExtraDrop;
|
||||
var newItemIDList = new List<int>(eTKeepsake.FishIDList);
|
||||
var newItemWeight = new List<float>(eTKeepsake.FishWeightList);
|
||||
//===================信物相关===================
|
||||
int curHour = ZZTimeHelper.UtcNow().UtcNowOffset().Hour;
|
||||
if (curHour >= 16)
|
||||
{
|
||||
curHour = 16;
|
||||
}
|
||||
else if (curHour >= 8)
|
||||
{
|
||||
curHour = 8;
|
||||
}
|
||||
else
|
||||
{
|
||||
curHour = 0;
|
||||
}
|
||||
int fishCount = GContext.container.Resolve<PlayerShopData>().GetShopPackBuyCount("CTFishID0" + curHour);
|
||||
|
||||
//每日信物权重
|
||||
var keepsakeWeight = eTKeepsake.KeepsakeWeight;
|
||||
if (fishCount < keepsakeWeight.Count)
|
||||
{
|
||||
newItemWeight[0] = keepsakeWeight[fishCount];
|
||||
}
|
||||
//buff重置鱼和信物权重
|
||||
if (collectionTargetWeight != null)
|
||||
{
|
||||
newItemWeight = new List<float>(collectionTargetWeight.NewWeightList);
|
||||
}
|
||||
//===================信物相关===================
|
||||
NewItemIDListFun(newItemIDList, newItemWeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void NewItemIDListFun(List<int> newItemIDList, List<float> newItemWeight)
|
||||
{
|
||||
fishingData.NewIndex = 0;
|
||||
fishingData.NewItemID = newItemIDList[0];
|
||||
float allWeight = newItemWeight.Sum();
|
||||
//特殊物品概率特殊调整 Todo
|
||||
float randomWeight = Random.Range(0.001f, allWeight);
|
||||
float sum = 0;
|
||||
for (int i = 0; i < newItemIDList.Count; i++)
|
||||
{
|
||||
sum += newItemWeight[i];
|
||||
if (randomWeight < sum)
|
||||
{
|
||||
fishingData.NewIndex = i;
|
||||
fishingData.NewItemID = newItemIDList[fishingData.NewIndex];
|
||||
fishingData.fishItem = GContext.container.Resolve<Tables>().GetItemData(fishingData.NewItemID);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 额外掉落代币数量
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public int GetAddCollecting()
|
||||
{
|
||||
return addCollecting;
|
||||
}
|
||||
|
||||
public float ExtraCashDrop()
|
||||
{
|
||||
if (addCollecting > 0 && extraCashDrop > 0)
|
||||
{
|
||||
DropPackageList dropPackageList = GContext.container.Resolve<Tables>().TbDrop[extraCashDrop].DropList;
|
||||
return dropPackageList.DropCountList[0];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GampPlay/Fishing/CollectingData.cs.meta
Normal file
11
Assets/Scripts/GampPlay/Fishing/CollectingData.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3ae443f88645a784ea153394be9c2c69
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
222
Assets/Scripts/GampPlay/Fishing/Fish.cs
Normal file
222
Assets/Scripts/GampPlay/Fishing/Fish.cs
Normal file
@@ -0,0 +1,222 @@
|
||||
using asap.core;
|
||||
using DG.Tweening;
|
||||
using Game;
|
||||
using GameCore;
|
||||
using System.Collections;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
public struct FishRotateEvent
|
||||
{
|
||||
public float rotate;
|
||||
public int state;// 0:停止自转, 1:开始自转, 2:旋转,3:固定角度, 4:隐藏, 5:显示
|
||||
public int rodType;
|
||||
public FishRotateEvent(float rotate, int state, int rodType)
|
||||
{
|
||||
this.rotate = rotate;
|
||||
this.state = state;
|
||||
this.rodType = rodType;
|
||||
}
|
||||
}
|
||||
public class Fish : MonoBehaviour
|
||||
{
|
||||
//鱼嘴位置
|
||||
public Transform mouthPos;
|
||||
public Transform Head;
|
||||
public Transform LeftEye;
|
||||
public Transform RightEye;
|
||||
public Transform Fin;
|
||||
public Transform Tail;
|
||||
public Transform Neck;
|
||||
public Transform Root;
|
||||
public Animator animator;
|
||||
//public FishingFlyingFish fishingFlyingFish;
|
||||
BoxCollider boxCollider;
|
||||
bool isCollider = false;
|
||||
[HideInInspector]
|
||||
public GameObject modeGo;
|
||||
//旋转速度
|
||||
public int rotateSpeed = 10;
|
||||
System.IDisposable disposable;
|
||||
float _fishAnimSpeed;
|
||||
bool Pulling01;
|
||||
public float FishAnimSpeed
|
||||
{
|
||||
set
|
||||
{
|
||||
_fishAnimSpeed = value;
|
||||
animator.speed = _fishAnimSpeed;
|
||||
}
|
||||
get { return _fishAnimSpeed; }
|
||||
}
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
boxCollider = GetComponent<BoxCollider>();
|
||||
if (boxCollider)
|
||||
{
|
||||
boxCollider.enabled = isCollider;
|
||||
}
|
||||
}
|
||||
public Transform Find(string name)
|
||||
{
|
||||
switch (name)
|
||||
{
|
||||
case "Fin":
|
||||
return Fin;
|
||||
case "Tail":
|
||||
return Tail;
|
||||
case "Neck":
|
||||
return Neck;
|
||||
case "Head":
|
||||
return Head;
|
||||
case "LeftEye":
|
||||
return LeftEye;
|
||||
case "RightEye":
|
||||
return RightEye;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
Pulling01 = false;
|
||||
transform.DOKill();
|
||||
disposable = GContext.OnEvent<FishRotateEvent>().Subscribe(OnFishingRotate);
|
||||
GameEventMgr.Instance.AddListener(GameEvents.EventFishingPlay, PlayerClick);
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
disposable.Dispose();
|
||||
disposable = null;
|
||||
GameEventMgr.Instance.RemoveListener(GameEvents.EventFishingPlay, PlayerClick);
|
||||
}
|
||||
public void EnableCollider()
|
||||
{
|
||||
isCollider = true;
|
||||
if (boxCollider)
|
||||
{
|
||||
boxCollider.enabled = true;
|
||||
}
|
||||
}
|
||||
public float GetColliderSize(float size)
|
||||
{
|
||||
if (boxCollider)
|
||||
{
|
||||
boxCollider.isTrigger = true;
|
||||
boxCollider.size *= size;
|
||||
return boxCollider.size.magnitude / 2;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private void PlayerClick()
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
var clicp = animator.GetCurrentAnimatorClipInfo(0);
|
||||
if (clicp[0].clip.name == "Idle01")
|
||||
{
|
||||
StartCoroutine(PlayClickSound());
|
||||
animator.SetTrigger("Click01");
|
||||
}
|
||||
}
|
||||
}
|
||||
public void PlayBite()
|
||||
{
|
||||
animator.SetTrigger("Bite01");
|
||||
}
|
||||
public void PlayJump()
|
||||
{
|
||||
animator.SetTrigger("Jump01");
|
||||
}
|
||||
public void SetTrigger(string triggerName)
|
||||
{
|
||||
animator.SetBool("Swim01", false);
|
||||
animator.speed = 1;
|
||||
animator.SetTrigger(triggerName);
|
||||
}
|
||||
public void PlaySwim01()
|
||||
{
|
||||
animator.speed = _fishAnimSpeed;
|
||||
if (!Pulling01)
|
||||
{
|
||||
animator.SetTrigger("Swim01");
|
||||
}
|
||||
}
|
||||
public void SetSkillInt(int inValue)
|
||||
{
|
||||
animator.SetInteger("SkillIndex", inValue);
|
||||
}
|
||||
public void SetSkillType(int inValue)
|
||||
{
|
||||
animator.SetInteger("SkillType", inValue);
|
||||
}
|
||||
IEnumerator PlayClickSound()
|
||||
{
|
||||
FishingData fishingData = GContext.container.Resolve<FishingData>();
|
||||
yield return new WaitForSeconds(fishingData.curFishData.DelaySplashClick);
|
||||
var audios = fishingData.curFishData.AudioSplashClick;
|
||||
if (audios.Count > 0)
|
||||
{
|
||||
string pullingOutSound = audios[Random.Range(0, audios.Count)];
|
||||
|
||||
GContext.Publish(new EventFishingSound(pullingOutSound));
|
||||
}
|
||||
if (!string.IsNullOrEmpty(fishingData.curFishData.FxWaterSplash))
|
||||
GContext.Publish(new PlayerRaindropEvent() { FxWaterSplash = fishingData.curFishData.FxWaterSplash });
|
||||
}
|
||||
public void Pulling()
|
||||
{
|
||||
if (animator != null)
|
||||
{
|
||||
animator.SetBool("Swim01", false);
|
||||
Pulling01 = true;
|
||||
animator.SetTrigger("Pulling01");
|
||||
}
|
||||
}
|
||||
void OnFishingRotate(FishRotateEvent fishRotateEvent)
|
||||
{
|
||||
OnFishingRotate(fishRotateEvent.rotate, fishRotateEvent.state, fishRotateEvent.rodType);
|
||||
}
|
||||
private void OnFishingRotate(float rotate, int state, int rodType)
|
||||
{
|
||||
switch (state)
|
||||
{
|
||||
case 0:
|
||||
//停止自转
|
||||
transform.DOKill();
|
||||
break;
|
||||
case 1:
|
||||
DOLocalRotate(rodType);
|
||||
break;
|
||||
case 2:
|
||||
transform.Rotate(Vector3.forward * rotate);
|
||||
break;
|
||||
case 3:
|
||||
transform.DOKill();
|
||||
transform.localEulerAngles = Vector3.back * rotate;
|
||||
break;
|
||||
case 4:
|
||||
animator.gameObject.SetActive(false);
|
||||
break;
|
||||
case 5:
|
||||
animator.gameObject.SetActive(true);
|
||||
animator.Play("Idle01");
|
||||
DOLocalRotate(rodType);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void DOLocalRotate(int rodType)
|
||||
{
|
||||
transform.DOKill();
|
||||
//开始自转
|
||||
Vector3 vector3 = Vector3.back * 360;
|
||||
if (rodType == 2)
|
||||
{
|
||||
vector3 = Vector3.forward * 360;
|
||||
}
|
||||
transform.DOLocalRotate(vector3, rotateSpeed, RotateMode.LocalAxisAdd).SetEase(Ease.Linear).SetLoops(-1);
|
||||
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GampPlay/Fishing/Fish.cs.meta
Normal file
11
Assets/Scripts/GampPlay/Fishing/Fish.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69a1181c1a285784699a8abf736f7aa0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
250
Assets/Scripts/GampPlay/Fishing/FishingSkinTool.cs
Normal file
250
Assets/Scripts/GampPlay/Fishing/FishingSkinTool.cs
Normal file
@@ -0,0 +1,250 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using GameCore;
|
||||
using UniRx;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AddressableAssets;
|
||||
public enum RodSkinType
|
||||
{
|
||||
skin = 0,
|
||||
glove = 1,
|
||||
//accessories = 2
|
||||
}
|
||||
public struct ChangeSkinEvent
|
||||
{
|
||||
public ChangeSkinEvent(RodSkinType Type)
|
||||
{
|
||||
this.Type = Type;
|
||||
}
|
||||
public RodSkinType Type;
|
||||
}
|
||||
public struct SelectSkinEvent
|
||||
{
|
||||
public SelectSkinEvent(int ID)
|
||||
{
|
||||
this.ID = ID;
|
||||
}
|
||||
public int ID;
|
||||
}
|
||||
public struct SelectGloveEvent
|
||||
{
|
||||
public SelectGloveEvent(int ID)
|
||||
{
|
||||
this.ID = ID;
|
||||
}
|
||||
public int ID;
|
||||
}
|
||||
public struct SelectAccessoriesEvent
|
||||
{
|
||||
public SelectAccessoriesEvent(int ID)
|
||||
{
|
||||
this.ID = ID;
|
||||
}
|
||||
public int ID;
|
||||
}
|
||||
public class FishingSkinTool : MonoBehaviour
|
||||
{
|
||||
Tables _tables;
|
||||
public GameObject _bait;
|
||||
GameObject baitAB;
|
||||
//相机初始化
|
||||
public Animator _cameraAnimator;
|
||||
public GameObject _fishingRodHandle;
|
||||
public Vector2 _lineResolution; // 钓鱼线的分辨率
|
||||
Animator rodHandleAni;
|
||||
Vector3 _targetPos;
|
||||
Animator fishingRodAnimator;
|
||||
Rod RodBehaviour;
|
||||
GameObject rodPrefab;
|
||||
HandController HandController;
|
||||
GameObject handAB;
|
||||
CompositeDisposable disposables = new CompositeDisposable();
|
||||
PlayerData playerData;
|
||||
PlayerFishData playerFishData;
|
||||
float FishingScale = 1;
|
||||
string _rodSkinPath;
|
||||
string _glovePath;
|
||||
private void Awake()
|
||||
{
|
||||
_tables = GContext.container.Resolve<Tables>();
|
||||
playerData = GContext.container.Resolve<PlayerData>();
|
||||
playerFishData = GContext.container.Resolve<PlayerFishData>();
|
||||
GContext.OnEvent<SelectGloveEvent>().Subscribe(OnSelectGloveEvent).AddTo(disposables);
|
||||
GContext.OnEvent<SelectSkinEvent>().Subscribe(OnSelectSkinEvent).AddTo(disposables);
|
||||
}
|
||||
private void Start()
|
||||
{
|
||||
LoadHand();
|
||||
LoadFishRod();
|
||||
LoadBait();
|
||||
}
|
||||
void LoadHand()
|
||||
{
|
||||
GloveData gloveData = GContext.container.Resolve<PlayerFishData>().GetGloveData;
|
||||
InitRodHandAsync(gloveData);
|
||||
}
|
||||
|
||||
void OnSelectGloveEvent(SelectGloveEvent e)
|
||||
{
|
||||
var gloveData = _tables.TbGloveData[e.ID];
|
||||
InitRodHandAsync(gloveData);
|
||||
}
|
||||
public async void InitRodHandAsync(GloveData gloveData)
|
||||
{
|
||||
if (gloveData == null)
|
||||
{
|
||||
Debug.LogError("gloveData is null");
|
||||
return;
|
||||
}
|
||||
string path = gloveData.Fbx;
|
||||
if (_glovePath == path)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_glovePath = path;
|
||||
if (handAB != null)
|
||||
{
|
||||
Addressables.ReleaseInstance(handAB);
|
||||
}
|
||||
var hand = await Addressables.InstantiateAsync(path, transform).Task;
|
||||
if (hand != null)
|
||||
{
|
||||
if (path != gloveData.Fbx)
|
||||
{
|
||||
Addressables.ReleaseInstance(hand);
|
||||
return;
|
||||
}
|
||||
handAB = hand;
|
||||
HandController = handAB.GetComponent<HandController>();
|
||||
if (RodBehaviour != null)
|
||||
{
|
||||
HandController.SetHandTargets(RodBehaviour.RightHandTargets, RodBehaviour.LeftHandTargets, RodBehaviour.BodyTargets);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async void LoadBait()
|
||||
{
|
||||
baitAB = await Addressables.InstantiateAsync("BaitRoot", _bait.transform).Task;
|
||||
baitAB.transform.localPosition = Vector3.zero;
|
||||
baitAB.transform.localRotation = Quaternion.identity;
|
||||
baitAB.transform.localScale = Vector3.one;
|
||||
}
|
||||
void LoadFishRod()
|
||||
{
|
||||
int equipRodID = playerData.equipRodID;
|
||||
var fishRodData = _tables.TbRodData[equipRodID];
|
||||
InitFishRodAsync(fishRodData);
|
||||
}
|
||||
public void InitFishRodAsync(RodData fishRodData)
|
||||
{
|
||||
int skindID = playerFishData.GetRodSkin(fishRodData.ID);
|
||||
if (skindID > 0)
|
||||
{
|
||||
var fishRodSkinData = _tables.TbRodSkinData.GetOrDefault(skindID);
|
||||
if (fishRodSkinData != null)
|
||||
{
|
||||
FishingScale = fishRodSkinData.FishingScale;
|
||||
LoadFishRodAsync(fishRodSkinData.Fbx);
|
||||
}
|
||||
}
|
||||
}
|
||||
void OnSelectSkinEvent(SelectSkinEvent e)
|
||||
{
|
||||
int skindID = e.ID;
|
||||
if (skindID > 0)
|
||||
{
|
||||
var fishRodSkinData = _tables.TbRodSkinData.GetOrDefault(skindID);
|
||||
if (fishRodSkinData != null)
|
||||
{
|
||||
FishingScale = fishRodSkinData.FishingScale;
|
||||
LoadFishRodAsync(fishRodSkinData.Fbx);
|
||||
}
|
||||
}
|
||||
}
|
||||
async void LoadFishRodAsync(string path)
|
||||
{
|
||||
if (_rodSkinPath == path)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_rodSkinPath = path;
|
||||
var goPrefab = await Addressables.LoadAssetAsync<GameObject>(path).Task;
|
||||
_bait.transform.SetParent(transform);
|
||||
if (goPrefab != null)
|
||||
{
|
||||
if (rodPrefab)
|
||||
{
|
||||
Addressables.Release(rodPrefab);
|
||||
}
|
||||
rodPrefab = goPrefab;
|
||||
var go = Instantiate(goPrefab, transform.Find("FishingRodHandle"));
|
||||
go.transform.localPosition = Vector3.zero;
|
||||
go.transform.localScale = Vector3.one * FishingScale;
|
||||
if (RodBehaviour != null)
|
||||
{
|
||||
DestroyImmediate(RodBehaviour.gameObject);
|
||||
}
|
||||
|
||||
RodBehaviour = go.GetComponent<Rod>();
|
||||
fishingRodAnimator = RodBehaviour.rod.GetComponent<Animator>();
|
||||
//Set HandIK Target
|
||||
if (HandController != null)
|
||||
{
|
||||
HandController.SetHandTargets(RodBehaviour.RightHandTargets, RodBehaviour.LeftHandTargets, RodBehaviour.BodyTargets);
|
||||
}
|
||||
|
||||
if (RodBehaviour.cCDIK != null)
|
||||
{
|
||||
RodBehaviour.cCDIK.enabled = false;
|
||||
}
|
||||
_bait.transform.SetParent(RodBehaviour.Bait);
|
||||
_bait.transform.localPosition = Vector3.zero; //-Vector3.up * 0.1f;
|
||||
_bait.transform.localRotation = Quaternion.Euler(Vector3.forward * 90);
|
||||
}
|
||||
}
|
||||
private void LateUpdate()
|
||||
{
|
||||
DrawFishingLine();
|
||||
}
|
||||
private void DrawFishingLine()
|
||||
{
|
||||
if (RodBehaviour == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
// 计算钓鱼线上的点
|
||||
Vector3[] linePoints;
|
||||
int addCount = RodBehaviour.LineList.Count + 4;
|
||||
linePoints = new Vector3[addCount];
|
||||
linePoints[0] = RodBehaviour.LineHole.position;
|
||||
linePoints[1] = RodBehaviour.EndLine.position;
|
||||
|
||||
for (int i = 0; i < RodBehaviour.LineList.Count; i++)
|
||||
{
|
||||
linePoints[i + 2] = RodBehaviour.LineList[i].position;
|
||||
|
||||
}
|
||||
linePoints[addCount - 2] = RodBehaviour.TopLine.position;
|
||||
linePoints[addCount - 1] = _bait.transform.position;
|
||||
// 绘制钓鱼线
|
||||
RodBehaviour.fishingLineRenderer.positionCount = addCount;
|
||||
RodBehaviour.fishingLineRenderer.SetPositions(linePoints);
|
||||
}
|
||||
private float CalculateSegmetLenght(float distance, Vector2 lineResolution)
|
||||
{
|
||||
float x = Mathf.InverseLerp(1, 50, distance);
|
||||
float value = Mathf.Lerp(lineResolution.x, lineResolution.y, x);
|
||||
|
||||
return value;
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
disposables?.Dispose();
|
||||
disposables = null;
|
||||
|
||||
Addressables.Release(rodPrefab);
|
||||
Addressables.ReleaseInstance(baitAB);
|
||||
Addressables.ReleaseInstance(handAB);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GampPlay/Fishing/FishingSkinTool.cs.meta
Normal file
11
Assets/Scripts/GampPlay/Fishing/FishingSkinTool.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a655abc298aa9dd45ad5da6cedb3ed5d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
150
Assets/Scripts/GampPlay/Fishing/HandController.cs
Normal file
150
Assets/Scripts/GampPlay/Fishing/HandController.cs
Normal file
@@ -0,0 +1,150 @@
|
||||
using asap.core;
|
||||
using cfg;
|
||||
using RootMotion.FinalIK;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum EHandState
|
||||
{
|
||||
None,
|
||||
Idle,
|
||||
Hold,
|
||||
Fishing,
|
||||
Catch,
|
||||
Release,
|
||||
End
|
||||
}
|
||||
|
||||
public class HandController : MonoBehaviour
|
||||
{
|
||||
// private Animator anim_hand;
|
||||
//[HideInInspector]
|
||||
//public Animator anim_rightElbowDirection;
|
||||
|
||||
HandPoser poser_l;
|
||||
HandPoser poser_r;
|
||||
|
||||
private FullBodyBipedIK _bodyIK;
|
||||
|
||||
private Transform
|
||||
_leftElbowDireciton,
|
||||
_rightElbowDireciton,
|
||||
_rightHandTargets,
|
||||
_leftHandTargets,
|
||||
Shoulder;
|
||||
|
||||
private bool _isRightHandFollowTarget;
|
||||
private bool _isLeftHandFollowTarget;
|
||||
MMTService mmtService;
|
||||
|
||||
public EHandState EHandState { get; private set; }
|
||||
#region State Method
|
||||
bool isInit;
|
||||
public void ChangeHandState(EHandState state)
|
||||
{
|
||||
}
|
||||
|
||||
public void OnStateEnter(EHandState state)
|
||||
{
|
||||
|
||||
}
|
||||
public void OnStateExit()
|
||||
{
|
||||
|
||||
}
|
||||
public void SetActive(bool value)
|
||||
{
|
||||
if (mmtService == null)
|
||||
{
|
||||
mmtService = GContext.container.Resolve<MMTService>();
|
||||
}
|
||||
if (mmtService.CanShowHand)
|
||||
{
|
||||
gameObject.SetActive(value);
|
||||
}
|
||||
else
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Component Method
|
||||
void Awake()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
private void Init()
|
||||
{
|
||||
if (isInit)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isInit = true;
|
||||
Shoulder = transform.Find("HandComponent/Shoulder");
|
||||
// anim_hand = transform.Find("Hand").GetComponent<Animator>();
|
||||
_rightElbowDireciton = transform.Find("HandComponent/Elbow/RightElbowDirection");
|
||||
_leftElbowDireciton = transform.Find("HandComponent/Elbow/LeftElbowDirection");
|
||||
//anim_rightElbowDirection = transform.Find("RightElbowDirection").GetComponent<Animator>();
|
||||
_bodyIK = GetComponentInChildren<FullBodyBipedIK>();
|
||||
var posers = GetComponentsInChildren<HandPoser>();
|
||||
if (posers.Length == 2)
|
||||
{
|
||||
poser_l = posers[0];
|
||||
poser_r = posers[1];
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("HandPoser not found: " + posers.Length);
|
||||
}
|
||||
_bodyIK.solver.rightArmChain.bendConstraint.bendGoal = _rightElbowDireciton;
|
||||
_bodyIK.solver.leftArmChain.bendConstraint.bendGoal = _leftElbowDireciton;
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
SetShoulderRota(Vector3.zero);
|
||||
}
|
||||
public void SetHandTargets(Transform rightHand, Transform LeftHand, Transform body)
|
||||
{
|
||||
Init();
|
||||
_leftHandTargets = LeftHand;
|
||||
_rightHandTargets = rightHand;
|
||||
|
||||
_bodyIK.solver.leftHandEffector.target = _leftHandTargets;
|
||||
_bodyIK.solver.rightHandEffector.target = _rightHandTargets;
|
||||
|
||||
//_bodyIK.solver.bodyEffector.target = body;
|
||||
if (poser_l != null)
|
||||
{
|
||||
poser_l.poseRoot = _leftHandTargets;
|
||||
}
|
||||
if (poser_r != null)
|
||||
{
|
||||
poser_r.poseRoot = _rightHandTargets;
|
||||
}
|
||||
|
||||
SetAllHandIkTarget(1f);
|
||||
|
||||
}
|
||||
|
||||
private void SetAllHandIkTarget(float weight)
|
||||
{
|
||||
SetHandIKWeight(_bodyIK.solver.leftHandEffector, weight);
|
||||
SetHandIKWeight(_bodyIK.solver.rightHandEffector, weight);
|
||||
}
|
||||
|
||||
private void SetHandIKWeight(IKEffector effector, float weight)
|
||||
{
|
||||
effector.positionWeight = weight;
|
||||
effector.rotationWeight = weight;
|
||||
}
|
||||
public void SetShoulderRota(Vector3 vector)
|
||||
{
|
||||
Quaternion quaternion = Quaternion.Euler(vector);
|
||||
Shoulder.localRotation = quaternion;
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
11
Assets/Scripts/GampPlay/Fishing/HandController.cs.meta
Normal file
11
Assets/Scripts/GampPlay/Fishing/HandController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0b11f7381675ee4ca0229d57b014134
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
97
Assets/Scripts/GampPlay/Fishing/HandPosController.cs
Normal file
97
Assets/Scripts/GampPlay/Fishing/HandPosController.cs
Normal file
@@ -0,0 +1,97 @@
|
||||
using asap.core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UniRx;
|
||||
|
||||
public enum ERightState
|
||||
{
|
||||
Idle,
|
||||
Throwing,
|
||||
Waiting,
|
||||
Piercing,
|
||||
Drawing,
|
||||
Pulling,
|
||||
Preparing,
|
||||
Noviceguide,
|
||||
MaxCombo,
|
||||
Shock,
|
||||
PiercingSp,
|
||||
}
|
||||
[Serializable]
|
||||
public class RightState
|
||||
{
|
||||
public ERightState state;
|
||||
public float time;
|
||||
public Vector3 pos;
|
||||
}
|
||||
|
||||
public class HandPosController : MonoBehaviour
|
||||
{
|
||||
[Header("专为钓场钓鱼使用,其他场景不再初始化")]
|
||||
public List<RightState> RightStateDic;
|
||||
public ERightState curERightState;
|
||||
Coroutine coroutine;
|
||||
IDisposable disposable;
|
||||
bool isInFishingAct = false;
|
||||
private void Awake()
|
||||
{
|
||||
IAct act = GContext.container.ResolveAct("ShooterFishAct");
|
||||
isInFishingAct = act == null;
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
if (isInFishingAct)
|
||||
{
|
||||
disposable = GContext.OnEvent<ERightState>().Subscribe(SetRightStateDic);
|
||||
SetRightStateDic(ERightState.Preparing);
|
||||
}
|
||||
}
|
||||
public void SetRightStateDic(ERightState state)
|
||||
{
|
||||
RightState rightState = null;
|
||||
foreach (var item in RightStateDic)
|
||||
{
|
||||
if (item.state == state)
|
||||
{
|
||||
rightState = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (rightState != null)
|
||||
{
|
||||
if (coroutine != null)
|
||||
{
|
||||
StopCoroutine(coroutine);
|
||||
}
|
||||
coroutine = StartCoroutine(SetRightHandTarget(rightState));
|
||||
}
|
||||
}
|
||||
IEnumerator SetRightHandTarget(RightState rightState)
|
||||
{
|
||||
curERightState = rightState.state;
|
||||
Vector3 pos = rightState.pos;
|
||||
Vector3 starPos = transform.localPosition;
|
||||
float time = rightState.time;
|
||||
float timer = 0;
|
||||
if (time > 0.01)
|
||||
{
|
||||
while (timer < time)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
transform.localPosition = Vector3.Lerp(starPos, pos, timer / time);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localPosition = pos;
|
||||
}
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/GampPlay/Fishing/HandPosController.cs.meta
Normal file
11
Assets/Scripts/GampPlay/Fishing/HandPosController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: df32d4aa770f98d439ee9b5784c253f7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
93
Assets/Scripts/GampPlay/Fishing/HandPosShootController.cs
Normal file
93
Assets/Scripts/GampPlay/Fishing/HandPosShootController.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
using asap.core;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UniRx;
|
||||
|
||||
public enum EShootState
|
||||
{
|
||||
Appear,
|
||||
Idle,
|
||||
Aim,
|
||||
Back,
|
||||
Shoot,
|
||||
Capture,
|
||||
Escape,
|
||||
}
|
||||
[Serializable]
|
||||
public class ShootState
|
||||
{
|
||||
public EShootState state;
|
||||
public float time;
|
||||
public Vector3 pos;
|
||||
}
|
||||
public class HandPosShootController : MonoBehaviour
|
||||
{
|
||||
[Header("专为射场射鱼使用,其他场景不再初始化")]
|
||||
|
||||
public List<ShootState> ShootStateDic;
|
||||
public EShootState curEShootState;
|
||||
Coroutine coroutine;
|
||||
IDisposable disposable;
|
||||
bool isInShooterFishAct = false;
|
||||
private void Awake()
|
||||
{
|
||||
IAct act = GContext.container.ResolveAct("ShooterFishAct");
|
||||
isInShooterFishAct = act != null;
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
if (isInShooterFishAct)
|
||||
{
|
||||
disposable = GContext.OnEvent<EShootState>().Subscribe(SetShootStateDic);
|
||||
SetShootStateDic(EShootState.Appear);
|
||||
}
|
||||
}
|
||||
public void SetShootStateDic(EShootState state)
|
||||
{
|
||||
ShootState ShootState = null;
|
||||
foreach (var item in ShootStateDic)
|
||||
{
|
||||
if (item.state == state)
|
||||
{
|
||||
ShootState = item;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ShootState != null)
|
||||
{
|
||||
if (coroutine != null)
|
||||
{
|
||||
StopCoroutine(coroutine);
|
||||
}
|
||||
coroutine = StartCoroutine(SetRightHandTarget(ShootState));
|
||||
}
|
||||
}
|
||||
IEnumerator SetRightHandTarget(ShootState ShootState)
|
||||
{
|
||||
curEShootState = ShootState.state;
|
||||
Vector3 pos = ShootState.pos;
|
||||
Vector3 starPos = transform.localPosition;
|
||||
float time = ShootState.time;
|
||||
float timer = 0;
|
||||
if (time > 0.01)
|
||||
{
|
||||
while (timer < time)
|
||||
{
|
||||
timer += Time.deltaTime;
|
||||
transform.localPosition = Vector3.Lerp(starPos, pos, timer / time);
|
||||
yield return null;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
transform.localPosition = pos;
|
||||
}
|
||||
}
|
||||
private void OnDisable()
|
||||
{
|
||||
disposable?.Dispose();
|
||||
disposable = null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c5460e27361bef643b2d3d9a357d7eef
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
24
Assets/Scripts/GampPlay/Fishing/Rod.cs
Normal file
24
Assets/Scripts/GampPlay/Fishing/Rod.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using RootMotion.FinalIK;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class Rod : MonoBehaviour
|
||||
{
|
||||
public GameObject rod;
|
||||
|
||||
public Transform Bait; // 鱼饵的位置
|
||||
public Transform TopLine; // 钓鱼竿的顶部位置
|
||||
public Transform EndLine;
|
||||
public Transform Rod_Joint;
|
||||
public List<Transform> LineList;
|
||||
public Transform LineHole;
|
||||
|
||||
public LineRenderer fishingLineRenderer;
|
||||
public CCDIK cCDIK;
|
||||
|
||||
public Transform LeftHandTargets;
|
||||
public Transform RightHandTargets;
|
||||
public Transform BodyTargets;
|
||||
public TMP_Text lineLength;
|
||||
}
|
||||
11
Assets/Scripts/GampPlay/Fishing/Rod.cs.meta
Normal file
11
Assets/Scripts/GampPlay/Fishing/Rod.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1999f4b34d23d5942b9966f39f71c715
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user