Insanely huge initial commit

This commit is contained in:
2026-02-21 17:04:05 -08:00
parent 9cdd36191a
commit 613d75914a
22525 changed files with 4035207 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f3c0ca99476dd73418f733dc8837d50b
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,173 @@
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using UnityEngine;
using UnityEngine.SceneManagement;
namespace MoreMountains.Tools
{
/// <summary>
/// Command lines to be run from the MMDebugMenu
/// To add new ones, add the [MMDebugLogCommand] attribute to any static method
/// </summary>
public class MMDebugMenuCommands : MonoBehaviour
{
/// <summary>
/// Outputs Time.time
/// </summary>
[MMDebugLogCommand]
public static void Now()
{
string message = "Time.time is " + Time.time;
MMDebug.DebugLogTime(message, "", 3, true);
}
/// <summary>
/// Clears the console
/// </summary>
[MMDebugLogCommand]
public static void Clear()
{
MMDebug.DebugLogClear();
}
/// <summary>
/// Restarts the current scene
/// </summary>
[MMDebugLogCommand]
public static void Restart()
{
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene(scene.name, LoadSceneMode.Single);
}
/// <summary>
/// Reloads the current scene
/// </summary>
[MMDebugLogCommand]
public static void Reload()
{
Scene scene = SceneManager.GetActiveScene();
SceneManager.LoadScene(scene.name, LoadSceneMode.Single);
}
/// <summary>
/// Displays system info
/// </summary>
[MMDebugLogCommand]
public static void Sysinfo()
{
MMDebug.DebugLogTime(MMDebug.GetSystemInfo());
}
/// <summary>
/// Exits the application
/// </summary>
[MMDebugLogCommand]
public static void Quit()
{
InternalQuit();
}
/// <summary>
/// Exits the application
/// </summary>
[MMDebugLogCommand]
public static void Exit()
{
InternalQuit();
}
/// <summary>
/// Displays a list of all the commands
/// </summary>
[MMDebugLogCommand]
public static void Help()
{
string result = "LIST OF COMMANDS";
foreach (MethodInfo method in MMDebug.Commands.OrderBy(m => m.Name))
{
result += "\n- <color=#FFFFFF>"+method.Name+"</color>";
}
MMDebug.DebugLogTime(result, "#FFC400", 3, true);
}
/// <summary>
/// Internal method used to exit the app
/// </summary>
private static void InternalQuit()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
/// <summary>
/// Sets the vsync count to the specified parameter
/// </summary>
/// <param name="args"></param>
[MMDebugLogCommandArgumentCount(1)]
[MMDebugLogCommand]
public static void Vsync(string[] args)
{
if (int.TryParse(args[1], out int vSyncCount))
{
QualitySettings.vSyncCount = vSyncCount;
MMDebug.DebugLogTime("VSyncCount set to " + vSyncCount, "#FFC400", 3, true);
}
}
/// <summary>
/// Sets the target framerate to the specified value
/// </summary>
/// <param name="args"></param>
[MMDebugLogCommandArgumentCount(1)]
[MMDebugLogCommand]
public static void Framerate(string[] args)
{
if (int.TryParse(args[1], out int framerate))
{
Application.targetFrameRate = framerate;
MMDebug.DebugLogTime("Framerate set to " + framerate, "#FFC400", 3, true);
}
}
/// <summary>
/// Sets the target timescale to the specified value
/// </summary>
/// <param name="args"></param>
[MMDebugLogCommandArgumentCount(1)]
[MMDebugLogCommand]
public static void Timescale(string[] args)
{
if (float.TryParse(args[1], System.Globalization.NumberStyles.Float, CultureInfo.InvariantCulture, out float timescale))
{
Time.timeScale = timescale;
MMDebug.DebugLogTime("Timescale set to " + timescale, "#FFC400", 3, true);
}
}
/// <summary>
/// Computes and displays the biggest int out of the two passed in arguments
/// Just an example of how you can do multiple argument commands
/// </summary>
/// <param name="args"></param>
[MMDebugLogCommandArgumentCount(2)]
[MMDebugLogCommand]
public static void Biggest(string[] args)
{
if (int.TryParse(args[1], out int i1) && int.TryParse(args[2], out int i2))
{
string result;
int biggest = (i1 >= i2) ? i1 : i2;
result = biggest + " is the biggest number";
MMDebug.DebugLogTime(result, "#FFC400", 3, true);
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1e4e4b1cacbffd14ebb3aea93190805f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: eada5cd1ed867c44e9de94da9de97bde
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,23 @@
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// An event used to broadcast button events from a MMDebugMenu
/// </summary>
public struct MMDebugMenuButtonEvent
{
public enum EventModes { FromButton, SetButton }
static private event Delegate OnEvent;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] private static void RuntimeInitialization() { OnEvent = null; }
static public void Register(Delegate callback) { OnEvent += callback; }
static public void Unregister(Delegate callback) { OnEvent -= callback; }
public delegate void Delegate(string buttonEventName, bool active = true, EventModes eventMode = EventModes.FromButton);
static public void Trigger(string buttonEventName, bool active = true, EventModes eventMode = EventModes.FromButton)
{
OnEvent?.Invoke(buttonEventName, active, eventMode);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7fb7575f8c305d244ba40b4b661d997c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,72 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// An event fired when a button gets pressed in a MMDebugMenu
/// </summary>
[Serializable]
public class MMDButtonPressedEvent : UnityEvent
{
}
/// <summary>
/// A class used to listen to button events from a MMDebugMenu
/// </summary>
public class MMDebugMenuButtonEventListener : MonoBehaviour
{
[Header("Event")]
/// the name of the event to listen to
public string ButtonEventName = "Button";
/// an event to fire when the event is heard
public MMDButtonPressedEvent MMDEvent;
[Header("Test")]
public bool TestValue = true;
[MMInspectorButton("TestSetValue")]
public bool TestSetValueButton;
/// <summary>
/// This test methods will send a set event to all buttons bound to the ButtonEventName
/// </summary>
protected virtual void TestSetValue()
{
MMDebugMenuButtonEvent.Trigger(ButtonEventName, TestValue, MMDebugMenuButtonEvent.EventModes.SetButton);
}
/// <summary>
/// When we get a menu button event, we invoke
/// </summary>
/// <param name="buttonEventName"></param>
protected virtual void OnMMDebugMenuButtonEvent(string buttonEventName, bool value, MMDebugMenuButtonEvent.EventModes eventMode)
{
if ((eventMode == MMDebugMenuButtonEvent.EventModes.FromButton) && (buttonEventName == ButtonEventName))
{
if (MMDEvent != null)
{
MMDEvent.Invoke();
}
}
}
/// <summary>
/// Starts listening for events
/// </summary>
public virtual void OnEnable()
{
MMDebugMenuButtonEvent.Register(OnMMDebugMenuButtonEvent);
}
/// <summary>
/// Stops listening for events
/// </summary>
public virtual void OnDisable()
{
MMDebugMenuButtonEvent.Unregister(OnMMDebugMenuButtonEvent);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2313508e7b935c54d9877ca20548a1b5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// An event used to broadcast checkbox events from a MMDebugMenu
/// </summary>
public struct MMDebugMenuCheckboxEvent
{
static private event Delegate OnEvent;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] private static void RuntimeInitialization() { OnEvent = null; }
static public void Register(Delegate callback) { OnEvent += callback; }
static public void Unregister(Delegate callback) { OnEvent -= callback; }
public enum EventModes { FromCheckbox, SetCheckbox }
public delegate void Delegate(string checkboxEventName, bool value, EventModes eventMode = EventModes.FromCheckbox);
static public void Trigger(string checkboxEventName, bool value, EventModes eventMode = EventModes.FromCheckbox)
{
OnEvent?.Invoke(checkboxEventName, value, eventMode);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d039e33a2be33f14e98835c8a207cc1d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,91 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
[Serializable]
public class MMDCheckboxPressedEvent : UnityEvent<bool> { }
[Serializable]
public class MMDCheckboxTrueEvent : UnityEvent { }
[Serializable]
public class MMDCheckboxFalseEvent : UnityEvent { }
/// <summary>
/// A class used to listen to events from a MMDebugMenu's checkbox
/// </summary>
public class MMDebugMenuCheckboxEventListener : MonoBehaviour
{
[Header("Events")]
/// the name of the event to listen to
public string CheckboxEventName = "CheckboxEventName";
/// an event fired when the checkbox gets pressed
public MMDCheckboxPressedEvent MMDPressedEvent;
/// an event fired when the checkbox is pressed and becomes true/checked
public MMDCheckboxTrueEvent MMDTrueEvent;
/// an event fired when the checkbox is pressed and becomes false/unchecked
public MMDCheckboxFalseEvent MMDFalseEvent;
[Header("Test")]
public bool TestValue = true;
[MMInspectorButton("TestSetValue")]
public bool TestSetValueButton;
/// <summary>
/// This test methods will send a set event to all checkboxes bound to the CheckboxEventName
/// </summary>
protected virtual void TestSetValue()
{
MMDebugMenuCheckboxEvent.Trigger(CheckboxEventName, TestValue, MMDebugMenuCheckboxEvent.EventModes.SetCheckbox);
}
/// <summary>
/// When get a checkbox event, we invoke our events if needed
/// </summary>
/// <param name="checkboxNameEvent"></param>
/// <param name="value"></param>
protected virtual void OnMMDebugMenuCheckboxEvent(string checkboxNameEvent, bool value, MMDebugMenuCheckboxEvent.EventModes eventMode)
{
if ((eventMode == MMDebugMenuCheckboxEvent.EventModes.FromCheckbox) && (checkboxNameEvent == CheckboxEventName))
{
if (MMDPressedEvent != null)
{
MMDPressedEvent.Invoke(value);
}
if (value)
{
if (MMDTrueEvent != null)
{
MMDTrueEvent.Invoke();
}
}
else
{
if (MMDFalseEvent != null)
{
MMDFalseEvent.Invoke();
}
}
}
}
/// <summary>
/// Starts listening for events
/// </summary>
public virtual void OnEnable()
{
MMDebugMenuCheckboxEvent.Register(OnMMDebugMenuCheckboxEvent);
}
/// <summary>
/// Stops listening for events
/// </summary>
public virtual void OnDisable()
{
MMDebugMenuCheckboxEvent.Unregister(OnMMDebugMenuCheckboxEvent);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9091b3d5ef7624b47a328c984fa25e09
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,22 @@
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// An event used to broadcast slider events from a MMDebugMenu
/// </summary>
public struct MMDebugMenuSliderEvent
{
static private event Delegate OnEvent;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)] private static void RuntimeInitialization() { OnEvent = null; }
static public void Register(Delegate callback) { OnEvent += callback; }
static public void Unregister(Delegate callback) { OnEvent -= callback; }
public enum EventModes { FromSlider, SetSlider }
public delegate void Delegate(string sliderEventName, float value, EventModes eventMode = EventModes.FromSlider);
static public void Trigger(string sliderEventName, float value, EventModes eventMode = EventModes.FromSlider)
{
OnEvent?.Invoke(sliderEventName, value, eventMode);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e815f28291646fc47a4ea53fa52db2a4
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
[Serializable]
public class MMDSliderValueChangedEvent : UnityEvent<float> { }
/// <summary>
/// A class used to listen to slider events from a MMDebugMenu
/// </summary>
public class MMDebugMenuSliderEventListener : MonoBehaviour
{
[Header("Events")]
/// the name of the slider event to listen to
public string SliderEventName = "SliderEventName";
/// an event fired when the slider's value changes
public MMDSliderValueChangedEvent MMDValueChangedEvent;
[Header("Test")]
[Range(0f, 1f)]
public float TestValue = 1f;
[MMInspectorButton("TestSetValue")]
public bool TestSetValueButton;
/// <summary>
/// This test methods will send a set event to all sliders bound to the SliderEventName
/// </summary>
protected virtual void TestSetValue()
{
MMDebugMenuSliderEvent.Trigger(SliderEventName, TestValue, MMDebugMenuSliderEvent.EventModes.SetSlider);
}
/// <summary>
/// When we get a slider event, we trigger an event if needed
/// </summary>
/// <param name="sliderEventName"></param>
/// <param name="value"></param>
protected virtual void OnMMDebugMenuSliderEvent(string sliderEventName, float value, MMDebugMenuSliderEvent.EventModes eventMode)
{
if ( (eventMode == MMDebugMenuSliderEvent.EventModes.FromSlider)
&& (sliderEventName == SliderEventName))
{
if (MMDValueChangedEvent != null)
{
MMDValueChangedEvent.Invoke(value);
}
}
}
/// <summary>
/// Starts listening for events
/// </summary>
public virtual void OnEnable()
{
MMDebugMenuSliderEvent.Register(OnMMDebugMenuSliderEvent);
}
/// <summary>
/// Stops listening for events
/// </summary>
public virtual void OnDisable()
{
MMDebugMenuSliderEvent.Unregister(OnMMDebugMenuSliderEvent);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 186a986c8de07d3478b88dc10e508869
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,522 @@
using System.Collections;
using UnityEngine;
using UnityEngine.Events;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
using UnityEngine.InputSystem;
#endif
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A debug menu helper, meant to help create quick mobile friendly debug menus
/// </summary>
public class MMDebugMenu : MonoBehaviour
{
/// the possible directions for the menu to appear
public enum ToggleDirections { TopToBottom, LeftToRight, RightToLeft, BottomToTop }
[Header("Data")]
/// the scriptable object containing the menu's data
public MMDebugMenuData Data;
[Header("Bindings")]
/// the container of the whole menu
public CanvasGroup MenuContainer;
/// the scrolling contents
public RectTransform Contents;
/// the menu's background image
public Image MenuBackground;
/// the icon used to close the menu
public Image CloseIcon;
/// the tab bar (where the tab buttons go)
public RectTransform TabBar;
/// the tab contents container (where the contents of the page will go)
public RectTransform TabContainer;
/// the tab manager
public MMDebugMenuTabManager TabManager;
/// the MoreMountains logo
public Image MMLogo;
[Header("Events")]
/// an event to call when the menu opens
public UnityEvent OnOpenEvent;
/// an event to call when the menu closes
public UnityEvent OnCloseEvent;
[Header("Test")]
/// whether or not this menu is active at this moment
[MMReadOnly]
public bool Active = false;
/// a test button to toggle the menu
[MMInspectorButton("ToggleMenu")]
public bool ToggleButton;
protected RectTransform _containerRect;
protected Vector3 _initialContainerPosition;
protected Vector3 _offPosition;
protected Vector3 _newPosition;
protected bool _toggling = false;
/// <summary>
/// On Start we init our menu
/// </summary>
protected virtual void Start()
{
Initialization();
}
/// <summary>
/// Prepares transitions and grabs components
/// </summary>
protected virtual void Initialization()
{
if (Data != null)
{
FillMenu();
}
CloseIcon.color = Data.TextColor;
_containerRect = MenuContainer.GetComponent<RectTransform>();
_initialContainerPosition = _containerRect.localPosition;
MenuBackground.color = Data.BackgroundColor;
switch (Data.ToggleDirection)
{
case ToggleDirections.RightToLeft:
_offPosition = _initialContainerPosition + Vector3.right * _containerRect.rect.width;
break;
case ToggleDirections.LeftToRight:
_offPosition = _initialContainerPosition + Vector3.left * _containerRect.rect.width;
break;
case ToggleDirections.TopToBottom:
_offPosition = _initialContainerPosition + Vector3.up * _containerRect.rect.height;
break;
case ToggleDirections.BottomToTop:
_offPosition = _initialContainerPosition + Vector3.down * _containerRect.rect.height;
break;
}
_containerRect.localPosition = _offPosition;
}
/// <summary>
/// Fills the menu based on the data's contents
/// </summary>
public virtual void FillMenu(bool triggerEvents = false)
{
int tabCounter = 0;
if (MMLogo != null)
{
MMLogo.color = Data.TextColor;
}
foreach (Transform child in Contents.transform)
{
GameObject.Destroy(child.gameObject);
}
foreach (Transform child in TabBar.transform)
Destroy(child.gameObject);
TabManager.Tabs.Clear();
TabManager.TabsContents.Clear();
foreach(MMDebugMenuTabData tab in Data.Tabs)
{
if (!tab.Active)
{
continue;
}
// create tab in the menu
MMDebugMenuTab tabBarTab = Instantiate(Data.TabPrefab);
tabBarTab.SelectedBackgroundColor = Data.TextColor;
tabBarTab.SelectedTextColor = Data.BackgroundColor;
tabBarTab.DeselectedBackgroundColor = Data.BackgroundColor;
tabBarTab.DeselectedTextColor = Data.TextColor;
tabBarTab.TabText.text = tab.Name;
tabBarTab.TabText.font = Data.RegularFont;
tabBarTab.transform.SetParent(TabBar);
tabBarTab.Index = tabCounter;
tabBarTab.Manager = TabManager;
TabManager.Tabs.Add(tabBarTab);
// create tab contents
MMDebugMenuTabContents contents = Instantiate(Data.TabContentsPrefab);
contents.transform.SetParent(TabContainer);
RectTransform rectTransform = contents.GetComponent<RectTransform>();
rectTransform.MMSetLeft(0f);
rectTransform.MMSetRight(0f);
rectTransform.MMSetTop(0f);
rectTransform.MMSetBottom(0f);
contents.Index = tabCounter;
FillTab(contents, tabCounter, triggerEvents);
if (tabCounter == Data.InitialActiveTabIndex)
{
contents.gameObject.SetActive(true);
tabBarTab.Select();
}
else
{
contents.gameObject.SetActive(false);
tabBarTab.Deselect();
}
TabManager.TabsContents.Add(contents);
tabCounter++;
}
// debug tab
if (Data.DisplayDebugTab)
{
MMDebugMenuTab tabBarTab = Instantiate(Data.TabPrefab);
tabBarTab.SelectedBackgroundColor = Data.TextColor;
tabBarTab.SelectedTextColor = Data.BackgroundColor;
tabBarTab.DeselectedBackgroundColor = Data.BackgroundColor;
tabBarTab.DeselectedTextColor = Data.TextColor;
tabBarTab.TabText.text = Data.DebugTabName;
tabBarTab.TabText.font = Data.RegularFont;
tabBarTab.transform.SetParent(TabBar);
tabBarTab.Index = tabCounter;
tabBarTab.Manager = TabManager;
TabManager.Tabs.Add(tabBarTab);
MMDebugMenuDebugTab debugTab = Instantiate(Data.DebugTabPrefab);
debugTab.DebugText.color = Data.TextColor;
debugTab.DebugText.font = Data.RegularFont;
debugTab.transform.SetParent(TabContainer);
debugTab.CommandPrompt.textComponent.font = Data.RegularFont;
debugTab.CommandPrompt.textComponent.color = Data.TextColor;
debugTab.CommandPromptCharacter.font = Data.RegularFont;
debugTab.CommandPromptCharacter.color = Data.TextColor;
MMDebugMenuTabContents debugTabContents = debugTab.GetComponent<MMDebugMenuTabContents>();
debugTabContents.Index = tabCounter;
TabManager.TabsContents.Add(debugTabContents);
RectTransform rectTransform = debugTabContents.GetComponent<RectTransform>();
rectTransform.MMSetLeft(0f);
rectTransform.MMSetRight(0f);
rectTransform.MMSetTop(0f);
rectTransform.MMSetBottom(0f);
if (tabCounter == Data.InitialActiveTabIndex)
{
debugTab.gameObject.SetActive(true);
TabManager.Tabs[tabCounter].Select();
}
else
{
debugTab.gameObject.SetActive(false);
TabManager.Tabs[tabCounter].Deselect();
}
tabCounter++;
}
// fill with spacers
int spacerCount = Data.MaxTabs - tabCounter;
for (int i = 0; i < spacerCount; i++)
{
RectTransform spacer = Instantiate(Data.TabSpacerPrefab);
spacer.transform.SetParent(TabBar);
}
}
protected virtual void FillTab(MMDebugMenuTabContents tab, int index, bool triggerEvents = false)
{
Transform parent = tab.Parent;
foreach (MMDebugMenuItem item in Data.Tabs[index].MenuItems)
{
if (!item.Active)
{
continue;
}
switch (item.Type)
{
case MMDebugMenuItem.MMDebugMenuItemTypes.Button:
MMDebugMenuItemButton button;
button = (item.ButtonType == MMDebugMenuItem.MMDebugMenuItemButtonTypes.Border) ? Instantiate(Data.ButtonBorderPrefab) : Instantiate(Data.ButtonPrefab);
button.name = "MMDebugMenuItemButton_" + item.Name;
button.ButtonText.text = item.ButtonText;
button.ButtonEventName = item.ButtonEventName;
if (item.ButtonType == MMDebugMenuItem.MMDebugMenuItemButtonTypes.Border)
{
button.ButtonText.color = Data.AccentColor;
button.ButtonBg.color = Data.TextColor;
}
else
{
button.ButtonText.color = Data.BackgroundColor;
button.ButtonBg.color = Data.AccentColor;
}
button.ButtonText.font = Data.RegularFont;
button.transform.SetParent(parent);
break;
case MMDebugMenuItem.MMDebugMenuItemTypes.Checkbox:
MMDebugMenuItemCheckbox checkbox = Instantiate(Data.CheckboxPrefab);
checkbox.name = "MMDebugMenuItemCheckbox_" + item.Name;
checkbox.SwitchText.text = item.CheckboxText;
if (item.CheckboxInitialState)
{
checkbox.Switch.SetTrue();
}
else
{
checkbox.Switch.SetFalse();
}
checkbox.CheckboxEventName = item.CheckboxEventName;
checkbox.transform.SetParent(parent);
checkbox.Switch.GetComponent<Image>().color = Data.AccentColor;
checkbox.SwitchText.color = Data.TextColor;
checkbox.SwitchText.font = Data.RegularFont;
break;
case MMDebugMenuItem.MMDebugMenuItemTypes.Slider:
MMDebugMenuItemSlider slider = Instantiate(Data.SliderPrefab);
slider.name = "MMDebugMenuItemSlider_" + item.Name;
slider.Mode = item.SliderMode;
slider.RemapZero = item.SliderRemapZero;
slider.RemapOne = item.SliderRemapOne;
slider.TargetSlider.value = MMMaths.Remap(item.SliderInitialValue, item.SliderRemapZero, item.SliderRemapOne, 0f, 1f);
slider.transform.SetParent(parent);
slider.SliderText.text = item.SliderText;
slider.SliderText.color = Data.TextColor;
slider.SliderText.font = Data.RegularFont;
slider.SliderValueText.text = (item.SliderMode == MMDebugMenuItemSlider.Modes.Int) ? item.SliderInitialValue.ToString() : item.SliderInitialValue.ToString("F3");
slider.SliderValueText.color = Data.AccentColor;
slider.SliderValueText.font = Data.BoldFont;
slider.SliderKnob.color = Data.AccentColor;
slider.SliderLine.color = Data.TextColor;
slider.SliderEventName = item.SliderEventName;
break;
case MMDebugMenuItem.MMDebugMenuItemTypes.Spacer:
GameObject spacerPrefab = (item.SpacerType == MMDebugMenuItem.MMDebugMenuItemSpacerTypes.Small) ? Data.SpacerSmallPrefab : Data.SpacerBigPrefab;
GameObject spacer = Instantiate(spacerPrefab);
spacer.name = "MMDebugMenuItemSpacer_" + item.Name;
spacer.transform.SetParent(parent);
break;
case MMDebugMenuItem.MMDebugMenuItemTypes.Title:
MMDebugMenuItemTitle title = Instantiate(Data.TitlePrefab);
title.name = "MMDebugMenuItemSlider_" + item.Name;
title.TitleText.text = item.TitleText;
title.TitleText.color = Data.TextColor;
title.TitleText.font = Data.BoldFont;
title.TitleLine.color = Data.AccentColor;
title.transform.SetParent(parent);
break;
case MMDebugMenuItem.MMDebugMenuItemTypes.Choices:
MMDebugMenuItemChoices choicesPrefab;
if (item.ChoicesType == MMDebugMenuItem.MMDebugMenuItemChoicesTypes.TwoChoices)
{
choicesPrefab = Data.TwoChoicesPrefab;
}
else
{
choicesPrefab = Data.ThreeChoicesPrefab;
}
MMDebugMenuItemChoices choices = Instantiate(choicesPrefab);
choices.name = "MMDebugMenuItemChoices_" + item.Name;
choices.Choices[0].ButtonText.text = item.ChoiceOneText;
choices.Choices[1].ButtonText.text = item.ChoiceTwoText;
choices.Choices[0].ButtonEventName = item.ChoiceOneEventName;
choices.Choices[1].ButtonEventName = item.ChoiceTwoEventName;
if (item.ChoicesType == MMDebugMenuItem.MMDebugMenuItemChoicesTypes.ThreeChoices)
{
choices.Choices[2].ButtonEventName = item.ChoiceThreeEventName;
choices.Choices[2].ButtonText.text = item.ChoiceThreeText;
}
choices.OffColor = Data.BackgroundColor;
choices.OnColor = Data.TextColor;
choices.AccentColor = Data.AccentColor;
foreach (MMDebugMenuChoiceEntry entry in choices.Choices)
{
if (entry != null)
{
entry.ButtonText.font = Data.RegularFont;
}
}
choices.Select(item.SelectedChoice);
if (triggerEvents)
choices.TriggerButtonEvent(item.SelectedChoice);
choices.transform.SetParent(parent);
break;
case MMDebugMenuItem.MMDebugMenuItemTypes.Value:
MMDebugMenuItemValue value = Instantiate(Data.ValuePrefab);
value.name = "MMDebugMenuItemValue_" + item.Name;
value.LabelText.text = item.ValueLabel;
value.LabelText.color = Data.TextColor;
value.LabelText.font = Data.RegularFont;
value.ValueText.text = item.ValueInitialValue;
value.ValueText.color = Data.AccentColor;
value.ValueText.font = Data.BoldFont;
value.RadioReceiver.Channel = item.ValueMMRadioReceiverChannel;
value.transform.SetParent(parent);
break;
case MMDebugMenuItem.MMDebugMenuItemTypes.Text:
MMDebugMenuItemText textPrefab;
switch (item.TextType)
{
case MMDebugMenuItem.MMDebugMenuItemTextTypes.Tiny:
textPrefab = Data.TextTinyPrefab;
break;
case MMDebugMenuItem.MMDebugMenuItemTextTypes.Small:
textPrefab = Data.TextSmallPrefab;
break;
case MMDebugMenuItem.MMDebugMenuItemTextTypes.Long:
textPrefab = Data.TextLongPrefab;
break;
default:
textPrefab = Data.TextTinyPrefab;
break;
}
MMDebugMenuItemText text = Instantiate(textPrefab);
text.name = "MMDebugMenuItemText_" + item.Name;
text.ContentText.text = item.TextContents;
text.ContentText.color = Data.TextColor;
text.ContentText.font = Data.RegularFont;
text.transform.SetParent(parent);
break;
}
}
// we always add a spacer at the end because scrollviews are terrible
GameObject finalSpacer = Instantiate(Data.SpacerBigPrefab);
finalSpacer.name = "MMDebugMenuItemSpacer_FinalSpacer";
finalSpacer.transform.SetParent(parent);
}
/// <summary>
/// Makes the menu appear
/// </summary>
public virtual void OpenMenu()
{
OnOpenEvent?.Invoke();
StartCoroutine(ToggleCo(false));
}
/// <summary>
/// Makes the menu disappear
/// </summary>
public virtual void CloseMenu()
{
StartCoroutine(ToggleCo(true));
}
/// <summary>
/// Closes or opens the menu depending on its current state
/// </summary>
public virtual void ToggleMenu()
{
StartCoroutine(ToggleCo(Active));
}
/// <summary>
/// A coroutine used to toggle the menu
/// </summary>
/// <param name="active"></param>
/// <returns></returns>
protected virtual IEnumerator ToggleCo(bool active)
{
if (_toggling)
{
yield break;
}
if (!active)
{
OnOpenEvent?.Invoke();
_containerRect.gameObject.SetActive(true);
}
_toggling = true;
Active = active;
_newPosition = active ? _offPosition : _initialContainerPosition;
MMTween.MoveRectTransform(this, _containerRect, _containerRect.localPosition, _newPosition, null, 0f, Data.ToggleDuration, Data.ToggleCurve, ignoreTimescale:true);
yield return MMCoroutine.WaitForUnscaled(Data.ToggleDuration);
if (active)
{
OnCloseEvent?.Invoke();
_containerRect.gameObject.SetActive(false);
}
Active = !active;
_toggling = false;
}
/// <summary>
/// On update we handle our input
/// </summary>
protected virtual void Update()
{
HandleInput();
}
/// <summary>
/// Looks for shortcut input
/// </summary>
protected virtual void HandleInput()
{
bool input = false;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
input = Keyboard.current[Data.ToggleKey].wasPressedThisFrame;
#else
input = Input.GetKeyDown(Data.ToggleShortcut);
#endif
if (input)
{
ToggleMenu();
}
}
/// <summary>
/// Routes console logs to the MMDebugConsole
/// </summary>
/// <param name="logString"></param>
/// <param name="stackTrace"></param>
/// <param name="type"></param>
protected virtual void CaptureConsoleLog(string logString, string stackTrace, LogType type)
{
MMDebug.LogDebugToConsole(logString + " (" + type + ")", "#00FFFF", 3, false);
}
/// <summary>
/// On Enable, we start listening for log messages
/// </summary>
protected virtual void OnEnable()
{
Application.logMessageReceived += CaptureConsoleLog;
}
/// <summary>
/// On Disable, we stop listening for log messages
/// </summary>
protected virtual void OnDisable()
{
Application.logMessageReceived -= CaptureConsoleLog;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 65772fc08a0d9314f86205390e1e772d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,175 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
using UnityEngine.InputSystem;
#endif
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to store and display a reorderable list of menu items
/// </summary>
[Serializable]
public class MMDebugMenuItemList : MMReorderableArray<MMDebugMenuItem>
{
}
[Serializable]
public class MMDebugMenuTabData
{
public string Name = "TabName";
public bool Active = true;
[MMReorderableAttribute]
public MMDebugMenuItemList MenuItems;
}
/// <summary>
/// A class used to store a menu item
/// </summary>
[Serializable]
public class MMDebugMenuItem
{
// EDITOR NAME
public string Name;
public bool Active = true;
public enum MMDebugMenuItemTypes { Title, Spacer, Button, Checkbox, Slider, Text, Value, Choices }
public MMDebugMenuItemTypes Type = MMDebugMenuItemTypes.Title;
// TITLE
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Title)]
public string TitleText = "Title text";
// TEXT
public enum MMDebugMenuItemTextTypes { Tiny, Small, Long }
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Text)]
public MMDebugMenuItemTextTypes TextType = MMDebugMenuItemTextTypes.Tiny;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Text)]
public string TextContents = "Lorem ipsum dolor sit amet";
// CHOICES
public enum MMDebugMenuItemChoicesTypes { TwoChoices, ThreeChoices }
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public MMDebugMenuItemChoicesTypes ChoicesType = MMDebugMenuItemChoicesTypes.TwoChoices;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public string ChoiceOneText;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public string ChoiceOneEventName = "ChoiceOneEvent";
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public string ChoiceTwoText;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public string ChoiceTwoEventName = "ChoiceTwoEvent";
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public string ChoiceThreeText;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public string ChoiceThreeEventName = "ChoiceThreeEvent";
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Choices)]
public int SelectedChoice = 0;
// VALUE
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Value)]
public string ValueLabel = "Value Label";
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Value)]
public string ValueInitialValue = "255";
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Value)]
public int ValueMMRadioReceiverChannel = 0;
// BUTTON
public enum MMDebugMenuItemButtonTypes { Border, Full }
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Button)]
public string ButtonText = "Button text";
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Button)]
public MMDebugMenuItemButtonTypes ButtonType = MMDebugMenuItemButtonTypes.Border;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Button)]
public string ButtonEventName = "Button";
// SPACER
public enum MMDebugMenuItemSpacerTypes { Small, Big }
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Spacer)]
public MMDebugMenuItemSpacerTypes SpacerType = MMDebugMenuItemSpacerTypes.Small;
// CHECKBOX
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Checkbox)]
public string CheckboxText;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Checkbox)]
public bool CheckboxInitialState = false;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Checkbox)]
public string CheckboxEventName = "CheckboxEventName";
// SLIDER
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Slider)]
public MMDebugMenuItemSlider.Modes SliderMode = MMDebugMenuItemSlider.Modes.Float;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Slider)]
public string SliderText;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Slider)]
public float SliderRemapZero = 0f;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Slider)]
public float SliderRemapOne = 1f;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Slider)]
public float SliderInitialValue = 0f;
[MMEnumCondition("Type", (int)MMDebugMenuItemTypes.Slider)]
public string SliderEventName = "Slider";
[MMHidden]
public MMDebugMenuItemSlider TargetSlider;
[MMHidden]
public MMDebugMenuItemButton TargetButton;
[MMHidden]
public MMDebugMenuItemCheckbox TargetCheckbox;
}
/// <summary>
/// A data class used to store the contents of a debug menu
/// </summary>
[CreateAssetMenu(fileName = "MMDebugMenuData", menuName = "MoreMountains/MMDebugMenu/MMDebugMenuData")]
public class MMDebugMenuData : ScriptableObject
{
[Header("Prefabs")]
public MMDebugMenuItemTitle TitlePrefab;
public MMDebugMenuItemButton ButtonPrefab;
public MMDebugMenuItemButton ButtonBorderPrefab;
public MMDebugMenuItemCheckbox CheckboxPrefab;
public MMDebugMenuItemSlider SliderPrefab;
public GameObject SpacerSmallPrefab;
public GameObject SpacerBigPrefab;
public MMDebugMenuItemText TextTinyPrefab;
public MMDebugMenuItemText TextSmallPrefab;
public MMDebugMenuItemText TextLongPrefab;
public MMDebugMenuItemValue ValuePrefab;
public MMDebugMenuItemChoices TwoChoicesPrefab;
public MMDebugMenuItemChoices ThreeChoicesPrefab;
public MMDebugMenuTab TabPrefab;
public MMDebugMenuTabContents TabContentsPrefab;
public RectTransform TabSpacerPrefab;
public MMDebugMenuDebugTab DebugTabPrefab;
public string DebugTabName = "Logs";
[Header("Tabs")]
public List<MMDebugMenuTabData> Tabs;
public bool DisplayDebugTab = true;
public int MaxTabs = 5;
public int InitialActiveTabIndex = 0;
[Header("Toggle")]
public MMDebugMenu.ToggleDirections ToggleDirection = MMDebugMenu.ToggleDirections.RightToLeft;
public float ToggleDuration = 0.2f;
public MMTween.MMTweenCurve ToggleCurve = MMTween.MMTweenCurve.EaseInCubic;
#if ENABLE_INPUT_SYSTEM && !ENABLE_LEGACY_INPUT_MANAGER
public Key ToggleKey = Key.Backquote;
#else
public KeyCode ToggleShortcut = KeyCode.Quote;
#endif
[Header("Style")]
public Font RegularFont;
public Font BoldFont;
public Color BackgroundColor = Color.black;
public Color AccentColor = MMColors.ReunoYellow;
public Color TextColor = Color.white;
}
}

View File

@@ -0,0 +1,47 @@
fileFormatVersion: 2
guid: b950a5ce764708a4ca0425a952fce75f
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- TitlePrefab: {fileID: 2112759074905327847, guid: 80be1ec3d14da9c489fbefa63b82915f,
type: 3}
- ButtonPrefab: {fileID: 7110842687765492728, guid: dbb3e138861cf2040b20217e62a5edf2,
type: 3}
- ButtonBorderPrefab: {fileID: 1985568128000399461, guid: f2be8011322fbf943a44edc64dedbf2c,
type: 3}
- CheckboxPrefab: {fileID: 2731002163667230428, guid: e48b9501c5356cf4e9c390d40d81438c,
type: 3}
- SliderPrefab: {fileID: 8595552693496322647, guid: addcaa6f7df18984691dc300b3be4f7b,
type: 3}
- SpacerSmallPrefab: {fileID: 3952073977153845988, guid: 1a4b9ae95443d5a489bd918c848e2390,
type: 3}
- SpacerBigPrefab: {fileID: 8096383012134595547, guid: f72e7b8c96262ed4d976576afafd53b0,
type: 3}
- TextTinyPrefab: {fileID: 7812354180902260709, guid: 57336066c3d7ff5418ae88b7880aafed,
type: 3}
- TextSmallPrefab: {fileID: 6550416838355534067, guid: 6689802a48b01104ebd8e101f5cce555,
type: 3}
- TextLongPrefab: {fileID: 7073910567540320170, guid: 4332ad3ebf8592c41bc275ff77d24b29,
type: 3}
- ValuePrefab: {fileID: 3610448643810830552, guid: 855a2d614e531f44caecc17a8c3bd51c,
type: 3}
- TwoChoicesPrefab: {fileID: 5258430688713385724, guid: 90a0e72c11dfcbe4f88bccc465c6a0cd,
type: 3}
- ThreeChoicesPrefab: {fileID: 207464785538935126, guid: 804c003da46ec914e80badaf93e6d2da,
type: 3}
- TabPrefab: {fileID: 3232960445196542265, guid: a8296d633c27f554a99bbbf94958722e,
type: 3}
- TabContentsPrefab: {fileID: 2838565908494160927, guid: f2f0b25301bf93e43ac5ecc33208a420,
type: 3}
- TabSpacerPrefab: {fileID: 2188017814106785258, guid: 57633cde530d56a48995d0733efa9450,
type: 3}
- DebugTabPrefab: {fileID: 521718878734460126, guid: 94cfa935aa4cff74a9451b22cb7627a6,
type: 3}
- RegularFont: {fileID: 12800000, guid: 5686e06ef14cf104b8e282ee7c41b9a6, type: 3}
- BoldFont: {fileID: 12800000, guid: ae4e4b833eb9f63448b39edf3f03e309, type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c68de6e839f65554eb79ea21fc34c164
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,65 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to bind a button to a MMDebugMenu
/// </summary>
public class MMDebugMenuItemButton : MonoBehaviour
{
[Header("Bindings")]
/// the associated button
public Button TargetButton;
/// the button's text comp
public Text ButtonText;
/// the button's background image
public Image ButtonBg;
/// the name of the event bound to this button
public string ButtonEventName = "Button";
protected bool _listening = false;
/// <summary>
/// Triggers a button event using the button's event name
/// </summary>
public virtual void TriggerButtonEvent()
{
MMDebugMenuButtonEvent.Trigger(ButtonEventName);
}
protected virtual void OnMMDebugMenuButtonEvent(string checkboxEventName, bool active, MMDebugMenuButtonEvent.EventModes eventMode)
{
if ((eventMode == MMDebugMenuButtonEvent.EventModes.SetButton)
&& (checkboxEventName == ButtonEventName)
&& (TargetButton != null))
{
TargetButton.interactable = active;
}
}
/// <summary>
/// Starts listening for events
/// </summary>
public virtual void OnEnable()
{
if (!_listening)
{
_listening = true;
MMDebugMenuButtonEvent.Register(OnMMDebugMenuButtonEvent);
}
}
/// <summary>
/// Stops listening for events
/// </summary>
public virtual void OnDestroy()
{
_listening = false;
MMDebugMenuButtonEvent.Unregister(OnMMDebugMenuButtonEvent);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4111d7e29da39ee46b807daa22dd3af9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,102 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to bind a checkbox to a MMDebugMenu
/// </summary>
public class MMDebugMenuItemCheckbox : MonoBehaviour
{
[Header("Bindings")]
/// the switch used to display the checkbox
public MMDebugMenuSwitch Switch;
/// the text used to display the checkbox's text
public Text SwitchText;
/// the name of the checkbox event
public string CheckboxEventName = "Checkbox";
protected bool _valueSetThisFrame = false;
protected bool _listening = false;
/// <summary>
/// Triggers an event when the checkbox gets pressed
/// </summary>
public virtual void TriggerCheckboxEvent()
{
if (_valueSetThisFrame)
{
_valueSetThisFrame = false;
return;
}
MMDebugMenuCheckboxEvent.Trigger(CheckboxEventName, Switch.SwitchState, MMDebugMenuCheckboxEvent.EventModes.FromCheckbox);
}
/// <summary>
/// Triggers an event when the checkbox gets checked and becomes true
/// </summary>
public virtual void TriggerCheckboxEventTrue()
{
if (_valueSetThisFrame)
{
_valueSetThisFrame = false;
return;
}
MMDebugMenuCheckboxEvent.Trigger(CheckboxEventName, true, MMDebugMenuCheckboxEvent.EventModes.FromCheckbox);
}
/// <summary>
/// Triggers an event when the checkbox gets unchecked and becomes false
/// </summary>
public virtual void TriggerCheckboxEventFalse()
{
if (_valueSetThisFrame)
{
_valueSetThisFrame = false;
return;
}
MMDebugMenuCheckboxEvent.Trigger(CheckboxEventName, false, MMDebugMenuCheckboxEvent.EventModes.FromCheckbox);
}
protected virtual void OnMMDebugMenuCheckboxEvent(string checkboxEventName, bool value, MMDebugMenuCheckboxEvent.EventModes eventMode)
{
if ((eventMode == MMDebugMenuCheckboxEvent.EventModes.SetCheckbox)
&& (checkboxEventName == CheckboxEventName))
{
_valueSetThisFrame = true;
if (value)
{
Switch.SetTrue();
}
else
{
Switch.SetFalse();
}
}
}
/// <summary>
/// Starts listening for events
/// </summary>
public virtual void OnEnable()
{
if (!_listening)
{
_listening = true;
MMDebugMenuCheckboxEvent.Register(OnMMDebugMenuCheckboxEvent);
}
}
/// <summary>
/// Stops listening for events
/// </summary>
public virtual void OnDestroy()
{
_listening = false;
MMDebugMenuCheckboxEvent.Unregister(OnMMDebugMenuCheckboxEvent);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 28ad17ba84c916d499cb74e758d28e8e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,77 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to store choices contents
/// </summary>
[System.Serializable]
public class MMDebugMenuChoiceEntry
{
/// the button associated to this choice
public Button TargetButton;
/// the text comp used to display the button's text
public Text ButtonText;
/// the button's background image comp
public Image ButtonBg;
/// the name of the event bound to this button
public string ButtonEventName = "ButtonEvent";
}
/// <summary>
/// A class used to bind a Choice menu item to a MMDebugMenu
/// </summary>
public class MMDebugMenuItemChoices : MonoBehaviour
{
[Header("Bindings")]
/// the sprite to use when the button is active
public Sprite SelectedSprite;
/// the sprite to use as bg when the button is inactive
public Sprite OffSprite;
/// the color to use when the button is active
public Color OnColor = Color.white;
/// the color to use when the button is inactive
public Color OffColor = Color.black;
/// the color to use when the button is accented
public Color AccentColor = MMColors.ReunoYellow;
/// a list of choices
public List<MMDebugMenuChoiceEntry> Choices;
/// <summary>
/// Triggers a button event of the selected index
/// </summary>
/// <param name="index"></param>
public virtual void TriggerButtonEvent(int index)
{
MMDebugMenuButtonEvent.Trigger(Choices[index].ButtonEventName);
}
/// <summary>
/// Selects one of the buttons
/// </summary>
/// <param name="index"></param>
public virtual void Select(int index)
{
Deselect();
Choices[index].ButtonBg.sprite = SelectedSprite;
Choices[index].ButtonBg.color = AccentColor;
Choices[index].ButtonText.color = OffColor;
}
/// <summary>
/// Deselects all buttons
/// </summary>
public virtual void Deselect()
{
foreach(MMDebugMenuChoiceEntry entry in Choices)
{
entry.ButtonBg.sprite = OffSprite;
entry.ButtonBg.color = OnColor;
entry.ButtonText.color = OnColor;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 1b2bca3004ee68c45bb99ade8a9e5380
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,139 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to bind a slider to a MMDebugMenu
/// </summary>
public class MMDebugMenuItemSlider : MonoBehaviour
{
/// the possible modes this slider can operate on
public enum Modes { Float, Int }
[Header("Bindings")]
/// the selected mode for this slider
public Modes Mode = Modes.Float;
/// the Slider to use to change the value
public Slider TargetSlider;
/// the text comp used to display the slider's name
public Text SliderText;
/// the text comp used to display the slider's value
public Text SliderValueText;
/// the target knob
public Image SliderKnob;
/// the line behind the knob
public Image SliderLine;
/// the value to remap the slider's 0 to
public float RemapZero = 0f;
/// the value to remap the slider's 1 to
public float RemapOne = 1f;
/// the name of the event bound to this slider
public string SliderEventName = "Checkbox";
/// the current slider value
[MMReadOnly]
public float SliderValue;
/// the current slider int value
[MMReadOnly]
public int SliderValueInt;
protected bool _valueSetThisFrame = false;
protected bool _listening = false;
/// <summary>
/// On Awake we start listening for slider changes
/// </summary>
protected virtual void Awake()
{
TargetSlider.onValueChanged.AddListener(delegate { ValueChangeCheck(); });
}
/// <summary>
/// Invoked when the slider value changes
/// </summary>
public void ValueChangeCheck()
{
if (_valueSetThisFrame)
{
_valueSetThisFrame = false;
return;
}
bool valueChanged = true;
SliderValue = MMMaths.Remap(TargetSlider.value, 0f, 1f, RemapZero, RemapOne);
if (Mode == Modes.Int)
{
SliderValue = Mathf.Round(SliderValue);
if (SliderValue == SliderValueInt)
{
valueChanged = false;
}
SliderValueInt = (int)SliderValue;
}
if (valueChanged)
{
UpdateValue(SliderValue);
}
TriggerSliderEvent(SliderValue);
}
protected virtual void UpdateValue(float newValue)
{
SliderValueText.text = (Mode == Modes.Int) ? newValue.ToString() : newValue.ToString("F3");
}
/// <summary>
/// Triggers a slider event
/// </summary>
/// <param name="value"></param>
protected virtual void TriggerSliderEvent(float value)
{
MMDebugMenuSliderEvent.Trigger(SliderEventName, value, MMDebugMenuSliderEvent.EventModes.FromSlider);
}
/// <summary>
/// When we get a set slider event, we set our value
/// </summary>
/// <param name="sliderEventName"></param>
/// <param name="value"></param>
protected virtual void OnMMDebugMenuSliderEvent(string sliderEventName, float value, MMDebugMenuSliderEvent.EventModes eventMode)
{
if ((eventMode == MMDebugMenuSliderEvent.EventModes.SetSlider)
&& (sliderEventName == SliderEventName))
{
_valueSetThisFrame = true;
TargetSlider.value = MMMaths.Remap(value, RemapZero, RemapOne, 0f, 1f);
UpdateValue(value);
}
}
/// <summary>
/// Starts listening for events
/// </summary>
public virtual void OnEnable()
{
if (!_listening)
{
MMDebugMenuSliderEvent.Register(OnMMDebugMenuSliderEvent);
_listening = true;
}
}
/// <summary>
/// Stops listening for events
/// </summary>
public virtual void OnDestroy()
{
_listening = false;
MMDebugMenuSliderEvent.Unregister(OnMMDebugMenuSliderEvent);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6d8d661dac43a98489944be49a162bda
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to bind a text item to a MMDebugMenu
/// </summary>
public class MMDebugMenuItemText : MonoBehaviour
{
[Header("Bindings")]
/// a text comp used to display the text
[TextArea]
public Text ContentText;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 26996c3ee681f254592c7bbaf459447a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to bind a title item to a MMDebugMenu
/// </summary>
public class MMDebugMenuItemTitle : MonoBehaviour
{
[Header("Bindings")]
/// the text comp used to display the title
public Text TitleText;
/// a line below the title
public Image TitleLine;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: debc95d929132814d968cb0e4c3c8bca
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to bind a value item to a MMDebugMenu
/// </summary>
public class MMDebugMenuItemValue : MonoBehaviour
{
[Header("Bindings")]
/// the label to display next to the value
public Text LabelText;
/// the text comp to display the value with
public Text ValueText;
/// a radio receiver to update the value with
public MMRadioReceiver RadioReceiver;
/// the current level of this value item
public float Level { get { return _level; } set { _level = value; ValueText.text = value.ToString("F2"); } }
protected float _level;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5aecab0d11ad9fe47bd4744bf897a145
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,93 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace MoreMountains.Tools
{
/// <summary>
/// Add this class to a canvas and it'll automatically reposition TouchPrefabs at the position of touches
/// You can set a higher TouchProvision if your game gets more than the default number (6) simultaneous touches
/// Disable/enable this mono for it to stop/work
/// </summary>
public class MMDebugTouchDisplay : MonoBehaviour
{
[Header("Bindings")]
/// the canvas to display the TouchPrefabs on
public Canvas TargetCanvas;
[Header("Touches")]
/// the prefabs to instantiate to signify the position of the touches
public RectTransform TouchPrefab;
/// the amount of these prefabs to pool and provision
public int TouchProvision = 6;
protected List<RectTransform> _touchDisplays;
/// <summary>
/// On Start we initialize our pool
/// </summary>
protected virtual void Start()
{
Initialization();
}
/// <summary>
/// Creates the pool of prefabs
/// </summary>
protected virtual void Initialization()
{
_touchDisplays = new List<RectTransform>();
for (int i = 0; i < TouchProvision; i++)
{
RectTransform touchDisplay = Instantiate(TouchPrefab);
touchDisplay.transform.SetParent(TargetCanvas.transform);
touchDisplay.name = "MMDebugTouchDisplay_" + i;
touchDisplay.gameObject.SetActive(false);
_touchDisplays.Add(touchDisplay);
}
this.enabled = false;
}
/// <summary>
/// On update we detect touches and move our prefabs at their position
/// </summary>
protected virtual void Update()
{
DisableAllDisplays();
DetectTouches();
}
/// <summary>
/// Acts on all touches
/// </summary>
protected virtual void DetectTouches()
{
for (int i = 0; i < Input.touchCount; ++i)
{
_touchDisplays[i].gameObject.SetActive(true);
_touchDisplays[i].position = Input.GetTouch(i).position;
}
}
/// <summary>
/// Disables all touch prefabs
/// </summary>
protected virtual void DisableAllDisplays()
{
foreach(RectTransform display in _touchDisplays)
{
display.gameObject.SetActive(false);
}
}
/// <summary>
/// When this mono gets disabled we turn all our prefabs off
/// </summary>
protected virtual void OnDisable()
{
DisableAllDisplays();
}
}
}

View File

@@ -0,0 +1,14 @@
fileFormatVersion: 2
guid: e41826a58ab20124eab7cfc4d79a1eaa
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences:
- TargetCanvas: {instanceID: 0}
- TouchPrefab: {fileID: 5958022166018464836, guid: 626a9fe06209d574da486d5d818915f2,
type: 3}
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b35e5eebb7959ed4a8a96d7e6fb73e86
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,118 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to handle the display of a debug log tab in a MMDebugMenu
/// </summary>
public class MMDebugMenuDebugTab : MonoBehaviour
{
/// the scrollrect where the log will be displayed
public ScrollRect DebugScrollRect;
/// the text container
public Text DebugText;
/// the prompt input
public InputField CommandPrompt;
/// a decorative prompt character
public Text CommandPromptCharacter;
/// whether or not the touch screen is visible
public bool TouchScreenVisible = false;
protected TouchScreenKeyboard _touchScreenKeyboard;
protected RectTransform _rectTransform;
protected float _mobileMenuOffset = -1000f;
protected bool _touchScreenVisibleLastFrame;
/// <summary>
/// On awake we prepare our prompt listener
/// </summary>
protected virtual void Awake()
{
MMDebug.MMDebugLogEvent.Register(OnMMDebugLogEvent);
DebugText.text = "";
_rectTransform = this.gameObject.GetComponent<RectTransform>();
CommandPrompt.onEndEdit.AddListener(val =>
{
CommandPrompt.text = "";
if (val != "")
{
MMDebug.DebugLogCommand(val);
}
});
}
/// <summary>
/// if the mobile touchscreen is open, we move away
/// </summary>
protected virtual void Update()
{
TouchScreenVisible = TouchScreenKeyboard.visible;
if (TouchScreenVisible)
{
_rectTransform.MMSetBottom(650f);
}
else
{
_rectTransform.MMSetBottom(0f);
}
}
/// <summary>
/// on late update we scroll to the bottom if needed
/// </summary>
protected virtual void LateUpdate()
{
if (_touchScreenVisibleLastFrame != TouchScreenVisible)
{
StartCoroutine(ScrollToLogBottomCo());
}
_touchScreenVisibleLastFrame = TouchScreenVisible;
}
/// <summary>
/// Scrolls to the bottom on enable
/// </summary>
protected virtual void OnEnable()
{
StartCoroutine(ScrollToLogBottomCo());
}
/// <summary>
/// when we get a new log event, we update our text and scroll to the bottom
/// </summary>
/// <param name="item"></param>
protected virtual void OnMMDebugLogEvent(MMDebug.DebugLogItem item)
{
DebugText.text = MMDebug.LogHistoryText;
if (this.gameObject.activeInHierarchy)
{
StartCoroutine(ScrollToLogBottomCo());
}
}
/// <summary>
/// A coroutine used to scroll to the bottom
/// </summary>
/// <returns></returns>
protected virtual IEnumerator ScrollToLogBottomCo()
{
yield return new WaitForEndOfFrame();
DebugScrollRect.normalizedPosition = Vector2.zero;
CommandPrompt.ActivateInputField();
CommandPrompt.Select();
}
/// <summary>
/// Stops listening for events
/// </summary>
public virtual void OnDestroy()
{
MMDebug.MMDebugLogEvent.Unregister(OnMMDebugLogEvent);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5f28e9eb155c32542978f8e9ecbc19f3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,70 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to handle the display of a tab in a MMDebugMenu
/// </summary>
public class MMDebugMenuTab : MonoBehaviour
{
/// the tab's title
public Text TabText;
/// the tab's background image
public Image TabBackground;
/// the color to use for the background when the tab is selected
public Color SelectedBackgroundColor;
/// the color to use for the background when the tab is not selected
public Color DeselectedBackgroundColor;
/// the color to use for the text when the tab is selected
public Color SelectedTextColor;
/// the color to use for the text when the tab is not selected
public Color DeselectedTextColor;
/// the index of that tab, auto setup by the manager
public int Index;
/// the manager for this tab, auto setup
public MMDebugMenuTabManager Manager;
/// if this is true, scale will be forced to one on init
public bool ForceScaleOne = true;
/// <summary>
/// On Start we initialize this tab item
/// </summary>
protected virtual void Start()
{
Initialization();
}
/// <summary>
/// On init we force the scale to one
/// </summary>
protected virtual void Initialization()
{
if (ForceScaleOne)
{
this.gameObject.GetComponent<RectTransform>().localScale = Vector3.one;
}
}
/// <summary>
/// Selects this tab
/// </summary>
public virtual void Select()
{
Manager.Select(Index);
TabText.color = SelectedTextColor;
TabBackground.color = SelectedBackgroundColor;
}
/// <summary>
/// Deselects this tab
/// </summary>
public virtual void Deselect()
{
TabText.color = DeselectedTextColor;
TabBackground.color = DeselectedBackgroundColor;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 5fe2233d73fc8b7449e98cbeb826216a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,39 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to describe tab contents
/// </summary>
public class MMDebugMenuTabContents : MonoBehaviour
{
/// the index of the tab, setup by MMDebugMenu
public int Index = 0;
/// the parent of the tab, setup by MMDebugMenu
public Transform Parent;
/// if this is true, scale will be forced to one on init
public bool ForceScaleOne = true;
/// <summary>
/// On Start we initialize this tab contents
/// </summary>
protected virtual void Start()
{
Initialization();
}
/// <summary>
/// On init we force the scale to one
/// </summary>
protected virtual void Initialization()
{
if (ForceScaleOne)
{
this.gameObject.GetComponent<RectTransform>().localScale = Vector3.one;
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d72d65b4a360e184da7662f4f4c6acc0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,44 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class used to keep track of tabs and their contents in a MMDebugMenu
/// </summary>
public class MMDebugMenuTabManager : MonoBehaviour
{
/// a list of all the tabs under that manager
public List<MMDebugMenuTab> Tabs;
/// a list of all the tabs contents under that manager
public List<MMDebugMenuTabContents> TabsContents;
/// <summary>
/// Selects a tab, hides the others
/// </summary>
/// <param name="selected"></param>
public virtual void Select(int selected)
{
foreach(MMDebugMenuTab tab in Tabs)
{
if (tab.Index != selected)
{
tab.Deselect();
}
}
foreach(MMDebugMenuTabContents contents in TabsContents)
{
if (contents.Index == selected)
{
contents.gameObject.SetActive(true);
}
else
{
contents.gameObject.SetActive(false);
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 6caabe887d9340e4cae45cc9f41897dc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ea78b83e8173dc24e884ce1186c14ac7
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,63 @@
using UnityEngine;
using System.Collections;
using System;
using MoreMountains.Tools;
using UnityEngine.UI;
using System.Collections.Generic;
namespace MoreMountains.Tools
{
/// <summary>
/// A class to handle radio buttons.
/// To group them, just use the same RadioButtonGroupName string for all radio buttons in the group
/// </summary>
public class MMDebugMenuRadioButton : MMDebugMenuSpriteReplace
{
/// The name of the radio button group. Use the same one for each buttons in the group
public string RadioButtonGroupName;
protected List<MMDebugMenuRadioButton> _group;
/// <summary>
/// On Init, we grab all buttons from the group
/// </summary>
public override void Initialization()
{
base.Initialization ();
FindAllRadioButtonsFromTheSameGroup ();
}
/// <summary>
/// Finds all radio buttons from the same group.
/// </summary>
protected virtual void FindAllRadioButtonsFromTheSameGroup ()
{
_group = new List<MMDebugMenuRadioButton> ();
MMDebugMenuRadioButton[] radioButtons = FindObjectsOfType(typeof(MMDebugMenuRadioButton)) as MMDebugMenuRadioButton[];
foreach (MMDebugMenuRadioButton radioButton in radioButtons)
{
if ((radioButton.RadioButtonGroupName == RadioButtonGroupName)
&& (radioButton != this))
{
_group.Add (radioButton);
}
}
}
/// <summary>
/// When turning the button on, we turn off all other buttons in the group
/// </summary>
protected override void SpriteOn()
{
base.SpriteOn ();
if (_group.Count >= 1)
{
foreach (MMDebugMenuRadioButton radioButton in _group)
{
radioButton.SwitchToOffSprite ();
}
}
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 17217ce8411bdf240a5e6ab4b8ad0a65
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,112 @@
using UnityEngine;
using System.Collections;
using System;
using MoreMountains.Tools;
using UnityEngine.UI;
namespace MoreMountains.Tools
{
/// <summary>
/// A class to add to an image to have it act like a button with a different sprite for on and off states
/// </summary>
public class MMDebugMenuSpriteReplace : MonoBehaviour
{
/// the sprite to use when in the "on" state
public Sprite OnSprite;
/// the sprite to use when in the "off" state
public Sprite OffSprite;
/// if this is true, the button will start if "on" state
public bool StartsOn = true;
/// the current state of the button
public bool CurrentValue { get { return (_image.sprite == OnSprite); } }
protected Image _image;
protected MMTouchButton _mmTouchButton;
/// <summary>
/// On Start we initialize our button
/// </summary>
protected virtual void Awake()
{
//Initialization ();
}
/// <summary>
/// On init, we grab our image component, and set our sprite in its initial state
/// </summary>
public virtual void Initialization()
{
_image = this.gameObject.GetComponent<Image> ();
_mmTouchButton = this.gameObject.GetComponent<MMTouchButton> ();
if (_mmTouchButton != null)
{
_mmTouchButton.ReturnToInitialSpriteAutomatically = false;
}
if (_image == null) { return; }
if ((OnSprite == null) || (OffSprite == null)) { return; }
if (StartsOn)
{
_image.sprite = OnSprite;
}
else
{
_image.sprite = OffSprite;
}
}
/// <summary>
/// A public method to change the sprite
/// </summary>
public virtual void Swap()
{
if (_image.sprite != OnSprite)
{
SwitchToOnSprite ();
}
else
{
SwitchToOffSprite ();
}
}
/// <summary>
/// a public method to switch to off sprite directly
/// </summary>
public virtual void SwitchToOffSprite()
{
if (_image == null) { return; }
if (OffSprite == null) { return; }
SpriteOff ();
}
/// <summary>
/// sets the image's sprite to off
/// </summary>
protected virtual void SpriteOff()
{
_image.sprite = OffSprite;
}
/// <summary>
/// a public method to switch to on sprite directly
/// </summary>
public virtual void SwitchToOnSprite()
{
if (_image == null) { return; }
if (OnSprite == null) { return; }
SpriteOn ();
}
/// <summary>
/// sets the image's sprite to on
/// </summary>
protected virtual void SpriteOn()
{
_image.sprite = OnSprite;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 67c3b5deddd7fd5438aebce3a8ea178e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,109 @@
using UnityEngine;
using System.Collections;
using System;
using MoreMountains.Tools;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine.Events;
namespace MoreMountains.Tools
{
/// <summary>
/// A component to handle switches
/// </summary>
public class MMDebugMenuSwitch : MMTouchButton
{
[Header("Switch")]
/// a SpriteReplace to represent the switch knob
public MMDebugMenuSpriteReplace SwitchKnob;
/// the possible states of the switch
[MMReadOnly]
public bool SwitchState;
/// the state the switch should start in
public bool InitialState = false;
[Header("Binding")]
/// the methods to call when the switch is turned on
public UnityEvent OnSwitchOn;
/// the methods to call when the switch is turned off
public UnityEvent OnSwitchOff;
/// the methods to call when the switch is turned off
public UnityEvent<bool> OnSwitchToggle;
/// <summary>
/// On init, we set our current switch state
/// </summary>
protected override void Initialization()
{
base.Initialization ();
SwitchState = InitialState;
InitializeState ();
SwitchKnob.Initialization();
if (InitialState)
{
SwitchKnob.SwitchToOnSprite();
}
else
{
SwitchKnob.SwitchToOffSprite();
}
}
public virtual void InitializeState()
{
/*if (CurrentSwitchState == SwitchStates.Left)
{
_animator?.Play ("RollLeft");
}
else
{
_animator?.Play ("RollRight");
}*/
}
public virtual void SetTrue()
{
SwitchState = true;
if (_animator != null)
{
_animator.SetTrigger("Right");
}
SwitchKnob.SwitchToOnSprite();
if (OnSwitchOn != null)
{
OnSwitchOn.Invoke();
}
}
public virtual void SetFalse()
{
SwitchState = false;
if (_animator != null)
{
_animator.SetTrigger("Left");
}
SwitchKnob.SwitchToOffSprite();
if (OnSwitchOff != null)
{
OnSwitchOff.Invoke();
}
}
/// <summary>
/// Use this method to go from one state to the other
/// </summary>
public virtual void ToggleState()
{
if (SwitchState == false)
{
SetTrue();
}
else
{
SetFalse();
}
OnSwitchToggle?.Invoke(SwitchState);
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 752e7f2cbc3684a4ca1c13a049c09d5d
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: