static void OnDispose(object r, Delegate f) { var raiser = SafeCast.As <EventRaiser <T> >(r); var func = SafeCast.As <Action <T> >(f); raiser.Unsubscribe(func); }
public static bool TryGetArray4Fast([MaybeNullWhen(false)] out object?[] instance) { // If the exclusion control is successfully obtained, I try to get the instance from the pool. if (_lock.TryEnter() == false) { instance = null; return(false); } try { instance = _root; if (instance is not null) { Debug.Assert(_pooledCount > 0); Debug.Assert(instance.Length == LengthOfPoolTargetArray); _pooledCount--; _root = SafeCast.As <object?[]>(MemoryMarshal.GetArrayDataReference(instance)); // _root = (object?[])instance[0]; MemoryMarshal.GetArrayDataReference(instance) = null; // instance[0] = null; return(true); } return(false); } finally { _lock.Exit(); } }
private static UniTask StartPrivate <TParent, TState>(TParent parent, TState state, Delegate coroutine, FrameTiming timing) where TParent : class { if (typeof(TParent) == typeof(IHostScreen)) { var parentScreen = SafeCast.As <IHostScreen>(parent); if (parentScreen.IsRunning == false) { ThrowParentNotAlive(); return(UniTask.CompletedTask); } else { return(StartCoroutine(new CoroutineState(parentScreen), state, coroutine, null, timing)); } } else if (typeof(TParent) == typeof(FrameObject)) { var parentFrameObject = SafeCast.As <FrameObject>(parent); if (parentFrameObject.LifeState.IsBefore(LifeState.Alive)) { ThrowParentNotAlive(); return(UniTask.CompletedTask); } else { return(StartCoroutine(new CoroutineState(parentFrameObject), state, coroutine, null, timing)); } } else { Debug.Fail("Something wrong"); return(UniTask.CompletedTask); } }
private static void StartOrReservePrivate <TParent, TState>(TParent parent, TState state, Delegate coroutine, Action <Exception>?onCatch, FrameTiming timing) where TParent : class { if (typeof(TParent) == typeof(IHostScreen)) { var parentScreen = SafeCast.As <IHostScreen>(parent); if (parentScreen.IsRunning == false) { ReserveCoroutine(parentScreen, state, coroutine, onCatch, timing); } else { StartCoroutine(new CoroutineState(parentScreen), state, coroutine, onCatch, timing).Forget(); } } else if (typeof(TParent) == typeof(FrameObject)) { var parentFrameObject = SafeCast.As <FrameObject>(parent); if (parentFrameObject.LifeState.IsBefore(LifeState.Alive)) { ReserveCoroutine(parentFrameObject, state, coroutine, null, timing); } else { StartCoroutine(new CoroutineState(parentFrameObject), state, coroutine, null, timing).Forget(); } } else { Debug.Fail("Something wrong"); } }
public UIRenderable(Control control) { Debug.Assert(control is not null); _control = control; IsFrozen = true; // disable calling update method per frame HasShadow = false; Activating.Subscribe((f, ct) => SafeCast.As <UIRenderable>(f).OnActivating()); }
protected override ContentAreaInfo MesureContentArea(Control parent, Control target) { var grid = SafeCast.As <Grid>(parent); var padding = grid.Padding; var gridContentsSize = grid.ActualSize - new Vector2(padding.Left + padding.Right, padding.Top + padding.Bottom); var col = grid.GetColumnOf(target); var row = grid.GetRowOf(target); var(cellSize, cellPos) = grid.GetCellSizePos(gridContentsSize, col, row); return(new ContentAreaInfo(cellPos, cellSize, LayoutThickness.Zero)); }
private static async UniTask StartCoroutine <TState>(CoroutineState coroutineState, TState state, Delegate coroutine, Action <Exception>?onCatch, FrameTiming timing) { var fo = coroutineState.FrameObject; if (fo is null) { if (coroutineState.Screen.IsRunning == false) { return; } } else { Debug.Assert(fo.LifeState.IsSameOrAfter(LifeState.Alive)); if (fo.LifeState == LifeState.Dead) { return; } } try { await coroutineState.TimingOf(timing).Next(); if (typeof(TState) == typeof(DummyState)) { var noStateCoroutine = SafeCast.As <Func <CoroutineState, UniTask> >(coroutine); await noStateCoroutine(coroutineState); } else { var statefulCoroutine = SafeCast.As <Func <CoroutineState, TState, UniTask> >(coroutine); await statefulCoroutine(coroutineState, state); } } catch (Exception ex) { if (onCatch != null) { onCatch.Invoke(ex); } else { if (EngineSetting.UserCodeExceptionCatchMode == UserCodeExceptionCatchMode.Throw) { throw; } } } }
public static bool TryGetArray4([MaybeNullWhen(false)] out object?[] instance) { _lock.Enter(); try { instance = _root; if (instance is not null) { Debug.Assert(_pooledCount > 0); Debug.Assert(instance.Length == LengthOfPoolTargetArray); _pooledCount--; _root = SafeCast.As <object?[]>(MemoryMarshal.GetArrayDataReference(instance)); // _root = (object?[])instance[0]; MemoryMarshal.GetArrayDataReference(instance) = null; // instance[0] = null; return(true); } return(false); } finally { _lock.Exit(); } }
public SkyBox() { Activating.Subscribe((f, ct) => SafeCast.As <SkyBox>(f).OnActivating()); }
public SkySphere() { Activating.Subscribe((f, ct) => SafeCast.As <SkySphere>(f).OnActivating()); }
public DeferredRenderingLayer(int sortNumber = DRLayerDefaultSort) : base(sortNumber) { _gBuffer = new GBuffer(); _postProcess = new PbrDeferredRenderingPostProcess(this, static screen => ref screen.Camera.View); Activating.Subscribe((l, ct) => SafeCast.As <DeferredRenderingLayer>(l).OnActivating()); }
public bool TryGetUILayer([MaybeNullWhen(false)] out UILayer layer) { layer = SafeCast.As <UILayer>(Layer); return(layer is not null); }
public Cube() { Activating.Subscribe((f, ct) => SafeCast.As <Cube>(f).OnActivating()); }
private static void ReserveCoroutine <TParent, TState>(TParent parent, TState state, Delegate coroutine, Action <Exception>?onCatch, FrameTiming timing) where TParent : class { if (typeof(TParent) == typeof(IHostScreen)) { var parentScreen = SafeCast.As <IHostScreen>(parent); if (typeof(TState) == typeof(DummyState)) { if (onCatch is null) { // [capture] coroutine, timing parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), DummyState.Null, coroutine, null, timing).Forget(); } else { // [capture] coroutine, onCatch, timing parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), DummyState.Null, coroutine, onCatch, timing).Forget(); } return; } else { if (onCatch is null) { // [capture] state, coroutine, timing parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), state, coroutine, null, timing).Forget(); } else { // [capture] state, coroutine, onCatch, timing parentScreen.Initialized += p => StartCoroutine(new CoroutineState(p), state, coroutine, onCatch, timing).Forget(); } return; } } else if (typeof(TParent) == typeof(FrameObject)) { var parentFrameObject = SafeCast.As <FrameObject>(parent); if (typeof(TState) == typeof(DummyState)) { if (onCatch is null) { // [capture] coroutine, timing parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), DummyState.Null, coroutine, null, timing).Forget(); } else { // [capture] coroutine, onCatch, timing parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), DummyState.Null, coroutine, onCatch, timing).Forget(); } return; } else { if (onCatch is null) { // [capture] state, coroutine, timing parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), state, coroutine, null, timing).Forget(); } else { // [capture] state, coroutine, onCatch, timing parentFrameObject.Alive += f => StartCoroutine(new CoroutineState(f), state, coroutine, onCatch, timing).Forget(); } return; } } else { Debug.Fail("Something wrong"); return; } }