maint: added livewatch asset
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"name": "LivewWatch.Editor",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8bae3fcddb249414ead59707780b36ca"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f48d2c511c057542be4107c51af6208
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/LiveWatch.Editor.asmdef
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,59 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class MenuWatchScriptTemplateCreator
|
||||
{
|
||||
[MenuItem("Assets/Create/LiveWatch/WatchManagerScript", false)]
|
||||
public static void CreateWatchTemplates()
|
||||
{
|
||||
ProjectWindowUtil.CreateAssetWithContent("WatchManager.cs",
|
||||
@"using Ingvar.LiveWatch;
|
||||
using UnityEngine;
|
||||
|
||||
// Don't forget to attach this script to some object on your scene
|
||||
public class WatchManager : MonoBehaviour
|
||||
{
|
||||
private static WatchManager _instance;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
// Single instance check + preserve between scenes. Remove if not needed
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
// All new watches must be added only AFTER this call
|
||||
// You can remove this call if you want to preserve watch data from the previous session
|
||||
Watch.DestroyAll();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// You can declare new watches here or anywhere else in project
|
||||
|
||||
// Auto watch example (SetAlwaysCollapsable() is needed to prevent spamming)
|
||||
Watch.GetOrAdd(""Frame"", () => Time.frameCount).SetAlwaysCollapsable();
|
||||
|
||||
// Manual watch example
|
||||
Watch.Push(""Log"", ""Hello World!"");
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
// All manual watch Push() methods in project must be called BEFORE this call
|
||||
// Updates ALL auto watches in project. Avoid calling more than once per update
|
||||
Watch.UpdateAll();
|
||||
}
|
||||
}"
|
||||
, EditorGUIUtility.IconContent("cs Script Icon").image as Texture2D);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 578e5063a0304d50bd50cca0d7cc7ca3
|
||||
timeCreated: 1726154897
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/MenuWatchScriptTemplateCreator.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8684acd3a5444a97a7f9371e2f3cb1d8
|
||||
timeCreated: 1637702019
|
||||
@@ -0,0 +1,76 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class Colors
|
||||
{
|
||||
public static readonly Color Background;
|
||||
public static readonly Color BackgroundOdd;
|
||||
|
||||
public static readonly Color SegmentFrame;
|
||||
public static readonly Color SegmentFrameInner;
|
||||
public static readonly Color SegmentFill;
|
||||
public static readonly Color SegmentFillOdd;
|
||||
public static readonly Color GraphFill;
|
||||
public static readonly Color GraphFillOdd;
|
||||
public static readonly Color GraphLine;
|
||||
public static readonly Color GraphLineSearch;
|
||||
|
||||
public static readonly Color CellDivider;
|
||||
public static readonly Color CellBackgroundSelected;
|
||||
public static readonly Color CellBackgroundSelectedGraph;
|
||||
public static readonly Color CellSelectionLine;
|
||||
public static readonly Color CellSelectionLineGraph;
|
||||
|
||||
public static readonly Color MetaInfoLine;
|
||||
public static readonly Color ExtraTextLineGraph;
|
||||
|
||||
public static readonly Color32 PreviewCellEmpty;
|
||||
public static readonly Color32 PreviewCellHasValue;
|
||||
public static readonly Color32 PreviewCellHasValueOdd;
|
||||
public static readonly Color32 PreviewCellOriginal;
|
||||
public static readonly Color32 PreviewCellOriginalOdd;
|
||||
public static readonly Color32 PreviewCellSearched;
|
||||
public static readonly Color32 PreviewCellSearchedOdd;
|
||||
public static readonly Color32 PreviewCellSearchedOriginal;
|
||||
public static readonly Color32 PreviewCellSearchedOriginalOdd;
|
||||
public static readonly Color32 PreviewOriginalEdge;
|
||||
|
||||
static Colors()
|
||||
{
|
||||
Background = EditorGUIUtility.isProSkin ? new Color32 (56, 56, 56, 255) : new Color32 (194, 194, 194, 255);
|
||||
BackgroundOdd = Background + new Color32(6, 6, 6, 0);
|
||||
|
||||
SegmentFrame = EditorGUIUtility.isProSkin ? new Color32(80, 80, 80, 255) : new Color32(130, 130, 130, 255);
|
||||
SegmentFrameInner = EditorGUIUtility.isProSkin ? new Color32(90, 90, 90, 40) : new Color32(140, 140, 140, 255);
|
||||
SegmentFill = EditorGUIUtility.isProSkin ? new Color32(70, 70, 70, 255) : new Color32(160, 160, 160, 255);
|
||||
SegmentFillOdd = SegmentFill + new Color32(6, 6, 6, 0);
|
||||
|
||||
GraphFill = EditorGUIUtility.isProSkin ? new Color32(80, 80, 80, 255) : new Color32(170, 170, 170, 255);
|
||||
GraphFillOdd = SegmentFill + new Color32(6, 6, 6, 0);
|
||||
GraphLine = EditorGUIUtility.isProSkin ? new Color32(100, 100, 100, 255) : new Color32(140, 140, 140, 255);
|
||||
GraphLineSearch = new Color32(0, 100, 150, 255);
|
||||
|
||||
CellDivider = new Color32(90, 90, 90, 100);
|
||||
CellBackgroundSelected = EditorGUIUtility.isProSkin ? new Color32(100, 100, 100, 200) : new Color32(150, 150, 150, 200);;
|
||||
CellBackgroundSelectedGraph = EditorGUIUtility.isProSkin ? new Color32(120, 120, 120, 175) : new Color32(140, 140, 140, 225);;
|
||||
CellSelectionLine = new Color32(0, 100, 150, 255);
|
||||
CellSelectionLineGraph = new Color32(0, 100, 200, 100);
|
||||
|
||||
MetaInfoLine = EditorGUIUtility.isProSkin ? new Color32(150, 150, 150, 255) : new Color32(255, 255, 255, 255);
|
||||
ExtraTextLineGraph = EditorGUIUtility.isProSkin ? new Color32(170, 170, 170, 255) : new Color32(255, 255, 255, 255);
|
||||
|
||||
PreviewCellEmpty = new Color32(0, 0, 0, 0);
|
||||
PreviewOriginalEdge = new Color32(50, 50, 50, 80);
|
||||
PreviewCellHasValue = new Color32(60, 60, 60, 80);
|
||||
PreviewCellHasValueOdd = new Color32(70, 70, 70, 80);
|
||||
PreviewCellOriginal = new Color32(100, 100, 100, 80);
|
||||
PreviewCellOriginalOdd = new Color32(110, 110, 110, 80);
|
||||
PreviewCellSearched = new Color32(0, 150, 250, 30);
|
||||
PreviewCellSearchedOdd = new Color32(0, 160, 255, 35);
|
||||
PreviewCellSearchedOriginal = new Color32(0, 150, 250, 50);
|
||||
PreviewCellSearchedOriginalOdd = new Color32(0, 160, 255, 55);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c4130c7ebfa04ea8aff82105dedcbfaa
|
||||
timeCreated: 1637702036
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Predefined/Colors.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,60 @@
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class Constants
|
||||
{
|
||||
public const float MouseScrollbarMultiplier = 10;
|
||||
|
||||
public const float ToolbarAreaHeight = 20;
|
||||
public const float ToolbarClearButtonWidth = 50;
|
||||
public const float ToolbarLiveButtonWidth = 50;
|
||||
public const float ToolbarCollapseButtonWidth = 60;
|
||||
public const float ToolbarSearchButtonWidth = 60;
|
||||
public const float ToolbarSaveButtonWidth = 30;
|
||||
public const float ToolbarLoadButtonWidth = 30;
|
||||
public const float ToolbarOptionsButtonWidth = 30;
|
||||
public const float ToolbarViewButtonWidth = 50;
|
||||
|
||||
public const float SearchAreaMinHeight = 46;
|
||||
public const float SearchToolbarHeight = 20;
|
||||
public const float SearchToolbarProgressBarMinWidth = 40;
|
||||
public const float SearchToolbarAddWidth = 50;
|
||||
public const float SearchToolbarRunWidth = 60;
|
||||
public const float SearchToolbarAutoRunWidth = 60;
|
||||
public const float SearchToolbarSpaceWidth = 40;
|
||||
public const float SearchToolbarMoveWidth = 20;
|
||||
public const float SearchLineHeight = 20;
|
||||
public const float SearchConnectiveWidth = 50;
|
||||
public const float SearchInvertWidth = 40;
|
||||
public const float SearchTargetWidth = 55;
|
||||
public const float SearchValueWidth = 70;
|
||||
public const float SearchOperatorWidth = 115;
|
||||
public const float SearchQueryMinWidth = 60;
|
||||
public const float SearchCaseWidth = 50;
|
||||
public const float SearchDeleteWidth = 20;
|
||||
|
||||
public const float VariablesAreaMinHeight = 100;
|
||||
public const float VariableLabelMinWidth = 100;
|
||||
public const float VariableLabelIndentWidth = 25;
|
||||
public const float VariableValuesMinWidth = 100;
|
||||
public const float VariableRowHeight = 30;
|
||||
public const float VariableRowHeighMin = 17;
|
||||
public const float VariableRowHeightMax = 80;
|
||||
public const float VariableValueColumnWidth = 30;
|
||||
public const float VariableValueColumnWidthMin = 1;
|
||||
public const float VariableValueColumnWidthMax = 120;
|
||||
public const float VariableLabelOffset = 10;
|
||||
public const float VariableSelectionLineMinWidth = 3;
|
||||
public const float VariableGraphMinValueHeight = 10;
|
||||
|
||||
public const float VerticalScrollWidth = 15;
|
||||
public const float HorizontalScrollHeight = 15;
|
||||
|
||||
public const float InfoAreaMinHeight = 60;
|
||||
public const float InfoHeaderCopyButtonWidth = 50;
|
||||
|
||||
|
||||
public const int VariableValueFontSize = 11;
|
||||
public const int VariableSelectedValueFontSize = 11;
|
||||
public const int VariableGraphMinMaxFontSize = 10;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cd6b300b538a48c8a0973096e5f4f19f
|
||||
timeCreated: 1636230183
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Predefined/Constants.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,97 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class Styles
|
||||
{
|
||||
public static readonly GUIStyle VariableLabel;
|
||||
public static readonly GUIStyle VariableFoldoutLabel;
|
||||
public static readonly GUIStyle VariableGraphMaxLabel;
|
||||
public static readonly GUIStyle VariableGraphMinLabel;
|
||||
|
||||
public static readonly GUIStyle VariableValue;
|
||||
public static readonly GUIStyle VariableValueSelected;
|
||||
public static readonly GUIStyle VariableValueLeft;
|
||||
public static readonly GUIStyle VariableValueSelectedLeft;
|
||||
|
||||
public static readonly GUIStyle InfoValueText;
|
||||
public static readonly GUIStyle InfoMetaText;
|
||||
public static readonly GUIStyle InfoHeaderFoldout;
|
||||
public static readonly GUIStyle InfoCopyButton;
|
||||
public static readonly GUIStyle InfoCustomButton;
|
||||
|
||||
public static readonly GUIStyle SettingsSubTitleText;
|
||||
|
||||
public static readonly GUIStyle ElementBackground = (GUIStyle) "RL Element";
|
||||
|
||||
static Styles()
|
||||
{
|
||||
VariableLabel = new GUIStyle(EditorStyles.label);
|
||||
VariableFoldoutLabel = new GUIStyle(EditorStyles.foldout);
|
||||
|
||||
VariableGraphMaxLabel = new GUIStyle(new GUIStyle(EditorStyles.label)
|
||||
{
|
||||
alignment = TextAnchor.UpperRight,
|
||||
fontSize = Constants.VariableGraphMinMaxFontSize
|
||||
});
|
||||
|
||||
VariableGraphMinLabel = new GUIStyle(new GUIStyle(EditorStyles.label)
|
||||
{
|
||||
alignment = TextAnchor.LowerRight,
|
||||
fontSize = Constants.VariableGraphMinMaxFontSize
|
||||
});
|
||||
|
||||
VariableValue = new GUIStyle(new GUIStyle(EditorStyles.label)
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontSize = Constants.VariableValueFontSize
|
||||
});
|
||||
|
||||
VariableValueLeft = new GUIStyle(new GUIStyle(EditorStyles.label)
|
||||
{
|
||||
alignment = TextAnchor.MiddleLeft,
|
||||
fontSize = Constants.VariableValueFontSize
|
||||
});
|
||||
|
||||
VariableValueSelected = new GUIStyle(new GUIStyle(EditorStyles.boldLabel)
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter,
|
||||
fontSize = Constants.VariableSelectedValueFontSize
|
||||
});
|
||||
|
||||
VariableValueSelectedLeft = new GUIStyle(new GUIStyle(EditorStyles.boldLabel)
|
||||
{
|
||||
alignment = TextAnchor.MiddleLeft,
|
||||
fontSize = Constants.VariableSelectedValueFontSize
|
||||
});
|
||||
|
||||
InfoValueText = new GUIStyle(EditorStyles.label)
|
||||
{
|
||||
alignment = TextAnchor.UpperLeft,
|
||||
wordWrap = true
|
||||
};
|
||||
InfoMetaText = "CN Message";
|
||||
|
||||
InfoHeaderFoldout = new GUIStyle(EditorStyles.foldout)
|
||||
{
|
||||
fontSize = 10,
|
||||
fontStyle = FontStyle.Italic,
|
||||
};
|
||||
|
||||
InfoCopyButton = new GUIStyle(EditorStyles.toolbarButton)
|
||||
{
|
||||
fixedHeight = 14,
|
||||
fontSize = 10
|
||||
};
|
||||
|
||||
InfoCustomButton = new GUIStyle(GUI.skin.button);
|
||||
|
||||
SettingsSubTitleText = new GUIStyle(EditorStyles.boldLabel)
|
||||
{
|
||||
alignment = TextAnchor.UpperLeft,
|
||||
fontSize = 14,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e1767215ceea4e84913a4a9ecae3bd44
|
||||
timeCreated: 1636575597
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Predefined/Styles.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,304 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class Textures
|
||||
{
|
||||
public static Texture2D Dots => EditorGUIUtility.isProSkin ? WhiteDots : BlackDots;
|
||||
public static Texture2D WhiteDots
|
||||
{
|
||||
get
|
||||
{
|
||||
if (whiteDots != null)
|
||||
return whiteDots;
|
||||
|
||||
whiteDots = new Texture2D(8, 3);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(200, 200, 200, 255);
|
||||
var w2 = new Color32(200, 200, 200, 100);
|
||||
var w3 = new Color32(200, 200, 200, 30);
|
||||
var w4 = new Color32(200, 200, 200, 20);
|
||||
var w5 = new Color32(200, 200, 200, 5);
|
||||
|
||||
whiteDots.SetPixels(new Color[]
|
||||
{
|
||||
e, w5, e, e, e, e, w5, e,
|
||||
w3, w1, w4, e, e, w3, w1, w4,
|
||||
e, w2, e, e, e, e, w2, e,
|
||||
});
|
||||
whiteDots.Apply();
|
||||
|
||||
return whiteDots;
|
||||
}
|
||||
}
|
||||
public static Texture2D BlueDots
|
||||
{
|
||||
get
|
||||
{
|
||||
if (blueDots != null)
|
||||
return blueDots;
|
||||
|
||||
blueDots = new Texture2D(8, 3);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(0, 150, 255, 255);
|
||||
var w2 = new Color32(0, 150, 255, 150);
|
||||
var w3 = new Color32(0, 150, 255, 60);
|
||||
var w4 = new Color32(0, 150, 255, 40);
|
||||
var w5 = new Color32(0, 150, 255, 15);
|
||||
|
||||
blueDots.SetPixels(new Color[]
|
||||
{
|
||||
e, w5, e, e, e, e, w5, e,
|
||||
w3, w1, w4, e, e, w3, w1, w4,
|
||||
e, w2, e, e, e, e, w2, e,
|
||||
});
|
||||
blueDots.Apply();
|
||||
|
||||
return blueDots;
|
||||
}
|
||||
}
|
||||
public static Texture2D BlackDots
|
||||
{
|
||||
get
|
||||
{
|
||||
if (blackDots != null)
|
||||
return blackDots;
|
||||
|
||||
blackDots = new Texture2D(8, 3);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(0, 0, 0, 255);
|
||||
var w2 = new Color32(0, 0, 0, 150);
|
||||
var w3 = new Color32(0, 0, 0, 60);
|
||||
var w4 = new Color32(0, 0, 0, 40);
|
||||
var w5 = new Color32(0, 0, 0, 15);
|
||||
|
||||
blackDots.SetPixels(new Color[]
|
||||
{
|
||||
e, w5, e, e, e, e, w5, e,
|
||||
w3, w1, w4, e, e, w3, w1, w4,
|
||||
e, w2, e, e, e, e, w2, e,
|
||||
});
|
||||
blackDots.Apply();
|
||||
|
||||
return blackDots;
|
||||
}
|
||||
}
|
||||
public static Texture2D WhiteTriangleTopLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
if (whiteTriangleTopLeft != null)
|
||||
return whiteTriangleTopLeft;
|
||||
|
||||
whiteTriangleTopLeft = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(TriangleColor, TriangleColor, TriangleColor, 255);
|
||||
var w2 = new Color32(TriangleColor, TriangleColor, TriangleColor, 150);
|
||||
|
||||
whiteTriangleTopLeft.SetPixels(new Color[]
|
||||
{
|
||||
w2, e, e, e,
|
||||
w1, w2, e, e,
|
||||
w1, w1, w2, e,
|
||||
w1, w1, w1, w2,
|
||||
});
|
||||
whiteTriangleTopLeft.Apply();
|
||||
|
||||
return whiteTriangleTopLeft;
|
||||
}
|
||||
}
|
||||
public static Texture2D WhiteTriangleTopRight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (whiteTriangleTopRight != null)
|
||||
return whiteTriangleTopRight;
|
||||
|
||||
whiteTriangleTopRight = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(TriangleColor, TriangleColor, TriangleColor, 255);
|
||||
var w2 = new Color32(TriangleColor, TriangleColor, TriangleColor, 150);
|
||||
|
||||
whiteTriangleTopRight.SetPixels(new Color[]
|
||||
{
|
||||
e, e, e, w2,
|
||||
e, e, w2, w1,
|
||||
e, w2, w1, w1,
|
||||
w2, w1, w1, w1,
|
||||
});
|
||||
whiteTriangleTopRight.Apply();
|
||||
|
||||
return whiteTriangleTopRight;
|
||||
}
|
||||
}
|
||||
public static Texture2D WhiteTriangleBottomLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
if (whiteTriangleBottomLeft != null)
|
||||
return whiteTriangleBottomLeft;
|
||||
|
||||
whiteTriangleBottomLeft = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(TriangleColor, TriangleColor, TriangleColor, 255);
|
||||
var w2 = new Color32(TriangleColor, TriangleColor, TriangleColor, 150);
|
||||
|
||||
whiteTriangleBottomLeft.SetPixels(new Color[]
|
||||
{
|
||||
w1, w1, w1, w2,
|
||||
w1, w1, w2, e,
|
||||
w1, w2, e, e,
|
||||
w2, e, e, e,
|
||||
});
|
||||
whiteTriangleBottomLeft.Apply();
|
||||
|
||||
return whiteTriangleBottomLeft;
|
||||
}
|
||||
}
|
||||
public static Texture2D WhiteTriangleBottomRight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (whiteTriangleBottomRight != null)
|
||||
return whiteTriangleBottomRight;
|
||||
|
||||
whiteTriangleBottomRight = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(TriangleColor, TriangleColor, TriangleColor, 255);
|
||||
var w2 = new Color32(TriangleColor, TriangleColor, TriangleColor, 150);
|
||||
|
||||
whiteTriangleBottomRight.SetPixels(new Color[]
|
||||
{
|
||||
w2, w1, w1, w1,
|
||||
e, w2, w1, w1,
|
||||
e, e, w2, w1,
|
||||
e, e, e, w2,
|
||||
});
|
||||
whiteTriangleBottomRight.Apply();
|
||||
|
||||
return whiteTriangleBottomRight;
|
||||
}
|
||||
}
|
||||
public static Texture2D BlueTriangleTopLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
if (blueTriangleTopLeft != null)
|
||||
return blueTriangleTopLeft;
|
||||
|
||||
blueTriangleTopLeft = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(0, 150, 255, 255);
|
||||
var w2 = new Color32(0, 150, 255, 150);
|
||||
|
||||
blueTriangleTopLeft.SetPixels(new Color[]
|
||||
{
|
||||
w2, e, e, e,
|
||||
w1, w2, e, e,
|
||||
w1, w1, w2, e,
|
||||
w1, w1, w1, w2,
|
||||
});
|
||||
blueTriangleTopLeft.Apply();
|
||||
|
||||
return blueTriangleTopLeft;
|
||||
}
|
||||
}
|
||||
public static Texture2D BlueTriangleTopRight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (blueTriangleTopRight != null)
|
||||
return blueTriangleTopRight;
|
||||
|
||||
blueTriangleTopRight = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(0, 150, 255, 255);
|
||||
var w2 = new Color32(0, 150, 255, 150);
|
||||
|
||||
blueTriangleTopRight.SetPixels(new Color[]
|
||||
{
|
||||
e, e, e, w2,
|
||||
e, e, w2, w1,
|
||||
e, w2, w1, w1,
|
||||
w2, w1, w1, w1,
|
||||
});
|
||||
blueTriangleTopRight.Apply();
|
||||
|
||||
return blueTriangleTopRight;
|
||||
}
|
||||
}
|
||||
public static Texture2D BlueTriangleBottomLeft
|
||||
{
|
||||
get
|
||||
{
|
||||
if (blueTriangleBottomLeft != null)
|
||||
return blueTriangleBottomLeft;
|
||||
|
||||
blueTriangleBottomLeft = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(0, 150, 255, 255);
|
||||
var w2 = new Color32(0, 150, 255, 150);
|
||||
|
||||
blueTriangleBottomLeft.SetPixels(new Color[]
|
||||
{
|
||||
w1, w1, w1, w2,
|
||||
w1, w1, w2, e,
|
||||
w1, w2, e, e,
|
||||
w2, e, e, e,
|
||||
});
|
||||
blueTriangleBottomLeft.Apply();
|
||||
|
||||
return blueTriangleBottomLeft;
|
||||
}
|
||||
}
|
||||
public static Texture2D BlueTriangleBottomRight
|
||||
{
|
||||
get
|
||||
{
|
||||
if (blueTriangleBottomRight != null)
|
||||
return blueTriangleBottomRight;
|
||||
|
||||
blueTriangleBottomRight = new Texture2D(4, 4, TextureFormat.RGBA32, false);
|
||||
|
||||
var e = new Color32(0, 0, 0, 0);
|
||||
var w1 = new Color32(0, 150, 255, 255);
|
||||
var w2 = new Color32(0, 150, 255, 150);
|
||||
|
||||
blueTriangleBottomRight.SetPixels(new Color[]
|
||||
{
|
||||
w2, w1, w1, w1,
|
||||
e, w2, w1, w1,
|
||||
e, e, w2, w1,
|
||||
e, e, e, w2,
|
||||
});
|
||||
blueTriangleBottomRight.Apply();
|
||||
|
||||
return blueTriangleBottomRight;
|
||||
}
|
||||
}
|
||||
|
||||
private static Texture2D whiteDots;
|
||||
private static Texture2D blackDots;
|
||||
private static Texture2D blueDots;
|
||||
private static Texture2D whiteTriangleTopLeft;
|
||||
private static Texture2D whiteTriangleTopRight;
|
||||
private static Texture2D whiteTriangleBottomLeft;
|
||||
private static Texture2D whiteTriangleBottomRight;
|
||||
private static Texture2D blueTriangleTopLeft;
|
||||
private static Texture2D blueTriangleTopRight;
|
||||
private static Texture2D blueTriangleBottomLeft;
|
||||
private static Texture2D blueTriangleBottomRight;
|
||||
private const byte TriangleColor = 150;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7c71c5a3984d4d18891c622b864c7776
|
||||
timeCreated: 1638208750
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Predefined/Textures.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3062c13d1aa648f59cdd73f33e9360a0
|
||||
timeCreated: 1724579269
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class EventModifiersEditorProperty : EditorProperty<EventModifiers>
|
||||
{
|
||||
public EventModifiersEditorProperty(string key, EventModifiers defaultValue) : base(key, defaultValue)
|
||||
{
|
||||
|
||||
}
|
||||
protected override bool IsEqual(EventModifiers left, EventModifiers right)
|
||||
{
|
||||
return left == right;
|
||||
}
|
||||
|
||||
protected override EventModifiers Load()
|
||||
{
|
||||
return (EventModifiers)EditorPrefs.GetInt(Key);
|
||||
}
|
||||
|
||||
protected override void Save(EventModifiers value)
|
||||
{
|
||||
EditorPrefs.SetInt(Key, (int)value);
|
||||
}
|
||||
|
||||
protected override EditorPropertyDrawer<EventModifiers> GetDrawer()
|
||||
{
|
||||
return new EventModifiersEditorPropertyDrawer(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class EventModifiersEditorPropertyDrawer : EditorPropertyDrawer<EventModifiers>
|
||||
{
|
||||
public EventModifiersEditorPropertyDrawer(EditorProperty<EventModifiers> property) : base(property)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Draw(params GUILayoutOption[] options)
|
||||
{
|
||||
Property.Value = (EventModifiers)EditorGUILayout.EnumFlagsField(Property, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1faf266ff65478a987b67c7b2f064c5
|
||||
timeCreated: 1724871754
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/UserSettings/EventModifiersEditorProperty.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,46 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class KeyCodeEditorProperty : EditorProperty<KeyCode>
|
||||
{
|
||||
public KeyCodeEditorProperty(string key, KeyCode defaultValue) : base(key, defaultValue)
|
||||
{
|
||||
|
||||
}
|
||||
protected override bool IsEqual(KeyCode left, KeyCode right)
|
||||
{
|
||||
return left == right;
|
||||
}
|
||||
|
||||
protected override KeyCode Load()
|
||||
{
|
||||
return (KeyCode)EditorPrefs.GetInt(Key);
|
||||
}
|
||||
|
||||
protected override void Save(KeyCode value)
|
||||
{
|
||||
EditorPrefs.SetInt(Key, (int)value);
|
||||
}
|
||||
|
||||
protected override EditorPropertyDrawer<KeyCode> GetDrawer()
|
||||
{
|
||||
return new KeyEditorPropertyDrawer(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class KeyEditorPropertyDrawer : EditorPropertyDrawer<KeyCode>
|
||||
{
|
||||
public KeyEditorPropertyDrawer(EditorProperty<KeyCode> property) : base(property)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void Draw(params GUILayoutOption[] options)
|
||||
{
|
||||
Property.Value = (KeyCode)EditorGUILayout.EnumPopup(Property, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7b3601a302864c8ca35cb90ea4ec060a
|
||||
timeCreated: 1724923745
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/UserSettings/KeyCodeEditorProperty.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,35 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class UserSettings
|
||||
{
|
||||
private const string PREFIX = "LivwWatch.";
|
||||
|
||||
public static EditorProperty<EventModifiers> WidthZoomKeys = new EventModifiersEditorProperty($"{PREFIX}WidthZoomKeys", EventModifiers.Control);
|
||||
public static EditorProperty<EventModifiers> HeightZoomKeys = new EventModifiersEditorProperty($"{PREFIX}HeightZoomKeys", EventModifiers.Shift);
|
||||
public static EditorProperty<EventModifiers> ScrollValuesKeys = new EventModifiersEditorProperty($"{PREFIX}ScrollValuesKeys", EventModifiers.Alt);
|
||||
|
||||
public static EditorProperty<KeyCode> FlipSelectionKey = new KeyCodeEditorProperty($"{PREFIX}FlipSelectionKey", KeyCode.F);
|
||||
public static EditorProperty<KeyCode> ExpandVariableKey = new KeyCodeEditorProperty($"{PREFIX}ExpandVariableKey", KeyCode.Space);
|
||||
public static EditorProperty<KeyCode> PreviousValueKey = new KeyCodeEditorProperty($"{PREFIX}PreviousValueKey", KeyCode.LeftArrow);
|
||||
public static EditorProperty<KeyCode> NextValueKey = new KeyCodeEditorProperty($"{PREFIX}NextValueKey", KeyCode.RightArrow);
|
||||
public static EditorProperty<KeyCode> PreviousVariableKey = new KeyCodeEditorProperty($"{PREFIX}PreviousVariableKey", KeyCode.UpArrow);
|
||||
public static EditorProperty<KeyCode> NextVariableKey = new KeyCodeEditorProperty($"{PREFIX}NextVariableKey", KeyCode.DownArrow);
|
||||
|
||||
public static void RestoreDefaultValues()
|
||||
{
|
||||
WidthZoomKeys.SetToDefault();
|
||||
HeightZoomKeys.SetToDefault();
|
||||
ScrollValuesKeys.SetToDefault();
|
||||
|
||||
FlipSelectionKey.SetToDefault();
|
||||
ExpandVariableKey.SetToDefault();
|
||||
PreviousValueKey.SetToDefault();
|
||||
NextValueKey.SetToDefault();
|
||||
PreviousVariableKey.SetToDefault();
|
||||
NextVariableKey.SetToDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31eee50e570748d5bd8cdd7b0816ac9e
|
||||
timeCreated: 1724579283
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/UserSettings/UserSettings.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,76 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class UserSettingsProvider
|
||||
{
|
||||
[SettingsProvider]
|
||||
public static SettingsProvider CreateUserSettingsProvider()
|
||||
{
|
||||
var provider = new SettingsProvider("Preferences/Live Watch", SettingsScope.User)
|
||||
{
|
||||
label = "Live Watch",
|
||||
guiHandler = (searchContext) =>
|
||||
{
|
||||
SettingsGUI();
|
||||
},
|
||||
|
||||
keywords = new HashSet<string>(new[] { "Live", "Watch", "LiveWatch" })
|
||||
};
|
||||
|
||||
return provider;
|
||||
}
|
||||
|
||||
private static void SettingsGUI()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
DrawShortcuts();
|
||||
}
|
||||
|
||||
private static void DrawShortcuts()
|
||||
{
|
||||
EditorGUILayout.Space(5);
|
||||
GUILayout.Label("Shortcuts", Styles.SettingsSubTitleText);
|
||||
EditorGUILayout.Space(5);
|
||||
|
||||
ModifierField("Cell Width Zoom In/Out", UserSettings.WidthZoomKeys);
|
||||
ModifierField("Cell Height Zoom In/Out", UserSettings.HeightZoomKeys);
|
||||
ModifierField("Values Scroll", UserSettings.ScrollValuesKeys);
|
||||
GUILayout.Space(5);
|
||||
KeyField("Flip Selection", UserSettings.FlipSelectionKey);
|
||||
KeyField("Expand selected variable", UserSettings.ExpandVariableKey);
|
||||
KeyField("Previous variable", UserSettings.NextVariableKey);
|
||||
KeyField("Next variable", UserSettings.PreviousVariableKey);
|
||||
KeyField("Previous value", UserSettings.PreviousValueKey);
|
||||
KeyField("Next value", UserSettings.NextValueKey);
|
||||
GUILayout.Space(5);
|
||||
|
||||
if (GUILayout.Button("Restore default shortcuts", GUILayout.Width(200)))
|
||||
{
|
||||
UserSettings.RestoreDefaultValues();
|
||||
}
|
||||
|
||||
void ModifierField(string labelText, EditorProperty<EventModifiers> property)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(labelText);
|
||||
property.PropertyDrawer.Draw(GUILayout.Width(100));
|
||||
GUILayout.Space(20);
|
||||
GUILayout.Label("+", EditorStyles.boldLabel, GUILayout.Width(30));
|
||||
GUILayout.Label("Mouse Scroll Up/Down", EditorStyles.label, GUILayout.Width(150));
|
||||
GUILayout.FlexibleSpace();
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
void KeyField(string labelText, EditorProperty<KeyCode> property)
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
EditorGUILayout.PrefixLabel(labelText);
|
||||
property.PropertyDrawer.Draw(GUILayout.Width(100));
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 23db2225b4844147b8eb2afa45b9a830
|
||||
timeCreated: 1724578679
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/UserSettings/UserSettingsProvider.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6a3779d0db2f41a292cde5a6bd827733
|
||||
timeCreated: 1637530360
|
||||
@@ -0,0 +1,32 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class AssetExtensions
|
||||
{
|
||||
public static IEnumerable<T> FindAssetsByType<T>() where T : Object
|
||||
{
|
||||
var guids = AssetDatabase.FindAssets($"t:{typeof(T)}");
|
||||
|
||||
foreach (var guid in guids)
|
||||
{
|
||||
var assetPath = AssetDatabase.GUIDToAssetPath(guid);
|
||||
var asset = AssetDatabase.LoadAssetAtPath<T>(assetPath);
|
||||
|
||||
if (asset != null)
|
||||
{
|
||||
yield return asset;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveAndRefresh(Object asset)
|
||||
{
|
||||
EditorUtility.SetDirty(asset);
|
||||
AssetDatabase.SaveAssetIfDirty(asset);
|
||||
AssetDatabase.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 727b5540f1294567b2d7b4d379f0a531
|
||||
timeCreated: 1686934776
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Utilities/AssetExtensions.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,71 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public abstract class EditorProperty<T>
|
||||
{
|
||||
public string Key { get; }
|
||||
public T Value
|
||||
{
|
||||
get => value;
|
||||
set
|
||||
{
|
||||
if (IsEqual(this.value, value))
|
||||
return;
|
||||
|
||||
this.value = value;
|
||||
Save(value);
|
||||
}
|
||||
}
|
||||
|
||||
public EditorPropertyDrawer<T> PropertyDrawer
|
||||
{
|
||||
get
|
||||
{
|
||||
if (propertyDrawer != null)
|
||||
return propertyDrawer;
|
||||
|
||||
propertyDrawer = GetDrawer();
|
||||
return propertyDrawer;
|
||||
}
|
||||
}
|
||||
|
||||
private T value;
|
||||
private readonly T defaultValue;
|
||||
private EditorPropertyDrawer<T> propertyDrawer;
|
||||
|
||||
public EditorProperty(string key, T defaultValue)
|
||||
{
|
||||
this.defaultValue = defaultValue;
|
||||
|
||||
Key = key;
|
||||
value = EditorPrefs.HasKey(key) ? Load() : defaultValue;
|
||||
}
|
||||
|
||||
public void SetToDefault()
|
||||
{
|
||||
Value = defaultValue;
|
||||
}
|
||||
|
||||
protected abstract bool IsEqual(T left, T right);
|
||||
protected abstract T Load();
|
||||
protected abstract void Save(T value);
|
||||
protected abstract EditorPropertyDrawer<T> GetDrawer();
|
||||
|
||||
public static implicit operator T(EditorProperty<T> p) => p.Value;
|
||||
}
|
||||
|
||||
public abstract class EditorPropertyDrawer<T>
|
||||
{
|
||||
protected EditorProperty<T> Property { get; }
|
||||
|
||||
public EditorPropertyDrawer(EditorProperty<T> property)
|
||||
{
|
||||
Property = property;
|
||||
}
|
||||
|
||||
public abstract void Draw(params GUILayoutOption[] options);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9276ecf1d7404d54b0906d24bd5dd03f
|
||||
timeCreated: 1724871250
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Utilities/EditorProperty.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,34 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class GUIExtensions
|
||||
{
|
||||
public static void DrawSelectionFrame(Rect rect, int density = 2)
|
||||
{
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Styles.ElementBackground.Draw(rect.CropFromStartToPosition(CropEdge.LeftLocal, density), false, true, true, true);
|
||||
Styles.ElementBackground.Draw(rect.CropFromStartToPosition(CropEdge.TopLocal, density), false, true, true, true);
|
||||
Styles.ElementBackground.Draw(rect.CropFromStartToPosition(CropEdge.RightLocal, density), false, true, true, true);
|
||||
Styles.ElementBackground.Draw(rect.CropFromStartToPosition(CropEdge.BottomLocal, density), false, true, true, true);
|
||||
}
|
||||
|
||||
public static void DrawColorFrame(Rect rect, Color color, int density = 2)
|
||||
{
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
EditorGUI.DrawRect(rect.CropFromStartToPosition(CropEdge.LeftLocal, density), color);
|
||||
EditorGUI.DrawRect(rect.CropFromStartToPosition(CropEdge.TopLocal, density), color);
|
||||
EditorGUI.DrawRect(rect.CropFromStartToPosition(CropEdge.RightLocal, density), color);
|
||||
EditorGUI.DrawRect(rect.CropFromStartToPosition(CropEdge.BottomLocal, density), color);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b5c9bb7e96fc4d03be73970eeea90597
|
||||
timeCreated: 1684672374
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Utilities/GUIExtensions.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,307 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public enum CropEdge
|
||||
{
|
||||
LeftLocal = 1,
|
||||
RightLocal = 2,
|
||||
TopLocal = 3,
|
||||
BottomLocal = 4,
|
||||
HorizontalGlobal = 5,
|
||||
VerticalGlobal = 6
|
||||
}
|
||||
|
||||
public enum WidthSetSpace
|
||||
{
|
||||
Left = 0,
|
||||
Center = 1,
|
||||
Right = 2
|
||||
}
|
||||
|
||||
public enum HeightSetSpace
|
||||
{
|
||||
Top = 0,
|
||||
Center = 1,
|
||||
Bottom = 2
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum ExtrudeFlags
|
||||
{
|
||||
Left = 1 << 1,
|
||||
Right = 1 << 2,
|
||||
Top = 1 << 3,
|
||||
Bottom = 1 << 4,
|
||||
None = 0,
|
||||
All = ~None
|
||||
}
|
||||
|
||||
public static class RectExtensions
|
||||
{
|
||||
#region Offset
|
||||
|
||||
public static Rect Offset(this Rect rect, float xDelta, float yDelta, float widthDelta, float heightDelta)
|
||||
{
|
||||
return new Rect(rect.x + xDelta, rect.y + yDelta, rect.width + widthDelta, rect.height + heightDelta);
|
||||
}
|
||||
|
||||
public static Rect OffsetByX(this Rect rect, float xDelta)
|
||||
{
|
||||
return new Rect(rect.x + xDelta, rect.y, rect.width, rect.height);
|
||||
}
|
||||
|
||||
public static Rect OffsetByY(this Rect rect, float yDelta)
|
||||
{
|
||||
return new Rect(rect.x, rect.y + yDelta, rect.width, rect.height);
|
||||
}
|
||||
|
||||
public static Rect OffsetByWidth(this Rect rect, float widthDelta)
|
||||
{
|
||||
return new Rect(rect.x, rect.y, rect.width + widthDelta, rect.height);
|
||||
}
|
||||
|
||||
public static Rect OffsetByHeight(this Rect rect, float heightDelta)
|
||||
{
|
||||
return new Rect(rect.x, rect.y, rect.width, rect.height + heightDelta);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Extrude
|
||||
|
||||
public static Rect Extrude(this Rect rect, ExtrudeFlags flags, float size)
|
||||
{
|
||||
var xMin = rect.xMin;
|
||||
var xMax = rect.xMax;
|
||||
var yMin = rect.yMin;
|
||||
var yMax = rect.yMax;
|
||||
|
||||
if ((flags & ExtrudeFlags.Left) == ExtrudeFlags.Left)
|
||||
xMin -= size;
|
||||
|
||||
if ((flags & ExtrudeFlags.Right) == ExtrudeFlags.Right)
|
||||
xMax += size;
|
||||
|
||||
if ((flags & ExtrudeFlags.Top) == ExtrudeFlags.Top)
|
||||
yMin -= size;
|
||||
|
||||
if ((flags & ExtrudeFlags.Bottom) == ExtrudeFlags.Bottom)
|
||||
yMax += size;
|
||||
|
||||
return Rect.MinMaxRect(xMin, yMin, xMax, yMax);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Set
|
||||
|
||||
public static Rect SetX(this Rect rect, float x)
|
||||
{
|
||||
return new Rect(x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
|
||||
public static Rect SetY(this Rect rect, float y)
|
||||
{
|
||||
return new Rect(rect.x, y, rect.width, rect.height);
|
||||
}
|
||||
|
||||
public static Rect SetWidth(this Rect rect, float width, WidthSetSpace setSpace = WidthSetSpace.Left)
|
||||
{
|
||||
switch (setSpace)
|
||||
{
|
||||
case WidthSetSpace.Left:
|
||||
return new Rect(rect.x, rect.y, width, rect.height);
|
||||
|
||||
case WidthSetSpace.Center:
|
||||
return new Rect(rect.center.x - width/2, rect.y, width, rect.height);
|
||||
|
||||
case WidthSetSpace.Right:
|
||||
return new Rect(rect.xMax - width, rect.y, width, rect.height);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(setSpace), setSpace, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect SetHeight(this Rect rect, float height, HeightSetSpace setSpace = HeightSetSpace.Top)
|
||||
{
|
||||
switch (setSpace)
|
||||
{
|
||||
case HeightSetSpace.Top:
|
||||
return new Rect(rect.x, rect.y, rect.width, height);
|
||||
|
||||
case HeightSetSpace.Center:
|
||||
return new Rect(rect.x, rect.center.y - height / 2, rect.width, height);
|
||||
|
||||
case HeightSetSpace.Bottom:
|
||||
return new Rect(rect.x, rect.yMax - height, rect.width, height);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(setSpace), setSpace, null);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region TakeEdge
|
||||
|
||||
public static Rect CropFromStartToPosition(this Rect rect, CropEdge crop, float position)
|
||||
{
|
||||
switch (crop)
|
||||
{
|
||||
case CropEdge.LeftLocal:
|
||||
return new Rect(rect.x, rect.y, position, rect.height);
|
||||
|
||||
case CropEdge.RightLocal:
|
||||
return new Rect(rect.xMax - position, rect.y, position, rect.height);
|
||||
|
||||
case CropEdge.TopLocal:
|
||||
return new Rect(rect.x, rect.y, rect.width, position);
|
||||
|
||||
case CropEdge.BottomLocal:
|
||||
return new Rect(rect.x, rect.yMax - position, rect.width, position);
|
||||
|
||||
case CropEdge.HorizontalGlobal:
|
||||
return new Rect(rect.x, rect.y, position - rect.x, rect.height);
|
||||
|
||||
case CropEdge.VerticalGlobal:
|
||||
return new Rect(rect.x, rect.y, rect.width, position - rect.y);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(crop), crop, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect CropFromPositionToEnd(this Rect rect, CropEdge crop, float position)
|
||||
{
|
||||
switch (crop)
|
||||
{
|
||||
case CropEdge.LeftLocal:
|
||||
return new Rect(rect.x + position, rect.y, rect.width - position, rect.height);
|
||||
|
||||
case CropEdge.RightLocal:
|
||||
return new Rect(rect.x, rect.y, rect.width - position, rect.height);
|
||||
|
||||
case CropEdge.TopLocal:
|
||||
return new Rect(rect.x, rect.y + position, rect.width, rect.height - position);
|
||||
|
||||
case CropEdge.BottomLocal:
|
||||
return new Rect(rect.x, rect.y, rect.width, rect.height - position);
|
||||
|
||||
case CropEdge.HorizontalGlobal:
|
||||
return new Rect(position, rect.y, rect.xMax - position, rect.height);
|
||||
|
||||
case CropEdge.VerticalGlobal:
|
||||
return new Rect(rect.x, position, rect.width, rect.yMax - position);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(crop), crop, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect CropFromPositionWithSize(this Rect rect, CropEdge crop, float position, float size)
|
||||
{
|
||||
switch (crop)
|
||||
{
|
||||
case CropEdge.LeftLocal:
|
||||
return new Rect(rect.x + position, rect.y, size, rect.height);
|
||||
|
||||
case CropEdge.RightLocal:
|
||||
return new Rect(rect.xMax - position - size, rect.y, size, rect.height);
|
||||
|
||||
case CropEdge.TopLocal:
|
||||
return new Rect(rect.x, rect.y + position, rect.width, size);
|
||||
|
||||
case CropEdge.BottomLocal:
|
||||
return new Rect(rect.x, rect.yMax - position - size, rect.width, size);
|
||||
|
||||
case CropEdge.HorizontalGlobal:
|
||||
return new Rect(position, rect.y, size, rect.height);
|
||||
|
||||
case CropEdge.VerticalGlobal:
|
||||
return new Rect(rect.x, position, rect.width, size);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(crop), crop, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static Rect CropFromPositionToPosition(this Rect rect, CropEdge crop, float positionStart, float positionEnd)
|
||||
{
|
||||
switch (crop)
|
||||
{
|
||||
case CropEdge.LeftLocal:
|
||||
return new Rect(rect.x + positionStart, rect.y, positionEnd - positionStart, rect.height);
|
||||
|
||||
case CropEdge.RightLocal:
|
||||
return new Rect(rect.xMax - positionEnd, rect.y, positionEnd - positionStart, rect.height);
|
||||
|
||||
case CropEdge.TopLocal:
|
||||
return new Rect(rect.x, rect.y + positionStart, rect.width, positionEnd - positionStart);
|
||||
|
||||
case CropEdge.BottomLocal:
|
||||
return new Rect(rect.x, rect.yMax - positionEnd, rect.width, positionEnd - positionStart);
|
||||
|
||||
case CropEdge.HorizontalGlobal:
|
||||
return new Rect(positionStart, rect.y, positionEnd - positionStart, rect.height);
|
||||
|
||||
case CropEdge.VerticalGlobal:
|
||||
return new Rect(rect.x, positionStart, rect.width, positionEnd - positionStart);
|
||||
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException(nameof(crop), crop, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Clamp
|
||||
|
||||
public static float ClampPositionX(this Rect rect, float xPosition)
|
||||
{
|
||||
return Mathf.Clamp(xPosition, rect.xMin, rect.xMax);
|
||||
}
|
||||
|
||||
public static float ClampPositionY(this Rect rect, float yPosition)
|
||||
{
|
||||
return Mathf.Clamp(yPosition, rect.yMin, rect.yMax);
|
||||
}
|
||||
|
||||
public static Vector2 ClampPosition(this Rect rect, Vector2 position)
|
||||
{
|
||||
return new Vector2(rect.ClampPositionX(position.x), rect.ClampPositionY(position.y));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public static Rect FitInRect(this Rect rect, Rect rectToFitIn)
|
||||
{
|
||||
return Rect.MinMaxRect(
|
||||
Mathf.Max(rect.xMin, rectToFitIn.xMin),
|
||||
Mathf.Max(rect.yMin, rectToFitIn.yMin),
|
||||
Mathf.Min(rect.xMax, rectToFitIn.xMax),
|
||||
Mathf.Min(rect.yMax, rectToFitIn.yMax));
|
||||
}
|
||||
|
||||
public static Rect RelativeToOther(this Rect rect, Rect otherRect)
|
||||
{
|
||||
return new Rect(
|
||||
rect.x - otherRect.x,
|
||||
rect.y - otherRect.y,
|
||||
rect.width,
|
||||
rect.height);
|
||||
}
|
||||
|
||||
public static RectInt ToRectInt(this Rect rect)
|
||||
{
|
||||
return new RectInt(
|
||||
Mathf.RoundToInt(rect.x),
|
||||
Mathf.RoundToInt(rect.y),
|
||||
Mathf.RoundToInt(rect.width),
|
||||
Mathf.RoundToInt(rect.height));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 35b0bc8d29614c17a7195521d142a91b
|
||||
timeCreated: 1637089732
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Utilities/RectExtensions.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,88 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ResizerGUI
|
||||
{
|
||||
public bool IsHorizontal;
|
||||
public float HandleSize = 8;
|
||||
public float LineSize = 1;
|
||||
public Color LineColor = Color.black;
|
||||
|
||||
public Rect LocalArea;
|
||||
|
||||
public float NormPosition;
|
||||
public float Position => GetPositionFromNorm(NormPosition);
|
||||
public bool IsResizing { get; private set; }
|
||||
public ResizerGUI(bool isHorizontal, float handleSize, float lineSize, Color lineColor, float normaPosition = 0)
|
||||
{
|
||||
IsHorizontal = isHorizontal;
|
||||
HandleSize = handleSize;
|
||||
LineSize = lineSize;
|
||||
LineColor = lineColor;
|
||||
NormPosition = normaPosition;
|
||||
}
|
||||
|
||||
public void ProcessHandle()
|
||||
{
|
||||
var controlId = GUIUtility.GetControlID(FocusType.Passive);
|
||||
|
||||
var resizerControlRect = LocalArea.CropFromPositionWithSize(
|
||||
IsHorizontal ? CropEdge.VerticalGlobal : CropEdge.HorizontalGlobal,
|
||||
Position - HandleSize / 2,
|
||||
HandleSize);
|
||||
|
||||
EditorGUIUtility.AddCursorRect(resizerControlRect, IsHorizontal ? MouseCursor.ResizeVertical : MouseCursor.ResizeHorizontal, controlId);
|
||||
|
||||
if (Event.current.type == EventType.MouseDown
|
||||
&& Event.current.button == 0
|
||||
&& resizerControlRect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
IsResizing = true;
|
||||
GUIUtility.hotControl = controlId;
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
if (IsResizing && Event.current.type == EventType.Layout)
|
||||
{
|
||||
var previousNormPos = NormPosition;
|
||||
NormPosition = GetNormFromPosition(IsHorizontal ? Event.current.mousePosition.y : Event.current.mousePosition.x);
|
||||
|
||||
if (Mathf.Abs(NormPosition - previousNormPos) > 0.0001f)
|
||||
GUI.changed = true;
|
||||
}
|
||||
|
||||
if (Event.current.GetTypeForControl(controlId) == EventType.MouseUp)
|
||||
{
|
||||
IsResizing = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawLine()
|
||||
{
|
||||
var resizerLineRect = LocalArea.CropFromPositionWithSize(
|
||||
IsHorizontal ? CropEdge.VerticalGlobal : CropEdge.HorizontalGlobal,
|
||||
Position - LineSize / 2,
|
||||
LineSize);
|
||||
|
||||
EditorGUI.DrawRect(resizerLineRect, LineColor);
|
||||
}
|
||||
|
||||
private float GetPositionFromNorm(float normPosition)
|
||||
{
|
||||
return IsHorizontal
|
||||
? Mathf.Lerp(LocalArea.yMin, LocalArea.yMax, normPosition)
|
||||
: Mathf.Lerp(LocalArea.xMin, LocalArea.xMax, normPosition);
|
||||
}
|
||||
|
||||
private float GetNormFromPosition(float position)
|
||||
{
|
||||
return IsHorizontal
|
||||
? Mathf.InverseLerp(LocalArea.yMin, LocalArea.yMax, position)
|
||||
: Mathf.InverseLerp(LocalArea.xMin, LocalArea.xMax, position);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 18f1196977484d65b2374f25347869d2
|
||||
timeCreated: 1644830319
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Utilities/ResizerGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class ScrollbarGUI
|
||||
{
|
||||
public bool AllowStickToLast;
|
||||
public bool IsHorizontal;
|
||||
public Rect ScrollRect;
|
||||
public float Size;
|
||||
public float StartValue;
|
||||
public float EndValue;
|
||||
|
||||
public float ScrollValue;
|
||||
public float ScrollValueNormalized => EndValue - Size <= 0 ? 0 : ScrollValue / (EndValue - Size);
|
||||
public bool IsStickingToLast { get; set; }
|
||||
|
||||
public ScrollbarGUI(bool isHorizontal)
|
||||
{
|
||||
IsHorizontal = isHorizontal;
|
||||
IsStickingToLast = false;
|
||||
}
|
||||
|
||||
public void Prepare(Rect scrollRect, float size, float startValue, float endValue)
|
||||
{
|
||||
ScrollRect = scrollRect;
|
||||
Size = size;
|
||||
StartValue = startValue;
|
||||
EndValue = endValue;
|
||||
}
|
||||
|
||||
public void DrawPlaceholder()
|
||||
{
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
var style = new GUIStyle(GUI.skin.horizontalScrollbar);
|
||||
style.Draw(ScrollRect, false, false, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
public void Draw()
|
||||
{
|
||||
if (EndValue <= Size)
|
||||
{
|
||||
ScrollValue = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsStickingToLast)
|
||||
ScrollValue = EndValue - Size;
|
||||
|
||||
var scrollValueBefore = ScrollValue;
|
||||
|
||||
ScrollValue = IsHorizontal
|
||||
? GUI.HorizontalScrollbar(ScrollRect, ScrollValue, Size, StartValue, EndValue)
|
||||
: GUI.VerticalScrollbar(ScrollRect, ScrollValue, Size, StartValue, EndValue);
|
||||
|
||||
var scrollValueAfter = ScrollValue;
|
||||
|
||||
if (AllowStickToLast && !IsStickingToLast && scrollValueBefore < scrollValueAfter &&
|
||||
ScrollValueNormalized >= 0.99f)
|
||||
{
|
||||
IsStickingToLast = true;
|
||||
}
|
||||
else if (IsStickingToLast && scrollValueAfter < scrollValueBefore)
|
||||
{
|
||||
IsStickingToLast = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetNormalizedPosition(float normPos, float normAnchor = 0.5f)
|
||||
{
|
||||
normPos = Mathf.Clamp01(normPos);
|
||||
normAnchor = Mathf.Clamp01(normAnchor);
|
||||
|
||||
ScrollValue = Mathf.Lerp(StartValue, EndValue, normPos);
|
||||
ScrollValue = Mathf.Clamp(ScrollValue - Size * normAnchor, 0, EndValue - Size);
|
||||
}
|
||||
|
||||
public void ScrollToValue(float value, float normAnchor = 0.5f)
|
||||
{
|
||||
ScrollValue = Mathf.Clamp(
|
||||
value - Mathf.Clamp01(normAnchor) * Size,
|
||||
0,
|
||||
EndValue - Size);
|
||||
}
|
||||
|
||||
public void ResizeRelativeToPointer(float pointerPosition, float resizeFactor)
|
||||
{
|
||||
var normAnchor = IsHorizontal
|
||||
? Mathf.InverseLerp(ScrollRect.xMin, ScrollRect.xMax, pointerPosition)
|
||||
: Mathf.InverseLerp(ScrollRect.yMin, ScrollRect.yMax, pointerPosition);
|
||||
|
||||
var newScrollPos = resizeFactor * (ScrollValue + Size * normAnchor);
|
||||
|
||||
EndValue *= resizeFactor;
|
||||
|
||||
ScrollToValue(newScrollPos, normAnchor);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 511b306726d94ec89e2a370f56e86396
|
||||
timeCreated: 1656676186
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Utilities/ScrollbarGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,126 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class TextureDrawGUI
|
||||
{
|
||||
[SerializeField] private Texture2D _mainTexture;
|
||||
|
||||
private int _textureWidth;
|
||||
private int _textureHeight;
|
||||
private Rect _frameRect;
|
||||
private Color[] _colorsArray = new Color[2048 * 2048];
|
||||
|
||||
public void Prepare(Rect frameRect)
|
||||
{
|
||||
_frameRect = frameRect;
|
||||
|
||||
_textureWidth = Mathf.CeilToInt(frameRect.width);
|
||||
_textureHeight = Mathf.CeilToInt(frameRect.height);
|
||||
|
||||
if (_mainTexture == null)
|
||||
{
|
||||
_mainTexture = new Texture2D(_textureWidth, _textureHeight);
|
||||
}
|
||||
else if (_mainTexture.width != _textureWidth || _mainTexture.height != _textureHeight)
|
||||
{
|
||||
_mainTexture.Reinitialize(_textureWidth, _textureHeight);
|
||||
_mainTexture.Apply(false);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawResult()
|
||||
{
|
||||
_mainTexture.Apply(false);
|
||||
GUI.DrawTexture(_frameRect, _mainTexture);
|
||||
}
|
||||
|
||||
public void DrawColorAll(Color color)
|
||||
{
|
||||
FillColorArray(_textureWidth * _textureHeight + 1, color);
|
||||
_mainTexture.SetPixels(0, 0, _textureWidth, _textureHeight, _colorsArray);
|
||||
}
|
||||
|
||||
public void DrawTestGraph(Color backColor, GraphPointInfo[] graphPoints, int pointsCount)
|
||||
{
|
||||
var pixelIndex = 0;
|
||||
|
||||
for (var y = 0; y < _textureHeight; y++)
|
||||
{
|
||||
for (var x = 0; x < _textureWidth; x++)
|
||||
{
|
||||
if (x >= pointsCount)
|
||||
{
|
||||
_colorsArray[pixelIndex++] = backColor;
|
||||
continue;
|
||||
}
|
||||
|
||||
var color = backColor;
|
||||
var point = graphPoints[x];
|
||||
|
||||
if (point.IsEmpty)
|
||||
{
|
||||
_colorsArray[pixelIndex++] = color;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (y <= 0)
|
||||
{
|
||||
color = point.BottomLineColor;
|
||||
}
|
||||
else if (y == point.PixelHeight || y == point.PixelHeight - 1)
|
||||
{
|
||||
if (point.WithLine)
|
||||
color = point.TopLineColor;
|
||||
}
|
||||
else if (y < point.PixelHeight)
|
||||
{
|
||||
color = point.FillColor;
|
||||
}
|
||||
|
||||
|
||||
_colorsArray[pixelIndex++] = color;
|
||||
}
|
||||
}
|
||||
|
||||
_mainTexture.SetPixels(_colorsArray);
|
||||
}
|
||||
|
||||
public void DrawColorRect(Rect rect, Color color)
|
||||
{
|
||||
var fitRect = rect.FitInRect(_frameRect);
|
||||
|
||||
if (fitRect.width <= 0 || fitRect.height <= 0)
|
||||
return;
|
||||
|
||||
var drawRect = fitRect
|
||||
.RelativeToOther(_frameRect)
|
||||
.ToRectInt();
|
||||
|
||||
FillColorArray(drawRect.width * drawRect.height + 1, color);
|
||||
_mainTexture.SetPixels(drawRect.x, drawRect.y, drawRect.width, drawRect.height, _colorsArray);
|
||||
}
|
||||
|
||||
private void FillColorArray(int count, Color color)
|
||||
{
|
||||
if (_colorsArray.Length < count)
|
||||
Array.Resize(ref _colorsArray, 2048*2048);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
_colorsArray[i] = color;
|
||||
}
|
||||
|
||||
public struct GraphPointInfo
|
||||
{
|
||||
public bool IsEmpty;
|
||||
public bool WithLine;
|
||||
public int PixelHeight;
|
||||
public Color TopLineColor;
|
||||
public Color BottomLineColor;
|
||||
public Color FillColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4c3ee7718d44610bafd7e0860d9ca06
|
||||
timeCreated: 1715513207
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/Utilities/TextureDrawGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,95 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Experimental.Rendering;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class WatchCellDividerDrawer
|
||||
{
|
||||
public const int MaxColumnsPerTexture = 10;
|
||||
|
||||
private Dictionary<int, BlockPerWidthInfo> _perWidthInfos = new();
|
||||
private Color32[] _colors = new Color32[100];
|
||||
|
||||
public void Draw(Rect rect, int columnWidth)
|
||||
{
|
||||
var columnCount = Mathf.RoundToInt(rect.width / columnWidth);
|
||||
|
||||
if (columnCount <= 1)
|
||||
return;
|
||||
|
||||
var columnsLeft = columnCount - 1;
|
||||
var currentX = (float)columnWidth;
|
||||
|
||||
while (columnsLeft > 0)
|
||||
{
|
||||
var columnsToDraw = columnsLeft >= MaxColumnsPerTexture ? MaxColumnsPerTexture : columnsLeft;
|
||||
columnsLeft -= columnsToDraw;
|
||||
|
||||
var textureRect = rect.CropFromPositionWithSize(CropEdge.LeftLocal, currentX, columnsToDraw * columnWidth);
|
||||
var texture = GetOrCreateTexture(columnWidth, columnsToDraw);
|
||||
|
||||
GUI.DrawTexture(textureRect, texture, ScaleMode.StretchToFill, true);
|
||||
|
||||
currentX += textureRect.width;
|
||||
}
|
||||
}
|
||||
|
||||
private Texture2D GetOrCreateTexture(int columnWidth, int columnsCount)
|
||||
{
|
||||
var hasBlockForWidth = _perWidthInfos.TryGetValue(columnWidth, out var blockPerWidth);
|
||||
|
||||
if (!hasBlockForWidth)
|
||||
{
|
||||
blockPerWidth = new BlockPerWidthInfo();
|
||||
_perWidthInfos[columnWidth] = blockPerWidth;
|
||||
}
|
||||
|
||||
var hasTextureForCount = blockPerWidth.TexturesPerCount.TryGetValue(columnsCount, out var texture) && texture != null;
|
||||
|
||||
if (!hasTextureForCount)
|
||||
{
|
||||
texture = CreateDividerTexture(columnWidth, columnsCount, Colors.CellDivider);
|
||||
blockPerWidth.TexturesPerCount[columnsCount] = texture;
|
||||
}
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
private Texture2D CreateDividerTexture(int columnWidth, int columnsCount, Color color)
|
||||
{
|
||||
var pixelsCount = columnsCount * columnWidth;
|
||||
var texture = new Texture2D(pixelsCount, 1, TextureFormat.ARGB32, false, true)
|
||||
{
|
||||
filterMode = FilterMode.Point,
|
||||
wrapMode = TextureWrapMode.Clamp
|
||||
};
|
||||
|
||||
PrepareColors(pixelsCount);
|
||||
|
||||
for (var c = 0; c < columnsCount; c++)
|
||||
_colors[c * columnWidth] = color;
|
||||
|
||||
texture.SetPixels32(0, 0, pixelsCount, 1, _colors);
|
||||
texture.Apply(false);
|
||||
|
||||
return texture;
|
||||
}
|
||||
|
||||
private void PrepareColors(int count)
|
||||
{
|
||||
if (_colors.Length < count)
|
||||
Array.Resize(ref _colors, count);
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
_colors[i] = Color.clear;
|
||||
}
|
||||
|
||||
private class BlockPerWidthInfo
|
||||
{
|
||||
public Dictionary<int, Texture2D> TexturesPerCount = new();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d599e701be64466396a55749b0a7bd5d
|
||||
timeCreated: 1727618703
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchCellDividerDrawer.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public static class WatchEditorServices
|
||||
{
|
||||
public static WatchGUICache GUICache { get; set; } = new ();
|
||||
public static WatchPreviewDrawer PreviewDrawer { get; set; } = new ();
|
||||
public static WatchCellDividerDrawer CellDividerDrawer { get; set; } = new ();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 934d23ee36264f6db727fed909203725
|
||||
timeCreated: 1653138211
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchEditorServices.cs
|
||||
uploadId: 770587
|
||||
20
Assets/Plugins/LiveWatchLite/Scripts/Editor/WatchGUICache.cs
Normal file
20
Assets/Plugins/LiveWatchLite/Scripts/Editor/WatchGUICache.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class WatchGUICache
|
||||
{
|
||||
private Dictionary<string, GUIContent> _textToGUIContentCache = new();
|
||||
|
||||
public GUIContent GetContent(string text)
|
||||
{
|
||||
if (_textToGUIContentCache.TryGetValue(text, out var guiContent))
|
||||
return guiContent;
|
||||
|
||||
guiContent = new GUIContent(text, text);
|
||||
_textToGUIContentCache[text] = guiContent;
|
||||
return guiContent;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 66d373d9cb7d4bf380c48512e04a019b
|
||||
timeCreated: 1712346509
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchGUICache.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,422 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using Random = UnityEngine.Random;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class WatchPreviewDrawer
|
||||
{
|
||||
private static int PreviousStartIndex;
|
||||
private static float StartIndexChangedTime;
|
||||
|
||||
public bool Search { get; set; }
|
||||
|
||||
private ConcurrentDictionary<WatchVariable, PreviewInfo> _previewInfos = new();
|
||||
|
||||
public void DrawPreview(Rect rect, Rect drawRect, WatchVariable variable, List<int> indicesToDisplay, int columnWidth)
|
||||
{
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
return;
|
||||
|
||||
if (PreviousStartIndex != indicesToDisplay[0])
|
||||
{
|
||||
PreviousStartIndex = indicesToDisplay[0];
|
||||
StartIndexChangedTime = Time.realtimeSinceStartup;
|
||||
}
|
||||
|
||||
if (_previewInfos.TryGetValue(variable, out var previewInfo)
|
||||
&& IsValidPreview(previewInfo, rect, indicesToDisplay)
|
||||
&& (previewInfo.Texture != null || previewInfo.State is not PreviewInfo.StateType.ReadyToUse))
|
||||
{
|
||||
if (previewInfo.State is PreviewInfo.StateType.Computing)
|
||||
return;
|
||||
|
||||
if (previewInfo.State is PreviewInfo.StateType.ReadyToSetPixels)
|
||||
{
|
||||
if (previewInfo.MinReadyTime > Time.realtimeSinceStartup)
|
||||
return;
|
||||
|
||||
PrepareTexture(previewInfo.Size, ref previewInfo.Texture);
|
||||
previewInfo.Texture.SetPixels32(0, 0, previewInfo.Size.x, previewInfo.Size.y, previewInfo.Colors);
|
||||
previewInfo.Texture.Apply(false);
|
||||
previewInfo.State = PreviewInfo.StateType.ReadyToUse;
|
||||
}
|
||||
|
||||
GUI.DrawTexture(drawRect, previewInfo.Texture);
|
||||
}
|
||||
|
||||
if (previewInfo == null)
|
||||
{
|
||||
previewInfo = new PreviewInfo();
|
||||
_previewInfos.TryAdd(variable, previewInfo);
|
||||
}
|
||||
|
||||
previewInfo.Token?.Cancel();
|
||||
previewInfo.Token?.Dispose();
|
||||
previewInfo.Variable = variable;
|
||||
previewInfo.Rect = rect;
|
||||
previewInfo.StartIndex = indicesToDisplay[0];
|
||||
previewInfo.EndIndex = indicesToDisplay[^1];
|
||||
previewInfo.Token = new CancellationTokenSource();
|
||||
previewInfo.MinReadyTime = StartIndexChangedTime + 0.2f;
|
||||
|
||||
if (IsValidPreview(previewInfo, rect, indicesToDisplay) )
|
||||
previewInfo.State = PreviewInfo.StateType.ComputingSilently;
|
||||
else
|
||||
previewInfo.State = PreviewInfo.StateType.Computing;
|
||||
|
||||
Task.Factory.StartNew(() => BuildPreviewTexture(previewInfo, indicesToDisplay, columnWidth));
|
||||
}
|
||||
|
||||
private void BuildPreviewTexture(PreviewInfo preview, List<int> keysToDisplay, int columnWidth)
|
||||
{
|
||||
preview.CalcMeta.KeysToDisplay = keysToDisplay.ToList();
|
||||
keysToDisplay = preview.CalcMeta.KeysToDisplay;
|
||||
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
PrepareColors(preview.Size, ref preview.Colors);
|
||||
RefreshPixelInfos(preview);
|
||||
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
var blocksCount = preview.CalcMeta.PixelBlockCount;
|
||||
var pixelBlocks = preview.CalcMeta.PixelBlocks;
|
||||
|
||||
for (var k = 0; k < keysToDisplay.Count; k++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
var startX = k * columnWidth;
|
||||
var endX = startX + columnWidth - 1;
|
||||
|
||||
var currentBlockTopY = preview.Size.y - 1;
|
||||
for (var b = 0; b < blocksCount; b++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
var endY = currentBlockTopY;
|
||||
var startY = endY - pixelBlocks[b].HeightPixels + 1;
|
||||
|
||||
var mode = ValueModeType.None;
|
||||
GetValueModForChilds(preview.Variable, keysToDisplay[k], pixelBlocks[b].ChildNames, ref mode);
|
||||
|
||||
if (!preview.HasSearchResults)
|
||||
mode &= ~ValueModeType.Searched;
|
||||
|
||||
var blockColor = GetColorFromMode(mode, b % 2 == 0);
|
||||
|
||||
for (var x = startX; x <= endX; x++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
for (var y = startY; y <= endY; y++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
var pixelIndex = GetPixelIndex(x, y, preview.Size);
|
||||
|
||||
if ((mode & ValueModeType.HasValue) == ValueModeType.HasValue && x == startX && columnWidth > 1)
|
||||
{
|
||||
preview.Colors[pixelIndex] = Colors.PreviewOriginalEdge;
|
||||
}
|
||||
else
|
||||
{
|
||||
preview.Colors[pixelIndex] = blockColor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
currentBlockTopY = startY - 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
preview.State = PreviewInfo.StateType.ReadyToSetPixels;
|
||||
LiveWatchWindow.IsRepaintRequested = true;
|
||||
}
|
||||
|
||||
private int GetPixelIndex(int x, int y, Vector2Int textureSize)
|
||||
{
|
||||
return y * textureSize.x + x;
|
||||
}
|
||||
|
||||
private Color32 SumColors(Color32 left, Color32 right)
|
||||
{
|
||||
return new Color32(
|
||||
(byte)Mathf.Clamp(left.r + right.r, 0, 255),
|
||||
(byte)Mathf.Clamp(left.g + right.g, 0, 255),
|
||||
(byte)Mathf.Clamp(left.b + right.b, 0, 255),
|
||||
(byte)Mathf.Clamp(left.a + right.a, 0, 255));
|
||||
}
|
||||
|
||||
private void RefreshPixelInfos(PreviewInfo preview)
|
||||
{
|
||||
var cm = preview.CalcMeta;
|
||||
|
||||
var pixelsPerChild = (float)preview.Size.y / preview.Variable.Childs.Count;
|
||||
|
||||
if (pixelsPerChild > 1f)
|
||||
{
|
||||
cm.PixelBlockCount = preview.Variable.Childs.Count;
|
||||
PreparePixelBlocks(cm.PixelBlockCount);
|
||||
|
||||
var roundedPixelsPerChild = Mathf.FloorToInt(pixelsPerChild);
|
||||
|
||||
for (var i = 0; i < cm.PixelBlockCount; i++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
cm.PixelBlocks[i] ??= new PixelBlockInfo();
|
||||
cm.PixelBlocks[i].Clear();
|
||||
cm.PixelBlocks[i].HeightPixels = roundedPixelsPerChild;
|
||||
cm.PixelBlocks[i].ChildNames.Add(preview.Variable.Childs.SortedNames[i]);
|
||||
}
|
||||
|
||||
var pixelsLeft = preview.Size.y - roundedPixelsPerChild * preview.Variable.Childs.Count;
|
||||
|
||||
var currentBlockIndex = 0;
|
||||
while (pixelsLeft > 0)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
pixelsLeft--;
|
||||
cm.PixelBlocks[currentBlockIndex].HeightPixels++;
|
||||
|
||||
currentBlockIndex++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
cm.PixelBlockCount = preview.Size.y;
|
||||
PreparePixelBlocks(cm.PixelBlockCount);
|
||||
|
||||
cm.ChildCountPerBlock ??= new List<int>();
|
||||
cm.ChildCountPerBlock.Clear();
|
||||
|
||||
var childPerPixel = 1f / pixelsPerChild;
|
||||
var roundedChildPerBlock = Mathf.FloorToInt(childPerPixel);
|
||||
|
||||
for (var i = 0; i < cm.PixelBlockCount; i++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
cm.PixelBlocks[i] ??= new PixelBlockInfo();
|
||||
cm.PixelBlocks[i].HeightPixels = 1;
|
||||
cm.ChildCountPerBlock.Add(roundedChildPerBlock);
|
||||
}
|
||||
|
||||
var childLeft = preview.Variable.Childs.Count - cm.PixelBlockCount * roundedChildPerBlock;
|
||||
var currentBlockIndex = cm.PixelBlockCount - 1;
|
||||
|
||||
while (childLeft > 0)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
childLeft--;
|
||||
cm.ChildCountPerBlock[currentBlockIndex]++;
|
||||
currentBlockIndex--;
|
||||
}
|
||||
|
||||
var currentChildIndex = 0;
|
||||
|
||||
for (var i = 0; i < cm.PixelBlockCount; i++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
cm.PixelBlocks[i].Clear();
|
||||
|
||||
for (var c = 0; c < cm.ChildCountPerBlock[i]; c++)
|
||||
{
|
||||
if (preview.Token.IsCancellationRequested)
|
||||
return;
|
||||
|
||||
cm.PixelBlocks[i].ChildNames.Add(preview.Variable.Childs.SortedNames[currentChildIndex++]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void PreparePixelBlocks(int count)
|
||||
{
|
||||
if (cm.PixelBlocks == null)
|
||||
cm.PixelBlocks = new PixelBlockInfo[count];
|
||||
else if (cm.PixelBlocks.Length < count)
|
||||
Array.Resize(ref cm.PixelBlocks, count);
|
||||
}
|
||||
}
|
||||
|
||||
private void PrepareColors(Vector2Int size, ref Color32[] colors)
|
||||
{
|
||||
var targetCount = Mathf.CeilToInt(size.x) * Mathf.CeilToInt(size.y) * 2;
|
||||
|
||||
if (colors == null)
|
||||
colors = new Color32[targetCount];
|
||||
else if (colors.Length < targetCount)
|
||||
Array.Resize(ref colors, targetCount);
|
||||
|
||||
for (var i = 0; i < colors.Length; i++)
|
||||
colors[i] = new Color32(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
private void PrepareTexture(Vector2Int size, ref Texture2D texture)
|
||||
{
|
||||
if (texture == null)
|
||||
{
|
||||
texture = new Texture2D(size.x, size.y);
|
||||
}
|
||||
else if (texture.width != size.x || texture.height != size.y)
|
||||
{
|
||||
texture.Reinitialize(size.x, size.y);
|
||||
texture.Apply(false);
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsValidPreview(PreviewInfo preview, Rect rect, List<int> indicesToDisplay)
|
||||
{
|
||||
return preview.Size.x == Mathf.CeilToInt(rect.width)
|
||||
&& preview.Size.y == Mathf.CeilToInt(rect.height)
|
||||
&& preview.StartIndex == indicesToDisplay[0]
|
||||
&& preview.EndIndex == indicesToDisplay[^1];
|
||||
}
|
||||
|
||||
|
||||
private Color32 GetColorFromMode(ValueModeType mode, bool isOdd)
|
||||
{
|
||||
var resultColor = Colors.PreviewCellEmpty;
|
||||
|
||||
if ((mode & ValueModeType.EmptyValue) == ValueModeType.EmptyValue)
|
||||
resultColor = Colors.PreviewCellEmpty;
|
||||
|
||||
if ((mode & ValueModeType.HasValue) != ValueModeType.HasValue)
|
||||
return resultColor;
|
||||
|
||||
resultColor = isOdd ? Colors.PreviewCellHasValueOdd : Colors.PreviewCellHasValue;
|
||||
|
||||
if ((mode & ValueModeType.Original) == ValueModeType.Original)
|
||||
resultColor = isOdd ? Colors.PreviewCellOriginalOdd : Colors.PreviewCellOriginal;
|
||||
|
||||
if ((mode & ValueModeType.Searched) == ValueModeType.Searched)
|
||||
{
|
||||
resultColor = isOdd
|
||||
? ((mode & ValueModeType.Original) == ValueModeType.Original) ? Colors.PreviewCellSearchedOriginalOdd : Colors.PreviewCellSearchedOdd
|
||||
: ((mode & ValueModeType.Original) == ValueModeType.Original) ? Colors.PreviewCellSearchedOriginal : Colors.PreviewCellSearched;
|
||||
}
|
||||
|
||||
return resultColor;
|
||||
}
|
||||
|
||||
private void GetValueModForChilds(WatchVariable variable, int key, List<string> childNames, ref ValueModeType mode)
|
||||
{
|
||||
foreach (var childName in childNames)
|
||||
{
|
||||
var child = variable.Childs.Get(childName);
|
||||
GetValueModeRecursive(child, key, ref mode);
|
||||
}
|
||||
}
|
||||
|
||||
private void GetValueModeRecursive(WatchVariable variable, int key, ref ValueModeType mode)
|
||||
{
|
||||
if (variable.HasChilds)
|
||||
{
|
||||
foreach (var childName in variable.Childs.SortedNames)
|
||||
{
|
||||
var child = variable.Childs.Get(childName);
|
||||
GetValueModeRecursive(child, key, ref mode);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!variable.Values.AnyAt(key))
|
||||
return;
|
||||
|
||||
if (variable.Values.IsEmptyAt(key))
|
||||
mode |= ValueModeType.EmptyValue;
|
||||
else
|
||||
mode |= ValueModeType.HasValue;
|
||||
|
||||
if (variable.Values.IsOriginalAt(key) && key > 0 && !variable.Values.IsEmptyAt(key - 1))
|
||||
mode |= ValueModeType.Original;
|
||||
|
||||
if (variable.EditorMeta.SearchResult.ValueResults != null
|
||||
&& variable.EditorMeta.SearchResult.ValueResults.ContainsKey(variable.Values.GetOriginalKey(key)))
|
||||
mode |= ValueModeType.Searched;
|
||||
}
|
||||
}
|
||||
|
||||
private class PreviewInfo
|
||||
{
|
||||
public StateType State;
|
||||
public float MinReadyTime;
|
||||
public WatchVariable Variable;
|
||||
public Rect Rect;
|
||||
public int StartIndex;
|
||||
public int EndIndex;
|
||||
public bool HasSearchResults;
|
||||
public int SearchId;
|
||||
public Texture2D Texture;
|
||||
public Color32[] Colors;
|
||||
public CancellationTokenSource Token;
|
||||
public PreviewCalcMeta CalcMeta = new();
|
||||
public Vector2Int Size => new (Mathf.CeilToInt(Rect.width), Mathf.CeilToInt(Rect.height));
|
||||
|
||||
public enum StateType
|
||||
{
|
||||
Computing,
|
||||
ComputingSilently,
|
||||
ReadyToSetPixels,
|
||||
ReadyToUse
|
||||
}
|
||||
}
|
||||
|
||||
private class PreviewCalcMeta
|
||||
{
|
||||
public List<int> KeysToDisplay;
|
||||
public List<int> ChildCountPerBlock;
|
||||
public int PixelBlockCount;
|
||||
public PixelBlockInfo[] PixelBlocks;
|
||||
}
|
||||
|
||||
private class PixelBlockInfo
|
||||
{
|
||||
public int HeightPixels;
|
||||
public List<string> ChildNames = new();
|
||||
public Dictionary<int, ValueModeType> ModePerKeys = new();
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
ChildNames.Clear();
|
||||
ModePerKeys.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
private enum ValueModeType
|
||||
{
|
||||
None = 0,
|
||||
HasValue = 1 << 0,
|
||||
EmptyValue = 1 << 1,
|
||||
Original = 1 << 2,
|
||||
Searched = 1 << 3,
|
||||
|
||||
OriginalWithValue = HasValue | Original,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 848b74d86e4e4da4b3f5e7ad740b2c53
|
||||
timeCreated: 1727021380
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchPreviewDrawer.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 41800da9799c48f19a23c6e8ea172edf
|
||||
timeCreated: 1653071522
|
||||
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class CellSettingsDropdownWindow : EditorWindow
|
||||
{
|
||||
protected float ColumnWidth
|
||||
{
|
||||
get => WatchStorageSO.instance.ColumnWidth;
|
||||
set => WatchStorageSO.instance.ColumnWidth = value;
|
||||
}
|
||||
|
||||
protected float RowHeight
|
||||
{
|
||||
get => WatchStorageSO.instance.RowHeight;
|
||||
set => WatchStorageSO.instance.RowHeight = value;
|
||||
}
|
||||
|
||||
protected bool IsLeftSelection
|
||||
{
|
||||
get => WatchStorageSO.instance.IsLeftSelection;
|
||||
set => WatchStorageSO.instance.IsLeftSelection = value;
|
||||
}
|
||||
|
||||
private int selectionTypeIndex;
|
||||
private static string[] selectionTypes = new[] {"Left", "Right"};
|
||||
private static Vector2 windowSize = new Vector2(150, 90);
|
||||
|
||||
public static void Create(Rect buttonRect)
|
||||
{
|
||||
var window = CreateInstance<CellSettingsDropdownWindow>();
|
||||
window.ShowAsDropDown(buttonRect, windowSize);
|
||||
window.Focus();
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
var prevWidth = ColumnWidth;
|
||||
var prevHeight = RowHeight;
|
||||
|
||||
DrawBackground();
|
||||
DrawWidthSlider();
|
||||
DrawHeightSlider();
|
||||
DrawSelectionPopup();
|
||||
DrawRestoreDefaultsButton();
|
||||
|
||||
if (Math.Abs(prevWidth - ColumnWidth) > 0.001f
|
||||
|| Math.Abs(prevHeight - RowHeight) > 0.001f)
|
||||
{
|
||||
var window = GetWindow<LiveWatchWindow>();
|
||||
|
||||
EditorUtility.SetDirty(window);
|
||||
Focus();
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawBackground()
|
||||
{
|
||||
if (Event.current.type != EventType.Repaint)
|
||||
return;
|
||||
|
||||
var rect = new Rect(0, 0, position.width, position.height);
|
||||
|
||||
EditorGUI.DrawRect(rect, Color.black);
|
||||
EditorGUI.DrawRect(rect.Extrude(ExtrudeFlags.All, -1), Colors.Background);
|
||||
}
|
||||
|
||||
private void DrawWidthSlider()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Label(new GUIContent("Width", "Width of watch cells"), GUILayout.Width(60));
|
||||
ColumnWidth = GUILayout.HorizontalSlider(ColumnWidth, Constants.VariableValueColumnWidthMin, Constants.VariableValueColumnWidthMax);
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void DrawHeightSlider()
|
||||
{
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Label(new GUIContent("Height", "Height of watch cells"), GUILayout.Width(60));
|
||||
RowHeight = GUILayout.HorizontalSlider(RowHeight, Constants.VariableRowHeighMin, Constants.VariableRowHeightMax);
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
}
|
||||
|
||||
private void DrawSelectionPopup()
|
||||
{
|
||||
selectionTypeIndex = IsLeftSelection ? 0 : 1;
|
||||
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
GUILayout.Label(new GUIContent("Selection", "The direction of cell's selection"), GUILayout.Width(60));
|
||||
selectionTypeIndex = EditorGUILayout.Popup(selectionTypeIndex, selectionTypes);
|
||||
GUILayout.Space(5);
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
IsLeftSelection = selectionTypeIndex == 0;
|
||||
}
|
||||
|
||||
private void DrawRestoreDefaultsButton()
|
||||
{
|
||||
GUILayout.FlexibleSpace();
|
||||
|
||||
if (GUILayout.Button(new GUIContent("Restore defaults", "Reset all view preferences to default values")))
|
||||
{
|
||||
ColumnWidth = 30;
|
||||
RowHeight = 30;
|
||||
IsLeftSelection = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b48c34bd3e504c09803af7a0b361e42b
|
||||
timeCreated: 1724491075
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/CellSettingsDropdownWindow.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class InfoGUI
|
||||
{
|
||||
public WatchVariable SelectedVariable { get; set; }
|
||||
public bool IsTitleSelected { get; set; }
|
||||
public int SelectedColumn { get; set; }
|
||||
|
||||
private Rect contentRect;
|
||||
private Vector2 scrollPosition;
|
||||
|
||||
public void OnGUI(Rect areaRect)
|
||||
{
|
||||
EditorGUI.DrawRect(areaRect.Extrude(ExtrudeFlags.Top, 1), Colors.Background);
|
||||
|
||||
if (SelectedVariable == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsTitleSelected)
|
||||
{
|
||||
DrawForTitle(areaRect);
|
||||
}
|
||||
else if (SelectedVariable.HasValues)
|
||||
{
|
||||
DrawForValues(areaRect);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawForTitle(Rect rect)
|
||||
{
|
||||
contentRect = rect.Extrude(ExtrudeFlags.All, -2);
|
||||
|
||||
GUILayout.BeginArea(contentRect);
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition);
|
||||
|
||||
DrawVariableName();
|
||||
|
||||
GUILayout.FlexibleSpace();
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
private void DrawForValues(Rect rect)
|
||||
{
|
||||
if (!SelectedVariable.Values.AnyAt(SelectedColumn))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
contentRect = rect.Extrude(ExtrudeFlags.All, -2);
|
||||
|
||||
GUILayout.BeginArea(contentRect);
|
||||
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUIStyle.none);
|
||||
|
||||
DrawValueText();
|
||||
|
||||
GUILayout.EndScrollView();
|
||||
GUILayout.EndArea();
|
||||
}
|
||||
|
||||
private void DrawVariableName()
|
||||
{
|
||||
DrawLabel(SelectedVariable.Name, Styles.InfoValueText);
|
||||
}
|
||||
|
||||
private void DrawValueText()
|
||||
{
|
||||
var selectedValueText = SelectedVariable.GetValueText(SelectedColumn);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(selectedValueText))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawLabel(selectedValueText, Styles.InfoValueText);
|
||||
}
|
||||
|
||||
private void DrawLabel(string text, GUIStyle textStyle)
|
||||
{
|
||||
var content = WatchEditorServices.GUICache.GetContent(text);
|
||||
var estimatedHeight = textStyle.CalcHeight(content, contentRect.width);
|
||||
|
||||
EditorGUILayout.SelectableLabel(
|
||||
text,
|
||||
textStyle,
|
||||
GUILayout.ExpandWidth(true),
|
||||
GUILayout.ExpandHeight(false),
|
||||
GUILayout.Height(estimatedHeight));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ad9df77212b54b11b26b9e11a74868ba
|
||||
timeCreated: 1657039461
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/InfoGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,171 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEditorInternal;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class LiveWatchWindow : EditorWindow
|
||||
{
|
||||
public static bool IsRepaintRequested { get; set; }
|
||||
public static int SelectedColumnIndex { get; set; } = -1;
|
||||
public static float MaxPlayRepaintDelay { get; set; } = 1f;
|
||||
public static float MinSoftRepaintDelay { get; set; } = 0.3f;
|
||||
|
||||
private Vector2 _watchesScrollPosition;
|
||||
|
||||
[SerializeField] private ToolbarGUI _toolbarGUI = new ToolbarGUI();
|
||||
[SerializeField] private VariablesListGUI _variablesListGUI = new VariablesListGUI();
|
||||
[SerializeField] private InfoGUI _infoGUI = new InfoGUI();
|
||||
|
||||
[SerializeField] private ResizerGUI _horizontalResizerSearchToList = new ResizerGUI(true, 8, 1, Color.black);
|
||||
[SerializeField] private ResizerGUI _horizontalResizerListToInfo = new ResizerGUI(true, 8, 1, Color.black, 1);
|
||||
[SerializeField] private ResizerGUI _verticalResizerNameToValues = new ResizerGUI(false, 8, 1, Color.black);
|
||||
|
||||
private float previousRepaintTime;
|
||||
|
||||
[MenuItem("Window/LiveWatch")]
|
||||
static void Init()
|
||||
{
|
||||
LiveWatchWindow window = (LiveWatchWindow)EditorWindow.GetWindow(typeof(LiveWatchWindow));
|
||||
window.titleContent = new GUIContent("LiveWatch");
|
||||
window.Show();
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
IsRepaintRequested = false;
|
||||
_variablesListGUI.OnEnable();
|
||||
EditorApplication.update += OnEditorUpdate;
|
||||
Watch.OnClearedAll += OnWatchClearedAll;
|
||||
Watch.OnDestroyedAll += OnWatchDestroyedAll;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
EditorApplication.update -= OnEditorUpdate;
|
||||
Watch.OnClearedAll -= OnWatchClearedAll;
|
||||
Watch.OnDestroyedAll -= OnWatchDestroyedAll;
|
||||
}
|
||||
|
||||
private void OnEditorUpdate()
|
||||
{
|
||||
if (EditorApplication.isPlaying)
|
||||
{
|
||||
if (Time.realtimeSinceStartup < previousRepaintTime + MaxPlayRepaintDelay)
|
||||
return;
|
||||
|
||||
Repaint();
|
||||
}
|
||||
else if (IsRepaintRequested)
|
||||
{
|
||||
if (Time.realtimeSinceStartup < previousRepaintTime + MinSoftRepaintDelay)
|
||||
return;
|
||||
|
||||
IsRepaintRequested = false;
|
||||
Repaint();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnGUI()
|
||||
{
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
previousRepaintTime = Time.realtimeSinceStartup;
|
||||
|
||||
Profiler.BeginSample("Watch GUI");
|
||||
|
||||
HandleResizers();
|
||||
|
||||
DrawVariableList();
|
||||
|
||||
DrawToolbar();
|
||||
DrawInfo();
|
||||
|
||||
DrawResizers();
|
||||
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
private void OnWatchClearedAll()
|
||||
{
|
||||
_variablesListGUI.Clear();
|
||||
}
|
||||
|
||||
private void OnWatchDestroyedAll()
|
||||
{
|
||||
_variablesListGUI.Clear();
|
||||
}
|
||||
|
||||
private void HandleResizers()
|
||||
{
|
||||
if (_toolbarGUI.Search)
|
||||
{
|
||||
_horizontalResizerSearchToList.LocalArea = new Rect(0, 0, position.width, position.height)
|
||||
.CropFromStartToPosition(CropEdge.TopLocal, _horizontalResizerListToInfo.Position)
|
||||
.CropFromPositionToEnd(CropEdge.TopLocal, Constants.ToolbarAreaHeight + Constants.SearchAreaMinHeight)
|
||||
.CropFromPositionToEnd(CropEdge.BottomLocal, Constants.VariablesAreaMinHeight);
|
||||
|
||||
_horizontalResizerSearchToList.ProcessHandle();
|
||||
}
|
||||
|
||||
_verticalResizerNameToValues.LocalArea = new Rect(0, 0, position.width, position.height)
|
||||
.CropFromStartToPosition(CropEdge.TopLocal, _horizontalResizerListToInfo.Position)
|
||||
.CropFromPositionToEnd(CropEdge.TopLocal, _toolbarGUI.Search ? _horizontalResizerSearchToList.Position : Constants.ToolbarAreaHeight)
|
||||
.CropFromPositionToEnd(CropEdge.LeftLocal, Constants.VariableLabelMinWidth)
|
||||
.CropFromPositionToEnd(CropEdge.RightLocal, Constants.VariableValuesMinWidth);
|
||||
|
||||
_horizontalResizerListToInfo.LocalArea = new Rect(0, 0, position.width, position.height)
|
||||
.CropFromPositionToEnd(CropEdge.TopLocal, Constants.ToolbarAreaHeight + Constants.SearchAreaMinHeight + Constants.VariablesAreaMinHeight)
|
||||
.CropFromPositionToEnd(CropEdge.BottomLocal, Constants.InfoAreaMinHeight);
|
||||
|
||||
_verticalResizerNameToValues.ProcessHandle();
|
||||
_horizontalResizerListToInfo.ProcessHandle();
|
||||
}
|
||||
|
||||
private void DrawResizers()
|
||||
{
|
||||
if (_toolbarGUI.Search)
|
||||
{
|
||||
_horizontalResizerSearchToList.DrawLine();
|
||||
}
|
||||
|
||||
_verticalResizerNameToValues.DrawLine();
|
||||
_horizontalResizerListToInfo.DrawLine();
|
||||
}
|
||||
|
||||
private void DrawToolbar()
|
||||
{
|
||||
var toolbarRect = new Rect(0, 0, position.width + 1, Constants.ToolbarAreaHeight);
|
||||
|
||||
_toolbarGUI.WindowRect = position;
|
||||
_toolbarGUI.OnGUI(toolbarRect);
|
||||
}
|
||||
|
||||
|
||||
private void DrawVariableList()
|
||||
{
|
||||
var contentRect = new Rect(0, 0, position.width + 1, position.height)
|
||||
.CropFromPositionToPosition(
|
||||
CropEdge.TopLocal,
|
||||
_toolbarGUI.Search ? _horizontalResizerSearchToList.Position : Constants.ToolbarAreaHeight,
|
||||
_horizontalResizerListToInfo.Position);
|
||||
|
||||
_variablesListGUI.Search = _toolbarGUI.Search;
|
||||
_variablesListGUI.NameColumnWidth = _verticalResizerNameToValues.Position;
|
||||
_variablesListGUI.OnGUI(contentRect);
|
||||
}
|
||||
|
||||
private void DrawInfo()
|
||||
{
|
||||
var infoRect = new Rect(0, _horizontalResizerListToInfo.Position + 1, position.width + 1, position.height - _horizontalResizerListToInfo.Position - 1);
|
||||
|
||||
_infoGUI.SelectedVariable = _variablesListGUI.SelectedVariable;
|
||||
_infoGUI.IsTitleSelected = _variablesListGUI.IsTitleSelected;
|
||||
_infoGUI.SelectedColumn = _variablesListGUI.SelectedColumnIndex;
|
||||
|
||||
_infoGUI.OnGUI(infoRect);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f81180f981e90b459cd7620791b6aca
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/LiveWatchWindow.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,148 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
public class ToolbarGUI
|
||||
{
|
||||
public bool Search { get; set; }
|
||||
public bool Live
|
||||
{
|
||||
get => Watch.IsLive;
|
||||
set => Watch.IsLive = value;
|
||||
}
|
||||
public bool Collapse
|
||||
{
|
||||
get => WatchStorageSO.instance.Collapse;
|
||||
set => WatchStorageSO.instance.Collapse = value;
|
||||
}
|
||||
|
||||
public WatchStorage Watches
|
||||
{
|
||||
get => WatchStorageSO.instance.Watches;
|
||||
set
|
||||
{
|
||||
Watch.DestroyAll();
|
||||
WatchStorageSO.instance.Watches = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Rect WindowRect { get; set; }
|
||||
private Rect areaRect;
|
||||
private float xOffsetRight;
|
||||
private float xOffsetLeft;
|
||||
private GUIContent saveButtonContent;
|
||||
private GUIContent loadButtonContent;
|
||||
private GUIContent optionsButtonContent;
|
||||
private List<WatchVariable> variables = new();
|
||||
|
||||
public void OnGUI(Rect areaRect)
|
||||
{
|
||||
this.areaRect = areaRect;
|
||||
GUI.Label(areaRect, string.Empty, EditorStyles.toolbar);
|
||||
|
||||
xOffsetLeft = 0;
|
||||
|
||||
var centerBlockWidth = Constants.ToolbarLiveButtonWidth + Constants.ToolbarCollapseButtonWidth + Constants.ToolbarClearButtonWidth;
|
||||
xOffsetLeft = areaRect.width/2 - centerBlockWidth/2;
|
||||
DoLiveButton(CropEdge.LeftLocal, ref xOffsetLeft);
|
||||
DoCollapseButton(CropEdge.LeftLocal, ref xOffsetLeft);
|
||||
DoClearButton(CropEdge.LeftLocal, ref xOffsetLeft);
|
||||
|
||||
xOffsetRight = 0;
|
||||
DoOptionsButton(CropEdge.RightLocal, ref xOffsetRight);
|
||||
DoViewSettingsButton(CropEdge.RightLocal, ref xOffsetRight);
|
||||
}
|
||||
|
||||
|
||||
private void DoOptionsButton(CropEdge edge, ref float offset)
|
||||
{
|
||||
optionsButtonContent ??= EditorGUIUtility.TrIconContent("_Menu", "Extra options");
|
||||
var rect = areaRect.CropFromPositionWithSize(edge, offset, Constants.ToolbarOptionsButtonWidth);
|
||||
|
||||
if (GUI.Button(rect, optionsButtonContent, EditorStyles.toolbarButton))
|
||||
{
|
||||
GenericMenu genericMenu = new GenericMenu();
|
||||
|
||||
genericMenu.AddItem(new GUIContent(
|
||||
"Preferences", "Go to Live Watch preferences"),
|
||||
false,
|
||||
new GenericMenu.MenuFunction(OpenPreferences));
|
||||
genericMenu.AddItem(new GUIContent(
|
||||
"Collapse all rows", "Collapses all watched variables recursively"),
|
||||
false,
|
||||
new GenericMenu.MenuFunction(CollapseAll));
|
||||
genericMenu.AddItem(new GUIContent(
|
||||
"Destroy all watches", "Directly calls Watch.DestroyAll() and removes all watched variables"),
|
||||
false,
|
||||
new GenericMenu.MenuFunction(Watch.DestroyAll));
|
||||
genericMenu.DropDown(rect);
|
||||
}
|
||||
|
||||
offset += Constants.ToolbarOptionsButtonWidth;
|
||||
|
||||
void OpenPreferences()
|
||||
{
|
||||
SettingsService.OpenUserPreferences("Preferences/Live Watch");
|
||||
}
|
||||
|
||||
void CollapseAll()
|
||||
{
|
||||
Watches.GetAllChildRecursive(variables, WatchFilters.NoChilds, WatchFilters.None);
|
||||
|
||||
foreach (var variable in variables)
|
||||
variable.EditorMeta.IsExpanded = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void DoViewSettingsButton(CropEdge edge, ref float offset)
|
||||
{
|
||||
var rect = areaRect.CropFromPositionWithSize(edge, offset, Constants.ToolbarViewButtonWidth);
|
||||
var content = new GUIContent("View");
|
||||
|
||||
if (GUI.Button(rect, content, EditorStyles.toolbarDropDown))
|
||||
{
|
||||
var buttonWorldRect = new Rect(rect.x + WindowRect.x, rect.yMax + WindowRect.y, rect.width, rect.height);
|
||||
CellSettingsDropdownWindow.Create(buttonWorldRect);
|
||||
}
|
||||
|
||||
offset += Constants.ToolbarViewButtonWidth;
|
||||
}
|
||||
|
||||
private void DoClearButton(CropEdge edge, ref float offset)
|
||||
{
|
||||
var rect = areaRect.CropFromPositionWithSize(edge, offset, Constants.ToolbarClearButtonWidth);
|
||||
var content = new GUIContent("Clear", "Clear all watch values");
|
||||
|
||||
if (GUI.Button(rect, content, EditorStyles.toolbarButton))
|
||||
{
|
||||
Watch.ClearAll();
|
||||
}
|
||||
|
||||
offset += Constants.ToolbarClearButtonWidth;
|
||||
}
|
||||
|
||||
private void DoCollapseButton(CropEdge edge, ref float offset)
|
||||
{
|
||||
var rect = areaRect.CropFromPositionWithSize(edge, offset, Constants.ToolbarCollapseButtonWidth);
|
||||
var content = new GUIContent("Collapse", Collapse ? "Show columns without unique values" : "Hide columns without unique values");
|
||||
|
||||
Collapse = GUI.Toggle(rect, Collapse, content, EditorStyles.toolbarButton);
|
||||
|
||||
offset += Constants.ToolbarCollapseButtonWidth;
|
||||
}
|
||||
|
||||
private void DoLiveButton(CropEdge edge, ref float offset)
|
||||
{
|
||||
var rect = areaRect.CropFromPositionWithSize(edge, offset, Constants.ToolbarLiveButtonWidth);
|
||||
var content = new GUIContent("Live", Live ? "Watches are recording. Click to pause" : "Watches are not recording. Click to unpause");
|
||||
|
||||
Live = GUI.Toggle(rect, Live, content, EditorStyles.toolbarButton);
|
||||
|
||||
offset += Constants.ToolbarLiveButtonWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e16d283d694d4d4aa55978ca311438b6
|
||||
timeCreated: 1651572292
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/ToolbarGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,247 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class VariableCellGUI
|
||||
{
|
||||
public bool IsSelected { get; set; }
|
||||
public int RowIndex { get; set; }
|
||||
public int SelectedColumnIndex { get; set; }
|
||||
public bool IsNarrowMode { get; set; }
|
||||
public float ValueColumnWidth { get; set; }
|
||||
public WatchVariable Variable { get; set; }
|
||||
public Rect ValuesRect { get; set; }
|
||||
public VariableSelectedFitInfo SelectedFitInfo { get; set; }
|
||||
public bool PreferRightSelection { get; set; }
|
||||
public List<int> IndicesToDisplay { get; set; }
|
||||
|
||||
private VariableSelectedFitInfo _currentFitInfo = new();
|
||||
|
||||
private float currentSideOffset;
|
||||
private bool isRightSelection => PreferRightSelection ? SelectedFitInfo.CanFitRight : !SelectedFitInfo.CanFitLeft;
|
||||
|
||||
public void DrawValueCellSegment(Rect rect, string value, List<int> contentIndices, float progress)
|
||||
{
|
||||
if (Event.current.type is not EventType.Repaint)
|
||||
return;
|
||||
|
||||
currentSideOffset = 0;
|
||||
|
||||
if (value == string.Empty)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var isSelected = contentIndices.Contains(SelectedColumnIndex);
|
||||
|
||||
EditorGUI.DrawRect(rect.Extrude(ExtrudeFlags.All, -1f), Colors.SegmentFrame);
|
||||
EditorGUI.DrawRect(rect.Extrude(ExtrudeFlags.All, -2.5f), RowIndex % 2 == 0 ? Colors.Background : Colors.BackgroundOdd);
|
||||
|
||||
var innerRect = rect.Extrude(ExtrudeFlags.All, -4f);
|
||||
currentSideOffset = 4;
|
||||
|
||||
var progressPixels = Mathf.FloorToInt(Mathf.Clamp(progress * innerRect.height, 2, innerRect.height));
|
||||
var progressRect = innerRect.CropFromPositionWithSize(CropEdge.BottomLocal, 0.5f, progressPixels);
|
||||
var progressColor = RowIndex % 2 == 0 ? Colors.SegmentFill : Colors.SegmentFillOdd;
|
||||
|
||||
DrawFormatCells(progressRect, contentIndices, progressColor);
|
||||
DrawDividerCells(progressRect.Extrude(ExtrudeFlags.Left | ExtrudeFlags.Right, 4f), contentIndices);
|
||||
|
||||
if (isSelected)
|
||||
return;
|
||||
|
||||
var estimatedSize = Styles.VariableValue.CalcSize(WatchEditorServices.GUICache.GetContent(value));
|
||||
estimatedSize.x -= 4;
|
||||
var valueRect = innerRect;
|
||||
|
||||
if (estimatedSize.x > valueRect.width)
|
||||
{
|
||||
var dotsRect = valueRect
|
||||
.CropFromPositionWithSize(CropEdge.RightLocal, 0, 7)
|
||||
.CropFromPositionWithSize(CropEdge.BottomLocal, valueRect.height/2f - 6, 3);
|
||||
|
||||
GUI.DrawTexture(dotsRect,
|
||||
Textures.Dots);
|
||||
valueRect = valueRect.Extrude(ExtrudeFlags.Right, -6);
|
||||
}
|
||||
|
||||
if (valueRect.width > 5)
|
||||
{
|
||||
var style = estimatedSize.x > valueRect.width ? Styles.VariableValueLeft : Styles.VariableValue;
|
||||
DrawLabelWitchSearchResult(valueRect, Variable.GetValueText(contentIndices[0]), contentIndices[0], style);
|
||||
}
|
||||
}
|
||||
|
||||
public void DrawSelectedCell(Rect rect, string value, int index)
|
||||
{
|
||||
if (Event.current.type is not (EventType.Repaint or EventType.Layout))
|
||||
return;
|
||||
|
||||
var availableRect = rect.Extrude(ExtrudeFlags.All, -1);
|
||||
var estimatedSize = Styles.VariableValueSelected.CalcSize(WatchEditorServices.GUICache.GetContent(value))
|
||||
+ Vector2.right * 10;
|
||||
var resultWidth = Mathf.Max(availableRect.width, estimatedSize.x);
|
||||
|
||||
if (Event.current.type is not EventType.Repaint)
|
||||
{
|
||||
var cellRectRight = availableRect.CropFromStartToPosition(CropEdge.LeftLocal, resultWidth);
|
||||
_currentFitInfo.CanFitRight = cellRectRight.xMax <= ValuesRect.xMax;
|
||||
|
||||
var cellRectLeft = availableRect.CropFromStartToPosition(CropEdge.RightLocal, resultWidth);
|
||||
_currentFitInfo.CanFitLeft = cellRectLeft.xMin >= ValuesRect.xMin;
|
||||
|
||||
SelectedFitInfo.MergeWith(_currentFitInfo);
|
||||
return;
|
||||
}
|
||||
|
||||
var edge = PreferRightSelection
|
||||
? SelectedFitInfo.CanFitRight ? CropEdge.LeftLocal : CropEdge.RightLocal
|
||||
: SelectedFitInfo.CanFitLeft ? CropEdge.RightLocal : CropEdge.LeftLocal;
|
||||
|
||||
var distToValuesEdge = edge == CropEdge.LeftLocal
|
||||
? ValuesRect.xMax - availableRect.xMin
|
||||
: availableRect.xMax - ValuesRect.xMin;
|
||||
|
||||
if (distToValuesEdge > 40)
|
||||
resultWidth = Mathf.Min(resultWidth, distToValuesEdge - 5);
|
||||
|
||||
var cellBackRect = availableRect.CropFromStartToPosition(edge, resultWidth);
|
||||
|
||||
if (IsNarrowMode)
|
||||
{
|
||||
cellBackRect = cellBackRect.OffsetByX(Mathf.Max(rect.width, Constants.VariableSelectionLineMinWidth)
|
||||
* (edge == CropEdge.LeftLocal ? 1 : - 1));
|
||||
cellBackRect = cellBackRect.Extrude(
|
||||
ExtrudeFlags.Top | ExtrudeFlags.Bottom,
|
||||
-Mathf.Abs(cellBackRect.height - estimatedSize.y)/2f);
|
||||
}
|
||||
|
||||
EditorGUI.DrawRect(cellBackRect, IsNarrowMode ? Colors.CellBackgroundSelectedGraph : Colors.CellBackgroundSelected);
|
||||
|
||||
DrawPreviewTriangles(cellBackRect);
|
||||
DrawSelectedCelLine(rect);
|
||||
|
||||
var cellValueRect = cellBackRect;
|
||||
var isTextFit = estimatedSize.x < cellValueRect.width;
|
||||
var textStyle = isTextFit ? Styles.VariableValueSelected : Styles.VariableValueSelectedLeft;
|
||||
cellValueRect = cellValueRect.CropFromPositionToEnd(CropEdge.LeftLocal, isTextFit ? 0 : 5);
|
||||
DrawLabelWitchSearchResult(cellValueRect, value, index, textStyle);
|
||||
}
|
||||
|
||||
public void DrawSelectedCelLine(Rect rect)
|
||||
{
|
||||
if (Event.current.type is not EventType.Repaint)
|
||||
return;
|
||||
|
||||
var edge = PreferRightSelection
|
||||
? SelectedFitInfo.CanFitRight ? CropEdge.LeftLocal : CropEdge.RightLocal
|
||||
: SelectedFitInfo.CanFitLeft ? CropEdge.RightLocal : CropEdge.LeftLocal;
|
||||
|
||||
var lineRect = IsNarrowMode
|
||||
? rect
|
||||
: rect.CropFromPositionWithSize(edge, 1, 3);
|
||||
|
||||
if (IsNarrowMode && lineRect.width < Constants.VariableSelectionLineMinWidth)
|
||||
{
|
||||
lineRect = new Rect(
|
||||
lineRect.center.x - Constants.VariableSelectionLineMinWidth / 2,
|
||||
lineRect.y,
|
||||
Constants.VariableSelectionLineMinWidth,
|
||||
lineRect.height);
|
||||
}
|
||||
|
||||
EditorGUI.DrawRect(lineRect, IsNarrowMode ? Colors.CellSelectionLineGraph : Colors.CellSelectionLine);
|
||||
}
|
||||
|
||||
private void DrawLabelWitchSearchResult(Rect labelRect, string text, int index, GUIStyle style, bool forceFullSelection = false)
|
||||
{
|
||||
if (Event.current.type is not EventType.Repaint)
|
||||
return;
|
||||
|
||||
if (labelRect.width > ValueColumnWidth)
|
||||
labelRect = labelRect.FitInRect(ValuesRect);
|
||||
style.Draw(labelRect, WatchEditorServices.GUICache.GetContent(text), -1);
|
||||
}
|
||||
|
||||
private void DrawFormatCells(Rect rect, List<int> contentIndices, Color fallbackColor)
|
||||
{
|
||||
{
|
||||
TryDrawFormatRect(rect
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
void TryDrawFormatRect(Rect formatRect
|
||||
)
|
||||
{
|
||||
if (fallbackColor != Color.clear)
|
||||
EditorGUI.DrawRect(formatRect, fallbackColor);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawDividerCells(Rect rect, List<int> contentIndices)
|
||||
{
|
||||
WatchEditorServices.CellDividerDrawer.Draw(rect, Mathf.FloorToInt(ValueColumnWidth));
|
||||
}
|
||||
|
||||
|
||||
private Rect GetCellRect(int index, Rect rect, List<int> contentIndices)
|
||||
{
|
||||
var cellWidth = ValueColumnWidth;
|
||||
|
||||
if (index == 0)
|
||||
cellWidth -= currentSideOffset;
|
||||
|
||||
if (index == contentIndices.Count - 1)
|
||||
cellWidth -= currentSideOffset;
|
||||
|
||||
var cellRect = rect.CropFromPositionWithSize(
|
||||
CropEdge.LeftLocal,
|
||||
index * ValueColumnWidth + (index == 0 ? 0 : -currentSideOffset),
|
||||
cellWidth);
|
||||
|
||||
return cellRect;
|
||||
}
|
||||
|
||||
private void DrawPreviewTriangles(Rect rect)
|
||||
{
|
||||
var isSelectedNumberValid = Variable.IsValidNumberValue(SelectedColumnIndex, out var selectedNumberValue);
|
||||
|
||||
if (Variable.Values.IsOriginalAt(SelectedColumnIndex))
|
||||
{
|
||||
var prevToSelectedIndex = IndicesToDisplay.IndexOf(SelectedColumnIndex) - 1;
|
||||
|
||||
if (prevToSelectedIndex >= 0)
|
||||
{
|
||||
var isPrevNumberValid = Variable.IsValidNumberValue(IndicesToDisplay[prevToSelectedIndex], out var prevNumberValue);
|
||||
var isTopAngle = isPrevNumberValid && prevNumberValue >= selectedNumberValue;
|
||||
var isNextToSearchResult = false;
|
||||
var triangleLeftRect = rect
|
||||
.CropFromPositionWithSize(CropEdge.LeftLocal, IsNarrowMode ? 1 : (isRightSelection ? 3 : 0), 4)
|
||||
.CropFromPositionWithSize(isTopAngle ? CropEdge.TopLocal : CropEdge.BottomLocal, IsSelected && !IsNarrowMode ? 3 : 0, 4);
|
||||
GUI.DrawTexture(triangleLeftRect, isTopAngle
|
||||
? (isNextToSearchResult ? Textures.BlueTriangleTopLeft : Textures.WhiteTriangleTopLeft)
|
||||
: (isNextToSearchResult ? Textures.BlueTriangleBottomLeft : Textures.WhiteTriangleBottomLeft));
|
||||
}
|
||||
}
|
||||
|
||||
var nextToSelectedIndex = IndicesToDisplay.IndexOf(SelectedColumnIndex) + 1;
|
||||
if (nextToSelectedIndex < IndicesToDisplay.Count && Variable.Values.IsOriginalAt(IndicesToDisplay[nextToSelectedIndex]))
|
||||
{
|
||||
var isNextNumberValid = Variable.IsValidNumberValue(IndicesToDisplay[nextToSelectedIndex], out var nextNumberValue);
|
||||
var isTopAngle = isNextNumberValid && nextNumberValue >= selectedNumberValue;
|
||||
var isNextToSearchResult = false;
|
||||
var triangleRightRect = rect
|
||||
.CropFromPositionWithSize(CropEdge.RightLocal, isRightSelection || IsNarrowMode ? 0 : 3, 4)
|
||||
.CropFromPositionWithSize(isTopAngle ? CropEdge.TopLocal : CropEdge.BottomLocal, IsSelected && !IsNarrowMode ? 3 : 0, 4);
|
||||
GUI.DrawTexture(triangleRightRect, isTopAngle
|
||||
? (isNextToSearchResult ? Textures.BlueTriangleTopRight : Textures.WhiteTriangleTopRight)
|
||||
: (isNextToSearchResult ? Textures.BlueTriangleBottomRight : Textures.WhiteTriangleBottomRight));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3514d7c2cb624b31ad8e441dc64facfe
|
||||
timeCreated: 1686599538
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/VariableCellGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,396 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class VariableGUI
|
||||
{
|
||||
public int Index { get; set; }
|
||||
public int IndentLevel { get; set; }
|
||||
public float LabelAreaWidth { get; set; }
|
||||
public float ValueColumnWidth { get; set; }
|
||||
public float ValueRowHeight { get; set; }
|
||||
public bool IsMouseDraggingOverValues { get; set; }
|
||||
public float HorizontalScrollValue { get; set; }
|
||||
public int SelectedColumnIndex { get; set; }
|
||||
public bool Search { get; set; }
|
||||
public bool Collapse { get; set; }
|
||||
public Rect VariablesTotalArea { get; set; }
|
||||
public int StartIndex { get; set; }
|
||||
public float RectOffset { get; set; }
|
||||
public List<int> IndicesToDisplay { get; set; }
|
||||
public int IndicesCount { get; set; }
|
||||
public bool IsSelected { get; set; }
|
||||
public VariableSelectedFitInfo SelectedFitInfo { get; set; }
|
||||
public bool PreferRightSelection { get; set; }
|
||||
public double MinValue { get; set; }
|
||||
public double MaxValue { get; set; }
|
||||
public bool IsNarrowMode => ValueColumnWidth <= 12;
|
||||
public VariableClickInfo ClickInfo => _clickInfo;
|
||||
|
||||
protected Color BackgroundColor => Index % 2 == 0 ? Colors.Background : Colors.BackgroundOdd;
|
||||
protected VariableCellGUI CellGUI
|
||||
{
|
||||
get { return _cellGUI ??= new VariableCellGUI(); }
|
||||
}
|
||||
protected VariableGraphGUI GraphGUI
|
||||
{
|
||||
get { return _graphGUI ??= new VariableGraphGUI(); }
|
||||
}
|
||||
|
||||
[SerializeField] private VariableCellGUI _cellGUI;
|
||||
[SerializeField] private VariableGraphGUI _graphGUI;
|
||||
|
||||
private WatchVariable _variable;
|
||||
private VariableClickInfo _clickInfo;
|
||||
private List<int> _segmentIndices = new(100);
|
||||
|
||||
public void Draw(Rect rect, WatchVariable variable)
|
||||
{
|
||||
_variable = variable;
|
||||
|
||||
_clickInfo = new VariableClickInfo()
|
||||
{
|
||||
CurrentPositionIndex = -1
|
||||
};
|
||||
|
||||
var valuesRect = rect.CropFromPositionToEnd(CropEdge.LeftLocal, LabelAreaWidth);
|
||||
|
||||
CellGUI.IsSelected = IsSelected;
|
||||
CellGUI.Variable = variable;
|
||||
CellGUI.SelectedColumnIndex = SelectedColumnIndex;
|
||||
CellGUI.IsNarrowMode = IsNarrowMode;
|
||||
CellGUI.ValueColumnWidth = ValueColumnWidth;
|
||||
CellGUI.ValuesRect = valuesRect;
|
||||
CellGUI.SelectedFitInfo = SelectedFitInfo;
|
||||
CellGUI.PreferRightSelection = PreferRightSelection;
|
||||
CellGUI.IndicesToDisplay = IndicesToDisplay;
|
||||
|
||||
ProcessRowEvents(rect);
|
||||
|
||||
DrawValuesBackground(valuesRect);
|
||||
DrawValues(valuesRect);
|
||||
|
||||
var labelBackgroundRect = rect.CropFromPositionToPosition(CropEdge.LeftLocal, 0, LabelAreaWidth);
|
||||
var labelRect = rect.CropFromPositionToPosition(CropEdge.LeftLocal,
|
||||
Constants.VariableLabelOffset + Constants.VariableLabelIndentWidth * IndentLevel, LabelAreaWidth);
|
||||
|
||||
DrawLabelBackground(labelBackgroundRect);
|
||||
ProcessLabelEvents(labelRect);
|
||||
DrawLabelContent(labelRect);
|
||||
DrawMinMaxForGraph(labelRect);
|
||||
|
||||
if (IsSelected && variable.HasValues)
|
||||
{
|
||||
GUIExtensions.DrawColorFrame(SelectedColumnIndex > 0 ? rect : labelBackgroundRect, Colors.CellSelectionLine, 3);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawLabelBackground(Rect rect)
|
||||
{
|
||||
EditorGUI.DrawRect(rect, BackgroundColor);
|
||||
}
|
||||
|
||||
#region Full row
|
||||
|
||||
private void ProcessRowEvents(Rect rect)
|
||||
{
|
||||
if (!VariablesTotalArea.Contains(Event.current.mousePosition)
|
||||
|| Event.current.type != EventType.MouseDown && GUIUtility.hotControl != 0)
|
||||
return;
|
||||
|
||||
GUIUtility.hotControl = 0;
|
||||
|
||||
if (rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
if (Event.current.isMouse && Event.current.button == 0)
|
||||
{
|
||||
_clickInfo.IsMouse = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Label zone
|
||||
|
||||
private void ProcessLabelEvents(Rect rect)
|
||||
{
|
||||
if (!VariablesTotalArea.Contains(Event.current.mousePosition) || IsMouseDraggingOverValues)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
_clickInfo.CurrentPositionIndex = -1;
|
||||
_clickInfo.IsOverTitleArea = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawLabelContent(Rect rect)
|
||||
{
|
||||
if (!_variable.HasChilds)
|
||||
{
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
DrawLabelWitchSearchResult(
|
||||
rect,
|
||||
_variable.Name,
|
||||
_variable.EditorMeta.SearchResult.NameResult,
|
||||
Styles.VariableLabel);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (Event.current.type == EventType.Layout || Event.current.type == EventType.Repaint || rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
_variable.EditorMeta.IsExpanded = EditorGUI.Foldout(
|
||||
rect,
|
||||
_variable.EditorMeta.IsExpanded,
|
||||
string.Empty,
|
||||
Styles.VariableFoldoutLabel);
|
||||
|
||||
if (Event.current.type == EventType.Used)
|
||||
_clickInfo.IsOverTitleArea = false;
|
||||
}
|
||||
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
DrawLabelWitchSearchResult(
|
||||
rect.CropFromPositionToEnd(CropEdge.LeftLocal, 15),
|
||||
_variable.Name,
|
||||
_variable.EditorMeta.SearchResult.NameResult,
|
||||
Styles.VariableLabel);
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMinMaxForGraph(Rect rect)
|
||||
{
|
||||
if (Event.current.type != EventType.Repaint
|
||||
|| _variable.Values.Type is WatchValueType.String or WatchValueType.Bool or WatchValueType.NotSet
|
||||
|| !IsNarrowMode
|
||||
|| ValueRowHeight < 38)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var maxValueRect = rect
|
||||
.CropFromPositionWithSize(CropEdge.TopLocal, 2 , Constants.VariableGraphMinValueHeight)
|
||||
.CropFromPositionToEnd(CropEdge.RightLocal, 2);
|
||||
|
||||
var minValueRect = rect
|
||||
.CropFromPositionWithSize(CropEdge.BottomLocal, 2, Constants.VariableGraphMinValueHeight)
|
||||
.CropFromPositionToEnd(CropEdge.RightLocal, 2);
|
||||
|
||||
GUI.Label(maxValueRect, Math.Round(MaxValue, _variable.RuntimeMeta.DecimalPlaces).ToString(), Styles.VariableGraphMaxLabel);
|
||||
GUI.Label(minValueRect, Math.Round(MinValue, _variable.RuntimeMeta.DecimalPlaces).ToString(), Styles.VariableGraphMinLabel);
|
||||
}
|
||||
|
||||
private void DrawLabelWitchSearchResult(Rect labelRect, string text, SearchQueryResult searchResult, GUIStyle style)
|
||||
{
|
||||
if (searchResult.IsPositive)
|
||||
{
|
||||
var charStartIndex = searchResult.IsWholeSelection ? 0 : searchResult.SelectionStartIndex;
|
||||
var charEndIndex = searchResult.IsWholeSelection ? text.Length : searchResult.SelectionEndIndex;
|
||||
|
||||
style.DrawWithTextSelection(
|
||||
labelRect,
|
||||
WatchEditorServices.GUICache.GetContent(text),
|
||||
-1,
|
||||
charStartIndex,
|
||||
charEndIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
style.Draw(labelRect, WatchEditorServices.GUICache.GetContent(text), 0);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Values zone
|
||||
|
||||
private void DrawValuesBackground(Rect rect)
|
||||
{
|
||||
if (Event.current.type is not EventType.Repaint)
|
||||
return;
|
||||
|
||||
EditorGUI.DrawRect(rect, BackgroundColor);
|
||||
}
|
||||
|
||||
private void DrawValues(Rect rect)
|
||||
{
|
||||
if (IndicesToDisplay.Count > 0
|
||||
&& (Event.current.type is EventType.MouseDown && VariablesTotalArea.Contains(Event.current.mousePosition)
|
||||
|| IsMouseDraggingOverValues)
|
||||
&& Event.current.isMouse
|
||||
&& Event.current.button == 0
|
||||
&& GUIUtility.hotControl == 0)
|
||||
{
|
||||
if (rect.Contains(Event.current.mousePosition))
|
||||
{
|
||||
var clickedValueIndex = (int)Mathf.Floor((Event.current.mousePosition.x - (rect.x + RectOffset)) / ValueColumnWidth);
|
||||
clickedValueIndex = Mathf.Clamp(clickedValueIndex, 0, IndicesToDisplay.Count - 1);
|
||||
|
||||
_clickInfo.IsMouse = true;
|
||||
_clickInfo.CurrentPositionIndex = IndicesToDisplay[clickedValueIndex];
|
||||
_clickInfo.MouseButton = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
var selectedIndex = 0;
|
||||
_clickInfo.CurrentPositionIndex = IndicesToDisplay[selectedIndex];
|
||||
}
|
||||
}
|
||||
|
||||
if (IndicesCount == 0 || Event.current.type != EventType.Repaint)
|
||||
{
|
||||
TryDrawSelectedCell();
|
||||
return;
|
||||
}
|
||||
|
||||
if (IsNarrowMode)
|
||||
DrawValuesAsGraph();
|
||||
else
|
||||
DrawValuesAsCells();
|
||||
|
||||
TryDrawSelectedCell();
|
||||
|
||||
if (_variable.HasChilds && !_variable.EditorMeta.IsExpanded)
|
||||
{
|
||||
var previewRect = rect
|
||||
.CropFromPositionWithSize(CropEdge.LeftLocal, RectOffset, IndicesCount * ValueColumnWidth)
|
||||
.Extrude(ExtrudeFlags.Top | ExtrudeFlags.Bottom, -1);
|
||||
var drawRect = IsSelected ? previewRect.Extrude(ExtrudeFlags.Top | ExtrudeFlags.Bottom, -3) : previewRect;
|
||||
|
||||
WatchEditorServices.PreviewDrawer.Search = Search;
|
||||
WatchEditorServices.PreviewDrawer.DrawPreview(previewRect, drawRect, _variable, IndicesToDisplay, Mathf.CeilToInt(ValueColumnWidth));
|
||||
}
|
||||
|
||||
void DrawValuesAsGraph()
|
||||
{
|
||||
GraphGUI.RowIndex = Index;
|
||||
GraphGUI.Variable = _variable;
|
||||
GraphGUI.IndicesToDisplay = IndicesToDisplay;
|
||||
GraphGUI.StartIndex = StartIndex;
|
||||
GraphGUI.IndicesCount = IndicesCount;
|
||||
GraphGUI.MinValue = MinValue;
|
||||
GraphGUI.MaxValue = MaxValue;
|
||||
GraphGUI.ValueColumnWidth = ValueColumnWidth;
|
||||
GraphGUI.BackgroundColor = BackgroundColor;
|
||||
|
||||
var graphRect = rect.CropFromPositionWithSize(CropEdge.LeftLocal, RectOffset, IndicesCount * ValueColumnWidth);
|
||||
GraphGUI.DrawValues(graphRect);
|
||||
}
|
||||
|
||||
void DrawValuesAsCells()
|
||||
{
|
||||
_segmentIndices.Clear();
|
||||
var previousLocalIndex = 0;
|
||||
var previousKeyIndex = _variable.Values.GetOriginalKey(IndicesToDisplay[0]);
|
||||
|
||||
for (var localIndex = 0; localIndex < IndicesCount; localIndex++)
|
||||
{
|
||||
var key = IndicesToDisplay[localIndex];
|
||||
var keyIndex = _variable.Values.GetOriginalKey(key);
|
||||
|
||||
var isOriginal = localIndex != 0 && previousKeyIndex != keyIndex;
|
||||
|
||||
if (isOriginal)
|
||||
{
|
||||
previousKeyIndex = keyIndex;
|
||||
|
||||
DrawSegment(previousLocalIndex, localIndex - 1, _segmentIndices);
|
||||
previousLocalIndex = localIndex;
|
||||
_segmentIndices.Clear();
|
||||
}
|
||||
|
||||
_segmentIndices.Add(key);
|
||||
}
|
||||
|
||||
DrawSegment(previousLocalIndex, IndicesCount - 1, _segmentIndices);
|
||||
}
|
||||
|
||||
void TryDrawSelectedCell()
|
||||
{
|
||||
var isAnySelected = IndicesToDisplay.Contains(SelectedColumnIndex);
|
||||
|
||||
if (!isAnySelected)
|
||||
return;
|
||||
|
||||
var cellRect = rect.CropFromPositionWithSize(
|
||||
CropEdge.LeftLocal,
|
||||
RectOffset + IndicesToDisplay.IndexOf(SelectedColumnIndex) * ValueColumnWidth,
|
||||
ValueColumnWidth);
|
||||
|
||||
if (!_variable.Values.IsEmptyAt(SelectedColumnIndex) && SelectedColumnIndex < _variable.Values.Count)
|
||||
{
|
||||
CellGUI.DrawSelectedCell(cellRect, _variable.GetValueText(SelectedColumnIndex), SelectedColumnIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
CellGUI.DrawSelectedCelLine(cellRect);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawSegment(int startLocalIndex, int endLocalIndex, List<int> contentIndices)
|
||||
{
|
||||
var valueIndex = contentIndices[0];
|
||||
var numberValue = _variable.GetValueNumber(valueIndex);
|
||||
|
||||
var segmentRect = rect.CropFromPositionWithSize(
|
||||
CropEdge.LeftLocal,
|
||||
RectOffset + startLocalIndex * ValueColumnWidth,
|
||||
ValueColumnWidth * (endLocalIndex - startLocalIndex + 1));
|
||||
|
||||
var progress = 0f;
|
||||
|
||||
if (!double.IsNaN(numberValue))
|
||||
{
|
||||
progress = (float)((MaxValue - MinValue) < 0.000001
|
||||
? 1
|
||||
: (numberValue - MinValue) / (MaxValue - MinValue));
|
||||
}
|
||||
|
||||
CellGUI.DrawValueCellSegment(
|
||||
segmentRect,
|
||||
_variable.GetValueText(valueIndex),
|
||||
contentIndices,
|
||||
(float)progress);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public struct VariableClickInfo
|
||||
{
|
||||
public bool IsMouse;
|
||||
public int MouseButton;
|
||||
public int CurrentPositionIndex;
|
||||
public bool IsOverTitleArea;
|
||||
}
|
||||
|
||||
public class VariableSelectedFitInfo
|
||||
{
|
||||
public bool CanFitLeft = true;
|
||||
public bool CanFitRight = true;
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
CanFitLeft = true;
|
||||
CanFitRight = true;
|
||||
}
|
||||
|
||||
public void MergeWith(VariableSelectedFitInfo other)
|
||||
{
|
||||
CanFitLeft &= other.CanFitLeft;
|
||||
CanFitRight &= other.CanFitRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: de1be43f08224713a1e76d603eae4b19
|
||||
timeCreated: 1637774053
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/VariableGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,90 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Profiling;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class VariableGraphGUI
|
||||
{
|
||||
public int RowIndex { get; set; }
|
||||
public WatchVariable Variable { get; set; }
|
||||
public List<int> IndicesToDisplay { get; set; } = new();
|
||||
public int StartIndex { get; set; }
|
||||
public int IndicesCount { get; set; }
|
||||
public double MinValue { get; set; }
|
||||
public double MaxValue { get; set; }
|
||||
public float ValueColumnWidth { get; set; }
|
||||
public Color BackgroundColor { get; set; }
|
||||
|
||||
[SerializeField] private TextureDrawGUI _textureDrawGUI = new();
|
||||
|
||||
private TextureDrawGUI.GraphPointInfo[] _graphPoints = new TextureDrawGUI.GraphPointInfo[1000];
|
||||
|
||||
public void DrawValues(Rect rect)
|
||||
{
|
||||
var isEmptyVariable = Variable.Values.Count == 0 || Variable.Values.OriginalKeys.Count == 1 && Variable.Values.IsEmptyAt(0);
|
||||
|
||||
if (isEmptyVariable )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var graphRect = isEmptyVariable ? rect : rect.Extrude(ExtrudeFlags.Top | ExtrudeFlags.Bottom, -3);
|
||||
var valueColumnWidthInt = Mathf.RoundToInt(ValueColumnWidth);
|
||||
var graphPointsCount = 0;
|
||||
|
||||
foreach (var index in IndicesToDisplay)
|
||||
{
|
||||
var noValue = Variable.Values.IsEmptyAt(index);
|
||||
|
||||
|
||||
var filColor = Colors.GraphFill;
|
||||
var topLineColor = Colors.GraphLine;
|
||||
var bottomLineColor = Colors.GraphFill;
|
||||
var pixelHeight = Mathf.RoundToInt(graphRect.height);
|
||||
|
||||
|
||||
if (!noValue)
|
||||
{
|
||||
var value = Variable.GetValueNumber(index);
|
||||
var normValue = MaxValue - MinValue < 0.000001 ? 1 : (value - MinValue) / (MaxValue - MinValue);
|
||||
pixelHeight = Mathf.RoundToInt(graphRect.height * (float)normValue);
|
||||
}
|
||||
{
|
||||
bottomLineColor = Colors.ExtraTextLineGraph;
|
||||
}
|
||||
|
||||
for (var i = 0; i < valueColumnWidthInt; i++)
|
||||
{
|
||||
var isDivider = ValueColumnWidth > 1 && index != IndicesToDisplay[0] && i == 0;
|
||||
|
||||
var point = new TextureDrawGUI.GraphPointInfo()
|
||||
{
|
||||
IsEmpty = noValue ,
|
||||
WithLine = !noValue,
|
||||
PixelHeight = pixelHeight,
|
||||
TopLineColor = topLineColor,
|
||||
BottomLineColor = bottomLineColor,
|
||||
FillColor = isDivider ? filColor + new Color32(10, 10, 10, 10) : filColor
|
||||
};
|
||||
|
||||
_graphPoints[graphPointsCount++] = point;
|
||||
|
||||
if (graphPointsCount == _graphPoints.Length)
|
||||
Array.Resize(ref _graphPoints, _graphPoints.Length * 2);
|
||||
}
|
||||
}
|
||||
|
||||
_textureDrawGUI.Prepare(graphRect);
|
||||
_textureDrawGUI.DrawTestGraph(
|
||||
BackgroundColor,
|
||||
_graphPoints,
|
||||
graphPointsCount);
|
||||
_textureDrawGUI.DrawResult();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 02fc4c661d1a4a69865d58d6be233daa
|
||||
timeCreated: 1715788313
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/VariableGraphGUI.cs
|
||||
uploadId: 770587
|
||||
@@ -0,0 +1,679 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ingvar.LiveWatch.Editor
|
||||
{
|
||||
[Serializable]
|
||||
public class VariablesListGUI
|
||||
{
|
||||
public const int MaxDrawDepth = 100;
|
||||
public WatchStorage Variables => WatchStorageSO.instance.Watches;
|
||||
public bool Search { get; set; }
|
||||
public float NameColumnWidth { get; set; } = 50;
|
||||
|
||||
public bool Collapse
|
||||
{
|
||||
get => WatchStorageSO.instance.Collapse;
|
||||
set => WatchStorageSO.instance.Collapse = value;
|
||||
}
|
||||
|
||||
public float ValueColumnWidth
|
||||
{
|
||||
get => WatchStorageSO.instance.ColumnWidth;
|
||||
set => WatchStorageSO.instance.ColumnWidth = value;
|
||||
}
|
||||
|
||||
public float ValueRowHeight
|
||||
{
|
||||
get => WatchStorageSO.instance.RowHeight;
|
||||
set => WatchStorageSO.instance.RowHeight = value;
|
||||
}
|
||||
|
||||
public bool IsLeftSelection
|
||||
{
|
||||
get => WatchStorageSO.instance.IsLeftSelection;
|
||||
set => WatchStorageSO.instance.IsLeftSelection = value;
|
||||
}
|
||||
|
||||
public int SelectedColumnIndex
|
||||
{
|
||||
get => LiveWatchWindow.SelectedColumnIndex;
|
||||
set => LiveWatchWindow.SelectedColumnIndex = value;
|
||||
}
|
||||
|
||||
public WatchVariable SelectedVariable { get; private set; }
|
||||
public bool IsMouseDraggingOverValues { get; set; }
|
||||
public bool IsTitleSelected => _isSelectedTitle;
|
||||
|
||||
protected VariableGUI VariableGUI
|
||||
{
|
||||
get { return _variableGUI ??= new VariableGUI(); }
|
||||
}
|
||||
|
||||
private SortedSet<int> _nonShrinkableColumns = new SortedSet<int>();
|
||||
private List<int> _indicesToDisplay = new List<int>(100);
|
||||
private int _valueStartIndex;
|
||||
private float _valueRectOffset;
|
||||
private ScrollbarGUI _horizontalScrollbar = new ScrollbarGUI(true);
|
||||
private ScrollbarGUI _verticalScrollbar = new ScrollbarGUI(false);
|
||||
|
||||
private Rect _frame;
|
||||
private Rect _variableListRect;
|
||||
private Rect _currentSelectionRect;
|
||||
private bool _isSelectedTitle;
|
||||
private int _variableDrawnCounter;
|
||||
private int _variableTotalCounter;
|
||||
private int _valriableValuesMaxCount;
|
||||
private VariableGUI _variableGUI;
|
||||
private GUIStyle _horizontalScrollStyle;
|
||||
private GUIStyle _verticalScrollStyle;
|
||||
private VariableSelectedFitInfo _selectedFitInfo = new();
|
||||
private List<WatchVariable> _variables = new (10);
|
||||
|
||||
public void OnEnable()
|
||||
{
|
||||
if (SelectedVariable != null)
|
||||
{
|
||||
Variables.GetAllChildRecursive(_variables, WatchFilters.None, WatchFilters.None);
|
||||
|
||||
var found = false;
|
||||
|
||||
foreach (var variable in _variables)
|
||||
found |= variable == SelectedVariable;
|
||||
|
||||
if (!found)
|
||||
{
|
||||
SelectedVariable = null;
|
||||
SelectedColumnIndex = -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Variables.Count == 0)
|
||||
{
|
||||
_horizontalScrollbar.IsStickingToLast = true;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnGUI(Rect frame)
|
||||
{
|
||||
_frame = frame;
|
||||
|
||||
ProcessEvents(Event.current);
|
||||
|
||||
PrepareVariables();
|
||||
|
||||
DoList();
|
||||
|
||||
DoHorizontalScroll();
|
||||
DoVerticalScroll();
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
SelectedColumnIndex = -1;
|
||||
SelectedVariable = null;
|
||||
|
||||
_valriableValuesMaxCount = 0;
|
||||
_isSelectedTitle = true;
|
||||
|
||||
_nonShrinkableColumns.Clear();
|
||||
_indicesToDisplay.Clear();
|
||||
|
||||
_horizontalScrollbar.ScrollValue = 0;
|
||||
_horizontalScrollbar.IsStickingToLast = true;
|
||||
}
|
||||
|
||||
private void PrepareVariables()
|
||||
{
|
||||
RefreshNonShrinkableColumns();
|
||||
RefreshIndicesToDisplay();
|
||||
}
|
||||
|
||||
private void DoList()
|
||||
{
|
||||
_variableDrawnCounter = 0;
|
||||
_variableTotalCounter = 0;
|
||||
|
||||
var posY = _frame.y - _verticalScrollbar.ScrollValue;
|
||||
posY = Mathf.FloorToInt(posY);
|
||||
|
||||
_variableListRect = _frame
|
||||
.CropFromPositionToEnd(CropEdge.RightLocal, Constants.VerticalScrollWidth)
|
||||
.CropFromPositionToEnd(CropEdge.BottomLocal, Constants.HorizontalScrollHeight);
|
||||
|
||||
VariableGUI.LabelAreaWidth = NameColumnWidth;
|
||||
VariableGUI.ValueColumnWidth = ValueColumnWidth;
|
||||
VariableGUI.ValueRowHeight = ValueRowHeight;
|
||||
VariableGUI.HorizontalScrollValue = _horizontalScrollbar.ScrollValue;
|
||||
VariableGUI.SelectedColumnIndex = SelectedColumnIndex;
|
||||
VariableGUI.Search = Search;
|
||||
VariableGUI.Collapse = Collapse;
|
||||
VariableGUI.VariablesTotalArea = _variableListRect;
|
||||
VariableGUI.IndicesToDisplay = _indicesToDisplay;
|
||||
VariableGUI.StartIndex = _valueStartIndex;
|
||||
VariableGUI.RectOffset = _valueRectOffset;
|
||||
VariableGUI.IsMouseDraggingOverValues = IsMouseDraggingOverValues;
|
||||
|
||||
foreach (var variableName in Variables.SortedNames)
|
||||
{
|
||||
posY = DrawWatchVariableRowRecursive(posY, Variables.Get(variableName), 0);
|
||||
}
|
||||
|
||||
if (SelectedVariable != null)
|
||||
{
|
||||
GUIExtensions.DrawColorFrame(_currentSelectionRect, Colors.CellSelectionLine, 3);
|
||||
}
|
||||
}
|
||||
|
||||
private void DoVerticalScroll()
|
||||
{
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
var placeholderRect = _frame
|
||||
.CropFromStartToPosition(CropEdge.RightLocal, Constants.VerticalScrollWidth)
|
||||
.CropFromPositionToEnd(CropEdge.BottomLocal, Constants.HorizontalScrollHeight);
|
||||
|
||||
EditorGUI.DrawRect(placeholderRect, Colors.Background);
|
||||
|
||||
_verticalScrollStyle ??= new GUIStyle(GUI.skin.verticalScrollbar);
|
||||
_verticalScrollStyle.Draw(placeholderRect, false, false, false, false);
|
||||
}
|
||||
|
||||
var scrollRect = _frame
|
||||
.CropFromStartToPosition(CropEdge.RightLocal, Constants.VerticalScrollWidth)
|
||||
.CropFromPositionToEnd(CropEdge.BottomLocal, Constants.HorizontalScrollHeight);
|
||||
|
||||
var variablesTotalHeight = GetVariablesTotalHeight();
|
||||
|
||||
_verticalScrollbar.Prepare(scrollRect, scrollRect.height, 0, variablesTotalHeight);
|
||||
_verticalScrollbar.Draw();
|
||||
}
|
||||
|
||||
private void DoHorizontalScroll()
|
||||
{
|
||||
if (Event.current.type == EventType.Repaint)
|
||||
{
|
||||
var placeholderRect = _frame.CropFromStartToPosition(CropEdge.BottomLocal, Constants.HorizontalScrollHeight);
|
||||
|
||||
EditorGUI.DrawRect(placeholderRect, Colors.Background);
|
||||
|
||||
_horizontalScrollStyle ??= new GUIStyle(GUI.skin.horizontalScrollbar);
|
||||
_horizontalScrollStyle.Draw(placeholderRect, false, false, false, false);
|
||||
}
|
||||
|
||||
var scrollRect = _frame
|
||||
.CropFromStartToPosition(CropEdge.BottomLocal, Constants.HorizontalScrollHeight)
|
||||
.CropFromPositionToEnd(CropEdge.LeftLocal, NameColumnWidth);
|
||||
|
||||
var variablesMaxWidth = GetVariablesMaxWidth();
|
||||
|
||||
_horizontalScrollbar.AllowStickToLast = true;
|
||||
_horizontalScrollbar.Prepare(scrollRect, scrollRect.width-Constants.VerticalScrollWidth, 0, variablesMaxWidth);
|
||||
_horizontalScrollbar.Draw();
|
||||
}
|
||||
|
||||
private void ProcessEvents(Event e)
|
||||
{
|
||||
if (e.type == EventType.MouseUp && IsMouseDraggingOverValues)
|
||||
{
|
||||
e.Use();
|
||||
IsMouseDraggingOverValues = false;
|
||||
}
|
||||
else if (e.type == EventType.MouseDown && _frame.Contains(e.mousePosition))
|
||||
{
|
||||
GUIUtility.hotControl = 0;
|
||||
GUIUtility.keyboardControl = 0;
|
||||
}
|
||||
else if (e.modifiers.HasFlag(UserSettings.WidthZoomKeys) && e.isScrollWheel)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
float delta = -e.delta.y;
|
||||
var newColumnWidth = Mathf.Clamp(ValueColumnWidth + delta, Constants.VariableValueColumnWidthMin, Constants.VariableValueColumnWidthMax);
|
||||
|
||||
_horizontalScrollbar.ResizeRelativeToPointer(e.mousePosition.x, newColumnWidth/ValueColumnWidth);
|
||||
|
||||
ValueColumnWidth = newColumnWidth;
|
||||
}
|
||||
else if (e.modifiers.HasFlag(UserSettings.HeightZoomKeys) && e.isScrollWheel)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
float delta = -e.delta.y;
|
||||
var newRowHeight = Mathf.Clamp(ValueRowHeight + delta, Constants.VariableRowHeighMin, Constants.VariableRowHeightMax);
|
||||
|
||||
_verticalScrollbar.ResizeRelativeToPointer(e.mousePosition.y, newRowHeight/ValueRowHeight);
|
||||
|
||||
ValueRowHeight = newRowHeight;
|
||||
}
|
||||
else if (e.modifiers.HasFlag(UserSettings.ScrollValuesKeys) && e.isScrollWheel)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
float delta = e.delta.y * Constants.MouseScrollbarMultiplier;
|
||||
_horizontalScrollbar.ScrollValue += delta;
|
||||
}
|
||||
else if (e.isScrollWheel)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
float delta = e.delta.y * Constants.MouseScrollbarMultiplier;
|
||||
_verticalScrollbar.ScrollValue += delta;
|
||||
}
|
||||
else if (e.keyCode == UserSettings.FlipSelectionKey && e.type == EventType.KeyDown)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
IsLeftSelection = !IsLeftSelection;
|
||||
}
|
||||
else if (e.keyCode == UserSettings.ExpandVariableKey && e.type == EventType.KeyDown)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
if (SelectedVariable != null)
|
||||
SelectedVariable.EditorMeta.IsExpanded = !SelectedVariable.EditorMeta.IsExpanded;
|
||||
}
|
||||
else if (e.keyCode == UserSettings.PreviousVariableKey && e.type == EventType.KeyDown)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
MoveToVariable(-1);
|
||||
}
|
||||
else if (e.keyCode == UserSettings.NextVariableKey && e.type == EventType.KeyDown)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
MoveToVariable(1);
|
||||
}
|
||||
else if (e.keyCode == UserSettings.PreviousValueKey && e.type == EventType.KeyDown)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
MoveToVariable(0, -1);
|
||||
}
|
||||
else if (e.keyCode == UserSettings.NextValueKey && e.type == EventType.KeyDown)
|
||||
{
|
||||
e.Use();
|
||||
|
||||
MoveToVariable(0, 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshNonShrinkableColumns()
|
||||
{
|
||||
_valriableValuesMaxCount = 0;
|
||||
Variables.GetAllChildRecursive(_variables, WatchFilters.None, WatchFilters.NoValues);
|
||||
|
||||
foreach (var variable in _variables)
|
||||
{
|
||||
_valriableValuesMaxCount = Mathf.Max(variable.Values.Count, _valriableValuesMaxCount);
|
||||
|
||||
if (WatchServices.VariableCreator.IsAlwaysShrinkable(variable))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var currentIndexOfOriginalKey = variable.EditorMeta.LastNonShrinkableIndexOfKey;
|
||||
var maxIndexOfOriginalKeys = variable.Values.OriginalKeys.Count - 1;
|
||||
|
||||
while (currentIndexOfOriginalKey < maxIndexOfOriginalKeys)
|
||||
{
|
||||
currentIndexOfOriginalKey++;
|
||||
|
||||
_nonShrinkableColumns.Add(variable.Values.OriginalKeys[currentIndexOfOriginalKey]);
|
||||
}
|
||||
|
||||
variable.EditorMeta.LastNonShrinkableIndexOfKey = currentIndexOfOriginalKey;
|
||||
}
|
||||
}
|
||||
|
||||
private void RefreshIndicesToDisplay()
|
||||
{
|
||||
_valueStartIndex = Mathf.FloorToInt(_horizontalScrollbar.ScrollValue / ValueColumnWidth);
|
||||
_valueRectOffset = _valueStartIndex * ValueColumnWidth - _horizontalScrollbar.ScrollValue;
|
||||
_valueRectOffset = Mathf.FloorToInt(_valueRectOffset);
|
||||
var valuesWidth = _frame.width - Constants.VerticalScrollWidth - NameColumnWidth;
|
||||
var columnsCount = Mathf.FloorToInt((valuesWidth - _valueRectOffset) / ValueColumnWidth);
|
||||
|
||||
_indicesToDisplay.Clear();
|
||||
|
||||
if (Collapse)
|
||||
{
|
||||
var rawIndex = 0;
|
||||
|
||||
foreach (var column in _nonShrinkableColumns)
|
||||
{
|
||||
if (_indicesToDisplay.Count > columnsCount)
|
||||
break;
|
||||
|
||||
if (rawIndex++ < _valueStartIndex)
|
||||
continue;
|
||||
|
||||
_indicesToDisplay.Add(column);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (var i = _valueStartIndex; i < _valriableValuesMaxCount; i++)
|
||||
{
|
||||
if (_indicesToDisplay.Count > columnsCount)
|
||||
break;
|
||||
|
||||
_indicesToDisplay.Add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private float DrawWatchVariableRowRecursive(float positionY, WatchVariable variable, int recursionDepth)
|
||||
{
|
||||
if (recursionDepth > MaxDrawDepth)
|
||||
{
|
||||
return positionY;
|
||||
}
|
||||
|
||||
_variableTotalCounter++;
|
||||
|
||||
var listStartY = _frame.y;
|
||||
var listEndY = listStartY + _verticalScrollbar.Size;
|
||||
|
||||
var positionFinishY = positionY + ValueRowHeight;
|
||||
|
||||
if (positionY >= listEndY)
|
||||
{
|
||||
return positionY;
|
||||
}
|
||||
|
||||
bool draw = positionFinishY > listStartY;
|
||||
|
||||
var rect = new Rect(0, positionY, _frame.width - Constants.VerticalScrollWidth, ValueRowHeight);
|
||||
|
||||
if (draw)
|
||||
{
|
||||
_variableDrawnCounter++;
|
||||
|
||||
OnBeforeVariableDraw(variable, recursionDepth);
|
||||
|
||||
VariableGUI.Draw(rect, variable);
|
||||
|
||||
if (VariableGUI.ClickInfo.IsMouse)
|
||||
{
|
||||
OnVariableClicked(variable);
|
||||
}
|
||||
}
|
||||
|
||||
if (!variable.EditorMeta.IsExpanded)
|
||||
{
|
||||
if (SelectedVariable == variable)
|
||||
_currentSelectionRect = rect;
|
||||
|
||||
return positionFinishY;
|
||||
}
|
||||
|
||||
foreach (var childVariableName in variable.Childs.SortedNames)
|
||||
{
|
||||
positionFinishY = DrawWatchVariableRowRecursive(positionFinishY, variable.Childs.Get(childVariableName), recursionDepth + 1);
|
||||
}
|
||||
|
||||
if (SelectedVariable == variable)
|
||||
{
|
||||
_currentSelectionRect = rect.SetHeight(positionFinishY - positionY);
|
||||
}
|
||||
|
||||
return positionFinishY;
|
||||
}
|
||||
|
||||
private void OnBeforeVariableDraw(WatchVariable variable, int recursionDepth)
|
||||
{
|
||||
CalcIndicesCount();
|
||||
|
||||
CalcMinMaxLocal();
|
||||
|
||||
|
||||
VariableGUI.Index = _variableTotalCounter;
|
||||
VariableGUI.IndentLevel = recursionDepth;
|
||||
VariableGUI.IsSelected = variable == SelectedVariable;
|
||||
VariableGUI.SelectedFitInfo = _selectedFitInfo;
|
||||
VariableGUI.PreferRightSelection = !IsLeftSelection;
|
||||
|
||||
void CalcIndicesCount()
|
||||
{
|
||||
VariableGUI.IndicesCount = 0;
|
||||
|
||||
foreach (var index in _indicesToDisplay)
|
||||
{
|
||||
if (variable.Values.Count <= index)
|
||||
break;
|
||||
|
||||
VariableGUI.IndicesCount++;
|
||||
}
|
||||
}
|
||||
|
||||
void CalcMinMaxLocal()
|
||||
{
|
||||
VariableGUI.MinValue = double.MaxValue;
|
||||
VariableGUI.MaxValue = double.MinValue;
|
||||
|
||||
if (variable.Values.Type is WatchValueType.Bool)
|
||||
{
|
||||
VariableGUI.MinValue = 0;
|
||||
VariableGUI.MaxValue = 1;
|
||||
return;
|
||||
}
|
||||
|
||||
var previousOriginalKeyIndex = -1;
|
||||
|
||||
for (int i = 0; i < VariableGUI.IndicesCount; i++)
|
||||
{
|
||||
var key = _indicesToDisplay[i];
|
||||
var keyIndex = variable.Values.GetOriginalKey(key);
|
||||
|
||||
if (keyIndex != previousOriginalKeyIndex)
|
||||
{
|
||||
previousOriginalKeyIndex = key;
|
||||
|
||||
var isValid = variable.IsValidNumberValue(key, out var value);
|
||||
|
||||
if (!isValid)
|
||||
continue;
|
||||
|
||||
if (value > VariableGUI.MaxValue)
|
||||
VariableGUI.MaxValue = value;
|
||||
|
||||
if (value < VariableGUI.MinValue)
|
||||
VariableGUI.MinValue = value;
|
||||
}
|
||||
}
|
||||
|
||||
VariableGUI.MaxValue = Math.Max(VariableGUI.MaxValue, VariableGUI.MinValue);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnVariableClicked(WatchVariable variable)
|
||||
{
|
||||
SelectedVariable = variable;
|
||||
_isSelectedTitle = VariableGUI.ClickInfo.IsOverTitleArea;
|
||||
|
||||
if (_isSelectedTitle)
|
||||
SelectedColumnIndex = -1;
|
||||
|
||||
if (VariableGUI.ClickInfo.CurrentPositionIndex >= 0)
|
||||
SelectedColumnIndex = VariableGUI.ClickInfo.CurrentPositionIndex;
|
||||
|
||||
if (Event.current.type == EventType.MouseDown && !_isSelectedTitle)
|
||||
IsMouseDraggingOverValues = true;
|
||||
|
||||
_selectedFitInfo.Reset();
|
||||
GUI.changed = true;
|
||||
|
||||
|
||||
if (Event.current.type is not (EventType.Layout or EventType.Repaint))
|
||||
Event.current.Use();
|
||||
}
|
||||
|
||||
|
||||
private void MoveToVariable(int variableOffset, int indexOffset = 0)
|
||||
{
|
||||
if (_variables.Count == 0)
|
||||
return;
|
||||
|
||||
if (SelectedVariable == null)
|
||||
{
|
||||
SelectedVariable = _variables[0];
|
||||
_isSelectedTitle = true;
|
||||
JumpToSelectedVariable();
|
||||
return;
|
||||
}
|
||||
else if (variableOffset == 0 && indexOffset == 0)
|
||||
{
|
||||
JumpToSelectedVariable();
|
||||
return;
|
||||
}
|
||||
|
||||
Variables.GetAllChildRecursive(_variables, WatchFilters.FoldedIfChilds, WatchFilters.None);
|
||||
|
||||
if (indexOffset == 0)
|
||||
{
|
||||
if (variableOffset < 0)
|
||||
{
|
||||
SelectedVariable = GetPrevious();
|
||||
JumpToSelectedVariable();
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedVariable = GetNext();
|
||||
JumpToSelectedVariable();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var currentSelectionIndex = _isSelectedTitle ? -1 : SelectedColumnIndex;
|
||||
currentSelectionIndex += indexOffset;
|
||||
currentSelectionIndex = Mathf.Clamp(currentSelectionIndex, 0, SelectedVariable.Values.Count-1);
|
||||
|
||||
if (currentSelectionIndex < -1)
|
||||
{
|
||||
SelectedVariable = GetPrevious();
|
||||
SelectedColumnIndex = -1;
|
||||
|
||||
if (SelectedVariable.Values.Count > 0)
|
||||
SelectedColumnIndex = SelectedVariable.Values.Count - 1;
|
||||
|
||||
_isSelectedTitle = SelectedVariable.Values.Count <= 0;
|
||||
|
||||
JumpToSelectedVariable();
|
||||
}
|
||||
else if (currentSelectionIndex >= SelectedVariable.Values.Count)
|
||||
{
|
||||
SelectedVariable = GetNext();
|
||||
SelectedColumnIndex = -1;
|
||||
_isSelectedTitle = true;
|
||||
|
||||
JumpToSelectedVariable();
|
||||
}
|
||||
else
|
||||
{
|
||||
SelectedColumnIndex = currentSelectionIndex;
|
||||
_isSelectedTitle = SelectedColumnIndex < 0;
|
||||
|
||||
JumpToSelectedVariable();
|
||||
}
|
||||
|
||||
void JumpToSelectedVariable()
|
||||
{
|
||||
JumpToVariable(
|
||||
SelectedVariable,
|
||||
_isSelectedTitle ? -1 : SelectedColumnIndex,
|
||||
variableOffset != 0,
|
||||
indexOffset != 0);
|
||||
}
|
||||
|
||||
WatchVariable GetPrevious()
|
||||
{
|
||||
WatchVariable previousVariable = null;
|
||||
|
||||
foreach (var variable in _variables)
|
||||
{
|
||||
if (variable == SelectedVariable)
|
||||
return previousVariable ?? _variables[^1];
|
||||
|
||||
previousVariable = variable;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
WatchVariable GetNext()
|
||||
{
|
||||
WatchVariable firstVariable = _variables[0];
|
||||
WatchVariable currentVariable = null;
|
||||
|
||||
foreach (var nextVariable in _variables)
|
||||
{
|
||||
if (currentVariable == SelectedVariable)
|
||||
return nextVariable;
|
||||
|
||||
currentVariable = nextVariable;
|
||||
}
|
||||
|
||||
return firstVariable;
|
||||
}
|
||||
}
|
||||
|
||||
private void JumpToVariable(WatchVariable variable, int index, bool vertical, bool horizontal)
|
||||
{
|
||||
_horizontalScrollbar.IsStickingToLast = false;
|
||||
|
||||
if (vertical)
|
||||
{
|
||||
_verticalScrollbar.EndValue = GetVariablesTotalHeight();
|
||||
var indexOfVisibleVariable = _variables.IndexOf(variable);
|
||||
_verticalScrollbar.SetNormalizedPosition((float)indexOfVisibleVariable / _variables.Count);
|
||||
}
|
||||
|
||||
SelectedVariable = variable;
|
||||
SelectedColumnIndex = index;
|
||||
|
||||
if (horizontal && index >= 0)
|
||||
{
|
||||
if (Collapse && !_nonShrinkableColumns.Contains(index))
|
||||
{
|
||||
Collapse = false;
|
||||
_horizontalScrollbar.EndValue = VariableGUI.ValueColumnWidth * _valriableValuesMaxCount;
|
||||
}
|
||||
|
||||
var valuesCount = Collapse ? _nonShrinkableColumns.Count : _valriableValuesMaxCount;
|
||||
var normPos = (float)index / valuesCount;
|
||||
_horizontalScrollbar.SetNormalizedPosition(normPos);
|
||||
}
|
||||
}
|
||||
|
||||
private float GetVariablesTotalHeight()
|
||||
{
|
||||
Variables.GetAllChildRecursive(_variables, WatchFilters.FoldedIfChilds, WatchFilters.None);
|
||||
return _variables.Count * ValueRowHeight;
|
||||
}
|
||||
|
||||
private float GetVariablesMaxWidth()
|
||||
{
|
||||
if (Collapse)
|
||||
{
|
||||
return _nonShrinkableColumns.Count * VariableGUI.ValueColumnWidth;
|
||||
}
|
||||
|
||||
var maxWidth = 0f;
|
||||
|
||||
Variables.GetAllChildRecursive(_variables, WatchFilters.FoldedIfChilds, WatchFilters.NoValues);
|
||||
|
||||
foreach (var variable in _variables)
|
||||
{
|
||||
maxWidth = Mathf.Max(maxWidth, variable.Values.Count * VariableGUI.ValueColumnWidth);
|
||||
}
|
||||
|
||||
return maxWidth;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cf450bb6780140c79376f33a3729a2d1
|
||||
timeCreated: 1636229945
|
||||
AssetOrigin:
|
||||
serializedVersion: 1
|
||||
productId: 324001
|
||||
packageName: LiveWatch Lite | Debug with full history of changes
|
||||
packageVersion: 1.0.1
|
||||
assetPath: Assets/LiveWatchLite/Scripts/Editor/WatchVariablesGUI/VariablesListGUI.cs
|
||||
uploadId: 770587
|
||||
Reference in New Issue
Block a user