三国卡牌客户端基础资源仓库
yyl
2025-08-25 214fe94eaf7f09741a7857775dfffe8c3b83c75c
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ output extension=".cs" #>
<#
    var empty = new (string, string)[0];
 
    var triggers = new (string triggerName, string methodName, string returnType, string handlerInterface, (string argType, string argName)[] arguments)[]
    {
        ("AnimatorIK", "OnAnimatorIK", "int", null, new []{ ("int", "layerIndex") }),
        ("AnimatorMove", "OnAnimatorMove", "AsyncUnit", null, empty),
        ("OnCanvasGroupChanged", "OnCanvasGroupChanged", "AsyncUnit", null, empty ),
        ("CollisionEnter2D", "OnCollisionEnter2D", "Collision2D", null, new []{ ("Collision2D", "coll") }),
        ("CollisionExit2D", "OnCollisionExit2D", "Collision2D", null, new []{ ("Collision2D", "coll") }),
        ("CollisionStay2D", "OnCollisionStay2D", "Collision2D", null, new []{ ("Collision2D", "coll") }),
        ("CollisionEnter", "OnCollisionEnter", "Collision", null, new []{ ("Collision", "coll") }),
        ("CollisionExit", "OnCollisionExit", "Collision", null, new []{ ("Collision", "coll") }),
        ("CollisionStay", "OnCollisionStay", "Collision", null, new []{ ("Collision", "coll") }),
        ("Enable", "OnEnable", "AsyncUnit", null, empty),
        ("Disable", "OnDisable", "AsyncUnit", null, empty),
        ("JointBreak", "OnJointBreak", "float", null, new []{ ("float", "breakForce") }),
        ("JointBreak2D", "OnJointBreak2D", "Joint2D", null, new []{ ("Joint2D", "brokenJoint") }),
        ("Update", "Update", "AsyncUnit", null, empty),
        ("FixedUpdate", "FixedUpdate", "AsyncUnit", null, empty),
        ("LateUpdate", "LateUpdate", "AsyncUnit", null, empty),
        
        ("ParticleCollision", "OnParticleCollision", "GameObject", null, new []{ ("GameObject", "other") }),
        ("RectTransformDimensionsChange", "OnRectTransformDimensionsChange", "AsyncUnit", null, empty),
        ("RectTransformRemoved", "OnRectTransformRemoved", "AsyncUnit", null, empty),
        ("BeforeTransformParentChanged", "OnBeforeTransformParentChanged", "AsyncUnit", null, empty),
        ("TransformParentChanged", "OnTransformParentChanged", "AsyncUnit", null, empty),
        ("TransformChildrenChanged", "OnTransformChildrenChanged", "AsyncUnit", null, empty),
        ("TriggerEnter2D", "OnTriggerEnter2D", "Collider2D", null, new []{ ("Collider2D", "other") }),
        ("TriggerExit2D", "OnTriggerExit2D", "Collider2D", null, new []{ ("Collider2D", "other") }),
        ("TriggerStay2D", "OnTriggerStay2D", "Collider2D", null, new []{ ("Collider2D", "other") }),
        ("TriggerEnter", "OnTriggerEnter", "Collider", null, new []{ ("Collider", "other") }),
        ("TriggerExit", "OnTriggerExit", "Collider", null, new []{ ("Collider", "other") }),
        ("TriggerStay", "OnTriggerStay", "Collider", null, new []{ ("Collider", "other") }),
        ("BecameInvisible", "OnBecameInvisible", "AsyncUnit", null, empty),
        ("BecameVisible", "OnBecameVisible", "AsyncUnit", null, empty),
        
        // Mouse... #if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
        ("MouseDown", "OnMouseDown", "AsyncUnit", null, empty),
        ("MouseDrag", "OnMouseDrag", "AsyncUnit", null, empty),
        ("MouseEnter", "OnMouseEnter", "AsyncUnit", null, empty),
        ("MouseExit", "OnMouseExit", "AsyncUnit", null, empty),
        ("MouseOver", "OnMouseOver", "AsyncUnit", null, empty),
        ("MouseUp", "OnMouseUp", "AsyncUnit", null, empty),
        ("MouseUpAsButton", "OnMouseUpAsButton", "AsyncUnit", null, empty),
 
        // new in v2
        ("ApplicationFocus", "OnApplicationFocus", "bool", null, new []{("bool", "hasFocus") }),
        ("ApplicationPause", "OnApplicationPause", "bool", null, new []{("bool", "pauseStatus") }),
        ("ApplicationQuit", "OnApplicationQuit", "AsyncUnit", null, empty),
        ("AudioFilterRead", "OnAudioFilterRead", "(float[] data, int channels)", null, new[]{("float[]", "data"), ("int", "channels")}),
        ("ControllerColliderHit", "OnControllerColliderHit", "ControllerColliderHit", null, new[]{("ControllerColliderHit", "hit")}),
        ("DrawGizmos", "OnDrawGizmos", "AsyncUnit", null, empty),
        ("DrawGizmosSelected", "OnDrawGizmosSelected", "AsyncUnit", null, empty),
        ("GUI", "OnGUI", "AsyncUnit", null, empty),
        ("ParticleSystemStopped", "OnParticleSystemStopped", "AsyncUnit", null, empty),
        ("ParticleTrigger", "OnParticleTrigger", "AsyncUnit", null, empty),
        ("PostRender", "OnPostRender", "AsyncUnit", null, empty),
        ("PreCull", "OnPreCull", "AsyncUnit", null, empty),
        ("PreRender", "OnPreRender", "AsyncUnit", null, empty),
        ("RenderImage", "OnRenderImage", "(RenderTexture source, RenderTexture destination)", null, new[]{("RenderTexture", "source"), ("RenderTexture", "destination")}),
        ("RenderObject", "OnRenderObject", "AsyncUnit", null, empty),
        ("ServerInitialized", "OnServerInitialized", "AsyncUnit", null, empty),
        ("Validate", "OnValidate", "AsyncUnit", null, empty),
        ("WillRenderObject", "OnWillRenderObject", "AsyncUnit", null, empty),
        ("Reset", "Reset", "AsyncUnit", null, empty),
 
        // uGUI
        ("BeginDrag", "OnBeginDrag", "PointerEventData", "IBeginDragHandler", new []{ ("PointerEventData", "eventData") }),
        ("Cancel", "OnCancel", "BaseEventData", "ICancelHandler", new []{ ("BaseEventData", "eventData") }),
        ("Deselect", "OnDeselect", "BaseEventData", "IDeselectHandler", new []{ ("BaseEventData", "eventData") }),
        ("Drag", "OnDrag", "PointerEventData", "IDragHandler", new []{ ("PointerEventData", "eventData") }),
        ("Drop", "OnDrop", "PointerEventData", "IDropHandler", new []{ ("PointerEventData", "eventData") }),
        ("EndDrag", "OnEndDrag", "PointerEventData", "IEndDragHandler", new []{ ("PointerEventData", "eventData") }),
        ("InitializePotentialDrag", "OnInitializePotentialDrag", "PointerEventData", "IInitializePotentialDragHandler", new []{ ("PointerEventData", "eventData") }),
        ("Move", "OnMove", "AxisEventData", "IMoveHandler", new []{ ("AxisEventData", "eventData") }),
        ("PointerClick", "OnPointerClick", "PointerEventData", "IPointerClickHandler", new []{ ("PointerEventData", "eventData") }),
        ("PointerDown", "OnPointerDown", "PointerEventData", "IPointerDownHandler", new []{ ("PointerEventData", "eventData") }),
        ("PointerEnter", "OnPointerEnter", "PointerEventData", "IPointerEnterHandler", new []{ ("PointerEventData", "eventData") }),
        ("PointerExit", "OnPointerExit", "PointerEventData", "IPointerExitHandler", new []{ ("PointerEventData", "eventData") }),
        ("PointerUp", "OnPointerUp", "PointerEventData", "IPointerUpHandler", new []{ ("PointerEventData", "eventData") }),
        ("Scroll", "OnScroll", "PointerEventData", "IScrollHandler", new []{ ("PointerEventData", "eventData") }),
        ("Select", "OnSelect", "BaseEventData", "ISelectHandler", new []{ ("BaseEventData", "eventData") }),
        ("Submit", "OnSubmit", "BaseEventData", "ISubmitHandler", new []{ ("BaseEventData", "eventData") }),
        ("UpdateSelected", "OnUpdateSelected", "BaseEventData", "IUpdateSelectedHandler", new []{ ("BaseEventData", "eventData") }),
 
        // 2019.3
        ("ParticleUpdateJobScheduled", "OnParticleUpdateJobScheduled", "UnityEngine.ParticleSystemJobs.ParticleSystemJobData", null, new[]{("UnityEngine.ParticleSystemJobs.ParticleSystemJobData", "particles")}),
 
        // Oneshot
        // Awake, Start, Destroy
    };
 
    triggers = triggers.OrderBy(x => x.handlerInterface != null).ThenBy(x => x.handlerInterface != null ? x.handlerInterface : x.methodName).ToArray();
 
    Func<string, string> ToInterfaceName = x => $"IAsync{x}Handler";
    Func<string, string> ToUniTaskName = x => x == "AsyncUnit" ? "UniTask" : $"UniTask<{x}>";
    Func<string, string> ToCastUniTasSourceType = x => x == "AsyncUnit" ? "IUniTaskSource" : $"IUniTaskSource<{x}>";
    Func<string, string> OnInvokeSuffix = x => x == "AsyncUnit" ? ".AsUniTask()" : $"";
    Func<(string argType, string argName)[], string> BuildMethodArgument = x => string.Join(", ", x.Select(y => y.argType + " " + y.argName));
    Func<(string argType, string argName)[], string> BuildResultParameter = x => x.Length == 0 ? "AsyncUnit.Default" : "(" + string.Join(", ", x.Select(y => y.argName)) + ")";
 
    Func<string, bool> IsParticleSystem = x => x == "ParticleUpdateJobScheduled";
    Func<string, bool> IsMouseTrigger = x => x.StartsWith("Mouse");
    Func<string, string> RequirePhysicsModule = x => (x.StartsWith("Collision") || x.StartsWith("Collider") || x.StartsWith("ControllerCollider") || x.StartsWith("Joint") || x.StartsWith("Trigger"))
        ? (x.Contains("2D") ? "UNITASK_PHYSICS2D_SUPPORT" : "UNITASK_PHYSICS_SUPPORT") 
        : null;
    Func<string, bool> IsUguiSystem = x => x != null;
#>
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
 
using System.Threading;
using UnityEngine;
#if !UNITY_2019_1_OR_NEWER || UNITASK_UGUI_SUPPORT
using UnityEngine.EventSystems;
#endif
 
namespace Cysharp.Threading.Tasks.Triggers
{
<# foreach(var t in triggers) { #>
#region <#= t.triggerName #>
<# if(IsUguiSystem(t.handlerInterface)) { #>
#if !UNITY_2019_1_OR_NEWER || UNITASK_UGUI_SUPPORT
<# } #>
<# if(IsParticleSystem(t.triggerName)) { #>
#if UNITY_2019_3_OR_NEWER && (!UNITY_2019_1_OR_NEWER || UNITASK_PARTICLESYSTEM_SUPPORT)
<# } #>
<# if(IsMouseTrigger(t.triggerName)) { #>
#if !(UNITY_IPHONE || UNITY_ANDROID || UNITY_METRO)
<# } #>
<# if(RequirePhysicsModule(t.triggerName) != null) { #>
#if !UNITY_2019_1_OR_NEWER || <#= RequirePhysicsModule(t.triggerName) #>
<# } #>
 
    public interface <#= ToInterfaceName(t.methodName) #>
    {
        <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async();
    }
 
    public partial class AsyncTriggerHandler<T> : <#= ToInterfaceName(t.methodName) #>
    {
        <#= ToUniTaskName(t.returnType) #> <#= ToInterfaceName(t.methodName) #>.<#= t.methodName #>Async()
        {
            core.Reset();
            return new <#= ToUniTaskName(t.returnType) #>((<#= ToCastUniTasSourceType(t.returnType) #>)(object)this, core.Version);
        }
    }
 
    public static partial class AsyncTriggerExtensions
    {
        public static Async<#= t.triggerName #>Trigger GetAsync<#= t.triggerName #>Trigger(this GameObject gameObject)
        {
            return GetOrAddComponent<Async<#= t.triggerName #>Trigger>(gameObject);
        }
        
        public static Async<#= t.triggerName #>Trigger GetAsync<#= t.triggerName #>Trigger(this Component component)
        {
            return component.gameObject.GetAsync<#= t.triggerName #>Trigger();
        }
    }
 
    [DisallowMultipleComponent]
    public sealed class Async<#= t.triggerName #>Trigger : AsyncTriggerBase<<#= t.returnType #>><#= (t.handlerInterface == null) ? "" : $", {t.handlerInterface}" #>
    {
        void <#= (t.handlerInterface == null) ? "" : $"{t.handlerInterface}." #><#= t.methodName #>(<#= BuildMethodArgument(t.arguments) #>)
        {
            RaiseEvent(<#= BuildResultParameter(t.arguments) #>);
        }
 
        public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler()
        {
            return new AsyncTriggerHandler<<#= t.returnType #>>(this, false);
        }
 
        public <#= ToInterfaceName(t.methodName) #> Get<#= t.methodName #>AsyncHandler(CancellationToken cancellationToken)
        {
            return new AsyncTriggerHandler<<#= t.returnType #>>(this, cancellationToken, false);
        }
 
        public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async()
        {
            return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(this, true)).<#= t.methodName #>Async();
        }
 
        public <#= ToUniTaskName(t.returnType) #> <#= t.methodName #>Async(CancellationToken cancellationToken)
        {
            return ((<#= ToInterfaceName(t.methodName) #>)new AsyncTriggerHandler<<#= t.returnType #>>(this, cancellationToken, true)).<#= t.methodName #>Async();
        }
    }
<# if(IsUguiSystem(t.handlerInterface)) { #>
#endif
<# } #>
<# if(RequirePhysicsModule(t.triggerName) != null) { #>
#endif
<# } #>
<# if(IsParticleSystem(t.triggerName) || IsMouseTrigger(t.triggerName)) { #>
#endif
<# } #>
#endregion
 
<# } #>
}