public override void OnInspectorGUI() { base.OnInspectorGUI(); GUILayout.Space(5); UiLayoutElement layoutElement = target as UiLayoutElement; UiAnimation animation = layoutElement.GetComponent <UiAnimation>(); if (animation != null) { int indexShow = 0; int indexHide = 0; string[] animations = new string[animation.AnimationClips.Count + 1]; animations[0] = "None"; for (int i = 0; i < animation.AnimationClips.Count; i++) { animations[i + 1] = animation.AnimationClips[i].Name; } for (int i = 0; i < animations.Length; i++) { if (layoutElement.AnimationShow != null && layoutElement.AnimationShow == animations[i]) { indexShow = i; } if (layoutElement.AnimationHide != null && layoutElement.AnimationHide == animations[i]) { indexHide = i; } } EditorGUI.BeginChangeCheck(); indexShow = EditorGUILayout.Popup("Animation Show", indexShow, animations); if (EditorGUI.EndChangeCheck()) { layoutElement.AnimationShow = indexShow > 0 ? animations[indexShow] : null; } EditorGUI.BeginChangeCheck(); indexHide = EditorGUILayout.Popup("Animation Hide", indexHide, animations); if (EditorGUI.EndChangeCheck()) { layoutElement.AnimationHide = indexHide > 0 ? animations[indexHide] : null; } } else { layoutElement.AnimationShow = null; layoutElement.AnimationHide = null; EditorGUILayout.HelpBox("\nAdd UiTweener component to create Show and Hide animations.\n", MessageType.Info); } }
// Render item element prefab field private void RenderListItemPrefab(List <UiLayoutPreset> list, UiLayoutPreset item, ItemType type) { GameObject prefabOriginal = Resources.Load <GameObject>(item.PrefabPath); UiLayoutElement prefab = prefabOriginal != null?prefabOriginal.GetComponent <UiLayoutElement>() : null; // Screen property EditorGUI.BeginChangeCheck(); switch (type) { case ItemType.Popup: prefab = (UiLayoutElementPopup)EditorGUILayout.ObjectField("Prefab", prefab, typeof(UiLayoutElementPopup), allowSceneObjects: false); break; case ItemType.Panel: prefab = (UiLayoutElementPanel)EditorGUILayout.ObjectField("Prefab", prefab, typeof(UiLayoutElementPanel), allowSceneObjects: false); break; case ItemType.Screen: prefab = (UiLayoutElementScreen)EditorGUILayout.ObjectField("Prefab", prefab, typeof(UiLayoutElementScreen), allowSceneObjects: false); break; } if (EditorGUI.EndChangeCheck()) { InternalUtilities.SetDirty(target); if (prefab != null) { Match match = Regex.Match ( AssetDatabase.GetAssetPath(prefab.gameObject), @"Resources/([A-Za-z0-9\-\/.]*).prefab", RegexOptions.IgnoreCase ); item.PrefabPath = match.Success ? match.Groups[1].Value : string.Empty; UiLayoutSettings.Signal signalShow = InternalUtilities.AddSignal("Ui." + GetItemPrefabName(item) + ".Show"); UiLayoutSettings.Signal signalHide = InternalUtilities.AddSignal("Ui." + GetItemPrefabName(item) + ".Hide"); item.SignalsShow = item.SignalsShow.Push(signalShow.Id); item.SignalsHide = item.SignalsHide.Push(signalHide.Id); } else { item.PrefabPath = string.Empty; //item.SignalShow = string.Empty; //item.SignalHide = string.Empty; } } }
// Recursively searches parent layout element. private UiLayoutElement FindParentLayoutElement(Transform transform) { UiLayoutElement element = transform.GetComponent <UiLayoutElement>(); if (element != null) { return(element); } if (transform.parent == null) { return(null); } return(FindParentLayoutElement(transform.parent)); }
// Initialization private void Start() { for (int i = 0; i < AnimationClips.Count; i++) { if (AnimationClips[i].PlayOnAwake) { Play(AnimationClips[i]); } if (AnimationClips[i].PlayOnSignals != null) { for (int j = 0; j < AnimationClips[i].PlayOnSignals.Length; j++) { UiLayoutSettings.Signal signal = Expansion.Instance.LayoutSettings.Signals.Find(x => x.Id == AnimationClips[i].PlayOnSignals[j]); if (signal != null) { SubscribeClipToSignal(signal.Id, AnimationClips[i].Name); SubscribeClipToSignal(signal.Name, AnimationClips[i].Name); } else { SubscribeClipToSignal(AnimationClips[i].PlayOnSignals[j], AnimationClips[i].Name); } } } } UiLayoutElement element = FindParentLayoutElement(gameObject.transform); if (element != null) { element.OnShowBegin += OnParentLayoutElementShowBegin; element.OnHideBegin += OnParentLayoutElementHideBegin; } }