chore: initial commit
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
#if MM_UI
|
||||
using System.Collections;
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5f28e9eb155c32542978f8e9ecbc19f3
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,70 @@
|
||||
#if MM_UI
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5fe2233d73fc8b7449e98cbeb826216a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,39 @@
|
||||
#if MM_UI
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d72d65b4a360e184da7662f4f4c6acc0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,45 @@
|
||||
#if MM_UI
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6caabe887d9340e4cae45cc9f41897dc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user