IEnumerator FadeIn(UIBehaviour thingToFade) { yield return null; yield return null; yield return null; yield return null; float timer = 0; if (thingToFade.GetComponent<Text>() != null) { while (timer <= FadeTimer) { Color textColor = thingToFade.GetComponent<Text>().color; textColor = new Color(textColor.r, textColor.g, textColor.b, timer / FadeTimer); thingToFade.GetComponent<Text>().color = textColor; timer += Time.deltaTime; yield return null; } } else if (thingToFade.GetComponent<Image>() != null) { while (timer <= FadeTimer) { Color imgColor = thingToFade.GetComponent<Image>().color; imgColor = new Color(imgColor.r, imgColor.g, imgColor.b, timer / FadeTimer); thingToFade.GetComponent<Image>().color = imgColor; timer += Time.deltaTime; yield return null; } } yield return null; }
public static void Unselect(UIBehaviour ui, int skipFrames = 0) { IndependentSelectable selectable = ui.GetComponent <IndependentSelectable>(); if (selectable != null) { selectable.m_unselect = true; selectable.m_selectOnEventSystemLateUpdate = 1 + skipFrames; } }
public static IndependentEventSystem GetEventSystem(UIBehaviour ui) { IndependentSelectable selectable = ui.GetComponent <IndependentSelectable>(); if (selectable != null) { return(selectable.EventSystem); } return(null); }
public static void RemoveAllListeners(this UIBehaviour uiBehaviour, EventTriggerType eventID) { var eventTrigger = uiBehaviour.GetComponent <EventTrigger>(); if (eventTrigger == null) { return; } eventTrigger.triggers.RemoveAll(listener => listener.eventID == eventID); }
public static void AddListener(this UIBehaviour uiBehaviour, EventTriggerType eventID, UnityAction <BaseEventData> callback) { var entry = new EventTrigger.Entry(); entry.eventID = eventID; entry.callback.AddListener(callback); var eventTriggers = (uiBehaviour.GetComponent <EventTrigger>() ?? uiBehaviour.gameObject.AddComponent <EventTrigger>()).triggers; eventTriggers.Add(entry); }
public static CanvasGroup CreateCanvasGroup(this UIBehaviour uiObject) { var group = uiObject.GetComponent <CanvasGroup>(); if (group == null) { group = uiObject.gameObject.AddComponent <CanvasGroup>(); } group.ignoreParentGroups = false; return(group); }
//public Transform GetLayerTransform(E_UILayer layer) //{ // switch (layer) // { // case E_UILayer.Bot: // return mMainBot; // case E_UILayer.Mid: // return mMainMid; // case E_UILayer.Top: // return mMainTop; // case E_UILayer.System: // return mMainSystem; // default: // return null; // } //} /// <summary> /// add a event listener on a ui component /// </summary> /// <param name="control">ui component</param> /// <param name="type">event type</param> /// <param name="callBackAction">call back function</param> public static void AddCustomEventListener(UIBehaviour control, EventTriggerType type, UnityAction <BaseEventData> callBackAction) { EventTrigger trigger = control.GetComponent <EventTrigger>(); if (trigger == null) { trigger = control.gameObject.AddComponent <EventTrigger>(); } EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = type; entry.callback.AddListener(callBackAction); trigger.triggers.Add(entry); }
public static void AddOnPointerDown(this UIBehaviour uiBehaviour, System.Action Action) { EventTrigger trigger = uiBehaviour.GetComponent <EventTrigger>(); if (trigger == null) { trigger = uiBehaviour.gameObject.AddComponent <EventTrigger>(); } var pointerDown = new EventTrigger.Entry(); pointerDown.eventID = EventTriggerType.PointerDown; pointerDown.callback.AddListener((BaseEventData e) => { Action(); }); trigger.triggers.Add(pointerDown); }
/// <summary> /// 鼠标离开 /// </summary> /// <param name="ui"></param> /// <param name="action">回调事件</param> public static void OnMouseExit(this UIBehaviour ui, Action action) { //获取EventTrigger如果没有就添加一个 EventTrigger trigger; trigger = ui.GetComponent <EventTrigger>(); if (trigger == null) { trigger = ui.gameObject.AddComponent <EventTrigger>(); } //添加进入事件 EventTrigger.Entry entry = new EventTrigger.Entry(); entry.eventID = EventTriggerType.PointerExit; entry.callback = new EventTrigger.TriggerEvent(); //将回调的Action添加 entry.callback.AddListener(e => action()); //添加进EventTrigger trigger.triggers.Add(entry); }
//change button visuals private void SetButtonVisuals() { switch (currentSelectionState) { case ButtonState.Disabled: GetComponent <Image>().color = disabledTint; if (child.GetComponent <Text>()) { child.GetComponent <Text>().color = childDisabledTint; } else { child.GetComponent <Image>().color = childDisabledTint; } break; case ButtonState.Highlighted: GetComponent <Image>().color = highlightedTint; if (child.GetComponent <Text>()) { child.GetComponent <Text>().color = childHighlightedTint; } else { child.GetComponent <Image>().color = childHighlightedTint; } break; case ButtonState.Normal: GetComponent <Image>().color = normalTint; if (child.GetComponent <Text>()) { child.GetComponent <Text>().color = childNormalTint; } else { child.GetComponent <Image>().color = childNormalTint; } break; case ButtonState.Pressed: GetComponent <Image>().color = pressedTint; if (child.GetComponent <Text>()) { child.GetComponent <Text>().color = childPressedTint; } else { child.GetComponent <Image>().color = childPressedTint; } break; } }
/// <summary> /// 注册UI控件响应或被响应事件 /// </summary> /// <param name="uiControlsName">UI控件名称</param> /// <param name="uIBehaviour">UI控件</param> internal override void RegisterUIControlEvent(string uiControlsName, UIBehaviour uIBehaviour) { switch (uiControlsName) { case "Last": uIBehaviour.OnButtonClick(new UnityEngine.Events.UnityAction(() => Controller.SongControl.PlayLastSong())); break; case "PlayOrPause": uIBehaviour.OnButtonClick(new UnityEngine.Events.UnityAction(() => Controller.SongControl.PlayOrPauseSong())); break; case "Next": uIBehaviour.OnButtonClick(new UnityEngine.Events.UnityAction(() => Controller.SongControl.PlayNextSong())); break; case "LyricOrList": break; case "SongTimeSlider": uIBehaviour.OnEventTrigger(UnityEngine.EventSystems.EventTriggerType.Drag, new UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData>((baseEvent) => { Controller.SongControl.ChangeSongTime(uIBehaviour.GetComponent <UnityEngine.UI.Slider>().value); })); break; case "PlayType": uIBehaviour.OnButtonClick(new UnityEngine.Events.UnityAction(() => { if (UIManager.Instance.IsOpenPanel("SongTypePanel")) { UIManager.Instance.ClosePanel("SongTypePanel"); } else { UIManager.Instance.OpenPanel("SongTypePanel"); } })); break; case "Volume": uIBehaviour.OnEventTrigger(UnityEngine.EventSystems.EventTriggerType.PointerEnter, new UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData>((baseEvent) => { UIManager.Instance.OpenPanel("VolumePanel"); if (UIManager.Instance.IsOpenPanel("SongTypePanel")) { UIManager.Instance.ClosePanel("SongTypePanel"); } })); uIBehaviour.OnEventTrigger(UnityEngine.EventSystems.EventTriggerType.PointerExit, new UnityEngine.Events.UnityAction <UnityEngine.EventSystems.BaseEventData>((baseEvent) => { UIManager.Instance.ClosePanel("VolumePanel"); })); break; case "SongList": { uIBehaviour.OnButtonClick(new UnityEngine.Events.UnityAction(() => { if (UIManager.Instance.IsOpenPanel("SongListPanel")) { UIManager.Instance.ClosePanel("SongListPanel"); } else { UIManager.Instance.OpenPanel("SongListPanel"); } })); } break; default: break; } }
public GameSection CreateSection(GameSceneTables.SectionData section_data, LoadObject[] use_objects) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) //IL_0123: Unknown result type (might be due to invalid IL or missing references) //IL_0128: Expected O, but got Unknown GameSection gameSection = null; HierarchyData last = GetLast(); Transform parent = (last != null) ? last.section._transform : MonoBehaviourSingleton <UIManager> .I.uiCamera.get_transform(); if (section_data.type == GAME_SECTION_TYPE.COMMON_DIALOG) { gameSection = (Utility.CreateGameObjectAndComponent(section_data.typeParams[0], parent, 5) as GameSection); gameSection.baseDepth = GetPrefabUIDepth(section_data.type); gameSection.set_name(section_data.sectionName); parent = gameSection._transform; } int i = 0; for (int num = use_objects.Length; i < num; i++) { LoadObject loadObject = use_objects[i]; if (loadObject != null) { GameObject val = loadObject.loadedObject as GameObject; if (val != null) { if (val.GetComponent <UIVirtualScreen>() != null) { Type type = null; if (gameSection == null) { type = Type.GetType(section_data.sectionName); } UIBehaviour uIBehaviour = UIManager.CreatePrefabUI(val, loadObject.PopInstantiatedGameObject(), type, false, parent, GetPrefabUIDepth(section_data.type), section_data); if (gameSection == null && section_data.type == GAME_SECTION_TYPE.COMMON_DIALOG) { gameSection = (uIBehaviour.get_gameObject().AddComponent(Type.GetType(section_data.typeParams[0])) as GameSection); parent = gameSection._transform; } else if (gameSection == null && type != null) { gameSection = (uIBehaviour.GetComponent <UIBehaviour>() as GameSection); parent = gameSection._transform; } else { if (gameSection == null) { gameSection = (uIBehaviour.GetComponent <UIBehaviour>() as GameSection); } if (gameSection == null) { gameSection = (Utility.CreateGameObjectAndComponent(section_data.sectionName, parent, 5) as GameSection); gameSection.baseDepth = GetPrefabUIDepth(section_data.type); parent = gameSection._transform; } if (section_data.type != GAME_SECTION_TYPE.COMMON_DIALOG) { uIBehaviour.Open(UITransition.TYPE.OPEN); } } } else if (gameSection != null) { gameSection.AddPrefab(val, loadObject.PopInstantiatedGameObject()); } else { Log.Warning(LOG.GAMESCENE, "[{0}] is not used.", val.get_name()); } } } } if (gameSection == null) { gameSection = (Utility.CreateGameObjectAndComponent(section_data.sectionName, parent, 5) as GameSection); gameSection.baseDepth = GetPrefabUIDepth(section_data.type); } HierarchyData hierarchyData = new HierarchyData(); hierarchyData.section = gameSection; hierarchyData.data = section_data; hierarchyList.Add(hierarchyData); int type2 = (int)section_data.type; if (typedDatas[type2] == null) { typedDatas[type2] = hierarchyData; } return(gameSection); }
private void TurnAlphaToZero(UIBehaviour thing) { if (thing.GetComponent<Text>() != null) { Color textColor = thing.GetComponent<Text>().color; textColor = new Color(textColor.r, textColor.g, textColor.b, 0); thing.GetComponent<Text>().color = textColor; } else if (thing.GetComponent<Image>() != null) { Color imgColor = thing.GetComponent<Image>().color; imgColor = new Color(imgColor.r, imgColor.g, imgColor.b, 0); thing.GetComponent<Image>().color = imgColor; } }
IEnumerator findOffsetPositon(UIBehaviour thing) { yield return null; yield return null; yield return null; yield return null; float timer = 0f; if (thing.GetComponent<Button>() != null) { while (timer < FadeTimer) { thing.GetComponent<RectTransform>().position = new Vector3(thing.GetComponent<RectTransform>().position.x - offsetPosition * timer / FadeTimer, thing.GetComponent<RectTransform>().position.y, thing.GetComponent<RectTransform>().position.z); timer += Time.deltaTime; yield return null; } } yield return null; }
public static RectTransform GetRect(this UIBehaviour go) { return(go.GetComponent <RectTransform>()); }