using Fantasy.Entitas;
using Fantasy.Entitas.Interface;
using UnityEngine;
namespace NBF.Fishing2
{
///
/// 手电筒组件
///
public class FlashlightComponent : Entity
{
private GameObject _fishingLight;
public class FlashlightComponentAwakeSystem : AwakeSystem
{
protected override void Awake(FlashlightComponent self)
{
var numericComponent = self.Parent.GetComponent();
var unityComponent = self.Parent.GetComponent();
// 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.OnPlayerPerformed += self.OnPlayerCanceled;
}
}
}
public class FlashlightComponentDestroySystem : DestroySystem
{
protected override void Destroy(FlashlightComponent self)
{
self._fishingLight = null;
var mapUnit = self.Parent as MapUnit;
if (mapUnit.IsSelf())
{
var inputComponent = self.Scene.GetComponent();
if (inputComponent != null)
{
inputComponent.OnPlayerPerformed -= self.OnPlayerCanceled;
}
}
}
}
private void OnPlayerCanceled(string action)
{
if (action == InputDef.Player.UseTorch)
{
var numericComponent = Parent.GetComponent();
if (numericComponent != null)
{
var oldValue = numericComponent[NumericType.Flashlight];
numericComponent[NumericType.Flashlight] = oldValue > 0 ? 0 : 1;
}
}
}
public void Change(long value)
{
_fishingLight.SetActive(value > 0);
}
}
}