chore: initial commit
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fb7575f8c305d244ba40b4b661d997c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2313508e7b935c54d9877ca20548a1b5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d039e33a2be33f14e98835c8a207cc1d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9091b3d5ef7624b47a328c984fa25e09
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e815f28291646fc47a4ea53fa52db2a4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 186a986c8de07d3478b88dc10e508869
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user