少年修仙传客户端代码仓库
hch
2025-03-19 6770e1eb64c4282def45adb824b14b2a407fdd30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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<Action<bool,int>> todo;
        BusinessTestHandler test;
        Action onExpect;
        Action<int> 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<bool,int>> _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<int> _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);
                }
            }
        }
 
    }
 
}