Files
Fishing2/Assets/Scripts/Fishing2~/Unit/Unity/UnitUnityComponent.cs

74 lines
2.4 KiB
C#

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>();
}
}
}