89 lines
2.4 KiB
C#
89 lines
2.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
|
|
namespace QFramework
|
|
{
|
|
public class ObjClickCondition : ICondition
|
|
{
|
|
|
|
private static SimpleObjectPool<ObjClickCondition> mSimpleObjectPool =
|
|
new SimpleObjectPool<ObjClickCondition>(() => new ObjClickCondition(), null, 10);
|
|
|
|
private ObjClickCondition() { }
|
|
public GameObject obj = null;
|
|
string path;
|
|
public static ObjClickCondition Allocate(string path)
|
|
{
|
|
var conditionAction = mSimpleObjectPool.Allocate();
|
|
conditionAction.ActionID = ActionKit.ID_GENERATOR++;
|
|
conditionAction.Deinited = false;
|
|
conditionAction.Reset();
|
|
conditionAction.path = path;
|
|
return conditionAction;
|
|
}
|
|
public bool Check()
|
|
{
|
|
if (obj == null)
|
|
{
|
|
obj = Utility.FindObj(path);
|
|
}
|
|
if (obj != null && Input.GetMouseButtonUp(0))
|
|
{
|
|
Vector3 mousePos = Input.mousePosition;
|
|
Ray ray = Camera.main.ScreenPointToRay(mousePos);
|
|
RaycastHit hit;
|
|
if (Physics.Raycast(ray, out hit))
|
|
{
|
|
return obj == hit.collider.gameObject;
|
|
}
|
|
}
|
|
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;
|
|
path = null;
|
|
mSimpleObjectPool.Recycle(this);
|
|
}
|
|
}
|
|
|
|
public void Reset()
|
|
{
|
|
Paused = false;
|
|
Status = ActionStatus.NotStart;
|
|
}
|
|
}
|
|
|
|
public static class ObjClickConditionExtension
|
|
{
|
|
public static ISequence ObjClickCondition(this ISequence self, string uipath)
|
|
{
|
|
return self.Append(QFramework.ObjClickCondition.Allocate(uipath));
|
|
}
|
|
}
|
|
} |