结构大修改,改成朴实无华的结构,不过度架构。能跑就行
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using Fantasy.Entitas;
|
||||
using Fantasy.Entitas.Interface;
|
||||
using UnityEngine;
|
||||
|
||||
namespace NBF.Fishing2
|
||||
{
|
||||
/// <summary>
|
||||
/// 手电筒组件
|
||||
/// </summary>
|
||||
public class FlashlightComponent : Entity
|
||||
{
|
||||
private GameObject _fishingLight;
|
||||
|
||||
|
||||
public class FlashlightComponentAwakeSystem : AwakeSystem<FlashlightComponent>
|
||||
{
|
||||
protected override void Awake(FlashlightComponent self)
|
||||
{
|
||||
var numericComponent = self.Parent.GetComponent<NumericComponent>();
|
||||
var unityComponent = self.Parent.GetComponent<UnitUnityComponent>();
|
||||
// self._fishingLight = unityComponent.Asset.FishingLight;
|
||||
// self.Change(numericComponent[NumericType.Flashlight]);
|
||||
|
||||
var mapUnit = self.Parent as MapUnit;
|
||||
if (mapUnit.IsSelf())
|
||||
{
|
||||
var inputComponent = self.Scene.GetComponent<InputComponent>();
|
||||
inputComponent.OnPlayerPerformed += self.OnPlayerCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class FlashlightComponentDestroySystem : DestroySystem<FlashlightComponent>
|
||||
{
|
||||
protected override void Destroy(FlashlightComponent self)
|
||||
{
|
||||
self._fishingLight = null;
|
||||
var mapUnit = self.Parent as MapUnit;
|
||||
if (mapUnit.IsSelf())
|
||||
{
|
||||
var inputComponent = self.Scene.GetComponent<InputComponent>();
|
||||
if (inputComponent != null)
|
||||
{
|
||||
inputComponent.OnPlayerPerformed -= self.OnPlayerCanceled;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void OnPlayerCanceled(string action)
|
||||
{
|
||||
if (action == InputDef.Player.UseTorch)
|
||||
{
|
||||
var numericComponent = Parent.GetComponent<NumericComponent>();
|
||||
if (numericComponent != null)
|
||||
{
|
||||
var oldValue = numericComponent[NumericType.Flashlight];
|
||||
numericComponent[NumericType.Flashlight] = oldValue > 0 ? 0 : 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Change(long value)
|
||||
{
|
||||
_fishingLight.SetActive(value > 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user