void OnSelectionChanged() { if (Application.isPlaying) { return; } if (!_enableAutoBibaCanvasGroupActivation) { return; } if (Selection.activeGameObject) { BibaCanvasGroup selected = lookForBibaCanvasGroup(Selection.activeGameObject); if (selected) { DeactivateLastGroup(); selected.canvasGroup.alpha = 1f; selected.canvasGroup.interactable = true; lastGroup = selected; } else { DeactivateLastGroup(); } } TryToGetCanvasGroupFromAnimatorState(); }
void TryToGetCanvasGroupFromAnimatorState() { try { AnimatorState state = (AnimatorState)Selection.activeObject; if (!state) { return; } foreach (StateMachineBehaviour behaviour in state.behaviours) { BibaGameState bibaState = behaviour as BibaGameState; if (bibaState) { BibaCanvasGroup[] bibaCanvasGroups = ((BibaGameView)target).gameObject.GetComponentsInChildren <BibaCanvasGroup>(true); foreach (BibaCanvasGroup canvasGroup in bibaCanvasGroups) { if (canvasGroup.currentState == bibaState.currentState) { DeactivateLastGroup(); canvasGroup.canvasGroup.alpha = 1f; canvasGroup.canvasGroup.interactable = true; lastGroup = canvasGroup; return; } } break; } } } catch { } }
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // Add state dependent functionality here: switch (currentState) { default: break; } if (currentCanvasGroup != null) { previousCanvasGroup = currentCanvasGroup; previousCanvasGroup.canvasGroup.FadeAlphaTo(0f, currentCanvasGroup.exitFadeDuration, currentCanvasGroup.exitDelay, DisablePreviousCanvasGroup); previousCanvasGroup.canvasGroup.EnableInteraction(false); } }
//OnStateEnter is called when a transition starts and the state machine starts to evaluate this state override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) { // Get reference to RelayGameLogic only if needed if (logic == null) { logic = animator.GetComponent <BibaGameView> (); } logic.currentGameState = currentState; // Get the Canvas Group bound to the current RelayGameState, else throw a warning. if (logic.statesToBibaCanvasGroups.ContainsKey(currentState)) { currentCanvasGroup = logic.statesToBibaCanvasGroups [currentState]; } else { Debug.LogError("Key not found in GameLogic Dictionary."); } // Add state dependent functionality here: switch (currentState) { default: break; } if (currentCanvasGroup != null) { currentCanvasGroup.gameObject.SetActive(true); currentCanvasGroup.canvasGroup.FadeAlphaTo(1f, currentCanvasGroup.entryFadeDuration, currentCanvasGroup.entryDelay); currentCanvasGroup.canvasGroup.EnableInteraction(true); logic.statesToBibaCanvasGroups [currentState].CanvasGroupIsActive(); } else { Debug.LogError("Canvas Group is null"); } }
/// <summary> /// Looks for Biba Canvas Group. /// </summary> /// <returns>The first Biba Canvas Group found. NULL if parent tree contains no Biba Canvas Groups. </returns> /// <param name="obj">Object which or which any parent may contain a Biba Canvas Group.</param> BibaCanvasGroup lookForBibaCanvasGroup(GameObject obj) { if (!obj) { return(null); } BibaCanvasGroup onObject = obj.GetComponent <BibaCanvasGroup> (); if (onObject) { return(onObject); } else { if (obj.transform.parent) { return(lookForBibaCanvasGroup(obj.transform.parent.gameObject)); } else { return(null); } } }