mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-09-27 02:36:14 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6739582ce86516749a398ff57c5ca282
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@@ -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.");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b54f4d46edbb634985db4a2fa4ada2f
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b6cf74d4a6343648bbe857301cf1bc8
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@@ -0,0 +1,377 @@
|
||||
using System.Linq;
|
||||
|
||||
namespace SRDebugger.UI.Tabs
|
||||
{
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using Controls;
|
||||
using Controls.Data;
|
||||
using Internal;
|
||||
using Other;
|
||||
using Services;
|
||||
using SRF;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class OptionsTabController : SRMonoBehaviourEx
|
||||
{
|
||||
private class CategoryInstance
|
||||
{
|
||||
public CategoryGroup CategoryGroup { get; private set; }
|
||||
public readonly List<OptionsControlBase> Options = new List<OptionsControlBase>();
|
||||
|
||||
public CategoryInstance(CategoryGroup group)
|
||||
{
|
||||
CategoryGroup = group;
|
||||
}
|
||||
}
|
||||
|
||||
private readonly List<OptionsControlBase> _controls = new List<OptionsControlBase>();
|
||||
private readonly List<CategoryInstance> _categories = new List<CategoryInstance>();
|
||||
|
||||
private readonly Dictionary<OptionDefinition, OptionsControlBase> _options =
|
||||
new Dictionary<OptionDefinition, OptionsControlBase>();
|
||||
|
||||
private bool _queueRefresh;
|
||||
private bool _selectionModeEnabled;
|
||||
private Canvas _optionCanvas;
|
||||
|
||||
[RequiredField] public ActionControl ActionControlPrefab;
|
||||
|
||||
[RequiredField] public CategoryGroup CategoryGroupPrefab;
|
||||
|
||||
[RequiredField] public RectTransform ContentContainer;
|
||||
|
||||
[RequiredField] public GameObject NoOptionsNotice;
|
||||
|
||||
[RequiredField] public Toggle PinButton;
|
||||
|
||||
[RequiredField] public GameObject PinPromptSpacer;
|
||||
|
||||
[RequiredField] public GameObject PinPromptText;
|
||||
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
PinButton.onValueChanged.AddListener(SetSelectionModeEnabled);
|
||||
|
||||
PinPromptText.SetActive(false);
|
||||
//PinPromptSpacer.SetActive(false);
|
||||
|
||||
Populate();
|
||||
|
||||
_optionCanvas = GetComponent<Canvas>();
|
||||
|
||||
Service.Options.OptionsUpdated += OnOptionsUpdated;
|
||||
Service.PinnedUI.OptionPinStateChanged += OnOptionPinnedStateChanged;
|
||||
}
|
||||
|
||||
protected override void OnDestroy()
|
||||
{
|
||||
if (Service.Options != null)
|
||||
{
|
||||
Service.Options.OptionsUpdated -= OnOptionsUpdated;
|
||||
}
|
||||
|
||||
if (Service.PinnedUI != null)
|
||||
{
|
||||
Service.PinnedUI.OptionPinStateChanged -= OnOptionPinnedStateChanged;
|
||||
}
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
|
||||
private void OnOptionPinnedStateChanged(OptionDefinition optionDefinition, bool isPinned)
|
||||
{
|
||||
if (_options.ContainsKey(optionDefinition))
|
||||
{
|
||||
_options[optionDefinition].IsSelected = isPinned;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnOptionsUpdated(object sender, EventArgs eventArgs)
|
||||
{
|
||||
Clear();
|
||||
Populate();
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
|
||||
Service.Panel.VisibilityChanged += PanelOnVisibilityChanged;
|
||||
}
|
||||
|
||||
protected override void OnDisable()
|
||||
{
|
||||
// Always end pinning mode when tabbing away
|
||||
SetSelectionModeEnabled(false);
|
||||
|
||||
if (Service.Panel != null)
|
||||
{
|
||||
Service.Panel.VisibilityChanged -= PanelOnVisibilityChanged;
|
||||
}
|
||||
|
||||
base.OnDisable();
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (_queueRefresh)
|
||||
{
|
||||
_queueRefresh = false;
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void PanelOnVisibilityChanged(IDebugPanelService debugPanelService, bool b)
|
||||
{
|
||||
// Always end pinning mode when panel is closed
|
||||
if (!b)
|
||||
{
|
||||
SetSelectionModeEnabled(false);
|
||||
|
||||
// Refresh bindings for all pinned controls
|
||||
Refresh();
|
||||
}
|
||||
else if (b && CachedGameObject.activeInHierarchy)
|
||||
{
|
||||
// If the panel is visible, and this tab is active (selected), refresh all the data bindings
|
||||
Refresh();
|
||||
}
|
||||
|
||||
if (_optionCanvas != null)
|
||||
{
|
||||
_optionCanvas.enabled = b;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSelectionModeEnabled(bool isEnabled)
|
||||
{
|
||||
if (_selectionModeEnabled == isEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_selectionModeEnabled = isEnabled;
|
||||
|
||||
PinButton.isOn = isEnabled;
|
||||
PinPromptText.SetActive(isEnabled);
|
||||
//PinPromptSpacer.SetActive(isEnabled);
|
||||
|
||||
foreach (var kv in _options)
|
||||
{
|
||||
kv.Value.SelectionModeEnabled = isEnabled;
|
||||
|
||||
// Set IsSelected if entering selection mode.
|
||||
if (isEnabled)
|
||||
{
|
||||
kv.Value.IsSelected = Service.PinnedUI.HasPinned(kv.Key);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var cat in _categories)
|
||||
{
|
||||
cat.CategoryGroup.SelectionModeEnabled = isEnabled;
|
||||
}
|
||||
|
||||
RefreshCategorySelection();
|
||||
|
||||
// Return if entering selection mode
|
||||
if (isEnabled)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
for (var i = 0; i < _options.Count; i++)
|
||||
{
|
||||
_controls[i].Refresh();
|
||||
_controls[i].SelectionModeEnabled = _selectionModeEnabled;
|
||||
_controls[i].IsSelected = Service.PinnedUI.HasPinned(_controls[i].Option);
|
||||
}
|
||||
}
|
||||
|
||||
private void CommitPinnedOptions()
|
||||
{
|
||||
foreach (var kv in _options)
|
||||
{
|
||||
var control = kv.Value;
|
||||
|
||||
if (control.IsSelected && !Service.PinnedUI.HasPinned(kv.Key))
|
||||
{
|
||||
Service.PinnedUI.Pin(kv.Key);
|
||||
}
|
||||
else if (!control.IsSelected && Service.PinnedUI.HasPinned(kv.Key))
|
||||
{
|
||||
Service.PinnedUI.Unpin(kv.Key);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private bool _isTogglingCategory;
|
||||
|
||||
private void RefreshCategorySelection()
|
||||
{
|
||||
_isTogglingCategory = true;
|
||||
|
||||
foreach (var cat in _categories)
|
||||
{
|
||||
var allSelected = true;
|
||||
|
||||
for (var i = 0; i < cat.Options.Count; i++)
|
||||
{
|
||||
if (!cat.Options[i].IsSelected)
|
||||
{
|
||||
allSelected = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cat.CategoryGroup.IsSelected = allSelected;
|
||||
}
|
||||
|
||||
_isTogglingCategory = false;
|
||||
}
|
||||
|
||||
private void OnOptionSelectionToggle(bool selected)
|
||||
{
|
||||
if (!_isTogglingCategory)
|
||||
{
|
||||
RefreshCategorySelection();
|
||||
CommitPinnedOptions();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When a category mode selection is changed.
|
||||
/// </summary>
|
||||
/// <param name="category"></param>
|
||||
/// <param name="selected"></param>
|
||||
private void OnCategorySelectionToggle(CategoryInstance category, bool selected)
|
||||
{
|
||||
_isTogglingCategory = true;
|
||||
|
||||
for (var i = 0; i < category.Options.Count; i++)
|
||||
{
|
||||
category.Options[i].IsSelected = selected;
|
||||
}
|
||||
|
||||
_isTogglingCategory = false;
|
||||
|
||||
CommitPinnedOptions();
|
||||
}
|
||||
|
||||
#region Initialisation
|
||||
|
||||
protected void Populate()
|
||||
{
|
||||
var sortedOptions = new Dictionary<string, List<OptionDefinition>>();
|
||||
|
||||
foreach (var option in Service.Options.Options)
|
||||
{
|
||||
if (!OptionControlFactory.CanCreateControl(option))
|
||||
{
|
||||
if (option.IsProperty)
|
||||
{
|
||||
Debug.LogError("[SRDebugger.OptionsTab] Unsupported property type: {0} (on property {1})".Fmt(option.Property.PropertyType, option.Property));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("[SRDebugger.OptionsTab] Unsupported method signature: {0}".Fmt(option.Name));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
// Find a properly list for that category, or create a new one
|
||||
List<OptionDefinition> memberList;
|
||||
|
||||
if (!sortedOptions.TryGetValue(option.Category, out memberList))
|
||||
{
|
||||
memberList = new List<OptionDefinition>();
|
||||
sortedOptions.Add(option.Category, memberList);
|
||||
}
|
||||
|
||||
memberList.Add(option);
|
||||
}
|
||||
|
||||
var hasCreated = false;
|
||||
|
||||
foreach (var kv in sortedOptions.OrderBy(p => p.Key))
|
||||
{
|
||||
if (kv.Value.Count == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
hasCreated = true;
|
||||
CreateCategory(kv.Key, kv.Value);
|
||||
}
|
||||
|
||||
if (hasCreated)
|
||||
{
|
||||
NoOptionsNotice.SetActive(false);
|
||||
}
|
||||
|
||||
RefreshCategorySelection();
|
||||
}
|
||||
|
||||
protected void CreateCategory(string title, List<OptionDefinition> options)
|
||||
{
|
||||
options.Sort((d1, d2) => d1.SortPriority.CompareTo(d2.SortPriority));
|
||||
|
||||
var groupInstance = SRInstantiate.Instantiate(CategoryGroupPrefab);
|
||||
var categoryInstance = new CategoryInstance(groupInstance);
|
||||
|
||||
_categories.Add(categoryInstance);
|
||||
|
||||
groupInstance.CachedTransform.SetParent(ContentContainer, false);
|
||||
groupInstance.Header.text = title;
|
||||
groupInstance.SelectionModeEnabled = _selectionModeEnabled;
|
||||
|
||||
categoryInstance.CategoryGroup.SelectionToggle.onValueChanged.AddListener(
|
||||
b => OnCategorySelectionToggle(categoryInstance, b));
|
||||
|
||||
foreach (var option in options)
|
||||
{
|
||||
var control = OptionControlFactory.CreateControl(option, title);
|
||||
|
||||
if (control == null)
|
||||
{
|
||||
Debug.LogError("[SRDebugger.OptionsTab] Failed to create option control for {0}".Fmt(option.Name));
|
||||
continue;
|
||||
}
|
||||
|
||||
categoryInstance.Options.Add(control);
|
||||
control.CachedTransform.SetParent(groupInstance.Container, false);
|
||||
control.IsSelected = Service.PinnedUI.HasPinned(option);
|
||||
control.SelectionModeEnabled = _selectionModeEnabled;
|
||||
control.SelectionModeToggle.onValueChanged.AddListener(OnOptionSelectionToggle);
|
||||
|
||||
_options.Add(option, control);
|
||||
_controls.Add(control);
|
||||
}
|
||||
}
|
||||
|
||||
void Clear()
|
||||
{
|
||||
foreach (var categoryInstance in _categories)
|
||||
{
|
||||
Destroy(categoryInstance.CategoryGroup.gameObject);
|
||||
}
|
||||
|
||||
_categories.Clear();
|
||||
_controls.Clear();
|
||||
_options.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 977db337f5942e64aa7b62fc1ca01e28
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
@@ -0,0 +1,49 @@
|
||||
//#define SR_CONSOLE_DEBUG
|
||||
|
||||
namespace SRDebugger.UI.Tabs
|
||||
{
|
||||
using SRF;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ProfilerTabController : SRMonoBehaviourEx
|
||||
{
|
||||
private bool _isDirty;
|
||||
|
||||
[RequiredField] public Toggle PinToggle;
|
||||
|
||||
protected override void Start()
|
||||
{
|
||||
base.Start();
|
||||
|
||||
PinToggle.onValueChanged.AddListener(PinToggleValueChanged);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void PinToggleValueChanged(bool isOn)
|
||||
{
|
||||
SRDebug.Instance.IsProfilerDocked = isOn;
|
||||
}
|
||||
|
||||
protected override void OnEnable()
|
||||
{
|
||||
base.OnEnable();
|
||||
_isDirty = true;
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (_isDirty)
|
||||
{
|
||||
Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
PinToggle.isOn = SRDebug.Instance.IsProfilerDocked;
|
||||
_isDirty = false;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f26b5a0018be8444fb0a18037b471f65
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
Reference in New Issue
Block a user