结构大修改,改成朴实无华的结构,不过度架构。能跑就行
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using NBC;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
public class CharacterAnimatorComponent : Entity
|
||||
{
|
||||
#region 参数定义
|
||||
|
||||
public static readonly int IsSwiming = Animator.StringToHash("Swim");
|
||||
|
||||
public static readonly int ThrowFar = Animator.StringToHash("ThrowFar");
|
||||
|
||||
public static readonly int BoatDriving = Animator.StringToHash("BoatDriving");
|
||||
|
||||
public static readonly int BaitInWater = Animator.StringToHash("BaitInWater");
|
||||
|
||||
public static readonly int HeldRod = Animator.StringToHash("HeldRod");
|
||||
|
||||
public static readonly int RodArming = Animator.StringToHash("RodArming");
|
||||
|
||||
public static readonly int Forward = Animator.StringToHash("Forward");
|
||||
|
||||
public static readonly int Turn = Animator.StringToHash("Turn");
|
||||
|
||||
public static readonly int OnGround = Animator.StringToHash("OnGround");
|
||||
|
||||
public static readonly int RodRight = Animator.StringToHash("rod right");
|
||||
|
||||
public static readonly int RodForward = Animator.StringToHash("rod forward");
|
||||
|
||||
public static readonly int PreciseCast = Animator.StringToHash("Precise Cast");
|
||||
|
||||
public static readonly int PreciseIdle = Animator.StringToHash("Precise Idle");
|
||||
|
||||
|
||||
public static readonly string Torso = "Torso";
|
||||
|
||||
#endregion
|
||||
|
||||
public Animator Animator { get; private set; }
|
||||
public MapUnit MapUnit;
|
||||
|
||||
private bool _isTorsoLayerEnabled;
|
||||
|
||||
#region System
|
||||
|
||||
public class CharacterAnimatorComponentDestroySystem : DestroySystem<CharacterAnimatorComponent>
|
||||
{
|
||||
protected override void Destroy(CharacterAnimatorComponent self)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class CharacterAnimatorComponentAwakeSystem : AwakeSystem<CharacterAnimatorComponent>
|
||||
{
|
||||
protected override void Awake(CharacterAnimatorComponent self)
|
||||
{
|
||||
self.MapUnit = self.Parent as MapUnit;
|
||||
var unitUnityComponent = self.Parent.GetComponent<UnitUnityComponent>();
|
||||
self.Animator = unitUnityComponent.ModelAsset.Animator;
|
||||
}
|
||||
}
|
||||
|
||||
// public class CharacterAnimatorComponentUpdateSystem : UpdateSystem<CharacterAnimatorComponent>
|
||||
// {
|
||||
// protected override void Update(CharacterAnimatorComponent self)
|
||||
// {
|
||||
// // self.UpdateAnimator();
|
||||
// }
|
||||
// }
|
||||
|
||||
public class CharacterAnimatorComponentLateUpdateSystem : LateUpdateSystem<CharacterAnimatorComponent>
|
||||
{
|
||||
protected override void LateUpdate(CharacterAnimatorComponent self)
|
||||
{
|
||||
self.UpdateAnimator();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
private void UpdateAnimator()
|
||||
{
|
||||
Animator.SetBool(OnGround, MapUnit.IsGrounded);
|
||||
float value3 = Mathf.Lerp(Animator.GetFloat(Forward), MapUnit.Speed / 5f, Time.deltaTime * 20f);
|
||||
Animator.SetFloat(Forward, value3);
|
||||
|
||||
// 平滑处理
|
||||
// float smoothedTurn = Mathf.SmoothDamp(Animator.GetFloat(Turn),
|
||||
// MapUnit.RotationSpeed,
|
||||
// ref turnSmoothVelocity,
|
||||
// smoothingTime
|
||||
// );
|
||||
|
||||
float smoothedTurn = Mathf.Lerp(Animator.GetFloat(Turn), MapUnit.RotationSpeed, Time.deltaTime * 10f);
|
||||
Animator.SetFloat(Turn, smoothedTurn);
|
||||
|
||||
|
||||
float layerWeight = Animator.GetLayerWeight(Animator.GetLayerIndex(Torso));
|
||||
SetLayerWeight(Torso,
|
||||
Mathf.MoveTowards(layerWeight, _isTorsoLayerEnabled ? 1f : 0f, Time.deltaTime * 3f));
|
||||
}
|
||||
|
||||
public void SetLayerWeight(string layer, float weight)
|
||||
{
|
||||
Animator.SetLayerWeight(Animator.GetLayerIndex(layer), weight);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c8042507191477295dbdac2c7dd7c59
|
||||
timeCreated: 1765353895
|
||||
74
Assets/Scripts/Fishing2~/Unit/Unity/UnitUnityComponent.cs
Normal file
74
Assets/Scripts/Fishing2~/Unit/Unity/UnitUnityComponent.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using ECM2;
|
||||
using ECM2.Examples.FirstPerson;
|
||||
using Fantasy.Async;
|
||||
using NBC;
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using RootMotion.FinalIK;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
/// <summary>
|
||||
/// Unit 对应的unity对象组件
|
||||
/// </summary>
|
||||
public class UnitUnityComponent : Entity
|
||||
{
|
||||
public GameObject GameObject { get; set; }
|
||||
public GameObject ModelGameObject { get; set; }
|
||||
|
||||
public Transform Transform { get; set; }
|
||||
|
||||
public PlayerModelAsset ModelAsset { get; set; }
|
||||
|
||||
public CharacterMovement Character { get; set; }
|
||||
public FirstPersonCharacter FirstPerson { get; set; }
|
||||
|
||||
public PlayerRootAsset RootAsset { get; set; }
|
||||
|
||||
#region System
|
||||
|
||||
public class UnitUnityComponentDestroySystem : DestroySystem<UnitUnityComponent>
|
||||
{
|
||||
protected override void Destroy(UnitUnityComponent self)
|
||||
{
|
||||
if (self.GameObject != null)
|
||||
{
|
||||
Object.Destroy(self.GameObject);
|
||||
}
|
||||
|
||||
self.ModelAsset = null;
|
||||
self.GameObject = null;
|
||||
self.Transform = null;
|
||||
self.Character = null;
|
||||
self.FirstPerson = null;
|
||||
self.RootAsset = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public async FTask InitUnityObject()
|
||||
{
|
||||
var gameObject = PrefabsHelper.CreatePlayer(SceneSettings.Instance.Node);
|
||||
GameObject = gameObject;
|
||||
Transform = gameObject.transform;
|
||||
Transform.localPosition = new Vector3(484, 1, 422);
|
||||
Parent.GetOrAddComponent<FlashlightComponent>();
|
||||
Character = gameObject.GetComponent<CharacterMovement>();
|
||||
FirstPerson = gameObject.GetComponent<FirstPersonCharacter>();
|
||||
RootAsset = gameObject.GetComponent<PlayerRootAsset>();
|
||||
// Parent.GetOrAddComponent<CharacterControllerComponent>();
|
||||
|
||||
var modelObject = PrefabsHelper.CreatePlayer(RootAsset.Root, "Human_Male");
|
||||
modelObject.transform.localPosition = Vector3.zero;
|
||||
ModelGameObject = modelObject;
|
||||
ModelAsset = modelObject.GetComponent<PlayerModelAsset>();
|
||||
|
||||
|
||||
Parent.GetOrAddComponent<CharacterMovementComponent>();
|
||||
Parent.GetOrAddComponent<CharacterLookComponent>();
|
||||
Parent.GetOrAddComponent<CharacterAnimatorComponent>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d2c42a4bc1347cebc390147a1a95c54
|
||||
timeCreated: 1755921030
|
||||
Reference in New Issue
Block a user