Imported UI Assets

This commit is contained in:
MarcoHampel
2024-02-01 22:45:59 -05:00
parent 95a3f673f0
commit 5192d8b669
1355 changed files with 518302 additions and 153 deletions

View File

@ -0,0 +1,237 @@
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.DualShock;
using UnityEngine.InputSystem.XInput;
namespace Michsky.UI.Heat
{
[DefaultExecutionOrder(-100)]
[DisallowMultipleComponent]
public class ControllerManager : MonoBehaviour
{
// Static Instance
public static ControllerManager instance;
// Resources
public ControllerPresetManager presetManager;
public GameObject firstSelected;
public List<PanelManager> panels = new List<PanelManager>();
public List<ButtonManager> buttons = new List<ButtonManager>();
public List<BoxButtonManager> boxButtons = new List<BoxButtonManager>();
public List<ShopButtonManager> shopButtons = new List<ShopButtonManager>();
public List<SettingsElement> settingsElements = new List<SettingsElement>();
[Tooltip("Objects in this list will be enabled when the gamepad is un-plugged.")]
public List<GameObject> keyboardObjects = new List<GameObject>();
[Tooltip("Objects in this list will be enabled when the gamepad is plugged.")]
public List<GameObject> gamepadObjects = new List<GameObject>();
public List<HotkeyEvent> hotkeyObjects = new List<HotkeyEvent>();
// Settings
[Tooltip("Checks for input changes each frame.")]
public bool alwaysUpdate = true;
public bool affectCursor = true;
public InputAction gamepadHotkey;
// Helpers
Vector3 cursorPos;
Vector3 lastCursorPos;
Navigation customNav = new Navigation();
[HideInInspector] public int currentManagerIndex;
[HideInInspector] public bool gamepadConnected;
[HideInInspector] public bool gamepadEnabled;
[HideInInspector] public bool keyboardEnabled;
[HideInInspector] public float hAxis;
[HideInInspector] public float vAxis;
[HideInInspector] public string currentController;
[HideInInspector] public ControllerPreset currentControllerPreset;
void Awake()
{
instance = this;
}
void Start()
{
InitInput();
}
void Update()
{
if (!alwaysUpdate)
return;
CheckForController();
CheckForEmptyObject();
}
void InitInput()
{
gamepadHotkey.Enable();
if (Gamepad.current == null) { gamepadConnected = false; SwitchToKeyboard(); }
else { gamepadConnected = true; SwitchToGamepad(); }
}
void CheckForEmptyObject()
{
if (!gamepadEnabled) { return; }
else if (EventSystem.current.currentSelectedGameObject != null && EventSystem.current.currentSelectedGameObject.gameObject.activeInHierarchy) { return; }
if (gamepadHotkey.triggered && panels.Count != 0 && panels[currentManagerIndex].panels[panels[currentManagerIndex].currentPanelIndex].firstSelected != null)
{
SelectUIObject(panels[currentManagerIndex].panels[panels[currentManagerIndex].currentPanelIndex].firstSelected);
}
}
public void CheckForController()
{
if (Gamepad.current == null) { gamepadConnected = false; }
else
{
gamepadConnected = true;
hAxis = Gamepad.current.rightStick.x.ReadValue();
vAxis = Gamepad.current.rightStick.y.ReadValue();
}
cursorPos = Mouse.current.position.ReadValue();
if (gamepadConnected && gamepadEnabled && !keyboardEnabled && cursorPos != lastCursorPos) { SwitchToKeyboard(); }
else if (gamepadConnected && !gamepadEnabled && keyboardEnabled && gamepadHotkey.triggered) { SwitchToGamepad(); }
else if (!gamepadConnected && !keyboardEnabled) { SwitchToKeyboard(); }
}
void CheckForCurrentObject()
{
if ((EventSystem.current.currentSelectedGameObject == null || !EventSystem.current.currentSelectedGameObject.activeInHierarchy) && panels.Count != 0)
{
SelectUIObject(panels[currentManagerIndex].panels[panels[currentManagerIndex].currentPanelIndex].firstSelected);
}
}
public void SwitchToGamepad()
{
if (affectCursor) { Cursor.visible = false; }
for (int i = 0; i < keyboardObjects.Count; i++)
{
if (keyboardObjects[i] == null)
continue;
keyboardObjects[i].SetActive(false);
}
for (int i = 0; i < gamepadObjects.Count; i++)
{
if (gamepadObjects[i] == null)
continue;
gamepadObjects[i].SetActive(true);
LayoutRebuilder.ForceRebuildLayoutImmediate(gamepadObjects[i].GetComponentInParent<RectTransform>());
}
customNav.mode = Navigation.Mode.Automatic;
for (int i = 0; i < buttons.Count; i++) { if (buttons[i] != null && !buttons[i].useUINavigation) { buttons[i].AddUINavigation(); } }
for (int i = 0; i < boxButtons.Count; i++) { if (boxButtons[i] != null && !boxButtons[i].useUINavigation) { boxButtons[i].AddUINavigation(); } }
for (int i = 0; i < shopButtons.Count; i++) { if (shopButtons[i] != null && !shopButtons[i].useUINavigation) { shopButtons[i].AddUINavigation(); } }
for (int i = 0; i < settingsElements.Count; i++) { if (settingsElements[i] != null && !settingsElements[i].useUINavigation) { settingsElements[i].AddUINavigation(); } }
gamepadEnabled = true;
keyboardEnabled = false;
lastCursorPos = Mouse.current.position.ReadValue();
CheckForGamepadType();
CheckForCurrentObject();
}
void CheckForGamepadType()
{
currentController = Gamepad.current.displayName;
// Search for main and custom gameapds
if (Gamepad.current is XInputController && presetManager != null && presetManager.xboxPreset != null) { currentControllerPreset = presetManager.xboxPreset; }
#if !UNITY_WEBGL && !UNITY_IOS && !UNITY_ANDROID && !UNITY_STANDALONE_LINUX
else if (Gamepad.current is DualSenseGamepadHID && presetManager != null && presetManager.dualsensePreset != null) { currentControllerPreset = presetManager.dualsensePreset; }
#endif
else
{
for (int i = 0; i < presetManager.customPresets.Count; i++)
{
if (currentController == presetManager.customPresets[i].controllerName)
{
currentControllerPreset = presetManager.customPresets[i];
break;
}
}
}
foreach (HotkeyEvent he in hotkeyObjects)
{
if (he == null)
continue;
he.controllerPreset = currentControllerPreset;
he.UpdateUI();
}
}
public void SwitchToKeyboard()
{
if (affectCursor) { Cursor.visible = true; }
if (presetManager != null && presetManager.keyboardPreset != null)
{
currentControllerPreset = presetManager.keyboardPreset;
foreach (HotkeyEvent he in hotkeyObjects)
{
if (he == null)
continue;
he.controllerPreset = currentControllerPreset;
he.UpdateUI();
}
}
for (int i = 0; i < gamepadObjects.Count; i++)
{
if (gamepadObjects[i] == null)
continue;
gamepadObjects[i].SetActive(false);
}
for (int i = 0; i < keyboardObjects.Count; i++)
{
if (keyboardObjects[i] == null)
continue;
keyboardObjects[i].SetActive(true);
LayoutRebuilder.ForceRebuildLayoutImmediate(keyboardObjects[i].GetComponentInParent<RectTransform>());
}
customNav.mode = Navigation.Mode.None;
for (int i = 0; i < buttons.Count; i++) { if (buttons[i] != null && !buttons[i].useUINavigation) { buttons[i].DisableUINavigation(); } }
for (int i = 0; i < boxButtons.Count; i++) { if (boxButtons[i] != null && !boxButtons[i].useUINavigation) { boxButtons[i].DisableUINavigation(); } }
for (int i = 0; i < shopButtons.Count; i++) { if (shopButtons[i] != null && !shopButtons[i].useUINavigation) { shopButtons[i].DisableUINavigation(); } }
for (int i = 0; i < settingsElements.Count; i++) { if (settingsElements[i] != null && !settingsElements[i].useUINavigation) { settingsElements[i].DisableUINavigation(); } }
gamepadEnabled = false;
keyboardEnabled = true;
}
public void SelectUIObject(GameObject tempObj)
{
if (!gamepadEnabled)
return;
EventSystem.current.SetSelectedGameObject(tempObj.gameObject);
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 38730517d0a0b2f4f9935f5b526ee7d6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 70b6ed493cdde1b4a911df2d89e1694f, 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/Input/ControllerManager.cs
uploadId: 629893

View File

@ -0,0 +1,59 @@
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using UnityEngine.UIElements;
namespace Michsky.UI.Heat
{
[CanEditMultipleObjects]
[CustomEditor(typeof(ControllerManager))]
public class ControllerManagerEditor : Editor
{
private ControllerManager cmTarget;
private GUISkin customSkin;
private void OnEnable()
{
cmTarget = (ControllerManager)target;
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
}
public override void OnInspectorGUI()
{
var presetManager = serializedObject.FindProperty("presetManager");
var firstSelected = serializedObject.FindProperty("firstSelected");
var gamepadObjects = serializedObject.FindProperty("gamepadObjects");
var keyboardObjects = serializedObject.FindProperty("keyboardObjects");
var alwaysUpdate = serializedObject.FindProperty("alwaysUpdate");
var affectCursor = serializedObject.FindProperty("affectCursor");
var gamepadHotkey = serializedObject.FindProperty("gamepadHotkey");
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
HeatUIEditorHandler.DrawProperty(presetManager, customSkin, "Preset Manager");
HeatUIEditorHandler.DrawProperty(firstSelected, customSkin, "First Selected", "UI element to be selected first in the home panel (e.g. Play button).");
GUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(gamepadObjects, new GUIContent("Gamepad Objects"), true);
EditorGUI.indentLevel = 0;
GUILayout.EndVertical();
GUILayout.BeginVertical();
EditorGUI.indentLevel = 1;
EditorGUILayout.PropertyField(keyboardObjects, new GUIContent("Keyboard Objects"), true);
EditorGUI.indentLevel = 0;
GUILayout.EndVertical();
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 10);
alwaysUpdate.boolValue = HeatUIEditorHandler.DrawToggle(alwaysUpdate.boolValue, customSkin, "Always Update");
affectCursor.boolValue = HeatUIEditorHandler.DrawToggle(affectCursor.boolValue, customSkin, "Affect Cursor", "Changes the cursor state depending on the controller state.");
EditorGUILayout.PropertyField(gamepadHotkey, new GUIContent("Gamepad Hotkey", "Triggers to switch to gamepad when pressed."), true);
serializedObject.ApplyModifiedProperties();
}
}
}
#endif

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: bd49ec269b8d3fa44a95b6a6ca3a603b
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/Input/ControllerManagerEditor.cs
uploadId: 629893

View File

@ -0,0 +1,26 @@
using System.Collections.Generic;
using UnityEngine;
namespace Michsky.UI.Heat
{
[CreateAssetMenu(fileName = "New Controller Preset", menuName = "Heat UI/Controller/New Controller Preset")]
public class ControllerPreset : ScriptableObject
{
[Header("Settings")]
public string controllerName = "Controller Name";
[Space(10)]
public List<ControllerItem> items = new List<ControllerItem>();
public enum ItemType { Icon, Text }
[System.Serializable]
public class ControllerItem
{
public string itemID;
public ItemType itemType;
public Sprite itemIcon;
public string itemText;
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 42ee925c372713347a6a28631564a3f0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 70b6ed493cdde1b4a911df2d89e1694f, 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/Input/ControllerPreset.cs
uploadId: 629893

View File

@ -0,0 +1,14 @@
using System.Collections.Generic;
using UnityEngine;
namespace Michsky.UI.Heat
{
[CreateAssetMenu(fileName = "New Controller Preset Manager", menuName = "Heat UI/Controller/New Controller Preset Manager")]
public class ControllerPresetManager : ScriptableObject
{
public ControllerPreset keyboardPreset;
public ControllerPreset xboxPreset;
public ControllerPreset dualsensePreset;
public List<ControllerPreset> customPresets = new List<ControllerPreset>();
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d0363e7a7841d294a97aee9fd222febe
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: 70b6ed493cdde1b4a911df2d89e1694f, 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/Input/ControllerPresetManager.cs
uploadId: 629893

View File

@ -0,0 +1,65 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.InputSystem;
namespace Michsky.UI.Heat
{
[RequireComponent(typeof(Scrollbar))]
public class ScrollbarInputHandler : MonoBehaviour
{
[Header("Resources")]
[SerializeField] private Scrollbar scrollbarObject;
[SerializeField] private GameObject indicator;
[Header("Settings")]
[SerializeField] private ScrollbarDirection direction = ScrollbarDirection.Vertical;
[Range(0.1f, 50)] public float scrollSpeed = 3;
[SerializeField] [Range(0.01f, 1)] private float deadzone = 0.1f;
[SerializeField] private bool optimizeUpdates = true;
public bool allowInputs = true;
[SerializeField] private bool reversePosition;
// Helpers
float divideValue = 1000;
public enum ScrollbarDirection { Horizontal, Vertical }
void OnEnable()
{
if (scrollbarObject == null) { scrollbarObject = gameObject.GetComponent<Scrollbar>(); }
if (ControllerManager.instance == null) { Destroy(this); }
if (indicator == null)
{
indicator = new GameObject();
indicator.name = "[Generated Indicator]";
indicator.transform.SetParent(transform);
}
indicator.SetActive(false);
}
void Update()
{
if (Gamepad.current == null || ControllerManager.instance == null || !allowInputs) { indicator.SetActive(false); return; }
else if (optimizeUpdates && ControllerManager.instance != null && !ControllerManager.instance.gamepadEnabled) { indicator.SetActive(false); return; }
indicator.SetActive(true);
if (direction == ScrollbarDirection.Vertical)
{
if (reversePosition && ControllerManager.instance.vAxis >= 0.1f) { scrollbarObject.value -= (scrollSpeed / divideValue) * ControllerManager.instance.vAxis; }
else if (!reversePosition && ControllerManager.instance.vAxis >= 0.1f) { scrollbarObject.value += (scrollSpeed / divideValue) * ControllerManager.instance.vAxis; }
else if (reversePosition && ControllerManager.instance.vAxis <= -0.1f) { scrollbarObject.value += (scrollSpeed / divideValue) * Mathf.Abs(ControllerManager.instance.vAxis); }
else if (!reversePosition && ControllerManager.instance.vAxis <= -0.1f) { scrollbarObject.value -= (scrollSpeed / divideValue) * Mathf.Abs(ControllerManager.instance.vAxis); }
}
else if (direction == ScrollbarDirection.Horizontal)
{
if (reversePosition && ControllerManager.instance.hAxis >= deadzone) { scrollbarObject.value -= (scrollSpeed / divideValue) * ControllerManager.instance.hAxis; }
else if (!reversePosition && ControllerManager.instance.hAxis >= deadzone) { scrollbarObject.value += (scrollSpeed / divideValue) * ControllerManager.instance.hAxis; }
else if (reversePosition && ControllerManager.instance.hAxis <= -deadzone) { scrollbarObject.value += (scrollSpeed / divideValue) * Mathf.Abs(ControllerManager.instance.hAxis); }
else if (!reversePosition && ControllerManager.instance.hAxis <= -deadzone) { scrollbarObject.value -= (scrollSpeed / divideValue) * Mathf.Abs(ControllerManager.instance.hAxis); }
}
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: 73a37c87ce93433428156c9813812c30
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: f4007fbdb43231c4c8a13871706d7c46, 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/Input/ScrollbarInputHandler.cs
uploadId: 629893

View File

@ -0,0 +1,69 @@
using System.Collections;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace Michsky.UI.Heat
{
public class SelectorInputHandler : MonoBehaviour
{
[Header("Resources")]
[SerializeField] private HorizontalSelector selectorObject;
[SerializeField] private GameObject indicator;
[Header("Settings")]
public float selectorCooldown = 0.4f;
[SerializeField] private bool optimizeUpdates = true;
public bool requireSelecting = true;
// Helpers
bool isInCooldown = false;
void OnEnable()
{
if (ControllerManager.instance == null || selectorObject == null) { Destroy(this); }
if (indicator == null)
{
indicator = new GameObject();
indicator.name = "[Generated Indicator]";
indicator.transform.SetParent(transform);
}
indicator.SetActive(false);
}
void Update()
{
if (Gamepad.current == null || ControllerManager.instance == null) { indicator.SetActive(false); return; }
else if (requireSelecting && EventSystem.current.currentSelectedGameObject != gameObject) { indicator.SetActive(false); return; }
else if (optimizeUpdates && ControllerManager.instance != null && !ControllerManager.instance.gamepadEnabled) { indicator.SetActive(false); return; }
else if (isInCooldown) { return; }
indicator.SetActive(true);
if (ControllerManager.instance.hAxis >= 0.75)
{
selectorObject.NextItem();
isInCooldown = true;
StopCoroutine("CooldownTimer");
StartCoroutine("CooldownTimer");
}
else if (ControllerManager.instance.hAxis <= -0.75)
{
selectorObject.PreviousItem();
isInCooldown = true;
StopCoroutine("CooldownTimer");
StartCoroutine("CooldownTimer");
}
}
IEnumerator CooldownTimer()
{
yield return new WaitForSecondsRealtime(selectorCooldown);
isInCooldown = false;
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: d4b1a0f691a9bf843b60feec050fd352
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: f4007fbdb43231c4c8a13871706d7c46, 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/Input/SelectorInputHandler.cs
uploadId: 629893

View File

@ -0,0 +1,57 @@
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.EventSystems;
using UnityEngine.InputSystem;
namespace Michsky.UI.Heat
{
public class SliderInputHandler : MonoBehaviour
{
[Header("Resources")]
[SerializeField] private Slider sliderObject;
[SerializeField] private GameObject indicator;
[Header("Settings")]
[Range(0.1f, 50)] public float valueMultiplier = 1;
[SerializeField] [Range(0.01f, 1)] private float deadzone = 0.1f;
[SerializeField] private bool optimizeUpdates = true;
public bool requireSelecting = true;
[SerializeField] private bool reversePosition;
[SerializeField] private bool divideByMaxValue;
// Helpers
float divideValue = 1000;
void OnEnable()
{
if (ControllerManager.instance == null || sliderObject == null) { Destroy(this); }
if (indicator == null)
{
indicator = new GameObject();
indicator.name = "[Generated Indicator]";
indicator.transform.SetParent(transform);
}
indicator.SetActive(false);
if (divideByMaxValue)
{
divideValue = sliderObject.maxValue;
}
}
void Update()
{
if (Gamepad.current == null || ControllerManager.instance == null) { indicator.SetActive(false); return; }
else if (requireSelecting && EventSystem.current.currentSelectedGameObject != gameObject) { indicator.SetActive(false); return; }
else if (optimizeUpdates && ControllerManager.instance != null && !ControllerManager.instance.gamepadEnabled) { indicator.SetActive(false); return; }
indicator.SetActive(true);
if (reversePosition && ControllerManager.instance.hAxis >= deadzone) { sliderObject.value -= (valueMultiplier / divideValue) * ControllerManager.instance.hAxis; }
else if (!reversePosition && ControllerManager.instance.hAxis >= deadzone) { sliderObject.value += (valueMultiplier / divideValue) * ControllerManager.instance.hAxis; }
else if (reversePosition && ControllerManager.instance.hAxis <= -deadzone) { sliderObject.value += (valueMultiplier / divideValue) * Mathf.Abs(ControllerManager.instance.hAxis); }
else if (!reversePosition && ControllerManager.instance.hAxis <= -deadzone) { sliderObject.value -= (valueMultiplier / divideValue) * Mathf.Abs(ControllerManager.instance.hAxis); }
}
}
}

View File

@ -0,0 +1,18 @@
fileFormatVersion: 2
guid: eb371ec4e1984f640867ff04efd1612e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {fileID: 2800000, guid: f4007fbdb43231c4c8a13871706d7c46, 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/Input/SliderInputHandler.cs
uploadId: 629893