public static void CreateExpansionLayoutScreen() { GameObject gameObject = new GameObject("LayoutElementScreen"); RectTransform rectTransform = CreateRectTransform(gameObject, Selection.activeTransform); UiLayoutElementScreen element = gameObject.AddComponent <UiLayoutElementScreen>(); UiAnimationClip animationShow = new UiAnimationClip { Name = "Screen Show Animation", PlayOnLayoutElementShow = true }; UiAnimationClip animationHide = new UiAnimationClip { Name = "Screen Hide Animation", PlayOnLayoutElementHide = true }; UiAnimation animation = gameObject.AddComponent <UiAnimation>(); animation.AnimationClips = new System.Collections.Generic.List <UiAnimationClip> { animationShow, animationHide }; element.AnimationShow = animationShow.Name; element.AnimationHide = animationHide.Name; Selection.activeObject = gameObject; }
/// <summary> /// Sets and shows the active screen and hides previous active screen. /// </summary> /// <param name="screen">Target screen</param> /// <param name="transitionOffset"> /// Normalized time of current screen's hide duration that the target screen will wait before start to showing. /// For example, a value of 0.5 would mean the target screen will begin showing at 50% of the current screen hide animation time. /// </param> public static void SetActiveScreen(UiLayoutElementScreen screen, float transitionOffset = .5f) { if (_activeTransition != null) { return; } _activeTransition = new UiLayoutTransition ( ActiveScreen, screen, transitionOffset ); _activeTransition.OnHide += () => { ActiveScreen = screen; _activeTransition = null; }; _activeTransition.OnComplete += () => { ActiveScreen = screen; _activeTransition = null; }; _activeTransition.Start(); }
/// <summary> /// Immediately sets the active screen without playing any hide and show animations. /// </summary> /// <param name="screen">Target screen</param> public static void SetActiveScreenImmediately(UiLayoutElementScreen screen) { if (ActiveScreen != null) { ActiveScreen.HideImmediately(); } ActiveScreen = screen; if (ActiveScreen != null) { ActiveScreen.ShowImmediately(); } }
/// <summary> /// Loads and instantiates UiLayoutElementScreen stored at path in a Resources folder. /// Throws exception if screen with specified path was instantiated before. /// </summary> /// <param name="path">Prefab path in a Resources folder</param> /// <param name="parent">Parent RectTransform</param> /// <returns>Instance of UiLayoutElementScreen</returns> public static UiLayoutElementScreen CreateScreen(string path, RectTransform parent = null) { if (GetElement(path) != null) { throw new Exception("Screen " + path + " is already instantiated. Use UiLayout.FindScreen to get the instance."); } UiLayoutElementScreen screen = UiObject.Instantiate <UiLayoutElementScreen> ( path, GetFirstNotContainer(parent, DefaultContainer) ); AddElement(path, screen); return(screen); }