92 lines
2.5 KiB
C#
Raw Permalink Normal View History

2025-05-19 15:08:55 +08:00
using System;
using System.Collections.Generic;
using System.IO;
using System.Xml.Linq;
using UnityEngine;
using UnityEngine.EventSystems;
namespace QFramework
{
public class HasDeviceCondition : ICondition
{
private static SimpleObjectPool<HasDeviceCondition> mSimpleObjectPool =
new SimpleObjectPool<HasDeviceCondition>(() => new HasDeviceCondition(), null, 10);
private HasDeviceCondition() { }
public GameObject obj = null;
string name;
int count = 1;
public static HasDeviceCondition Allocate(Dictionary<string, string> datas)
{
var conditionAction = mSimpleObjectPool.Allocate();
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
conditionAction.Deinited = false;
conditionAction.Reset();
conditionAction.name = datas.ContainsKey("deviceName") ? datas["deviceName"] : "";
if (datas.ContainsKey("count"))
{
if (int.TryParse(datas["count"], out conditionAction.count) == false)
{
conditionAction.count = 1;
}
}
return conditionAction;
}
public bool Check()
{
if (string.IsNullOrEmpty(name) == false)
{
var device = PlayerController.Instance.HasDevice(name);
if (device != null && device.count >= count)
{
return true;
}
}
return false;
}
public bool Paused { get; set; }
public bool Deinited { get; set; }
public ulong ActionID { get; set; }
public ActionStatus Status { get; set; }
public void OnStart()
{
}
public void OnExecute(float dt)
{
if (Check())
{
this.Finish();
}
}
public void OnFinish()
{
}
public void Deinit()
{
if (!Deinited)
{
Deinited = true;
obj = null;
mSimpleObjectPool.Recycle(this);
}
}
public void Reset()
{
Paused = false;
Status = ActionStatus.NotStart;
}
}
public static class HasDeviceConditionExtension
{
public static ISequence HasDeviceCondition(this ISequence self, Dictionary<string, string> datas)
{
return self.Append(QFramework.HasDeviceCondition.Allocate(datas));
}
}
}