maint: added livewatch asset

This commit is contained in:
Chris
2025-08-31 18:14:07 -04:00
parent 7f5d95787b
commit ae2371a6fa
385 changed files with 150792 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1949d46200f34bbf852e2474fd7b86ca
timeCreated: 1653138250

View File

@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using System.Reflection;
using UnityEngine;
namespace Ingvar.LiveWatch
{
public static partial class Watch
{
public static char PathSeparator { get; set; } = '/';
internal static int MaxRecursionDepth = 100;
public static bool IsLive
{
get => WatchStorageSO.instance.IsLive;
set => WatchStorageSO.instance.IsLive = value;
}
internal static WatchStorage Watches
{
get => WatchStorageSO.instance.Watches;
set
{
DestroyAll();
WatchStorageSO.instance.Watches = value;
}
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 0ced31b9fdad40c1bc42f90d63659828
timeCreated: 1643051681
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/API/Watch.cs
uploadId: 770587

View File

@@ -0,0 +1,102 @@
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace Ingvar.LiveWatch
{
/// <summary>
/// Type for generic Watch methods when you don't know what type it is, or don't want use type based functionality
/// </summary>
public class Any
{
}
public partial struct WatchReference<T>
{
internal WatchVariable WatchVariable { get; }
public int ChildCount
{
get
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return WatchVariable.Childs.Count;
#else
return 0;
#endif
}
}
internal WatchReference(WatchVariable watchVariable)
{
WatchVariable = watchVariable;
}
public WatchReference<T> SetAlwaysCollapsable()
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
WatchVariable.RuntimeMeta.AlwaysShrinkable = true;
#endif
return this;
}
public WatchReference<T> SetDecimalPlaces(int value)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
WatchVariable.RuntimeMeta.DecimalPlaces = value;
#endif
return this;
}
public WatchReference<T> SetSortOrder(int value)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (!WatchVariable.RuntimeMeta.IsOrderSet)
{
WatchVariable.RuntimeMeta.SortOrder = value;
WatchVariable.RuntimeMeta.IsOrderSet = true;
WatchVariable.RuntimeMeta.IsSortingRequired = true;
}
#endif
return this;
}
public WatchReference<T> UpdateOnce()
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
WatchVariable.RuntimeMeta.UpdateOnce = true;
#endif
return this;
}
public WatchReference<T> PushEmptyValue(bool withRoot = true, int maxRecursionDepth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (Watch.IsLive)
WatchServices.ReferenceCreator.PushEmpty(this, withRoot, maxRecursionDepth);
#endif
return this;
}
public IEnumerable<string> GetChildNames()
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return WatchVariable.Childs.SortedNames;
#else
return Array.Empty<string>();
#endif
}
public WatchReference<V> GetOrAdd<V>(string path)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return WatchServices.ReferenceCreator.GetOrAdd<V, T>(this, path);
#else
return WatchServices.ReferenceCreator.Empty<V>();
#endif
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: bde558d1e19241fd9894b6507614c742
timeCreated: 1643051866
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/API/WatchReference.cs
uploadId: 770587

View File

@@ -0,0 +1,72 @@
using System;
namespace Ingvar.LiveWatch
{
public partial struct WatchReference<T>
{
public WatchReference<double> GetOrAdd(string path, Func<double> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<float> GetOrAdd(string path, Func<float> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<int> GetOrAdd(string path, Func<int> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<string> GetOrAdd(string path, Func<string> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<bool> GetOrAdd(string path, Func<bool> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<decimal> GetOrAdd(string path, Func<decimal> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<long> GetOrAdd(string path, Func<long> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<short> GetOrAdd(string path, Func<short> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<byte> GetOrAdd(string path, Func<byte> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<ulong> GetOrAdd(string path, Func<ulong> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<ushort> GetOrAdd(string path, Func<ushort> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<sbyte> GetOrAdd(string path, Func<sbyte> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
public WatchReference<char> GetOrAdd(string path, Func<char> valueGetter)
{
return Watch.GetOrAdd(this, path, valueGetter);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 88d3577466c148bd8198f7e01c7835a1
timeCreated: 1748342793
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/API/WatchReference_BasicTypes.cs
uploadId: 770587

View File

@@ -0,0 +1,55 @@
using System;
using System.Diagnostics;
namespace Ingvar.LiveWatch
{
public static partial class Watch
{
public static event Action OnClearedAll;
public static event Action OnDestroyedAll;
public static WatchReference<T> GetOrAdd<T>(string path)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return WatchServices.ReferenceCreator.GetOrAdd<T>(path);
#else
return WatchServices.ReferenceCreator.Empty<T>();
#endif
}
public static WatchReference<Any> PushEmpty(string path)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return WatchServices.ReferenceCreator.GetOrAdd<Any>(path).PushEmptyValue();
#else
return WatchServices.ReferenceCreator.Empty<Any>();
#endif
}
public static void UpdateAll()
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
WatchServices.VariableUpdater.UpdateAll();
#endif
}
public static void ClearAll()
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
WatchServices.VariableUpdater.ClearAll();
OnClearedAll?.Invoke();
#endif
}
public static void DestroyAll()
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
WatchServices.VariableUpdater.ClearAll();
Watches.Clear();
OnDestroyedAll?.Invoke();
#endif
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: d8dd881e863b44138a5167c7d7feb882
timeCreated: 1652649243
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/API/Watch_API.cs
uploadId: 770587

View File

@@ -0,0 +1,841 @@
#pragma warning disable CS0162
using System;
using System.Linq;
using System.Collections.Generic;
using Ingvar.LiveWatch;
using Object = UnityEngine.Object;
namespace Ingvar.LiveWatch
{
// It's completely generated class, avoid modifying!
public static partial class Watch
{
private static string _tempStr;
private static HashSet<string> _tempStrSet = new();
private static Dictionary<object, HashSet<string>> _tempSetDict = new();
private static WatchReferenceCreator RC = WatchServices.ReferenceCreator;
private static WatchCachedNamesBuilder NB = WatchServices.NameBuilder;
#region Double
public static WatchReference<Double> GetOrAdd(string path, Func<Double> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Double>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Double>();
#endif
}
public static WatchReference<Double> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Double> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Double, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Double>();
#endif
}
public static WatchReference<Double> Setup(WatchReference<Double> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Double);
#endif
return wr;
}
public static WatchReference<Double> Push(WatchReference<Double> wr, Double value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushDouble(wr, value);
#endif
return wr;
}
public static WatchReference<Double> Push(string path, Double value, int depth = 10)
{
return Push(RC.GetOrAdd<Double>(path), value, depth);
}
#endregion
#region Single
public static WatchReference<Single> GetOrAdd(string path, Func<Single> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Single>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Single>();
#endif
}
public static WatchReference<Single> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Single> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Single, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Single>();
#endif
}
public static WatchReference<Single> Setup(WatchReference<Single> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Float);
#endif
return wr;
}
public static WatchReference<Single> Push(WatchReference<Single> wr, Single value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushFloat(wr, value);
#endif
return wr;
}
public static WatchReference<Single> Push(string path, Single value, int depth = 10)
{
return Push(RC.GetOrAdd<Single>(path), value, depth);
}
#endregion
#region Int32
public static WatchReference<Int32> GetOrAdd(string path, Func<Int32> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Int32>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Int32>();
#endif
}
public static WatchReference<Int32> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Int32> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Int32, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Int32>();
#endif
}
public static WatchReference<Int32> Setup(WatchReference<Int32> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Int);
#endif
return wr;
}
public static WatchReference<Int32> Push(WatchReference<Int32> wr, Int32 value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushInt(wr, value);
#endif
return wr;
}
public static WatchReference<Int32> Push(string path, Int32 value, int depth = 10)
{
return Push(RC.GetOrAdd<Int32>(path), value, depth);
}
#endregion
#region String
public static WatchReference<String> GetOrAdd(string path, Func<String> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<String>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<String>();
#endif
}
public static WatchReference<String> GetOrAdd<T>(WatchReference<T> parent, string path, Func<String> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<String, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<String>();
#endif
}
public static WatchReference<String> Setup(WatchReference<String> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.String);
#endif
return wr;
}
public static WatchReference<String> Push(WatchReference<String> wr, String value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
if (value == null)
return RC.PushNull(wr, depth - 1);
RC.PushString(wr, value);
#endif
return wr;
}
public static WatchReference<String> Push(string path, String value, int depth = 10)
{
return Push(RC.GetOrAdd<String>(path), value, depth);
}
#endregion
#region Boolean
public static WatchReference<Boolean> GetOrAdd(string path, Func<Boolean> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Boolean>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Boolean>();
#endif
}
public static WatchReference<Boolean> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Boolean> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Boolean, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Boolean>();
#endif
}
public static WatchReference<Boolean> Setup(WatchReference<Boolean> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Bool);
#endif
return wr;
}
public static WatchReference<Boolean> Push(WatchReference<Boolean> wr, Boolean value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushBool(wr, value);
#endif
return wr;
}
public static WatchReference<Boolean> Push(string path, Boolean value, int depth = 10)
{
return Push(RC.GetOrAdd<Boolean>(path), value, depth);
}
#endregion
#region Decimal
public static WatchReference<Decimal> GetOrAdd(string path, Func<Decimal> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Decimal>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Decimal>();
#endif
}
public static WatchReference<Decimal> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Decimal> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Decimal, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Decimal>();
#endif
}
public static WatchReference<Decimal> Setup(WatchReference<Decimal> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Double);
#endif
return wr;
}
public static WatchReference<Decimal> Push(WatchReference<Decimal> wr, Decimal value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushDecimal(wr, value);
#endif
return wr;
}
public static WatchReference<Decimal> Push(string path, Decimal value, int depth = 10)
{
return Push(RC.GetOrAdd<Decimal>(path), value, depth);
}
#endregion
#region Int64
public static WatchReference<Int64> GetOrAdd(string path, Func<Int64> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Int64>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Int64>();
#endif
}
public static WatchReference<Int64> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Int64> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Int64, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Int64>();
#endif
}
public static WatchReference<Int64> Setup(WatchReference<Int64> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Double);
#endif
return wr;
}
public static WatchReference<Int64> Push(WatchReference<Int64> wr, Int64 value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushLong(wr, value);
#endif
return wr;
}
public static WatchReference<Int64> Push(string path, Int64 value, int depth = 10)
{
return Push(RC.GetOrAdd<Int64>(path), value, depth);
}
#endregion
#region Int16
public static WatchReference<Int16> GetOrAdd(string path, Func<Int16> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Int16>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Int16>();
#endif
}
public static WatchReference<Int16> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Int16> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Int16, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Int16>();
#endif
}
public static WatchReference<Int16> Setup(WatchReference<Int16> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Int);
#endif
return wr;
}
public static WatchReference<Int16> Push(WatchReference<Int16> wr, Int16 value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushShort(wr, value);
#endif
return wr;
}
public static WatchReference<Int16> Push(string path, Int16 value, int depth = 10)
{
return Push(RC.GetOrAdd<Int16>(path), value, depth);
}
#endregion
#region Byte
public static WatchReference<Byte> GetOrAdd(string path, Func<Byte> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Byte>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Byte>();
#endif
}
public static WatchReference<Byte> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Byte> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Byte, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Byte>();
#endif
}
public static WatchReference<Byte> Setup(WatchReference<Byte> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Int);
#endif
return wr;
}
public static WatchReference<Byte> Push(WatchReference<Byte> wr, Byte value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushByte(wr, value);
#endif
return wr;
}
public static WatchReference<Byte> Push(string path, Byte value, int depth = 10)
{
return Push(RC.GetOrAdd<Byte>(path), value, depth);
}
#endregion
#region UInt64
public static WatchReference<UInt64> GetOrAdd(string path, Func<UInt64> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<UInt64>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<UInt64>();
#endif
}
public static WatchReference<UInt64> GetOrAdd<T>(WatchReference<T> parent, string path, Func<UInt64> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<UInt64, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<UInt64>();
#endif
}
public static WatchReference<UInt64> Setup(WatchReference<UInt64> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Double);
#endif
return wr;
}
public static WatchReference<UInt64> Push(WatchReference<UInt64> wr, UInt64 value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushULong(wr, value);
#endif
return wr;
}
public static WatchReference<UInt64> Push(string path, UInt64 value, int depth = 10)
{
return Push(RC.GetOrAdd<UInt64>(path), value, depth);
}
#endregion
#region UInt16
public static WatchReference<UInt16> GetOrAdd(string path, Func<UInt16> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<UInt16>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<UInt16>();
#endif
}
public static WatchReference<UInt16> GetOrAdd<T>(WatchReference<T> parent, string path, Func<UInt16> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<UInt16, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<UInt16>();
#endif
}
public static WatchReference<UInt16> Setup(WatchReference<UInt16> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Int);
#endif
return wr;
}
public static WatchReference<UInt16> Push(WatchReference<UInt16> wr, UInt16 value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushUShort(wr, value);
#endif
return wr;
}
public static WatchReference<UInt16> Push(string path, UInt16 value, int depth = 10)
{
return Push(RC.GetOrAdd<UInt16>(path), value, depth);
}
#endregion
#region SByte
public static WatchReference<SByte> GetOrAdd(string path, Func<SByte> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<SByte>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<SByte>();
#endif
}
public static WatchReference<SByte> GetOrAdd<T>(WatchReference<T> parent, string path, Func<SByte> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<SByte, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<SByte>();
#endif
}
public static WatchReference<SByte> Setup(WatchReference<SByte> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.Int);
#endif
return wr;
}
public static WatchReference<SByte> Push(WatchReference<SByte> wr, SByte value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushSByte(wr, value);
#endif
return wr;
}
public static WatchReference<SByte> Push(string path, SByte value, int depth = 10)
{
return Push(RC.GetOrAdd<SByte>(path), value, depth);
}
#endregion
#region Char
public static WatchReference<Char> GetOrAdd(string path, Func<Char> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Char>(path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Char>();
#endif
}
public static WatchReference<Char> GetOrAdd<T>(WatchReference<T> parent, string path, Func<Char> valueGetter)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
var wr = Setup(RC.GetOrAdd<Char, T>(parent, path));
RC.SetUpdateCall(wr, () =>
{
var value = valueGetter();
Push(wr, value);
});
return wr;
#else
return RC.Empty<Char>();
#endif
}
public static WatchReference<Char> Setup(WatchReference<Char> wr)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
return RC.TrySetupAs(wr, WatchValueType.String);
#endif
return wr;
}
public static WatchReference<Char> Push(WatchReference<Char> wr, Char value, int depth = 10)
{
#if UNITY_EDITOR || LIVE_WATCH_BUILD
if (depth <= 0 || !Watch.IsLive || RC.IsInvalidType(wr))
return wr;
Setup(wr);
RC.PushChar(wr, value);
#endif
return wr;
}
public static WatchReference<Char> Push(string path, Char value, int depth = 10)
{
return Push(RC.GetOrAdd<Char>(path), value, depth);
}
#endregion
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: c1a460e3212a4e6f8328f8e396c05609
timeCreated: 1652647985
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/API/Watch_BaseTypes.cs
uploadId: 770587

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: faafb2df84004a18b24814642303ad28
timeCreated: 1652628751
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/API/Watch_UnityTypes.cs
uploadId: 770587

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 84e5666af01d4648bdb9e3665a235b1a
timeCreated: 1644066983

View File

@@ -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
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8684acd3a5444a97a7f9371e2f3cb1d8
timeCreated: 1637702019

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -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,
};
}
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 3062c13d1aa648f59cdd73f33e9360a0
timeCreated: 1724579269

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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();
}
}
}

View File

@@ -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

View File

@@ -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();
}
}
}
}

View File

@@ -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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 6a3779d0db2f41a292cde5a6bd827733
timeCreated: 1637530360

View File

@@ -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();
}
}
}

View File

@@ -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

View File

@@ -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);
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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));
}
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -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

View File

@@ -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();
}
}
}

View File

@@ -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

View File

@@ -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 ();
}
}

View File

@@ -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

View 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;
}
}
}

View File

@@ -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

View File

@@ -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,
}
}
}

View File

@@ -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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 41800da9799c48f19a23c6e8ea172edf
timeCreated: 1653071522

View File

@@ -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;
}
}
}
}

View File

@@ -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

View File

@@ -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));
}
}
}

View File

@@ -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

View File

@@ -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);
}
}
}

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -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

View File

@@ -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));
}
}
}
}

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -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

View File

@@ -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();
}
}
}

View File

@@ -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

View File

@@ -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;
}
}
}

View File

@@ -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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 0e087f75ab984a3aa6d2fe30b9b2c6ff
timeCreated: 1648729632

View File

@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Ingvar.LiveWatch
{
[Serializable]
public struct OverridenValue<T> : IEquatable<OverridenValue<T>> where T : IEquatable<T>
{
[SerializeField] private bool isSet;
[SerializeField] private T value;
public bool IsSet => isSet;
public T Value => value;
public OverridenValue(T initialValue)
{
isSet = true;
value = initialValue;
}
public void SetValue(T setValue)
{
isSet = true;
value = setValue;
}
public bool Equals(OverridenValue<T> other)
{
return isSet && other.isSet && value.Equals(other.value)
|| !isSet && !other.isSet;
}
public override bool Equals(object obj)
{
return obj is OverridenValue<T> other && Equals(other);
}
public override int GetHashCode()
{
return HashCode.Combine(isSet, value);
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: bbc5c46530a74212ba5698b86e986707
timeCreated: 1717141617
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/Utilities/OverridenValue.cs
uploadId: 770587

View File

@@ -0,0 +1,142 @@
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ingvar.LiveWatch
{
[Serializable]
public class RepetitiveValueList<T> where T : IEquatable<T>
{
public int Count
{
get => _count;
set => _count = value;
}
public List<int> OriginalKeys => _originalKeys;
public List<T> OriginalValues => _originalValues;
[SerializeField] private int _count = 0;
[SerializeField] private List<int> _originalKeys = new(1);
[SerializeField] private List<T> _originalValues = new(1);
private object _lockObject = new ();
private int _previousIndexOfOriginalKey;
private List<int> _indicesToOriginalKeysMap = new(1);
public bool AnyAt(int index)
{
return index >= 0 && index < _count;
}
public bool IsOriginalAt(int index)
{
if (index == 0)
return true;
var originalValueIndex = GetOriginalValueIndex(index);
var previousOriginalValueIndex = GetOriginalValueIndex(index-1);
return previousOriginalValueIndex != originalValueIndex;
}
public int GetOriginalIndex(int index)
{
var indexOfOriginalValue = GetOriginalValueIndex(index);
return _originalKeys[indexOfOriginalValue];
}
public void Add(T value)
{
if (_count == 0 || !_originalValues[^1].Equals(value))
{
_originalKeys.Add(_count);
_originalValues.Add(value);
}
_count++;
}
public void Expand(int expandCount)
{
if (_count == 0)
return;
_count += expandCount;
}
public T this[int index]
{
get
{
var indexOfOriginalValue = GetOriginalValueIndex(index);
return _originalValues[indexOfOriginalValue];
}
set
{
var indexOfOriginalValue = GetOriginalValueIndex(index);
_originalValues[indexOfOriginalValue] = value;
}
}
public void Clear()
{
_count = 0;
_originalKeys.Clear();
_originalValues.Clear();
_previousIndexOfOriginalKey = 0;
_indicesToOriginalKeysMap.Clear();
}
public void UpdateIndicesMap(int desiredIndex)
{
var startIndex = _indicesToOriginalKeysMap.Count;
var finishIndex = Mathf.Min(_originalKeys[^1] - 1, desiredIndex);
var currentLastIndex = _indicesToOriginalKeysMap.Count - 1;
if (_count == 0 || currentLastIndex >= finishIndex)
return;
for (var index = startIndex; index <= finishIndex; index++)
{
if (index == 0)
{
_indicesToOriginalKeysMap.Add(0);
continue;
}
if (_previousIndexOfOriginalKey == _originalKeys.Count - 1)
{
_indicesToOriginalKeysMap.Add(_indicesToOriginalKeysMap[^1]);
continue;
}
var nextOriginalKey = _originalKeys[_previousIndexOfOriginalKey + 1];
if (index < nextOriginalKey)
{
_indicesToOriginalKeysMap.Add(_indicesToOriginalKeysMap[^1]);
}
else
{
_indicesToOriginalKeysMap.Add(_indicesToOriginalKeysMap[^1] + 1);
_previousIndexOfOriginalKey++;
}
}
}
private int GetOriginalValueIndex(int index)
{
if (index >= _originalKeys[^1])
return _originalValues.Count - 1;
lock (_lockObject)
{
UpdateIndicesMap(index);
}
return _indicesToOriginalKeysMap[index];
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 813e6dd3a8a54599aaaf2439227b0cd6
timeCreated: 1712997159
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/Utilities/RepetitiveValueList.cs
uploadId: 770587

View File

@@ -0,0 +1,22 @@
using System.IO;
using UnityEngine;
namespace Ingvar.LiveWatch
{
public abstract class Singleton<T> where T : new()
{
public static T instance
{
get
{
if (_instance != null)
return _instance;
_instance = new T();
return _instance;
}
}
private static T _instance;
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: b717d3e4766a4bbc94186b355c68048c
timeCreated: 1644152748
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/Utilities/Singleton.cs
uploadId: 770587

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
namespace Ingvar.LiveWatch
{
[Flags]
public enum WatchFilters
{
None = 0,
FoldedIfChilds = 1 << 0,
NoValues = 1 << 1,
NoChilds = 1 << 2,
}
public static class WatchVariableQueryExtensions
{
public static void GetAllChildRecursive(this WatchStorage storage, List<WatchVariable> variables, WatchFilters breakFilters, WatchFilters continueFilters, bool includeItself = true)
{
variables.Clear();
foreach (var variableName in storage.SortedNames)
{
FindAllChildsRecursive(storage.Items[variableName], 0, variables, breakFilters, continueFilters, includeItself);
}
}
private static void FindAllChildsRecursive(WatchVariable variable, int recursionDepth, List<WatchVariable> results, WatchFilters breakFilters, WatchFilters continueFilters, bool includeItself = true)
{
if (includeItself && !SkippedByQuery(variable, continueFilters))
{
results.Add(variable);
}
if (recursionDepth >= Watch.MaxRecursionDepth
|| SkippedByQuery(variable, breakFilters))
{
return;
}
foreach (var childVariableName in variable.Childs.SortedNames)
{
FindAllChildsRecursive(variable.Childs.Items[childVariableName], recursionDepth + 1, results, breakFilters, continueFilters);
}
}
private static bool SkippedByQuery(WatchVariable variable, WatchFilters filters)
{
if (filters == WatchFilters.None)
{
return false;
}
if (filters.HasFlag(WatchFilters.FoldedIfChilds) && variable.HasChilds && !variable.EditorMeta.IsExpanded)
{
return true;
}
if (filters.HasFlag(WatchFilters.NoValues) && !variable.HasValues)
{
return true;
}
if (filters.HasFlag(WatchFilters.NoChilds) && !variable.HasChilds)
{
return true;
}
return false;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: ea5b0b3ca3e14eac9c939a1705ee09ef
timeCreated: 1657218960
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/Utilities/WatchVariableQueryExtensions.cs
uploadId: 770587

View File

@@ -0,0 +1,126 @@
using System;
using System.Collections.Generic;
namespace Ingvar.LiveWatch
{
public class WatchCachedNamesBuilder
{
public string ArrayItemFormat = "Item[{0}]";
public string DictionaryKeyFormat = "Key {0}";
public string DictionaryValueFormat = "Value {0}";
private Dictionary<int, string> _arrayItemNames = new();
private Dictionary<int, string> _dicitonaryKeyNames = new();
private Dictionary<int, string> _dictionaryValueNames = new();
private Dictionary<Type, Dictionary<int, string>> _enumToStrings = new();
private Dictionary<int, string> _intToStrings = new();
private Dictionary<long, string> _longToStrings = new();
private Dictionary<char, string> _charToStrings = new();
private string _tempStr;
public string GetCollectionItemName(int index)
{
if (_arrayItemNames.TryGetValue(index, out _tempStr))
{
return _tempStr;
}
_tempStr = string.Format(ArrayItemFormat, index);
_arrayItemNames.Add(index, _tempStr);
return _tempStr;
}
public string GetDictionaryKeyName(int hashCode)
{
if (_dicitonaryKeyNames.TryGetValue(hashCode, out _tempStr))
{
return _tempStr;
}
_tempStr = string.Format(DictionaryKeyFormat, hashCode);
_dicitonaryKeyNames.Add(hashCode, _tempStr);
return _tempStr;
}
public string GetDictionaryValueName(int hashCode)
{
if (_dictionaryValueNames.TryGetValue(hashCode, out _tempStr))
{
return _tempStr;
}
_tempStr = string.Format(DictionaryValueFormat, hashCode);
_dictionaryValueNames.Add(hashCode, _tempStr);
return _tempStr;
}
public string GetStringFromEnum<T>(int value) where T : Enum
{
var intToStrDict = GetIntToStrDict();
if (intToStrDict.TryGetValue(value, out _tempStr))
{
return _tempStr;
}
_tempStr = Enum.GetName(typeof(T), value);
intToStrDict.Add(value, _tempStr);
return _tempStr;
Dictionary<int, string> GetIntToStrDict()
{
if (_enumToStrings.TryGetValue(typeof(T), out var dict))
return dict;
dict = new Dictionary<int, string>();
_enumToStrings.Add(typeof(T), dict);
return dict;
}
}
public string GetString(int value)
{
if (_intToStrings.TryGetValue(value, out _tempStr))
{
return _tempStr;
}
_tempStr = value.ToString();
_intToStrings.Add(value, _tempStr);
return _tempStr;
}
public string GetString(long value)
{
if (_longToStrings.TryGetValue(value, out _tempStr))
{
return _tempStr;
}
_tempStr = value.ToString();
_longToStrings.Add(value, _tempStr);
return _tempStr;
}
public string GetString(char value)
{
if (_charToStrings.TryGetValue(value, out _tempStr))
{
return _tempStr;
}
_tempStr = value.ToString();
_charToStrings.Add(value, _tempStr);
return _tempStr;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: cdf1c9c57c2e4f72b640291516cfd619
timeCreated: 1691088640
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/WatchCachedNamesBuilder.cs
uploadId: 770587

View File

@@ -0,0 +1,286 @@
using System;
using UnityEngine;
namespace Ingvar.LiveWatch
{
public class WatchReferenceCreator
{
private static Type typeAny = typeof(Any);
public WatchReference<T> Empty<T>()
{
return new WatchReference<T>();
}
public virtual WatchReference<T> GetOrAdd<T>(string path, bool directChild = true)
{
var variable = WatchServices.VariableCreator.GetOrAdd(Watch.Watches, path, directChild);
var castType = typeof(T);
if (castType != typeAny)
variable.RuntimeMeta.ValueType ??= castType;
return CreateWatchRef<T>(variable);
}
public virtual WatchReference<T> GetOrAdd<T, V>(WatchReference<V> parent, string path, bool directChild = true)
{
var variable = WatchServices.VariableCreator.GetOrAdd(parent.WatchVariable.Childs, path, directChild);
if (directChild)
variable.Parent = parent.WatchVariable;
if (typeof(T) != typeof(Any))
variable.RuntimeMeta.ValueType ??= typeof(T);
return CreateWatchRef<T>(variable);
}
public void SetUpdateCall<T>(WatchReference<T> watch, Action updateCall)
{
watch.WatchVariable.RuntimeMeta.UpdateCall = updateCall;
}
public bool IsInvalidType<T>(WatchReference<T> watch)
{
if (watch.WatchVariable == null)
return true;
var castType = typeof(T);
if (castType == watch.WatchVariable.RuntimeMeta.ValueType || castType == typeAny)
return false;
return true;
}
public void MarkAsCollectionValue<T>(WatchReference<T> watch)
{
watch.WatchVariable.RuntimeMeta.IsCollectionValue = true;
}
public void MarkAsDictionaryKey<T>(WatchReference<T> watch)
{
watch.WatchVariable.RuntimeMeta.IsDictionaryKey = true;
}
public void MarkAsDictionaryValue<T>(WatchReference<T> watch)
{
watch.WatchVariable.RuntimeMeta.IsDictionaryValue = true;
}
public bool IsSetUp<T>(WatchReference<T> watch)
{
return watch.WatchVariable.RuntimeMeta.IsSetUp;
}
public bool IsDictionaryKey<T>(WatchReference<T> watch)
{
return watch.WatchVariable.RuntimeMeta.IsDictionaryKey;
}
public bool IsDictionaryValue<T>(WatchReference<T> watch)
{
return watch.WatchVariable.RuntimeMeta.IsDictionaryValue;
}
public bool IsCollectionValue<T>(WatchReference<T> watch)
{
return watch.WatchVariable.RuntimeMeta.IsCollectionValue;
}
public WatchReference<T> PushEmpty<T>(WatchReference<T> watch, bool withRoot = true, int maxRecursionDepth = 10)
{
WatchServices.VariableCreator.PushEmpty(watch.WatchVariable, withRoot, maxRecursionDepth);
return watch;
}
public WatchReference<double> PushDouble(WatchReference<double> watch, double value)
{
watch.WatchVariable.Values.DoubleList.Add(new WatchValue<double>(value));
AfterPush(watch);
return watch;
}
public WatchReference<float> PushFloat(WatchReference<float> watch, float value)
{
watch.WatchVariable.Values.FloatList.Add(new WatchValue<float>(value));
AfterPush(watch);
return watch;
}
public WatchReference<int> PushInt(WatchReference<int> watch, int value)
{
watch.WatchVariable.Values.IntList.Add(new WatchValue<int>(value));
AfterPush(watch);
return watch;
}
public WatchReference<string> PushString(WatchReference<string> watch, string value)
{
watch.WatchVariable.Values.StringList.Add(new WatchValue<string>(value));
AfterPush(watch);
return watch;
}
public WatchReference<bool> PushBool(WatchReference<bool> watch, bool value)
{
watch.WatchVariable.Values.BoolList.Add(new WatchValue<bool>(value));
AfterPush(watch);
return watch;
}
public WatchReference<decimal> PushDecimal(WatchReference<decimal> watch, decimal value)
{
watch.WatchVariable.Values.DoubleList.Add(new WatchValue<double>((double)value));
AfterPush(watch);
return watch;
}
public WatchReference<long> PushLong(WatchReference<long> watch, long value)
{
watch.WatchVariable.Values.DoubleList.Add(new WatchValue<double>(value));
AfterPush(watch);
return watch;
}
public WatchReference<short> PushShort(WatchReference<short> watch, short value)
{
watch.WatchVariable.Values.IntList.Add(new WatchValue<int>(value));
AfterPush(watch);
return watch;
}
public WatchReference<byte> PushByte(WatchReference<byte> watch, byte value)
{
watch.WatchVariable.Values.IntList.Add(new WatchValue<int>(value));
AfterPush(watch);
return watch;
}
public WatchReference<ulong> PushULong(WatchReference<ulong> watch, ulong value)
{
watch.WatchVariable.Values.DoubleList.Add(new WatchValue<double>(value));
AfterPush(watch);
return watch;
}
public WatchReference<ushort> PushUShort(WatchReference<ushort> watch, ushort value)
{
watch.WatchVariable.Values.IntList.Add(new WatchValue<int>(value));
AfterPush(watch);
return watch;
}
public WatchReference<sbyte> PushSByte(WatchReference<sbyte> watch, sbyte value)
{
watch.WatchVariable.Values.IntList.Add(new WatchValue<int>(value));
AfterPush(watch);
return watch;
}
public WatchReference<char> PushChar(WatchReference<char> watch, char value)
{
watch.WatchVariable.Values.StringList.Add(new WatchValue<string>(WatchServices.NameBuilder.GetString(value)));
AfterPush(watch);
return watch;
}
public WatchReference<T> PushNull<T>(WatchReference<T> watch, int maxRecursionDepth = 10)
{
watch.WatchVariable.Values.StringList.Add(new WatchValue<string>("NULL"));
WatchServices.VariableCreator.PushEmpty(watch.WatchVariable, false, maxRecursionDepth);
AfterPush(watch);
return watch;
}
public WatchReference<T> PushNonBasic<T>(WatchReference<T> watch, T value)
{
watch.WatchVariable.Values.PushEmpty();
AfterPush(watch);
return watch;
}
public WatchReference<T> TrySetupAs<T>(WatchReference<T> watch, WatchValueType type)
{
if (watch.WatchVariable.RuntimeMeta.IsSetUp)
return watch;
watch.WatchVariable.Values.Type = type;
watch.WatchVariable.RuntimeMeta.ValueType = typeof(T);
watch.WatchVariable.RuntimeMeta.IsSetUp = true;
var watchStorage = watch.WatchVariable.Parent == null ? Watch.Watches : watch.WatchVariable.Parent.Childs;
if (watchStorage.IsSortable)
{
watch.WatchVariable.RuntimeMeta.IsSortingRequired = true;
}
return watch;
}
private void AfterPush<T>(WatchReference<T> watch)
{
WatchServices.VariableUpdater.UpdateTotalValuesCount(watch.WatchVariable);
WatchServices.VariableSortUpdater.TrySortByVariable(watch.WatchVariable);
WatchServices.VariableUpdater.AnyPushSinceUpdate = true;
}
private WatchReference<T> CreateWatchRef<T>(WatchVariable variable)
{
return new WatchReference<T>(variable);
}
#region Obsolete
public WatchReference<T> PushEmptyRoot<T>(WatchReference<T> watch)
{
watch.WatchVariable.Values.PushEmpty();
WatchServices.VariableUpdater.UpdateTotalValuesCount(watch.WatchVariable);
return watch;
}
public void SetValuesType<T>(WatchReference<T> watch, WatchValueType valueType)
{
watch.WatchVariable.Values.Type = valueType;
watch.WatchVariable.RuntimeMeta.ValueType = typeof(T);
}
public void MarkAsSetUp<T>(WatchReference<T> watch)
{
watch.WatchVariable.RuntimeMeta.IsSetUp = true;
}
public void PushFloat<T>(WatchReference<T> watch, float value)
{
watch.WatchVariable.Values.FloatList.Add(new WatchValue<float>(value));
WatchServices.VariableUpdater.UpdateTotalValuesCount(watch.WatchVariable);
}
public void PushDouble<T>(WatchReference<T> watch, double value)
{
watch.WatchVariable.Values.DoubleList.Add(new WatchValue<double>(value));
WatchServices.VariableUpdater.UpdateTotalValuesCount(watch.WatchVariable);
}
public void PushInt<T>(WatchReference<T> watch, int value)
{
watch.WatchVariable.Values.IntList.Add(new WatchValue<int>(value));
WatchServices.VariableUpdater.UpdateTotalValuesCount(watch.WatchVariable);
}
public void PushString<T>(WatchReference<T> watch, string value)
{
watch.WatchVariable.Values.StringList.Add(new WatchValue<string>(value));
WatchServices.VariableUpdater.UpdateTotalValuesCount(watch.WatchVariable);
}
public void PushBool<T>(WatchReference<T> watch, bool value)
{
watch.WatchVariable.Values.BoolList.Add(new WatchValue<bool>(value));
WatchServices.VariableUpdater.UpdateTotalValuesCount(watch.WatchVariable);
}
#endregion
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 61b1c0842d7d4b36a0410bc1eb51eaae
timeCreated: 1652734755
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/WatchReferenceCreator.cs
uploadId: 770587

View File

@@ -0,0 +1,11 @@
namespace Ingvar.LiveWatch
{
public static class WatchServices
{
public static WatchReferenceCreator ReferenceCreator { get; set; } = new();
public static WatchVariableCreator VariableCreator { get; set; } = new();
public static WatchVariableUpdater VariableUpdater { get; set; } = new();
public static WatchCachedNamesBuilder NameBuilder { get; set; } = new();
public static WatchVariableSortUpdater VariableSortUpdater { get; set; } = new();
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 96454465bb924e4fae99828dad4a295e
timeCreated: 1653071422
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/WatchServices.cs
uploadId: 770587

View File

@@ -0,0 +1,59 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
namespace Ingvar.LiveWatch
{
public class WatchStorageSO :
#if UNITY_EDITOR
ScriptableSingleton<WatchStorageSO>
#else
Singleton<WatchStorageSO>
#endif
{
[SerializeField] private bool _isLive = true;
[SerializeField] private bool _collapse = true;
[SerializeField] private bool _isLeftSelection = false;
[SerializeField] private float _columnWidth = 30;
[SerializeField] private float _rowHeight = 30;
[SerializeField] private WatchStorage _watches = new WatchStorage();
public bool IsLive
{
get => _isLive;
set => _isLive = value;
}
public bool Collapse
{
get => _collapse;
set => _collapse = value;
}
public bool IsLeftSelection
{
get => _isLeftSelection;
set => _isLeftSelection = value;
}
public float ColumnWidth
{
get => _columnWidth;
set => _columnWidth = Mathf.RoundToInt(value);
}
public float RowHeight
{
get => _rowHeight;
set => _rowHeight = Mathf.RoundToInt(value);
}
public WatchStorage Watches
{
get => _watches;
set => _watches = value;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: e9b6ce6462174837ba694c741866a94f
timeCreated: 1644152689
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/WatchStorageSO.cs
uploadId: 770587

View File

@@ -0,0 +1,75 @@
using System;
using System.Globalization;
namespace Ingvar.LiveWatch
{
public static class WatchValueTextExtensions
{
public static string TrueString = "True";
public static string FalseString = "False";
public static string GetValueText(this WatchVariable variable, int index)
{
if (variable.Values.IsEmptyAt(index))
return string.Empty;
return variable.Values.Type switch
{
WatchValueType.String or WatchValueType.NotSet => GetStringText(variable.Values.StringList, index),
WatchValueType.Float => GetFloatText(variable.Values.FloatList, index, variable.RuntimeMeta.DecimalPlaces),
WatchValueType.Double => GetDoubleText(variable.Values.DoubleList, index, variable.RuntimeMeta.DecimalPlaces),
WatchValueType.Int => GetIntText(variable.Values.IntList, index),
WatchValueType.Bool => GetBoolText(variable.Values.BoolList, index),
_ => throw new ArgumentOutOfRangeException()
};
}
private static string GetFloatText(RepetitiveValueList<WatchValue<float>> valueList, int index, int decimalPlaces)
{
var watchValue = valueList[index];
if (!string.IsNullOrEmpty(watchValue.ValueText))
return watchValue.ValueText;
watchValue.ValueText = Math.Round(watchValue.Value, decimalPlaces).ToString(NumberFormatInfo.CurrentInfo);
valueList[index] = watchValue;
return watchValue.ValueText;
}
private static string GetDoubleText(RepetitiveValueList<WatchValue<double>> valueList, int index, int decimalPlaces)
{
var watchValue = valueList[index];
if (!string.IsNullOrEmpty(watchValue.ValueText))
return watchValue.ValueText;
watchValue.ValueText = Math.Round(watchValue.Value, decimalPlaces).ToString(NumberFormatInfo.CurrentInfo);
valueList[index] = watchValue;
return watchValue.ValueText;
}
private static string GetIntText(RepetitiveValueList<WatchValue<int>> valueList, int index)
{
var watchValue = valueList[index];
if (!string.IsNullOrEmpty(watchValue.ValueText))
return watchValue.ValueText;
watchValue.ValueText = watchValue.Value.ToString();
valueList[index] = watchValue;
return watchValue.ValueText;
}
private static string GetStringText(RepetitiveValueList<WatchValue<string>> valueList, int index)
{
var watchValue = valueList[index];
return watchValue.Value;
}
private static string GetBoolText(RepetitiveValueList<WatchValue<bool>> valueList, int index)
{
var watchValue = valueList[index];
return watchValue.Value ? TrueString : FalseString;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 022ad7c1a9f94695a9098fd7abc73b9a
timeCreated: 1706976188
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/WatchValueTextExtensions.cs
uploadId: 770587

View File

@@ -0,0 +1,174 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace Ingvar.LiveWatch
{
public static class WatchValueNumberExtensions
{
public static bool IsValidNumberValue(this WatchVariable variable, int index, out double value)
{
if (variable.Values.IsEmptyAt(index))
{
value = 0;
return false;
}
switch (variable.Values.Type)
{
case WatchValueType.NotSet:
value = 0;
return false;
case WatchValueType.Float:
var rawValueFloat = variable.Values.FloatList[index].Value;
value = rawValueFloat;
return float.IsFinite(rawValueFloat);
case WatchValueType.Double:
var rawValueDouble = variable.Values.DoubleList[index].Value;
value = rawValueDouble;
return double.IsFinite(rawValueDouble);
case WatchValueType.Int:
value = variable.Values.IntList[index].Value;
return true;
case WatchValueType.Bool:
value = variable.Values.BoolList[index].Value ? 1 : 0;
return true;
case WatchValueType.String when variable.RuntimeMeta.ValueType is { IsEnum: true }:
value = GetEnumNumber(
ref variable.EditorMeta.StringToNumberValues,
variable.Values.StringList[index].Value,
variable.RuntimeMeta.ValueType);
return true;
case WatchValueType.String:
value = GetStringNumber(
ref variable.EditorMeta.StringToNumberValues,
variable.Values.StringList[index].Value,
ref variable.EditorMeta.LastStringToNumberValue);
return true;
default:
throw new ArgumentOutOfRangeException();
}
}
public static bool IsValidNumberValueByIndexOfKey(this WatchVariable variable, int indexOfKey, out double value)
{
var isEmpty = variable.Values.Type switch
{
WatchValueType.Float => variable.Values.FloatList.OriginalValues[indexOfKey].IsEmpty,
WatchValueType.Double => variable.Values.DoubleList.OriginalValues[indexOfKey].IsEmpty,
WatchValueType.Int => variable.Values.IntList.OriginalValues[indexOfKey].IsEmpty,
WatchValueType.Bool => variable.Values.BoolList.OriginalValues[indexOfKey].IsEmpty,
WatchValueType.String or WatchValueType.NotSet => variable.Values.StringList.OriginalValues[indexOfKey].IsEmpty,
_ => throw new ArgumentOutOfRangeException()
};
if (isEmpty)
{
value = 0;
return false;
}
switch (variable.Values.Type)
{
case WatchValueType.NotSet:
value = 0;
return false;
case WatchValueType.Float:
var rawValueFloat = variable.Values.FloatList.OriginalValues[indexOfKey].Value;
value = rawValueFloat;
return float.IsFinite(rawValueFloat);
case WatchValueType.Double:
var rawValueDouble = variable.Values.DoubleList.OriginalValues[indexOfKey].Value;
value = rawValueDouble;
return double.IsFinite(rawValueDouble);
case WatchValueType.Int:
value = variable.Values.IntList.OriginalValues[indexOfKey].Value;
return true;
case WatchValueType.Bool:
value = variable.Values.BoolList.OriginalValues[indexOfKey].Value ? 1 : 0;
return true;
case WatchValueType.String when variable.RuntimeMeta.ValueType is { IsEnum: true }:
value = GetEnumNumber(
ref variable.EditorMeta.StringToNumberValues,
variable.Values.StringList.OriginalValues[indexOfKey].Value,
variable.RuntimeMeta.ValueType);
return true;
case WatchValueType.String:
value = GetStringNumber(
ref variable.EditorMeta.StringToNumberValues,
variable.Values.StringList.OriginalValues[indexOfKey].Value,
ref variable.EditorMeta.LastStringToNumberValue);
return true;
default:
throw new ArgumentOutOfRangeException();
}
}
public static double GetValueNumber(this WatchVariable variable, int index)
{
if (variable.Values.IsEmptyAt(index))
return 0;
return variable.Values.Type switch
{
WatchValueType.NotSet => 0,
WatchValueType.Float => variable.Values.FloatList[index].Value,
WatchValueType.Double => variable.Values.DoubleList[index].Value,
WatchValueType.Int => variable.Values.IntList[index].Value,
WatchValueType.Bool => variable.Values.BoolList[index].Value ? 1 : 0,
WatchValueType.String when variable.RuntimeMeta.ValueType is { IsEnum: true } => GetEnumNumber(
ref variable.EditorMeta.StringToNumberValues,
variable.Values.StringList[index].Value,
variable.RuntimeMeta.ValueType),
WatchValueType.String => GetStringNumber(
ref variable.EditorMeta.StringToNumberValues,
variable.Values.StringList[index].Value,
ref variable.EditorMeta.LastStringToNumberValue),
_ => throw new ArgumentOutOfRangeException()
};
}
private static int GetStringNumber(ref Dictionary<string, int> stringToNumbers, string stringValue, ref int lastStringToNumValue)
{
stringToNumbers ??= new Dictionary<string, int>();
if (stringToNumbers.TryGetValue(stringValue, out var number))
return number;
stringToNumbers.Add(stringValue, ++lastStringToNumValue);
return lastStringToNumValue;
}
private static int GetEnumNumber(ref Dictionary<string, int> stringToNumbers, string stringValue, Type enumType)
{
if (stringToNumbers == null)
{
stringToNumbers = new Dictionary<string, int>();
var names = Enum.GetNames(enumType);
for (var i = 0; i < names.Length; i++)
stringToNumbers.Add(names[i], i);
}
return stringToNumbers.TryGetValue(stringValue, out var number)
? number
: 0;
}
}
}

View File

@@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: aed4ed9fbcde48c2b678be9437927261
timeCreated: 1717959110
AssetOrigin:
serializedVersion: 1
productId: 324001
packageName: LiveWatch Lite | Debug with full history of changes
packageVersion: 1.0.1
assetPath: Assets/LiveWatchLite/Scripts/WatchValuesNumberBuilder.cs
uploadId: 770587

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 1707993120a44a7fba373a13ecd0f649
timeCreated: 1637776208

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 022d5fba93224fc08eff4e5e45aebd17
timeCreated: 1637776221

View File

@@ -0,0 +1,95 @@
using System;
using UnityEngine;
namespace Ingvar.LiveWatch
{
[Serializable]
public struct SearchQueryResult
{
public bool IsPositive;
public bool IsWholeSelection;
public int SelectionStartIndex;
public int SelectionEndIndex;
public int IndexOfResultInTotalList;
public static SearchQueryResult True() => new ()
{ IsPositive = true, IsWholeSelection = true};
public static SearchQueryResult True(int selectionStart, int selectionEnd) => new ()
{ IsPositive = true, SelectionStartIndex = selectionStart, SelectionEndIndex = selectionEnd};
public static SearchQueryResult False() => new ()
{ IsPositive = false };
public static SearchQueryResult And(SearchQueryResult left, SearchQueryResult right)
{
if (!left.IsPositive || !right.IsPositive)
{
return SearchQueryResult.False();
}
if (left.IsWholeSelection && right.IsWholeSelection)
{
return SearchQueryResult.True();
}
if (!left.IsWholeSelection && right.IsWholeSelection)
{
return left;
}
if (left.IsWholeSelection && !right.IsWholeSelection)
{
return right;
}
if (!left.IsWholeSelection && !right.IsWholeSelection)
{
var greater = right.SelectionEndIndex >= left.SelectionEndIndex ? right : left;
var lesser = greater.Equals(right) ? left : right;
if (lesser.SelectionEndIndex < greater.SelectionStartIndex)
{
return SearchQueryResult.False();
}
else
{
return SearchQueryResult.True(lesser.SelectionEndIndex, greater.SelectionEndIndex);
}
}
return SearchQueryResult.False();
}
public static SearchQueryResult Or(SearchQueryResult left, SearchQueryResult right)
{
if (!left.IsPositive && !right.IsPositive)
{
return SearchQueryResult.False();
}
if (left.IsWholeSelection || right.IsWholeSelection)
{
return SearchQueryResult.True();
}
if (left.IsPositive && !right.IsPositive)
{
return left;
}
if (!left.IsPositive && right.IsPositive)
{
return right;
}
var startIndex = Mathf.Min(left.SelectionStartIndex, right.SelectionStartIndex);
var endIndex = Mathf.Min(left.SelectionEndIndex, right.SelectionEndIndex);
return SearchQueryResult.True(startIndex, endIndex);
}
public static SearchQueryResult Inverse(SearchQueryResult result)
{
return result.IsPositive ? SearchQueryResult.False() : SearchQueryResult.True();
}
}
}

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