Imported UI Assets
This commit is contained in:
@ -0,0 +1,332 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class BoxButtonManager : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
|
||||
{
|
||||
// Content
|
||||
public Sprite buttonBackground;
|
||||
public Sprite buttonIcon;
|
||||
public string buttonTitle = "Button";
|
||||
public string titleLocalizationKey;
|
||||
public string buttonDescription = "Description";
|
||||
public string descriptionLocalizationKey;
|
||||
public BackgroundFilter backgroundFilter;
|
||||
|
||||
// Resources
|
||||
[SerializeField] private Animator animator;
|
||||
public Image backgroundObj;
|
||||
public Image iconObj;
|
||||
public TextMeshProUGUI titleObj;
|
||||
public TextMeshProUGUI descriptionObj;
|
||||
public Image filterObj;
|
||||
public List<Sprite> filters = new List<Sprite>();
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool enableBackground = true;
|
||||
public bool enableIcon = false;
|
||||
public bool enableTitle = true;
|
||||
public bool enableDescription = true;
|
||||
public bool enableFilter = true;
|
||||
public bool useCustomContent = false;
|
||||
public bool checkForDoubleClick = true;
|
||||
public bool useLocalization = true;
|
||||
public bool bypassUpdateOnEnable = false;
|
||||
public bool useUINavigation = false;
|
||||
public Navigation.Mode navigationMode = Navigation.Mode.Automatic;
|
||||
public GameObject selectOnUp;
|
||||
public GameObject selectOnDown;
|
||||
public GameObject selectOnLeft;
|
||||
public GameObject selectOnRight;
|
||||
public bool wrapAround = false;
|
||||
public bool useSounds = true;
|
||||
[Range(0.1f, 1)] public float doubleClickPeriod = 0.25f;
|
||||
|
||||
// Events
|
||||
public UnityEvent onClick = new UnityEvent();
|
||||
public UnityEvent onDoubleClick = new UnityEvent();
|
||||
public UnityEvent onHover = new UnityEvent();
|
||||
public UnityEvent onLeave = new UnityEvent();
|
||||
public UnityEvent onSelect = new UnityEvent();
|
||||
public UnityEvent onDeselect = new UnityEvent();
|
||||
|
||||
// Helpers
|
||||
bool isInitialized = false;
|
||||
float cachedStateLength = 0.5f;
|
||||
bool waitingForDoubleClickInput;
|
||||
Button targetButton;
|
||||
LocalizedObject localizedObject;
|
||||
#if UNITY_EDITOR
|
||||
public int latestTabIndex = 0;
|
||||
#endif
|
||||
|
||||
public enum BackgroundFilter
|
||||
{
|
||||
Aqua,
|
||||
Dawn,
|
||||
Dusk,
|
||||
Emerald,
|
||||
Kylo,
|
||||
Memory,
|
||||
Mice,
|
||||
Pinky,
|
||||
Retro,
|
||||
Rock,
|
||||
Sunset,
|
||||
Violet,
|
||||
Warm,
|
||||
Random
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
cachedStateLength = HeatUIInternalTools.GetAnimatorClipLength(animator, "BoxButton_Highlighted") + 0.1f;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!isInitialized) { Initialize(); }
|
||||
if (!bypassUpdateOnEnable) { UpdateUI(); }
|
||||
if (Application.isPlaying && useUINavigation) { AddUINavigation(); }
|
||||
else if (Application.isPlaying && !useUINavigation && targetButton == null)
|
||||
{
|
||||
targetButton = gameObject.AddComponent<Button>();
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
if (ControllerManager.instance != null) { ControllerManager.instance.boxButtons.Add(this); }
|
||||
if (UIManagerAudio.instance == null) { useSounds = false; }
|
||||
if (animator == null) { animator = GetComponent<Animator>(); }
|
||||
if (GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
TriggerAnimation("Start");
|
||||
|
||||
if (useLocalization && !useCustomContent)
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
|
||||
if (localizedObject == null || !localizedObject.CheckLocalizationStatus()) { useLocalization = false; }
|
||||
else if (localizedObject != null && !string.IsNullOrEmpty(titleLocalizationKey))
|
||||
{
|
||||
// Forcing button to take the localized output on awake
|
||||
buttonTitle = localizedObject.GetKeyOutput(titleLocalizationKey);
|
||||
|
||||
// Change button text on language change
|
||||
localizedObject.onLanguageChanged.AddListener(delegate
|
||||
{
|
||||
buttonTitle = localizedObject.GetKeyOutput(titleLocalizationKey);
|
||||
buttonDescription = localizedObject.GetKeyOutput(descriptionLocalizationKey);
|
||||
UpdateUI();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (enableIcon && iconObj != null) { iconObj.gameObject.SetActive(true); iconObj.sprite = buttonIcon; }
|
||||
else if (iconObj != null) { iconObj.gameObject.SetActive(false); }
|
||||
|
||||
if (enableTitle && titleObj != null) { titleObj.gameObject.SetActive(true); titleObj.text = buttonTitle; }
|
||||
else if (titleObj != null) { titleObj.gameObject.SetActive(false); }
|
||||
|
||||
if (enableDescription && descriptionObj != null) { descriptionObj.gameObject.SetActive(true); descriptionObj.text = buttonDescription; }
|
||||
else if (descriptionObj != null)
|
||||
{
|
||||
descriptionObj.gameObject.SetActive(false);
|
||||
if (Application.isPlaying && enableTitle && titleObj != null) { titleObj.transform.parent.gameObject.name = titleObj.gameObject.name + "_D"; }
|
||||
}
|
||||
|
||||
if (!enableFilter && filterObj != null) { filterObj.gameObject.SetActive(false); }
|
||||
else if (enableFilter && filterObj != null && filters.Count >= (int)backgroundFilter + 1)
|
||||
{
|
||||
filterObj.gameObject.SetActive(true);
|
||||
|
||||
if (backgroundFilter == BackgroundFilter.Random) { filterObj.sprite = filters[(int)Random.Range(0, filters.Count - 2)]; }
|
||||
else { filterObj.sprite = filters[(int)backgroundFilter]; }
|
||||
}
|
||||
|
||||
if (enableBackground && backgroundObj != null) { backgroundObj.sprite = buttonBackground; }
|
||||
if (!Application.isPlaying || !gameObject.activeInHierarchy) { return; }
|
||||
|
||||
TriggerAnimation("Start");
|
||||
}
|
||||
|
||||
public void SetText(string text) { buttonTitle = text; UpdateUI(); }
|
||||
public void SetDescription(string text) { buttonDescription = text; UpdateUI(); }
|
||||
public void SetIcon(Sprite icon) { buttonIcon = icon; UpdateUI(); }
|
||||
public void SetBackground(Sprite bg) { buttonBackground = bg; UpdateUI(); }
|
||||
public void SetInteractable(bool value) { isInteractable = value; }
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
if (targetButton == null)
|
||||
{
|
||||
if (gameObject.GetComponent<Button>() == null) { targetButton = gameObject.AddComponent<Button>(); }
|
||||
else { targetButton = GetComponent<Button>(); }
|
||||
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
|
||||
if (targetButton.navigation.mode == navigationMode)
|
||||
return;
|
||||
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = navigationMode;
|
||||
|
||||
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
|
||||
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine("InitUINavigation", customNav); return; }
|
||||
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
|
||||
public void DisableUINavigation()
|
||||
{
|
||||
if (targetButton != null)
|
||||
{
|
||||
Navigation customNav = new Navigation();
|
||||
Navigation.Mode navMode = Navigation.Mode.None;
|
||||
customNav.mode = navMode;
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
}
|
||||
|
||||
public void InvokeOnClick()
|
||||
{
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
void TriggerAnimation(string triggername)
|
||||
{
|
||||
animator.enabled = true;
|
||||
|
||||
animator.ResetTrigger("Start");
|
||||
animator.ResetTrigger("Normal");
|
||||
animator.ResetTrigger("Highlighted");
|
||||
|
||||
animator.SetTrigger(triggername);
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable || eventData.button != PointerEventData.InputButton.Left) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
// Invoke click actions
|
||||
onClick.Invoke();
|
||||
|
||||
// Check for double click
|
||||
if (!checkForDoubleClick) { return; }
|
||||
if (waitingForDoubleClickInput)
|
||||
{
|
||||
onDoubleClick.Invoke();
|
||||
waitingForDoubleClickInput = false;
|
||||
return;
|
||||
}
|
||||
|
||||
waitingForDoubleClickInput = true;
|
||||
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("CheckForDoubleClick");
|
||||
StartCoroutine("CheckForDoubleClick");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
TriggerAnimation("Highlighted");
|
||||
onHover.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
TriggerAnimation("Normal");
|
||||
onLeave.Invoke();
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
TriggerAnimation("Highlighted");
|
||||
onSelect.Invoke();
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
TriggerAnimation("Normal");
|
||||
onDeselect.Invoke();
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
if (EventSystem.current.currentSelectedGameObject != gameObject) { TriggerAnimation("Normal"); }
|
||||
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
IEnumerator CheckForDoubleClick()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(doubleClickPeriod);
|
||||
waitingForDoubleClickInput = false;
|
||||
}
|
||||
|
||||
IEnumerator InitUINavigation(Navigation nav)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.1f);
|
||||
|
||||
if (selectOnUp != null) { nav.selectOnUp = selectOnUp.GetComponent<Selectable>(); }
|
||||
if (selectOnDown != null) { nav.selectOnDown = selectOnDown.GetComponent<Selectable>(); }
|
||||
if (selectOnLeft != null) { nav.selectOnLeft = selectOnLeft.GetComponent<Selectable>(); }
|
||||
if (selectOnRight != null) { nav.selectOnRight = selectOnRight.GetComponent<Selectable>(); }
|
||||
|
||||
targetButton.navigation = nav;
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(cachedStateLength);
|
||||
animator.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 98f5fdf6a0a827e408eae2107ce2ac4f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b044a95718e69ee40ac27035753bf3c6, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/BoxButtonManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,259 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using static Michsky.UI.Heat.BoxButtonManager;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(BoxButtonManager))]
|
||||
public class BoxButtonManagerEditor : Editor
|
||||
{
|
||||
private BoxButtonManager buttonTarget;
|
||||
private GUISkin customSkin;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
buttonTarget = (BoxButtonManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Button Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
buttonTarget.latestTabIndex = HeatUIEditorHandler.DrawTabs(buttonTarget.latestTabIndex, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
buttonTarget.latestTabIndex = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
buttonTarget.latestTabIndex = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
buttonTarget.latestTabIndex = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var animator = serializedObject.FindProperty("animator");
|
||||
var audioManager = serializedObject.FindProperty("audioManager");
|
||||
var backgroundObj = serializedObject.FindProperty("backgroundObj");
|
||||
var iconObj = serializedObject.FindProperty("iconObj");
|
||||
var titleObj = serializedObject.FindProperty("titleObj");
|
||||
var descriptionObj = serializedObject.FindProperty("descriptionObj");
|
||||
var filterObj = serializedObject.FindProperty("filterObj");
|
||||
|
||||
var buttonBackground = serializedObject.FindProperty("buttonBackground");
|
||||
var buttonIcon = serializedObject.FindProperty("buttonIcon");
|
||||
var buttonTitle = serializedObject.FindProperty("buttonTitle");
|
||||
var titleLocalizationKey = serializedObject.FindProperty("titleLocalizationKey");
|
||||
var buttonDescription = serializedObject.FindProperty("buttonDescription");
|
||||
var descriptionLocalizationKey = serializedObject.FindProperty("descriptionLocalizationKey");
|
||||
var backgroundFilter = serializedObject.FindProperty("backgroundFilter");
|
||||
|
||||
var isInteractable = serializedObject.FindProperty("isInteractable");
|
||||
var enableBackground = serializedObject.FindProperty("enableBackground");
|
||||
var enableIcon = serializedObject.FindProperty("enableIcon");
|
||||
var enableTitle = serializedObject.FindProperty("enableTitle");
|
||||
var enableDescription = serializedObject.FindProperty("enableDescription");
|
||||
var enableFilter = serializedObject.FindProperty("enableFilter");
|
||||
var useUINavigation = serializedObject.FindProperty("useUINavigation");
|
||||
var navigationMode = serializedObject.FindProperty("navigationMode");
|
||||
var wrapAround = serializedObject.FindProperty("wrapAround");
|
||||
var selectOnUp = serializedObject.FindProperty("selectOnUp");
|
||||
var selectOnDown = serializedObject.FindProperty("selectOnDown");
|
||||
var selectOnLeft = serializedObject.FindProperty("selectOnLeft");
|
||||
var selectOnRight = serializedObject.FindProperty("selectOnRight");
|
||||
var checkForDoubleClick = serializedObject.FindProperty("checkForDoubleClick");
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var useSounds = serializedObject.FindProperty("useSounds");
|
||||
var doubleClickPeriod = serializedObject.FindProperty("doubleClickPeriod");
|
||||
var useCustomContent = serializedObject.FindProperty("useCustomContent");
|
||||
|
||||
var onClick = serializedObject.FindProperty("onClick");
|
||||
var onDoubleClick = serializedObject.FindProperty("onDoubleClick");
|
||||
var onHover = serializedObject.FindProperty("onHover");
|
||||
var onLeave = serializedObject.FindProperty("onLeave");
|
||||
|
||||
switch (buttonTarget.latestTabIndex)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (useCustomContent.boolValue == false)
|
||||
{
|
||||
if (buttonTarget.backgroundObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableBackground.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableBackground.boolValue, customSkin, "Enable Background");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableBackground.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonBackground, customSkin, "Background", 110);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.iconObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableIcon.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableIcon.boolValue, customSkin, "Enable Icon");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableIcon.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonIcon, customSkin, "Button Icon", 110);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.titleObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableTitle.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableTitle.boolValue, customSkin, "Enable Title");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableTitle.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonTitle, customSkin, "Button Text", 110);
|
||||
if (useLocalization.boolValue == true) { HeatUIEditorHandler.DrawPropertyCW(titleLocalizationKey, customSkin, "Localization Key", 110); }
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.descriptionObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableDescription.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableDescription.boolValue, customSkin, "Enable Description");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableDescription.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonDescription, customSkin, "Description", 110);
|
||||
if (useLocalization.boolValue == true) { HeatUIEditorHandler.DrawPropertyCW(descriptionLocalizationKey, customSkin, "Localization Key", 110); }
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.filterObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableFilter.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableFilter.boolValue, customSkin, "Enable Hover Filter");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableFilter.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(backgroundFilter, customSkin, "Background Filter", 110);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (Application.isPlaying == false) { buttonTarget.UpdateUI(); }
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("'Use Custom Content' is enabled. Content is now managed manually.", MessageType.Info); }
|
||||
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
|
||||
if (Application.isPlaying == true && GUILayout.Button("Update UI", customSkin.button)) { buttonTarget.UpdateUI(); }
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onClick, new GUIContent("On Click"), true);
|
||||
EditorGUILayout.PropertyField(onDoubleClick, new GUIContent("On Double Click"), true);
|
||||
EditorGUILayout.PropertyField(onHover, new GUIContent("On Hover"), true);
|
||||
EditorGUILayout.PropertyField(onLeave, new GUIContent("On Leave"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(backgroundObj, customSkin, "Background Object");
|
||||
HeatUIEditorHandler.DrawProperty(iconObj, customSkin, "Icon Object");
|
||||
HeatUIEditorHandler.DrawProperty(titleObj, customSkin, "Title Object");
|
||||
HeatUIEditorHandler.DrawProperty(descriptionObj, customSkin, "Description Object");
|
||||
HeatUIEditorHandler.DrawProperty(filterObj, customSkin, "Filter Object");
|
||||
HeatUIEditorHandler.DrawProperty(animator, customSkin, "Animator");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(doubleClickPeriod, customSkin, "Double Click Period");
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
useCustomContent.boolValue = HeatUIEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content", "Bypasses inspector values and allows manual editing.");
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
GUI.enabled = true;
|
||||
checkForDoubleClick.boolValue = HeatUIEditorHandler.DrawToggle(checkForDoubleClick.boolValue, customSkin, "Check For Double Click");
|
||||
useSounds.boolValue = HeatUIEditorHandler.DrawToggle(useSounds.boolValue, customSkin, "Use Button Sounds");
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
useUINavigation.boolValue = HeatUIEditorHandler.DrawTogglePlain(useUINavigation.boolValue, customSkin, "Use UI Navigation", "Enables controller navigation.");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (useUINavigation.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
HeatUIEditorHandler.DrawPropertyPlain(navigationMode, customSkin, "Navigation Mode");
|
||||
|
||||
if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Horizontal)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawToggle(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Vertical)
|
||||
{
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawTogglePlain(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
}
|
||||
|
||||
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Explicit)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnUp, customSkin, "Select On Up");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnDown, customSkin, "Select On Down");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnLeft, customSkin, "Select On Left");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnRight, customSkin, "Select On Right");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
buttonTarget.UpdateUI();
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e824907b24267f449215027fbd6a3ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/BoxButtonManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,65 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Heat UI/Animation/Box Container")]
|
||||
public class BoxContainer : MonoBehaviour
|
||||
{
|
||||
[Header("Animation")]
|
||||
public AnimationCurve animationCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f));
|
||||
[Range(0.5f, 10)] public float curveSpeed = 1;
|
||||
[Range(0, 5)] public float animationDelay = 0;
|
||||
|
||||
[Header("Fading")]
|
||||
[Range(0, 0.99f)] public float fadeAfterScale = 0.75f;
|
||||
[Range(0.1f, 10)] public float fadeSpeed = 5f;
|
||||
|
||||
[Header("Settings")]
|
||||
public UpdateMode updateMode = UpdateMode.DeltaTime;
|
||||
[Range(0, 1)] public float itemCooldown = 0.1f;
|
||||
public bool playOnce = false;
|
||||
|
||||
// Helpers
|
||||
[HideInInspector] public bool isPlayedOnce = false;
|
||||
List<BoxContainerItem> cachedItems = new List<BoxContainerItem>();
|
||||
|
||||
public enum UpdateMode { DeltaTime, UnscaledTime }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
foreach (Transform child in transform)
|
||||
{
|
||||
BoxContainerItem temp = child.gameObject.AddComponent<BoxContainerItem>();
|
||||
temp.container = this;
|
||||
cachedItems.Add(temp);
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (animationDelay > 0) { Invoke(nameof(Animate), animationDelay); }
|
||||
else { Animate(); }
|
||||
}
|
||||
|
||||
public void Animate()
|
||||
{
|
||||
if (playOnce && isPlayedOnce)
|
||||
return;
|
||||
|
||||
float tempTime = 0;
|
||||
|
||||
if (cachedItems.Count > 0)
|
||||
{
|
||||
foreach (BoxContainerItem item in cachedItems)
|
||||
{
|
||||
item.Process(tempTime);
|
||||
tempTime += itemCooldown;
|
||||
}
|
||||
}
|
||||
|
||||
isPlayedOnce = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbceb0544d0aeb64ebf0df5192b73514
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b633d2f960ff9e74a901c2047b5e76ea, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/BoxContainer.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,88 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class BoxContainerItem : MonoBehaviour
|
||||
{
|
||||
[HideInInspector] public BoxContainer container;
|
||||
|
||||
// Helpers
|
||||
CanvasGroup cg;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
cg = GetComponent<CanvasGroup>();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (container.playOnce && container.isPlayedOnce)
|
||||
{
|
||||
cg.alpha = 1;
|
||||
transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
cg.alpha = 0;
|
||||
transform.localScale = new Vector3(0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void Process(float time)
|
||||
{
|
||||
if (!gameObject.activeInHierarchy)
|
||||
return;
|
||||
|
||||
StartCoroutine("ProcessBoxScale", time);
|
||||
}
|
||||
|
||||
IEnumerator ProcessBoxScale(float time)
|
||||
{
|
||||
transform.localScale = new Vector3(0, 0, 0);
|
||||
|
||||
if (container.updateMode == BoxContainer.UpdateMode.DeltaTime) { yield return new WaitForSeconds(time); }
|
||||
else { yield return new WaitForSecondsRealtime(time); }
|
||||
|
||||
float elapsedTime = 0;
|
||||
float startingPoint = 0;
|
||||
bool fadeStarted = false;
|
||||
|
||||
while (elapsedTime < 1)
|
||||
{
|
||||
float lerpValue = Mathf.Lerp(startingPoint, 1, container.animationCurve.Evaluate(elapsedTime));
|
||||
transform.localScale = new Vector3(lerpValue, lerpValue, lerpValue);
|
||||
|
||||
if (transform.localScale.x > container.fadeAfterScale && !fadeStarted)
|
||||
{
|
||||
fadeStarted = true;
|
||||
StartCoroutine("ProcessBoxFade");
|
||||
}
|
||||
|
||||
if (container.updateMode == BoxContainer.UpdateMode.DeltaTime) { elapsedTime += Time.deltaTime * container.curveSpeed; }
|
||||
else { elapsedTime += Time.unscaledDeltaTime * container.curveSpeed; }
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
transform.localScale = new Vector3(1, 1, 1);
|
||||
}
|
||||
|
||||
IEnumerator ProcessBoxFade()
|
||||
{
|
||||
cg.alpha = 0;
|
||||
|
||||
while (cg.alpha < 0.99f)
|
||||
{
|
||||
if (container.updateMode == BoxContainer.UpdateMode.DeltaTime) { cg.alpha += Time.deltaTime * container.fadeSpeed; }
|
||||
else { cg.alpha += Time.unscaledDeltaTime * container.fadeSpeed; }
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
cg.alpha = 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1880f76b598b4344586f7b093d9cf6bd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/BoxContainerItem.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,455 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[DisallowMultipleComponent]
|
||||
public class ButtonManager : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
|
||||
{
|
||||
// Content
|
||||
public Sprite buttonIcon;
|
||||
public string buttonText = "Button";
|
||||
[Range(0.1f, 10)] public float iconScale = 1;
|
||||
[Range(1, 200)] public float textSize = 24;
|
||||
|
||||
// Resources
|
||||
[SerializeField] private CanvasGroup normalCG;
|
||||
[SerializeField] private CanvasGroup highlightCG;
|
||||
[SerializeField] private CanvasGroup disabledCG;
|
||||
public TextMeshProUGUI normalTextObj;
|
||||
public TextMeshProUGUI highlightTextObj;
|
||||
public TextMeshProUGUI disabledTextObj;
|
||||
public Image normalImageObj;
|
||||
public Image highlightImageObj;
|
||||
public Image disabledImageObj;
|
||||
|
||||
// Auto Size
|
||||
public bool autoFitContent = true;
|
||||
public Padding padding;
|
||||
[Range(0, 100)] public int spacing = 12;
|
||||
[SerializeField] private HorizontalLayoutGroup disabledLayout;
|
||||
[SerializeField] private HorizontalLayoutGroup normalLayout;
|
||||
[SerializeField] private HorizontalLayoutGroup highlightedLayout;
|
||||
public HorizontalLayoutGroup mainLayout;
|
||||
[SerializeField] private ContentSizeFitter mainFitter;
|
||||
[SerializeField] private ContentSizeFitter targetFitter;
|
||||
[SerializeField] private RectTransform targetRect;
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool enableIcon = false;
|
||||
public bool enableText = true;
|
||||
public bool useCustomContent = false;
|
||||
[SerializeField] private bool useCustomTextSize = false;
|
||||
public bool checkForDoubleClick = true;
|
||||
public bool useLocalization = true;
|
||||
public bool bypassUpdateOnEnable = false;
|
||||
public bool useUINavigation = false;
|
||||
public Navigation.Mode navigationMode = Navigation.Mode.Automatic;
|
||||
public GameObject selectOnUp;
|
||||
public GameObject selectOnDown;
|
||||
public GameObject selectOnLeft;
|
||||
public GameObject selectOnRight;
|
||||
public bool wrapAround = false;
|
||||
public bool useSounds = true;
|
||||
[Range(0.1f, 1)] public float doubleClickPeriod = 0.25f;
|
||||
[Range(1, 15)] public float fadingMultiplier = 8;
|
||||
|
||||
// Events
|
||||
public UnityEvent onClick = new UnityEvent();
|
||||
public UnityEvent onDoubleClick = new UnityEvent();
|
||||
public UnityEvent onHover = new UnityEvent();
|
||||
public UnityEvent onLeave = new UnityEvent();
|
||||
public UnityEvent onSelect = new UnityEvent();
|
||||
public UnityEvent onDeselect = new UnityEvent();
|
||||
|
||||
// Helpers
|
||||
bool isInitialized = false;
|
||||
Button targetButton;
|
||||
LocalizedObject localizedObject;
|
||||
bool waitingForDoubleClickInput;
|
||||
#if UNITY_EDITOR
|
||||
public int latestTabIndex = 0;
|
||||
#endif
|
||||
|
||||
[System.Serializable] public class Padding { public int left = 18; public int right = 18; public int top = 15; public int bottom = 15; }
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!isInitialized) { Initialize(); }
|
||||
if (!bypassUpdateOnEnable) { UpdateUI(); }
|
||||
if (Application.isPlaying && useUINavigation) { AddUINavigation(); }
|
||||
else if (Application.isPlaying && !useUINavigation && targetButton == null)
|
||||
{
|
||||
targetButton = gameObject.AddComponent<Button>();
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
if (disabledCG != null) { disabledCG.alpha = 0; }
|
||||
if (normalCG != null) { normalCG.alpha = 1; }
|
||||
if (highlightCG != null) { highlightCG.alpha = 0; }
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying)
|
||||
return;
|
||||
#endif
|
||||
if (ControllerManager.instance != null) { ControllerManager.instance.buttons.Add(this); }
|
||||
if (UIManagerAudio.instance == null) { useSounds = false; }
|
||||
if (normalCG == null) { normalCG = new GameObject().AddComponent<CanvasGroup>(); normalCG.gameObject.AddComponent<RectTransform>(); normalCG.transform.SetParent(transform); normalCG.gameObject.name = "Normal"; }
|
||||
if (highlightCG == null) { highlightCG = new GameObject().AddComponent<CanvasGroup>(); highlightCG.gameObject.AddComponent<RectTransform>(); highlightCG.transform.SetParent(transform); highlightCG.gameObject.name = "Highlight"; }
|
||||
if (disabledCG == null) { disabledCG = new GameObject().AddComponent<CanvasGroup>(); disabledCG.gameObject.AddComponent<RectTransform>(); disabledCG.transform.SetParent(transform); disabledCG.gameObject.name = "Disabled"; }
|
||||
if (GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
normalCG.alpha = 1;
|
||||
highlightCG.alpha = 0;
|
||||
disabledCG.alpha = 0;
|
||||
|
||||
if (useLocalization && !useCustomContent)
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
|
||||
if (localizedObject == null || !localizedObject.CheckLocalizationStatus()) { useLocalization = false; }
|
||||
else if (localizedObject != null && !string.IsNullOrEmpty(localizedObject.localizationKey))
|
||||
{
|
||||
// Forcing button to take the localized output on awake
|
||||
buttonText = localizedObject.GetKeyOutput(localizedObject.localizationKey);
|
||||
|
||||
// Change button text on language change
|
||||
localizedObject.onLanguageChanged.AddListener(delegate
|
||||
{
|
||||
buttonText = localizedObject.GetKeyOutput(localizedObject.localizationKey);
|
||||
UpdateUI();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (!autoFitContent)
|
||||
{
|
||||
if (mainFitter != null) { mainFitter.enabled = false; }
|
||||
if (mainLayout != null) { mainLayout.enabled = false; }
|
||||
if (disabledLayout != null) { disabledLayout.childForceExpandWidth = false; }
|
||||
if (normalLayout != null) { normalLayout.childForceExpandWidth = false; }
|
||||
if (highlightedLayout != null) { highlightedLayout.childForceExpandWidth = false; }
|
||||
if (targetFitter != null)
|
||||
{
|
||||
targetFitter.enabled = false;
|
||||
|
||||
if (targetRect != null)
|
||||
{
|
||||
targetRect.anchorMin = new Vector2(0, 0);
|
||||
targetRect.anchorMax = new Vector2(1, 1);
|
||||
targetRect.offsetMin = new Vector2(0, 0);
|
||||
targetRect.offsetMax = new Vector2(0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (disabledLayout != null) { disabledLayout.childForceExpandWidth = true; }
|
||||
if (normalLayout != null) { normalLayout.childForceExpandWidth = true; }
|
||||
if (highlightedLayout != null) { highlightedLayout.childForceExpandWidth = true; }
|
||||
if (mainFitter != null) { mainFitter.enabled = true; }
|
||||
if (mainLayout != null) { mainLayout.enabled = true; }
|
||||
if (targetFitter != null) { targetFitter.enabled = true; }
|
||||
}
|
||||
|
||||
if (disabledLayout != null && autoFitContent) { disabledLayout.padding = new RectOffset(padding.left, padding.right, padding.top, padding.bottom); disabledLayout.spacing = spacing; }
|
||||
if (normalLayout != null && autoFitContent) { normalLayout.padding = new RectOffset(padding.left, padding.right, padding.top, padding.bottom); normalLayout.spacing = spacing; }
|
||||
if (highlightedLayout != null && autoFitContent) { highlightedLayout.padding = new RectOffset(padding.left, padding.right, padding.top, padding.bottom); highlightedLayout.spacing = spacing; }
|
||||
|
||||
if (enableText)
|
||||
{
|
||||
if (normalTextObj != null)
|
||||
{
|
||||
normalTextObj.gameObject.SetActive(true);
|
||||
normalTextObj.text = buttonText;
|
||||
if (useCustomTextSize == false) { normalTextObj.fontSize = textSize; }
|
||||
}
|
||||
|
||||
if (highlightTextObj != null)
|
||||
{
|
||||
highlightTextObj.gameObject.SetActive(true);
|
||||
highlightTextObj.text = buttonText;
|
||||
if (useCustomTextSize == false) { highlightTextObj.fontSize = textSize; }
|
||||
}
|
||||
|
||||
if (disabledTextObj != null)
|
||||
{
|
||||
disabledTextObj.gameObject.SetActive(true);
|
||||
disabledTextObj.text = buttonText;
|
||||
if (useCustomTextSize == false) { disabledTextObj.fontSize = textSize; }
|
||||
}
|
||||
}
|
||||
|
||||
else if (!enableText)
|
||||
{
|
||||
if (normalTextObj != null) { normalTextObj.gameObject.SetActive(false); }
|
||||
if (highlightTextObj != null) { highlightTextObj.gameObject.SetActive(false); }
|
||||
if (disabledTextObj != null) { disabledTextObj.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
if (enableIcon)
|
||||
{
|
||||
Vector3 tempScale = new Vector3(iconScale, iconScale, iconScale);
|
||||
|
||||
if (normalImageObj != null) { normalImageObj.transform.parent.gameObject.SetActive(true); normalImageObj.sprite = buttonIcon; normalImageObj.transform.localScale = tempScale; }
|
||||
if (highlightImageObj != null) { highlightImageObj.transform.parent.gameObject.SetActive(true); highlightImageObj.sprite = buttonIcon; highlightImageObj.transform.localScale = tempScale; }
|
||||
if (disabledImageObj != null) { disabledImageObj.transform.parent.gameObject.SetActive(true); disabledImageObj.sprite = buttonIcon; disabledImageObj.transform.localScale = tempScale; }
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (normalImageObj != null) { normalImageObj.transform.parent.gameObject.SetActive(false); }
|
||||
if (highlightImageObj != null) { highlightImageObj.transform.parent.gameObject.SetActive(false); }
|
||||
if (disabledImageObj != null) { disabledImageObj.transform.parent.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying && autoFitContent)
|
||||
{
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
|
||||
if (disabledCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(disabledCG.GetComponent<RectTransform>()); }
|
||||
if (normalCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(normalCG.GetComponent<RectTransform>()); }
|
||||
if (highlightCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(highlightCG.GetComponent<RectTransform>()); }
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!Application.isPlaying || !gameObject.activeInHierarchy) { return; }
|
||||
if (!isInteractable) { StartCoroutine("SetDisabled"); }
|
||||
else if (isInteractable && disabledCG.alpha == 1) { StartCoroutine("SetNormal"); }
|
||||
|
||||
StartCoroutine("LayoutFix");
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
if (!Application.isPlaying || !gameObject.activeInHierarchy) { return; }
|
||||
if (!isInteractable) { StartCoroutine("SetDisabled"); }
|
||||
else if (isInteractable) { StartCoroutine("SetNormal"); }
|
||||
}
|
||||
|
||||
|
||||
public void SetText(string text) { buttonText = text; UpdateUI(); }
|
||||
public void SetIcon(Sprite icon) { buttonIcon = icon; UpdateUI(); }
|
||||
|
||||
public void Interactable(bool value)
|
||||
{
|
||||
isInteractable = value;
|
||||
|
||||
if (gameObject.activeInHierarchy == false) { return; }
|
||||
if (!isInteractable) { StartCoroutine("SetDisabled"); }
|
||||
else if (isInteractable && disabledCG.alpha == 1) { StartCoroutine("SetNormal"); }
|
||||
}
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
if (targetButton == null)
|
||||
{
|
||||
if (gameObject.GetComponent<Button>() == null) { targetButton = gameObject.AddComponent<Button>(); }
|
||||
else { targetButton = GetComponent<Button>(); }
|
||||
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
|
||||
if (targetButton.navigation.mode == navigationMode)
|
||||
return;
|
||||
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = navigationMode;
|
||||
|
||||
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
|
||||
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine("InitUINavigation", customNav); return; }
|
||||
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
|
||||
public void DisableUINavigation()
|
||||
{
|
||||
if (targetButton != null)
|
||||
{
|
||||
Navigation customNav = new Navigation();
|
||||
Navigation.Mode navMode = Navigation.Mode.None;
|
||||
customNav.mode = navMode;
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
}
|
||||
|
||||
public void InvokeOnClick() { onClick.Invoke(); }
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable || eventData.button != PointerEventData.InputButton.Left) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
// Invoke click actions
|
||||
onClick.Invoke();
|
||||
|
||||
// Check for double click
|
||||
if (!checkForDoubleClick) { return; }
|
||||
if (waitingForDoubleClickInput)
|
||||
{
|
||||
onDoubleClick.Invoke();
|
||||
waitingForDoubleClickInput = false;
|
||||
return;
|
||||
}
|
||||
|
||||
waitingForDoubleClickInput = true;
|
||||
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("CheckForDoubleClick");
|
||||
StartCoroutine("CheckForDoubleClick");
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
onHover.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
onLeave.Invoke();
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
onSelect.Invoke();
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
onDeselect.Invoke();
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
if (EventSystem.current.currentSelectedGameObject != gameObject) { StartCoroutine("SetNormal"); }
|
||||
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
IEnumerator LayoutFix()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.025f);
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(transform.parent.GetComponent<RectTransform>());
|
||||
if (disabledCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(disabledCG.GetComponent<RectTransform>()); }
|
||||
if (normalCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(normalCG.GetComponent<RectTransform>()); }
|
||||
if (highlightCG != null) { LayoutRebuilder.ForceRebuildLayoutImmediate(highlightCG.GetComponent<RectTransform>()); }
|
||||
}
|
||||
|
||||
IEnumerator SetNormal()
|
||||
{
|
||||
StopCoroutine("SetHighlight");
|
||||
StopCoroutine("SetDisabled");
|
||||
|
||||
while (normalCG.alpha < 0.99f)
|
||||
{
|
||||
normalCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
disabledCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
normalCG.alpha = 1;
|
||||
highlightCG.alpha = 0;
|
||||
disabledCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetHighlight()
|
||||
{
|
||||
StopCoroutine("SetNormal");
|
||||
StopCoroutine("SetDisabled");
|
||||
|
||||
while (highlightCG.alpha < 0.99f)
|
||||
{
|
||||
normalCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
highlightCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
disabledCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
normalCG.alpha = 0;
|
||||
highlightCG.alpha = 1;
|
||||
disabledCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetDisabled()
|
||||
{
|
||||
StopCoroutine("SetNormal");
|
||||
StopCoroutine("SetHighlight");
|
||||
|
||||
while (disabledCG.alpha < 0.99f)
|
||||
{
|
||||
normalCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
disabledCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
normalCG.alpha = 0;
|
||||
highlightCG.alpha = 0;
|
||||
disabledCG.alpha = 1;
|
||||
}
|
||||
|
||||
IEnumerator CheckForDoubleClick()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(doubleClickPeriod);
|
||||
waitingForDoubleClickInput = false;
|
||||
}
|
||||
|
||||
IEnumerator InitUINavigation(Navigation nav)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.1f);
|
||||
if (selectOnUp != null) { nav.selectOnUp = selectOnUp.GetComponent<Selectable>(); }
|
||||
if (selectOnDown != null) { nav.selectOnDown = selectOnDown.GetComponent<Selectable>(); }
|
||||
if (selectOnLeft != null) { nav.selectOnLeft = selectOnLeft.GetComponent<Selectable>(); }
|
||||
if (selectOnRight != null) { nav.selectOnRight = selectOnRight.GetComponent<Selectable>(); }
|
||||
targetButton.navigation = nav;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 504050c5fda9c0645802e401a644a171
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b044a95718e69ee40ac27035753bf3c6, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ButtonManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,263 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(ButtonManager))]
|
||||
public class ButtonManagerEditor : Editor
|
||||
{
|
||||
private ButtonManager buttonTarget;
|
||||
private GUISkin customSkin;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
buttonTarget = (ButtonManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Button Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
buttonTarget.latestTabIndex = HeatUIEditorHandler.DrawTabs(buttonTarget.latestTabIndex, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
buttonTarget.latestTabIndex = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
buttonTarget.latestTabIndex = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
buttonTarget.latestTabIndex = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var normalCG = serializedObject.FindProperty("normalCG");
|
||||
var highlightCG = serializedObject.FindProperty("highlightCG");
|
||||
var disabledCG = serializedObject.FindProperty("disabledCG");
|
||||
var normalTextObj = serializedObject.FindProperty("normalTextObj");
|
||||
var highlightTextObj = serializedObject.FindProperty("highlightTextObj");
|
||||
var disabledTextObj = serializedObject.FindProperty("disabledTextObj");
|
||||
var normalImageObj = serializedObject.FindProperty("normalImageObj");
|
||||
var highlightImageObj = serializedObject.FindProperty("highlightImageObj");
|
||||
var disabledImageObj = serializedObject.FindProperty("disabledImageObj");
|
||||
|
||||
var buttonIcon = serializedObject.FindProperty("buttonIcon");
|
||||
var buttonText = serializedObject.FindProperty("buttonText");
|
||||
var iconScale = serializedObject.FindProperty("iconScale");
|
||||
var textSize = serializedObject.FindProperty("textSize");
|
||||
|
||||
var autoFitContent = serializedObject.FindProperty("autoFitContent");
|
||||
var padding = serializedObject.FindProperty("padding");
|
||||
var spacing = serializedObject.FindProperty("spacing");
|
||||
var disabledLayout = serializedObject.FindProperty("disabledLayout");
|
||||
var normalLayout = serializedObject.FindProperty("normalLayout");
|
||||
var highlightedLayout = serializedObject.FindProperty("highlightedLayout");
|
||||
var mainLayout = serializedObject.FindProperty("mainLayout");
|
||||
var mainFitter = serializedObject.FindProperty("mainFitter");
|
||||
var targetFitter = serializedObject.FindProperty("targetFitter");
|
||||
var targetRect = serializedObject.FindProperty("targetRect");
|
||||
|
||||
var isInteractable = serializedObject.FindProperty("isInteractable");
|
||||
var enableIcon = serializedObject.FindProperty("enableIcon");
|
||||
var enableText = serializedObject.FindProperty("enableText");
|
||||
var useCustomTextSize = serializedObject.FindProperty("useCustomTextSize");
|
||||
var useUINavigation = serializedObject.FindProperty("useUINavigation");
|
||||
var navigationMode = serializedObject.FindProperty("navigationMode");
|
||||
var wrapAround = serializedObject.FindProperty("wrapAround");
|
||||
var selectOnUp = serializedObject.FindProperty("selectOnUp");
|
||||
var selectOnDown = serializedObject.FindProperty("selectOnDown");
|
||||
var selectOnLeft = serializedObject.FindProperty("selectOnLeft");
|
||||
var selectOnRight = serializedObject.FindProperty("selectOnRight");
|
||||
var checkForDoubleClick = serializedObject.FindProperty("checkForDoubleClick");
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var useSounds = serializedObject.FindProperty("useSounds");
|
||||
var doubleClickPeriod = serializedObject.FindProperty("doubleClickPeriod");
|
||||
var fadingMultiplier = serializedObject.FindProperty("fadingMultiplier");
|
||||
var useCustomContent = serializedObject.FindProperty("useCustomContent");
|
||||
var bypassControllerManager = serializedObject.FindProperty("bypassControllerManager");
|
||||
|
||||
var onClick = serializedObject.FindProperty("onClick");
|
||||
var onDoubleClick = serializedObject.FindProperty("onDoubleClick");
|
||||
var onHover = serializedObject.FindProperty("onHover");
|
||||
var onLeave = serializedObject.FindProperty("onLeave");
|
||||
|
||||
switch (buttonTarget.latestTabIndex)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (useCustomContent.boolValue == false)
|
||||
{
|
||||
if (buttonTarget.normalImageObj != null || buttonTarget.highlightImageObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableIcon.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableIcon.boolValue, customSkin, "Enable Icon");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableIcon.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonIcon, customSkin, "Button Icon", 80);
|
||||
HeatUIEditorHandler.DrawPropertyCW(iconScale, customSkin, "Icon Scale", 80);
|
||||
if (enableText.boolValue == true) { HeatUIEditorHandler.DrawPropertyCW(spacing, customSkin, "Spacing", 80); }
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.normalTextObj != null || buttonTarget.highlightTextObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableText.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableText.boolValue, customSkin, "Enable Text");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableText.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonText, customSkin, "Button Text", 80);
|
||||
if (useCustomTextSize.boolValue == false) { HeatUIEditorHandler.DrawPropertyCW(textSize, customSkin, "Text Size", 80); }
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (Application.isPlaying == false) { buttonTarget.UpdateUI(); }
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("'Use Custom Content' is enabled. Content is now managed manually.", MessageType.Info); }
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
autoFitContent.boolValue = HeatUIEditorHandler.DrawTogglePlain(autoFitContent.boolValue, customSkin, "Auto-Fit Content", "Sets the width based on the button content.");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (autoFitContent.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
EditorGUI.indentLevel = 1;
|
||||
EditorGUILayout.PropertyField(padding, new GUIContent(" Padding"), true);
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
|
||||
if (Application.isPlaying == true && GUILayout.Button("Update UI", customSkin.button)) { buttonTarget.UpdateUI(); }
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onClick, new GUIContent("On Click"), true);
|
||||
EditorGUILayout.PropertyField(onDoubleClick, new GUIContent("On Double Click"), true);
|
||||
EditorGUILayout.PropertyField(onHover, new GUIContent("On Hover"), true);
|
||||
EditorGUILayout.PropertyField(onLeave, new GUIContent("On Leave"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(normalCG, customSkin, "Normal CG");
|
||||
HeatUIEditorHandler.DrawProperty(highlightCG, customSkin, "Highlight CG");
|
||||
HeatUIEditorHandler.DrawProperty(disabledCG, customSkin, "Disabled CG");
|
||||
|
||||
if (enableText.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(normalTextObj, customSkin, "Normal Text");
|
||||
HeatUIEditorHandler.DrawProperty(highlightTextObj, customSkin, "Highlighted Text");
|
||||
HeatUIEditorHandler.DrawProperty(disabledTextObj, customSkin, "Disabled Text");
|
||||
}
|
||||
|
||||
if (enableIcon.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(normalImageObj, customSkin, "Normal Icon");
|
||||
HeatUIEditorHandler.DrawProperty(highlightImageObj, customSkin, "Highlight Icon");
|
||||
HeatUIEditorHandler.DrawProperty(disabledImageObj, customSkin, "Disabled Icon");
|
||||
}
|
||||
|
||||
HeatUIEditorHandler.DrawProperty(disabledLayout, customSkin, "Disabled Layout");
|
||||
HeatUIEditorHandler.DrawProperty(normalLayout, customSkin, "Normal Layout");
|
||||
HeatUIEditorHandler.DrawProperty(highlightedLayout, customSkin, "Highlighted Layout");
|
||||
HeatUIEditorHandler.DrawProperty(mainLayout, customSkin, "Main Layout");
|
||||
|
||||
if (autoFitContent.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(mainFitter, customSkin, "Main Fitter");
|
||||
HeatUIEditorHandler.DrawProperty(targetFitter, customSkin, "Target Fitter");
|
||||
HeatUIEditorHandler.DrawProperty(targetRect, customSkin, "Target Rect");
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(fadingMultiplier, customSkin, "Fading Multiplier", "Set the animation fade multiplier.");
|
||||
HeatUIEditorHandler.DrawProperty(doubleClickPeriod, customSkin, "Double Click Period");
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
useCustomContent.boolValue = HeatUIEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content", "Bypasses inspector values and allows manual editing.");
|
||||
if (useCustomContent.boolValue == true || enableText.boolValue == false) { GUI.enabled = false; }
|
||||
useCustomTextSize.boolValue = HeatUIEditorHandler.DrawToggle(useCustomTextSize.boolValue, customSkin, "Use Custom Text Size");
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
GUI.enabled = true;
|
||||
checkForDoubleClick.boolValue = HeatUIEditorHandler.DrawToggle(checkForDoubleClick.boolValue, customSkin, "Check For Double Click");
|
||||
useSounds.boolValue = HeatUIEditorHandler.DrawToggle(useSounds.boolValue, customSkin, "Use Button Sounds");
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
useUINavigation.boolValue = HeatUIEditorHandler.DrawTogglePlain(useUINavigation.boolValue, customSkin, "Use UI Navigation", "Enables controller navigation.");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (useUINavigation.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
HeatUIEditorHandler.DrawPropertyPlain(navigationMode, customSkin, "Navigation Mode");
|
||||
|
||||
if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Horizontal)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawToggle(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Vertical)
|
||||
{
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawTogglePlain(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
}
|
||||
|
||||
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Explicit)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnUp, customSkin, "Select On Up");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnDown, customSkin, "Select On Down");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnLeft, customSkin, "Select On Left");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnRight, customSkin, "Select On Right");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
buttonTarget.UpdateUI();
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e5b395d7ae505aa42b21b5179b2783ad
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ButtonManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,18 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(Canvas))]
|
||||
[RequireComponent(typeof(CanvasScaler))]
|
||||
public class CanvasManager : MonoBehaviour
|
||||
{
|
||||
CanvasScaler canvasScaler;
|
||||
|
||||
public void SetScale(int scale = 1080)
|
||||
{
|
||||
if (canvasScaler == null) { canvasScaler = gameObject.GetComponent<CanvasScaler>(); }
|
||||
canvasScaler.referenceResolution = new Vector2(canvasScaler.referenceResolution.x, scale);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec1c16a050f9c6e43b099f695c557ca0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: ee083492dcf46e24daded170502f8f55, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/CanvasManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,469 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class Dropdown : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
|
||||
{
|
||||
// Resources
|
||||
public GameObject triggerObject;
|
||||
public TextMeshProUGUI headerText;
|
||||
public Image headerImage;
|
||||
public Transform itemParent;
|
||||
[SerializeField] private GameObject itemPreset;
|
||||
public Scrollbar scrollbar;
|
||||
public VerticalLayoutGroup itemList;
|
||||
[SerializeField] private CanvasGroup highlightCG;
|
||||
public CanvasGroup contentCG;
|
||||
[SerializeField] private CanvasGroup listCG;
|
||||
[SerializeField] private RectTransform listRect;
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool enableIcon = true;
|
||||
public bool enableTrigger = true;
|
||||
public bool enableScrollbar = true;
|
||||
[SerializeField] private bool startAtBottom = false;
|
||||
public bool setHighPriority = true;
|
||||
public bool updateOnEnable = true;
|
||||
public bool outOnPointerExit = false;
|
||||
public bool invokeOnEnable = false;
|
||||
public bool initOnEnable = true;
|
||||
public bool useSounds = true;
|
||||
[Range(1, 15)] public float fadingMultiplier = 8;
|
||||
[Range(1, 50)] public int itemPaddingTop = 8;
|
||||
[Range(1, 50)] public int itemPaddingBottom = 8;
|
||||
[Range(1, 50)] public int itemPaddingLeft = 8;
|
||||
[Range(1, 50)] public int itemPaddingRight = 25;
|
||||
[Range(1, 50)] public int itemSpacing = 8;
|
||||
public int selectedItemIndex = 0;
|
||||
|
||||
// UI Navigation
|
||||
public bool useUINavigation = false;
|
||||
public Navigation.Mode navigationMode = Navigation.Mode.Automatic;
|
||||
public GameObject selectOnUp;
|
||||
public GameObject selectOnDown;
|
||||
public GameObject selectOnLeft;
|
||||
public GameObject selectOnRight;
|
||||
public bool wrapAround = false;
|
||||
|
||||
// Animation
|
||||
public PanelDirection panelDirection;
|
||||
[Range(25, 1000)] public float panelSize = 200;
|
||||
[Range(0.5f, 10)] public float curveSpeed = 2;
|
||||
public AnimationCurve animationCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f));
|
||||
|
||||
// Saving
|
||||
public bool saveSelected = false;
|
||||
public string saveKey = "My Dropdown";
|
||||
|
||||
// Item list
|
||||
[SerializeField]
|
||||
public List<Item> items = new List<Item>();
|
||||
|
||||
// Events
|
||||
[System.Serializable] public class DropdownEvent : UnityEvent<int> { }
|
||||
public DropdownEvent onValueChanged;
|
||||
|
||||
// Helpers
|
||||
[HideInInspector] public bool isOn;
|
||||
[HideInInspector] public int index = 0;
|
||||
[HideInInspector] public int siblingIndex = 0;
|
||||
EventTrigger triggerEvent;
|
||||
Button targetButton;
|
||||
|
||||
public enum PanelDirection { Bottom, Top }
|
||||
|
||||
[System.Serializable]
|
||||
public class Item
|
||||
{
|
||||
public string itemName = "Dropdown Item";
|
||||
public string localizationKey;
|
||||
public Sprite itemIcon;
|
||||
[HideInInspector] public int itemIndex;
|
||||
[HideInInspector] public bool isInvisible = false;
|
||||
[HideInInspector] public ButtonManager itemButton;
|
||||
public UnityEvent onItemSelection = new UnityEvent();
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (initOnEnable) { Initialize(); }
|
||||
if (useUINavigation) { AddUINavigation(); }
|
||||
|
||||
if (enableTrigger && triggerObject != null)
|
||||
{
|
||||
// triggerButton = gameObject.GetComponent<Button>();
|
||||
triggerEvent = triggerObject.AddComponent<EventTrigger>();
|
||||
EventTrigger.Entry entry = new EventTrigger.Entry();
|
||||
entry.eventID = EventTriggerType.PointerClick;
|
||||
entry.callback.AddListener((eventData) => { Animate(); });
|
||||
triggerEvent.GetComponent<EventTrigger>().triggers.Add(entry);
|
||||
}
|
||||
|
||||
if (highlightCG == null)
|
||||
{
|
||||
highlightCG = new GameObject().AddComponent<CanvasGroup>();
|
||||
highlightCG.gameObject.AddComponent<RectTransform>();
|
||||
highlightCG.transform.SetParent(transform);
|
||||
highlightCG.gameObject.name = "Highlight";
|
||||
}
|
||||
|
||||
if (gameObject.GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
if (setHighPriority)
|
||||
{
|
||||
if (contentCG == null) { contentCG = transform.Find("Content/Item List").GetComponent<CanvasGroup>(); }
|
||||
contentCG.alpha = 1;
|
||||
|
||||
Canvas tempCanvas = contentCG.gameObject.AddComponent<Canvas>();
|
||||
tempCanvas.overrideSorting = true;
|
||||
tempCanvas.sortingOrder = 30000;
|
||||
contentCG.gameObject.AddComponent<GraphicRaycaster>();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (listCG == null) { listCG = gameObject.GetComponentInChildren<CanvasGroup>(); }
|
||||
if (listRect == null) { listRect = listCG.GetComponent<RectTransform>(); }
|
||||
if (updateOnEnable && index < items.Count) { SetDropdownIndex(selectedItemIndex); }
|
||||
if (contentCG != null) { contentCG.alpha = 1; }
|
||||
if (UIManagerAudio.instance == null) { useSounds = false; }
|
||||
|
||||
listCG.alpha = 0;
|
||||
listCG.interactable = false;
|
||||
listCG.blocksRaycasts = false;
|
||||
listRect.sizeDelta = new Vector2(listRect.sizeDelta.x, 0);
|
||||
isOn = false;
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (items.Count == 0) { return; }
|
||||
if (!enableScrollbar && scrollbar != null) { Destroy(scrollbar); }
|
||||
if (itemList == null) { itemList = itemParent.GetComponent<VerticalLayoutGroup>(); }
|
||||
|
||||
UpdateItemLayout();
|
||||
index = 0;
|
||||
|
||||
foreach (Transform child in itemParent) { Destroy(child.gameObject); }
|
||||
for (int i = 0; i < items.Count; ++i)
|
||||
{
|
||||
GameObject go = Instantiate(itemPreset, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
go.transform.SetParent(itemParent, false);
|
||||
go.name = items[i].itemName;
|
||||
|
||||
ButtonManager goBtn = go.GetComponent<ButtonManager>();
|
||||
goBtn.buttonText = items[i].itemName;
|
||||
goBtn.bypassUpdateOnEnable = true;
|
||||
items[i].itemButton = goBtn;
|
||||
|
||||
if (items[i].isInvisible)
|
||||
{
|
||||
go.SetActive(false);
|
||||
continue;
|
||||
}
|
||||
|
||||
LocalizedObject loc = goBtn.GetComponent<LocalizedObject>();
|
||||
if (string.IsNullOrEmpty(items[i].localizationKey) && loc != null) { Destroy(loc); }
|
||||
else if (!string.IsNullOrEmpty(items[i].localizationKey) && loc != null)
|
||||
{
|
||||
loc.localizationKey = items[i].localizationKey;
|
||||
loc.onLanguageChanged.AddListener(delegate
|
||||
{
|
||||
goBtn.buttonText = loc.GetKeyOutput(loc.localizationKey);
|
||||
goBtn.UpdateUI();
|
||||
});
|
||||
loc.InitializeItem();
|
||||
loc.UpdateItem();
|
||||
}
|
||||
|
||||
if (items[i].itemIcon == null) { goBtn.enableIcon = false; }
|
||||
else { goBtn.enableIcon = true; goBtn.buttonIcon = items[i].itemIcon; }
|
||||
|
||||
goBtn.UpdateUI();
|
||||
|
||||
items[i].itemIndex = i;
|
||||
Item mainItem = items[i];
|
||||
|
||||
goBtn.onClick.AddListener(Animate);
|
||||
goBtn.onClick.AddListener(items[index = mainItem.itemIndex].onItemSelection.Invoke);
|
||||
goBtn.onClick.AddListener(delegate
|
||||
{
|
||||
SetDropdownIndex(index = mainItem.itemIndex);
|
||||
onValueChanged.Invoke(index = mainItem.itemIndex);
|
||||
if (saveSelected) { PlayerPrefs.SetInt("Dropdown_" + saveKey, mainItem.itemIndex); }
|
||||
});
|
||||
}
|
||||
|
||||
if (headerImage != null && !enableIcon) { headerImage.gameObject.SetActive(false); }
|
||||
else if (headerImage != null) { headerImage.sprite = items[selectedItemIndex].itemIcon; }
|
||||
if (headerText != null) { headerText.text = items[selectedItemIndex].itemName; }
|
||||
|
||||
if (saveSelected)
|
||||
{
|
||||
if (invokeOnEnable) { items[PlayerPrefs.GetInt("Dropdown_" + saveKey)].onItemSelection.Invoke(); }
|
||||
else { SetDropdownIndex(PlayerPrefs.GetInt("Dropdown_" + saveKey)); }
|
||||
}
|
||||
else if (invokeOnEnable) { items[selectedItemIndex].onItemSelection.Invoke(); }
|
||||
}
|
||||
|
||||
public void SetDropdownIndex(int itemIndex)
|
||||
{
|
||||
selectedItemIndex = itemIndex;
|
||||
|
||||
if (headerText != null) { headerText.text = items[itemIndex].itemButton.buttonText; }
|
||||
if (items[itemIndex].isInvisible) { return; }
|
||||
|
||||
if (headerImage != null && enableIcon && items[itemIndex].itemButton.enableIcon) { headerImage.gameObject.SetActive(true); headerImage.sprite = items[itemIndex].itemButton.buttonIcon; }
|
||||
else if (headerImage != null && enableIcon && !items[itemIndex].itemButton.enableIcon) { headerImage.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
public void Animate()
|
||||
{
|
||||
if (!isOn)
|
||||
{
|
||||
if (enableScrollbar && scrollbar != null && startAtBottom)
|
||||
{
|
||||
scrollbar.value = 0;
|
||||
}
|
||||
|
||||
isOn = true;
|
||||
listCG.blocksRaycasts = true;
|
||||
listCG.interactable = true;
|
||||
listCG.gameObject.SetActive(true);
|
||||
|
||||
StopCoroutine("StartMinimize");
|
||||
StopCoroutine("StartExpand");
|
||||
StartCoroutine("StartExpand");
|
||||
}
|
||||
|
||||
else if (isOn)
|
||||
{
|
||||
isOn = false;
|
||||
listCG.blocksRaycasts = false;
|
||||
listCG.interactable = false;
|
||||
|
||||
StopCoroutine("StartMinimize");
|
||||
StopCoroutine("StartExpand");
|
||||
StartCoroutine("StartMinimize");
|
||||
}
|
||||
|
||||
if (enableTrigger && triggerObject != null && !isOn) { triggerObject.SetActive(false); }
|
||||
else if (enableTrigger && triggerObject != null && isOn) { triggerObject.SetActive(true); }
|
||||
if (enableTrigger && outOnPointerExit && triggerObject != null) { triggerObject.SetActive(false); }
|
||||
}
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
if (targetButton == null)
|
||||
{
|
||||
targetButton = gameObject.AddComponent<Button>();
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = navigationMode;
|
||||
|
||||
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
|
||||
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine("InitUINavigation", customNav); return; }
|
||||
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
|
||||
public void DisableUINavigation()
|
||||
{
|
||||
if (targetButton != null)
|
||||
{
|
||||
Navigation customNav = new Navigation();
|
||||
Navigation.Mode navMode = Navigation.Mode.None;
|
||||
customNav.mode = navMode;
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
}
|
||||
|
||||
public void Interactable(bool value)
|
||||
{
|
||||
isInteractable = value;
|
||||
if (gameObject.activeInHierarchy == false) { return; }
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void CreateNewItem(string title, Sprite icon, bool notify)
|
||||
{
|
||||
Item item = new Item();
|
||||
item.itemName = title;
|
||||
item.itemIcon = icon;
|
||||
items.Add(item);
|
||||
if (notify == true) { Initialize(); }
|
||||
}
|
||||
|
||||
public void CreateNewItem(string title, bool notify)
|
||||
{
|
||||
Item item = new Item();
|
||||
item.itemName = title;
|
||||
items.Add(item);
|
||||
if (notify == true) { Initialize(); }
|
||||
}
|
||||
|
||||
public void CreateNewItem(string title)
|
||||
{
|
||||
Item item = new Item();
|
||||
item.itemName = title;
|
||||
items.Add(item);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public void RemoveItem(string itemTitle, bool notify)
|
||||
{
|
||||
var item = items.Find(x => x.itemName == itemTitle);
|
||||
items.Remove(item);
|
||||
if (notify == true) { Initialize(); }
|
||||
}
|
||||
|
||||
public void RemoveItem(string itemTitle)
|
||||
{
|
||||
var item = items.Find(x => x.itemName == itemTitle);
|
||||
items.Remove(item);
|
||||
Initialize();
|
||||
}
|
||||
|
||||
public void UpdateItemLayout()
|
||||
{
|
||||
if (itemList == null)
|
||||
return;
|
||||
|
||||
itemList.spacing = itemSpacing;
|
||||
itemList.padding.top = itemPaddingTop;
|
||||
itemList.padding.bottom = itemPaddingBottom;
|
||||
itemList.padding.left = itemPaddingLeft;
|
||||
itemList.padding.right = itemPaddingRight;
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
Animate();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (outOnPointerExit && isOn) { Animate(); }
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
if (EventSystem.current.currentSelectedGameObject != gameObject) { StartCoroutine("SetNormal"); }
|
||||
}
|
||||
|
||||
IEnumerator StartExpand()
|
||||
{
|
||||
float elapsedTime = 0;
|
||||
|
||||
Vector2 startPos = listRect.sizeDelta;
|
||||
Vector2 endPos = new Vector2(listRect.sizeDelta.x, panelSize);
|
||||
|
||||
while (listRect.sizeDelta.y <= panelSize - 0.1f)
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
|
||||
listCG.alpha += Time.unscaledDeltaTime * (curveSpeed * 2);
|
||||
listRect.sizeDelta = Vector2.Lerp(startPos, endPos, animationCurve.Evaluate(elapsedTime * curveSpeed));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
listCG.alpha = 1;
|
||||
listRect.sizeDelta = endPos;
|
||||
}
|
||||
|
||||
IEnumerator StartMinimize()
|
||||
{
|
||||
float elapsedTime = 0;
|
||||
|
||||
Vector2 startPos = listRect.sizeDelta;
|
||||
Vector2 endPos = new Vector2(listRect.sizeDelta.x, 0);
|
||||
|
||||
while (listRect.sizeDelta.y >= 0.1f)
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
|
||||
listCG.alpha -= Time.unscaledDeltaTime * (curveSpeed * 2);
|
||||
listRect.sizeDelta = Vector2.Lerp(startPos, endPos, animationCurve.Evaluate(elapsedTime * curveSpeed));
|
||||
|
||||
yield return null;
|
||||
}
|
||||
|
||||
listCG.alpha = 0;
|
||||
listRect.sizeDelta = endPos;
|
||||
listCG.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
IEnumerator SetNormal()
|
||||
{
|
||||
StopCoroutine("SetHighlight");
|
||||
|
||||
while (highlightCG.alpha > 0.01f)
|
||||
{
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetHighlight()
|
||||
{
|
||||
StopCoroutine("SetNormal");
|
||||
|
||||
while (highlightCG.alpha < 0.99f)
|
||||
{
|
||||
highlightCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ae4666d06da1ed4eafab2e25b13aea1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- triggerObject: {instanceID: 0}
|
||||
- headerText: {instanceID: 0}
|
||||
- headerImage: {instanceID: 0}
|
||||
- itemParent: {instanceID: 0}
|
||||
- itemPreset: {fileID: 1168081051609938, guid: 5f072f268a6a4dd4d8ff2f0e18d93805,
|
||||
type: 3}
|
||||
- scrollbar: {instanceID: 0}
|
||||
- itemList: {instanceID: 0}
|
||||
- listParent: {instanceID: 0}
|
||||
- soundSource: {instanceID: 0}
|
||||
- currentListParent: {instanceID: 0}
|
||||
- listRect: {instanceID: 0}
|
||||
- listCG: {instanceID: 0}
|
||||
- hoverSound: {instanceID: 0}
|
||||
- clickSound: {instanceID: 0}
|
||||
- setItemText: {instanceID: 0}
|
||||
- setItemImage: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 94f186bfe92d7434198c876b4b138195, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/Dropdown.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,294 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using static UnityEngine.GraphicsBuffer;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(Dropdown))]
|
||||
public class DropdownEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private Dropdown dTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
dTarget = (Dropdown)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
|
||||
if (dTarget.selectedItemIndex > dTarget.items.Count - 1) { dTarget.selectedItemIndex = 0; }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Dropdown Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var items = serializedObject.FindProperty("items");
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
|
||||
var triggerObject = serializedObject.FindProperty("triggerObject");
|
||||
var headerText = serializedObject.FindProperty("headerText");
|
||||
var headerImage = serializedObject.FindProperty("headerImage");
|
||||
var itemParent = serializedObject.FindProperty("itemParent");
|
||||
var itemPreset = serializedObject.FindProperty("itemPreset");
|
||||
var scrollbar = serializedObject.FindProperty("scrollbar");
|
||||
var listRect = serializedObject.FindProperty("listRect");
|
||||
var listCG = serializedObject.FindProperty("listCG");
|
||||
var contentCG = serializedObject.FindProperty("contentCG");
|
||||
var highlightCG = serializedObject.FindProperty("highlightCG");
|
||||
|
||||
var panelDirection = serializedObject.FindProperty("panelDirection");
|
||||
var panelSize = serializedObject.FindProperty("panelSize");
|
||||
var curveSpeed = serializedObject.FindProperty("curveSpeed");
|
||||
var animationCurve = serializedObject.FindProperty("animationCurve");
|
||||
|
||||
var saveSelected = serializedObject.FindProperty("saveSelected");
|
||||
var saveKey = serializedObject.FindProperty("saveKey");
|
||||
var enableIcon = serializedObject.FindProperty("enableIcon");
|
||||
var enableTrigger = serializedObject.FindProperty("enableTrigger");
|
||||
var enableScrollbar = serializedObject.FindProperty("enableScrollbar");
|
||||
var startAtBottom = serializedObject.FindProperty("startAtBottom");
|
||||
var setHighPriority = serializedObject.FindProperty("setHighPriority");
|
||||
var outOnPointerExit = serializedObject.FindProperty("outOnPointerExit");
|
||||
var invokeOnEnable = serializedObject.FindProperty("invokeOnEnable");
|
||||
var initOnEnable = serializedObject.FindProperty("initOnEnable");
|
||||
var selectedItemIndex = serializedObject.FindProperty("selectedItemIndex");
|
||||
var useSounds = serializedObject.FindProperty("useSounds");
|
||||
var itemSpacing = serializedObject.FindProperty("itemSpacing");
|
||||
var itemPaddingLeft = serializedObject.FindProperty("itemPaddingLeft");
|
||||
var itemPaddingRight = serializedObject.FindProperty("itemPaddingRight");
|
||||
var itemPaddingTop = serializedObject.FindProperty("itemPaddingTop");
|
||||
var itemPaddingBottom = serializedObject.FindProperty("itemPaddingBottom");
|
||||
|
||||
var useUINavigation = serializedObject.FindProperty("useUINavigation");
|
||||
var navigationMode = serializedObject.FindProperty("navigationMode");
|
||||
var selectOnUp = serializedObject.FindProperty("selectOnUp");
|
||||
var selectOnDown = serializedObject.FindProperty("selectOnDown");
|
||||
var selectOnLeft = serializedObject.FindProperty("selectOnLeft");
|
||||
var selectOnRight = serializedObject.FindProperty("selectOnRight");
|
||||
var wrapAround = serializedObject.FindProperty("wrapAround");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (Application.isPlaying == false && dTarget.items.Count != 0)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.LabelField(new GUIContent("Selected Item:"), customSkin.FindStyle("Text"), GUILayout.Width(82));
|
||||
GUI.enabled = true;
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent(dTarget.items[selectedItemIndex.intValue].itemName), customSkin.FindStyle("Text"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
selectedItemIndex.intValue = EditorGUILayout.IntSlider(selectedItemIndex.intValue, 0, dTarget.items.Count - 1);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
else if (Application.isPlaying == true && dTarget.items.Count != 0)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUI.enabled = false;
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Item:"), customSkin.FindStyle("Text"), GUILayout.Width(74));
|
||||
EditorGUILayout.LabelField(new GUIContent(dTarget.items[dTarget.selectedItemIndex].itemName), customSkin.FindStyle("Text"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
EditorGUILayout.IntSlider(dTarget.index, 0, dTarget.items.Count - 1);
|
||||
|
||||
GUI.enabled = true;
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("There is no item in the list.", MessageType.Warning); }
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
EditorGUI.indentLevel = 1;
|
||||
EditorGUILayout.PropertyField(items, new GUIContent("Dropdown Items"), true);
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (Application.isPlaying == false && dTarget.contentCG != null)
|
||||
{
|
||||
if (dTarget.contentCG.alpha == 0 && GUILayout.Button("Show Content Preview", customSkin.button)) { dTarget.contentCG.alpha = 1; }
|
||||
else if (dTarget.contentCG.alpha == 1 && GUILayout.Button("Disable Content Preview", customSkin.button)) { dTarget.contentCG.alpha = 0; }
|
||||
}
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(triggerObject, customSkin, "Trigger Object");
|
||||
HeatUIEditorHandler.DrawProperty(headerText, customSkin, "Header Text");
|
||||
HeatUIEditorHandler.DrawProperty(headerImage, customSkin, "Header Image");
|
||||
HeatUIEditorHandler.DrawProperty(itemPreset, customSkin, "Item Preset");
|
||||
HeatUIEditorHandler.DrawProperty(itemParent, customSkin, "Item Parent");
|
||||
HeatUIEditorHandler.DrawProperty(scrollbar, customSkin, "Scrollbar");
|
||||
HeatUIEditorHandler.DrawProperty(highlightCG, customSkin, "Highlight CG");
|
||||
HeatUIEditorHandler.DrawProperty(contentCG, customSkin, "Content CG");
|
||||
HeatUIEditorHandler.DrawProperty(listCG, customSkin, "List CG");
|
||||
HeatUIEditorHandler.DrawProperty(listRect, customSkin, "List Rect");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Customization Header", 6);
|
||||
enableIcon.boolValue = HeatUIEditorHandler.DrawToggle(enableIcon.boolValue, customSkin, "Enable Header Icon");
|
||||
|
||||
if (dTarget.headerImage != null)
|
||||
{
|
||||
if (enableIcon.boolValue == true) { dTarget.headerImage.gameObject.SetActive(true); }
|
||||
else { dTarget.headerImage.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
else if (enableIcon.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox("'Header Image' is missing from the resources.", MessageType.Warning);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
enableScrollbar.boolValue = HeatUIEditorHandler.DrawToggle(enableScrollbar.boolValue, customSkin, "Enable Scrollbar");
|
||||
|
||||
if (dTarget.scrollbar != null)
|
||||
{
|
||||
if (enableScrollbar.boolValue == true) { dTarget.scrollbar.gameObject.SetActive(true); }
|
||||
else { dTarget.scrollbar.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
else if (enableScrollbar.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.HelpBox("'Scrollbar' is missing from the resources.", MessageType.Warning);
|
||||
GUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
startAtBottom.boolValue = HeatUIEditorHandler.DrawToggle(startAtBottom.boolValue, customSkin, "Start At Bottom");
|
||||
|
||||
HeatUIEditorHandler.DrawPropertyCW(itemSpacing, customSkin, "Item Spacing", 90);
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
EditorGUILayout.LabelField(new GUIContent("Item Padding"), customSkin.FindStyle("Text"), GUILayout.Width(90));
|
||||
GUILayout.EndHorizontal();
|
||||
EditorGUI.indentLevel = 1;
|
||||
|
||||
EditorGUILayout.PropertyField(itemPaddingTop, new GUIContent("Top"));
|
||||
EditorGUILayout.PropertyField(itemPaddingBottom, new GUIContent("Bottom"));
|
||||
EditorGUILayout.PropertyField(itemPaddingLeft, new GUIContent("Left"));
|
||||
EditorGUILayout.PropertyField(itemPaddingRight, new GUIContent("Right"));
|
||||
dTarget.UpdateItemLayout();
|
||||
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Animation Header", 10);
|
||||
HeatUIEditorHandler.DrawProperty(panelDirection, customSkin, "Panel Direction");
|
||||
HeatUIEditorHandler.DrawProperty(panelSize, customSkin, "Panel Size");
|
||||
HeatUIEditorHandler.DrawProperty(curveSpeed, customSkin, "Curve Speed");
|
||||
HeatUIEditorHandler.DrawProperty(animationCurve, customSkin, "Animation Curve");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 10);
|
||||
initOnEnable.boolValue = HeatUIEditorHandler.DrawToggle(initOnEnable.boolValue, customSkin, "Initialize On Enable");
|
||||
invokeOnEnable.boolValue = HeatUIEditorHandler.DrawToggle(invokeOnEnable.boolValue, customSkin, "Invoke On Enable", "Process events on awake.");
|
||||
|
||||
enableTrigger.boolValue = HeatUIEditorHandler.DrawToggle(enableTrigger.boolValue, customSkin, "Enable Trigger", "Clicking outside will close the dropdown.");
|
||||
if (enableTrigger.boolValue == true && dTarget.triggerObject == null) { EditorGUILayout.HelpBox("'Trigger Object' is missing from the resources.", MessageType.Warning); }
|
||||
|
||||
setHighPriority.boolValue = HeatUIEditorHandler.DrawToggle(setHighPriority.boolValue, customSkin, "Set High Priority");
|
||||
if (setHighPriority.boolValue == true) { EditorGUILayout.HelpBox("Set High Priority; renders the content above all objects when the dropdown is open.", MessageType.Info); }
|
||||
|
||||
outOnPointerExit.boolValue = HeatUIEditorHandler.DrawToggle(outOnPointerExit.boolValue, customSkin, "Out On Pointer Exit", "Close the dropdown on pointer exit.");
|
||||
useSounds.boolValue = HeatUIEditorHandler.DrawToggle(useSounds.boolValue, customSkin, "Use Sounds");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
saveSelected.boolValue = HeatUIEditorHandler.DrawTogglePlain(saveSelected.boolValue, customSkin, "Save Selected");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (saveSelected.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyPlainCW(saveKey, customSkin, "Save Key:", 66);
|
||||
EditorGUILayout.HelpBox("You must set a unique save key for each dropdown.", MessageType.Info);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
useUINavigation.boolValue = HeatUIEditorHandler.DrawTogglePlain(useUINavigation.boolValue, customSkin, "Use UI Navigation", "Enables controller navigation.");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (useUINavigation.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
HeatUIEditorHandler.DrawPropertyPlain(navigationMode, customSkin, "Navigation Mode");
|
||||
|
||||
if (dTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Horizontal)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawToggle(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
else if (dTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Vertical)
|
||||
{
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawTogglePlain(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
}
|
||||
|
||||
else if (dTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Explicit)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnUp, customSkin, "Select On Up");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnDown, customSkin, "Select On Down");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnLeft, customSkin, "Select On Left");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnRight, customSkin, "Select On Right");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 166a40e88eac6cb4786558bf9883177c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/DropdownEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,382 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class HorizontalSelector : MonoBehaviour
|
||||
{
|
||||
// Resources
|
||||
public TextMeshProUGUI label;
|
||||
[SerializeField] private TextMeshProUGUI labelHelper;
|
||||
public Image labelIcon;
|
||||
[SerializeField] private Image labelIconHelper;
|
||||
public Transform indicatorParent;
|
||||
public GameObject indicatorObject;
|
||||
[SerializeField] private Animator selectorAnimator;
|
||||
[SerializeField] private HorizontalLayoutGroup contentLayout;
|
||||
[SerializeField] private HorizontalLayoutGroup contentLayoutHelper;
|
||||
private string newItemTitle;
|
||||
|
||||
// Saving
|
||||
public bool saveSelected = false;
|
||||
public string saveKey = "Horizontal Selector";
|
||||
|
||||
// Settings
|
||||
public bool enableIndicator = true;
|
||||
public bool enableIcon = false;
|
||||
public bool invokeOnAwake = true;
|
||||
public bool invertAnimation;
|
||||
public bool loopSelection;
|
||||
public bool useLocalization = true;
|
||||
[Range(0.25f, 2.5f)] public float iconScale = 1;
|
||||
[Range(1, 50)] public int contentSpacing = 15;
|
||||
public int defaultIndex = 0;
|
||||
[HideInInspector] public int index = 0;
|
||||
|
||||
// Items
|
||||
public List<Item> items = new List<Item>();
|
||||
|
||||
// Events
|
||||
public HorizontalSelectorEvent onValueChanged = new HorizontalSelectorEvent();
|
||||
|
||||
// Helpers
|
||||
LocalizedObject localizedObject;
|
||||
float cachedStateLength;
|
||||
|
||||
[System.Serializable]
|
||||
public class Item
|
||||
{
|
||||
public string itemTitle = "Item Title";
|
||||
public string localizationKey;
|
||||
public Sprite itemIcon;
|
||||
public UnityEvent onItemSelect = new UnityEvent();
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
public class HorizontalSelectorEvent : UnityEvent<int> { }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (selectorAnimator == null) { selectorAnimator = gameObject.GetComponent<Animator>(); }
|
||||
if (label == null || labelHelper == null)
|
||||
{
|
||||
Debug.LogError("<b>[Horizontal Selector]</b> Cannot initalize the object due to missing resources.", this);
|
||||
return;
|
||||
}
|
||||
|
||||
InitializeSelector();
|
||||
UpdateContentLayout();
|
||||
|
||||
if (invokeOnAwake == true)
|
||||
{
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
}
|
||||
|
||||
cachedStateLength = HeatUIInternalTools.GetAnimatorClipLength(selectorAnimator, "HorizontalSelector_Next");
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
|
||||
if (useLocalization == true && !string.IsNullOrEmpty(items[index].localizationKey) && localizedObject.CheckLocalizationStatus() == true)
|
||||
{
|
||||
label.text = localizedObject.GetKeyOutput(items[index].localizationKey);
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeSelector()
|
||||
{
|
||||
if (items.Count == 0)
|
||||
return;
|
||||
|
||||
if (saveSelected == true)
|
||||
{
|
||||
if (PlayerPrefs.HasKey("HorizontalSelector_" + saveKey) == true) { defaultIndex = PlayerPrefs.GetInt("HorizontalSelector_" + saveKey); }
|
||||
else { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, defaultIndex); }
|
||||
}
|
||||
|
||||
label.text = items[defaultIndex].itemTitle;
|
||||
labelHelper.text = label.text;
|
||||
|
||||
if (labelIcon != null && enableIcon == true)
|
||||
{
|
||||
labelIcon.sprite = items[defaultIndex].itemIcon;
|
||||
labelIconHelper.sprite = labelIcon.sprite;
|
||||
}
|
||||
|
||||
else if (enableIcon == false)
|
||||
{
|
||||
if (labelIcon != null) { labelIcon.gameObject.SetActive(false); }
|
||||
if (labelIconHelper != null) { labelIconHelper.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
index = defaultIndex;
|
||||
|
||||
if (enableIndicator == true) { UpdateIndicators(); }
|
||||
else { Destroy(indicatorParent.gameObject); }
|
||||
|
||||
if (useLocalization == true)
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
|
||||
if (localizedObject == null || localizedObject.CheckLocalizationStatus() == false) { useLocalization = false; }
|
||||
else if (useLocalization == true) { localizedObject.onLanguageChanged.AddListener(delegate { UpdateUI(); }); }
|
||||
}
|
||||
}
|
||||
|
||||
public void PreviousItem()
|
||||
{
|
||||
if (items.Count == 0) { return; }
|
||||
StopCoroutine("DisableAnimator");
|
||||
|
||||
selectorAnimator.enabled = true;
|
||||
|
||||
if (loopSelection == false)
|
||||
{
|
||||
if (index != 0)
|
||||
{
|
||||
// Change the label helper text
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
|
||||
|
||||
// Change the index
|
||||
if (index == 0) { index = items.Count - 1; }
|
||||
else { index--; }
|
||||
|
||||
// Check for localization and change the label
|
||||
if (useLocalization == true && !string.IsNullOrEmpty(items[index].localizationKey)) { label.text = localizedObject.GetKeyOutput(items[index].localizationKey); }
|
||||
else { label.text = items[index].itemTitle; }
|
||||
|
||||
// Change the label icon
|
||||
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
// Invoke events
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
// Reset playback
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
// Play the animation
|
||||
if (invertAnimation == true) { selectorAnimator.Play("Next"); }
|
||||
else { selectorAnimator.Play("Prev"); }
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Change the label helper text
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
|
||||
|
||||
// Change the index
|
||||
if (index == 0) { index = items.Count - 1; }
|
||||
else { index--; }
|
||||
|
||||
// Check for localization and change the label
|
||||
if (useLocalization == true && !string.IsNullOrEmpty(items[index].localizationKey)) { label.text = localizedObject.GetKeyOutput(items[index].localizationKey); }
|
||||
else { label.text = items[index].itemTitle; }
|
||||
|
||||
// Change the label icon
|
||||
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
// Invoke events
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
// Reset playback
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
// Play the animation
|
||||
if (invertAnimation == true) { selectorAnimator.Play("Next"); }
|
||||
else { selectorAnimator.Play("Prev"); }
|
||||
}
|
||||
|
||||
if (saveSelected == true) { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, index); }
|
||||
if (enableIndicator == true)
|
||||
{
|
||||
for (int i = 0; i < items.Count; ++i)
|
||||
{
|
||||
GameObject go = indicatorParent.GetChild(i).gameObject;
|
||||
Transform onObj = go.transform.Find("On");
|
||||
Transform offObj = go.transform.Find("Off");
|
||||
|
||||
if (i == index) { onObj.gameObject.SetActive(true); offObj.gameObject.SetActive(false); }
|
||||
else { onObj.gameObject.SetActive(false); offObj.gameObject.SetActive(true); }
|
||||
}
|
||||
}
|
||||
|
||||
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
|
||||
}
|
||||
|
||||
public void NextItem()
|
||||
{
|
||||
if (items.Count == 0) { return; }
|
||||
StopCoroutine("DisableAnimator");
|
||||
|
||||
selectorAnimator.enabled = true;
|
||||
|
||||
if (loopSelection == false)
|
||||
{
|
||||
if (index != items.Count - 1)
|
||||
{
|
||||
// Change the label helper text
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
|
||||
|
||||
// Change the index
|
||||
if ((index + 1) >= items.Count) { index = 0; }
|
||||
else { index++; }
|
||||
|
||||
// Check for localization and change the label
|
||||
if (useLocalization == true && !string.IsNullOrEmpty(items[index].localizationKey)) { label.text = localizedObject.GetKeyOutput(items[index].localizationKey); }
|
||||
else { label.text = items[index].itemTitle; }
|
||||
|
||||
// Change the label icon
|
||||
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
// Invoke events
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
// Reset playback
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
// Play the animation
|
||||
if (invertAnimation == true) { selectorAnimator.Play("Prev"); }
|
||||
else { selectorAnimator.Play("Next"); }
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
// Change the label helper text
|
||||
labelHelper.text = label.text;
|
||||
if (labelIcon != null && enableIcon == true) { labelIconHelper.sprite = labelIcon.sprite; }
|
||||
|
||||
// Change the index
|
||||
if ((index + 1) >= items.Count) { index = 0; }
|
||||
else { index++; }
|
||||
|
||||
// Check for localization and change the label
|
||||
if (useLocalization == true && !string.IsNullOrEmpty(items[index].localizationKey)) { label.text = localizedObject.GetKeyOutput(items[index].localizationKey); }
|
||||
else { label.text = items[index].itemTitle; }
|
||||
|
||||
// Change the label icon
|
||||
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
// Invoke events
|
||||
items[index].onItemSelect.Invoke();
|
||||
onValueChanged.Invoke(index);
|
||||
|
||||
// Reset playback
|
||||
selectorAnimator.Play(null);
|
||||
selectorAnimator.StopPlayback();
|
||||
|
||||
// Play the animation
|
||||
if (invertAnimation == true) { selectorAnimator.Play("Prev"); }
|
||||
else { selectorAnimator.Play("Next"); }
|
||||
}
|
||||
|
||||
if (saveSelected == true) { PlayerPrefs.SetInt("HorizontalSelector_" + saveKey, index); }
|
||||
if (enableIndicator == true)
|
||||
{
|
||||
for (int i = 0; i < items.Count; ++i)
|
||||
{
|
||||
GameObject go = indicatorParent.GetChild(i).gameObject;
|
||||
Transform onObj = go.transform.Find("On"); ;
|
||||
Transform offObj = go.transform.Find("Off");
|
||||
|
||||
if (i == index) { onObj.gameObject.SetActive(true); offObj.gameObject.SetActive(false); }
|
||||
else { onObj.gameObject.SetActive(false); offObj.gameObject.SetActive(true); }
|
||||
}
|
||||
}
|
||||
|
||||
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
selectorAnimator.enabled = true;
|
||||
|
||||
if (useLocalization == true && !string.IsNullOrEmpty(items[index].localizationKey)) { label.text = localizedObject.GetKeyOutput(items[index].localizationKey); }
|
||||
else { label.text = items[index].itemTitle; }
|
||||
|
||||
if (labelIcon != null && enableIcon == true) { labelIcon.sprite = items[index].itemIcon; }
|
||||
|
||||
UpdateContentLayout();
|
||||
UpdateIndicators();
|
||||
|
||||
if (gameObject.activeInHierarchy == true) { StartCoroutine("DisableAnimator"); }
|
||||
}
|
||||
|
||||
public void UpdateIndicators()
|
||||
{
|
||||
if (enableIndicator == false)
|
||||
return;
|
||||
|
||||
foreach (Transform child in indicatorParent) { Destroy(child.gameObject); }
|
||||
for (int i = 0; i < items.Count; ++i)
|
||||
{
|
||||
GameObject go = Instantiate(indicatorObject, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
go.transform.SetParent(indicatorParent, false);
|
||||
go.name = items[i].itemTitle;
|
||||
|
||||
Transform onObj = go.transform.Find("On");
|
||||
Transform offObj = go.transform.Find("Off");
|
||||
|
||||
if (i == index) { onObj.gameObject.SetActive(true); offObj.gameObject.SetActive(false); }
|
||||
else { onObj.gameObject.SetActive(false); offObj.gameObject.SetActive(true); }
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateContentLayout()
|
||||
{
|
||||
if (contentLayout != null) { contentLayout.spacing = contentSpacing; }
|
||||
if (contentLayoutHelper != null) { contentLayoutHelper.spacing = contentSpacing; }
|
||||
if (labelIcon != null)
|
||||
{
|
||||
labelIcon.transform.localScale = new Vector3(iconScale, iconScale, iconScale);
|
||||
labelIconHelper.transform.localScale = new Vector3(iconScale, iconScale, iconScale);
|
||||
}
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(label.transform.parent.GetComponent<RectTransform>());
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSeconds(cachedStateLength + 0.1f);
|
||||
selectorAnimator.enabled = false;
|
||||
}
|
||||
|
||||
public void CreateNewItem(string title)
|
||||
{
|
||||
Item item = new Item();
|
||||
newItemTitle = title;
|
||||
item.itemTitle = newItemTitle;
|
||||
items.Add(item);
|
||||
}
|
||||
|
||||
public void RemoveItem(string itemTitle)
|
||||
{
|
||||
var item = items.Find(x => x.itemTitle == itemTitle);
|
||||
items.Remove(item);
|
||||
InitializeSelector();
|
||||
}
|
||||
|
||||
public void AddNewItem()
|
||||
{
|
||||
Item item = new Item();
|
||||
items.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9480998de676f6f46a59ce95b921fa36
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- label: {instanceID: 0}
|
||||
- labelHelper: {instanceID: 0}
|
||||
- labelIcon: {instanceID: 0}
|
||||
- labelIconHelper: {instanceID: 0}
|
||||
- indicatorParent: {instanceID: 0}
|
||||
- indicatorObject: {fileID: 8360441540658657422, guid: 0f37587388222c44cbb87b9df75ab411,
|
||||
type: 3}
|
||||
- selectorAnimator: {instanceID: 0}
|
||||
- contentLayout: {instanceID: 0}
|
||||
- contentLayoutHelper: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7185ad69366eadd4daaf3c522d870eb4, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/HorizontalSelector.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,205 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(HorizontalSelector))]
|
||||
public class HorizontalSelectorEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private HorizontalSelector hsTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
hsTarget = (HorizontalSelector)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Horizontal Selector Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var items = serializedObject.FindProperty("items");
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
var defaultIndex = serializedObject.FindProperty("defaultIndex");
|
||||
|
||||
var label = serializedObject.FindProperty("label");
|
||||
var selectorAnimator = serializedObject.FindProperty("selectorAnimator");
|
||||
var labelHelper = serializedObject.FindProperty("labelHelper");
|
||||
var labelIcon = serializedObject.FindProperty("labelIcon");
|
||||
var labelIconHelper = serializedObject.FindProperty("labelIconHelper");
|
||||
var indicatorParent = serializedObject.FindProperty("indicatorParent");
|
||||
var indicatorObject = serializedObject.FindProperty("indicatorObject");
|
||||
var contentLayout = serializedObject.FindProperty("contentLayout");
|
||||
var contentLayoutHelper = serializedObject.FindProperty("contentLayoutHelper");
|
||||
|
||||
var enableIcon = serializedObject.FindProperty("enableIcon");
|
||||
var saveSelected = serializedObject.FindProperty("saveSelected");
|
||||
var saveKey = serializedObject.FindProperty("saveKey");
|
||||
var enableIndicator = serializedObject.FindProperty("enableIndicator");
|
||||
var invokeOnAwake = serializedObject.FindProperty("invokeOnAwake");
|
||||
var invertAnimation = serializedObject.FindProperty("invertAnimation");
|
||||
var loopSelection = serializedObject.FindProperty("loopSelection");
|
||||
var iconScale = serializedObject.FindProperty("iconScale");
|
||||
var contentSpacing = serializedObject.FindProperty("contentSpacing");
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (Application.isPlaying == false && hsTarget.items.Count != 0)
|
||||
{
|
||||
if (hsTarget.defaultIndex >= hsTarget.items.Count) { hsTarget.defaultIndex = 0; }
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.LabelField(new GUIContent("Default Item:"), customSkin.FindStyle("Text"), GUILayout.Width(74));
|
||||
GUI.enabled = true;
|
||||
EditorGUILayout.LabelField(new GUIContent(hsTarget.items[defaultIndex.intValue].itemTitle), customSkin.FindStyle("Text"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
defaultIndex.intValue = EditorGUILayout.IntSlider(defaultIndex.intValue, 0, hsTarget.items.Count - 1);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
else if (Application.isPlaying == true && hsTarget.items.Count != 0)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUI.enabled = false;
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Item:"), customSkin.FindStyle("Text"), GUILayout.Width(74));
|
||||
EditorGUILayout.LabelField(new GUIContent(hsTarget.items[hsTarget.index].itemTitle), customSkin.FindStyle("Text"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
EditorGUILayout.IntSlider(hsTarget.index, 0, hsTarget.items.Count - 1);
|
||||
|
||||
GUI.enabled = true;
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("There is no item in the list.", MessageType.Warning); }
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
EditorGUI.indentLevel = 1;
|
||||
|
||||
EditorGUILayout.PropertyField(items, new GUIContent("Selector Items"), true);
|
||||
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(selectorAnimator, customSkin, "Animator");
|
||||
HeatUIEditorHandler.DrawProperty(label, customSkin, "Label");
|
||||
HeatUIEditorHandler.DrawProperty(labelHelper, customSkin, "Label Helper");
|
||||
HeatUIEditorHandler.DrawProperty(labelIcon, customSkin, "Label Icon");
|
||||
HeatUIEditorHandler.DrawProperty(labelIconHelper, customSkin, "Label Icon Helper");
|
||||
HeatUIEditorHandler.DrawProperty(indicatorParent, customSkin, "Indicator Parent");
|
||||
HeatUIEditorHandler.DrawProperty(indicatorObject, customSkin, "Indicator Object");
|
||||
HeatUIEditorHandler.DrawProperty(contentLayout, customSkin, "Content Layout");
|
||||
HeatUIEditorHandler.DrawProperty(contentLayoutHelper, customSkin, "Content Layout Helper");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Customization Header", 6);
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
enableIndicator.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableIndicator.boolValue, customSkin, "Enable Indicators");
|
||||
GUILayout.Space(3);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
if (enableIndicator.boolValue == true)
|
||||
{
|
||||
if (hsTarget.indicatorObject == null) { EditorGUILayout.HelpBox("'Enable Indicator' is enabled but 'Indicator Object' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error); }
|
||||
if (hsTarget.indicatorParent == null) { EditorGUILayout.HelpBox("'Enable Indicator' is enabled but 'Indicator Parent' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error); }
|
||||
else { hsTarget.indicatorParent.gameObject.SetActive(true); }
|
||||
}
|
||||
|
||||
else if (enableIndicator.boolValue == false && hsTarget.indicatorParent != null)
|
||||
hsTarget.indicatorParent.gameObject.SetActive(false);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
enableIcon.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableIcon.boolValue, customSkin, "Enable Icon");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (enableIcon.boolValue == true && hsTarget.labelIcon == null)
|
||||
EditorGUILayout.HelpBox("'Enable Icon' is enabled but 'Label Icon' is not assigned. Go to Resources tab and assign the correct variable.", MessageType.Error);
|
||||
else if (enableIcon.boolValue == true && hsTarget.labelIcon != null)
|
||||
hsTarget.labelIcon.gameObject.SetActive(true);
|
||||
else if (enableIcon.boolValue == false && hsTarget.labelIcon != null)
|
||||
hsTarget.labelIcon.gameObject.SetActive(false);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (enableIcon.boolValue == false) { GUI.enabled = false; }
|
||||
HeatUIEditorHandler.DrawProperty(iconScale, customSkin, "Icon Scale");
|
||||
HeatUIEditorHandler.DrawProperty(contentSpacing, customSkin, "Content Spacing");
|
||||
GUI.enabled = true;
|
||||
hsTarget.UpdateContentLayout();
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 10);
|
||||
invokeOnAwake.boolValue = HeatUIEditorHandler.DrawToggle(invokeOnAwake.boolValue, customSkin, "Invoke On Awake", "Process events on awake.");
|
||||
invertAnimation.boolValue = HeatUIEditorHandler.DrawToggle(invertAnimation.boolValue, customSkin, "Invert Animation");
|
||||
loopSelection.boolValue = HeatUIEditorHandler.DrawToggle(loopSelection.boolValue, customSkin, "Loop Selection");
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
saveSelected.boolValue = HeatUIEditorHandler.DrawTogglePlain(saveSelected.boolValue, customSkin, "Save Selected");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (saveSelected.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(saveKey, customSkin, "Save Key:", 66);
|
||||
EditorGUILayout.HelpBox("You must set a unique save key for each selector.", MessageType.Info);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53368fd7ebe9bbc43833ccf7baa3c947
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/HorizontalSelectorEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,93 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(TMP_InputField))]
|
||||
public class InputFieldManager : MonoBehaviour
|
||||
{
|
||||
[Header("Resources")]
|
||||
public TMP_InputField inputText;
|
||||
public Animator inputFieldAnimator;
|
||||
|
||||
[Header("Settings")]
|
||||
public bool processSubmit = false;
|
||||
public bool clearOnSubmit = false;
|
||||
|
||||
[Header("Events")]
|
||||
public UnityEvent onSubmit;
|
||||
|
||||
// Helpers
|
||||
float cachedStateLength = 0.25f;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (inputText == null) { inputText = gameObject.GetComponent<TMP_InputField>(); }
|
||||
if (clearOnSubmit) { onSubmit.AddListener(delegate { inputText.text = ""; }); }
|
||||
|
||||
inputText.onValueChanged.AddListener(delegate { UpdateState(); });
|
||||
inputText.onSelect.AddListener(delegate { AnimateIn(); });
|
||||
inputText.onEndEdit.AddListener(delegate { AnimateOut(); });
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (inputText == null) { return; }
|
||||
if (inputFieldAnimator != null && gameObject.activeInHierarchy) { StartCoroutine("DisableAnimator"); }
|
||||
|
||||
inputText.ForceLabelUpdate();
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (!processSubmit || string.IsNullOrEmpty(inputText.text) || EventSystem.current.currentSelectedGameObject != inputText.gameObject) { return; }
|
||||
if (Keyboard.current.enterKey.wasPressedThisFrame) { onSubmit.Invoke(); }
|
||||
}
|
||||
|
||||
public void AnimateIn()
|
||||
{
|
||||
if (inputFieldAnimator != null && inputFieldAnimator.gameObject.activeInHierarchy)
|
||||
{
|
||||
inputFieldAnimator.enabled = true;
|
||||
inputFieldAnimator.Play("In");
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
}
|
||||
|
||||
public void AnimateOut()
|
||||
{
|
||||
if (inputFieldAnimator != null && inputFieldAnimator.gameObject.activeInHierarchy)
|
||||
{
|
||||
inputFieldAnimator.enabled = true;
|
||||
if (inputText.text.Length == 0) { inputFieldAnimator.Play("Out"); }
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
if (inputText.text.Length == 0) { AnimateOut(); }
|
||||
else { AnimateIn(); }
|
||||
}
|
||||
|
||||
public void InvokeSubmit()
|
||||
{
|
||||
onSubmit.Invoke();
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSeconds(cachedStateLength);
|
||||
inputFieldAnimator.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2edfcad6e706d6349b60582dfd7fe738
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: d86eb75d994cd12488cc5c5e1b55a69b, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/InputFieldManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,221 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class ModalWindowManager : MonoBehaviour
|
||||
{
|
||||
// Resources
|
||||
public Image windowIcon;
|
||||
public TextMeshProUGUI windowTitle;
|
||||
public TextMeshProUGUI windowDescription;
|
||||
public ButtonManager confirmButton;
|
||||
public ButtonManager cancelButton;
|
||||
[SerializeField] private Animator mwAnimator;
|
||||
|
||||
// Content
|
||||
public Sprite icon;
|
||||
public string titleText = "Title";
|
||||
[TextArea(0, 4)] public string descriptionText = "Description here";
|
||||
|
||||
// Localization
|
||||
public string titleKey;
|
||||
public string descriptionKey;
|
||||
|
||||
// Settings
|
||||
public bool useCustomContent = false;
|
||||
public bool isOn = false;
|
||||
public bool closeOnCancel = true;
|
||||
public bool closeOnConfirm = true;
|
||||
public bool showCancelButton = true;
|
||||
public bool showConfirmButton = true;
|
||||
public bool useLocalization = true;
|
||||
[Range(0.5f, 2)] public float animationSpeed = 1;
|
||||
public StartBehaviour startBehaviour = StartBehaviour.Disable;
|
||||
public CloseBehaviour closeBehaviour = CloseBehaviour.Disable;
|
||||
public InputType inputType = InputType.Focused;
|
||||
|
||||
// Events
|
||||
public UnityEvent onConfirm = new UnityEvent();
|
||||
public UnityEvent onCancel = new UnityEvent();
|
||||
public UnityEvent onOpen = new UnityEvent();
|
||||
public UnityEvent onClose = new UnityEvent();
|
||||
|
||||
// Helpers
|
||||
string animIn = "In";
|
||||
string animOut = "Out";
|
||||
string animSpeedKey = "AnimSpeed";
|
||||
|
||||
// Event System
|
||||
bool canProcessEventSystem;
|
||||
float openStateLength;
|
||||
float closeStateLength;
|
||||
GameObject latestEventSystemObject;
|
||||
|
||||
public enum StartBehaviour { Enable, Disable }
|
||||
public enum CloseBehaviour { Disable, Destroy }
|
||||
public enum InputType { Focused, Free }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
InitModalWindow();
|
||||
InitEventSystem();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (startBehaviour == StartBehaviour.Disable) { isOn = false; gameObject.SetActive(false); }
|
||||
else if (startBehaviour == StartBehaviour.Enable) { isOn = false; OpenWindow(); }
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (inputType == InputType.Free || !isOn || !canProcessEventSystem || !ControllerManager.instance.gamepadEnabled)
|
||||
return;
|
||||
|
||||
CheckForEventButtons();
|
||||
}
|
||||
|
||||
void InitModalWindow()
|
||||
{
|
||||
if (mwAnimator == null) { mwAnimator = gameObject.GetComponent<Animator>(); }
|
||||
if (closeOnCancel) { onCancel.AddListener(CloseWindow); }
|
||||
if (closeOnConfirm) { onConfirm.AddListener(CloseWindow); }
|
||||
if (confirmButton != null) { confirmButton.onClick.AddListener(onConfirm.Invoke); }
|
||||
if (cancelButton != null) { cancelButton.onClick.AddListener(onCancel.Invoke); }
|
||||
if (useLocalization && !useCustomContent)
|
||||
{
|
||||
LocalizedObject mainLoc = GetComponent<LocalizedObject>();
|
||||
|
||||
if (mainLoc == null || !mainLoc.CheckLocalizationStatus()) { useLocalization = false; }
|
||||
else
|
||||
{
|
||||
if (windowTitle != null && !string.IsNullOrEmpty(titleKey))
|
||||
{
|
||||
LocalizedObject titleLoc = windowTitle.gameObject.GetComponent<LocalizedObject>();
|
||||
if (titleLoc != null)
|
||||
{
|
||||
titleLoc.tableIndex = mainLoc.tableIndex;
|
||||
titleLoc.localizationKey = titleKey;
|
||||
titleLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
if (windowDescription != null && !string.IsNullOrEmpty(descriptionKey))
|
||||
{
|
||||
LocalizedObject descLoc = windowDescription.gameObject.GetComponent<LocalizedObject>();
|
||||
if (descLoc != null)
|
||||
{
|
||||
descLoc.tableIndex = mainLoc.tableIndex;
|
||||
descLoc.localizationKey = descriptionKey;
|
||||
descLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
openStateLength = HeatUIInternalTools.GetAnimatorClipLength(mwAnimator, "ModalWindow_In");
|
||||
closeStateLength = HeatUIInternalTools.GetAnimatorClipLength(mwAnimator, "ModalWindow_Out");
|
||||
}
|
||||
|
||||
void InitEventSystem()
|
||||
{
|
||||
if (ControllerManager.instance == null) { canProcessEventSystem = false; }
|
||||
else if (cancelButton == null && confirmButton == null) { canProcessEventSystem = false; }
|
||||
else { canProcessEventSystem = true; }
|
||||
}
|
||||
|
||||
void CheckForEventButtons()
|
||||
{
|
||||
if (cancelButton != null && EventSystem.current.currentSelectedGameObject != cancelButton.gameObject && EventSystem.current.currentSelectedGameObject != confirmButton.gameObject) { ControllerManager.instance.SelectUIObject(cancelButton.gameObject); }
|
||||
else if (confirmButton != null && EventSystem.current.currentSelectedGameObject != cancelButton.gameObject && EventSystem.current.currentSelectedGameObject != confirmButton.gameObject) { ControllerManager.instance.SelectUIObject(confirmButton.gameObject); }
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (!useCustomContent)
|
||||
{
|
||||
if (windowIcon != null) { windowIcon.sprite = icon; }
|
||||
if (windowTitle != null && (!useLocalization || string.IsNullOrEmpty(titleKey))) { windowTitle.text = titleText; }
|
||||
if (windowDescription != null && (!useLocalization || string.IsNullOrEmpty(titleKey))) { windowDescription.text = descriptionText; }
|
||||
}
|
||||
|
||||
if (showCancelButton && cancelButton != null) { cancelButton.gameObject.SetActive(true); }
|
||||
else if (cancelButton != null) { cancelButton.gameObject.SetActive(false); }
|
||||
|
||||
if (showConfirmButton && confirmButton != null) { confirmButton.gameObject.SetActive(true); }
|
||||
else if (confirmButton != null) { confirmButton.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
public void OpenWindow()
|
||||
{
|
||||
if (isOn) { return; }
|
||||
if (EventSystem.current.currentSelectedGameObject != null) { latestEventSystemObject = EventSystem.current.currentSelectedGameObject; }
|
||||
|
||||
gameObject.SetActive(true);
|
||||
isOn = true;
|
||||
|
||||
StopCoroutine("DisableObject");
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
|
||||
mwAnimator.enabled = true;
|
||||
mwAnimator.SetFloat(animSpeedKey, animationSpeed);
|
||||
mwAnimator.Play(animIn);
|
||||
onOpen.Invoke();
|
||||
}
|
||||
|
||||
public void CloseWindow()
|
||||
{
|
||||
if (!isOn)
|
||||
return;
|
||||
|
||||
if (gameObject.activeSelf == true)
|
||||
{
|
||||
StopCoroutine("DisableObject");
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableObject");
|
||||
}
|
||||
|
||||
isOn = false;
|
||||
mwAnimator.enabled = true;
|
||||
mwAnimator.SetFloat(animSpeedKey, animationSpeed);
|
||||
mwAnimator.Play(animOut);
|
||||
onClose.Invoke();
|
||||
|
||||
if (ControllerManager.instance != null && latestEventSystemObject != null && latestEventSystemObject.activeInHierarchy)
|
||||
{
|
||||
ControllerManager.instance.SelectUIObject(latestEventSystemObject);
|
||||
}
|
||||
}
|
||||
|
||||
public void AnimateWindow()
|
||||
{
|
||||
if (!isOn) { OpenWindow(); }
|
||||
else { CloseWindow(); }
|
||||
}
|
||||
|
||||
IEnumerator DisableObject()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(closeStateLength);
|
||||
|
||||
if (closeBehaviour == CloseBehaviour.Disable) { gameObject.SetActive(false); }
|
||||
else if (closeBehaviour == CloseBehaviour.Destroy) { Destroy(gameObject); }
|
||||
|
||||
mwAnimator.enabled = false;
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(openStateLength + 0.1f);
|
||||
mwAnimator.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cac22f8f370b40a40bf4ab7308623738
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 5d812a96326edbf4f9ac91a9d39a79df, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ModalWindowManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,166 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(ModalWindowManager))]
|
||||
public class ModalWindowManagerEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private ModalWindowManager mwTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
mwTarget = (ModalWindowManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Modal WIndow Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var windowIcon = serializedObject.FindProperty("windowIcon");
|
||||
var windowTitle = serializedObject.FindProperty("windowTitle");
|
||||
var windowDescription = serializedObject.FindProperty("windowDescription");
|
||||
|
||||
var titleKey = serializedObject.FindProperty("titleKey");
|
||||
var descriptionKey = serializedObject.FindProperty("descriptionKey");
|
||||
|
||||
var onConfirm = serializedObject.FindProperty("onConfirm");
|
||||
var onCancel = serializedObject.FindProperty("onCancel");
|
||||
var onOpen = serializedObject.FindProperty("onOpen");
|
||||
var onClose = serializedObject.FindProperty("onClose");
|
||||
|
||||
var icon = serializedObject.FindProperty("icon");
|
||||
var titleText = serializedObject.FindProperty("titleText");
|
||||
var descriptionText = serializedObject.FindProperty("descriptionText");
|
||||
var confirmButton = serializedObject.FindProperty("confirmButton");
|
||||
var cancelButton = serializedObject.FindProperty("cancelButton");
|
||||
var mwAnimator = serializedObject.FindProperty("mwAnimator");
|
||||
|
||||
var closeBehaviour = serializedObject.FindProperty("closeBehaviour");
|
||||
var startBehaviour = serializedObject.FindProperty("startBehaviour");
|
||||
var useCustomContent = serializedObject.FindProperty("useCustomContent");
|
||||
var closeOnCancel = serializedObject.FindProperty("closeOnCancel");
|
||||
var closeOnConfirm = serializedObject.FindProperty("closeOnConfirm");
|
||||
var showCancelButton = serializedObject.FindProperty("showCancelButton");
|
||||
var showConfirmButton = serializedObject.FindProperty("showConfirmButton");
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var animationSpeed = serializedObject.FindProperty("animationSpeed");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (useCustomContent.boolValue == false)
|
||||
{
|
||||
if (mwTarget.windowIcon != null)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(icon, customSkin, "Icon");
|
||||
if (Application.isPlaying == false) { mwTarget.windowIcon.sprite = mwTarget.icon; }
|
||||
}
|
||||
|
||||
if (mwTarget.windowTitle != null)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(titleText, customSkin, "Title");
|
||||
if (Application.isPlaying == false) { mwTarget.windowTitle.text = titleText.stringValue; }
|
||||
}
|
||||
|
||||
if (mwTarget.windowDescription != null)
|
||||
{
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Description"), customSkin.FindStyle("Text"), GUILayout.Width(-3));
|
||||
EditorGUILayout.PropertyField(descriptionText, new GUIContent(""));
|
||||
GUILayout.EndHorizontal();
|
||||
if (Application.isPlaying == false) { mwTarget.windowDescription.text = descriptionText.stringValue; }
|
||||
}
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("'Use Custom Content' is enabled.", MessageType.Info); }
|
||||
|
||||
GUILayout.BeginHorizontal();
|
||||
if (mwTarget.showConfirmButton == true && mwTarget.confirmButton != null && GUILayout.Button("Edit Confirm Button", customSkin.button)) { Selection.activeObject = mwTarget.confirmButton; }
|
||||
if (mwTarget.showCancelButton == true && mwTarget.cancelButton != null && GUILayout.Button("Edit Cancel Button", customSkin.button)) { Selection.activeObject = mwTarget.cancelButton; }
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (Application.isPlaying == false)
|
||||
{
|
||||
if (mwTarget.GetComponent<CanvasGroup>().alpha == 0 && GUILayout.Button("Set Visible", customSkin.button))
|
||||
{
|
||||
mwTarget.GetComponent<CanvasGroup>().alpha = 1;
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
|
||||
else if (mwTarget.GetComponent<CanvasGroup>().alpha == 1 && GUILayout.Button("Set Invisible", customSkin.button))
|
||||
{
|
||||
mwTarget.GetComponent<CanvasGroup>().alpha = 0;
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
}
|
||||
|
||||
if (mwTarget.useCustomContent == false && mwTarget.useLocalization == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Languages Header", 10);
|
||||
HeatUIEditorHandler.DrawProperty(titleKey, customSkin, "Title Key", "Used for localization.");
|
||||
HeatUIEditorHandler.DrawProperty(descriptionKey, customSkin, "Description Key", "Used for localization.");
|
||||
}
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onConfirm, new GUIContent("On Confirm"), true);
|
||||
EditorGUILayout.PropertyField(onCancel, new GUIContent("On Cancel"), true);
|
||||
EditorGUILayout.PropertyField(onOpen, new GUIContent("On Open"), true);
|
||||
EditorGUILayout.PropertyField(onClose, new GUIContent("On Close"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(windowIcon, customSkin, "Icon Object");
|
||||
HeatUIEditorHandler.DrawProperty(windowTitle, customSkin, "Title Object");
|
||||
HeatUIEditorHandler.DrawProperty(windowDescription, customSkin, "Description Object");
|
||||
HeatUIEditorHandler.DrawProperty(confirmButton, customSkin, "Confirm Button");
|
||||
HeatUIEditorHandler.DrawProperty(cancelButton, customSkin, "Cancel Button");
|
||||
HeatUIEditorHandler.DrawProperty(mwAnimator, customSkin, "Animator");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(animationSpeed, customSkin, "Animation Speed");
|
||||
HeatUIEditorHandler.DrawProperty(startBehaviour, customSkin, "Start Behaviour");
|
||||
HeatUIEditorHandler.DrawProperty(closeBehaviour, customSkin, "Close Behaviour");
|
||||
useCustomContent.boolValue = HeatUIEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content", "Bypasses inspector values and allows manual editing.");
|
||||
closeOnCancel.boolValue = HeatUIEditorHandler.DrawToggle(closeOnCancel.boolValue, customSkin, "Close Window On Cancel");
|
||||
closeOnConfirm.boolValue = HeatUIEditorHandler.DrawToggle(closeOnConfirm.boolValue, customSkin, "Close Window On Confirm");
|
||||
showCancelButton.boolValue = HeatUIEditorHandler.DrawToggle(showCancelButton.boolValue, customSkin, "Show Cancel Button");
|
||||
showConfirmButton.boolValue = HeatUIEditorHandler.DrawToggle(showConfirmButton.boolValue, customSkin, "Show Confirm Button");
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e08211ebac4e0d4dae1496de0fafde5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ModalWindowManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,258 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class NewsSlider : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public List<Item> items = new List<Item>();
|
||||
private List<Animator> timers = new List<Animator>();
|
||||
|
||||
// Resources
|
||||
[SerializeField] private GameObject itemPreset;
|
||||
[SerializeField] private Transform itemParent;
|
||||
[SerializeField] private GameObject timerPreset;
|
||||
[SerializeField] private Transform timerParent;
|
||||
|
||||
// Settings
|
||||
public bool useLocalization = true;
|
||||
[Range(1, 30)] public float sliderTimer = 4;
|
||||
|
||||
// Helpers
|
||||
Animator currentItemObject;
|
||||
Animator currentIndicatorObject;
|
||||
Image currentIndicatorBar;
|
||||
int currentSliderIndex;
|
||||
float sliderTimerBar;
|
||||
bool isInitialized;
|
||||
LocalizedObject localizedObject;
|
||||
|
||||
[System.Serializable]
|
||||
public class Item
|
||||
{
|
||||
public string title = "News title";
|
||||
[TextArea] public string description = "News description";
|
||||
public Sprite background;
|
||||
public string buttonText = "Show More";
|
||||
public UnityEvent onButtonClick = new UnityEvent();
|
||||
|
||||
[Header("Localization")]
|
||||
public string titleKey = "TitleKey";
|
||||
public string descriptionKey = "DescriptionKey";
|
||||
public string buttonTextKey = "ButtonTextKey";
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (isInitialized == false) { Initialize(); }
|
||||
else { StartCoroutine(PrepareSlider()); }
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isInitialized == false)
|
||||
return;
|
||||
|
||||
CheckForTimer();
|
||||
}
|
||||
|
||||
void CheckForTimer()
|
||||
{
|
||||
if (sliderTimerBar <= sliderTimer && currentIndicatorBar != null)
|
||||
{
|
||||
sliderTimerBar += Time.unscaledDeltaTime;
|
||||
currentIndicatorBar.fillAmount = sliderTimerBar / sliderTimer;
|
||||
}
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (useLocalization == true)
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
if (localizedObject == null || localizedObject.CheckLocalizationStatus() == false) { useLocalization = false; }
|
||||
}
|
||||
|
||||
foreach (Transform child in itemParent) { Destroy(child.gameObject); }
|
||||
foreach (Transform child in timerParent) { Destroy(child.gameObject); }
|
||||
for (int i = 0; i < items.Count; ++i)
|
||||
{
|
||||
int tempIndex = i;
|
||||
|
||||
GameObject itemGO = Instantiate(itemPreset, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
itemGO.transform.SetParent(itemParent, false);
|
||||
itemGO.gameObject.name = items[i].title;
|
||||
|
||||
TextMeshProUGUI itemTitle = itemGO.transform.Find("Title").GetComponent<TextMeshProUGUI>();
|
||||
if (useLocalization == false || string.IsNullOrEmpty(items[i].titleKey)) { itemTitle.text = items[i].title; }
|
||||
else
|
||||
{
|
||||
LocalizedObject tempLoc = itemTitle.GetComponent<LocalizedObject>();
|
||||
if (tempLoc != null)
|
||||
{
|
||||
tempLoc.tableIndex = localizedObject.tableIndex;
|
||||
tempLoc.localizationKey = items[i].titleKey;
|
||||
tempLoc.onLanguageChanged.AddListener(delegate { itemTitle.text = tempLoc.GetKeyOutput(tempLoc.localizationKey); });
|
||||
tempLoc.InitializeItem();
|
||||
tempLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
TextMeshProUGUI itemDescription = itemGO.transform.Find("Description").GetComponent<TextMeshProUGUI>();
|
||||
if (useLocalization == false || string.IsNullOrEmpty(items[i].descriptionKey)) { itemDescription.text = items[i].description; }
|
||||
else
|
||||
{
|
||||
LocalizedObject tempLoc = itemDescription.GetComponent<LocalizedObject>();
|
||||
if (tempLoc != null)
|
||||
{
|
||||
tempLoc.tableIndex = localizedObject.tableIndex;
|
||||
tempLoc.localizationKey = items[i].descriptionKey;
|
||||
tempLoc.onLanguageChanged.AddListener(delegate { itemDescription.text = tempLoc.GetKeyOutput(tempLoc.localizationKey); });
|
||||
tempLoc.InitializeItem();
|
||||
tempLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
Image background = itemGO.transform.Find("Background").GetComponent<Image>();
|
||||
background.sprite = items[i].background;
|
||||
|
||||
ButtonManager libraryItemButton = itemGO.GetComponentInChildren<ButtonManager>();
|
||||
if (libraryItemButton != null)
|
||||
{
|
||||
if (useLocalization == false) { libraryItemButton.buttonText = items[i].buttonText; }
|
||||
else
|
||||
{
|
||||
LocalizedObject tempLoc = libraryItemButton.GetComponent<LocalizedObject>();
|
||||
if (tempLoc != null)
|
||||
{
|
||||
tempLoc.tableIndex = localizedObject.tableIndex;
|
||||
tempLoc.localizationKey = items[i].buttonTextKey;
|
||||
tempLoc.onLanguageChanged.AddListener(delegate
|
||||
{
|
||||
libraryItemButton.buttonText = tempLoc.GetKeyOutput(tempLoc.localizationKey);
|
||||
libraryItemButton.UpdateUI();
|
||||
});
|
||||
tempLoc.InitializeItem();
|
||||
tempLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
libraryItemButton.UpdateUI();
|
||||
libraryItemButton.onClick.AddListener(delegate { items[tempIndex].onButtonClick.Invoke(); });
|
||||
if (string.IsNullOrEmpty(libraryItemButton.buttonText)) { libraryItemButton.gameObject.SetActive(false); }
|
||||
}
|
||||
|
||||
GameObject timerGO = Instantiate(timerPreset, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
timerGO.transform.SetParent(timerParent, false);
|
||||
timerGO.gameObject.name = items[i].title;
|
||||
timers.Add(timerGO.GetComponent<Animator>());
|
||||
|
||||
Button timerButton = timerGO.transform.Find("Dot").GetComponent<Button>();
|
||||
timerButton.onClick.AddListener(delegate
|
||||
{
|
||||
StopCoroutine("WaitForSliderTimer");
|
||||
StopCoroutine("DisableItemAnimators");
|
||||
|
||||
currentItemObject.gameObject.SetActive(true);
|
||||
currentItemObject.enabled = true;
|
||||
currentIndicatorObject.enabled = true;
|
||||
|
||||
currentItemObject.Play("Out");
|
||||
currentIndicatorObject.Play("Out");
|
||||
|
||||
currentSliderIndex = timerGO.transform.GetSiblingIndex();
|
||||
currentItemObject = itemParent.GetChild(currentSliderIndex).GetComponent<Animator>();
|
||||
|
||||
currentIndicatorBar = timers[currentSliderIndex].transform.Find("Bar/Filled").GetComponent<Image>();
|
||||
currentIndicatorObject = timers[currentSliderIndex];
|
||||
|
||||
currentItemObject.gameObject.SetActive(true);
|
||||
currentItemObject.enabled = true;
|
||||
currentIndicatorObject.enabled = true;
|
||||
|
||||
currentItemObject.Play("In");
|
||||
currentIndicatorObject.Play("In");
|
||||
|
||||
sliderTimerBar = 0;
|
||||
currentIndicatorBar.fillAmount = sliderTimerBar;
|
||||
|
||||
StartCoroutine("WaitForSliderTimer");
|
||||
StartCoroutine("DisableItemAnimators");
|
||||
});
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
StartCoroutine(PrepareSlider());
|
||||
}
|
||||
|
||||
IEnumerator PrepareSlider()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.02f);
|
||||
|
||||
sliderTimerBar = 0;
|
||||
|
||||
currentItemObject = itemParent.GetChild(currentSliderIndex).GetComponent<Animator>();
|
||||
currentIndicatorBar = timers[currentSliderIndex].transform.Find("Bar/Filled").GetComponent<Image>();
|
||||
currentIndicatorObject = timers[currentSliderIndex];
|
||||
|
||||
currentItemObject.enabled = true;
|
||||
currentIndicatorObject.enabled = true;
|
||||
|
||||
currentItemObject.Play("In");
|
||||
currentIndicatorObject.Play("In");
|
||||
|
||||
StopCoroutine("WaitForSliderTimer");
|
||||
StopCoroutine("DisableItemAnimators");
|
||||
|
||||
StartCoroutine("WaitForSliderTimer");
|
||||
StartCoroutine("DisableItemAnimators");
|
||||
}
|
||||
|
||||
IEnumerator WaitForSliderTimer()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(sliderTimer);
|
||||
|
||||
currentItemObject.enabled = true;
|
||||
currentIndicatorObject.enabled = true;
|
||||
|
||||
currentItemObject.Play("Out");
|
||||
currentIndicatorObject.Play("Out");
|
||||
|
||||
if (currentSliderIndex == items.Count - 1) { currentSliderIndex = 0; }
|
||||
else { currentSliderIndex++; }
|
||||
|
||||
sliderTimerBar = 0;
|
||||
|
||||
currentItemObject = itemParent.GetChild(currentSliderIndex).GetComponent<Animator>();
|
||||
currentIndicatorBar = timers[currentSliderIndex].transform.Find("Bar/Filled").GetComponent<Image>();
|
||||
currentIndicatorBar.fillAmount = sliderTimerBar;
|
||||
currentIndicatorObject = timers[currentSliderIndex];
|
||||
|
||||
currentItemObject.gameObject.SetActive(true);
|
||||
currentItemObject.enabled = true;
|
||||
currentIndicatorObject.enabled = true;
|
||||
|
||||
currentItemObject.Play("In");
|
||||
currentIndicatorObject.Play("In");
|
||||
|
||||
StartCoroutine("DisableItemAnimators");
|
||||
StartCoroutine("WaitForSliderTimer");
|
||||
}
|
||||
|
||||
IEnumerator DisableItemAnimators()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.6f);
|
||||
|
||||
for (int i = 0; i < items.Count; i++)
|
||||
{
|
||||
if (i != currentSliderIndex) { itemParent.GetChild(i).gameObject.SetActive(false); }
|
||||
itemParent.GetChild(i).GetComponent<Animator>().enabled = false;
|
||||
timers[i].enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e26b6342e0c67348802c1cfa3a2ac3a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- itemPreset: {fileID: 1064687812996275502, guid: 102f1a606dfe9474c990bbdcc6e3f420,
|
||||
type: 3}
|
||||
- itemParent: {instanceID: 0}
|
||||
- timerPreset: {fileID: 4365411159188456008, guid: a80abac1dd1ef034abe777f4b0a739ef,
|
||||
type: 3}
|
||||
- timerParent: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: ab6ec0d5e64a0e84e871a30a8ec23f48, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/NewsSlider.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,82 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(NewsSlider))]
|
||||
public class NewsSliderEditor : Editor
|
||||
{
|
||||
private NewsSlider nsTarget;
|
||||
private GUISkin customSkin;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
nsTarget = (NewsSlider)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "News Slider Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var items = serializedObject.FindProperty("items");
|
||||
|
||||
var itemPreset = serializedObject.FindProperty("itemPreset");
|
||||
var itemParent = serializedObject.FindProperty("itemParent");
|
||||
var timerPreset = serializedObject.FindProperty("timerPreset");
|
||||
var timerParent = serializedObject.FindProperty("timerParent");
|
||||
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var sliderTimer = serializedObject.FindProperty("sliderTimer");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
EditorGUI.indentLevel = 1;
|
||||
EditorGUILayout.PropertyField(items, new GUIContent("Slider Items"), true);
|
||||
EditorGUI.indentLevel = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(itemPreset, customSkin, "Item Preset");
|
||||
HeatUIEditorHandler.DrawProperty(itemParent, customSkin, "Item Parent");
|
||||
HeatUIEditorHandler.DrawProperty(timerPreset, customSkin, "Timer Preset");
|
||||
HeatUIEditorHandler.DrawProperty(timerParent, customSkin, "Timer Parent");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
HeatUIEditorHandler.DrawProperty(sliderTimer, customSkin, "Slider Timer");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0a18454765edb814c9e8420a5cdf92cd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/NewsSliderEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,154 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class NotificationManager : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public Sprite icon;
|
||||
[TextArea] public string notificationText = "Notification Text";
|
||||
public string localizationKey;
|
||||
public AudioClip customSFX;
|
||||
|
||||
// Resources
|
||||
[SerializeField] private Animator itemAnimator;
|
||||
[SerializeField] private Image iconObj;
|
||||
[SerializeField] private TextMeshProUGUI textObj;
|
||||
|
||||
// Settings
|
||||
public bool useLocalization = true;
|
||||
[SerializeField] private bool updateOnAnimate = true;
|
||||
[Range(0, 10)] public float minimizeAfter = 3;
|
||||
public DefaultState defaultState = DefaultState.Minimized;
|
||||
public AfterMinimize afterMinimize = AfterMinimize.Disable;
|
||||
|
||||
// Events
|
||||
public UnityEvent onDestroy = new UnityEvent();
|
||||
|
||||
// Helpers
|
||||
bool isOn;
|
||||
LocalizedObject localizedObject;
|
||||
|
||||
public enum DefaultState { Minimized, Expanded }
|
||||
public enum AfterMinimize { Disable, Destroy }
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (itemAnimator == null) { itemAnimator = GetComponent<Animator>(); }
|
||||
if (useLocalization)
|
||||
{
|
||||
localizedObject = textObj.GetComponent<LocalizedObject>();
|
||||
|
||||
if (localizedObject == null || !localizedObject.CheckLocalizationStatus()) { useLocalization = false; }
|
||||
else if (localizedObject != null && !string.IsNullOrEmpty(localizationKey))
|
||||
{
|
||||
// Forcing component to take the localized output on awake
|
||||
notificationText = localizedObject.GetKeyOutput(localizationKey);
|
||||
|
||||
// Change text on language change
|
||||
localizedObject.onLanguageChanged.AddListener(delegate
|
||||
{
|
||||
notificationText = localizedObject.GetKeyOutput(localizationKey);
|
||||
UpdateUI();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (defaultState == DefaultState.Minimized) { gameObject.SetActive(false); }
|
||||
else if (defaultState == DefaultState.Expanded) { ExpandNotification(); }
|
||||
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
iconObj.sprite = icon;
|
||||
textObj.text = notificationText;
|
||||
}
|
||||
|
||||
public void AnimateNotification()
|
||||
{
|
||||
ExpandNotification();
|
||||
}
|
||||
|
||||
public void ExpandNotification()
|
||||
{
|
||||
if (isOn)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
|
||||
if (minimizeAfter != 0)
|
||||
{
|
||||
StopCoroutine("MinimizeItem");
|
||||
StartCoroutine("MinimizeItem");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
isOn = true;
|
||||
gameObject.SetActive(true);
|
||||
itemAnimator.enabled = true;
|
||||
itemAnimator.Play("In");
|
||||
|
||||
if (updateOnAnimate) { UpdateUI(); }
|
||||
if (minimizeAfter != 0) { StopCoroutine("MinimizeItem"); StartCoroutine("MinimizeItem"); }
|
||||
|
||||
if (customSFX != null && UIManagerAudio.instance != null) { UIManagerAudio.instance.audioSource.PlayOneShot(customSFX); }
|
||||
else if (UIManagerAudio.instance != null && UIManagerAudio.instance.UIManagerAsset.notificationSound != null) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.notificationSound); }
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
|
||||
}
|
||||
|
||||
public void MinimizeNotification()
|
||||
{
|
||||
if (!isOn)
|
||||
return;
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
|
||||
itemAnimator.enabled = true;
|
||||
itemAnimator.Play("Out");
|
||||
|
||||
StopCoroutine("DisableItem");
|
||||
StartCoroutine("DisableItem");
|
||||
}
|
||||
|
||||
public void DestroyNotification()
|
||||
{
|
||||
onDestroy.Invoke();
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSeconds(HeatUIInternalTools.GetAnimatorClipLength(itemAnimator, "Notification_In"));
|
||||
itemAnimator.enabled = false;
|
||||
}
|
||||
|
||||
IEnumerator DisableItem()
|
||||
{
|
||||
yield return new WaitForSeconds(HeatUIInternalTools.GetAnimatorClipLength(itemAnimator, "Notification_Out"));
|
||||
|
||||
isOn = false;
|
||||
|
||||
if (afterMinimize == AfterMinimize.Disable) { gameObject.SetActive(false); }
|
||||
else if (afterMinimize == AfterMinimize.Destroy) { DestroyNotification(); }
|
||||
}
|
||||
|
||||
IEnumerator MinimizeItem()
|
||||
{
|
||||
yield return new WaitForSeconds(minimizeAfter);
|
||||
MinimizeNotification();
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07bc033b565f76745812c218a778e1d6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: e6de80bc36d275741a94fa8d263b612d, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,69 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(NotificationManager))]
|
||||
public class NotificationManagerEditor : Editor
|
||||
{
|
||||
private NotificationManager nmTarget;
|
||||
private GUISkin customSkin;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
nmTarget = (NotificationManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var icon = serializedObject.FindProperty("icon");
|
||||
var notificationText = serializedObject.FindProperty("notificationText");
|
||||
var localizationKey = serializedObject.FindProperty("localizationKey");
|
||||
var customSFX = serializedObject.FindProperty("customSFX");
|
||||
|
||||
var itemAnimator = serializedObject.FindProperty("itemAnimator");
|
||||
var iconObj = serializedObject.FindProperty("iconObj");
|
||||
var textObj = serializedObject.FindProperty("textObj");
|
||||
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var updateOnAnimate = serializedObject.FindProperty("updateOnAnimate");
|
||||
var minimizeAfter = serializedObject.FindProperty("minimizeAfter");
|
||||
var defaultState = serializedObject.FindProperty("defaultState");
|
||||
var afterMinimize = serializedObject.FindProperty("afterMinimize");
|
||||
|
||||
var onDestroy = serializedObject.FindProperty("onDestroy");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(icon, customSkin, "Icon");
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Notification Text"), customSkin.FindStyle("Text"), GUILayout.Width(-3));
|
||||
EditorGUILayout.PropertyField(notificationText, new GUIContent(""), GUILayout.Height(70));
|
||||
GUILayout.EndHorizontal();
|
||||
HeatUIEditorHandler.DrawProperty(localizationKey, customSkin, "Localization Key");
|
||||
HeatUIEditorHandler.DrawProperty(customSFX, customSkin, "Custom SFX");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 10);
|
||||
HeatUIEditorHandler.DrawProperty(itemAnimator, customSkin, "Animator");
|
||||
HeatUIEditorHandler.DrawProperty(iconObj, customSkin, "Icon Object");
|
||||
HeatUIEditorHandler.DrawProperty(textObj, customSkin, "Text Object");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 10);
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
updateOnAnimate.boolValue = HeatUIEditorHandler.DrawToggle(updateOnAnimate.boolValue, customSkin, "Update On Animate");
|
||||
HeatUIEditorHandler.DrawProperty(minimizeAfter, customSkin, "Minimize After");
|
||||
HeatUIEditorHandler.DrawProperty(defaultState, customSkin, "Default State");
|
||||
HeatUIEditorHandler.DrawProperty(afterMinimize, customSkin, "After Minimize");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onDestroy, new GUIContent("On Destroy"), true);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dff76723f967b5f499f3a73c415bb57f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -0,0 +1,330 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[DisallowMultipleComponent]
|
||||
public class PanelButton : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
|
||||
{
|
||||
// Content
|
||||
public Sprite buttonIcon;
|
||||
public string buttonText = "Button";
|
||||
|
||||
// Resources
|
||||
[SerializeField] private CanvasGroup disabledCG;
|
||||
[SerializeField] private CanvasGroup normalCG;
|
||||
[SerializeField] private CanvasGroup highlightCG;
|
||||
[SerializeField] private CanvasGroup selectCG;
|
||||
[SerializeField] private TextMeshProUGUI disabledTextObj;
|
||||
[SerializeField] private TextMeshProUGUI normalTextObj;
|
||||
[SerializeField] private TextMeshProUGUI highlightTextObj;
|
||||
[SerializeField] private TextMeshProUGUI selectTextObj;
|
||||
[SerializeField] private Image disabledImageObj;
|
||||
[SerializeField] private Image normalImageObj;
|
||||
[SerializeField] private Image highlightImageObj;
|
||||
[SerializeField] private Image selectedImageObj;
|
||||
[SerializeField] private GameObject seperator;
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool isSelected;
|
||||
public bool useLocalization = true;
|
||||
public bool useCustomText = false;
|
||||
public bool useSeperator = true;
|
||||
public bool useUINavigation = false;
|
||||
public Navigation.Mode navigationMode = Navigation.Mode.Automatic;
|
||||
public GameObject selectOnUp;
|
||||
public GameObject selectOnDown;
|
||||
public GameObject selectOnLeft;
|
||||
public GameObject selectOnRight;
|
||||
public bool wrapAround = false;
|
||||
public bool useSounds = true;
|
||||
[Range(1, 15)] public float fadingMultiplier = 8;
|
||||
|
||||
// Events
|
||||
public UnityEvent onClick = new UnityEvent();
|
||||
public UnityEvent onHover = new UnityEvent();
|
||||
public UnityEvent onLeave = new UnityEvent();
|
||||
public UnityEvent onSelect = new UnityEvent();
|
||||
|
||||
// Helpers
|
||||
bool isInitialized = false;
|
||||
Button targetButton;
|
||||
LocalizedObject localizedObject;
|
||||
[HideInInspector] public NavigationBar navbar;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!isInitialized) { Initialize(); }
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
if (!Application.isPlaying) { return; }
|
||||
if (UIManagerAudio.instance == null) { useSounds = false; }
|
||||
if (useUINavigation) { AddUINavigation(); }
|
||||
if (gameObject.GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
disabledCG.alpha = 0;
|
||||
normalCG.alpha = 1;
|
||||
highlightCG.alpha = 0;
|
||||
selectCG.alpha = 0;
|
||||
|
||||
if (useLocalization)
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
|
||||
if (localizedObject == null || !localizedObject.CheckLocalizationStatus()) { useLocalization = false; }
|
||||
else if (useLocalization && !string.IsNullOrEmpty(localizedObject.localizationKey))
|
||||
{
|
||||
// Forcing button to take the localized output on awake
|
||||
buttonText = localizedObject.GetKeyOutput(localizedObject.localizationKey);
|
||||
|
||||
// Change button text on language change
|
||||
localizedObject.onLanguageChanged.AddListener(delegate
|
||||
{
|
||||
buttonText = localizedObject.GetKeyOutput(localizedObject.localizationKey);
|
||||
UpdateUI();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
public void IsInteractable(bool value)
|
||||
{
|
||||
isInteractable = value;
|
||||
|
||||
if (!isInteractable) { StartCoroutine("SetDisabled"); }
|
||||
else if (isInteractable && !isSelected) { StartCoroutine("SetNormal"); }
|
||||
}
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
if (targetButton == null)
|
||||
{
|
||||
targetButton = gameObject.AddComponent<Button>();
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = navigationMode;
|
||||
|
||||
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
|
||||
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine("InitUINavigation", customNav); return; }
|
||||
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
|
||||
public void DisableUINavigation()
|
||||
{
|
||||
if (targetButton != null)
|
||||
{
|
||||
Navigation customNav = new Navigation();
|
||||
Navigation.Mode navMode = Navigation.Mode.None;
|
||||
customNav.mode = navMode;
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (navbar != null) { navbar.DimButtons(this); }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
if (!isInteractable || isSelected) { return; }
|
||||
|
||||
onHover.Invoke();
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (navbar != null) { navbar.LitButtons(); }
|
||||
if (!isInteractable || isSelected) { return; }
|
||||
|
||||
onLeave.Invoke();
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable || isSelected)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable || isSelected)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable || isSelected)
|
||||
return;
|
||||
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (useSeperator && transform.parent != null && transform.GetSiblingIndex() != transform.parent.childCount - 1 && seperator != null) { seperator.SetActive(true); }
|
||||
else if (seperator != null) { seperator.SetActive(false); }
|
||||
|
||||
if (useCustomText)
|
||||
return;
|
||||
|
||||
if (disabledTextObj != null) { disabledTextObj.text = buttonText; }
|
||||
if (normalTextObj != null) { normalTextObj.text = buttonText; }
|
||||
if (highlightTextObj != null) { highlightTextObj.text = buttonText; }
|
||||
if (selectTextObj != null) { selectTextObj.text = buttonText; }
|
||||
|
||||
if (disabledImageObj != null && buttonIcon != null) { disabledImageObj.transform.parent.gameObject.SetActive(true); disabledImageObj.sprite = buttonIcon; }
|
||||
else if (disabledImageObj != null && buttonIcon == null) { disabledImageObj.transform.parent.gameObject.SetActive(false); }
|
||||
|
||||
if (normalImageObj != null && buttonIcon != null) { normalImageObj.transform.parent.gameObject.SetActive(true); normalImageObj.sprite = buttonIcon; }
|
||||
else if (normalImageObj != null && buttonIcon == null) { normalImageObj.transform.parent.gameObject.SetActive(false); }
|
||||
|
||||
if (highlightImageObj != null && buttonIcon != null) { highlightImageObj.transform.parent.gameObject.SetActive(true); highlightImageObj.sprite = buttonIcon; }
|
||||
else if (highlightImageObj != null && buttonIcon == null) { highlightImageObj.transform.parent.gameObject.SetActive(false); }
|
||||
|
||||
if (selectedImageObj != null && buttonIcon != null) { selectedImageObj.transform.parent.gameObject.SetActive(true); selectedImageObj.sprite = buttonIcon; }
|
||||
else if (selectedImageObj != null && buttonIcon == null) { selectedImageObj.transform.parent.gameObject.SetActive(false); }
|
||||
|
||||
if (isSelected)
|
||||
{
|
||||
disabledCG.alpha = 0;
|
||||
normalCG.alpha = 0;
|
||||
highlightCG.alpha = 0;
|
||||
selectCG.alpha = 1;
|
||||
}
|
||||
|
||||
else if (!isInteractable)
|
||||
{
|
||||
disabledCG.alpha = 1;
|
||||
normalCG.alpha = 0;
|
||||
highlightCG.alpha = 0;
|
||||
selectCG.alpha = 0;
|
||||
}
|
||||
|
||||
LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());
|
||||
}
|
||||
|
||||
public void SetSelected(bool value)
|
||||
{
|
||||
isSelected = value;
|
||||
|
||||
if (navbar != null) { navbar.LitButtons(this); }
|
||||
if (isSelected) { StartCoroutine("SetSelect"); onSelect.Invoke(); }
|
||||
else { StartCoroutine("SetNormal"); }
|
||||
}
|
||||
|
||||
IEnumerator SetDisabled()
|
||||
{
|
||||
StopCoroutine("SetNormal");
|
||||
StopCoroutine("SetHighlight");
|
||||
StopCoroutine("SetSelect");
|
||||
|
||||
while (disabledCG.alpha < 0.99f)
|
||||
{
|
||||
disabledCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
normalCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
selectCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
disabledCG.alpha = 1;
|
||||
normalCG.alpha = 0;
|
||||
highlightCG.alpha = 0;
|
||||
selectCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetNormal()
|
||||
{
|
||||
StopCoroutine("SetDisabled");
|
||||
StopCoroutine("SetHighlight");
|
||||
StopCoroutine("SetSelect");
|
||||
|
||||
while (normalCG.alpha < 0.99f)
|
||||
{
|
||||
disabledCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
normalCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
selectCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
disabledCG.alpha = 0;
|
||||
normalCG.alpha = 1;
|
||||
highlightCG.alpha = 0;
|
||||
selectCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetHighlight()
|
||||
{
|
||||
StopCoroutine("SetDisabled");
|
||||
StopCoroutine("SetNormal");
|
||||
StopCoroutine("SetSelect");
|
||||
|
||||
while (highlightCG.alpha < 0.99f)
|
||||
{
|
||||
disabledCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
normalCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
highlightCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
selectCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
disabledCG.alpha = 0;
|
||||
normalCG.alpha = 0;
|
||||
highlightCG.alpha = 1;
|
||||
selectCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetSelect()
|
||||
{
|
||||
StopCoroutine("SetDisabled");
|
||||
StopCoroutine("SetNormal");
|
||||
StopCoroutine("SetHighlight");
|
||||
|
||||
while (selectCG.alpha < 0.99f)
|
||||
{
|
||||
disabledCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
normalCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
selectCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
disabledCG.alpha = 0;
|
||||
normalCG.alpha = 0;
|
||||
highlightCG.alpha = 0;
|
||||
selectCG.alpha = 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc831e36e697c8f41b899dfcbf339684
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b044a95718e69ee40ac27035753bf3c6, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/PanelButton.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,124 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(PanelButton))]
|
||||
public class PanelButtonEditor : Editor
|
||||
{
|
||||
private PanelButton buttonTarget;
|
||||
private GUISkin customSkin;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
buttonTarget = (PanelButton)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Panel Button Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var buttonIcon = serializedObject.FindProperty("buttonIcon");
|
||||
var buttonText = serializedObject.FindProperty("buttonText");
|
||||
|
||||
var disabledCG = serializedObject.FindProperty("disabledCG");
|
||||
var normalCG = serializedObject.FindProperty("normalCG");
|
||||
var highlightCG = serializedObject.FindProperty("highlightCG");
|
||||
var selectCG = serializedObject.FindProperty("selectCG");
|
||||
var disabledTextObj = serializedObject.FindProperty("disabledTextObj");
|
||||
var normalTextObj = serializedObject.FindProperty("normalTextObj");
|
||||
var highlightTextObj = serializedObject.FindProperty("highlightTextObj");
|
||||
var selectTextObj = serializedObject.FindProperty("selectTextObj");
|
||||
var disabledImageObj = serializedObject.FindProperty("disabledImageObj");
|
||||
var normalImageObj = serializedObject.FindProperty("normalImageObj");
|
||||
var highlightImageObj = serializedObject.FindProperty("highlightImageObj");
|
||||
var selectedImageObj = serializedObject.FindProperty("selectedImageObj");
|
||||
var seperator = serializedObject.FindProperty("seperator");
|
||||
|
||||
var isInteractable = serializedObject.FindProperty("isInteractable");
|
||||
var isSelected = serializedObject.FindProperty("isSelected");
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var useCustomText = serializedObject.FindProperty("useCustomText");
|
||||
var useSeperator = serializedObject.FindProperty("useSeperator");
|
||||
var useSounds = serializedObject.FindProperty("useSounds");
|
||||
var useUINavigation = serializedObject.FindProperty("useUINavigation");
|
||||
var fadingMultiplier = serializedObject.FindProperty("fadingMultiplier");
|
||||
|
||||
var onClick = serializedObject.FindProperty("onClick");
|
||||
var onHover = serializedObject.FindProperty("onHover");
|
||||
var onLeave = serializedObject.FindProperty("onLeave");
|
||||
var onSelect = serializedObject.FindProperty("onSelect");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonIcon, customSkin, "Button Icon", 80);
|
||||
if (useCustomText.boolValue == false) { HeatUIEditorHandler.DrawPropertyCW(buttonText, customSkin, "Button Text", 80); }
|
||||
if (buttonTarget.buttonIcon != null || useCustomText.boolValue == false) { buttonTarget.UpdateUI(); }
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onClick, new GUIContent("On Click"), true);
|
||||
EditorGUILayout.PropertyField(onHover, new GUIContent("On Hover"), true);
|
||||
EditorGUILayout.PropertyField(onLeave, new GUIContent("On Leave"), true);
|
||||
EditorGUILayout.PropertyField(onSelect, new GUIContent("On Select"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(disabledCG, customSkin, "Disabled CG");
|
||||
HeatUIEditorHandler.DrawProperty(normalCG, customSkin, "Normal CG");
|
||||
HeatUIEditorHandler.DrawProperty(highlightCG, customSkin, "Highlight CG");
|
||||
HeatUIEditorHandler.DrawProperty(selectCG, customSkin, "Select CG");
|
||||
HeatUIEditorHandler.DrawProperty(disabledTextObj, customSkin, "Disabled Text");
|
||||
HeatUIEditorHandler.DrawProperty(normalTextObj, customSkin, "Normal Text");
|
||||
HeatUIEditorHandler.DrawProperty(highlightTextObj, customSkin, "Highlight Text");
|
||||
HeatUIEditorHandler.DrawProperty(selectTextObj, customSkin, "Select Text");
|
||||
HeatUIEditorHandler.DrawProperty(disabledImageObj, customSkin, "Disabled Image");
|
||||
HeatUIEditorHandler.DrawProperty(normalImageObj, customSkin, "Normal Image");
|
||||
HeatUIEditorHandler.DrawProperty(highlightImageObj, customSkin, "Highlight Image");
|
||||
HeatUIEditorHandler.DrawProperty(selectedImageObj, customSkin, "Select Image");
|
||||
HeatUIEditorHandler.DrawProperty(seperator, customSkin, "Seperator");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
isSelected.boolValue = HeatUIEditorHandler.DrawToggle(isSelected.boolValue, customSkin, "Is Selected");
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
useCustomText.boolValue = HeatUIEditorHandler.DrawToggle(useCustomText.boolValue, customSkin, "Use Custom Text", "Bypasses inspector values and allows manual editing.");
|
||||
useSeperator.boolValue = HeatUIEditorHandler.DrawToggle(useSeperator.boolValue, customSkin, "Use Seperator");
|
||||
useUINavigation.boolValue = HeatUIEditorHandler.DrawToggle(useUINavigation.boolValue, customSkin, "Use UI Navigation", "Enables controller navigation.");
|
||||
useSounds.boolValue = HeatUIEditorHandler.DrawToggle(useSounds.boolValue, customSkin, "Use Button Sounds");
|
||||
HeatUIEditorHandler.DrawProperty(fadingMultiplier, customSkin, "Fading Multiplier", "Set the animation fade multiplier.");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c449e50d33ad9d439d39433c374beae
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/PanelButtonEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,108 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
using UnityEngine.Events;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
public class ProgressBar : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public Sprite icon;
|
||||
public float currentValue;
|
||||
public float minValue = 0;
|
||||
public float maxValue = 100;
|
||||
public float minValueLimit = 0;
|
||||
public float maxValueLimit = 100;
|
||||
|
||||
// Resources
|
||||
public Image barImage;
|
||||
[SerializeField] private Image iconObject;
|
||||
[SerializeField] private Image altIconObject;
|
||||
[SerializeField] private TextMeshProUGUI textObject;
|
||||
[SerializeField] private TextMeshProUGUI altTextObject;
|
||||
|
||||
// Settings
|
||||
public bool addPrefix;
|
||||
public bool addSuffix;
|
||||
[Range(0, 5)] public int decimals = 0;
|
||||
public string prefix = "";
|
||||
public string suffix = "%";
|
||||
public BarDirection barDirection = BarDirection.Left;
|
||||
|
||||
// Events
|
||||
[System.Serializable]
|
||||
public class OnValueChanged : UnityEvent<float> { }
|
||||
public OnValueChanged onValueChanged;
|
||||
|
||||
// Helpers
|
||||
[HideInInspector] public Slider eventSource;
|
||||
|
||||
public enum BarDirection { Left, Right, Top, Bottom }
|
||||
|
||||
void Start()
|
||||
{
|
||||
Initialize();
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
void Update()
|
||||
{
|
||||
if (Application.isPlaying == true)
|
||||
return;
|
||||
|
||||
UpdateUI();
|
||||
SetBarDirection();
|
||||
}
|
||||
#endif
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (barImage != null) { barImage.fillAmount = currentValue / maxValue; }
|
||||
if (iconObject != null) { iconObject.sprite = icon; }
|
||||
if (altIconObject != null) { altIconObject.sprite = icon; }
|
||||
if (textObject != null) { UpdateText(textObject); }
|
||||
if (altTextObject != null) { UpdateText(altTextObject); }
|
||||
if (eventSource != null) { eventSource.value = currentValue; }
|
||||
}
|
||||
|
||||
void UpdateText(TextMeshProUGUI txt)
|
||||
{
|
||||
if (addSuffix == true) { txt.text = currentValue.ToString("F" + decimals) + suffix; }
|
||||
else { txt.text = currentValue.ToString("F" + decimals); }
|
||||
|
||||
if (addPrefix == true) { txt.text = prefix + txt.text; }
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
if (Application.isPlaying == true && onValueChanged.GetPersistentEventCount() != 0)
|
||||
{
|
||||
if (eventSource == null) { eventSource = gameObject.AddComponent(typeof(Slider)) as Slider; }
|
||||
eventSource.transition = Selectable.Transition.None;
|
||||
eventSource.minValue = minValue;
|
||||
eventSource.maxValue = maxValue;
|
||||
eventSource.onValueChanged.AddListener(onValueChanged.Invoke);
|
||||
}
|
||||
|
||||
SetBarDirection();
|
||||
}
|
||||
|
||||
void SetBarDirection()
|
||||
{
|
||||
if (barImage != null)
|
||||
{
|
||||
barImage.type = Image.Type.Filled;
|
||||
if (barDirection == BarDirection.Left) { barImage.fillMethod = Image.FillMethod.Horizontal; barImage.fillOrigin = 0; }
|
||||
else if (barDirection == BarDirection.Right) { barImage.fillMethod = Image.FillMethod.Horizontal; barImage.fillOrigin = 1; }
|
||||
else if (barDirection == BarDirection.Top) { barImage.fillMethod = Image.FillMethod.Vertical; barImage.fillOrigin = 1; }
|
||||
else if (barDirection == BarDirection.Bottom) { barImage.fillMethod = Image.FillMethod.Vertical; barImage.fillOrigin = 0; }
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearEvents() { eventSource.onValueChanged.RemoveAllListeners(); }
|
||||
public void SetValue(float newValue) { currentValue = newValue; UpdateUI(); }
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f57bb437b79d1e84f8e4d3d31a8ceea8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 9b313dd5573557748b6c46edc36bdeb5, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ProgressBar.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,155 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(ProgressBar))]
|
||||
public class ProgressBarEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private ProgressBar pbTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
pbTarget = (ProgressBar)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Progress Bar Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var icon = serializedObject.FindProperty("icon");
|
||||
var currentValue = serializedObject.FindProperty("currentValue");
|
||||
var minValue = serializedObject.FindProperty("minValue");
|
||||
var maxValue = serializedObject.FindProperty("maxValue");
|
||||
var minValueLimit = serializedObject.FindProperty("minValueLimit");
|
||||
var maxValueLimit = serializedObject.FindProperty("maxValueLimit");
|
||||
|
||||
var barImage = serializedObject.FindProperty("barImage");
|
||||
var iconObject = serializedObject.FindProperty("iconObject");
|
||||
var altIconObject = serializedObject.FindProperty("altIconObject");
|
||||
var textObject = serializedObject.FindProperty("textObject");
|
||||
var altTextObject = serializedObject.FindProperty("altTextObject");
|
||||
|
||||
var addPrefix = serializedObject.FindProperty("addPrefix");
|
||||
var addSuffix = serializedObject.FindProperty("addSuffix");
|
||||
var prefix = serializedObject.FindProperty("prefix");
|
||||
var suffix = serializedObject.FindProperty("suffix");
|
||||
var decimals = serializedObject.FindProperty("decimals");
|
||||
var barDirection = serializedObject.FindProperty("barDirection");
|
||||
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
if (pbTarget.barImage != null) { HeatUIEditorHandler.DrawPropertyCW(icon, customSkin, "Bar Icon", 99); }
|
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Percent"), customSkin.FindStyle("Text"), GUILayout.Width(100));
|
||||
currentValue.floatValue = EditorGUILayout.Slider(pbTarget.currentValue, minValue.floatValue, maxValue.floatValue);
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
pbTarget.UpdateUI();
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
EditorGUILayout.LabelField(new GUIContent("Min / Max Value"), customSkin.FindStyle("Text"), GUILayout.Width(110));
|
||||
GUILayout.BeginHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
minValue.floatValue = EditorGUILayout.Slider(minValue.floatValue, minValueLimit.floatValue, maxValue.floatValue - 1);
|
||||
maxValue.floatValue = EditorGUILayout.Slider(maxValue.floatValue, minValue.floatValue + 1, maxValueLimit.floatValue);
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
EditorGUILayout.HelpBox("You can increase the min/max value limit by changing 'Value Limit' in the settings tab.", MessageType.Info);
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"));
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(barImage, customSkin, "Bar Image");
|
||||
HeatUIEditorHandler.DrawProperty(iconObject, customSkin, "Icon Object");
|
||||
HeatUIEditorHandler.DrawProperty(altIconObject, customSkin, "Alt Icon Object");
|
||||
HeatUIEditorHandler.DrawProperty(textObject, customSkin, "Text Object");
|
||||
HeatUIEditorHandler.DrawProperty(altTextObject, customSkin, "Alt Text Object");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
addPrefix.boolValue = HeatUIEditorHandler.DrawTogglePlain(addPrefix.boolValue, customSkin, "Add Prefix");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (addPrefix.boolValue == true)
|
||||
HeatUIEditorHandler.DrawPropertyPlainCW(prefix, customSkin, "Prefix:", 40);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
addSuffix.boolValue = HeatUIEditorHandler.DrawTogglePlain(addSuffix.boolValue, customSkin, "Add Suffix");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (addSuffix.boolValue == true)
|
||||
HeatUIEditorHandler.DrawPropertyPlainCW(suffix, customSkin, "Suffix:", 40);
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawPropertyCW(decimals, customSkin, "Decimals", 80);
|
||||
|
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Min Limit"), customSkin.FindStyle("Text"), GUILayout.Width(80));
|
||||
EditorGUILayout.PropertyField(minValueLimit, new GUIContent(""));
|
||||
|
||||
if (minValueLimit.floatValue >= maxValueLimit.floatValue) { minValueLimit.floatValue = maxValueLimit.floatValue - 1; }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
EditorGUILayout.LabelField(new GUIContent("Max Limit"), customSkin.FindStyle("Text"), GUILayout.Width(80));
|
||||
EditorGUILayout.PropertyField(maxValueLimit, new GUIContent(""));
|
||||
|
||||
if (maxValueLimit.floatValue <= minValue.floatValue) { maxValueLimit.floatValue = minValue.floatValue + 1; }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
HeatUIEditorHandler.DrawPropertyCW(barDirection, customSkin, "Bar Direction", 80);
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 231ea7433843ca545a26de0ad5037a32
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ProgressBarEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,195 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
public class SettingsElement : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
|
||||
{
|
||||
// Resources
|
||||
[SerializeField] private CanvasGroup highlightCG;
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool useSounds = true;
|
||||
[Range(1, 15)] public float fadingMultiplier = 8;
|
||||
public bool useUINavigation = false;
|
||||
public Navigation.Mode navigationMode = Navigation.Mode.Automatic;
|
||||
public GameObject selectOnUp;
|
||||
public GameObject selectOnDown;
|
||||
public GameObject selectOnLeft;
|
||||
public GameObject selectOnRight;
|
||||
public bool wrapAround = false;
|
||||
|
||||
// Events
|
||||
public UnityEvent onClick = new UnityEvent();
|
||||
public UnityEvent onHover = new UnityEvent();
|
||||
public UnityEvent onLeave = new UnityEvent();
|
||||
|
||||
// Helpers
|
||||
Button targetButton;
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (ControllerManager.instance != null) { ControllerManager.instance.settingsElements.Add(this); }
|
||||
if (UIManagerAudio.instance == null) { useSounds = false; }
|
||||
|
||||
if (highlightCG == null)
|
||||
{
|
||||
highlightCG = new GameObject().AddComponent<CanvasGroup>();
|
||||
highlightCG.gameObject.AddComponent<RectTransform>();
|
||||
highlightCG.transform.SetParent(transform);
|
||||
highlightCG.gameObject.name = "Highlight";
|
||||
}
|
||||
|
||||
if (GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (highlightCG != null) { highlightCG.alpha = 0; }
|
||||
if (Application.isPlaying && useUINavigation) { AddUINavigation(); }
|
||||
else if (Application.isPlaying && !useUINavigation && targetButton == null)
|
||||
{
|
||||
targetButton = gameObject.AddComponent<Button>();
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
}
|
||||
|
||||
public void Interactable(bool value)
|
||||
{
|
||||
isInteractable = value;
|
||||
if (!gameObject.activeInHierarchy) { return; }
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
if (targetButton == null)
|
||||
{
|
||||
if (gameObject.GetComponent<Button>() == null) { targetButton = gameObject.AddComponent<Button>(); }
|
||||
else { targetButton = GetComponent<Button>(); }
|
||||
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
|
||||
if (targetButton.navigation.mode == navigationMode)
|
||||
return;
|
||||
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = navigationMode;
|
||||
|
||||
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
|
||||
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine("InitUINavigation", customNav); return; }
|
||||
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
|
||||
public void DisableUINavigation()
|
||||
{
|
||||
if (targetButton != null)
|
||||
{
|
||||
Navigation customNav = new Navigation();
|
||||
Navigation.Mode navMode = Navigation.Mode.None;
|
||||
customNav.mode = navMode;
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (isInteractable == false || eventData.button != PointerEventData.InputButton.Left) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
onHover.Invoke();
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
onLeave.Invoke();
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
onHover.Invoke();
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable || highlightCG == null)
|
||||
return;
|
||||
|
||||
onLeave.Invoke();
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
IEnumerator SetNormal()
|
||||
{
|
||||
StopCoroutine("SetHighlight");
|
||||
|
||||
while (highlightCG.alpha > 0.01f)
|
||||
{
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetHighlight()
|
||||
{
|
||||
StopCoroutine("SetNormal");
|
||||
|
||||
while (highlightCG.alpha < 0.99f)
|
||||
{
|
||||
highlightCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 1;
|
||||
}
|
||||
|
||||
IEnumerator InitUINavigation(Navigation nav)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.1f);
|
||||
if (selectOnUp != null) { nav.selectOnUp = selectOnUp.GetComponent<Selectable>(); }
|
||||
if (selectOnDown != null) { nav.selectOnDown = selectOnDown.GetComponent<Selectable>(); }
|
||||
if (selectOnLeft != null) { nav.selectOnLeft = selectOnLeft.GetComponent<Selectable>(); }
|
||||
if (selectOnRight != null) { nav.selectOnRight = selectOnRight.GetComponent<Selectable>(); }
|
||||
targetButton.navigation = nav;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c6bfa634473fe714ba695461c7b0cb22
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: fd3012dcfab95cb469aa3dd70c6af50b, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SettingsElement.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,98 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(SettingsElement))]
|
||||
public class SettingsElementEditor : Editor
|
||||
{
|
||||
private SettingsElement seTarget;
|
||||
private GUISkin customSkin;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
seTarget = (SettingsElement)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
var highlightCG = serializedObject.FindProperty("highlightCG");
|
||||
|
||||
var isInteractable = serializedObject.FindProperty("isInteractable");
|
||||
var useSounds = serializedObject.FindProperty("useSounds");
|
||||
var useUINavigation = serializedObject.FindProperty("useUINavigation");
|
||||
var navigationMode = serializedObject.FindProperty("navigationMode");
|
||||
var selectOnUp = serializedObject.FindProperty("selectOnUp");
|
||||
var selectOnDown = serializedObject.FindProperty("selectOnDown");
|
||||
var selectOnLeft = serializedObject.FindProperty("selectOnLeft");
|
||||
var selectOnRight = serializedObject.FindProperty("selectOnRight");
|
||||
var wrapAround = serializedObject.FindProperty("wrapAround");
|
||||
var fadingMultiplier = serializedObject.FindProperty("fadingMultiplier");
|
||||
|
||||
var onClick = serializedObject.FindProperty("onClick");
|
||||
var onHover = serializedObject.FindProperty("onHover");
|
||||
var onLeave = serializedObject.FindProperty("onLeave");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(highlightCG, customSkin, "Highlight CG");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 10);
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
useSounds.boolValue = HeatUIEditorHandler.DrawToggle(useSounds.boolValue, customSkin, "Use Sounds");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
useUINavigation.boolValue = HeatUIEditorHandler.DrawTogglePlain(useUINavigation.boolValue, customSkin, "Use UI Navigation", "Enables controller navigation.");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (useUINavigation.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
HeatUIEditorHandler.DrawPropertyPlain(navigationMode, customSkin, "Navigation Mode");
|
||||
|
||||
if (seTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Horizontal)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawToggle(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
else if (seTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Vertical)
|
||||
{
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawTogglePlain(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
}
|
||||
|
||||
else if (seTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Explicit)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnUp, customSkin, "Select On Up");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnDown, customSkin, "Select On Down");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnLeft, customSkin, "Select On Left");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnRight, customSkin, "Select On Right");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
HeatUIEditorHandler.DrawProperty(fadingMultiplier, customSkin, "Fading Multiplier", "Set the animation fade multiplier.");
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onClick, new GUIContent("On Click"), true);
|
||||
EditorGUILayout.PropertyField(onHover, new GUIContent("On Hover"), true);
|
||||
EditorGUILayout.PropertyField(onLeave, new GUIContent("On Leave"), true);
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d123696b48173d34ab865c2764affb4b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SettingsElementEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,72 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(CanvasGroup))]
|
||||
public class SettingsSubElement : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField][Range(0, 1)] private float disabledOpacity = 0.5f;
|
||||
[SerializeField][Range(1, 10)] private float animSpeed = 4;
|
||||
public DefaultState defaultState = DefaultState.Active;
|
||||
|
||||
[Header("Resources")]
|
||||
[SerializeField] private CanvasGroup targetCG;
|
||||
|
||||
public enum DefaultState { None, Active, Disabled }
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (targetCG == null)
|
||||
{
|
||||
targetCG = GetComponent<CanvasGroup>();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (defaultState == DefaultState.Active) { SetState(true); }
|
||||
else if (defaultState == DefaultState.Disabled) { SetState(false); }
|
||||
}
|
||||
|
||||
public void SetState(bool value)
|
||||
{
|
||||
if (value == true) { StartCoroutine("GroupIn"); defaultState = DefaultState.Active; }
|
||||
else { StartCoroutine("GroupOut"); defaultState = DefaultState.Disabled; }
|
||||
}
|
||||
|
||||
IEnumerator GroupIn()
|
||||
{
|
||||
StopCoroutine("GroupOut");
|
||||
|
||||
targetCG.interactable = true;
|
||||
targetCG.blocksRaycasts = true;
|
||||
|
||||
while (targetCG.alpha < 0.99)
|
||||
{
|
||||
targetCG.alpha += Time.unscaledDeltaTime * animSpeed;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
targetCG.alpha = 1;
|
||||
}
|
||||
|
||||
IEnumerator GroupOut()
|
||||
{
|
||||
StopCoroutine("GroupIn");
|
||||
|
||||
targetCG.interactable = false;
|
||||
targetCG.blocksRaycasts = false;
|
||||
|
||||
while (targetCG.alpha > disabledOpacity)
|
||||
{
|
||||
targetCG.alpha -= Time.unscaledDeltaTime * animSpeed;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
targetCG.alpha = disabledOpacity;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e3672d65a19e8654fb000921c5fd8b0d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: fd3012dcfab95cb469aa3dd70c6af50b, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SettingsSubElement.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,405 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[ExecuteInEditMode]
|
||||
[DisallowMultipleComponent]
|
||||
[RequireComponent(typeof(Animator))]
|
||||
public class ShopButtonManager : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
|
||||
{
|
||||
// Content
|
||||
public State state = State.Default;
|
||||
public Sprite buttonIcon;
|
||||
public string buttonTitle = "Button";
|
||||
public string titleLocalizationKey;
|
||||
public string buttonDescription = "Description";
|
||||
public string descriptionLocalizationKey;
|
||||
public Sprite priceIcon;
|
||||
public string priceText = "123";
|
||||
public BackgroundFilter backgroundFilter;
|
||||
|
||||
// Resources
|
||||
[SerializeField] private Animator animator;
|
||||
public ButtonManager purchaseButton;
|
||||
public ButtonManager purchasedButton;
|
||||
public GameObject purchasedIndicator;
|
||||
public ModalWindowManager purchaseModal;
|
||||
public Image iconObj;
|
||||
public Image priceIconObj;
|
||||
public TextMeshProUGUI titleObj;
|
||||
public TextMeshProUGUI descriptionObj;
|
||||
public TextMeshProUGUI priceObj;
|
||||
public Image filterObj;
|
||||
public List<Sprite> filters = new List<Sprite>();
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool enableIcon = false;
|
||||
public bool enableTitle = true;
|
||||
public bool enableDescription = true;
|
||||
public bool enablePrice = true;
|
||||
public bool enableFilter = true;
|
||||
public bool useModalWindow = true;
|
||||
public bool useCustomContent = false;
|
||||
public bool useLocalization = true;
|
||||
public bool bypassUpdateOnEnable = false;
|
||||
public bool useUINavigation = false;
|
||||
public Navigation.Mode navigationMode = Navigation.Mode.Automatic;
|
||||
public GameObject selectOnUp;
|
||||
public GameObject selectOnDown;
|
||||
public GameObject selectOnLeft;
|
||||
public GameObject selectOnRight;
|
||||
public bool wrapAround = false;
|
||||
public bool useSounds = true;
|
||||
|
||||
// Events
|
||||
public UnityEvent onPurchaseClick = new UnityEvent();
|
||||
public UnityEvent onPurchase = new UnityEvent();
|
||||
public UnityEvent onClick = new UnityEvent();
|
||||
public UnityEvent onHover = new UnityEvent();
|
||||
public UnityEvent onLeave = new UnityEvent();
|
||||
public UnityEvent onSelect = new UnityEvent();
|
||||
public UnityEvent onDeselect = new UnityEvent();
|
||||
|
||||
// Helpers
|
||||
bool isInitialized = false;
|
||||
float cachedStateLength = 0.5f;
|
||||
Button targetButton;
|
||||
#if UNITY_EDITOR
|
||||
public int latestTabIndex = 0;
|
||||
#endif
|
||||
|
||||
public enum State { Default, Purchased }
|
||||
|
||||
public enum BackgroundFilter
|
||||
{
|
||||
Aqua,
|
||||
Dawn,
|
||||
Dusk,
|
||||
Emerald,
|
||||
Kylo,
|
||||
Memory,
|
||||
Mice,
|
||||
Pinky,
|
||||
Retro,
|
||||
Rock,
|
||||
Sunset,
|
||||
Violet,
|
||||
Warm,
|
||||
Random
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
cachedStateLength = HeatUIInternalTools.GetAnimatorClipLength(animator, "ShopButton_Highlighted") + 0.1f;
|
||||
InitializePurchaseEvents();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (!isInitialized) { Initialize(); }
|
||||
if (!bypassUpdateOnEnable) { UpdateUI(); }
|
||||
if (Application.isPlaying && useUINavigation) { AddUINavigation(); }
|
||||
else if (Application.isPlaying && !useUINavigation && targetButton == null)
|
||||
{
|
||||
targetButton = gameObject.AddComponent<Button>();
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
}
|
||||
|
||||
void Initialize()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying) { return; }
|
||||
#endif
|
||||
if (ControllerManager.instance != null) { ControllerManager.instance.shopButtons.Add(this); }
|
||||
if (UIManagerAudio.instance == null) { useSounds = false; }
|
||||
if (animator == null) { animator = GetComponent<Animator>(); }
|
||||
if (GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
TriggerAnimation("Start");
|
||||
|
||||
if (useLocalization && !useCustomContent)
|
||||
{
|
||||
LocalizedObject mainLoc = GetComponent<LocalizedObject>();
|
||||
|
||||
if (mainLoc == null || !mainLoc.CheckLocalizationStatus()) { useLocalization = false; }
|
||||
else
|
||||
{
|
||||
if (titleObj != null && !string.IsNullOrEmpty(titleLocalizationKey))
|
||||
{
|
||||
LocalizedObject titleLoc = titleObj.gameObject.GetComponent<LocalizedObject>();
|
||||
if (titleLoc != null)
|
||||
{
|
||||
titleLoc.tableIndex = mainLoc.tableIndex;
|
||||
titleLoc.localizationKey = titleLocalizationKey;
|
||||
titleLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptionObj != null && !string.IsNullOrEmpty(descriptionLocalizationKey))
|
||||
{
|
||||
LocalizedObject descLoc = descriptionObj.gameObject.GetComponent<LocalizedObject>();
|
||||
if (descLoc != null)
|
||||
{
|
||||
descLoc.tableIndex = mainLoc.tableIndex;
|
||||
descLoc.localizationKey = descriptionLocalizationKey;
|
||||
descLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
// Change button text on language change
|
||||
mainLoc.onLanguageChanged.AddListener(delegate
|
||||
{
|
||||
buttonTitle = mainLoc.GetKeyOutput(titleLocalizationKey);
|
||||
buttonDescription = mainLoc.GetKeyOutput(descriptionLocalizationKey);
|
||||
UpdateUI();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (enableIcon && iconObj != null) { iconObj.gameObject.SetActive(true); iconObj.sprite = buttonIcon; }
|
||||
else if (iconObj != null) { iconObj.gameObject.SetActive(false); }
|
||||
|
||||
if (enableTitle && titleObj != null) { titleObj.gameObject.SetActive(true); titleObj.text = buttonTitle; }
|
||||
else if (titleObj != null) { titleObj.gameObject.SetActive(false); }
|
||||
|
||||
if (enableDescription && descriptionObj != null) { descriptionObj.gameObject.SetActive(true); descriptionObj.text = buttonDescription; }
|
||||
else if (descriptionObj != null)
|
||||
{
|
||||
descriptionObj.gameObject.SetActive(false);
|
||||
if (Application.isPlaying && enableTitle && titleObj != null) { titleObj.transform.parent.gameObject.name = titleObj.gameObject.name + "_D"; }
|
||||
}
|
||||
|
||||
if (!enablePrice && priceObj != null) { priceObj.transform.parent.gameObject.SetActive(false); }
|
||||
else if (enablePrice && priceIconObj != null)
|
||||
{
|
||||
if (priceObj != null) { priceObj.transform.parent.gameObject.SetActive(true); priceObj.text = priceText; }
|
||||
if (priceIconObj != null) { priceIconObj.sprite = priceIcon; }
|
||||
}
|
||||
|
||||
if (!enableFilter && filterObj != null) { filterObj.gameObject.SetActive(false); }
|
||||
else if (enableFilter && filterObj != null && filters.Count > 1)
|
||||
{
|
||||
filterObj.gameObject.SetActive(true);
|
||||
|
||||
if (Application.isPlaying && backgroundFilter == BackgroundFilter.Random) { filterObj.sprite = filters[Random.Range(0, filters.Count - 1)]; }
|
||||
else if (filters.Count >= (int)backgroundFilter + 1) { filterObj.sprite = filters[(int)backgroundFilter]; }
|
||||
}
|
||||
|
||||
UpdateState();
|
||||
|
||||
if (!Application.isPlaying || !gameObject.activeInHierarchy) { return; }
|
||||
|
||||
animator.enabled = true;
|
||||
animator.SetTrigger("Start");
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
public void UpdateState()
|
||||
{
|
||||
if (purchaseButton == null || purchasedButton == null || purchasedIndicator == null)
|
||||
return;
|
||||
|
||||
if (state == State.Default)
|
||||
{
|
||||
purchaseButton.gameObject.SetActive(true);
|
||||
purchasedButton.gameObject.SetActive(false);
|
||||
purchasedIndicator.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
else if (state == State.Purchased)
|
||||
{
|
||||
purchaseButton.gameObject.SetActive(false);
|
||||
purchasedButton.gameObject.SetActive(true);
|
||||
purchasedIndicator.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetState(State tempState)
|
||||
{
|
||||
state = tempState;
|
||||
UpdateState();
|
||||
}
|
||||
|
||||
public void Purchase()
|
||||
{
|
||||
if (state == State.Purchased)
|
||||
return;
|
||||
|
||||
SetState(State.Purchased);
|
||||
onPurchase.Invoke();
|
||||
}
|
||||
|
||||
public void InitializePurchaseEvents()
|
||||
{
|
||||
if (purchaseButton == null)
|
||||
{
|
||||
Debug.LogError("<b>[Shop Button]</b> 'Purchase Button' is missing.", this);
|
||||
return;
|
||||
}
|
||||
|
||||
purchaseButton.onClick.RemoveAllListeners();
|
||||
|
||||
if (useModalWindow && purchaseModal != null)
|
||||
{
|
||||
onPurchaseClick.AddListener(delegate
|
||||
{
|
||||
purchaseModal.onConfirm.RemoveAllListeners();
|
||||
purchaseModal.onConfirm.AddListener(Purchase);
|
||||
purchaseModal.onConfirm.AddListener(purchaseModal.CloseWindow);
|
||||
purchaseModal.OpenWindow();
|
||||
});
|
||||
}
|
||||
|
||||
purchaseButton.onClick.AddListener(onPurchaseClick.Invoke);
|
||||
}
|
||||
|
||||
public void SetText(string text) { buttonTitle = text; UpdateUI(); }
|
||||
public void SetIcon(Sprite icon) { buttonIcon = icon; UpdateUI(); }
|
||||
public void SetPrice(string text) { priceText = text; UpdateUI(); }
|
||||
public void SetInteractable(bool value) { isInteractable = value; }
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
if (targetButton == null)
|
||||
{
|
||||
if (gameObject.GetComponent<Button>() == null) { targetButton = gameObject.AddComponent<Button>(); }
|
||||
else { targetButton = GetComponent<Button>(); }
|
||||
|
||||
targetButton.transition = Selectable.Transition.None;
|
||||
}
|
||||
|
||||
if (targetButton.navigation.mode == navigationMode)
|
||||
return;
|
||||
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = navigationMode;
|
||||
|
||||
if (navigationMode == Navigation.Mode.Vertical || navigationMode == Navigation.Mode.Horizontal) { customNav.wrapAround = wrapAround; }
|
||||
else if (navigationMode == Navigation.Mode.Explicit) { StartCoroutine("InitUINavigation", customNav); return; }
|
||||
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
|
||||
public void DisableUINavigation()
|
||||
{
|
||||
if (targetButton != null)
|
||||
{
|
||||
Navigation customNav = new Navigation();
|
||||
Navigation.Mode navMode = Navigation.Mode.None;
|
||||
customNav.mode = navMode;
|
||||
targetButton.navigation = customNav;
|
||||
}
|
||||
}
|
||||
|
||||
public void InvokeOnClick()
|
||||
{
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
void TriggerAnimation(string triggername)
|
||||
{
|
||||
animator.enabled = true;
|
||||
|
||||
animator.ResetTrigger("Start");
|
||||
animator.ResetTrigger("Normal");
|
||||
animator.ResetTrigger("Highlighted");
|
||||
|
||||
animator.SetTrigger(triggername);
|
||||
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable || eventData.button != PointerEventData.InputButton.Left) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
// Invoke click actions
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
TriggerAnimation("Highlighted");
|
||||
onHover.Invoke();
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
TriggerAnimation("Normal");
|
||||
onLeave.Invoke();
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
TriggerAnimation("Highlighted");
|
||||
onSelect.Invoke();
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
TriggerAnimation("Normal");
|
||||
onDeselect.Invoke();
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
if (EventSystem.current.currentSelectedGameObject != gameObject) { TriggerAnimation("Normal"); }
|
||||
|
||||
onClick.Invoke();
|
||||
}
|
||||
|
||||
IEnumerator InitUINavigation(Navigation nav)
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.1f);
|
||||
|
||||
if (selectOnUp != null) { nav.selectOnUp = selectOnUp.GetComponent<Selectable>(); }
|
||||
if (selectOnDown != null) { nav.selectOnDown = selectOnDown.GetComponent<Selectable>(); }
|
||||
if (selectOnLeft != null) { nav.selectOnLeft = selectOnLeft.GetComponent<Selectable>(); }
|
||||
if (selectOnRight != null) { nav.selectOnRight = selectOnRight.GetComponent<Selectable>(); }
|
||||
|
||||
targetButton.navigation = nav;
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(cachedStateLength);
|
||||
animator.enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 85d9d6a0868c13243ba8f3abbae7ed13
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: b044a95718e69ee40ac27035753bf3c6, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ShopButtonManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,279 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(ShopButtonManager))]
|
||||
public class ShopButtonManagerEditor : Editor
|
||||
{
|
||||
private ShopButtonManager buttonTarget;
|
||||
private GUISkin customSkin;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
buttonTarget = (ShopButtonManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Button Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
buttonTarget.latestTabIndex = HeatUIEditorHandler.DrawTabs(buttonTarget.latestTabIndex, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
buttonTarget.latestTabIndex = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
buttonTarget.latestTabIndex = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
buttonTarget.latestTabIndex = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var animator = serializedObject.FindProperty("animator");
|
||||
var purchaseButton = serializedObject.FindProperty("purchaseButton");
|
||||
var purchasedButton = serializedObject.FindProperty("purchasedButton");
|
||||
var purchasedIndicator = serializedObject.FindProperty("purchasedIndicator");
|
||||
var purchaseModal = serializedObject.FindProperty("purchaseModal");
|
||||
var iconObj = serializedObject.FindProperty("iconObj");
|
||||
var titleObj = serializedObject.FindProperty("titleObj");
|
||||
var descriptionObj = serializedObject.FindProperty("descriptionObj");
|
||||
var priceIconObj = serializedObject.FindProperty("priceIconObj");
|
||||
var priceObj = serializedObject.FindProperty("priceObj");
|
||||
var filterObj = serializedObject.FindProperty("filterObj");
|
||||
|
||||
var state = serializedObject.FindProperty("state");
|
||||
var buttonIcon = serializedObject.FindProperty("buttonIcon");
|
||||
var buttonTitle = serializedObject.FindProperty("buttonTitle");
|
||||
var titleLocalizationKey = serializedObject.FindProperty("titleLocalizationKey");
|
||||
var buttonDescription = serializedObject.FindProperty("buttonDescription");
|
||||
var descriptionLocalizationKey = serializedObject.FindProperty("descriptionLocalizationKey");
|
||||
var priceIcon = serializedObject.FindProperty("priceIcon");
|
||||
var priceText = serializedObject.FindProperty("priceText");
|
||||
var backgroundFilter = serializedObject.FindProperty("backgroundFilter");
|
||||
|
||||
var isInteractable = serializedObject.FindProperty("isInteractable");
|
||||
var enableIcon = serializedObject.FindProperty("enableIcon");
|
||||
var enableTitle = serializedObject.FindProperty("enableTitle");
|
||||
var enableDescription = serializedObject.FindProperty("enableDescription");
|
||||
var enablePrice = serializedObject.FindProperty("enablePrice");
|
||||
var enableFilter = serializedObject.FindProperty("enableFilter");
|
||||
var useModalWindow = serializedObject.FindProperty("useModalWindow");
|
||||
var useUINavigation = serializedObject.FindProperty("useUINavigation");
|
||||
var navigationMode = serializedObject.FindProperty("navigationMode");
|
||||
var wrapAround = serializedObject.FindProperty("wrapAround");
|
||||
var selectOnUp = serializedObject.FindProperty("selectOnUp");
|
||||
var selectOnDown = serializedObject.FindProperty("selectOnDown");
|
||||
var selectOnLeft = serializedObject.FindProperty("selectOnLeft");
|
||||
var selectOnRight = serializedObject.FindProperty("selectOnRight");
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var useSounds = serializedObject.FindProperty("useSounds");
|
||||
var useCustomContent = serializedObject.FindProperty("useCustomContent");
|
||||
|
||||
var onClick = serializedObject.FindProperty("onClick");
|
||||
var onPurchaseClick = serializedObject.FindProperty("onPurchaseClick");
|
||||
var onPurchase = serializedObject.FindProperty("onPurchase");
|
||||
|
||||
switch (buttonTarget.latestTabIndex)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
HeatUIEditorHandler.DrawPropertyCW(state, customSkin, "Item State", 110);
|
||||
|
||||
if (useCustomContent.boolValue == false)
|
||||
{
|
||||
if (buttonTarget.iconObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableIcon.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableIcon.boolValue, customSkin, "Enable Icon");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableIcon.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonIcon, customSkin, "Button Icon", 110);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.titleObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableTitle.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableTitle.boolValue, customSkin, "Enable Title");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableTitle.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonTitle, customSkin, "Button Text", 110);
|
||||
if (useLocalization.boolValue == true) { HeatUIEditorHandler.DrawPropertyCW(titleLocalizationKey, customSkin, "Localization Key", 110); }
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.descriptionObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableDescription.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableDescription.boolValue, customSkin, "Enable Description");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableDescription.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(buttonDescription, customSkin, "Description", 110);
|
||||
if (useLocalization.boolValue == true) { HeatUIEditorHandler.DrawPropertyCW(descriptionLocalizationKey, customSkin, "Localization Key", 110); }
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.priceObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enablePrice.boolValue = HeatUIEditorHandler.DrawTogglePlain(enablePrice.boolValue, customSkin, "Enable Price");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enablePrice.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(priceIcon, customSkin, "Price Icon", 110);
|
||||
HeatUIEditorHandler.DrawPropertyCW(priceText, customSkin, "Price Text", 110);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
if (buttonTarget.filterObj != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
enableFilter.boolValue = HeatUIEditorHandler.DrawTogglePlain(enableFilter.boolValue, customSkin, "Enable Hover Filter");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (enableFilter.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(backgroundFilter, customSkin, "Background Filter", 110);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
useModalWindow.boolValue = HeatUIEditorHandler.DrawTogglePlain(useModalWindow.boolValue, customSkin, "Use Modal Window");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (useModalWindow.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(purchaseModal, customSkin, "Purchase Window", 110);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
if (Application.isPlaying == false) { buttonTarget.UpdateUI(); }
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("'Use Custom Content' is enabled. Content is now managed manually.", MessageType.Info); }
|
||||
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
|
||||
if (Application.isPlaying == true && GUILayout.Button("Update UI", customSkin.button)) { buttonTarget.UpdateUI(); }
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onClick, new GUIContent("On Click"), true);
|
||||
EditorGUILayout.PropertyField(onPurchaseClick, new GUIContent("On Purchase Click"), true);
|
||||
EditorGUILayout.PropertyField(onPurchase, new GUIContent("On Purchase"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(animator, customSkin, "Animator");
|
||||
HeatUIEditorHandler.DrawProperty(purchaseButton, customSkin, "Purchase Button");
|
||||
HeatUIEditorHandler.DrawProperty(purchasedButton, customSkin, "Purchased Button");
|
||||
HeatUIEditorHandler.DrawProperty(purchasedIndicator, customSkin, "Purchased Indicator");
|
||||
HeatUIEditorHandler.DrawProperty(iconObj, customSkin, "Icon Object");
|
||||
HeatUIEditorHandler.DrawProperty(titleObj, customSkin, "Title Object");
|
||||
HeatUIEditorHandler.DrawProperty(descriptionObj, customSkin, "Description Object");
|
||||
HeatUIEditorHandler.DrawProperty(priceObj, customSkin, "Price Object");
|
||||
HeatUIEditorHandler.DrawProperty(priceIconObj, customSkin, "Price Icon Object");
|
||||
HeatUIEditorHandler.DrawProperty(filterObj, customSkin, "Filter Object");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
useCustomContent.boolValue = HeatUIEditorHandler.DrawToggle(useCustomContent.boolValue, customSkin, "Use Custom Content", "Bypasses inspector values and allows manual editing.");
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
GUI.enabled = true;
|
||||
useSounds.boolValue = HeatUIEditorHandler.DrawToggle(useSounds.boolValue, customSkin, "Use Button Sounds");
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
|
||||
useUINavigation.boolValue = HeatUIEditorHandler.DrawTogglePlain(useUINavigation.boolValue, customSkin, "Use UI Navigation", "Enables controller navigation.");
|
||||
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (useUINavigation.boolValue == true)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
HeatUIEditorHandler.DrawPropertyPlain(navigationMode, customSkin, "Navigation Mode");
|
||||
|
||||
if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Horizontal)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawToggle(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Vertical)
|
||||
{
|
||||
wrapAround.boolValue = HeatUIEditorHandler.DrawTogglePlain(wrapAround.boolValue, customSkin, "Wrap Around");
|
||||
}
|
||||
|
||||
else if (buttonTarget.navigationMode == UnityEngine.UI.Navigation.Mode.Explicit)
|
||||
{
|
||||
EditorGUI.indentLevel = 1;
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnUp, customSkin, "Select On Up");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnDown, customSkin, "Select On Down");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnLeft, customSkin, "Select On Left");
|
||||
HeatUIEditorHandler.DrawPropertyPlain(selectOnRight, customSkin, "Select On Right");
|
||||
EditorGUI.indentLevel = 0;
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
buttonTarget.UpdateUI();
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 81b588e3927b0204484d75f84a833d00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/ShopButtonManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,68 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.InputSystem;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(TMP_InputField))]
|
||||
public class SliderInput : MonoBehaviour
|
||||
{
|
||||
[Header("Resources")]
|
||||
[SerializeField] private SliderManager sliderManager;
|
||||
[SerializeField] private TMP_InputField inputField;
|
||||
|
||||
[Header("Settings")]
|
||||
[SerializeField] private bool multiplyValue = false;
|
||||
[Range(1, 10)] public int maxChar = 5;
|
||||
[Range(0, 4)] public int decimals = 1;
|
||||
|
||||
[Header("Events")]
|
||||
public UnityEvent onSubmit;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (sliderManager == null) { Debug.LogWarning("'Slider Manager' is missing!"); return; }
|
||||
if (inputField == null) { inputField = GetComponent<TMP_InputField>(); }
|
||||
|
||||
if (sliderManager.mainSlider.wholeNumbers == true) { inputField.contentType = TMP_InputField.ContentType.IntegerNumber; }
|
||||
else if (sliderManager.mainSlider.wholeNumbers == true) { inputField.contentType = TMP_InputField.ContentType.DecimalNumber; decimals = 0; }
|
||||
|
||||
inputField.characterLimit = maxChar;
|
||||
inputField.selectionColor = new Color(inputField.textComponent.color.r, inputField.textComponent.color.g, inputField.textComponent.color.b, inputField.selectionColor.a);
|
||||
inputField.onDeselect.AddListener(delegate { SetText(sliderManager.mainSlider.value); });
|
||||
onSubmit.AddListener(SetValue);
|
||||
|
||||
sliderManager.mainSlider.onValueChanged.AddListener(SetText);
|
||||
sliderManager.mainSlider.onValueChanged.Invoke(sliderManager.mainSlider.value);
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (string.IsNullOrEmpty(inputField.text) == true || EventSystem.current.currentSelectedGameObject != inputField.gameObject) { return; }
|
||||
if (Keyboard.current.enterKey.wasPressedThisFrame) { onSubmit.Invoke(); }
|
||||
}
|
||||
|
||||
void SetText(float value)
|
||||
{
|
||||
if (multiplyValue == true) { value = value * 100; }
|
||||
|
||||
if (decimals == 0) { inputField.text = value.ToString("F0"); }
|
||||
else if (decimals == 1) { inputField.text = value.ToString("F1"); }
|
||||
else if (decimals == 2) { inputField.text = value.ToString("F2"); }
|
||||
else if (decimals == 3) { inputField.text = value.ToString("F3"); }
|
||||
else if(decimals == 4) { inputField.text = value.ToString("F4"); }
|
||||
}
|
||||
|
||||
void SetValue()
|
||||
{
|
||||
if (sliderManager.mainSlider.wholeNumbers == true) { sliderManager.mainSlider.value = int.Parse(inputField.text); }
|
||||
else if (multiplyValue == true) { sliderManager.mainSlider.value = (float.Parse(inputField.text) / 100); }
|
||||
else { sliderManager.mainSlider.value = float.Parse(inputField.text); }
|
||||
|
||||
if (multiplyValue == false && float.Parse(inputField.text) > sliderManager.mainSlider.maxValue) { sliderManager.mainSlider.value = sliderManager.mainSlider.maxValue; }
|
||||
else if (multiplyValue == true && (float.Parse(inputField.text) / 100) > sliderManager.mainSlider.maxValue) { sliderManager.mainSlider.value = sliderManager.mainSlider.maxValue; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6882cd12fef321743805883a56b89c9b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: dc7b26f02163c8a40ad68d18b8f7ecfd, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SliderInput.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,170 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(Slider))]
|
||||
public class SliderManager : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler
|
||||
{
|
||||
// Resources
|
||||
public Slider mainSlider;
|
||||
[SerializeField] private TextMeshProUGUI valueText;
|
||||
[SerializeField] private CanvasGroup highlightCG;
|
||||
|
||||
// Saving
|
||||
public bool saveValue = false;
|
||||
public bool invokeOnAwake = true;
|
||||
public string saveKey = "My Slider";
|
||||
|
||||
// Settings
|
||||
public bool isInteractable = true;
|
||||
public bool usePercent = false;
|
||||
public bool showValue = true;
|
||||
public bool showPopupValue = true;
|
||||
public bool useRoundValue = false;
|
||||
public bool useSounds = true;
|
||||
[Range(1, 15)] public float fadingMultiplier = 8;
|
||||
|
||||
// Events
|
||||
[System.Serializable] public class SliderEvent : UnityEvent<float> { }
|
||||
[SerializeField] public SliderEvent onValueChanged = new SliderEvent();
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (highlightCG == null) { highlightCG = new GameObject().AddComponent<CanvasGroup>(); highlightCG.gameObject.AddComponent<RectTransform>(); highlightCG.transform.SetParent(transform); highlightCG.gameObject.name = "Highlight"; }
|
||||
if (mainSlider == null) { mainSlider = gameObject.GetComponent<Slider>(); }
|
||||
if (gameObject.GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 0;
|
||||
highlightCG.gameObject.SetActive(false);
|
||||
float saveVal = mainSlider.value;
|
||||
|
||||
if (saveValue == true)
|
||||
{
|
||||
if (PlayerPrefs.HasKey("Slider_" + saveKey) == true) { saveVal = PlayerPrefs.GetFloat("Slider_" + saveKey); }
|
||||
else { PlayerPrefs.SetFloat("Slider_" + saveKey, saveVal); }
|
||||
|
||||
mainSlider.value = saveVal;
|
||||
mainSlider.onValueChanged.AddListener(delegate { PlayerPrefs.SetFloat("Slider_" + saveKey, mainSlider.value); });
|
||||
}
|
||||
|
||||
mainSlider.onValueChanged.AddListener(delegate
|
||||
{
|
||||
onValueChanged.Invoke(mainSlider.value);
|
||||
UpdateUI();
|
||||
});
|
||||
|
||||
if (invokeOnAwake == true) { onValueChanged.Invoke(mainSlider.value); }
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (UIManagerAudio.instance == null)
|
||||
{
|
||||
useSounds = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void Interactable(bool value)
|
||||
{
|
||||
isInteractable = value;
|
||||
mainSlider.interactable = isInteractable;
|
||||
}
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = Navigation.Mode.Automatic;
|
||||
mainSlider.navigation = customNav;
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (valueText == null)
|
||||
return;
|
||||
|
||||
if (useRoundValue == true)
|
||||
{
|
||||
if (usePercent == true && valueText != null) { valueText.text = Mathf.Round(mainSlider.value * 1.0f).ToString() + "%"; }
|
||||
else if (valueText != null) { valueText.text = Mathf.Round(mainSlider.value * 1.0f).ToString(); }
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (usePercent == true && valueText != null) { valueText.text = mainSlider.value.ToString("F1") + "%"; }
|
||||
else if (valueText != null) { valueText.text = mainSlider.value.ToString("F1"); }
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
if (isInteractable == false) { return; }
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (isInteractable == false)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (isInteractable == false)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (isInteractable == false)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
IEnumerator SetNormal()
|
||||
{
|
||||
StopCoroutine("SetHighlight");
|
||||
|
||||
while (highlightCG.alpha > 0.01f)
|
||||
{
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 0;
|
||||
highlightCG.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
IEnumerator SetHighlight()
|
||||
{
|
||||
StopCoroutine("SetNormal");
|
||||
highlightCG.gameObject.SetActive(true);
|
||||
|
||||
while (highlightCG.alpha < 0.99f)
|
||||
{
|
||||
highlightCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7d5511489d4e1f144a93a55cef49fc1f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: dc7b26f02163c8a40ad68d18b8f7ecfd, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SliderManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,172 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine.UI;
|
||||
using UnityEditor.SceneManagement;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(SliderManager))]
|
||||
public class SliderManagerEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private SliderManager sTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
sTarget = (SliderManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Slider Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
|
||||
var sliderObject = serializedObject.FindProperty("mainSlider");
|
||||
var valueText = serializedObject.FindProperty("valueText");
|
||||
var highlightCG = serializedObject.FindProperty("highlightCG");
|
||||
|
||||
var saveValue = serializedObject.FindProperty("saveValue");
|
||||
var saveKey = serializedObject.FindProperty("saveKey");
|
||||
var usePercent = serializedObject.FindProperty("usePercent");
|
||||
var useRoundValue = serializedObject.FindProperty("useRoundValue");
|
||||
var showValue = serializedObject.FindProperty("showValue");
|
||||
var showPopupValue = serializedObject.FindProperty("showPopupValue");
|
||||
var invokeOnAwake = serializedObject.FindProperty("invokeOnAwake");
|
||||
var fadingMultiplier = serializedObject.FindProperty("fadingMultiplier");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (sTarget.mainSlider != null)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
float tempValue = sTarget.mainSlider.value;
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Value"), customSkin.FindStyle("Text"), GUILayout.Width(120));
|
||||
sTarget.mainSlider.value = EditorGUILayout.Slider(sTarget.mainSlider.value, sTarget.mainSlider.minValue, sTarget.mainSlider.maxValue);
|
||||
if (tempValue != sTarget.mainSlider.value) { Undo.RegisterCompleteObjectUndo(sTarget.mainSlider, sTarget.name); }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
float tempMinValue = sTarget.mainSlider.minValue;
|
||||
|
||||
if (sTarget.mainSlider.wholeNumbers == false) { tempMinValue = EditorGUILayout.FloatField(new GUIContent("Min Value"), sTarget.mainSlider.minValue); }
|
||||
else { tempMinValue = EditorGUILayout.IntField(new GUIContent("Min Value"), (int)sTarget.mainSlider.minValue); }
|
||||
|
||||
if (tempMinValue < sTarget.mainSlider.maxValue && tempMinValue != sTarget.mainSlider.minValue)
|
||||
{
|
||||
sTarget.mainSlider.minValue = tempMinValue;
|
||||
EditorUtility.SetDirty(sTarget.mainSlider);
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
else { tempMinValue = sTarget.mainSlider.minValue; }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
float tempMaxValue = sTarget.mainSlider.maxValue;
|
||||
|
||||
if (sTarget.mainSlider.wholeNumbers == false) { tempMaxValue = EditorGUILayout.FloatField(new GUIContent("Max Value"), sTarget.mainSlider.maxValue); }
|
||||
else { tempMaxValue = EditorGUILayout.IntField(new GUIContent("Max Value"), (int)sTarget.mainSlider.maxValue); }
|
||||
|
||||
if (tempMaxValue > sTarget.mainSlider.minValue && tempMaxValue != sTarget.mainSlider.maxValue)
|
||||
{
|
||||
sTarget.mainSlider.maxValue = tempMaxValue;
|
||||
EditorUtility.SetDirty(sTarget.mainSlider);
|
||||
EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
|
||||
}
|
||||
else { tempMaxValue = sTarget.mainSlider.maxValue; }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.EndVertical();
|
||||
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
bool tempWN = sTarget.mainSlider.wholeNumbers;
|
||||
sTarget.mainSlider.wholeNumbers = GUILayout.Toggle(sTarget.mainSlider.wholeNumbers, new GUIContent("Use Whole Numbers"), customSkin.FindStyle("Toggle"));
|
||||
sTarget.mainSlider.wholeNumbers = GUILayout.Toggle(sTarget.mainSlider.wholeNumbers, new GUIContent(""), customSkin.FindStyle("Toggle Helper"));
|
||||
if (tempWN != sTarget.mainSlider.wholeNumbers) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.BeginHorizontal(EditorStyles.helpBox);
|
||||
|
||||
bool tempInt = sTarget.mainSlider.interactable;
|
||||
sTarget.mainSlider.interactable = GUILayout.Toggle(sTarget.mainSlider.interactable, new GUIContent("Is Interactable"), customSkin.FindStyle("Toggle"));
|
||||
sTarget.mainSlider.interactable = GUILayout.Toggle(sTarget.mainSlider.interactable, new GUIContent(""), customSkin.FindStyle("Toggle Helper"));
|
||||
if (tempInt != sTarget.mainSlider.interactable) { EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); }
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
if (Application.isPlaying == false) { sTarget.UpdateUI(); }
|
||||
}
|
||||
|
||||
else { sTarget.mainSlider = sTarget.GetComponent<Slider>(); }
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(sliderObject, customSkin, "Slider Source");
|
||||
if (showValue.boolValue == true) { HeatUIEditorHandler.DrawProperty(valueText, customSkin, "Label Text"); }
|
||||
HeatUIEditorHandler.DrawProperty(highlightCG, customSkin, "Highlight CG");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
usePercent.boolValue = HeatUIEditorHandler.DrawToggle(usePercent.boolValue, customSkin, "Use Percent");
|
||||
showValue.boolValue = HeatUIEditorHandler.DrawToggle(showValue.boolValue, customSkin, "Show Label");
|
||||
showPopupValue.boolValue = HeatUIEditorHandler.DrawToggle(showPopupValue.boolValue, customSkin, "Show Popup Label");
|
||||
useRoundValue.boolValue = HeatUIEditorHandler.DrawToggle(useRoundValue.boolValue, customSkin, "Use Round Value");
|
||||
invokeOnAwake.boolValue = HeatUIEditorHandler.DrawToggle(invokeOnAwake.boolValue, customSkin, "Invoke On Awake", "Process events on awake.");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
saveValue.boolValue = HeatUIEditorHandler.DrawTogglePlain(saveValue.boolValue, customSkin, "Save Value");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (saveValue.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyCW(saveKey, customSkin, "Save Key:", 66);
|
||||
EditorGUILayout.HelpBox("You must set a unique save key for each slider.", MessageType.Info);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawProperty(fadingMultiplier, customSkin, "Fading Multiplier");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cacceb6d64cd4e8448d377d948ed6eb2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SliderManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(Scrollbar))]
|
||||
public class SmoothScrollbar : MonoBehaviour
|
||||
{
|
||||
[Header("Settings")]
|
||||
[SerializeField] [Range(0.3f, 5)] private float curveSpeed = 1.5f;
|
||||
[SerializeField] private AnimationCurve animationCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f));
|
||||
private Scrollbar scrollbar;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
scrollbar = GetComponent<Scrollbar>();
|
||||
}
|
||||
|
||||
public void GoToTop()
|
||||
{
|
||||
StopCoroutine("GoBottom");
|
||||
StopCoroutine("GoTop");
|
||||
StartCoroutine("GoTop");
|
||||
}
|
||||
|
||||
public void GoToBottom()
|
||||
{
|
||||
StopCoroutine("GoBottom");
|
||||
StopCoroutine("GoTop");
|
||||
StartCoroutine("GoBottom");
|
||||
}
|
||||
|
||||
IEnumerator GoTop()
|
||||
{
|
||||
float startingPoint = scrollbar.value;
|
||||
float elapsedTime = 0;
|
||||
|
||||
while (scrollbar.value < 0.999f)
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
scrollbar.value = Mathf.Lerp(startingPoint, 1, animationCurve.Evaluate(elapsedTime * curveSpeed));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
scrollbar.value = 1;
|
||||
}
|
||||
|
||||
IEnumerator GoBottom()
|
||||
{
|
||||
float startingPoint = scrollbar.value;
|
||||
float elapsedTime = 0;
|
||||
|
||||
while (scrollbar.value > 0.001f)
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
scrollbar.value = Mathf.Lerp(startingPoint, 0, animationCurve.Evaluate(elapsedTime * curveSpeed));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
scrollbar.value = 0;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66e8ed26734261347a5a67a1783f8f05
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: dbc6cc7e705f0ed4a9d6338af5a89eb9, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SmoothScrollbar.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,267 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class SocialsWidget : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public List<Item> socials = new List<Item>();
|
||||
List<ButtonManager> buttons = new List<ButtonManager>();
|
||||
|
||||
// Resources
|
||||
[SerializeField] private GameObject itemPreset;
|
||||
[SerializeField] private Transform itemParent;
|
||||
[SerializeField] private GameObject buttonPreset;
|
||||
[SerializeField] private Transform buttonParent;
|
||||
[SerializeField] private Image background;
|
||||
|
||||
// Settings
|
||||
public bool useLocalization = true;
|
||||
[Range(1, 30)] public float timer = 4;
|
||||
[Range(0.1f, 3)] public float tintSpeed = 0.5f;
|
||||
[SerializeField] private AnimationCurve tintCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f));
|
||||
|
||||
// Helpers
|
||||
int currentSliderIndex;
|
||||
float timerCount = 0;
|
||||
bool isInitialized;
|
||||
bool updateTimer;
|
||||
bool isTransitionInProgress;
|
||||
Animator currentItemObject;
|
||||
LocalizedObject localizedObject;
|
||||
Image raycastImg;
|
||||
|
||||
[System.Serializable]
|
||||
public class Item
|
||||
{
|
||||
public string socialID = "News title";
|
||||
public Sprite icon;
|
||||
public Color backgroundTint = new Color(255, 255, 255, 255);
|
||||
[TextArea] public string description = "News description";
|
||||
public string link;
|
||||
public UnityEvent onClick = new UnityEvent();
|
||||
|
||||
[Header("Localization")]
|
||||
public string descriptionKey = "DescriptionKey";
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (isInitialized == false) { InitializeItems(); }
|
||||
else { StartCoroutine(InitCurrentItem()); }
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (isInitialized == false || updateTimer == false)
|
||||
return;
|
||||
|
||||
timerCount += Time.unscaledDeltaTime;
|
||||
|
||||
if (timerCount > timer)
|
||||
{
|
||||
SetSocialByTimer();
|
||||
timerCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void InitializeItems()
|
||||
{
|
||||
if (useLocalization == true)
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
if (localizedObject == null || localizedObject.CheckLocalizationStatus() == false) { useLocalization = false; }
|
||||
}
|
||||
|
||||
foreach (Transform child in itemParent) { Destroy(child.gameObject); }
|
||||
foreach (Transform child in buttonParent) { Destroy(child.gameObject); }
|
||||
for (int i = 0; i < socials.Count; ++i)
|
||||
{
|
||||
int tempIndex = i;
|
||||
|
||||
GameObject itemGO = Instantiate(itemPreset, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
itemGO.transform.SetParent(itemParent, false);
|
||||
itemGO.gameObject.name = socials[i].socialID;
|
||||
itemGO.SetActive(false);
|
||||
|
||||
TextMeshProUGUI itemDescription = itemGO.transform.GetComponentInChildren<TextMeshProUGUI>();
|
||||
if (useLocalization == false || string.IsNullOrEmpty(socials[i].descriptionKey)) { itemDescription.text = socials[i].description; }
|
||||
else
|
||||
{
|
||||
LocalizedObject tempLoc = itemDescription.GetComponent<LocalizedObject>();
|
||||
if (tempLoc != null)
|
||||
{
|
||||
tempLoc.tableIndex = localizedObject.tableIndex;
|
||||
tempLoc.localizationKey = socials[i].descriptionKey;
|
||||
tempLoc.onLanguageChanged.AddListener(delegate { itemDescription.text = tempLoc.GetKeyOutput(tempLoc.localizationKey); });
|
||||
tempLoc.InitializeItem();
|
||||
tempLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
GameObject btnGO = Instantiate(buttonPreset, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
btnGO.transform.SetParent(buttonParent, false);
|
||||
btnGO.gameObject.name = socials[i].socialID;
|
||||
|
||||
ButtonManager btn = btnGO.GetComponent<ButtonManager>();
|
||||
buttons.Add(btn);
|
||||
btn.SetIcon(socials[i].icon);
|
||||
btn.onClick.AddListener(delegate
|
||||
{
|
||||
socials[tempIndex].onClick.Invoke();
|
||||
if (string.IsNullOrEmpty(socials[tempIndex].link) == false) { Application.OpenURL(socials[tempIndex].link); }
|
||||
});
|
||||
btn.onHover.AddListener(delegate
|
||||
{
|
||||
foreach (ButtonManager tempBtn in buttons)
|
||||
{
|
||||
if (tempBtn == btn)
|
||||
continue;
|
||||
|
||||
tempBtn.Interactable(false);
|
||||
tempBtn.UpdateState();
|
||||
|
||||
StopCoroutine("SetSocialByHover");
|
||||
StartCoroutine("SetSocialByHover", tempIndex);
|
||||
}
|
||||
});
|
||||
btn.onLeave.AddListener(delegate
|
||||
{
|
||||
updateTimer = true;
|
||||
foreach (ButtonManager tempBtn in buttons)
|
||||
{
|
||||
if (tempBtn == btn)
|
||||
{
|
||||
tempBtn.StartCoroutine("SetHighlight");
|
||||
continue;
|
||||
}
|
||||
|
||||
tempBtn.Interactable(true);
|
||||
tempBtn.UpdateState();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
StartCoroutine(InitCurrentItem());
|
||||
isInitialized = true;
|
||||
|
||||
// Register raycast with image
|
||||
if (raycastImg == null)
|
||||
{
|
||||
raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSocialByTimer()
|
||||
{
|
||||
if (socials.Count > 1 && currentItemObject != null)
|
||||
{
|
||||
currentItemObject.enabled = true;
|
||||
currentItemObject.Play("Out");
|
||||
buttons[currentSliderIndex].UpdateState();
|
||||
|
||||
if (currentSliderIndex == socials.Count - 1) { currentSliderIndex = 0; }
|
||||
else { currentSliderIndex++; }
|
||||
|
||||
currentItemObject = itemParent.GetChild(currentSliderIndex).GetComponent<Animator>();
|
||||
currentItemObject.gameObject.SetActive(true);
|
||||
currentItemObject.enabled = true;
|
||||
currentItemObject.Play("In");
|
||||
buttons[currentSliderIndex].StartCoroutine("SetHighlight");
|
||||
|
||||
StopCoroutine("DisableItemAnimators");
|
||||
StartCoroutine("DisableItemAnimators");
|
||||
|
||||
if (background != null)
|
||||
{
|
||||
StopCoroutine("DoBackgroundColorLerp");
|
||||
StartCoroutine("DoBackgroundColorLerp");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator InitCurrentItem()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.02f);
|
||||
|
||||
currentItemObject = itemParent.GetChild(currentSliderIndex).GetComponent<Animator>();
|
||||
currentItemObject.gameObject.SetActive(true);
|
||||
currentItemObject.enabled = true;
|
||||
currentItemObject.Play("In");
|
||||
buttons[currentSliderIndex].StartCoroutine("SetHighlight");
|
||||
|
||||
StopCoroutine("DisableItemAnimators");
|
||||
StartCoroutine("DisableItemAnimators");
|
||||
|
||||
if (background != null)
|
||||
{
|
||||
StopCoroutine("DoBackgroundColorLerp");
|
||||
StartCoroutine("DoBackgroundColorLerp");
|
||||
}
|
||||
|
||||
timerCount = 0;
|
||||
updateTimer = true;
|
||||
}
|
||||
|
||||
IEnumerator SetSocialByHover(int index)
|
||||
{
|
||||
updateTimer = false;
|
||||
timerCount = 0;
|
||||
|
||||
if (currentSliderIndex == index) { yield break; }
|
||||
if (isTransitionInProgress == true) { yield return new WaitForSecondsRealtime(0.15f); isTransitionInProgress = false; }
|
||||
|
||||
isTransitionInProgress = true;
|
||||
|
||||
currentItemObject.enabled = true;
|
||||
currentItemObject.Play("Out");
|
||||
|
||||
currentSliderIndex = index;
|
||||
|
||||
currentItemObject = itemParent.GetChild(currentSliderIndex).GetComponent<Animator>();
|
||||
currentItemObject.gameObject.SetActive(true);
|
||||
currentItemObject.enabled = true;
|
||||
currentItemObject.Play("In");
|
||||
|
||||
StopCoroutine("DisableItemAnimators");
|
||||
StartCoroutine("DisableItemAnimators");
|
||||
|
||||
if (background != null)
|
||||
{
|
||||
StopCoroutine("DoBackgroundColorLerp");
|
||||
StartCoroutine("DoBackgroundColorLerp");
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DoBackgroundColorLerp()
|
||||
{
|
||||
float elapsedTime = 0;
|
||||
|
||||
while (background.color != socials[currentSliderIndex].backgroundTint)
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
background.color = Color.Lerp(background.color, socials[currentSliderIndex].backgroundTint, tintCurve.Evaluate(elapsedTime * tintSpeed));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
background.color = socials[currentSliderIndex].backgroundTint;
|
||||
}
|
||||
|
||||
IEnumerator DisableItemAnimators()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.6f);
|
||||
|
||||
for (int i = 0; i < socials.Count; i++)
|
||||
{
|
||||
if (i != currentSliderIndex) { itemParent.GetChild(i).gameObject.SetActive(false); }
|
||||
itemParent.GetChild(i).GetComponent<Animator>().enabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e0b3d7d612e9abb4bbcacc3ad689b1a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- itemPreset: {fileID: 5788905711005697609, guid: f1079baccc4cb6c4fad137d300429521,
|
||||
type: 3}
|
||||
- itemParent: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 441ebb1a140c9c1419229bc7b43d30bd, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SocialsWidget.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,88 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CanEditMultipleObjects]
|
||||
[CustomEditor(typeof(SocialsWidget))]
|
||||
public class SocialsWidgetEditor : Editor
|
||||
{
|
||||
private SocialsWidget swTarget;
|
||||
private GUISkin customSkin;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
swTarget = (SocialsWidget)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Socials Widget Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var socials = serializedObject.FindProperty("socials");
|
||||
|
||||
var itemPreset = serializedObject.FindProperty("itemPreset");
|
||||
var itemParent = serializedObject.FindProperty("itemParent");
|
||||
var buttonPreset = serializedObject.FindProperty("buttonPreset");
|
||||
var buttonParent = serializedObject.FindProperty("buttonParent");
|
||||
var background = serializedObject.FindProperty("background");
|
||||
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var timer = serializedObject.FindProperty("timer");
|
||||
var tintSpeed = serializedObject.FindProperty("tintSpeed");
|
||||
var tintCurve = serializedObject.FindProperty("tintCurve");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
EditorGUI.indentLevel = 1;
|
||||
EditorGUILayout.PropertyField(socials, new GUIContent("Socials"), true);
|
||||
EditorGUI.indentLevel = 0;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(itemPreset, customSkin, "Item Preset");
|
||||
HeatUIEditorHandler.DrawProperty(itemParent, customSkin, "Item Parent");
|
||||
HeatUIEditorHandler.DrawProperty(buttonPreset, customSkin, "Button Preset");
|
||||
HeatUIEditorHandler.DrawProperty(buttonParent, customSkin, "Button Parent");
|
||||
HeatUIEditorHandler.DrawProperty(background, customSkin, "Background");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization", "Bypasses localization functions when disabled.");
|
||||
HeatUIEditorHandler.DrawProperty(timer, customSkin, "Timer");
|
||||
HeatUIEditorHandler.DrawProperty(tintSpeed, customSkin, "Tint Speed");
|
||||
HeatUIEditorHandler.DrawProperty(tintCurve, customSkin, "Tint Curve");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dd1b2ea4efdd00d49a2516ac3afa472a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SocialsWidgetEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,270 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class SwitchManager : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler
|
||||
{
|
||||
// Resources
|
||||
[SerializeField] private Animator switchAnimator;
|
||||
[SerializeField] private CanvasGroup highlightCG;
|
||||
|
||||
// Saving
|
||||
public bool saveValue = false;
|
||||
public string saveKey = "My Switch";
|
||||
|
||||
// Settings
|
||||
public bool isOn = true;
|
||||
public bool isInteractable = true;
|
||||
public bool invokeOnEnable = true;
|
||||
public bool useSounds = true;
|
||||
public bool useUINavigation = false;
|
||||
[Range(1, 15)] public float fadingMultiplier = 8;
|
||||
|
||||
// Events
|
||||
[SerializeField] public SwitchEvent onValueChanged = new SwitchEvent();
|
||||
public UnityEvent onEvents = new UnityEvent();
|
||||
public UnityEvent offEvents = new UnityEvent();
|
||||
|
||||
[System.Serializable]
|
||||
public class SwitchEvent : UnityEvent<bool> { }
|
||||
|
||||
bool isInitialized = false;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (saveValue) { GetSavedData(); }
|
||||
else
|
||||
{
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
switchAnimator.enabled = true;
|
||||
|
||||
if (isOn) { switchAnimator.Play("On Instant"); }
|
||||
else { switchAnimator.Play("Off Instant"); }
|
||||
}
|
||||
|
||||
if (gameObject.GetComponent<Image>() == null)
|
||||
{
|
||||
Image raycastImg = gameObject.AddComponent<Image>();
|
||||
raycastImg.color = new Color(0, 0, 0, 0);
|
||||
raycastImg.raycastTarget = true;
|
||||
}
|
||||
|
||||
if (useUINavigation) { AddUINavigation(); }
|
||||
if (highlightCG == null) { highlightCG = new GameObject().AddComponent<CanvasGroup>(); highlightCG.transform.SetParent(transform); highlightCG.gameObject.name = "Highlighted"; }
|
||||
|
||||
if (invokeOnEnable && isOn) { onEvents.Invoke(); onValueChanged.Invoke(isOn); }
|
||||
else if (invokeOnEnable && !isOn) { offEvents.Invoke(); onValueChanged.Invoke(isOn); }
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (UIManagerAudio.instance == null) { useSounds = false; }
|
||||
if (isInitialized) { UpdateUI(); }
|
||||
}
|
||||
|
||||
void GetSavedData()
|
||||
{
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
switchAnimator.enabled = true;
|
||||
|
||||
if (PlayerPrefs.GetString("Switch_" + saveKey) == "" || !PlayerPrefs.HasKey("Switch_" + saveKey))
|
||||
{
|
||||
if (isOn) { switchAnimator.Play("Off"); PlayerPrefs.SetString("Switch_" + saveKey, "true"); }
|
||||
else { switchAnimator.Play("Off"); PlayerPrefs.SetString("Switch_" + saveKey, "false"); }
|
||||
}
|
||||
else if (PlayerPrefs.GetString("Switch_" + saveKey) == "true") { switchAnimator.Play("Off"); isOn = true; }
|
||||
else if (PlayerPrefs.GetString("Switch_" + saveKey) == "false") { switchAnimator.Play("Off"); isOn = false; }
|
||||
}
|
||||
|
||||
public void AddUINavigation()
|
||||
{
|
||||
Button navButton = gameObject.AddComponent<Button>();
|
||||
navButton.transition = Selectable.Transition.None;
|
||||
Navigation customNav = new Navigation();
|
||||
customNav.mode = Navigation.Mode.Automatic;
|
||||
navButton.navigation = customNav;
|
||||
}
|
||||
|
||||
public void AnimateSwitch()
|
||||
{
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
switchAnimator.enabled = true;
|
||||
|
||||
if (isOn)
|
||||
{
|
||||
switchAnimator.Play("Off");
|
||||
isOn = false;
|
||||
offEvents.Invoke();
|
||||
|
||||
if (saveValue)
|
||||
{
|
||||
PlayerPrefs.SetString("Switch_" + saveKey, "false");
|
||||
}
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
switchAnimator.Play("On");
|
||||
isOn = true;
|
||||
onEvents.Invoke();
|
||||
|
||||
if (saveValue)
|
||||
{
|
||||
PlayerPrefs.SetString("Switch_" + saveKey, "true");
|
||||
}
|
||||
}
|
||||
|
||||
onValueChanged.Invoke(isOn);
|
||||
}
|
||||
|
||||
public void SetOn()
|
||||
{
|
||||
if (saveValue) { PlayerPrefs.SetString("Switch_" + saveKey, "true"); }
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
switchAnimator.enabled = true;
|
||||
switchAnimator.Play("On");
|
||||
|
||||
isOn = true;
|
||||
onEvents.Invoke();
|
||||
onValueChanged.Invoke(true);
|
||||
}
|
||||
|
||||
public void SetOff()
|
||||
{
|
||||
if (saveValue) { PlayerPrefs.SetString("Switch_" + saveKey, "false"); }
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
switchAnimator.enabled = true;
|
||||
switchAnimator.Play("Off");
|
||||
|
||||
isOn = false;
|
||||
offEvents.Invoke();
|
||||
onValueChanged.Invoke(false);
|
||||
}
|
||||
|
||||
public void UpdateUI()
|
||||
{
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
StopCoroutine("DisableAnimator");
|
||||
StartCoroutine("DisableAnimator");
|
||||
}
|
||||
|
||||
switchAnimator.enabled = true;
|
||||
|
||||
if (isOn && switchAnimator.gameObject.activeInHierarchy) { switchAnimator.Play("On Instant"); }
|
||||
else if (!isOn && switchAnimator.gameObject.activeInHierarchy) { switchAnimator.Play("Off Instant"); }
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable || eventData.button != PointerEventData.InputButton.Left) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
|
||||
AnimateSwitch();
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable) { return; }
|
||||
if (useSounds) { UIManagerAudio.instance.audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnPointerExit(PointerEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSelect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetHighlight");
|
||||
}
|
||||
|
||||
public void OnDeselect(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
public void OnSubmit(BaseEventData eventData)
|
||||
{
|
||||
if (!isInteractable)
|
||||
return;
|
||||
|
||||
AnimateSwitch();
|
||||
StartCoroutine("SetNormal");
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimator()
|
||||
{
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
switchAnimator.enabled = false;
|
||||
}
|
||||
|
||||
IEnumerator SetNormal()
|
||||
{
|
||||
StopCoroutine("SetHighlight");
|
||||
|
||||
while (highlightCG.alpha > 0.01f)
|
||||
{
|
||||
highlightCG.alpha -= Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 0;
|
||||
}
|
||||
|
||||
IEnumerator SetHighlight()
|
||||
{
|
||||
StopCoroutine("SetNormal");
|
||||
|
||||
while (highlightCG.alpha < 0.99f)
|
||||
{
|
||||
highlightCG.alpha += Time.unscaledDeltaTime * fadingMultiplier;
|
||||
yield return null;
|
||||
}
|
||||
|
||||
highlightCG.alpha = 1;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a46be675a56ee44cacb99784ca39bc4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 7d937b2018e5a5c4a9eadbdec9c43b20, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SwitchManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,119 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(SwitchManager))]
|
||||
public class SwitchManagerEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private SwitchManager switchTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
switchTarget = (SwitchManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Switch Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[3];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = new GUIContent("Resources");
|
||||
toolbarTabs[2] = new GUIContent("Settings");
|
||||
|
||||
currentTab = HeatUIEditorHandler.DrawTabs(currentTab, toolbarTabs, customSkin);
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Content", "Content"), customSkin.FindStyle("Tab Content")))
|
||||
currentTab = 0;
|
||||
if (GUILayout.Button(new GUIContent("Resources", "Resources"), customSkin.FindStyle("Tab Resources")))
|
||||
currentTab = 1;
|
||||
if (GUILayout.Button(new GUIContent("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 2;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var onValueChanged = serializedObject.FindProperty("onValueChanged");
|
||||
var onEvents = serializedObject.FindProperty("onEvents");
|
||||
var offEvents = serializedObject.FindProperty("offEvents");
|
||||
|
||||
var switchAnimator = serializedObject.FindProperty("switchAnimator");
|
||||
var highlightCG = serializedObject.FindProperty("highlightCG");
|
||||
var audioManager = serializedObject.FindProperty("audioManager");
|
||||
|
||||
var fadingMultiplier = serializedObject.FindProperty("fadingMultiplier");
|
||||
var isOn = serializedObject.FindProperty("isOn");
|
||||
var isInteractable = serializedObject.FindProperty("isInteractable");
|
||||
var invokeOnEnable = serializedObject.FindProperty("invokeOnEnable");
|
||||
var useSounds = serializedObject.FindProperty("useSounds");
|
||||
var useUINavigation = serializedObject.FindProperty("useUINavigation");
|
||||
var saveValue = serializedObject.FindProperty("saveValue");
|
||||
var saveKey = serializedObject.FindProperty("saveKey");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
isOn.boolValue = HeatUIEditorHandler.DrawToggle(isOn.boolValue, customSkin, "Is On");
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
saveValue.boolValue = HeatUIEditorHandler.DrawTogglePlain(saveValue.boolValue, customSkin, "Save Value");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (saveValue.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyPlainCW(saveKey, customSkin, "Save Key:", 70);
|
||||
EditorGUILayout.HelpBox("Each switch should has its own unique key.", MessageType.Info);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onValueChanged, new GUIContent("On Value Changed"), true);
|
||||
EditorGUILayout.PropertyField(onEvents, new GUIContent("On Events"), true);
|
||||
EditorGUILayout.PropertyField(offEvents, new GUIContent("Off Events"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(switchAnimator, customSkin, "Switch hAnimator");
|
||||
HeatUIEditorHandler.DrawProperty(highlightCG, customSkin, "Highlight CG");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
isOn.boolValue = HeatUIEditorHandler.DrawToggle(isOn.boolValue, customSkin, "Is On");
|
||||
isInteractable.boolValue = HeatUIEditorHandler.DrawToggle(isInteractable.boolValue, customSkin, "Is Interactable");
|
||||
invokeOnEnable.boolValue = HeatUIEditorHandler.DrawToggle(invokeOnEnable.boolValue, customSkin, "Invoke On Enable", "Process events on enable.");
|
||||
useSounds.boolValue = HeatUIEditorHandler.DrawToggle(useSounds.boolValue, customSkin, "Use Switch Sounds");
|
||||
useUINavigation.boolValue = HeatUIEditorHandler.DrawToggle(useUINavigation.boolValue, customSkin, "Use UI Navigation", "Enables controller navigation.");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-3);
|
||||
saveValue.boolValue = HeatUIEditorHandler.DrawTogglePlain(saveValue.boolValue, customSkin, "Save Value");
|
||||
GUILayout.Space(3);
|
||||
|
||||
if (saveValue.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawPropertyPlainCW(saveKey, customSkin, "Save Key:", 70);
|
||||
EditorGUILayout.HelpBox("Each switch should has its own unique key.", MessageType.Info);
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawProperty(fadingMultiplier, customSkin, "Fading Multiplier");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 494fe4812025c264993ac77bc3997c08
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/SwitchManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,47 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[DisallowMultipleComponent]
|
||||
[AddComponentMenu("Heat UI/Audio/UI Element Sound")]
|
||||
public class UIElementSound : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler
|
||||
{
|
||||
[Header("Resources")]
|
||||
public AudioSource audioSource;
|
||||
|
||||
[Header("Custom SFX")]
|
||||
public AudioClip hoverSFX;
|
||||
public AudioClip clickSFX;
|
||||
|
||||
[Header("Settings")]
|
||||
public bool enableHoverSound = true;
|
||||
public bool enableClickSound = true;
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (UIManagerAudio.instance != null && audioSource == null)
|
||||
{
|
||||
audioSource = UIManagerAudio.instance.audioSource;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerEnter(PointerEventData eventData)
|
||||
{
|
||||
if (enableHoverSound)
|
||||
{
|
||||
if (hoverSFX == null) { audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.hoverSound); }
|
||||
else { audioSource.PlayOneShot(hoverSFX); }
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPointerClick(PointerEventData eventData)
|
||||
{
|
||||
if (enableClickSound)
|
||||
{
|
||||
if (clickSFX == null) { audioSource.PlayOneShot(UIManagerAudio.instance.UIManagerAsset.clickSound); }
|
||||
else { audioSource.PlayOneShot(clickSFX); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f3ca6e756c5267439d2c7550d10aaea
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: a423f273d3e14b1428a9709cc6fece1a, type: 3}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 264857
|
||||
packageName: Heat - Complete Modern UI
|
||||
packageVersion: 1.0.4
|
||||
assetPath: Assets/Heat - Complete Modern UI/Scripts/UI Elements/UIElementSound.cs
|
||||
uploadId: 629893
|
Reference in New Issue
Block a user