namespace UnityEngine.UI.CoroutineTween { // Base interface for tweeners, // using an interface instead of // an abstract class as we want the // tweens to be structs. internal interface ITweenValue { // ... }
// Color tween class, receives the // TweenValue callback and then sets // the value on the target. internal struct ColorTween : ITweenValue { // ... }
// Float tween class, receives the // TweenValue callback and then sets // the value on the target. internal struct FloatTween : ITweenValue { // ... }
// Tween runner, executes the given tween. // The coroutine will live within the given // behaviour container. internal class TweenRunner<T> where T : struct, ITweenValue { // ... } }
public T Get() { T element; if (m_Stack.Count == 0) { element = new T(); countAll++; } else { element = m_Stack.Pop(); } if (m_ActionOnGet != null) m_ActionOnGet(element); return element; }
public void Release(T element) { if (m_Stack.Count > 0 && ReferenceEquals(m_Stack.Peek(), element)) Debug.LogError("Internal error. Trying to destroy object that is already released to pool."); if (m_ActionOnRelease != null) m_ActionOnRelease(element); m_Stack.Push(element); }
internal class ReflectionMethodsCache { public delegate bool Raycast3DCallback (Ray r, out RaycastHit hit, float f, int i); public Raycast3DCallback raycast3D = null;
// ...
public ReflectionMethodsCache() { var raycast3DMethodInfo = typeof(Physics).GetMethod("Raycast", new[] {typeof(Ray), typeof(RaycastHit).MakeByRefType(), typeof(float), typeof(int)}); if (raycast3DMethodInfo != null) raycast3D = (Raycast3DCallback)UnityEngineInternal.ScriptingUtils.CreateDelegate(typeof(Raycast3DCallback), raycast3DMethodInfo); // ...
}
// ...
}
在GraphicRaycaster中可以看到其使用方法如下:
1 2 3 4 5 6
if (ReflectionMethodsCache.Singleton.raycast3D != null) { RaycastHit hit; if (ReflectionMethodsCache.Singleton.raycast3D(ray, out hit, dist, m_BlockingMask)) hitDistance = hit.distance; }