提交Unity 联机Pro

This commit is contained in:
PC-20230316NUNE\Administrator
2024-08-17 14:27:18 +08:00
parent f00193b000
commit 894100ae37
7448 changed files with 854473 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 50d86929c58b07248aadea9a99dc350d
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,112 @@
namespace SRDebugger.UI.Controls
{
using System;
using Services;
using SRF;
using SRF.UI;
using SRF.UI.Layout;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof (RectTransform))]
public class ConsoleEntryView : SRMonoBehaviourEx, IVirtualView
{
public const string ConsoleBlobInfo = "Console_Info_Blob";
public const string ConsoleBlobWarning = "Console_Warning_Blob";
public const string ConsoleBlobError = "Console_Error_Blob";
private int _count;
private bool _hasCount;
private ConsoleEntry _prevData;
private RectTransform _rectTransform;
[RequiredField] public Text Count;
[RequiredField] public CanvasGroup CountContainer;
[RequiredField] public StyleComponent ImageStyle;
[RequiredField] public Text Message;
[RequiredField] public Text StackTrace;
public void SetDataContext(object data)
{
var msg = data as ConsoleEntry;
if (msg == null)
{
throw new Exception("Data should be a ConsoleEntry");
}
// Always check for updates on "Count", as it can change
if (msg.Count > 1)
{
if (!_hasCount)
{
CountContainer.alpha = 1f;
_hasCount = true;
}
if (msg.Count != _count)
{
Count.text = Internal.SRDebuggerUtil.GetNumberString(msg.Count, 999, "999+");
_count = msg.Count;
}
}
else if (_hasCount)
{
CountContainer.alpha = 0f;
_hasCount = false;
}
// Only update everything else if data context has changed, not just for an update
if (msg == _prevData)
{
return;
}
_prevData = msg;
Message.text = msg.MessagePreview;
StackTrace.text = msg.StackTracePreview;
if (string.IsNullOrEmpty(StackTrace.text))
{
Message.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 2,
_rectTransform.rect.height - 4);
}
else
{
Message.rectTransform.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 12,
_rectTransform.rect.height - 14);
}
switch (msg.LogType)
{
case LogType.Log:
ImageStyle.StyleKey = ConsoleBlobInfo;
break;
case LogType.Warning:
ImageStyle.StyleKey = ConsoleBlobWarning;
break;
case LogType.Exception:
case LogType.Assert:
case LogType.Error:
ImageStyle.StyleKey = ConsoleBlobError;
break;
}
}
protected override void Awake()
{
base.Awake();
_rectTransform = CachedTransform as RectTransform;
CountContainer.alpha = 0f;
Message.supportRichText = Settings.Instance.RichTextInConsole;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c214ec24a4baf1a4f828768a9795f241
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,196 @@

#pragma warning disable 169
#pragma warning disable 649
namespace SRDebugger.UI.Controls
{
using System;
using System.Collections;
using Internal;
using Services;
using SRF;
using SRF.UI.Layout;
using UnityEngine;
using UnityEngine.UI;
public class ConsoleLogControl : SRMonoBehaviourEx
{
[RequiredField] [SerializeField] private VirtualVerticalLayoutGroup _consoleScrollLayoutGroup;
[RequiredField] [SerializeField] private ScrollRect _consoleScrollRect;
private bool _isDirty;
private Vector2? _scrollPosition;
private bool _showErrors = true;
private bool _showInfo = true;
private bool _showWarnings = true;
public Action<ConsoleEntry> SelectedItemChanged;
private string _filter;
public bool ShowErrors
{
get { return _showErrors; }
set
{
_showErrors = value;
SetIsDirty();
}
}
public bool ShowWarnings
{
get { return _showWarnings; }
set
{
_showWarnings = value;
SetIsDirty();
}
}
public bool ShowInfo
{
get { return _showInfo; }
set
{
_showInfo = value;
SetIsDirty();
}
}
public bool EnableSelection
{
get { return _consoleScrollLayoutGroup.EnableSelection; }
set { _consoleScrollLayoutGroup.EnableSelection = value; }
}
public string Filter
{
get { return _filter; }
set {
if (_filter != value)
{
_filter = value;
_isDirty = true;
}
}
}
protected override void Awake()
{
base.Awake();
_consoleScrollLayoutGroup.SelectedItemChanged.AddListener(OnSelectedItemChanged);
Service.Console.Updated += ConsoleOnUpdated;
}
protected override void Start()
{
base.Start();
SetIsDirty();
StartCoroutine(ScrollToBottom());
}
IEnumerator ScrollToBottom()
{
yield return new WaitForEndOfFrame();
yield return new WaitForEndOfFrame();
yield return new WaitForEndOfFrame();
_scrollPosition = new Vector2(0,0);
}
protected override void OnDestroy()
{
if (Service.Console != null)
{
Service.Console.Updated -= ConsoleOnUpdated;
}
base.OnDestroy();
}
private void OnSelectedItemChanged(object arg0)
{
var entry = arg0 as ConsoleEntry;
if (SelectedItemChanged != null)
{
SelectedItemChanged(entry);
}
}
protected override void Update()
{
base.Update();
if (_scrollPosition.HasValue)
{
_consoleScrollRect.normalizedPosition = _scrollPosition.Value;
_scrollPosition = null;
}
if (_isDirty)
{
Refresh();
}
}
private void Refresh()
{
if (_consoleScrollRect.normalizedPosition.y < 0.01f)
{
_scrollPosition = _consoleScrollRect.normalizedPosition;
}
_consoleScrollLayoutGroup.ClearItems();
var entries = Service.Console.Entries;
for (var i = 0; i < entries.Count; i++)
{
var e = entries[i];
if ((e.LogType == LogType.Error || e.LogType == LogType.Exception || e.LogType == LogType.Assert) &&
!ShowErrors)
{
if (e == _consoleScrollLayoutGroup.SelectedItem) _consoleScrollLayoutGroup.SelectedItem = null;
continue;
}
if (e.LogType == LogType.Warning && !ShowWarnings)
{
if (e == _consoleScrollLayoutGroup.SelectedItem) _consoleScrollLayoutGroup.SelectedItem = null;
continue;
}
if (e.LogType == LogType.Log && !ShowInfo)
{
if (e == _consoleScrollLayoutGroup.SelectedItem) _consoleScrollLayoutGroup.SelectedItem = null;
continue;
}
if (!string.IsNullOrEmpty(Filter))
{
if (e.Message.IndexOf(Filter, StringComparison.OrdinalIgnoreCase) < 0)
{
if (e == _consoleScrollLayoutGroup.SelectedItem) _consoleScrollLayoutGroup.SelectedItem = null;
continue;
}
}
_consoleScrollLayoutGroup.AddItem(e);
}
_isDirty = false;
}
private void SetIsDirty()
{
_isDirty = true;
}
private void ConsoleOnUpdated(IConsoleService console)
{
SetIsDirty();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 413376b74a5948a4db9e0a5c9c002724
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: b5fd2859be59fd34c83def152a20f905
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,52 @@
namespace SRDebugger.UI.Controls.Data
{
using System;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class ActionControl : OptionsControlBase
{
private SRF.Helpers.MethodReference _method;
[RequiredField] public UnityEngine.UI.Button Button;
[RequiredField] public Text Title;
public SRF.Helpers.MethodReference Method
{
get { return _method; }
}
protected override void Start()
{
base.Start();
Button.onClick.AddListener(ButtonOnClick);
}
private void ButtonOnClick()
{
if (_method == null)
{
Debug.LogWarning("[SRDebugger.Options] No method set for action control", this);
return;
}
try
{
_method.Invoke(null);
}
catch (Exception e)
{
Debug.LogError("[SRDebugger] Exception thrown while executing action.");
Debug.LogException(e);
}
}
public void SetMethod(string methodName, SRF.Helpers.MethodReference method)
{
_method = method;
Title.text = methodName;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6c637c8d0d16d024fa920dda64fb38db
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,44 @@
namespace SRDebugger.UI.Controls.Data
{
using System;
using SRF;
using UnityEngine.UI;
public class BoolControl : DataBoundControl
{
[RequiredField] public Text Title;
[RequiredField] public Toggle Toggle;
protected override void Start()
{
base.Start();
Toggle.onValueChanged.AddListener(ToggleOnValueChanged);
}
private void ToggleOnValueChanged(bool isOn)
{
UpdateValue(isOn);
}
protected override void OnBind(string propertyName, Type t)
{
base.OnBind(propertyName, t);
Title.text = propertyName;
Toggle.interactable = !IsReadOnly;
}
protected override void OnValueUpdated(object newValue)
{
var value = (bool) newValue;
Toggle.isOn = value;
}
public override bool CanBind(Type type, bool isReadOnly)
{
return type == typeof (bool);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 645dcae76b625be40b595e4bbc27abb6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,131 @@
namespace SRDebugger.UI.Controls
{
using System;
using UnityEngine;
using SRF.Helpers;
public abstract class DataBoundControl : OptionsControlBase
{
private bool _hasStarted;
private bool _isReadOnly;
private object _prevValue;
private SRF.Helpers.PropertyReference _prop;
public SRF.Helpers.PropertyReference Property
{
get { return _prop; }
}
public bool IsReadOnly
{
get { return _isReadOnly; }
}
public string PropertyName { get; private set; }
#region Data Binding
public void Bind(string propertyName, SRF.Helpers.PropertyReference prop)
{
PropertyName = propertyName;
_prop = prop;
_isReadOnly = !prop.CanWrite;
prop.ValueChanged += OnValueChanged;
OnBind(propertyName, prop.PropertyType);
Refresh();
}
private void OnValueChanged(PropertyReference property)
{
Refresh();
}
protected void UpdateValue(object newValue)
{
if (newValue == _prevValue)
{
return;
}
if (IsReadOnly)
{
return;
}
_prop.SetValue(newValue);
_prevValue = newValue;
}
public override void Refresh()
{
if (_prop == null)
{
return;
}
var currentValue = _prop.GetValue();
if (currentValue != _prevValue)
{
try
{
OnValueUpdated(currentValue);
}
catch (Exception e)
{
Debug.LogError("[SROptions] Error refreshing binding.");
Debug.LogException(e);
}
}
_prevValue = currentValue;
}
protected virtual void OnBind(string propertyName, Type t) {}
protected abstract void OnValueUpdated(object newValue);
public abstract bool CanBind(Type type, bool isReadOnly);
#endregion
#region Unity
protected override void Start()
{
base.Start();
Refresh();
_hasStarted = true;
}
protected override void OnEnable()
{
base.OnEnable();
if (_hasStarted)
{
if (_prop != null)
{
_prop.ValueChanged += OnValueChanged;
}
Refresh();
}
}
protected override void OnDisable()
{
base.OnDisable();
if (_prop != null)
{
_prop.ValueChanged -= OnValueChanged;
}
}
#endregion
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5f319c80d34ef2e4590641a136c82f1e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,109 @@
// ReSharper disable once RedundantUsingDirective
using System.Reflection;
namespace SRDebugger.UI.Controls.Data
{
using System;
using SRF;
using SRF.UI;
using UnityEngine;
using UnityEngine.UI;
public class EnumControl : DataBoundControl
{
private object _lastValue;
private string[] _names;
private Array _values;
[RequiredField] public LayoutElement ContentLayoutElement;
public GameObject[] DisableOnReadOnly;
[RequiredField] public SRSpinner Spinner;
[RequiredField] public Text Title;
[RequiredField] public Text Value;
protected override void Start()
{
base.Start();
}
protected override void OnBind(string propertyName, Type t)
{
base.OnBind(propertyName, t);
Title.text = propertyName;
Spinner.interactable = !IsReadOnly;
if (DisableOnReadOnly != null)
{
foreach (var child in DisableOnReadOnly)
{
child.SetActive(!IsReadOnly);
}
}
_names = Enum.GetNames(t);
_values = Enum.GetValues(t);
var longestName = "";
for (var i = 0; i < _names.Length; i++)
{
if (_names[i].Length > longestName.Length)
{
longestName = _names[i];
}
}
if (_names.Length == 0)
{
return;
}
// Set preferred width of content to the largest possible value size
var width = Value.cachedTextGeneratorForLayout.GetPreferredWidth(longestName,
Value.GetGenerationSettings(new Vector2(float.MaxValue, Value.preferredHeight)));
ContentLayoutElement.preferredWidth = width;
}
protected override void OnValueUpdated(object newValue)
{
_lastValue = newValue;
Value.text = newValue.ToString();
LayoutRebuilder.MarkLayoutForRebuild(GetComponent<RectTransform>());
}
public override bool CanBind(Type type, bool isReadOnly)
{
#if NETFX_CORE
return type.GetTypeInfo().IsEnum;
#else
return type.IsEnum;
#endif
}
private void SetIndex(int i)
{
UpdateValue(_values.GetValue(i));
Refresh();
}
public void GoToNext()
{
var currentIndex = Array.IndexOf(_values, _lastValue);
SetIndex(SRMath.Wrap(_values.Length, currentIndex + 1));
}
public void GoToPrevious()
{
var currentIndex = Array.IndexOf(_values, _lastValue);
SetIndex(SRMath.Wrap(_values.Length, currentIndex - 1));
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3b7f14311f0b3f442b273192dc8ffe4d
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,200 @@
using System.Globalization;
namespace SRDebugger.UI.Controls.Data
{
using System;
using System.Collections.Generic;
using SRF;
using SRF.UI;
using UnityEngine;
using UnityEngine.UI;
public class NumberControl : DataBoundControl
{
private static readonly Type[] IntegerTypes =
{
typeof (int), typeof (short), typeof (byte), typeof (sbyte), typeof (uint), typeof (ushort)
};
private static readonly Type[] DecimalTypes =
{
typeof (float), typeof (double)
};
public static readonly Dictionary<Type, ValueRange> ValueRanges = new Dictionary<Type, ValueRange>
{
{typeof (int), new ValueRange {MaxValue = int.MaxValue, MinValue = int.MinValue}},
{typeof (short), new ValueRange {MaxValue = short.MaxValue, MinValue = short.MinValue}},
{typeof (byte), new ValueRange {MaxValue = byte.MaxValue, MinValue = byte.MinValue}},
{typeof (sbyte), new ValueRange {MaxValue = sbyte.MaxValue, MinValue = sbyte.MinValue}},
{typeof (uint), new ValueRange {MaxValue = uint.MaxValue, MinValue = uint.MinValue}},
{typeof (ushort), new ValueRange {MaxValue = ushort.MaxValue, MinValue = ushort.MinValue}},
{typeof (float), new ValueRange {MaxValue = float.MaxValue, MinValue = float.MinValue}},
{typeof (double), new ValueRange {MaxValue = double.MaxValue, MinValue = double.MinValue}}
};
private string _lastValue;
private Type _type;
public GameObject[] DisableOnReadOnly;
public SRNumberButton DownNumberButton;
[RequiredField] public SRNumberSpinner NumberSpinner;
[RequiredField] public Text Title;
public SRNumberButton UpNumberButton;
protected override void Start()
{
base.Start();
NumberSpinner.onEndEdit.AddListener(OnValueChanged);
}
private void OnValueChanged(string newValue)
{
try
{
var num = Convert.ChangeType(newValue, _type, CultureInfo.InvariantCulture);
UpdateValue(num);
}
catch (Exception)
{
NumberSpinner.text = _lastValue;
}
LayoutRebuilder.MarkLayoutForRebuild(GetComponent<RectTransform>());
}
protected override void OnBind(string propertyName, Type t)
{
base.OnBind(propertyName, t);
Title.text = propertyName;
if (IsIntegerType(t))
{
NumberSpinner.contentType = InputField.ContentType.IntegerNumber;
}
else if (IsDecimalType(t))
{
NumberSpinner.contentType = InputField.ContentType.DecimalNumber;
}
else
{
throw new ArgumentException("Type must be one of expected types", "t");
}
var rangeAttrib = Property.GetAttribute<NumberRangeAttribute>();
NumberSpinner.MaxValue = GetMaxValue(t);
NumberSpinner.MinValue = GetMinValue(t);
if (rangeAttrib != null)
{
NumberSpinner.MaxValue = Math.Min(rangeAttrib.Max, NumberSpinner.MaxValue);
NumberSpinner.MinValue = Math.Max(rangeAttrib.Min, NumberSpinner.MinValue);
}
var incrementAttribute = Property.GetAttribute<IncrementAttribute>();
if (incrementAttribute != null)
{
if (UpNumberButton != null)
{
UpNumberButton.Amount = incrementAttribute.Increment;
}
if (DownNumberButton != null)
{
DownNumberButton.Amount = -incrementAttribute.Increment;
}
}
_type = t;
NumberSpinner.interactable = !IsReadOnly;
if (DisableOnReadOnly != null)
{
foreach (var childControl in DisableOnReadOnly)
{
childControl.SetActive(!IsReadOnly);
}
}
}
protected override void OnValueUpdated(object newValue)
{
var value = Convert.ToDecimal(newValue, CultureInfo.InvariantCulture).ToString(CultureInfo.InvariantCulture);
if (value != _lastValue)
{
NumberSpinner.text = value;
}
_lastValue = value;
}
public override bool CanBind(Type type, bool isReadOnly)
{
return IsDecimalType(type) || IsIntegerType(type);
}
protected static bool IsIntegerType(Type t)
{
for (var i = 0; i < IntegerTypes.Length; i++)
{
if (IntegerTypes[i] == t)
{
return true;
}
}
return false;
}
protected static bool IsDecimalType(Type t)
{
for (var i = 0; i < DecimalTypes.Length; i++)
{
if (DecimalTypes[i] == t)
{
return true;
}
}
return false;
}
protected double GetMaxValue(Type t)
{
ValueRange value;
if (ValueRanges.TryGetValue(t, out value))
{
return value.MaxValue;
}
Debug.LogWarning("[NumberControl] No MaxValue stored for type {0}".Fmt(t));
return double.MaxValue;
}
protected double GetMinValue(Type t)
{
ValueRange value;
if (ValueRanges.TryGetValue(t, out value))
{
return value.MinValue;
}
Debug.LogWarning("[NumberControl] No MinValue stored for type {0}".Fmt(t));
return double.MinValue;
}
public struct ValueRange
{
public double MaxValue;
public double MinValue;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4a6d9f7214a7c5e4b868bfc520d92799
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,74 @@
namespace SRDebugger.UI.Controls
{
using Internal;
using SRF;
using UnityEngine.UI;
public abstract class OptionsControlBase : SRMonoBehaviourEx
{
private bool _selectionModeEnabled;
[RequiredField] public Toggle SelectionModeToggle;
public OptionDefinition Option;
public bool SelectionModeEnabled
{
get { return _selectionModeEnabled; }
set
{
if (value == _selectionModeEnabled)
{
return;
}
_selectionModeEnabled = value;
SelectionModeToggle.gameObject.SetActive(_selectionModeEnabled);
if (SelectionModeToggle.graphic != null)
{
SelectionModeToggle.graphic.CrossFadeAlpha(IsSelected ? _selectionModeEnabled ? 1.0f : 0.2f : 0f, 0,
true);
}
}
}
public bool IsSelected
{
get { return SelectionModeToggle.isOn; }
set
{
SelectionModeToggle.isOn = value;
if (SelectionModeToggle.graphic != null)
{
SelectionModeToggle.graphic.CrossFadeAlpha(value ? _selectionModeEnabled ? 1.0f : 0.2f : 0f, 0, true);
}
}
}
protected override void Awake()
{
base.Awake();
IsSelected = false;
SelectionModeToggle.gameObject.SetActive(false);
}
protected override void OnEnable()
{
base.OnEnable();
// Reapply selection indicator alpha (is reset when disabled / reenabled)
if (SelectionModeToggle.graphic != null)
{
SelectionModeToggle.graphic.CrossFadeAlpha(IsSelected ? _selectionModeEnabled ? 1.0f : 0.2f : 0f, 0,
true);
}
}
public virtual void Refresh() {}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ff04c6750fdb3b744ac19818a2425666
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,36 @@
namespace SRDebugger.UI.Controls.Data
{
using System;
using SRF;
using UnityEngine.UI;
public class ReadOnlyControl : DataBoundControl
{
[RequiredField]
public Text ValueText;
[RequiredField]
public Text Title;
protected override void Start()
{
base.Start();
}
protected override void OnBind(string propertyName, Type t)
{
base.OnBind(propertyName, t);
Title.text = propertyName;
}
protected override void OnValueUpdated(object newValue)
{
ValueText.text = Convert.ToString(newValue);
}
public override bool CanBind(Type type, bool isReadOnly)
{
return type == typeof(string) && isReadOnly;
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 41b5dbc85a74ae84dbb6c6685e1151fc
timeCreated: 1466683332
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,47 @@
namespace SRDebugger.UI.Controls.Data
{
using System;
using SRF;
using UnityEngine.UI;
public class StringControl : DataBoundControl
{
[RequiredField] public InputField InputField;
[RequiredField] public Text Title;
protected override void Start()
{
base.Start();
#if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2
InputField.onValueChange.AddListener(OnValueChanged);
#else
InputField.onValueChanged.AddListener(OnValueChanged);
#endif
}
private void OnValueChanged(string newValue)
{
UpdateValue(newValue);
}
protected override void OnBind(string propertyName, Type t)
{
base.OnBind(propertyName, t);
Title.text = propertyName;
InputField.text = "";
InputField.interactable = !IsReadOnly;
}
protected override void OnValueUpdated(object newValue)
{
var value = newValue == null ? "" : (string) newValue;
InputField.text = value;
}
public override bool CanBind(Type type, bool isReadOnly)
{
return type == typeof (string) && !isReadOnly;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 019f81638c7cf1f438569f1ca9def175
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,12 @@
namespace SRDebugger.UI.Controls
{
using SRF;
using UnityEngine.UI;
public class InfoBlock : SRMonoBehaviourEx
{
[RequiredField] public Text Content;
[RequiredField] public Text Title;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3214a2a17debe0c489148429ec9a37b2
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,30 @@
namespace SRDebugger.UI.Controls
{
using UnityEngine;
using UnityEngine.EventSystems;
public class MultiTapButton : UnityEngine.UI.Button
{
private float _lastTap;
private int _tapCount;
public int RequiredTapCount = 3;
public float ResetTime = 0.5f;
public override void OnPointerClick(PointerEventData eventData)
{
if (Time.unscaledTime - _lastTap > ResetTime)
{
_tapCount = 0;
}
_lastTap = Time.unscaledTime;
_tapCount++;
if (_tapCount == RequiredTapCount)
{
base.OnPointerClick(eventData);
_tapCount = 0;
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: abc57d317f579f2459ba7317f386ecf3
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,214 @@
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace SRDebugger.UI.Controls
{
using System.Collections.Generic;
using System.Collections.ObjectModel;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public delegate void PinEntryControlCallback(IList<int> result, bool didCancel);
public class PinEntryControl : SRMonoBehaviourEx
{
private bool _isVisible = true;
private List<int> _numbers = new List<int>(4);
[RequiredField] public Image Background;
public bool CanCancel = true;
[RequiredField] public UnityEngine.UI.Button CancelButton;
[RequiredField] public Text CancelButtonText;
[RequiredField] public CanvasGroup CanvasGroup;
[RequiredField] public Animator DotAnimator;
public UnityEngine.UI.Button[] NumberButtons;
public Toggle[] NumberDots;
[RequiredField] public Text PromptText;
public event PinEntryControlCallback Complete;
protected override void Awake()
{
base.Awake();
for (var i = 0; i < NumberButtons.Length; i++)
{
var number = i;
NumberButtons[i].onClick.AddListener(() => { PushNumber(number); });
}
CancelButton.onClick.AddListener(CancelButtonPressed);
RefreshState();
}
protected override void OnEnable()
{
#if ENABLE_INPUT_SYSTEM
Keyboard.current.onTextInput += HandleCharacter;
#endif
}
protected override void OnDisable()
{
#if ENABLE_INPUT_SYSTEM
Keyboard.current.onTextInput -= HandleCharacter;
#endif
}
protected override void Update()
{
base.Update();
if (!_isVisible)
{
return;
}
#if ENABLE_INPUT_SYSTEM
bool delete = Keyboard.current.deleteKey.wasPressedThisFrame || Keyboard.current.backspaceKey.wasPressedThisFrame;
#else
bool delete = (Input.GetKeyDown(KeyCode.Backspace) || Input.GetKeyDown(KeyCode.Delete));
#endif
if (_numbers.Count > 0 && delete)
{
_numbers.PopLast();
RefreshState();
}
#if !ENABLE_INPUT_SYSTEM
var input = Input.inputString;
for (var i = 0; i < input.Length; i++)
{
HandleCharacter(input[i]);
}
#endif
}
private void HandleCharacter(char i)
{
if (!_isVisible)
{
return;
}
if (!char.IsNumber(i))
{
return;
}
var num = (int) char.GetNumericValue(i);
if (num > 9 || num < 0)
{
return;
}
PushNumber(num);
}
public void Show()
{
CanvasGroup.alpha = 1f;
CanvasGroup.blocksRaycasts = CanvasGroup.interactable = true;
_isVisible = true;
}
public void Hide()
{
CanvasGroup.alpha = 0f;
CanvasGroup.blocksRaycasts = CanvasGroup.interactable = false;
_isVisible = false;
}
public void Clear()
{
_numbers.Clear();
RefreshState();
}
public void PlayInvalidCodeAnimation()
{
DotAnimator.SetTrigger("Invalid");
}
protected void OnComplete()
{
if (Complete != null)
{
Complete(new ReadOnlyCollection<int>(_numbers), false);
}
}
protected void OnCancel()
{
if (Complete != null)
{
Complete(new int[] {}, true);
}
}
private void CancelButtonPressed()
{
if (_numbers.Count > 0)
{
_numbers.PopLast();
}
else
{
OnCancel();
}
RefreshState();
}
public void PushNumber(int number)
{
if (_numbers.Count >= 4)
{
Debug.LogWarning("[PinEntry] Expected 4 numbers");
return;
}
_numbers.Add(number);
if (_numbers.Count >= 4)
{
OnComplete();
}
RefreshState();
}
private void RefreshState()
{
for (var i = 0; i < NumberDots.Length; i++)
{
NumberDots[i].isOn = i < _numbers.Count;
}
if (_numbers.Count > 0)
{
CancelButtonText.text = "Delete";
}
else
{
CancelButtonText.text = CanCancel ? "Cancel" : "";
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ac5725a9566ed324c98b66c6cb03c5cf
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: de55705b2748e684483766cb59b84390
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,38 @@
namespace SRDebugger.UI
{
using Services;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class ProfilerFPSLabel : SRMonoBehaviourEx
{
private float _nextUpdate;
protected override void Update()
{
base.Update();
if (Time.realtimeSinceStartup > _nextUpdate)
{
Refresh();
}
}
private void Refresh()
{
_text.text = "FPS: {0:0.00}".Fmt(1f/_profilerService.AverageFrameTime);
_nextUpdate = Time.realtimeSinceStartup + UpdateFrequency;
}
#pragma warning disable 649
[Import] private IProfilerService _profilerService;
public float UpdateFrequency = 1f;
[RequiredField] [SerializeField] private Text _text;
#pragma warning restore 649
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 85621644eaef06f44835068498590190
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,79 @@
namespace SRDebugger.UI.Controls
{
using System;
using System.Collections;
using SRF;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling;
#endif
public class ProfilerMemoryBlock : SRMonoBehaviourEx
{
private float _lastRefresh;
[RequiredField] public Text CurrentUsedText;
[RequiredField] public Slider Slider;
[RequiredField] public Text TotalAllocatedText;
protected override void OnEnable()
{
base.OnEnable();
TriggerRefresh();
}
protected override void Update()
{
base.Update();
if (SRDebug.Instance.IsDebugPanelVisible && (Time.realtimeSinceStartup - _lastRefresh > 1f))
{
TriggerRefresh();
_lastRefresh = Time.realtimeSinceStartup;
}
}
public void TriggerRefresh()
{
long max;
long current;
#if UNITY_5_6_OR_NEWER
max = Profiler.GetTotalReservedMemoryLong();
current = Profiler.GetTotalAllocatedMemoryLong();
#else
max = Profiler.GetTotalReservedMemory();
current = Profiler.GetTotalAllocatedMemory();
#endif
var maxMb = (max >> 10);
maxMb /= 1024; // On new line to fix il2cpp
var currentMb = (current >> 10);
currentMb /= 1024;
Slider.maxValue = maxMb;
Slider.value = currentMb;
TotalAllocatedText.text = "Reserved: <color=#FFFFFF>{0}</color>MB".Fmt(maxMb);
CurrentUsedText.text = "<color=#FFFFFF>{0}</color>MB".Fmt(currentMb);
}
public void TriggerCleanup()
{
StartCoroutine(CleanUp());
}
private IEnumerator CleanUp()
{
GC.Collect();
yield return Resources.UnloadUnusedAssets();
GC.Collect();
TriggerRefresh();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 445cb6d0a347a0542a38dd652e9ba01b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,91 @@
namespace SRDebugger.UI.Controls
{
using System;
using SRF;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling;
#endif
public class ProfilerMonoBlock : SRMonoBehaviourEx
{
private float _lastRefresh;
[RequiredField]
public Text CurrentUsedText;
[RequiredField]
public GameObject NotSupportedMessage;
[RequiredField]
public Slider Slider;
[RequiredField]
public Text TotalAllocatedText;
private bool _isSupported;
protected override void OnEnable()
{
base.OnEnable();
#if UNITY_5_6_OR_NEWER
_isSupported = Profiler.GetMonoUsedSizeLong() > 0;
#else
_isSupported = Profiler.GetMonoUsedSize() > 0;
#endif
NotSupportedMessage.SetActive(!_isSupported);
CurrentUsedText.gameObject.SetActive(_isSupported);
TriggerRefresh();
}
protected override void Update()
{
base.Update();
if (SRDebug.Instance.IsDebugPanelVisible && (Time.realtimeSinceStartup - _lastRefresh > 1f))
{
TriggerRefresh();
_lastRefresh = Time.realtimeSinceStartup;
}
}
public void TriggerRefresh()
{
long max;
long current;
#if UNITY_5_6_OR_NEWER
max = _isSupported ? Profiler.GetMonoHeapSizeLong() : GC.GetTotalMemory(false);
current = Profiler.GetMonoUsedSizeLong();
#else
max = _isSupported ? Profiler.GetMonoHeapSize() : GC.GetTotalMemory(false);
current = Profiler.GetMonoUsedSize();
#endif
var maxMb = (max >> 10);
maxMb /= 1024; // On new line to workaround IL2CPP bug
var currentMb = (current >> 10);
currentMb /= 1024;
Slider.maxValue = maxMb;
Slider.value = currentMb;
TotalAllocatedText.text = "Total: <color=#FFFFFF>{0}</color>MB".Fmt(maxMb);
if (currentMb > 0)
{
CurrentUsedText.text = "<color=#FFFFFF>{0}</color>MB".Fmt(currentMb);
}
}
public void TriggerCollection()
{
GC.Collect();
TriggerRefresh();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 9fff10238b625f545b2d88c80d4cf9d4
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,73 @@
namespace SRDebugger.UI.Controls
{
using Internal;
using SRF;
using UnityEngine;
using UnityEngine.UI;
#if UNITY_5_5_OR_NEWER
using UnityEngine.Profiling;
#endif
public class ProfilerEnableControl : SRMonoBehaviourEx
{
private bool _previousState;
[RequiredField] public Text ButtonText;
[RequiredField] public UnityEngine.UI.Button EnableButton;
[RequiredField] public Text Text;
protected override void Start()
{
base.Start();
if (!Profiler.supported)
{
Text.text = SRDebugStrings.Current.Profiler_NotSupported;
EnableButton.gameObject.SetActive(false);
enabled = false;
return;
}
if (!Application.HasProLicense())
{
Text.text = SRDebugStrings.Current.Profiler_NoProInfo;
EnableButton.gameObject.SetActive(false);
enabled = false;
return;
}
UpdateLabels();
}
protected void UpdateLabels()
{
if (!Profiler.enabled)
{
Text.text = SRDebugStrings.Current.Profiler_EnableProfilerInfo;
ButtonText.text = "Enable";
}
else
{
Text.text = SRDebugStrings.Current.Profiler_DisableProfilerInfo;
ButtonText.text = "Disable";
}
_previousState = Profiler.enabled;
}
protected override void Update()
{
base.Update();
if (Profiler.enabled != _previousState)
{
UpdateLabels();
}
}
public void ToggleProfiler()
{
Debug.Log("Toggle Profiler");
Profiler.enabled = !Profiler.enabled;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 04ad714fc337b334687c4aedb49873e9
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,51 @@
namespace SRDebugger.UI.Controls
{
using SRF;
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof (RectTransform))]
public class ProfilerGraphAxisLabel : SRMonoBehaviourEx
{
private float _prevFrameTime;
private float? _queuedFrameTime;
private float _yPosition;
[RequiredField] public Text Text;
protected override void Update()
{
base.Update();
if (_queuedFrameTime.HasValue)
{
SetValueInternal(_queuedFrameTime.Value);
_queuedFrameTime = null;
}
}
public void SetValue(float frameTime, float yPosition)
{
if (_prevFrameTime == frameTime && _yPosition == yPosition)
{
return;
}
_queuedFrameTime = frameTime;
_yPosition = yPosition;
}
private void SetValueInternal(float frameTime)
{
_prevFrameTime = frameTime;
var ms = Mathf.FloorToInt(frameTime*1000);
var fps = Mathf.RoundToInt(1f/frameTime);
Text.text = "{0}ms ({1}FPS)".Fmt(ms, fps);
var r = (RectTransform) CachedTransform;
r.anchoredPosition = new Vector2(r.rect.width*0.5f + 10f, _yPosition);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4694d7052fd506340ba6cad9f8a10f1b
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,550 @@
//#define LOGGING
#if UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1
#define LEGACY_UI
#endif
namespace SRDebugger.UI.Controls
{
using System.Collections.Generic;
using Services;
using SRF;
using SRF.Service;
using UnityEngine;
using UnityEngine.UI;
[ExecuteInEditMode]
[RequireComponent(typeof (RectTransform))]
[RequireComponent(typeof (CanvasRenderer))]
public class ProfilerGraphControl : Graphic
{
public enum VerticalAlignments
{
Top,
Bottom
}
public VerticalAlignments VerticalAlignment = VerticalAlignments.Bottom;
private static readonly float[] ScaleSteps =
{
1f/200f,
1f/160f,
1f/120f,
1f/100f,
1f/60f,
1f/30f,
1f/20f,
1f/12f,
1f/6f
};
/// <summary>
/// Resize the y-axis to fit the nearest useful fps value
/// </summary>
public bool FloatingScale;
/// <summary>
/// If not using FloatingScale, use the target FPS set by Application.targetFrameRate for TargetFps
/// </summary>
public bool TargetFpsUseApplication;
/// <summary>
/// Toggle drawing of the various axes
/// </summary>
public bool DrawAxes = true;
/// <summary>
/// If FloatingScale is disabled, use this value to determine y-axis
/// </summary>
public int TargetFps = 60;
public bool Clip = true;
public const float DataPointMargin = 2f;
public const float DataPointVerticalMargin = 2f;
public const float DataPointWidth = 4f;
public int VerticalPadding = 10;
public const int LineCount = 3;
public Color[] LineColours = new Color[0];
private IProfilerService _profilerService;
private ProfilerGraphAxisLabel[] _axisLabels;
private Rect _clipBounds;
#if LEGACY_UI
private List<UIVertex> _vbo;
#else
private readonly List<Vector3> _meshVertices = new List<Vector3>();
private readonly List<Color32> _meshVertexColors = new List<Color32>();
private readonly List<int> _meshTriangles = new List<int>();
#endif
protected override void Awake()
{
base.Awake();
_profilerService = SRServiceManager.GetService<IProfilerService>();
}
protected override void Start()
{
base.Start();
}
protected void Update()
{
SetVerticesDirty();
}
#if LEGACY_UI
protected override void OnFillVBO(List<UIVertex> vbo)
#else
[System.ObsoleteAttribute]
protected override void OnPopulateMesh(Mesh m)
#endif
{
#if LEGACY_UI
_vbo = vbo;
#else
_meshVertices.Clear();
_meshVertexColors.Clear();
_meshTriangles.Clear();
#endif
#if LOGGING
if(!Application.isPlaying)
Debug.Log("Draw");
#endif
var graphWidth = rectTransform.rect.width;
var graphHeight = rectTransform.rect.height;
_clipBounds = new Rect(0, 0, graphWidth, graphHeight);
var targetFps = TargetFps;
if (Application.isPlaying && TargetFpsUseApplication && Application.targetFrameRate > 0)
{
targetFps = Application.targetFrameRate;
}
var maxValue = 1f/targetFps;
// Holds the index of the nearest 'useful' FPS step
var fpsStep = -1;
var maxFrameTime = FloatingScale ? CalculateMaxFrameTime() : 1f/targetFps;
if (FloatingScale)
{
for (var i = 0; i < ScaleSteps.Length; i++)
{
var step = ScaleSteps[i];
if (maxFrameTime < step*1.1f)
{
maxValue = step;
fpsStep = i;
break;
}
}
// Fall back on the largest one
if (fpsStep < 0)
{
fpsStep = ScaleSteps.Length - 1;
maxValue = ScaleSteps[fpsStep];
}
}
else
{
// Search for the next scale step after the user-provided step
for (var i = 0; i < ScaleSteps.Length; i++)
{
var step = ScaleSteps[i];
if (maxFrameTime > step)
{
fpsStep = i;
}
}
}
var verticalScale = (graphHeight - (VerticalPadding*2))/maxValue;
// Number of data points that can fit into the graph space
var availableDataPoints = CalculateVisibleDataPointCount();
// Reallocate vertex array if insufficient length (or not yet created)
var sampleCount = GetFrameBufferCurrentSize();
for (var i = 0; i < sampleCount; i++)
{
// Break loop if all visible data points have been drawn
if (i >= availableDataPoints)
{
break;
}
// When using right-alignment, read from the end of the profiler buffer
var frame = GetFrame(sampleCount - i - 1);
// Left-hand x coord
var lx = graphWidth - DataPointWidth*i - DataPointWidth - graphWidth/2f;
DrawDataPoint(lx, verticalScale, frame);
}
if (DrawAxes)
{
if (!FloatingScale)
{
DrawAxis(maxValue, maxValue*verticalScale, GetAxisLabel(0));
}
var axisCount = 2;
var j = 0;
if (!FloatingScale)
{
j++;
}
for (var i = fpsStep; i >= 0; --i)
{
if (j >= axisCount)
{
break;
}
DrawAxis(ScaleSteps[i], ScaleSteps[i]*verticalScale, GetAxisLabel(j));
++j;
}
}
#if !LEGACY_UI
m.Clear();
m.SetVertices(_meshVertices);
m.SetColors(_meshVertexColors);
m.SetTriangles(_meshTriangles, 0);
#endif
}
protected void DrawDataPoint(float xPosition, float verticalScale, ProfilerFrame frame)
{
// Right-hand x-coord
var rx = Mathf.Min(_clipBounds.width/2f, xPosition + DataPointWidth - DataPointMargin);
var currentLineHeight = 0f;
for (var j = 0; j < LineCount; j++)
{
var lineIndex = j;
var value = 0f;
if (j == 0)
{
value = (float) frame.UpdateTime;
}
else if (j == 1)
{
value = (float) frame.RenderTime;
}
else if (j == 2)
{
value = (float) frame.OtherTime;
}
value *= verticalScale;
if (value.ApproxZero() || value - DataPointVerticalMargin*2f < 0f)
{
continue;
}
// Lower y-coord
var ly = currentLineHeight + DataPointVerticalMargin - rectTransform.rect.height/2f;
if (VerticalAlignment == VerticalAlignments.Top)
{
ly = rectTransform.rect.height/2f - currentLineHeight - DataPointVerticalMargin;
}
// Upper y-coord
var uy = ly + value - DataPointVerticalMargin;
if (VerticalAlignment == VerticalAlignments.Top)
{
uy = ly - value + DataPointVerticalMargin;
}
var c = LineColours[lineIndex];
AddRect(new Vector3(Mathf.Max(-_clipBounds.width/2f, xPosition), ly),
new Vector3(Mathf.Max(-_clipBounds.width/2f, xPosition), uy), new Vector3(rx, uy),
new Vector3(rx, ly), c);
currentLineHeight += value;
}
}
protected void DrawAxis(float frameTime, float yPosition, ProfilerGraphAxisLabel label)
{
#if LOGGING
if(!Application.isPlaying)
Debug.Log("Draw Axis: {0}".Fmt(yPosition));
#endif
var lx = -rectTransform.rect.width*0.5f;
var rx = -lx;
var uy = yPosition - rectTransform.rect.height*0.5f + 0.5f;
var ly = yPosition - rectTransform.rect.height*0.5f - 0.5f;
var c = new Color(1f, 1f, 1f, 0.4f);
AddRect(new Vector3(lx, ly), new Vector3(lx, uy), new Vector3(rx, uy), new Vector3(rx, ly), c);
if (label != null)
{
label.SetValue(frameTime, yPosition);
}
}
protected void AddRect(Vector3 tl, Vector3 tr, Vector3 bl, Vector3 br, Color c)
{
#if LEGACY_UI
var v = UIVertex.simpleVert;
v.color = c;
v.position = tl;
_vbo.Add(v);
v.position = tr;
_vbo.Add(v);
v.position = bl;
_vbo.Add(v);
v.position = br;
_vbo.Add(v);
#else
// New UI system uses triangles
_meshVertices.Add(tl);
_meshVertices.Add(tr);
_meshVertices.Add(bl);
_meshVertices.Add(br);
_meshTriangles.Add(_meshVertices.Count - 4); // tl
_meshTriangles.Add(_meshVertices.Count - 3); // tr
_meshTriangles.Add(_meshVertices.Count - 1); // br
_meshTriangles.Add(_meshVertices.Count - 2); // bl
_meshTriangles.Add(_meshVertices.Count - 1); // br
_meshTriangles.Add(_meshVertices.Count - 3); // tr
_meshVertexColors.Add(c);
_meshVertexColors.Add(c);
_meshVertexColors.Add(c);
_meshVertexColors.Add(c);
#endif
}
protected ProfilerFrame GetFrame(int i)
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
return TestData[i];
}
#endif
return _profilerService.FrameBuffer[i];
}
protected int CalculateVisibleDataPointCount()
{
return Mathf.RoundToInt(rectTransform.rect.width/DataPointWidth);
}
protected int GetFrameBufferCurrentSize()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
return TestData.Length;
}
#endif
return _profilerService.FrameBuffer.Count;
}
protected int GetFrameBufferMaxSize()
{
#if UNITY_EDITOR
if (!Application.isPlaying)
{
return TestData.Length;
}
#endif
return _profilerService.FrameBuffer.Capacity;
}
protected float CalculateMaxFrameTime()
{
var frameCount = GetFrameBufferCurrentSize();
var c = Mathf.Min(CalculateVisibleDataPointCount(), frameCount);
var max = 0d;
for (var i = 0; i < c; i++)
{
var frameNumber = frameCount - i - 1;
var t = GetFrame(frameNumber);
if (t.FrameTime > max)
{
max = t.FrameTime;
}
}
return (float) max;
}
private ProfilerGraphAxisLabel GetAxisLabel(int index)
{
if (_axisLabels == null || !Application.isPlaying)
{
_axisLabels = GetComponentsInChildren<ProfilerGraphAxisLabel>();
}
if (_axisLabels.Length > index)
{
return _axisLabels[index];
}
Debug.LogWarning("[SRDebugger.Profiler] Not enough axis labels in pool");
return null;
}
#region Editor Only test data
#if UNITY_EDITOR
private ProfilerFrame[] TestData
{
get
{
if (_testData == null)
{
_testData = GenerateSampleData();
}
return _testData;
}
}
private ProfilerFrame[] _testData;
protected static ProfilerFrame[] GenerateSampleData()
{
var sampleCount = 200;
var data = new ProfilerFrame[sampleCount];
for (var i = 0; i < sampleCount; i++)
{
var frame = new ProfilerFrame();
for (var j = 0; j < 3; j++)
{
var v = 0d;
if (j == 0)
{
v = Mathf.PerlinNoise(i/200f, 0);
}
else if (j == 1)
{
v = Mathf.PerlinNoise(0, i/200f);
}
else
{
v = Random.Range(0, 1f);
}
v *= (1f/60f)*0.333f;
// Simulate spikes
if (Random.value > 0.8f)
{
v *= Random.Range(1.2f, 1.8f);
}
if (j == 2)
{
v *= 0.1f;
}
if (j == 0)
{
frame.UpdateTime = v;
}
else if (j == 1)
{
frame.RenderTime = v;
}
else if (j == 2)
{
frame.FrameTime = frame.RenderTime + frame.UpdateTime + v;
}
}
data[i] = frame;
}
data[0] = new ProfilerFrame
{
FrameTime = 0.005,
RenderTime = 0.005,
UpdateTime = 0.005
};
data[sampleCount - 1] = new ProfilerFrame
{
FrameTime = 1d/60d,
RenderTime = 0.007,
UpdateTime = 0.007
};
return data;
}
#endif
#endregion
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e5812a284a856b743b4f54c6a4637061
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,26 @@
namespace SRDebugger.UI.Controls
{
using SRF;
using SRF.UI;
using UnityEngine;
using UnityEngine.UI;
public class SRTabButton : SRMonoBehaviourEx
{
[RequiredField] public Behaviour ActiveToggle;
[RequiredField] public UnityEngine.UI.Button Button;
[RequiredField] public RectTransform ExtraContentContainer;
[RequiredField] public StyleComponent IconStyleComponent;
[RequiredField] public Text TitleText;
public bool IsActive
{
get { return ActiveToggle.enabled; }
set { ActiveToggle.enabled = value; }
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d2e81b40d04e8e440bb9659057db98c8
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,34 @@
namespace SRDebugger.UI
{
using Scripts;
using Services;
using SRF;
using SRF.Service;
using UnityEngine;
public class DebugPanelRoot : SRMonoBehaviourEx
{
[RequiredField] public Canvas Canvas;
[RequiredField] public CanvasGroup CanvasGroup;
[RequiredField] public DebuggerTabController TabController;
public void Close()
{
if (Settings.Instance.UnloadOnClose)
{
SRServiceManager.GetService<IDebugService>().DestroyDebugPanel();
}
else
{
SRServiceManager.GetService<IDebugService>().HideDebugPanel();
}
}
public void CloseAndDestroy()
{
SRServiceManager.GetService<IDebugService>().DestroyDebugPanel();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 64a45d1be7c826148a745e7d38b02161
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,119 @@
namespace SRDebugger.Scripts
{
using System;
using System.Linq;
using SRF;
using UI.Other;
using UnityEngine;
public class DebuggerTabController : SRMonoBehaviourEx
{
private SRTab _aboutTabInstance;
private DefaultTabs? _activeTab;
private bool _hasStarted;
public SRTab AboutTab;
[RequiredField] public SRTabController TabController;
public DefaultTabs? ActiveTab
{
get
{
var key = TabController.ActiveTab.Key;
if (string.IsNullOrEmpty(key))
{
return null;
}
var t = Enum.Parse(typeof (DefaultTabs), key);
if (!Enum.IsDefined(typeof (DefaultTabs), t))
{
return null;
}
return (DefaultTabs) t;
}
}
protected override void Start()
{
base.Start();
_hasStarted = true;
// Loads all available tabs from resources
var tabs = Resources.LoadAll<SRTab>("SRDebugger/UI/Prefabs/Tabs");
var defaultTabs = Enum.GetNames(typeof (DefaultTabs));
foreach (var srTab in tabs)
{
var enabler = srTab.GetComponent(typeof (IEnableTab)) as IEnableTab;
if (enabler != null && !enabler.IsEnabled)
{
continue;
}
if (defaultTabs.Contains(srTab.Key))
{
var tabValue = Enum.Parse(typeof (DefaultTabs), srTab.Key);
if (Enum.IsDefined(typeof (DefaultTabs), tabValue) &&
Settings.Instance.DisabledTabs.Contains((DefaultTabs) tabValue))
{
continue;
}
}
TabController.AddTab(SRInstantiate.Instantiate(srTab));
}
// Add about tab (has no button, accessed via "Stompy" logo
if (AboutTab != null)
{
_aboutTabInstance = SRInstantiate.Instantiate(AboutTab);
TabController.AddTab(_aboutTabInstance, false);
}
// Open active tab (set before panel loaded), or default tab from settings
var defaultTab = _activeTab ?? Settings.Instance.DefaultTab;
if (!OpenTab(defaultTab))
{
TabController.ActiveTab = TabController.Tabs.FirstOrDefault();
}
}
public bool OpenTab(DefaultTabs tab)
{
if (!_hasStarted)
{
_activeTab = tab;
return true;
}
var tabName = tab.ToString();
foreach (var t in TabController.Tabs)
{
if (t.Key == tabName)
{
TabController.ActiveTab = t;
return true;
}
}
return false;
}
public void ShowAboutTab()
{
if (_aboutTabInstance != null)
{
TabController.ActiveTab = _aboutTabInstance;
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 295aaaf6e216af84e99f15dff7b6fc32
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,162 @@
namespace SRDebugger.UI
{
using Other;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class MobileMenuController : SRMonoBehaviourEx
{
private UnityEngine.UI.Button _closeButton;
[SerializeField] private float _maxMenuWidth = 185f;
[SerializeField] private float _peekAmount = 45f;
private float _targetXPosition;
[RequiredField] public RectTransform Content;
[RequiredField] public RectTransform Menu;
[RequiredField] public UnityEngine.UI.Button OpenButton;
[RequiredField] public SRTabController TabController;
public float PeekAmount
{
get { return _peekAmount; }
}
public float MaxMenuWidth
{
get { return _maxMenuWidth; }
}
protected override void OnEnable()
{
base.OnEnable();
var parent = Menu.parent as RectTransform;
var layoutElement = Menu.GetComponent<LayoutElement>();
layoutElement.ignoreLayout = true;
// Set up menu anchors so it stretches to full height and has the screen width
Menu.pivot = new Vector2(1, 1);
Menu.offsetMin = new Vector2(1f, 0f);
Menu.offsetMax = new Vector2(1f, 1f);
Menu.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,
Mathf.Clamp(parent.rect.width - PeekAmount, 0, MaxMenuWidth));
Menu.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, parent.rect.height);
Menu.anchoredPosition = new Vector2(0, 0);
if (_closeButton == null)
{
CreateCloseButton();
}
OpenButton.gameObject.SetActive(true);
TabController.ActiveTabChanged += TabControllerOnActiveTabChanged;
}
protected override void OnDisable()
{
base.OnDisable();
var layoutElement = Menu.GetComponent<LayoutElement>();
layoutElement.ignoreLayout = false;
// Reset content position in case it has been moved by opening the menu
Content.anchoredPosition = new Vector2(0, 0);
_closeButton.gameObject.SetActive(false);
OpenButton.gameObject.SetActive(false);
TabController.ActiveTabChanged -= TabControllerOnActiveTabChanged;
}
private void CreateCloseButton()
{
var go = new GameObject("SR_CloseButtonCanvas", typeof(RectTransform));
go.transform.SetParent(Content, false);
var c = go.AddComponent<Canvas>();
go.AddComponent<GraphicRaycaster>();
var rect = go.GetComponentOrAdd<RectTransform>();
c.overrideSorting = true;
c.sortingOrder = 122;
go.AddComponent<LayoutElement>().ignoreLayout = true;
SetRectSize(rect);
var cGo = new GameObject("SR_CloseButton", typeof(RectTransform));
cGo.transform.SetParent(rect, false);
var cRect = cGo.GetComponent<RectTransform>();
SetRectSize(cRect);
cGo.AddComponent<Image>().color = new Color(0, 0, 0, 0);
_closeButton = cGo.AddComponent<UnityEngine.UI.Button>();
_closeButton.transition = Selectable.Transition.None;
_closeButton.onClick.AddListener(CloseButtonClicked);
_closeButton.gameObject.SetActive(false);
}
private void SetRectSize(RectTransform rect)
{
rect.anchorMin = new Vector2(0, 0);
rect.anchorMax = new Vector2(1, 1);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Content.rect.width);
rect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, Content.rect.height);
}
private void CloseButtonClicked()
{
Close();
}
protected override void Update()
{
base.Update();
var from = Content.anchoredPosition.x;
if (Mathf.Abs(_targetXPosition - from) < 2.5f)
{
Content.anchoredPosition = new Vector2(_targetXPosition, Content.anchoredPosition.y);
}
else
{
Content.anchoredPosition =
new Vector2(SRMath.SpringLerp(from, _targetXPosition, 15f, Time.unscaledDeltaTime),
Content.anchoredPosition.y);
}
}
private void TabControllerOnActiveTabChanged(SRTabController srTabController, SRTab srTab)
{
Close();
}
[ContextMenu("Open")]
public void Open()
{
_targetXPosition = Menu.rect.width;
_closeButton.gameObject.SetActive(true);
}
[ContextMenu("Close")]
public void Close()
{
_targetXPosition = 0;
_closeButton.gameObject.SetActive(false);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 3cc3afaacd56e9b4f9f2b6201ec85267
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: 7e7d110cdb77d7b41bfa3bc97d8144e2
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,12 @@
namespace SRDebugger.UI.Other
{
using SRF;
using UnityEngine;
public class BugReportPopoverRoot : SRMonoBehaviourEx
{
[RequiredField] public CanvasGroup CanvasGroup;
[RequiredField] public RectTransform Container;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 5c9a194ca4d3911419f82b2f06d5ef2e
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,195 @@

#if NETFX_CORE
using UnityEngine.Windows;
#endif
namespace SRDebugger.UI.Other
{
using System;
using System.Collections;
using System.Linq;
using Internal;
using Services;
using SRF;
using SRF.Service;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class BugReportSheetController : SRMonoBehaviourEx
{
[RequiredField] public GameObject ButtonContainer;
[RequiredField] public Text ButtonText;
[RequiredField] public UnityEngine.UI.Button CancelButton;
public Action CancelPressed;
[RequiredField] public InputField DescriptionField;
[RequiredField] public InputField EmailField;
[RequiredField] public Slider ProgressBar;
[RequiredField] public Text ResultMessageText;
public Action ScreenshotComplete;
[RequiredField] public UnityEngine.UI.Button SubmitButton;
public Action<bool, string> SubmitComplete;
public Action TakingScreenshot;
public bool IsCancelButtonEnabled
{
get { return CancelButton.gameObject.activeSelf; }
set { CancelButton.gameObject.SetActive(value); }
}
protected override void Start()
{
base.Start();
SetLoadingSpinnerVisible(false);
ClearErrorMessage();
ClearForm();
}
public void Submit()
{
EventSystem.current.SetSelectedGameObject(null);
ProgressBar.value = 0;
ClearErrorMessage();
SetLoadingSpinnerVisible(true);
SetFormEnabled(false);
if (!string.IsNullOrEmpty(EmailField.text))
{
SetDefaultEmailFieldContents(EmailField.text);
}
StartCoroutine(SubmitCo());
}
public void Cancel()
{
if (CancelPressed != null)
{
CancelPressed();
}
}
private IEnumerator SubmitCo()
{
if (BugReportScreenshotUtil.ScreenshotData == null && Settings.Instance.EnableBugReportScreenshot)
{
if (TakingScreenshot != null)
{
TakingScreenshot();
}
yield return new WaitForEndOfFrame();
yield return StartCoroutine(BugReportScreenshotUtil.ScreenshotCaptureCo());
if (ScreenshotComplete != null)
{
ScreenshotComplete();
}
}
var s = SRServiceManager.GetService<IBugReportService>();
var r = new BugReport();
r.Email = EmailField.text;
r.UserDescription = DescriptionField.text;
r.ConsoleLog = Service.Console.AllEntries.ToList();
r.SystemInformation = SRServiceManager.GetService<ISystemInformationService>().CreateReport();
r.ScreenshotData = BugReportScreenshotUtil.ScreenshotData;
BugReportScreenshotUtil.ScreenshotData = null;
s.SendBugReport(r, OnBugReportComplete, new Progress<float>(OnBugReportProgress));
}
private void OnBugReportProgress(float progress)
{
ProgressBar.value = progress;
}
private void OnBugReportComplete(bool didSucceed, string errorMessage)
{
if (!didSucceed)
{
ShowErrorMessage("Error sending bug report", errorMessage);
}
else
{
ClearForm();
ShowErrorMessage("Bug report submitted successfully");
}
SetLoadingSpinnerVisible(false);
SetFormEnabled(true);
if (SubmitComplete != null)
{
SubmitComplete(didSucceed, errorMessage);
}
}
protected void SetLoadingSpinnerVisible(bool visible)
{
ProgressBar.gameObject.SetActive(visible);
ButtonContainer.SetActive(!visible);
}
protected void ClearForm()
{
EmailField.text = GetDefaultEmailFieldContents();
DescriptionField.text = "";
}
protected void ShowErrorMessage(string userMessage, string serverMessage = null)
{
var txt = userMessage;
if (!string.IsNullOrEmpty(serverMessage))
{
txt += " (<b>{0}</b>)".Fmt(serverMessage);
}
ResultMessageText.text = txt;
ResultMessageText.gameObject.SetActive(true);
}
protected void ClearErrorMessage()
{
ResultMessageText.text = "";
ResultMessageText.gameObject.SetActive(false);
}
protected void SetFormEnabled(bool e)
{
SubmitButton.interactable = e;
CancelButton.interactable = e;
EmailField.interactable = e;
DescriptionField.interactable = e;
}
private string GetDefaultEmailFieldContents()
{
return PlayerPrefs.GetString("SRDEBUGGER_BUG_REPORT_LAST_EMAIL", "");
}
private void SetDefaultEmailFieldContents(string value)
{
PlayerPrefs.SetString("SRDEBUGGER_BUG_REPORT_LAST_EMAIL", value);
PlayerPrefs.Save();
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 63d76b94b1c670b4cbafd57dd8dcd2ff
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,56 @@
namespace SRDebugger.UI.Other
{
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class CategoryGroup : SRMonoBehaviourEx
{
[RequiredField] public RectTransform Container;
[RequiredField] public Text Header;
[RequiredField] public GameObject Background;
[RequiredField] public Toggle SelectionToggle;
public GameObject[] EnabledDuringSelectionMode = new GameObject[0];
private bool _selectionModeEnabled = true;
public bool IsSelected
{
get
{
return SelectionToggle.isOn;
}
set
{
SelectionToggle.isOn = value;
if (SelectionToggle.graphic != null)
{
SelectionToggle.graphic.CrossFadeAlpha(value ? _selectionModeEnabled ? 1.0f : 0.2f : 0f, 0, true);
}
}
}
public bool SelectionModeEnabled
{
get { return _selectionModeEnabled; }
set
{
if (value == _selectionModeEnabled)
{
return;
}
_selectionModeEnabled = value;
for (var i = 0; i < EnabledDuringSelectionMode.Length; i++)
{
EnabledDuringSelectionMode[i].SetActive(_selectionModeEnabled);
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 176c1a8b99c762143a65fa14f47b5d93
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,56 @@
using System;
using System.ComponentModel;
using UnityEngine.UI;
namespace SRDebugger.UI.Other
{
using Internal;
using SRF;
using UnityEngine;
[RequireComponent(typeof (Canvas))]
public class ConfigureCanvasFromSettings : SRMonoBehaviour
{
private Canvas _canvas;
private CanvasScaler _canvasScaler;
private float _originalScale;
private float _lastSetScale;
private Settings _settings;
private void Start()
{
_canvas = GetComponent<Canvas>();
_canvasScaler = GetComponent<CanvasScaler>();
SRDebuggerUtil.ConfigureCanvas(_canvas);
_settings = SRDebug.Instance.Settings;
_originalScale = _canvasScaler.scaleFactor;
_canvasScaler.scaleFactor = _originalScale * _settings.UIScale;
// Track the last set scale in case it is modified by the retina scaler.
_lastSetScale = _canvasScaler.scaleFactor;
_settings.PropertyChanged += SettingsOnPropertyChanged;
}
private void OnDestroy()
{
if (_settings != null)
{
_settings.PropertyChanged -= SettingsOnPropertyChanged;
}
}
private void SettingsOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
{
// If the last set scale does not match the current scale factor, then it is likely the retina scaler has applied a change.
// Treat the new value as the original scale.
if (_canvasScaler.scaleFactor != _lastSetScale) _originalScale = _canvasScaler.scaleFactor;
_canvasScaler.scaleFactor = _originalScale * _settings.UIScale;
_lastSetScale = _canvasScaler.scaleFactor;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: f0ad3d8afa9fd64429a249b5bbb19557
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,71 @@
namespace SRDebugger.UI.Other
{
using Services;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class ConsoleTabQuickViewControl : SRMonoBehaviourEx
{
private const int Max = 1000;
private static readonly string MaxString = (Max - 1) + "+";
private int _prevErrorCount = -1;
private int _prevInfoCount = -1;
private int _prevWarningCount = -1;
[Import] public IConsoleService ConsoleService;
[RequiredField] public Text ErrorCountText;
[RequiredField] public Text InfoCountText;
[RequiredField] public Text WarningCountText;
protected override void Awake()
{
base.Awake();
ErrorCountText.text = "0";
WarningCountText.text = "0";
InfoCountText.text = "0";
}
protected override void Update()
{
base.Update();
if (ConsoleService == null)
{
return;
}
if (HasChanged(ConsoleService.ErrorCount, ref _prevErrorCount, Max))
{
ErrorCountText.text = Internal.SRDebuggerUtil.GetNumberString(ConsoleService.ErrorCount, Max, MaxString);
}
if (HasChanged(ConsoleService.WarningCount, ref _prevWarningCount, Max))
{
WarningCountText.text = Internal.SRDebuggerUtil.GetNumberString(ConsoleService.WarningCount, Max,
MaxString);
}
if (HasChanged(ConsoleService.InfoCount, ref _prevInfoCount, Max))
{
InfoCountText.text = Internal.SRDebuggerUtil.GetNumberString(ConsoleService.InfoCount, Max, MaxString);
}
}
private static bool HasChanged(int newCount, ref int oldCount, int max)
{
var newCountClamped = Mathf.Clamp(newCount, 0, max);
var oldCountClamped = Mathf.Clamp(oldCount, 0, max);
var hasChanged = newCountClamped != oldCountClamped;
oldCount = newCount;
return hasChanged;
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: b9e7555976318b846887116c61e2ecf6
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,32 @@
namespace SRDebugger.UI.Other
{
using SRF;
using SRF.UI;
using UnityEngine;
[RequireComponent(typeof (StyleComponent))]
public class DebugPanelBackgroundBehaviour : SRMonoBehaviour
{
private StyleComponent _styleComponent;
public string TransparentStyleKey = "";
[SerializeField]
private StyleSheet _styleSheet;
private void Awake()
{
_styleComponent = GetComponent<StyleComponent>();
if (Settings.Instance.EnableBackgroundTransparency)
{
// Update transparent style to have the transparency set in the settings menu.
Style style = _styleSheet.GetStyle(TransparentStyleKey);
Color c = style.NormalColor;
c.a = Settings.Instance.BackgroundTransparency;
style.NormalColor = c;
_styleComponent.StyleKey = TransparentStyleKey;
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a819a08c122d6474a848377ee7ba3192
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,266 @@
namespace SRDebugger.UI.Other
{
using Controls;
using Internal;
using Services;
using SRF;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class DockConsoleController : SRMonoBehaviourEx, IPointerEnterHandler, IPointerExitHandler
{
public const float NonFocusOpacity = 0.65f;
private bool _isDirty;
private bool _isDragging;
private int _pointersOver;
[Import]
public IConsoleFilterState FilterState;
[RequiredField] public GameObject BottomHandle;
[RequiredField] public CanvasGroup CanvasGroup;
[RequiredField] public ConsoleLogControl Console;
[RequiredField] public GameObject Dropdown;
[RequiredField] public Image DropdownToggleSprite;
[RequiredField] public Text TextErrors;
[RequiredField] public Text TextInfo;
[RequiredField] public Text TextWarnings;
[RequiredField] public Toggle ToggleErrors;
[RequiredField] public Toggle ToggleInfo;
[RequiredField] public Toggle ToggleWarnings;
[RequiredField] public GameObject TopBar;
[RequiredField] public GameObject TopHandle;
[RequiredField] public GameObject TopSafeAreaSpacer;
[RequiredField] public GameObject BottomSafeAreaSpacer;
public bool IsVisible
{
get { return CachedGameObject.activeSelf; }
set { CachedGameObject.SetActive(value); }
}
protected override void Start()
{
base.Start();
//_canvasScaler = Canvas.GetComponent<CanvasScaler>();
Service.Console.Updated += ConsoleOnUpdated;
ToggleErrors.isOn = FilterState.GetConsoleFilterState(LogType.Error);
ToggleWarnings.isOn = FilterState.GetConsoleFilterState(LogType.Warning);
ToggleInfo.isOn = FilterState.GetConsoleFilterState(LogType.Log);
ToggleErrors.onValueChanged.AddListener(isOn =>
{
FilterState.SetConsoleFilterState(LogType.Error, isOn);
_isDirty = true;
});
ToggleWarnings.onValueChanged.AddListener(isOn =>
{
FilterState.SetConsoleFilterState(LogType.Warning, isOn);
_isDirty = true;
});
ToggleInfo.onValueChanged.AddListener(isOn =>
{
FilterState.SetConsoleFilterState(LogType.Log, isOn);
_isDirty = true;
});
FilterState.FilterStateChange += OnFilterStateChange;
Refresh();
RefreshAlpha();
}
protected override void OnDestroy()
{
base.OnDestroy();
if (Service.Console != null)
{
Service.Console.Updated -= ConsoleOnUpdated;
}
FilterState.FilterStateChange -= OnFilterStateChange;
}
protected override void OnEnable()
{
base.OnEnable();
_pointersOver = 0;
_isDragging = false;
RefreshAlpha();
}
protected override void OnDisable()
{
base.OnDisable();
_pointersOver = 0;
}
protected override void Update()
{
base.Update();
if (_isDirty)
{
Refresh();
}
}
private void OnFilterStateChange(LogType logType, bool newState)
{
switch (logType)
{
case LogType.Error:
ToggleErrors.isOn = newState;
break;
case LogType.Warning:
ToggleWarnings.isOn = newState;
break;
case LogType.Log:
ToggleInfo.isOn = newState;
break;
}
}
private void ConsoleOnUpdated(IConsoleService console)
{
_isDirty = true;
}
public void SetDropdownVisibility(bool visible)
{
Dropdown.SetActive(visible);
DropdownToggleSprite.rectTransform.localRotation = Quaternion.Euler(0, 0, visible ? 0f : 180f);
}
public void SetAlignmentMode(ConsoleAlignment alignment)
{
switch (alignment)
{
case ConsoleAlignment.Top:
{
TopBar.transform.SetSiblingIndex(0);
Dropdown.transform.SetSiblingIndex(2);
TopHandle.SetActive(false);
BottomHandle.SetActive(true);
transform.SetSiblingIndex(0);
DropdownToggleSprite.rectTransform.parent.localRotation = Quaternion.Euler(0, 0, 0f);
TopSafeAreaSpacer.SetActive(true);
BottomSafeAreaSpacer.SetActive(false);
break;
}
case ConsoleAlignment.Bottom:
{
Dropdown.transform.SetSiblingIndex(0);
TopBar.transform.SetSiblingIndex(2);
TopHandle.SetActive(true);
BottomHandle.SetActive(false);
transform.SetSiblingIndex(1);
DropdownToggleSprite.rectTransform.parent.localRotation = Quaternion.Euler(0, 0, 180f);
TopSafeAreaSpacer.SetActive(false);
BottomSafeAreaSpacer.SetActive(true);
break;
}
}
}
private void Refresh()
{
// Update total counts labels
TextInfo.text = SRDebuggerUtil.GetNumberString(Service.Console.InfoCount, 999, "999+");
TextWarnings.text = SRDebuggerUtil.GetNumberString(Service.Console.WarningCount, 999, "999+");
TextErrors.text = SRDebuggerUtil.GetNumberString(Service.Console.ErrorCount, 999, "999+");
ToggleErrors.isOn = FilterState.GetConsoleFilterState(LogType.Error);
ToggleWarnings.isOn = FilterState.GetConsoleFilterState(LogType.Warning);
ToggleInfo.isOn = FilterState.GetConsoleFilterState(LogType.Log);
_isDirty = false;
}
private void RefreshAlpha()
{
if (_isDragging || _pointersOver > 0)
{
CanvasGroup.alpha = 1.0f;
}
else
{
CanvasGroup.alpha = NonFocusOpacity;
}
}
#region Event Callbacks
public void ToggleDropdownVisible()
{
SetDropdownVisibility(!Dropdown.activeSelf);
}
public void MenuButtonPressed()
{
SRDebug.Instance.ShowDebugPanel(DefaultTabs.Console);
}
public void ClearButtonPressed()
{
Service.Console.Clear();
}
public void TogglesUpdated()
{
Console.ShowErrors = ToggleErrors.isOn;
Console.ShowWarnings = ToggleWarnings.isOn;
Console.ShowInfo = ToggleInfo.isOn;
SetDropdownVisibility(true);
}
public void OnPointerEnter(PointerEventData e)
{
_pointersOver = 1;
RefreshAlpha();
}
public void OnPointerExit(PointerEventData e)
{
_pointersOver = 0; //Mathf.Max(0, _pointersOver - 1);
RefreshAlpha();
}
public void OnBeginDrag()
{
_isDragging = true;
RefreshAlpha();
}
public void OnEndDrag()
{
_isDragging = false;
_pointersOver = 0;
RefreshAlpha();
}
#endregion
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: c8181ba76f89dd64a96c1e8c2beccb26
timeCreated: 1441833066
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,3 @@
// Deprecated file. Included to prevent conflicts when upgrading from a previous version of SRDebugger

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e502669a31931b74ea762540a783f1ff
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,56 @@
using UnityEngine;
namespace SRDebugger.UI.Other
{
public class ErrorNotifier : MonoBehaviour
{
public bool IsVisible
{
get { return _isShowing; }
}
private const float DisplayTime = 6;
[SerializeField]
private Animator _animator = null;
private int _triggerHash;
private float _hideTime;
private bool _isShowing;
private bool _queueWarning;
void Awake()
{
_triggerHash = Animator.StringToHash("Display");
}
public void ShowErrorWarning()
{
_queueWarning = true;
}
void Update()
{
if (_queueWarning)
{
_hideTime = Time.realtimeSinceStartup + DisplayTime;
if (!_isShowing)
{
_isShowing = true;
_animator.SetBool(_triggerHash, true);
}
_queueWarning = false;
}
if (_isShowing && Time.realtimeSinceStartup > _hideTime)
{
_animator.SetBool(_triggerHash, false);
_isShowing = false;
}
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: dc845b8723c64841aa76e259d4a0b6c4
timeCreated: 1582392762

View File

@@ -0,0 +1,44 @@
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
namespace SRDebugger.UI.Other
{
[RequireComponent(typeof(RectTransform)), ExecuteAlways]
public class FloatOverElement : UIBehaviour, ILayoutSelfController
{
public RectTransform CopyFrom;
private DrivenRectTransformTracker _tracker;
void Copy()
{
if (CopyFrom == null) return;
_tracker.Clear();
var r = GetComponent<RectTransform>();
r.anchorMin = CopyFrom.anchorMin;
r.anchorMax = CopyFrom.anchorMax;
r.anchoredPosition = CopyFrom.anchoredPosition;
r.offsetMin = CopyFrom.offsetMin;
r.offsetMax = CopyFrom.offsetMax;
r.sizeDelta = CopyFrom.sizeDelta;
r.localScale = CopyFrom.localScale;
r.pivot = CopyFrom.pivot;
_tracker.Add(this, r, DrivenTransformProperties.All);
}
public void SetLayoutHorizontal()
{
Copy();
}
public void SetLayoutVertical()
{
Copy();
}
}
}

View File

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

View File

@@ -0,0 +1,106 @@
namespace SRDebugger.UI.Other
{
using SRF;
using UnityEngine;
/// <summary>
/// Handles enabling/disabling handle objects for different anchoring modes
/// </summary>
public class HandleManager : SRMonoBehaviour
{
private bool _hasSet;
public GameObject BottomHandle;
public GameObject BottomLeftHandle;
public GameObject BottomRightHandle;
public PinAlignment DefaultAlignment;
public GameObject LeftHandle;
public GameObject RightHandle;
public GameObject TopHandle;
public GameObject TopLeftHandle;
public GameObject TopRightHandle;
private void Start()
{
if (!_hasSet)
{
SetAlignment(DefaultAlignment);
}
}
public void SetAlignment(PinAlignment alignment)
{
_hasSet = true;
switch (alignment)
{
case PinAlignment.TopLeft:
case PinAlignment.TopRight:
SetActive(BottomHandle, true);
SetActive(TopHandle, false);
SetActive(TopLeftHandle, false);
SetActive(TopRightHandle, false);
break;
case PinAlignment.BottomLeft:
case PinAlignment.BottomRight:
SetActive(BottomHandle, false);
SetActive(TopHandle, true);
SetActive(BottomLeftHandle, false);
SetActive(BottomRightHandle, false);
break;
}
switch (alignment)
{
case PinAlignment.TopLeft:
case PinAlignment.BottomLeft:
SetActive(LeftHandle, false);
SetActive(RightHandle, true);
SetActive(TopLeftHandle, false);
SetActive(BottomLeftHandle, false);
break;
case PinAlignment.TopRight:
case PinAlignment.BottomRight:
SetActive(LeftHandle, true);
SetActive(RightHandle, false);
SetActive(TopRightHandle, false);
SetActive(BottomRightHandle, false);
break;
}
switch (alignment)
{
case PinAlignment.TopLeft:
SetActive(BottomLeftHandle, false);
SetActive(BottomRightHandle, true);
break;
case PinAlignment.TopRight:
SetActive(BottomLeftHandle, true);
SetActive(BottomRightHandle, false);
break;
case PinAlignment.BottomLeft:
SetActive(TopLeftHandle, false);
SetActive(TopRightHandle, true);
break;
case PinAlignment.BottomRight:
SetActive(TopLeftHandle, true);
SetActive(TopRightHandle, false);
break;
}
}
private void SetActive(GameObject obj, bool active)
{
if (obj == null)
{
return;
}
obj.SetActive(active);
}
}
}

View File

@@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: 4292e93ad30fda64b96c60d4d68b3c0d
timeCreated: 1441815277
licenseType: Store
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,7 @@
namespace SRDebugger.UI.Other
{
public interface IEnableTab
{
bool IsEnabled { get; }
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: a0522b3ec2155a4468bea956e3ea2fd5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,35 @@
namespace SRDebugger.UI.Other
{
using SRF;
using UnityEngine;
public class LoadingSpinnerBehaviour : SRMonoBehaviour
{
private float _dt;
public int FrameCount = 12;
public float SpinDuration = 0.8f;
private void Update()
{
_dt += Time.unscaledDeltaTime;
var localRotation = CachedTransform.localRotation.eulerAngles;
var r = localRotation.z;
var fTime = SpinDuration/FrameCount;
var hasChanged = false;
while (_dt > fTime)
{
r -= 360f/FrameCount;
_dt -= fTime;
hasChanged = true;
}
if (hasChanged)
{
CachedTransform.localRotation = Quaternion.Euler(localRotation.x, localRotation.y, r);
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 44d058d954e809c4fa87cfab328237d7
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,26 @@
namespace SRDebugger.UI.Other
{
using SRF;
using SRF.UI.Layout;
using UnityEngine;
using UnityEngine.UI;
public class PinnedUIRoot : SRMonoBehaviourEx
{
[RequiredField] public Canvas Canvas;
[RequiredField] public RectTransform Container;
[RequiredField] public DockConsoleController DockConsoleController;
[RequiredField] public GameObject Options;
[RequiredField] public FlowLayoutGroup OptionsLayoutGroup;
[RequiredField] public GameObject Profiler;
[RequiredField] public HandleManager ProfilerHandleManager;
[RequiredField] public VerticalLayoutGroup ProfilerVerticalLayoutGroup;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7d5f8248a0899ee48adc84c3fb98627a
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,52 @@
namespace SRDebugger.UI.Other
{
using System;
using Controls;
using SRF;
using UnityEngine;
using UnityEngine.Serialization;
public class SRTab : SRMonoBehaviourEx
{
/// <summary>
/// Content that will be added to the content area of the header
/// </summary>
public RectTransform HeaderExtraContent;
[Obsolete] [HideInInspector] public Sprite Icon;
/// <summary>
/// Content that will be added to the content area of the tab button
/// </summary>
public RectTransform IconExtraContent;
public string IconStyleKey = "Icon_Stompy";
public int SortIndex;
[HideInInspector] public SRTabButton TabButton;
public string Title
{
get { return _title; }
}
public string LongTitle
{
get { return !string.IsNullOrEmpty(_longTitle) ? _longTitle : _title; }
}
public string Key
{
get { return _key; }
}
#pragma warning disable 649
[SerializeField] [FormerlySerializedAs("Title")] private string _title;
[SerializeField] private string _longTitle;
[SerializeField] private string _key;
#pragma warning restore 649
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 94b1f24ed4379dd4fab14add56e520a5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,133 @@
namespace SRDebugger.UI.Other
{
using System;
using System.Collections.Generic;
using Controls;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class SRTabController : SRMonoBehaviourEx
{
private readonly SRList<SRTab> _tabs = new SRList<SRTab>();
private SRTab _activeTab;
[RequiredField] public RectTransform TabButtonContainer;
[RequiredField] public SRTabButton TabButtonPrefab;
[RequiredField] public RectTransform TabContentsContainer;
[RequiredField] public RectTransform TabHeaderContentContainer;
[RequiredField] public Text TabHeaderText;
public SRTab ActiveTab
{
get { return _activeTab; }
set { MakeActive(value); }
}
public IList<SRTab> Tabs
{
get { return _tabs.AsReadOnly(); }
}
public event Action<SRTabController, SRTab> ActiveTabChanged;
public void AddTab(SRTab tab, bool visibleInSidebar = true)
{
tab.CachedTransform.SetParent(TabContentsContainer, false);
tab.CachedGameObject.SetActive(false);
if (visibleInSidebar)
{
// Create a tab button for this tab
var button = SRInstantiate.Instantiate(TabButtonPrefab);
button.CachedTransform.SetParent(TabButtonContainer, false);
button.TitleText.text = tab.Title.ToUpper();
if (tab.IconExtraContent != null)
{
var extraContent = SRInstantiate.Instantiate(tab.IconExtraContent);
extraContent.SetParent(button.ExtraContentContainer, false);
}
button.IconStyleComponent.StyleKey = tab.IconStyleKey;
button.IsActive = false;
button.Button.onClick.AddListener(() => MakeActive(tab));
tab.TabButton = button;
}
_tabs.Add(tab);
SortTabs();
if (_tabs.Count == 1)
{
ActiveTab = tab;
}
}
private void MakeActive(SRTab tab)
{
if (!_tabs.Contains(tab))
{
throw new ArgumentException("tab is not a member of this tab controller", "tab");
}
if (_activeTab != null)
{
_activeTab.CachedGameObject.SetActive(false);
if (_activeTab.TabButton != null)
{
_activeTab.TabButton.IsActive = false;
}
if (_activeTab.HeaderExtraContent != null)
{
_activeTab.HeaderExtraContent.gameObject.SetActive(false);
}
}
_activeTab = tab;
if (_activeTab != null)
{
_activeTab.CachedGameObject.SetActive(true);
TabHeaderText.text = _activeTab.LongTitle;
if (_activeTab.TabButton != null)
{
_activeTab.TabButton.IsActive = true;
}
if (_activeTab.HeaderExtraContent != null)
{
_activeTab.HeaderExtraContent.SetParent(TabHeaderContentContainer, false);
_activeTab.HeaderExtraContent.gameObject.SetActive(true);
}
}
if (ActiveTabChanged != null)
{
ActiveTabChanged(this, _activeTab);
}
}
private void SortTabs()
{
_tabs.Sort((t1, t2) => t1.SortIndex.CompareTo(t2.SortIndex));
for (var i = 0; i < _tabs.Count; i++)
{
if (_tabs[i].TabButton != null)
{
_tabs[i].TabButton.CachedTransform.SetSiblingIndex(i);
}
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 035be48566f8a3a4285521c6480d83ce
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,153 @@
using System;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace SRDebugger.UI.Other
{
/// <summary>
///
/// </summary>
[RequireComponent(typeof(RectTransform))]
[ExecuteInEditMode]
public class SafeAreaSizer : UIBehaviour, ILayoutElement
{
public RectTransform.Edge Edge
{
get { return _edge; }
set
{
if (_edge != value)
{
_edge = value;
LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform);
}
}
}
[SerializeField, FormerlySerializedAs("Edge")]
private RectTransform.Edge _edge;
public float Scale = 1f;
private float _height;
private float _width;
public float preferredWidth
{
get
{
return _width;
}
}
public float preferredHeight
{
get
{
return _height;
}
}
public float minWidth
{
get
{
return _width;
}
}
public float minHeight
{
get
{
return _height;
}
}
public int layoutPriority
{
get { return 2; }
}
public float flexibleHeight
{
get { return -1; }
}
public float flexibleWidth
{
get { return -1; }
}
#if UNITY_EDITOR
protected override void OnValidate()
{
base.OnValidate();
if (Application.isPlaying)
{
Refresh();
}
}
void Update()
{
_width = _height = 0;
}
#endif
void Refresh()
{
// Determine the distance in local coords
Rect safeArea = Screen.safeArea;
Canvas myCanvas = GetComponentInParent<Canvas>();
if (myCanvas == null)
{
return;
}
RectTransform canvasRect = myCanvas.GetComponent<RectTransform>();
// RectTransformUtility.PixelAdjustRect()
_width = _height = 0;
switch (_edge)
{
case RectTransform.Edge.Left:
_width = (safeArea.x / myCanvas.pixelRect.width) * canvasRect.rect.width;
break;
case RectTransform.Edge.Right:
_width = (Screen.width - safeArea.width - safeArea.x) / myCanvas.pixelRect.width * canvasRect.rect.width;
break;
case RectTransform.Edge.Top:
_height = (Screen.height - safeArea.height - safeArea.y) / myCanvas.pixelRect.height * canvasRect.rect.height;
break;
case RectTransform.Edge.Bottom:
_height = (safeArea.y / myCanvas.pixelRect.height) * canvasRect.rect.height;
break;
default:
throw new ArgumentOutOfRangeException();
}
_width *= Scale;
_height *= Scale;
}
public void CalculateLayoutInputHorizontal()
{
if (Application.isPlaying)
{
Refresh();
}
}
public void CalculateLayoutInputVertical()
{
if (Application.isPlaying)
{
Refresh();
}
}
}
}

View File

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

View File

@@ -0,0 +1,4 @@
/*
* This file has been deleted.
* This empty file is left here to ensure it is properly overwritten when importing a new version of the package over an old version.
*/

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: ec8340b6e7293114da3d567338dc8e9f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,23 @@
namespace SRDebugger.UI.Other
{
using UnityEngine;
using UnityEngine.UI;
[RequireComponent(typeof (ScrollRect))]
public class ScrollSettingsBehaviour : MonoBehaviour
{
public const float ScrollSensitivity = 40f;
private void Awake()
{
var scrollRect = GetComponent<ScrollRect>();
scrollRect.scrollSensitivity = ScrollSensitivity;
if (!Internal.SRDebuggerUtil.IsMobilePlatform)
{
scrollRect.movementType = ScrollRect.MovementType.Clamped;
scrollRect.inertia = false;
}
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6f0ff44b792ef2042856036000e22450
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,12 @@
namespace SRDebugger.UI.Other
{
using SRF;
public class SetLayerFromSettings : SRMonoBehaviour
{
private void Start()
{
gameObject.SetLayerRecursive(Settings.Instance.DebugLayer);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 40436e7c301de034f916ee1e7ddabeeb
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,21 @@
namespace SRDebugger.UI.Other
{
using Controls;
using SRF;
using SRF.UI;
using UnityEngine;
using UnityEngine.Serialization;
public class TriggerRoot : SRMonoBehaviourEx
{
[RequiredField] public Canvas Canvas;
[RequiredField] public LongPressButton TapHoldButton;
[RequiredField] public RectTransform TriggerTransform;
[RequiredField] public ErrorNotifier ErrorNotifier;
[RequiredField] [FormerlySerializedAs("TriggerButton")] public MultiTapButton TripleTapButton;
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: e511950015658d545aa9d10a45550b11
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,19 @@
namespace SRDebugger.UI.Other
{
using SRF;
using UnityEngine.UI;
public class VersionTextBehaviour : SRMonoBehaviourEx
{
public string Format = "SRDebugger {0}";
[RequiredField] public Text Text;
protected override void Start()
{
base.Start();
Text.text = string.Format(Format, SRDebug.Version);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: bc11b0e922d02a54fa6197856eee3976
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,5 @@
fileFormatVersion: 2
guid: e8e391e4f3003d641aaae5d4046e75f3
folderAsset: yes
DefaultImporter:
userData:

View File

@@ -0,0 +1,45 @@
using SRF.Service;
namespace SRDebugger.UI.Tabs
{
using Services;
using Other;
using SRF;
using UnityEngine;
public class BugReportTabController : SRMonoBehaviourEx, IEnableTab
{
[RequiredField] public BugReportSheetController BugReportSheetPrefab;
[RequiredField] public RectTransform Container;
public bool IsEnabled
{
get { return SRServiceManager.GetService<IBugReportService>().IsUsable; }
}
protected override void Start()
{
base.Start();
var sheet = SRInstantiate.Instantiate(BugReportSheetPrefab);
sheet.IsCancelButtonEnabled = false;
// Callbacks when taking screenshot will hide the debug panel so it is not present in the image
sheet.TakingScreenshot = TakingScreenshot;
sheet.ScreenshotComplete = ScreenshotComplete;
sheet.CachedTransform.SetParent(Container, false);
}
private void TakingScreenshot()
{
SRDebug.Instance.HideDebugPanel();
}
private void ScreenshotComplete()
{
SRDebug.Instance.ShowDebugPanel(false);
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 6739582ce86516749a398ff57c5ca282
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,410 @@
//#define SR_CONSOLE_DEBUG
using System.Collections;
namespace SRDebugger.UI.Tabs
{
using System;
using Controls;
using Internal;
using Services;
using SRF;
using UnityEngine;
using UnityEngine.UI;
public class ConsoleTabController : SRMonoBehaviourEx
{
private const int MaxLength = 2600;
private Canvas _consoleCanvas;
private bool _isDirty;
private static bool _hasWarnedAboutLogHandler;
private static bool _hasWarnedAboutLoggingDisabled;
[Import]
public IConsoleFilterState FilterState;
[RequiredField]
public ConsoleLogControl ConsoleLogControl;
[RequiredField]
public Toggle PinToggle;
//public bool IsListening = true;
[RequiredField]
public ScrollRect StackTraceScrollRect;
[RequiredField]
public Text StackTraceText;
[RequiredField]
public Toggle ToggleErrors;
[RequiredField]
public Text ToggleErrorsText;
[RequiredField]
public Toggle ToggleInfo;
[RequiredField]
public Text ToggleInfoText;
[RequiredField]
public Toggle ToggleWarnings;
[RequiredField]
public Text ToggleWarningsText;
[RequiredField]
public GameObject CopyToClipboardContainer;
[RequiredField]
public GameObject CopyToClipboardButton;
[RequiredField]
public GameObject CopyToClipboardMessage;
[RequiredField]
public CanvasGroup CopyToClipboardMessageCanvasGroup;
[RequiredField]
public GameObject LoggingIsDisabledCanvasGroup;
[RequiredField]
public GameObject LogHandlerHasBeenOverridenGroup;
[RequiredField]
public Toggle FilterToggle;
[RequiredField]
public InputField FilterField;
[RequiredField]
public GameObject FilterBarContainer;
private ConsoleEntry _selectedItem;
private Coroutine _fadeButtonCoroutine;
protected override void Start()
{
base.Start();
_consoleCanvas = GetComponent<Canvas>();
ToggleErrors.isOn = FilterState.GetConsoleFilterState(LogType.Error);
ToggleWarnings.isOn = FilterState.GetConsoleFilterState(LogType.Warning);
ToggleInfo.isOn = FilterState.GetConsoleFilterState(LogType.Log);
ToggleErrors.onValueChanged.AddListener(isOn =>
{
FilterState.SetConsoleFilterState(LogType.Error, isOn);
_isDirty = true;
});
ToggleWarnings.onValueChanged.AddListener(isOn =>
{
FilterState.SetConsoleFilterState(LogType.Warning, isOn);
_isDirty = true;
});
ToggleInfo.onValueChanged.AddListener(isOn =>
{
FilterState.SetConsoleFilterState(LogType.Log, isOn);
_isDirty = true;
});
PinToggle.onValueChanged.AddListener(PinToggleValueChanged);
FilterToggle.onValueChanged.AddListener(FilterToggleValueChanged);
FilterBarContainer.SetActive(FilterToggle.isOn);
#if UNITY_5_3_OR_NEWER
FilterField.onValueChanged.AddListener(FilterValueChanged);
#else
FilterField.onValueChange.AddListener(FilterValueChanged);
#endif
ConsoleLogControl.SelectedItemChanged = ConsoleLogSelectedItemChanged;
Service.Console.Updated += ConsoleOnUpdated;
Service.Panel.VisibilityChanged += PanelOnVisibilityChanged;
FilterState.FilterStateChange += OnFilterStateChange;
StackTraceText.supportRichText = Settings.Instance.RichTextInConsole;
PopulateStackTraceArea(null);
Refresh();
}
private void OnFilterStateChange(LogType logtype, bool newstate)
{
switch (logtype)
{
case LogType.Error:
ToggleErrors.isOn = newstate;
break;
case LogType.Warning:
ToggleWarnings.isOn = newstate;
break;
case LogType.Log:
ToggleInfo.isOn = newstate;
break;
}
}
private void FilterToggleValueChanged(bool isOn)
{
if (isOn)
{
FilterBarContainer.SetActive(true);
ConsoleLogControl.Filter = FilterField.text;
}
else
{
ConsoleLogControl.Filter = null;
FilterBarContainer.SetActive(false);
}
}
private void FilterValueChanged(string filterText)
{
if (FilterToggle.isOn && !string.IsNullOrEmpty(filterText) && filterText.Trim().Length != 0)
{
ConsoleLogControl.Filter = filterText;
}
else
{
ConsoleLogControl.Filter = null;
}
}
private void PanelOnVisibilityChanged(IDebugPanelService debugPanelService, bool b)
{
if (_consoleCanvas == null)
{
return;
}
if (b)
{
_consoleCanvas.enabled = true;
}
else
{
_consoleCanvas.enabled = false;
StopAnimations();
}
}
private void PinToggleValueChanged(bool isOn)
{
Service.DockConsole.IsVisible = isOn;
}
protected override void OnDestroy()
{
StopAnimations();
if (Service.Console != null)
{
Service.Console.Updated -= ConsoleOnUpdated;
}
FilterState.FilterStateChange -= OnFilterStateChange;
base.OnDestroy();
}
protected override void OnEnable()
{
base.OnEnable();
_isDirty = true;
}
protected override void OnDisable()
{
base.OnDisable();
StopAnimations();
}
private void ConsoleLogSelectedItemChanged(object item)
{
var log = item as ConsoleEntry;
PopulateStackTraceArea(log);
}
protected override void Update()
{
base.Update();
if (_isDirty)
{
Refresh();
}
}
private void PopulateStackTraceArea(ConsoleEntry entry)
{
if (entry == null)
{
SetCopyToClipboardButtonState(CopyToClipboardStates.Hidden);
StackTraceText.text = "";
}
else
{
if (SRDebug.CopyConsoleItemCallback != null)
{
SetCopyToClipboardButtonState(CopyToClipboardStates.Visible);
}
var text = entry.Message + Environment.NewLine +
(!string.IsNullOrEmpty(entry.StackTrace)
? entry.StackTrace
: SRDebugStrings.Current.Console_NoStackTrace);
if (text.Length > MaxLength)
{
text = text.Substring(0, MaxLength);
text += "\n" + SRDebugStrings.Current.Console_MessageTruncated;
}
StackTraceText.text = text;
}
StackTraceScrollRect.normalizedPosition = new Vector2(0, 1);
_selectedItem = entry;
}
public void CopyToClipboard()
{
if (_selectedItem != null)
{
SetCopyToClipboardButtonState(CopyToClipboardStates.Activated);
if (SRDebug.CopyConsoleItemCallback != null)
{
SRDebug.CopyConsoleItemCallback(_selectedItem);
}
else
{
Debug.LogError("[SRDebugger] Copy to clipboard is not available.");
}
}
}
public enum CopyToClipboardStates
{
Hidden,
Visible,
Activated
}
void SetCopyToClipboardButtonState(CopyToClipboardStates state)
{
StopAnimations();
switch (state)
{
case CopyToClipboardStates.Hidden:
CopyToClipboardContainer.SetActive(false);
CopyToClipboardButton.SetActive(false);
CopyToClipboardMessage.SetActive(false);
break;
case CopyToClipboardStates.Visible:
CopyToClipboardContainer.SetActive(true);
CopyToClipboardButton.SetActive(true);
CopyToClipboardMessage.SetActive(false);
break;
case CopyToClipboardStates.Activated:
CopyToClipboardMessageCanvasGroup.alpha = 1;
CopyToClipboardContainer.SetActive(true);
CopyToClipboardButton.SetActive(false);
CopyToClipboardMessage.SetActive(true);
_fadeButtonCoroutine = StartCoroutine(FadeCopyButton());
break;
default:
throw new ArgumentOutOfRangeException("state", state, null);
}
}
IEnumerator FadeCopyButton()
{
yield return new WaitForSecondsRealtime(2f);
float startTime = Time.realtimeSinceStartup;
float endTime = Time.realtimeSinceStartup + 1f;
while (Time.realtimeSinceStartup < endTime)
{
float currentAlpha = Mathf.InverseLerp(endTime, startTime, Time.realtimeSinceStartup);
CopyToClipboardMessageCanvasGroup.alpha = currentAlpha;
yield return new WaitForEndOfFrame();
}
CopyToClipboardMessageCanvasGroup.alpha = 0;
_fadeButtonCoroutine = null;
}
void StopAnimations()
{
if (_fadeButtonCoroutine != null)
{
StopCoroutine(_fadeButtonCoroutine);
_fadeButtonCoroutine = null;
CopyToClipboardMessageCanvasGroup.alpha = 0;
}
}
private void Refresh()
{
// Update total counts labels
ToggleInfoText.text = SRDebuggerUtil.GetNumberString(Service.Console.InfoCount, 999, "999+");
ToggleWarningsText.text = SRDebuggerUtil.GetNumberString(Service.Console.WarningCount, 999, "999+");
ToggleErrorsText.text = SRDebuggerUtil.GetNumberString(Service.Console.ErrorCount, 999, "999+");
ConsoleLogControl.ShowErrors = ToggleErrors.isOn;
ConsoleLogControl.ShowWarnings = ToggleWarnings.isOn;
ConsoleLogControl.ShowInfo = ToggleInfo.isOn;
PinToggle.isOn = Service.DockConsole.IsVisible;
_isDirty = false;
if (!_hasWarnedAboutLogHandler && Service.Console.LogHandlerIsOverriden)
{
LogHandlerHasBeenOverridenGroup.SetActive(true);
_hasWarnedAboutLogHandler = true;
}
if (!_hasWarnedAboutLoggingDisabled && !Service.Console.LoggingEnabled)
{
LoggingIsDisabledCanvasGroup.SetActive(true);
}
}
private void ConsoleOnUpdated(IConsoleService console)
{
_isDirty = true;
}
public void Clear()
{
Service.Console.Clear();
_isDirty = true;
}
public void LogHandlerHasBeenOverridenOkayButtonPress()
{
_hasWarnedAboutLogHandler = true;
LogHandlerHasBeenOverridenGroup.SetActive(false);
}
public void LoggingDisableCloseAndIgnorePressed()
{
LoggingIsDisabledCanvasGroup.SetActive(false);
_hasWarnedAboutLoggingDisabled = true;
}
public void LoggingDisableReenablePressed()
{
Service.Console.LoggingEnabled = true;
LoggingIsDisabledCanvasGroup.SetActive(false);
Debug.Log("[SRDebugger] Re-enabled logging.");
}
}
}

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 7b54f4d46edbb634985db4a2fa4ada2f
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

View File

@@ -0,0 +1,145 @@
using SRF.UI;
namespace SRDebugger.UI.Tabs
{
using System.Collections.Generic;
using System.Text;
using Controls;
using Services;
using SRF;
using SRF.Service;
using UnityEngine;
public class InfoTabController : SRMonoBehaviourEx
{
public const char Tick = '\u2713';
public const char Cross = '\u00D7';
public const string NameColor = "#BCBCBC";
private Dictionary<string, InfoBlock> _infoBlocks = new Dictionary<string, InfoBlock>();
[RequiredField] public InfoBlock InfoBlockPrefab;
[RequiredField] public RectTransform LayoutContainer;
[RequiredField] public FlashGraphic ToggleButton;
private bool _updateEveryFrame;
protected override void OnEnable()
{
base.OnEnable();
InternalRefresh();
if (_updateEveryFrame)
{
ToggleButton.FlashAndHoldUntilNextPress();
}
}
public void Refresh()
{
ToggleButton.Flash(); // flash to disable any "press and hold" that is going on
_updateEveryFrame = false;
InternalRefresh();
}
protected override void Update()
{
if (_updateEveryFrame)
{
InternalRefresh();
}
}
public void ActivateRefreshEveryFrame()
{
ToggleButton.FlashAndHoldUntilNextPress();
_updateEveryFrame = true;
InternalRefresh();
}
private void InternalRefresh()
{
var s = SRServiceManager.GetService<ISystemInformationService>();
foreach (var category in s.GetCategories())
{
if (!_infoBlocks.ContainsKey(category))
{
var block = CreateBlock(category);
_infoBlocks.Add(category, block);
}
}
foreach (var kv in _infoBlocks)
{
FillInfoBlock(kv.Value, s.GetInfo(kv.Key));
}
}
private void FillInfoBlock(InfoBlock block, IList<InfoEntry> info)
{
var sb = new StringBuilder();
var maxTitleLength = 0;
foreach (var systemInfo in info)
{
if (systemInfo.Title.Length > maxTitleLength)
{
maxTitleLength = systemInfo.Title.Length;
}
}
maxTitleLength += 2;
var first = true;
foreach (var i in info)
{
if (first)
{
first = false;
}
else
{
sb.AppendLine();
}
sb.Append("<color=");
sb.Append(NameColor);
sb.Append(">");
sb.Append(i.Title);
sb.Append(": ");
sb.Append("</color>");
for (var j = i.Title.Length; j <= maxTitleLength; ++j)
{
sb.Append(' ');
}
if (i.Value is bool)
{
sb.Append((bool) i.Value ? Tick : Cross);
}
else
{
sb.Append(i.Value);
}
}
block.Content.text = sb.ToString();
}
private InfoBlock CreateBlock(string title)
{
var block = SRInstantiate.Instantiate(InfoBlockPrefab);
block.Title.text = title;
block.CachedTransform.SetParent(LayoutContainer, false);
return block;
}
}
}

Some files were not shown because too many files have changed in this diff Show More