Imported UI Assets
This commit is contained in:
@ -0,0 +1,93 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class ChapterIdentifier : MonoBehaviour
|
||||
{
|
||||
[Header("Resources")]
|
||||
public Animator animator;
|
||||
[SerializeField] private RectTransform backgroundRect;
|
||||
public Image backgroundImage;
|
||||
public TextMeshProUGUI titleObject;
|
||||
public TextMeshProUGUI descriptionObject;
|
||||
public ButtonManager continueButton;
|
||||
public ButtonManager playButton;
|
||||
public ButtonManager replayButton;
|
||||
public GameObject completedIndicator;
|
||||
public GameObject unlockedIndicator;
|
||||
public GameObject lockedIndicator;
|
||||
|
||||
[HideInInspector] public ChapterManager chapterManager;
|
||||
[HideInInspector] public bool isLocked;
|
||||
[HideInInspector] public bool isCurrent;
|
||||
|
||||
public void UpdateBackgroundRect()
|
||||
{
|
||||
chapterManager.currentBackgroundRect = backgroundRect;
|
||||
chapterManager.DoStretch();
|
||||
}
|
||||
|
||||
public void SetCurrent()
|
||||
{
|
||||
completedIndicator.SetActive(false);
|
||||
unlockedIndicator.SetActive(true);
|
||||
lockedIndicator.SetActive(false);
|
||||
|
||||
continueButton.gameObject.SetActive(true);
|
||||
playButton.gameObject.SetActive(false);
|
||||
replayButton.gameObject.SetActive(true);
|
||||
|
||||
isLocked = false;
|
||||
isCurrent = true;
|
||||
continueButton.isInteractable = true;
|
||||
replayButton.isInteractable = true;
|
||||
}
|
||||
|
||||
public void SetLocked()
|
||||
{
|
||||
completedIndicator.SetActive(false);
|
||||
unlockedIndicator.SetActive(false);
|
||||
lockedIndicator.SetActive(true);
|
||||
|
||||
continueButton.gameObject.SetActive(false);
|
||||
playButton.gameObject.SetActive(true);
|
||||
replayButton.gameObject.SetActive(false);
|
||||
|
||||
isLocked = true;
|
||||
isCurrent = false;
|
||||
playButton.isInteractable = false;
|
||||
}
|
||||
|
||||
public void SetUnlocked()
|
||||
{
|
||||
completedIndicator.SetActive(false);
|
||||
unlockedIndicator.SetActive(true);
|
||||
lockedIndicator.SetActive(false);
|
||||
|
||||
continueButton.gameObject.SetActive(false);
|
||||
playButton.gameObject.SetActive(true);
|
||||
replayButton.gameObject.SetActive(false);
|
||||
|
||||
isLocked = false;
|
||||
isCurrent = false;
|
||||
playButton.isInteractable = true;
|
||||
}
|
||||
|
||||
public void SetCompleted()
|
||||
{
|
||||
completedIndicator.SetActive(true);
|
||||
unlockedIndicator.SetActive(false);
|
||||
lockedIndicator.SetActive(false);
|
||||
|
||||
continueButton.gameObject.SetActive(false);
|
||||
playButton.gameObject.SetActive(false);
|
||||
replayButton.gameObject.SetActive(true);
|
||||
|
||||
isLocked = false;
|
||||
isCurrent = false;
|
||||
replayButton.isInteractable = true;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96e0979008e54b64195684dc9ae6537f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 0a73f4df264086048a61a56eb1250804, 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/Panels/ChapterIdentifier.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,362 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class ChapterManager : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public List<ChapterItem> chapters = new List<ChapterItem>();
|
||||
private List<ChapterIdentifier> identifiers = new List<ChapterIdentifier>();
|
||||
public int currentChapterIndex;
|
||||
|
||||
// Resources
|
||||
[SerializeField] private GameObject chapterPreset;
|
||||
[SerializeField] private Transform chapterParent;
|
||||
[SerializeField] private ButtonManager previousButton;
|
||||
[SerializeField] private ButtonManager nextButton;
|
||||
[SerializeField] private Image progressFill;
|
||||
|
||||
// Settings
|
||||
[SerializeField] private bool showLockedChapters = true;
|
||||
[SerializeField] private bool setPanelAuto = true;
|
||||
[SerializeField] private bool checkChapterData = true;
|
||||
[SerializeField] private bool useLocalization = true;
|
||||
[SerializeField] [Range(0.5f, 10)] private float barCurveSpeed = 2f;
|
||||
[SerializeField] private AnimationCurve barCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f));
|
||||
[SerializeField] [Range(0.75f, 2)] private float animationSpeed = 1;
|
||||
|
||||
// Background Animation
|
||||
[SerializeField] private bool backgroundStretch = true;
|
||||
[SerializeField] [Range(0, 100)] private float maxStretch = 75;
|
||||
[SerializeField] [Range(0.02f, 0.5f)] private float stretchCurveSpeed = 0.1f;
|
||||
[SerializeField] private AnimationCurve stretchCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f));
|
||||
|
||||
// Events
|
||||
[System.Serializable] public class ChapterChangeCallback : UnityEvent<int> { }
|
||||
public ChapterChangeCallback onChapterPanelChanged = new ChapterChangeCallback();
|
||||
|
||||
// Helpers
|
||||
[HideInInspector] public RectTransform currentBackgroundRect;
|
||||
LocalizedObject localizedObject;
|
||||
string animSpeedKey = "AnimSpeed";
|
||||
|
||||
public enum ChapterState { Locked, Unlocked, Completed, Current }
|
||||
|
||||
[System.Serializable]
|
||||
public class ChapterItem
|
||||
{
|
||||
public string chapterID;
|
||||
public string title;
|
||||
public Sprite background;
|
||||
[TextArea] public string description;
|
||||
public ChapterState defaultState;
|
||||
|
||||
[Header("Localization")]
|
||||
public string titleKey = "TitleKey";
|
||||
public string descriptionKey = "DescriptionKey";
|
||||
|
||||
[Header("Events")]
|
||||
public UnityEvent onContinue;
|
||||
public UnityEvent onPlay;
|
||||
public UnityEvent onReplay;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
InitializeChapters();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
OpenCurrentPanel();
|
||||
}
|
||||
|
||||
void OnDisable()
|
||||
{
|
||||
if (backgroundStretch == false)
|
||||
return;
|
||||
|
||||
StopCoroutine("StretchPhaseOne");
|
||||
StopCoroutine("StretchPhaseTwo");
|
||||
}
|
||||
|
||||
public void DoStretch()
|
||||
{
|
||||
if (backgroundStretch == false || currentBackgroundRect == null || gameObject.activeInHierarchy == false)
|
||||
return;
|
||||
|
||||
float calcSize = 1 + (maxStretch / 960);
|
||||
currentBackgroundRect.localScale = new Vector3(calcSize, calcSize, calcSize);
|
||||
currentBackgroundRect.offsetMin = new Vector2(0, 0);
|
||||
currentBackgroundRect.offsetMax = new Vector2(0, 0);
|
||||
|
||||
StopCoroutine("StretchPhaseOne");
|
||||
StopCoroutine("StretchPhaseTwo");
|
||||
StartCoroutine("StretchPhaseOne");
|
||||
}
|
||||
|
||||
public void InitializeChapters()
|
||||
{
|
||||
if (useLocalization == true)
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
if (localizedObject == null || localizedObject.CheckLocalizationStatus() == false) { useLocalization = false; }
|
||||
}
|
||||
|
||||
identifiers.Clear();
|
||||
|
||||
foreach (Transform child in chapterParent) { Destroy(child.gameObject); }
|
||||
for (int i = 0; i < chapters.Count; ++i)
|
||||
{
|
||||
int tempIndex = i;
|
||||
|
||||
GameObject itemGO = Instantiate(chapterPreset, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
itemGO.transform.SetParent(chapterParent, false);
|
||||
itemGO.gameObject.name = chapters[i].chapterID;
|
||||
|
||||
ChapterIdentifier item = itemGO.GetComponent<ChapterIdentifier>();
|
||||
item.chapterManager = this;
|
||||
identifiers.Add(item);
|
||||
|
||||
// Background
|
||||
item.backgroundImage.sprite = chapters[i].background;
|
||||
item.UpdateBackgroundRect();
|
||||
|
||||
// Title
|
||||
if (useLocalization == false || string.IsNullOrEmpty(chapters[i].titleKey)) { item.titleObject.text = chapters[i].title; }
|
||||
else
|
||||
{
|
||||
LocalizedObject tempLoc = item.titleObject.GetComponent<LocalizedObject>();
|
||||
if (tempLoc != null)
|
||||
{
|
||||
tempLoc.tableIndex = localizedObject.tableIndex;
|
||||
tempLoc.localizationKey = chapters[i].titleKey;
|
||||
tempLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
// Description
|
||||
if (useLocalization == false || string.IsNullOrEmpty(chapters[i].descriptionKey)) { item.descriptionObject.text = chapters[i].description; }
|
||||
else
|
||||
{
|
||||
LocalizedObject tempLoc = item.descriptionObject.GetComponent<LocalizedObject>();
|
||||
if (tempLoc != null)
|
||||
{
|
||||
tempLoc.tableIndex = localizedObject.tableIndex;
|
||||
tempLoc.localizationKey = chapters[i].descriptionKey;
|
||||
tempLoc.UpdateItem();
|
||||
}
|
||||
}
|
||||
|
||||
// Set events
|
||||
item.continueButton.onClick.RemoveAllListeners();
|
||||
item.continueButton.onClick.AddListener(chapters[tempIndex].onContinue.Invoke);
|
||||
|
||||
item.playButton.onClick.RemoveAllListeners();
|
||||
item.playButton.onClick.AddListener(chapters[tempIndex].onPlay.Invoke);
|
||||
|
||||
item.replayButton.onClick.RemoveAllListeners();
|
||||
item.replayButton.onClick.AddListener(chapters[tempIndex].onReplay.Invoke);
|
||||
|
||||
// Check for chapter data
|
||||
if (checkChapterData == true)
|
||||
{
|
||||
if (!PlayerPrefs.HasKey("ChapterState_" + chapters[i].chapterID))
|
||||
{
|
||||
if (chapters[i].defaultState == ChapterState.Unlocked) { item.SetUnlocked(); }
|
||||
else if (chapters[i].defaultState == ChapterState.Locked) { item.SetLocked(); }
|
||||
else if (chapters[i].defaultState == ChapterState.Completed) { item.SetCompleted(); }
|
||||
else { item.SetCurrent(); }
|
||||
}
|
||||
else if (PlayerPrefs.HasKey("ChapterState_" + chapters[i].chapterID) && PlayerPrefs.GetString("ChapterState_" + chapters[i].chapterID) == "unlocked") { item.SetUnlocked(); }
|
||||
else if (PlayerPrefs.HasKey("ChapterState_" + chapters[i].chapterID) && PlayerPrefs.GetString("ChapterState_" + chapters[i].chapterID) == "current") { item.SetCurrent(); }
|
||||
else if (PlayerPrefs.HasKey("ChapterState_" + chapters[i].chapterID) && PlayerPrefs.GetString("ChapterState_" + chapters[i].chapterID) == "completed") { item.SetCompleted(); }
|
||||
else { item.SetLocked(); }
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
if (chapters[i].defaultState == ChapterState.Unlocked) { item.SetUnlocked(); }
|
||||
else if (chapters[i].defaultState == ChapterState.Locked) { item.SetLocked(); }
|
||||
else if (chapters[i].defaultState == ChapterState.Completed) { item.SetCompleted(); }
|
||||
else { item.SetCurrent(); }
|
||||
}
|
||||
|
||||
// Set visibility
|
||||
itemGO.SetActive(false);
|
||||
if (setPanelAuto == true && item.isCurrent == true) { currentChapterIndex = i; }
|
||||
}
|
||||
|
||||
// Set the current go active
|
||||
identifiers[currentChapterIndex].gameObject.SetActive(true);
|
||||
|
||||
// Set button events
|
||||
previousButton.onClick.RemoveAllListeners();
|
||||
previousButton.onClick.AddListener(PrevChapter);
|
||||
|
||||
nextButton.onClick.RemoveAllListeners();
|
||||
nextButton.onClick.AddListener(NextChapter);
|
||||
|
||||
UpdateButtonState();
|
||||
|
||||
if (progressFill != null)
|
||||
progressFill.fillAmount = 1f / chapters.Count * (currentChapterIndex + 1);
|
||||
}
|
||||
|
||||
public void NextChapter()
|
||||
{
|
||||
if (currentChapterIndex + 1 > identifiers.Count - 1 || showLockedChapters == false && identifiers[currentChapterIndex + 1].isLocked == true)
|
||||
return;
|
||||
|
||||
identifiers[currentChapterIndex].animator.enabled = true;
|
||||
identifiers[currentChapterIndex].animator.SetFloat(animSpeedKey, animationSpeed);
|
||||
identifiers[currentChapterIndex].animator.Play("Next Out");
|
||||
|
||||
currentChapterIndex++;
|
||||
|
||||
identifiers[currentChapterIndex].gameObject.SetActive(true);
|
||||
identifiers[currentChapterIndex].animator.enabled = true;
|
||||
identifiers[currentChapterIndex].animator.SetFloat(animSpeedKey, animationSpeed);
|
||||
identifiers[currentChapterIndex].animator.Play("Next In");
|
||||
identifiers[currentChapterIndex].UpdateBackgroundRect();
|
||||
|
||||
UpdateButtonState();
|
||||
|
||||
StopCoroutine("DisablePanels");
|
||||
StartCoroutine("DisablePanels");
|
||||
}
|
||||
|
||||
public void PrevChapter()
|
||||
{
|
||||
if (currentChapterIndex <= 0 || showLockedChapters == false && identifiers[currentChapterIndex - 1].isLocked == true)
|
||||
return;
|
||||
|
||||
identifiers[currentChapterIndex].animator.enabled = true;
|
||||
identifiers[currentChapterIndex].animator.SetFloat(animSpeedKey, animationSpeed);
|
||||
identifiers[currentChapterIndex].animator.Play("Prev Out");
|
||||
|
||||
currentChapterIndex--;
|
||||
|
||||
identifiers[currentChapterIndex].gameObject.SetActive(true);
|
||||
identifiers[currentChapterIndex].animator.enabled = true;
|
||||
identifiers[currentChapterIndex].animator.SetFloat(animSpeedKey, animationSpeed);
|
||||
identifiers[currentChapterIndex].animator.Play("Prev In");
|
||||
identifiers[currentChapterIndex].UpdateBackgroundRect();
|
||||
|
||||
UpdateButtonState();
|
||||
|
||||
StopCoroutine("DisablePanels");
|
||||
StartCoroutine("DisablePanels");
|
||||
}
|
||||
|
||||
void OpenCurrentPanel()
|
||||
{
|
||||
if (identifiers[currentChapterIndex] == null)
|
||||
return;
|
||||
|
||||
identifiers[currentChapterIndex].gameObject.SetActive(true);
|
||||
identifiers[currentChapterIndex].animator.enabled = true;
|
||||
identifiers[currentChapterIndex].animator.SetFloat(animSpeedKey, animationSpeed);
|
||||
identifiers[currentChapterIndex].animator.Play("Start");
|
||||
identifiers[currentChapterIndex].UpdateBackgroundRect();
|
||||
}
|
||||
|
||||
void UpdateButtonState()
|
||||
{
|
||||
if (currentChapterIndex >= identifiers.Count - 1 && nextButton != null) { nextButton.isInteractable = false; nextButton.UpdateUI(); }
|
||||
else if (nextButton != null) { nextButton.isInteractable = true; nextButton.UpdateUI(); }
|
||||
|
||||
if (currentChapterIndex < 1 && previousButton != null) { previousButton.isInteractable = false; previousButton.UpdateUI(); }
|
||||
else if (previousButton != null) { previousButton.isInteractable = true; previousButton.UpdateUI(); }
|
||||
|
||||
if (showLockedChapters == false && currentChapterIndex <= identifiers.Count - 1 && identifiers[currentChapterIndex + 1].isLocked == true)
|
||||
{
|
||||
nextButton.isInteractable = false;
|
||||
nextButton.UpdateUI();
|
||||
}
|
||||
|
||||
if (progressFill != null && gameObject.activeInHierarchy == true)
|
||||
{
|
||||
StopCoroutine("PlayProgressFill");
|
||||
StartCoroutine("PlayProgressFill");
|
||||
}
|
||||
|
||||
onChapterPanelChanged.Invoke(currentChapterIndex);
|
||||
}
|
||||
|
||||
public static void SetLocked(string chapterID) { PlayerPrefs.SetString("ChapterState_" + chapterID, "locked"); }
|
||||
public static void SetUnlocked(string chapterID) { PlayerPrefs.SetString("ChapterState_" + chapterID, "unlocked"); }
|
||||
public static void SetCurrent(string chapterID) { PlayerPrefs.SetString("ChapterState_" + chapterID, "current"); }
|
||||
public static void SetCompleted(string chapterID) { PlayerPrefs.SetString("ChapterState_" + chapterID, "completed"); }
|
||||
|
||||
IEnumerator StretchPhaseOne()
|
||||
{
|
||||
float elapsedTime = 0;
|
||||
Vector2 startPos = currentBackgroundRect.offsetMin;
|
||||
Vector2 endPos = new Vector2(-maxStretch, 0);
|
||||
|
||||
while (currentBackgroundRect.offsetMin.x > -maxStretch + 0.1f)
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
currentBackgroundRect.offsetMin = Vector2.Lerp(startPos, endPos, stretchCurve.Evaluate(elapsedTime * stretchCurveSpeed));
|
||||
currentBackgroundRect.offsetMax = Vector2.Lerp(startPos, endPos, stretchCurve.Evaluate(elapsedTime * stretchCurveSpeed));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
StartCoroutine("StretchPhaseTwo");
|
||||
}
|
||||
|
||||
IEnumerator StretchPhaseTwo()
|
||||
{
|
||||
float elapsedTime = 0;
|
||||
Vector2 startPos = currentBackgroundRect.offsetMin;
|
||||
Vector2 endPos = new Vector2(maxStretch, 0);
|
||||
|
||||
while (currentBackgroundRect.offsetMin.x < maxStretch - 0.1f)
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
currentBackgroundRect.offsetMin = Vector2.Lerp(startPos, endPos, stretchCurve.Evaluate(elapsedTime * stretchCurveSpeed));
|
||||
currentBackgroundRect.offsetMax = Vector2.Lerp(startPos, endPos, stretchCurve.Evaluate(elapsedTime * stretchCurveSpeed));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
StartCoroutine("StretchPhaseOne");
|
||||
}
|
||||
|
||||
IEnumerator DisablePanels()
|
||||
{
|
||||
yield return new WaitForSecondsRealtime(0.5f);
|
||||
|
||||
for (int i = 0; i < identifiers.Count; i++)
|
||||
{
|
||||
identifiers[i].animator.enabled = false;
|
||||
|
||||
if (i == currentChapterIndex)
|
||||
continue;
|
||||
|
||||
identifiers[i].gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator PlayProgressFill()
|
||||
{
|
||||
float startingPoint = progressFill.fillAmount;
|
||||
float dividedFill = 1f / chapters.Count;
|
||||
float toBeFilled = dividedFill * (currentChapterIndex + 1);
|
||||
float elapsedTime = 0;
|
||||
|
||||
while (progressFill.fillAmount.ToString("F2") != toBeFilled.ToString("F2"))
|
||||
{
|
||||
elapsedTime += Time.unscaledDeltaTime;
|
||||
progressFill.fillAmount = Mathf.Lerp(startingPoint, toBeFilled, barCurve.Evaluate(elapsedTime * barCurveSpeed));
|
||||
yield return null;
|
||||
}
|
||||
|
||||
progressFill.fillAmount = toBeFilled;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,25 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 490231dd090d15643ace2e0719884f7e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences:
|
||||
- chapterPreset: {fileID: 6494165352434410304, guid: 55e125313b5307545b68991fd6372f4d,
|
||||
type: 3}
|
||||
- chapterParent: {instanceID: 0}
|
||||
- previousButton: {instanceID: 0}
|
||||
- nextButton: {instanceID: 0}
|
||||
- currentBackground: {instanceID: 0}
|
||||
- currentBackgroundRect: {instanceID: 0}
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: 0a73f4df264086048a61a56eb1250804, 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/Panels/ChapterManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,149 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(ChapterManager))]
|
||||
public class ChapterManagerEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private ChapterManager cmTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
cmTarget = (ChapterManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Chapters 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 chapters = serializedObject.FindProperty("chapters");
|
||||
var currentChapterIndex = serializedObject.FindProperty("currentChapterIndex");
|
||||
var onChapterPanelChanged = serializedObject.FindProperty("onChapterPanelChanged");
|
||||
|
||||
var chapterPreset = serializedObject.FindProperty("chapterPreset");
|
||||
var chapterParent = serializedObject.FindProperty("chapterParent");
|
||||
var previousButton = serializedObject.FindProperty("previousButton");
|
||||
var nextButton = serializedObject.FindProperty("nextButton");
|
||||
var progressFill = serializedObject.FindProperty("progressFill");
|
||||
|
||||
var showLockedChapters = serializedObject.FindProperty("showLockedChapters");
|
||||
var setPanelAuto = serializedObject.FindProperty("setPanelAuto");
|
||||
var checkChapterData = serializedObject.FindProperty("checkChapterData");
|
||||
var useLocalization = serializedObject.FindProperty("useLocalization");
|
||||
var backgroundStretch = serializedObject.FindProperty("backgroundStretch");
|
||||
var stretchCurveSpeed = serializedObject.FindProperty("stretchCurveSpeed");
|
||||
var stretchCurve = serializedObject.FindProperty("stretchCurve");
|
||||
var maxStretch = serializedObject.FindProperty("maxStretch");
|
||||
var barCurveSpeed = serializedObject.FindProperty("barCurveSpeed");
|
||||
var barCurve = serializedObject.FindProperty("barCurve");
|
||||
var animationSpeed = serializedObject.FindProperty("animationSpeed");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (cmTarget.chapters.Count != 0)
|
||||
{
|
||||
if (Application.isPlaying == true) { GUI.enabled = false; }
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Chapter:"), customSkin.FindStyle("Text"), GUILayout.Width(94));
|
||||
GUI.enabled = true;
|
||||
|
||||
if (setPanelAuto.boolValue == true) { GUI.enabled = false; }
|
||||
EditorGUILayout.LabelField(new GUIContent(cmTarget.chapters[currentChapterIndex.intValue].chapterID), customSkin.FindStyle("Text"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
currentChapterIndex.intValue = EditorGUILayout.IntSlider(currentChapterIndex.intValue, 0, cmTarget.chapters.Count - 1);
|
||||
|
||||
GUI.enabled = true;
|
||||
if (setPanelAuto.boolValue == true) { EditorGUILayout.HelpBox("'Set Panel Automatically' is enabled. Current chapter will be set automatically based on default chapter states.", MessageType.Info); }
|
||||
GUILayout.EndVertical();
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("Chapter list is empty. Create a new item to see more options.", MessageType.Info); }
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
EditorGUI.indentLevel = 1;
|
||||
EditorGUILayout.PropertyField(chapters, new GUIContent("Chapters"), true);
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onChapterPanelChanged, new GUIContent("On Chapter Panel Changed"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Core Header", 6);
|
||||
HeatUIEditorHandler.DrawProperty(chapterPreset, customSkin, "Chapter Preset");
|
||||
HeatUIEditorHandler.DrawProperty(chapterParent, customSkin, "Chapter Parent");
|
||||
HeatUIEditorHandler.DrawProperty(previousButton, customSkin, "Previous Button");
|
||||
HeatUIEditorHandler.DrawProperty(nextButton, customSkin, "Next Button");
|
||||
HeatUIEditorHandler.DrawProperty(progressFill, customSkin, "Progress Fill");
|
||||
break;
|
||||
|
||||
case 2:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
showLockedChapters.boolValue = HeatUIEditorHandler.DrawToggle(showLockedChapters.boolValue, customSkin, "Show Locked Chapters");
|
||||
setPanelAuto.boolValue = HeatUIEditorHandler.DrawToggle(setPanelAuto.boolValue, customSkin, "Set Panel Automatically");
|
||||
checkChapterData.boolValue = HeatUIEditorHandler.DrawToggle(checkChapterData.boolValue, customSkin, "Check For Chapter Data");
|
||||
useLocalization.boolValue = HeatUIEditorHandler.DrawToggle(useLocalization.boolValue, customSkin, "Use Localization");
|
||||
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.Space(-2);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
backgroundStretch.boolValue = GUILayout.Toggle(backgroundStretch.boolValue, new GUIContent("Background Stretch"), customSkin.FindStyle("Toggle"));
|
||||
backgroundStretch.boolValue = GUILayout.Toggle(backgroundStretch.boolValue, new GUIContent(""), customSkin.FindStyle("Toggle Helper"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(4);
|
||||
|
||||
if (backgroundStretch.boolValue == true)
|
||||
{
|
||||
HeatUIEditorHandler.DrawProperty(maxStretch, customSkin, "Max Stretch");
|
||||
HeatUIEditorHandler.DrawProperty(stretchCurveSpeed, customSkin, "Curve Speed");
|
||||
HeatUIEditorHandler.DrawProperty(stretchCurve, customSkin, "Stretch Curve");
|
||||
}
|
||||
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawProperty(barCurveSpeed, customSkin, "Bar Curve Speed");
|
||||
HeatUIEditorHandler.DrawProperty(barCurve, customSkin, "Bar Curve");
|
||||
HeatUIEditorHandler.DrawProperty(animationSpeed, customSkin, "Panel Speed");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a733cb8f832d2540bac88c131fa5032
|
||||
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/Panels/ChapterManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,413 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class PanelManager : MonoBehaviour
|
||||
{
|
||||
// Content
|
||||
public List<PanelItem> panels = new List<PanelItem>();
|
||||
|
||||
// Settings
|
||||
public int currentPanelIndex = 0;
|
||||
private int currentButtonIndex = 0;
|
||||
private int newPanelIndex;
|
||||
public bool cullPanels = true;
|
||||
[SerializeField] private bool initializeButtons = true;
|
||||
[SerializeField] private bool bypassAnimationOnEnable = false;
|
||||
[SerializeField] private UpdateMode updateMode = UpdateMode.UnscaledTime;
|
||||
[SerializeField] private PanelMode panelMode = PanelMode.Custom;
|
||||
[Range(0.75f, 2)] public float animationSpeed = 1;
|
||||
|
||||
// Events
|
||||
[System.Serializable] public class PanelChangeCallback : UnityEvent<int> { }
|
||||
public PanelChangeCallback onPanelChanged = new PanelChangeCallback();
|
||||
|
||||
// Helpers
|
||||
Animator currentPanel;
|
||||
Animator nextPanel;
|
||||
|
||||
PanelButton currentButton;
|
||||
PanelButton nextButton;
|
||||
|
||||
string panelFadeIn = "Panel In";
|
||||
string panelFadeOut = "Panel Out";
|
||||
string animSpeedKey = "AnimSpeed";
|
||||
|
||||
bool isInitialized = false;
|
||||
public float cachedStateLength = 1;
|
||||
[HideInInspector] public int managerIndex;
|
||||
|
||||
public enum PanelMode { MainPanel, SubPanel, Custom }
|
||||
public enum UpdateMode { DeltaTime, UnscaledTime }
|
||||
|
||||
[System.Serializable]
|
||||
public class PanelItem
|
||||
{
|
||||
[Tooltip("[Required] This is the variable that you use to call specific panels.")]
|
||||
public string panelName = "My Panel";
|
||||
[Tooltip("[Required] Main panel object.")]
|
||||
public Animator panelObject;
|
||||
[Tooltip("[Optional] If you want the panel manager to have tabbing capability, you can assign a panel button here.")]
|
||||
public PanelButton panelButton;
|
||||
[Tooltip("[Optional] Alternate panel button variable that supports standard buttons instead of panel buttons.")]
|
||||
public ButtonManager altPanelButton;
|
||||
[Tooltip("[Optional] Alternate panel button variable that supports box buttons instead of panel buttons.")]
|
||||
public BoxButtonManager altBoxButton;
|
||||
[Tooltip("[Optional] This is the object that will be selected as the current UI object on panel activation. Useful for gamepad navigation.")]
|
||||
public GameObject firstSelected;
|
||||
[Tooltip("[Optional] Enables or disables child hotkeys depending on the panel state to avoid conflict between hotkeys.")]
|
||||
public Transform hotkeyParent;
|
||||
[Tooltip("Enable or disable panel navigation when using the 'Previous' or 'Next' methods.")]
|
||||
public bool disableNavigation = false;
|
||||
[HideInInspector] public GameObject latestSelected;
|
||||
[HideInInspector] public HotkeyEvent[] hotkeys;
|
||||
}
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (panels.Count == 0)
|
||||
return;
|
||||
|
||||
if (panelMode == PanelMode.MainPanel) { cachedStateLength = HeatUIInternalTools.GetAnimatorClipLength(panels[currentPanelIndex].panelObject, "MainPanel_In"); }
|
||||
else if (panelMode == PanelMode.SubPanel) { cachedStateLength = HeatUIInternalTools.GetAnimatorClipLength(panels[currentPanelIndex].panelObject, "SubPanel_In"); }
|
||||
else if (panelMode == PanelMode.Custom) { cachedStateLength = 1f; }
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
if (ControllerManager.instance != null) { managerIndex = ControllerManager.instance.panels.Count; ControllerManager.instance.panels.Add(this); }
|
||||
if (panels.Count == 0) { return; }
|
||||
|
||||
InitializePanels();
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
if (ControllerManager.instance != null)
|
||||
{
|
||||
ControllerManager.instance.currentManagerIndex = managerIndex;
|
||||
}
|
||||
|
||||
if (bypassAnimationOnEnable)
|
||||
{
|
||||
for (int i = 0; i < panels.Count; i++)
|
||||
{
|
||||
if (panels[i].panelObject == null)
|
||||
continue;
|
||||
|
||||
if (currentPanelIndex == i)
|
||||
{
|
||||
panels[i].panelObject.gameObject.SetActive(true);
|
||||
panels[i].panelObject.enabled = true;
|
||||
panels[i].panelObject.Play("Panel Instant In");
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
panels[i].panelObject.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (isInitialized && !bypassAnimationOnEnable && nextPanel == null)
|
||||
{
|
||||
currentPanel.enabled = true;
|
||||
currentPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
currentPanel.Play(panelFadeIn);
|
||||
if (currentButton != null) { currentButton.SetSelected(true); }
|
||||
}
|
||||
|
||||
else if (isInitialized && !bypassAnimationOnEnable && nextPanel != null)
|
||||
{
|
||||
nextPanel.enabled = true;
|
||||
nextPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
nextPanel.Play(panelFadeIn);
|
||||
if (nextButton != null) { nextButton.SetSelected(true); }
|
||||
}
|
||||
|
||||
StopCoroutine("DisablePreviousPanel");
|
||||
StopCoroutine("DisableAnimators");
|
||||
StartCoroutine("DisableAnimators");
|
||||
}
|
||||
|
||||
public void InitializePanels()
|
||||
{
|
||||
if (panels[currentPanelIndex].panelButton != null)
|
||||
{
|
||||
currentButton = panels[currentPanelIndex].panelButton;
|
||||
currentButton.SetSelected(true);
|
||||
}
|
||||
|
||||
currentPanel = panels[currentPanelIndex].panelObject;
|
||||
currentPanel.enabled = true;
|
||||
currentPanel.gameObject.SetActive(true);
|
||||
|
||||
currentPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
currentPanel.Play(panelFadeIn);
|
||||
|
||||
onPanelChanged.Invoke(currentPanelIndex);
|
||||
isInitialized = true;
|
||||
|
||||
for (int i = 0; i < panels.Count; i++)
|
||||
{
|
||||
if (panels[i].panelObject == null) { continue; }
|
||||
if (panels[i].hotkeyParent != null) { panels[i].hotkeys = panels[i].hotkeyParent.GetComponentsInChildren<HotkeyEvent>(); }
|
||||
if (i != currentPanelIndex && cullPanels) { panels[i].panelObject.gameObject.SetActive(false); }
|
||||
if (initializeButtons)
|
||||
{
|
||||
string tempName = panels[i].panelName;
|
||||
if (panels[i].panelButton != null) { panels[i].panelButton.onClick.AddListener(() => OpenPanel(tempName)); }
|
||||
if (panels[i].altPanelButton != null) { panels[i].altPanelButton.onClick.AddListener(() => OpenPanel(tempName)); }
|
||||
if (panels[i].altBoxButton != null) { panels[i].altBoxButton.onClick.AddListener(() => OpenPanel(tempName)); }
|
||||
}
|
||||
}
|
||||
|
||||
StopCoroutine("DisableAnimators");
|
||||
StartCoroutine("DisableAnimators");
|
||||
}
|
||||
|
||||
public void OpenFirstPanel()
|
||||
{
|
||||
OpenPanelByIndex(0);
|
||||
}
|
||||
|
||||
public void OpenPanel(string newPanel)
|
||||
{
|
||||
bool catchedPanel = false;
|
||||
|
||||
for (int i = 0; i < panels.Count; i++)
|
||||
{
|
||||
if (panels[i].panelName == newPanel)
|
||||
{
|
||||
newPanelIndex = i;
|
||||
catchedPanel = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (catchedPanel == false)
|
||||
{
|
||||
Debug.LogWarning("There is no panel named '" + newPanel + "' in the panel list.", this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (newPanelIndex != currentPanelIndex)
|
||||
{
|
||||
if (cullPanels) { StopCoroutine("DisablePreviousPanel"); }
|
||||
if (ControllerManager.instance != null) { ControllerManager.instance.currentManagerIndex = managerIndex; }
|
||||
|
||||
currentPanel = panels[currentPanelIndex].panelObject;
|
||||
|
||||
if (panels[currentPanelIndex].hotkeyParent != null) { foreach (HotkeyEvent he in panels[currentPanelIndex].hotkeys) { he.enabled = false; } }
|
||||
if (panels[currentPanelIndex].panelButton != null) { currentButton = panels[currentPanelIndex].panelButton; }
|
||||
if (ControllerManager.instance != null && EventSystem.current.currentSelectedGameObject != null) { panels[currentPanelIndex].latestSelected = EventSystem.current.currentSelectedGameObject; }
|
||||
|
||||
currentPanelIndex = newPanelIndex;
|
||||
nextPanel = panels[currentPanelIndex].panelObject;
|
||||
nextPanel.gameObject.SetActive(true);
|
||||
|
||||
currentPanel.enabled = true;
|
||||
nextPanel.enabled = true;
|
||||
|
||||
currentPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
nextPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
|
||||
currentPanel.Play(panelFadeOut);
|
||||
nextPanel.Play(panelFadeIn);
|
||||
|
||||
if (cullPanels) { StartCoroutine("DisablePreviousPanel"); }
|
||||
if (panels[currentPanelIndex].hotkeyParent != null) { foreach (HotkeyEvent he in panels[currentPanelIndex].hotkeys) { he.enabled = true; } }
|
||||
|
||||
currentButtonIndex = newPanelIndex;
|
||||
|
||||
if (ControllerManager.instance != null && panels[currentPanelIndex].latestSelected != null) { ControllerManager.instance.SelectUIObject(panels[currentPanelIndex].latestSelected); }
|
||||
else if (ControllerManager.instance != null && panels[currentPanelIndex].latestSelected == null) { ControllerManager.instance.SelectUIObject(panels[currentPanelIndex].firstSelected); }
|
||||
|
||||
if (currentButton != null) { currentButton.SetSelected(false); }
|
||||
if (panels[currentButtonIndex].panelButton != null)
|
||||
{
|
||||
nextButton = panels[currentButtonIndex].panelButton;
|
||||
nextButton.SetSelected(true);
|
||||
}
|
||||
|
||||
onPanelChanged.Invoke(currentPanelIndex);
|
||||
|
||||
StopCoroutine("DisableAnimators");
|
||||
StartCoroutine("DisableAnimators");
|
||||
}
|
||||
}
|
||||
|
||||
public void OpenPanelByIndex(int panelIndex)
|
||||
{
|
||||
if (panelIndex > panels.Count || panelIndex < 0)
|
||||
{
|
||||
Debug.LogWarning("Index '" + panelIndex.ToString() + "' doesn't exist.", this);
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = 0; i < panels.Count; i++)
|
||||
{
|
||||
if (panels[i].panelName == panels[panelIndex].panelName)
|
||||
{
|
||||
OpenPanel(panels[panelIndex].panelName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NextPanel()
|
||||
{
|
||||
if (currentPanelIndex <= panels.Count - 2 && !panels[currentPanelIndex + 1].disableNavigation)
|
||||
{
|
||||
OpenPanelByIndex(currentPanelIndex + 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void PreviousPanel()
|
||||
{
|
||||
if (currentPanelIndex >= 1 && !panels[currentPanelIndex - 1].disableNavigation)
|
||||
{
|
||||
OpenPanelByIndex(currentPanelIndex - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowCurrentPanel()
|
||||
{
|
||||
if (nextPanel == null)
|
||||
{
|
||||
StopCoroutine("DisableAnimators");
|
||||
StartCoroutine("DisableAnimators");
|
||||
|
||||
currentPanel.enabled = true;
|
||||
currentPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
currentPanel.Play(panelFadeIn);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
StopCoroutine("DisableAnimators");
|
||||
StartCoroutine("DisableAnimators");
|
||||
|
||||
nextPanel.enabled = true;
|
||||
nextPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
nextPanel.Play(panelFadeIn);
|
||||
}
|
||||
}
|
||||
|
||||
public void HideCurrentPanel()
|
||||
{
|
||||
if (nextPanel == null)
|
||||
{
|
||||
StopCoroutine("DisableAnimators");
|
||||
StartCoroutine("DisableAnimators");
|
||||
|
||||
currentPanel.enabled = true;
|
||||
currentPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
currentPanel.Play(panelFadeOut);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
StopCoroutine("DisableAnimators");
|
||||
StartCoroutine("DisableAnimators");
|
||||
|
||||
nextPanel.enabled = true;
|
||||
nextPanel.SetFloat(animSpeedKey, animationSpeed);
|
||||
nextPanel.Play(panelFadeOut);
|
||||
}
|
||||
}
|
||||
|
||||
public void ShowCurrentButton()
|
||||
{
|
||||
if (nextButton == null) { currentButton.SetSelected(true); }
|
||||
else { nextButton.SetSelected(true); }
|
||||
}
|
||||
|
||||
public void HideCurrentButton()
|
||||
{
|
||||
if (nextButton == null) { currentButton.SetSelected(false); }
|
||||
else { nextButton.SetSelected(false); }
|
||||
}
|
||||
|
||||
public void AddNewItem()
|
||||
{
|
||||
PanelItem panel = new PanelItem();
|
||||
|
||||
if (panels.Count != 0 && panels[panels.Count - 1].panelObject != null)
|
||||
{
|
||||
int tempIndex = panels.Count - 1;
|
||||
|
||||
GameObject tempPanel = panels[tempIndex].panelObject.transform.parent.GetChild(tempIndex).gameObject;
|
||||
GameObject newPanel = Instantiate(tempPanel, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
|
||||
newPanel.transform.SetParent(panels[tempIndex].panelObject.transform.parent, false);
|
||||
newPanel.gameObject.name = "New Panel " + tempIndex.ToString();
|
||||
|
||||
panel.panelName = "New Panel " + tempIndex.ToString();
|
||||
panel.panelObject = newPanel.GetComponent<Animator>();
|
||||
|
||||
if (panels[tempIndex].panelButton != null)
|
||||
{
|
||||
GameObject tempButton = panels[tempIndex].panelButton.transform.parent.GetChild(tempIndex).gameObject;
|
||||
GameObject newButton = Instantiate(tempButton, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
|
||||
newButton.transform.SetParent(panels[tempIndex].panelButton.transform.parent, false);
|
||||
newButton.gameObject.name = "New Panel " + tempIndex.ToString();
|
||||
|
||||
panel.panelButton = newButton.GetComponent<PanelButton>();
|
||||
}
|
||||
|
||||
else if (panels[tempIndex].altPanelButton != null)
|
||||
{
|
||||
GameObject tempButton = panels[tempIndex].altPanelButton.transform.parent.GetChild(tempIndex).gameObject;
|
||||
GameObject newButton = Instantiate(tempButton, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
|
||||
newButton.transform.SetParent(panels[tempIndex].panelButton.transform.parent, false);
|
||||
newButton.gameObject.name = "New Panel " + tempIndex.ToString();
|
||||
|
||||
panel.altPanelButton = newButton.GetComponent<ButtonManager>();
|
||||
}
|
||||
|
||||
else if (panels[tempIndex].altBoxButton != null)
|
||||
{
|
||||
GameObject tempButton = panels[tempIndex].altBoxButton.transform.parent.GetChild(tempIndex).gameObject;
|
||||
GameObject newButton = Instantiate(tempButton, new Vector3(0, 0, 0), Quaternion.identity) as GameObject;
|
||||
|
||||
newButton.transform.SetParent(panels[tempIndex].panelButton.transform.parent, false);
|
||||
newButton.gameObject.name = "New Panel " + tempIndex.ToString();
|
||||
|
||||
panel.altBoxButton = newButton.GetComponent<BoxButtonManager>();
|
||||
}
|
||||
}
|
||||
|
||||
panels.Add(panel);
|
||||
}
|
||||
|
||||
IEnumerator DisablePreviousPanel()
|
||||
{
|
||||
if (updateMode == UpdateMode.UnscaledTime) { yield return new WaitForSecondsRealtime(cachedStateLength * animationSpeed); }
|
||||
else { yield return new WaitForSeconds(cachedStateLength * animationSpeed); }
|
||||
|
||||
for (int i = 0; i < panels.Count; i++)
|
||||
{
|
||||
if (i == currentPanelIndex)
|
||||
continue;
|
||||
|
||||
panels[i].panelObject.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DisableAnimators()
|
||||
{
|
||||
if (updateMode == UpdateMode.UnscaledTime) { yield return new WaitForSecondsRealtime(cachedStateLength * animationSpeed); }
|
||||
else { yield return new WaitForSeconds(cachedStateLength * animationSpeed); }
|
||||
|
||||
if (currentPanel != null) { currentPanel.enabled = false; }
|
||||
if (nextPanel != null) { nextPanel.enabled = false; }
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 491c0a6eddecda542a6476e707dc7c7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {fileID: 2800000, guid: c347f4df1770e294a8bf85f04cf5757d, 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/Panels/PanelManager.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,127 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[CustomEditor(typeof(PanelManager))]
|
||||
public class PanelManagerEditor : Editor
|
||||
{
|
||||
private GUISkin customSkin;
|
||||
private PanelManager pmTarget;
|
||||
private int currentTab;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
pmTarget = (PanelManager)target;
|
||||
|
||||
if (EditorGUIUtility.isProSkin == true) { customSkin = HeatUIEditorHandler.GetDarkEditor(customSkin); }
|
||||
else { customSkin = HeatUIEditorHandler.GetLightEditor(customSkin); }
|
||||
}
|
||||
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
HeatUIEditorHandler.DrawComponentHeader(customSkin, "Panel Manager Top Header");
|
||||
|
||||
GUIContent[] toolbarTabs = new GUIContent[2];
|
||||
toolbarTabs[0] = new GUIContent("Content");
|
||||
toolbarTabs[1] = 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("Settings", "Settings"), customSkin.FindStyle("Tab Settings")))
|
||||
currentTab = 1;
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
|
||||
var panels = serializedObject.FindProperty("panels");
|
||||
var currentPanelIndex = serializedObject.FindProperty("currentPanelIndex");
|
||||
|
||||
var cullPanels = serializedObject.FindProperty("cullPanels");
|
||||
var onPanelChanged = serializedObject.FindProperty("onPanelChanged");
|
||||
var initializeButtons = serializedObject.FindProperty("initializeButtons");
|
||||
var bypassAnimationOnEnable = serializedObject.FindProperty("bypassAnimationOnEnable");
|
||||
var updateMode = serializedObject.FindProperty("updateMode");
|
||||
var panelMode = serializedObject.FindProperty("panelMode");
|
||||
var animationSpeed = serializedObject.FindProperty("animationSpeed");
|
||||
|
||||
switch (currentTab)
|
||||
{
|
||||
case 0:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Content Header", 6);
|
||||
|
||||
if (pmTarget.currentPanelIndex > pmTarget.panels.Count - 1) { pmTarget.currentPanelIndex = 0; }
|
||||
if (pmTarget.panels.Count != 0)
|
||||
{
|
||||
GUILayout.BeginVertical(EditorStyles.helpBox);
|
||||
GUILayout.BeginHorizontal();
|
||||
|
||||
GUI.enabled = false;
|
||||
EditorGUILayout.LabelField(new GUIContent("Current Panel:"), customSkin.FindStyle("Text"), GUILayout.Width(82));
|
||||
GUI.enabled = true;
|
||||
EditorGUILayout.LabelField(new GUIContent(pmTarget.panels[currentPanelIndex.intValue].panelName), customSkin.FindStyle("Text"));
|
||||
|
||||
GUILayout.EndHorizontal();
|
||||
GUILayout.Space(2);
|
||||
|
||||
if (Application.isPlaying == true) { GUI.enabled = false; }
|
||||
|
||||
currentPanelIndex.intValue = EditorGUILayout.IntSlider(currentPanelIndex.intValue, 0, pmTarget.panels.Count - 1);
|
||||
|
||||
if (Application.isPlaying == false && pmTarget.panels[currentPanelIndex.intValue].panelObject != null)
|
||||
{
|
||||
for (int i = 0; i < pmTarget.panels.Count; i++)
|
||||
{
|
||||
if (i == currentPanelIndex.intValue)
|
||||
{
|
||||
var tempCG = pmTarget.panels[currentPanelIndex.intValue].panelObject.GetComponent<CanvasGroup>();
|
||||
if (tempCG != null) { tempCG.alpha = 1; }
|
||||
}
|
||||
|
||||
else if (pmTarget.panels[i].panelObject != null)
|
||||
{
|
||||
var tempCG = pmTarget.panels[i].panelObject.GetComponent<CanvasGroup>();
|
||||
if (tempCG != null) { tempCG.alpha = 0; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (pmTarget.panels[pmTarget.currentPanelIndex].panelObject != null && GUILayout.Button("Select Current Panel", customSkin.button)) { Selection.activeObject = pmTarget.panels[pmTarget.currentPanelIndex].panelObject; }
|
||||
GUI.enabled = true;
|
||||
GUILayout.EndVertical();
|
||||
|
||||
}
|
||||
|
||||
else { EditorGUILayout.HelpBox("Panel List is empty. Create a new item to see more options.", MessageType.Info); }
|
||||
|
||||
GUILayout.BeginVertical();
|
||||
EditorGUI.indentLevel = 1;
|
||||
|
||||
EditorGUILayout.PropertyField(panels, new GUIContent("Panel Items"), true);
|
||||
|
||||
EditorGUI.indentLevel = 0;
|
||||
GUILayout.EndVertical();
|
||||
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Events Header", 10);
|
||||
EditorGUILayout.PropertyField(onPanelChanged, new GUIContent("On Panel Changed"), true);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
HeatUIEditorHandler.DrawHeader(customSkin, "Options Header", 6);
|
||||
cullPanels.boolValue = HeatUIEditorHandler.DrawToggle(cullPanels.boolValue, customSkin, "Cull Panels", "Disables unused panels.");
|
||||
initializeButtons.boolValue = HeatUIEditorHandler.DrawToggle(initializeButtons.boolValue, customSkin, "Initialize Buttons", "Automatically adds necessary events to buttons.");
|
||||
bypassAnimationOnEnable.boolValue = HeatUIEditorHandler.DrawToggle(bypassAnimationOnEnable.boolValue, customSkin, "Bypass Animation On Enable");
|
||||
HeatUIEditorHandler.DrawProperty(updateMode, customSkin, "Update Mode");
|
||||
HeatUIEditorHandler.DrawProperty(panelMode, customSkin, "Panel Mode");
|
||||
HeatUIEditorHandler.DrawProperty(animationSpeed, customSkin, "Animation Speed");
|
||||
break;
|
||||
}
|
||||
|
||||
serializedObject.ApplyModifiedProperties();
|
||||
if (Application.isPlaying == false) { Repaint(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 38786fb740848df47878eba57d4f11f7
|
||||
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/Panels/PanelManagerEditor.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
[RequireComponent(typeof(SettingsElement))]
|
||||
public class SettingsDescription : MonoBehaviour
|
||||
{
|
||||
[Header("Resources")]
|
||||
public SettingsDescriptionManager manager;
|
||||
public SettingsElement element;
|
||||
|
||||
[Header("Content")]
|
||||
[SerializeField] private Sprite cover;
|
||||
[SerializeField] private string title = "Title";
|
||||
[SerializeField][TextArea] private string description = "Description area.";
|
||||
|
||||
[Header("Localization")]
|
||||
[SerializeField] private string titleKey;
|
||||
[SerializeField] private string descriptionKey;
|
||||
|
||||
void Start()
|
||||
{
|
||||
#if UNITY_2023_2_OR_NEWER
|
||||
if (manager == null && FindObjectsByType<SettingsDescriptionManager>(FindObjectsSortMode.None).Length > 0)
|
||||
{
|
||||
manager = FindObjectsByType<SettingsDescriptionManager>(FindObjectsSortMode.None)[0];
|
||||
}
|
||||
#else
|
||||
if (manager == null && FindObjectsOfType(typeof(SettingsDescriptionManager)).Length > 0)
|
||||
{
|
||||
manager = (SettingsDescriptionManager)FindObjectsOfType(typeof(SettingsDescriptionManager))[0];
|
||||
}
|
||||
#endif
|
||||
else if (manager == null) { Destroy(this); }
|
||||
|
||||
if (element == null) { element = gameObject.GetComponent<SettingsElement>(); }
|
||||
|
||||
element.onHover.AddListener(delegate
|
||||
{
|
||||
if (manager == null)
|
||||
return;
|
||||
|
||||
if (manager.localizedObject != null && manager.useLocalization == true && !string.IsNullOrEmpty(titleKey) && !string.IsNullOrEmpty(descriptionKey))
|
||||
{
|
||||
manager.UpdateUI(manager.localizedObject.GetKeyOutput(titleKey), manager.localizedObject.GetKeyOutput(descriptionKey), cover);
|
||||
}
|
||||
else { manager.UpdateUI(title, description, cover); }
|
||||
});
|
||||
|
||||
element.onLeave.AddListener(delegate
|
||||
{
|
||||
if (manager == null)
|
||||
return;
|
||||
|
||||
manager.SetDefault();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca44c0d69fc9c164aae7a6e987dd529e
|
||||
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/Panels/SettingsDescription.cs
|
||||
uploadId: 629893
|
@ -0,0 +1,98 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using TMPro;
|
||||
|
||||
namespace Michsky.UI.Heat
|
||||
{
|
||||
public class SettingsDescriptionManager : MonoBehaviour
|
||||
{
|
||||
[Header("Default Content")]
|
||||
[SerializeField] private Sprite cover;
|
||||
[SerializeField] private string title = "Settings";
|
||||
[SerializeField] [TextArea] private string description = "Description area.";
|
||||
|
||||
[Header("Localization")]
|
||||
public string tableID = "UI";
|
||||
[SerializeField] private string titleKey;
|
||||
[SerializeField] private string descriptionKey;
|
||||
|
||||
[Header("Resources")]
|
||||
[SerializeField] private Image coverImage;
|
||||
[SerializeField] private TextMeshProUGUI titleObject;
|
||||
[SerializeField] private TextMeshProUGUI descriptionObject;
|
||||
|
||||
[Header("Settings")]
|
||||
public bool useLocalization = true;
|
||||
|
||||
// Helpers
|
||||
[HideInInspector] public LocalizedObject localizedObject;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (useLocalization && !string.IsNullOrEmpty(titleKey) && !string.IsNullOrEmpty(descriptionKey))
|
||||
{
|
||||
CheckForLocalization();
|
||||
}
|
||||
}
|
||||
|
||||
void OnEnable()
|
||||
{
|
||||
SetDefault();
|
||||
}
|
||||
|
||||
void CheckForLocalization()
|
||||
{
|
||||
localizedObject = gameObject.GetComponent<LocalizedObject>();
|
||||
|
||||
if (localizedObject == null)
|
||||
{
|
||||
localizedObject = gameObject.AddComponent<LocalizedObject>();
|
||||
localizedObject.objectType = LocalizedObject.ObjectType.ComponentDriven;
|
||||
localizedObject.updateMode = LocalizedObject.UpdateMode.OnDemand;
|
||||
localizedObject.InitializeItem();
|
||||
|
||||
LocalizationSettings locSettings = LocalizationManager.instance.UIManagerAsset.localizationSettings;
|
||||
foreach (LocalizationSettings.Table table in locSettings.tables)
|
||||
{
|
||||
if (tableID == table.tableID)
|
||||
{
|
||||
localizedObject.tableIndex = locSettings.tables.IndexOf(table);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (localizedObject.tableIndex == -1 || LocalizationManager.instance == null || !LocalizationManager.instance.UIManagerAsset.enableLocalization)
|
||||
{
|
||||
localizedObject = null;
|
||||
useLocalization = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateUI(string newTitle, string newDescription, Sprite newCover)
|
||||
{
|
||||
if (newCover != null) { coverImage.sprite = newCover; }
|
||||
else { coverImage.sprite = cover; }
|
||||
|
||||
titleObject.text = newTitle;
|
||||
descriptionObject.text = newDescription;
|
||||
}
|
||||
|
||||
public void SetDefault()
|
||||
{
|
||||
if (localizedObject == null)
|
||||
{
|
||||
titleObject.text = title;
|
||||
descriptionObject.text = description;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
titleObject.text = localizedObject.GetKeyOutput(titleKey);
|
||||
descriptionObject.text = localizedObject.GetKeyOutput(descriptionKey);
|
||||
}
|
||||
|
||||
coverImage.sprite = cover;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5da61ceb26ee86d43ac073c731909ac9
|
||||
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/Panels/SettingsDescriptionManager.cs
|
||||
uploadId: 629893
|
Reference in New Issue
Block a user