/// Recurses through Transform.parent to find the GameObject to which ContextView is attached /// Has a loop limit of 100 levels. /// By default, raises an Exception if no Context is found. virtual protected void bubbleToContext(MonoBehaviour view, BubbleType type, bool finalTry) { IContext context = Bootstrapper.Instance?.context; if (context == null) { if (finalTry) { Debug.LogError("Context is null"); } return; } switch (type) { case BubbleType.Add: context.AddView(view); registeredWithContext = true; break; case BubbleType.Remove: context.RemoveView(view); break; default: break; } }
/// Recurses through Transform.parent to find the GameObject to which ContextView is attached /// Has a loop limit of 100 levels. /// By default, raises an Exception if no Context is found. virtual protected void bubbleToContext(MonoBehaviour view, bool toAdd, bool finalTry) { /* * if (toAdd && registeredWithContext) * { * Debug.LogWarning("Already registered:" + view.name, view); * return; * }*/ const int LOOP_MAX = 100; int loopLimiter = 0; Transform trans = view.gameObject.transform; while (trans.parent != null && loopLimiter < LOOP_MAX) { loopLimiter++; trans = trans.parent; if (trans.gameObject.GetComponent <SimpleBootstrap>() != null) { SimpleBootstrap contextView = trans.gameObject.GetComponent <SimpleBootstrap>() as SimpleBootstrap; if (contextView.context != null) { BindToContext(contextView.SimpleContext); IContext context = contextView.context; if (toAdd) { context.AddView(view); registeredWithContext = true; } else { context.RemoveView(view); } return; } } } if (requiresContext && finalTry) { //last ditch. If there's a Context anywhere, we'll use it! if (SimpleContext.Context != null) { BindToContext(SimpleContext.Context); SimpleContext.Context.AddView(view); registeredWithContext = true; return; } string msg = (loopLimiter == LOOP_MAX) ? msg = "A view couldn't find a context. Loop limit reached." : msg = "A view was added with no context. Views must be added into the hierarchy of their ContextView lest all hell break loose."; msg += "\nView: " + view.ToString(); throw new MediationException(msg, MediationExceptionType.NO_CONTEXT); } }
protected override void Execute() { CameraContainerView cameraContainerView = CameraContainerView.Instance; if (cameraContainerView == null) { Debug.LogWarning("No CameraContainerView found."); } context.AddView(cameraContainerView); }
private void OnLoaded() { sceneStatus.currentScene = sceneStatus.sceneToLoad; viewContainerStatus.ViewContainer = Object.FindObjectOfType <ViewContainer>(); if (viewContainerStatus.ViewContainer != null) { context.AddView(viewContainerStatus.ViewContainer); } Release(); }
protected override void Execute() { View view = playerStatus.Player.GetComponent <T>(); if (view == null) { Debug.LogWarning("A view in " + (context as Context) + " is null"); Abort(); return; } context.AddView(view, false); }
/// Recurses through Transform.parent to find the GameObject to which ContextView is attached /// Has a loop limit of 100 levels. /// By default, raises an Exception if no Context is found. virtual protected void bubbleToContext(MonoBehaviour view, bool toAdd, bool finalTry) { const int LOOP_MAX = 100; int loopLimiter = 0; Transform trans = view.gameObject.transform; while (trans.parent != null && loopLimiter < LOOP_MAX) { loopLimiter++; trans = trans.parent; if (trans.gameObject.GetComponent <ContextView>() != null) { ContextView contextView = trans.gameObject.GetComponent <ContextView>() as ContextView; if (contextView.context != null) { IContext context = contextView.context; if (toAdd) { context.AddView(view); registeredWithContext = true; return; } else { context.RemoveView(view); return; } } } } if (requiresContext && finalTry) { //last ditch. If there's a Context anywhere, we'll use it! if (Context.firstContext != null) { Context.firstContext.AddView(view); registeredWithContext = true; return; } } if (requiresContext && !finalTry && !toAdd) { //last ditch. If there's a Context anywhere, we'll use it! if (Context.firstContext != null) { Context.firstContext.RemoveView(view); return; } } }
public void AddStatusView <T>() where T : View { string name = typeof(T).ToString(); GameObject gameObjectStatusViewGameObject = new GameObject() { name = name, }; gameObjectStatusViewGameObject.transform.SetParent(transform); T statusView = gameObjectStatusViewGameObject.AddComponent <T>(); statusViewsByKey.Add(name, statusView); context.AddView(statusView); }
protected void AddViewToContext(MonoBehaviour view, bool toAdd, ContextView contextView) { if (contextView.context != null) { IContext context = contextView.context; if (toAdd) { context.AddView(view); registeredWithContext = true; return; } else { context.RemoveView(view); return; } } }
/// Recurses through Transform.parent to find the GameObject to which ContextView is attached /// Has a loop limit of 100 levels. /// By default, raises an Exception if no Context is found. virtual protected void bubbleToContext(MonoBehaviour view, bool toAdd, bool finalTry) { const int LOOP_MAX = 100; int loopLimiter = 0; Transform trans = view.gameObject.transform; while (trans.parent != null && loopLimiter < LOOP_MAX) { loopLimiter++; trans = trans.parent; if (trans.gameObject.GetComponent <ContextView>() != null) { ContextView contextView = trans.gameObject.GetComponent <ContextView>() as ContextView; if (contextView.context != null) { IContext context = contextView.context; if (toAdd) { context.AddView(view); registeredWithContext = true; return; } else { context.RemoveView(view); return; } } } } if (requiresContext && finalTry) { string msg = (loopLimiter == LOOP_MAX) ? "A view couldn't find a context. Loop limit reached." : "A view was added with no context. Views must be added into the hierarchy of their ContextView lest all hell break loose."; msg += "\nView: " + view; Debug.LogWarning(msg); } }
private void AddCollisionHitDetectionView() { CollisionHitDetectionView collisionHitDetectionView = gameObject.AddComponent <CollisionHitDetectionView>(); context.AddView(collisionHitDetectionView, false); }
/// Recurses through Transform.parent to find the GameObject to which ContextView is attached /// Has a loop limit of 100 levels. /// By default, raises an Exception if no Context is found. virtual protected void bubbleToContext(MonoBehaviour view, BubbleType type, bool finalTry) { const int LOOP_MAX = 100; int loopLimiter = 0; Transform trans = view.gameObject.transform; while (trans.parent != null && loopLimiter < LOOP_MAX) { loopLimiter++; trans = trans.parent; if (trans.gameObject.GetComponent <ContextView>() != null) { ContextView contextView = trans.gameObject.GetComponent <ContextView>() as ContextView; if (contextView.context != null) { IContext context = contextView.context; bool success = true; switch (type) { case BubbleType.Add: context.AddView(view); registeredWithContext = true; break; case BubbleType.Remove: context.RemoveView(view); break; case BubbleType.Enable: context.EnableView(view); break; case BubbleType.Disable: context.DisableView(view); break; default: success = false; break; } if (success) { return; } } } } if (requiresContext && finalTry && type == BubbleType.Add) { //last ditch. If there's a Context anywhere, we'll use it! if (Context.firstContext != null) { Context.firstContext.AddView(view); registeredWithContext = true; return; } string msg = (loopLimiter == LOOP_MAX) ? msg = "A view couldn't find a context. Loop limit reached." : msg = "A view was added with no context. Views must be added into the hierarchy of their ContextView lest all hell break loose."; msg += "\nView: " + view.ToString(); throw new MediationException(msg, MediationExceptionType.NO_CONTEXT); } }