using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace vnxbqy.UI { public delegate bool BusinessTestHandler(out int error); public class BusinessEquationController { bool m_Busy = false; public bool busy { get { return m_Busy; } set { m_Busy = value; } } } public class BusinessEquation { Action> todo; BusinessTestHandler test; Action onExpect; Action onOutExpect; BusinessEquationController controller = null; public BusinessEquation(BusinessEquationController _controller) { controller = _controller; } public void Invoke() { if(controller.busy) { return; } var error = 0; if(test(out error)) { if(todo != null) { controller.busy = true; todo(OnResult); } } else { controller.busy = false; if(onOutExpect != null) { onOutExpect(error); } } } public BusinessEquation Do(Action> _action) { todo = _action; return this; } public BusinessEquation When(BusinessTestHandler _action) { test = _action; return this; } public BusinessEquation OnExpect(Action _action) { onExpect = _action; return this; } public BusinessEquation OnOutExpect(Action _action) { onOutExpect = _action; return this; } private void OnResult(bool _ok,int _error) { controller.busy = false; if(_ok) { if(onExpect != null) { onExpect(); } } else { if(onOutExpect != null) { onOutExpect(_error); } } } } }