From c8eee7ab3feefe664277d6152bbf7c01eda8ad1c Mon Sep 17 00:00:00 2001 From: PopSlime Date: Fri, 14 Oct 2022 23:32:43 +0800 Subject: [PATCH] Update Cryville.Common. --- Assets/Cryville/Common/AsyncDelivery.cs | 18 +++ Assets/Cryville/Common/IOExtensions.cs | 26 ++++- Assets/Cryville/Common/Logger.cs | 55 ++++++++- Assets/Cryville/Common/Math/ColumnVector.cs | 32 +++++ .../Cryville/Common/Math/IVectorOperator.cs | 16 +++ Assets/Cryville/Common/Math/SquareMatrix.cs | 28 +++++ Assets/Cryville/Common/ReflectionHelper.cs | 80 ++++++++++++- Assets/Cryville/Common/StringUtils.cs | 14 +++ .../Common/Unity/NetworkTaskWorker.cs | 110 +++++++++++++++--- .../Unity/UI/AspectRatioLayoutElement.cs | 20 ++++ .../Unity/UI/DockAspectRatioLayoutGroup.cs | 7 ++ .../Common/Unity/UI/DockLayoutGroup.cs | 35 ++++++ .../Unity/UI/DockOccupiedRatioLayoutGroup.cs | 7 ++ .../Common/Unity/UI/GridLayoutSizeFitter.cs | 6 + .../Cryville/Common/Unity/UI/ImageSliced3.cs | 2 + .../Unity/UI/LayoutAspectRatioFitter.cs | 7 ++ .../Cryville/Common/Unity/UI/ProgressBar.cs | 11 ++ .../Common/Unity/UI/ScrollableItemGrid.cs | 70 +++++++---- 18 files changed, 497 insertions(+), 47 deletions(-) diff --git a/Assets/Cryville/Common/AsyncDelivery.cs b/Assets/Cryville/Common/AsyncDelivery.cs index 5c5b996..2f18325 100644 --- a/Assets/Cryville/Common/AsyncDelivery.cs +++ b/Assets/Cryville/Common/AsyncDelivery.cs @@ -1,12 +1,30 @@ using System; namespace Cryville.Common { + /// + /// Represents a cancellable asynchronized task. + /// + /// public class AsyncDelivery { + /// + /// The delegate to cancel the task. + /// public Action CancelSource { private get; set; } + /// + /// The delegate to call on task completion. + /// public Action Destination { private get; set; } + /// + /// Delivers the result to the destination. + /// + /// Whether the task has succeeded. + /// The result. public void Deliver(bool succeeded, T result) { if (Destination != null) Destination(succeeded, result); } + /// + /// Cancels the task. + /// public void Cancel() { if (CancelSource != null) CancelSource(); } diff --git a/Assets/Cryville/Common/IOExtensions.cs b/Assets/Cryville/Common/IOExtensions.cs index a0e8ed6..1ec8857 100644 --- a/Assets/Cryville/Common/IOExtensions.cs +++ b/Assets/Cryville/Common/IOExtensions.cs @@ -1,22 +1,42 @@ -using System; using System.IO; using System.Text; namespace Cryville.Common { + /// + /// Provides a set of methods related to file system and IO. + /// public static class IOExtensions { + /// + /// Gets a subdirectory of a directory. The subdirectory is created if it does not exist. + /// + /// The parent directory. + /// The name of the subdirectory. + /// public static DirectoryInfo GetSubdirectory(this DirectoryInfo dir, string name) { var l1 = dir.GetDirectories(name); if (l1.Length == 0) return dir.CreateSubdirectory(name); else return l1[0]; } - + + /// + /// Reads a string length-prefixed with a . + /// + /// The binary reader. + /// The encoding of the string. + /// The string read from the reader. public static string ReadUInt16String(this BinaryReader reader, Encoding encoding = null) { if (encoding == null) encoding = Encoding.UTF8; var len = reader.ReadUInt16(); byte[] buffer = reader.ReadBytes(len); return encoding.GetString(buffer); } - + + /// + /// Writes a string length-prefixed with a . + /// + /// The binary writer. + /// The string to write by the writer. + /// The encoding of the string. public static void WriteUInt16String(this BinaryWriter writer, string value, Encoding encoding = null) { if (encoding == null) encoding = Encoding.UTF8; byte[] buffer = encoding.GetBytes(value); diff --git a/Assets/Cryville/Common/Logger.cs b/Assets/Cryville/Common/Logger.cs index f251881..f61d421 100644 --- a/Assets/Cryville/Common/Logger.cs +++ b/Assets/Cryville/Common/Logger.cs @@ -1,23 +1,42 @@ -using Ionic.Zip; using System; using System.Collections.Generic; using System.IO; namespace Cryville.Common { + /// + /// A logger. + /// public abstract class Logger { static readonly Dictionary Instances = new Dictionary(); static readonly Dictionary Files = new Dictionary(); static string logPath = null; + /// + /// Sets the path where the log files shall be stored. + /// + /// The path. public static void SetLogPath(string path) { logPath = path; var dir = new DirectoryInfo(path); if (!dir.Exists) Directory.CreateDirectory(dir.FullName); } + /// + /// Logs to the specified logger. + /// + /// The key of the logger. + /// The severity level. + /// The module that is logging. + /// The format string. + /// The arguments for formatting. public static void Log(string key, int level, string module, string format, params object[] args) { if (!Instances.ContainsKey(key)) return; Instances[key].Log(level, module, string.Format(format, args)); if (Files.ContainsKey(key)) Files[key].WriteLine("[{0:O}] [{1}] <{2}> {3}", DateTime.UtcNow, level, module, string.Format(format, args)); } + /// + /// Adds a created logger to the shared logger manager. + /// + /// The key of the logger. + /// The logger. public static void Create(string key, Logger logger) { Instances[key] = logger; if (logPath != null) { @@ -26,37 +45,65 @@ namespace Cryville.Common { }; } } + /// + /// Closes all loggers and related file streams. + /// public static void Close() { Instances.Clear(); foreach (var f in Files) f.Value.Dispose(); Files.Clear(); } - + /// + /// Logs to the logger. + /// + /// The severity level. + /// The module that is logging. + /// The message. public virtual void Log(int level, string module, string msg) { } } + /// + /// A that calls a callback function on log. + /// public class InstantLogger : Logger { readonly Action callback; + /// + /// Creates an instance of the class. + /// + /// The callback function. + /// is . public InstantLogger(Action callback) { if (callback == null) throw new ArgumentNullException("callback"); this.callback = callback; } + /// public override void Log(int level, string module, string msg) { base.Log(level, module, msg); callback(level, module, msg); } } - + + /// + /// A that buffers the logs for enumeration. + /// public class BufferedLogger : Logger { readonly List buffer = new List(); + /// + /// Creates an instance of the class. + /// public BufferedLogger() { } + /// public override void Log(int level, string module, string msg) { base.Log(level, module, msg); lock (buffer) { buffer.Add(new LogEntry(level, module, msg)); } } + /// + /// Enumerates the buffered logs. + /// + /// The callback function to receive the logs. public void Enumerate(Action callback) { lock (buffer) { foreach (var i in buffer) { @@ -67,7 +114,7 @@ namespace Cryville.Common { } } - public struct LogEntry { + struct LogEntry { public int level; public string module; public string msg; diff --git a/Assets/Cryville/Common/Math/ColumnVector.cs b/Assets/Cryville/Common/Math/ColumnVector.cs index 6e16ed1..ffaf002 100644 --- a/Assets/Cryville/Common/Math/ColumnVector.cs +++ b/Assets/Cryville/Common/Math/ColumnVector.cs @@ -1,18 +1,38 @@ namespace Cryville.Common.Math { + /// + /// Represents a column vector of vector type . + /// + /// The vector type of the elements. public class ColumnVector { readonly T[] content; + /// + /// The size of the vector. + /// public int Size { get; private set; } + /// + /// Creates a column vector with specified size. + /// + /// The size of the vector. public ColumnVector(int size) { content = new T[size]; Size = size; } + /// + /// Creates a column vector from an array. + /// + /// The array. public ColumnVector(T[] c) { Size = c.Length; content = c; } + /// + /// Gets or sets the element at the specified index. + /// + /// The zero-based index of the element to get or set. + /// The element at the specified index. public T this[int i] { get { return content[i]; @@ -21,12 +41,24 @@ namespace Cryville.Common.Math { content[i] = value; } } + /// + /// Performs dot operation with a column vector. + /// + /// The lefthand column vector. + /// The vector operator. + /// The result of the dot operation. public T Dot(ColumnVector lhs, IVectorOperator o) { T res = default(T); for (var i = 0; i < Size; i++) res = o.Add(res, o.ScalarMultiply(lhs[i], content[i])); return res; } + /// + /// Creates a column vector and fills it with polynomial coefficients. + /// + /// The size of the column vector. + /// The base number. + /// A column vector filled with polynomial coefficients. public static ColumnVector WithPolynomialCoefficients(int size, float num) { var m = new ColumnVector(size); for (var i = 0; i < size; i++) diff --git a/Assets/Cryville/Common/Math/IVectorOperator.cs b/Assets/Cryville/Common/Math/IVectorOperator.cs index 0da9fd2..3cba5f5 100644 --- a/Assets/Cryville/Common/Math/IVectorOperator.cs +++ b/Assets/Cryville/Common/Math/IVectorOperator.cs @@ -1,6 +1,22 @@ namespace Cryville.Common.Math { + /// + /// Provides a set of operators for vector type . + /// + /// The vector type. public interface IVectorOperator { + /// + /// Adds two vectors. + /// + /// Lefthand vector. + /// Righthand vector. + /// The sum of the two vectors. T Add(T lhs, T rhs); + /// + /// Multiplies a vector with a number. + /// + /// The number. + /// The vector. + /// The product of the number and the vector. T ScalarMultiply(float lhs, T rhs); } } diff --git a/Assets/Cryville/Common/Math/SquareMatrix.cs b/Assets/Cryville/Common/Math/SquareMatrix.cs index c19fa6d..c6a1060 100644 --- a/Assets/Cryville/Common/Math/SquareMatrix.cs +++ b/Assets/Cryville/Common/Math/SquareMatrix.cs @@ -1,18 +1,41 @@ namespace Cryville.Common.Math { + /// + /// Represents a square matrix. + /// public class SquareMatrix { readonly float[,] content; + /// + /// The size of the matrix. + /// public int Size { get; private set; } + /// + /// Creates a square matrix with the specified size. + /// + /// The size of the matrix. public SquareMatrix(int size) { content = new float[size, size]; Size = size; } + /// + /// Gets or sets the element at the specified index. + /// + /// The zero-based row index. + /// The zero-based column index. + /// The element at the specified index. public float this[int r, int c] { get { return content[r, c]; } set { content[r, c] = value; } } + /// + /// Eliminates the square matrix against a column vector. + /// + /// The vector type. + /// The column vector. + /// The column operator. + /// The column vector eliminated. public ColumnVector Eliminate(ColumnVector v, IVectorOperator o) { int s = Size; float[,] d = (float[,])content.Clone(); @@ -48,6 +71,11 @@ } return new ColumnVector(res); } + /// + /// Creates a square matrix and fills it with polynomial coefficients. + /// + /// The size of the square matrix. + /// A square matrix filled with polynomial coefficients. public static SquareMatrix WithPolynomialCoefficients(int size) { var m = new SquareMatrix(size); for (var r = 0; r < size; r++) { diff --git a/Assets/Cryville/Common/ReflectionHelper.cs b/Assets/Cryville/Common/ReflectionHelper.cs index 4bbcf83..4c698c9 100644 --- a/Assets/Cryville/Common/ReflectionHelper.cs +++ b/Assets/Cryville/Common/ReflectionHelper.cs @@ -4,16 +4,36 @@ using System.Collections.Generic; using System.Linq; namespace Cryville.Common { + /// + /// Provides a set of methods for refletion. + /// public static class ReflectionHelper { static readonly Type[] emptyTypeArray = {}; + /// + /// Gets the parameterless constructor of a type. + /// + /// The type. + /// The parameterless constructor of the type. public static ConstructorInfo GetEmptyConstructor(Type type) { return type.GetConstructor(emptyTypeArray); } static readonly object[] emptyObjectArray = {}; + /// + /// Invokes the parameterless constructor of a type and returns the result. + /// + /// The type. + /// The created instance. public static object InvokeEmptyConstructor(Type type) { return GetEmptyConstructor(type).Invoke(emptyObjectArray); } + /// + /// Tries to find a member with the specified attribute type in a type. + /// + /// The attribute type. + /// The type containing the member with the specified attribute type. + /// The member. + /// Whether the member is found. public static bool TryFindMemberWithAttribute(Type t, out MemberInfo mi) where T : Attribute { try { mi = FindMemberWithAttribute(t); @@ -24,6 +44,13 @@ namespace Cryville.Common { return false; } } + /// + /// Finds a member with the specified attribute type in a type. + /// + /// The attribute type. + /// The type containing the member with the specified attribute type. + /// + /// The member is not found or multiple members are found. public static MemberInfo FindMemberWithAttribute(Type type) where T : Attribute { var mil = type.FindMembers( MemberTypes.Field | MemberTypes.Property, @@ -36,10 +63,22 @@ namespace Cryville.Common { return mil[0]; } + /// + /// Gets whether a type is a . + /// + /// The type. + /// Whether the type is a . public static bool IsGenericDictionary(Type type) { return type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>); } - + + /// + /// Gets the member from a type with the specified name. + /// + /// The type. + /// The name of the member. + /// The member. + /// The member is not found or multiple members are found. public static MemberInfo GetMember(Type type, string name) { var mil = type.GetMember( name, @@ -50,16 +89,29 @@ namespace Cryville.Common { throw new MissingMemberException(type.Name, name); return mil[0]; } - + + /// + /// Gets the type of a member. + /// + /// The member. + /// The type of the member. + /// is not a field or a property. public static Type GetMemberType(MemberInfo mi) { if (mi is FieldInfo) return ((FieldInfo)mi).FieldType; if (mi is PropertyInfo) return ((PropertyInfo)mi).PropertyType; else - throw new ArgumentException(); + throw new ArgumentException("Member is not field or property."); } - + + /// + /// Gets the value of a member of an object. + /// + /// The member. + /// The object. + /// The value. + /// is not a field or a property. public static object GetValue(MemberInfo mi, object obj) { if (mi is FieldInfo) return ((FieldInfo)mi).GetValue(obj); @@ -68,7 +120,15 @@ namespace Cryville.Common { else throw new ArgumentException(); } - + + /// + /// Sets the value of a member of an object. + /// + /// The member. + /// The object. + /// The value. + /// An optional binder to convert the value. + /// is not a field or a property. public static void SetValue(MemberInfo mi, object obj, object value, Binder binder = null) { if (mi is FieldInfo) ((FieldInfo)mi).SetValue(obj, value, BindingFlags.Default, binder, null); @@ -78,6 +138,11 @@ namespace Cryville.Common { throw new ArgumentException(); } + /// + /// Gets all the subclasses of a type in the current app domain. + /// + /// The type. + /// An array containing all the subclasses of the type in the current app domain. public static Type[] GetSubclassesOf() where T : class { var assemblies = AppDomain.CurrentDomain.GetAssemblies(); IEnumerable r = new List(); @@ -90,6 +155,11 @@ namespace Cryville.Common { return r.ToArray(); } + /// + /// Gets a simple name of a type. + /// + /// The type. + /// A simple name of the class. public static string GetSimpleName(Type type) { string result = type.Name; var typeargs = type.GetGenericArguments(); diff --git a/Assets/Cryville/Common/StringUtils.cs b/Assets/Cryville/Common/StringUtils.cs index dc8c6d4..a25dc67 100644 --- a/Assets/Cryville/Common/StringUtils.cs +++ b/Assets/Cryville/Common/StringUtils.cs @@ -2,10 +2,24 @@ using System.Text; namespace Cryville.Common { + /// + /// Provides a set of methods related to string operations. + /// public static class StringUtils { + /// + /// Removes the extension in a file name or file path. + /// + /// The file name or file path. + /// The file name or file path with the extension removed. public static string TrimExt(string s) { return s.Substring(0, s.LastIndexOf(".")); } + /// + /// Converts the value of a to a human-readable string. + /// + /// The time span. + /// The digit count for seconds. + /// A human-readable string representing the time span. public static string ToString(this TimeSpan timeSpan, int digits) { var b = new StringBuilder(); bool flag = false; diff --git a/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs b/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs index 2f93bf3..45b6a51 100644 --- a/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs +++ b/Assets/Cryville/Common/Unity/NetworkTaskWorker.cs @@ -7,32 +7,52 @@ using UnityEngine.Rendering; #endif namespace Cryville.Common.Unity { + /// + /// A worker that performs network tasks in the background. + /// + /// + /// It is required to call every tick to keep the worker working. + /// public class NetworkTaskWorker { bool suspended; NetworkTask currentNetworkTask; readonly Queue networkTasks = new Queue(); + /// + /// Current queued task count. + /// public int TaskCount { get { return networkTasks.Count; } } + /// + /// Submits a new network task. + /// + /// The task. public void SubmitNetworkTask(NetworkTask task) { networkTasks.Enqueue(task); } + /// + /// Ticks the worker. + /// + /// The status of the worker. public WorkerStatus TickBackgroundTasks() { if (suspended) return WorkerStatus.Suspended; if (currentNetworkTask != null) { - if (currentNetworkTask.Canceled) currentNetworkTask = null; + if (currentNetworkTask.Cancelled) currentNetworkTask = null; else if (currentNetworkTask.Done()) currentNetworkTask = null; } while (networkTasks.Count > 0 && currentNetworkTask == null) { var task = networkTasks.Dequeue(); - if (task.Canceled) continue; + if (task.Cancelled) continue; currentNetworkTask = task; currentNetworkTask.Start(); } return currentNetworkTask == null ? WorkerStatus.Idle : WorkerStatus.Working; } + /// + /// Cancels the current working task (if present) and suspends all background tasks. + /// public void SuspendBackgroundTasks() { suspended = true; if (currentNetworkTask != null) { @@ -41,63 +61,123 @@ namespace Cryville.Common.Unity { } } + /// + /// Resumes background tasks. + /// public void ResumeBackgroundTasks() { suspended = false; } } + /// + /// Status of a . + /// public enum WorkerStatus { - Idle, Working, Suspended, + /// + /// The worker is not working nor suspended. + /// + Idle, + /// + /// The worker is working on a task. + /// + Working, + /// + /// The worker is suspended. + /// + Suspended, } + /// + /// A network task. + /// public abstract class NetworkTask { protected NetworkTask(string uri) { Uri = uri; } + /// + /// The URI of the resource. + /// public string Uri { get; private set; } - public bool Canceled { get; private set; } + /// + /// Whether the task is cancelled. + /// + public bool Cancelled { get; private set; } + /// + /// Cancels the task. + /// public virtual void Cancel() { - Canceled = true; + Cancelled = true; } #if UNITY_5_4_OR_NEWER protected UnityWebRequest www; + + /// + /// Starts the task. + /// public virtual void Start() { www = new UnityWebRequest(Uri); www.SendWebRequest(); } + /// + /// Gets whether the task is done. + /// + /// Whether the task is done. public virtual bool Done() { if (!www.isDone) return false; return true; } #else protected WWW www; - public virtual WWW Start() { - return new WWW(Uri); + /// + /// Starts the task. + /// + public virtual void Start() { + www = new WWW(Uri); + } + /// + /// Gets whether the task is done. + /// + /// Whether the task is done. + public virtual bool Done() { + if (!www.isDone) return false; + return true; } - public abstract void Done(); #endif } + /// + /// A that loads a texture. + /// public class LoadTextureTask : NetworkTask { + /// + /// Creates an instance of the class. + /// + /// The URI of the resource. + /// The callback function upon load complete. public LoadTextureTask(string uri, Action callback) : base(uri) { Callback = callback; } + /// + /// The callback function upon load complete. + /// public Action Callback { get; private set; } #if UNITY_5_4_OR_NEWER DownloadHandlerTexture handler; + /// public override void Start() { handler = new DownloadHandlerTexture(); www = new UnityWebRequest(Uri, "GET", handler, null); www.SendWebRequest(); } + /// public override bool Done() { - if (!handler.isDone) return false; - if (handler.texture != null) { + if (!www.isDone) return false; + if (handler.isDone && handler.texture != null) { var buffer = handler.texture; /*var result = new Texture2D(buffer.width, buffer.height, buffer.format, true); if (SystemInfo.copyTextureSupport.HasFlag(CopyTextureSupport.Basic)) { @@ -119,17 +199,21 @@ namespace Cryville.Common.Unity { return true; } #else - public override void PostProcess(WWW www) { + /// + public override bool Done() { + if (!www.isDone) return false; bool succeeded = string.IsNullOrEmpty(www.error); if (succeeded) { var buffer = www.texture; - var result = new Texture2D(buffer.width, buffer.height, buffer.format, true); + /*var result = new Texture2D(buffer.width, buffer.height, buffer.format, true); result.SetPixels(buffer.GetPixels()); result.Apply(true, true); Texture2D.Destroy(buffer); - Callback(true, result); + Callback(true, result);*/ + Callback(true, buffer); } else Callback(false, null); + return true; } #endif } diff --git a/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs b/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs index c7337fc..a389ab7 100644 --- a/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs +++ b/Assets/Cryville/Common/Unity/UI/AspectRatioLayoutElement.cs @@ -3,16 +3,27 @@ using UnityEngine.EventSystems; using UnityEngine.UI; namespace Cryville.Common.Unity.UI { + /// + /// A that takes the length of one axis to compute the preferred length of the other axis with respect to a aspect ratio. + /// public class AspectRatioLayoutElement : UIBehaviour, ILayoutElement { [SerializeField] + [Tooltip("The aspect ratio. Width divided by height.")] private float m_aspectRatio = 1; + /// + /// The aspect ratio. Width divided by height. + /// public float AspectRatio { get { return m_aspectRatio; } set { SetProperty(ref m_aspectRatio, value); } } [SerializeField] + [Tooltip("Whether to compute the length of the y axis.")] private bool m_isVertical = false; + /// + /// Whether to compute the length of the y axis. + /// public bool IsVertical { get { return m_isVertical; } set { SetProperty(ref m_isVertical, value); } @@ -29,26 +40,35 @@ namespace Cryville.Common.Unity.UI { LayoutRebuilder.MarkLayoutForRebuild(transform as RectTransform); } + /// public float minWidth { get { return m_isVertical ? 0 : (transform as RectTransform).rect.height * m_aspectRatio; } } + /// public float preferredWidth { get { return minWidth; } } + /// public float flexibleWidth { get { return 0; } } + /// public float minHeight { get { return m_isVertical ? (transform as RectTransform).rect.width / m_aspectRatio : 0; } } + /// public float preferredHeight { get { return minHeight; } } + /// public float flexibleHeight { get { return 0; } } + /// public int layoutPriority { get { return 1; } } + /// public void CalculateLayoutInputHorizontal() { } + /// public void CalculateLayoutInputVertical() { } protected override void OnDidApplyAnimationProperties() { diff --git a/Assets/Cryville/Common/Unity/UI/DockAspectRatioLayoutGroup.cs b/Assets/Cryville/Common/Unity/UI/DockAspectRatioLayoutGroup.cs index 1e2245d..625f248 100644 --- a/Assets/Cryville/Common/Unity/UI/DockAspectRatioLayoutGroup.cs +++ b/Assets/Cryville/Common/Unity/UI/DockAspectRatioLayoutGroup.cs @@ -1,9 +1,16 @@ using UnityEngine; namespace Cryville.Common.Unity.UI { + /// + /// A that sets the aspect ratio of the docking element. + /// public sealed class DockAspectRatioLayoutGroup : DockLayoutGroup { [SerializeField] + [Tooltip("The aspect ratio of the docking element.")] private float m_dockAspectRatio = 1; + /// + /// The aspect ratio of the docking element. + /// public float DockAspectRatio { get { return m_dockAspectRatio; } set { base.SetProperty(ref m_dockAspectRatio, value); } diff --git a/Assets/Cryville/Common/Unity/UI/DockLayoutGroup.cs b/Assets/Cryville/Common/Unity/UI/DockLayoutGroup.cs index 8a75c18..d3fa3b3 100644 --- a/Assets/Cryville/Common/Unity/UI/DockLayoutGroup.cs +++ b/Assets/Cryville/Common/Unity/UI/DockLayoutGroup.cs @@ -2,30 +2,60 @@ using UnityEngine.UI; namespace Cryville.Common.Unity.UI { + /// + /// A that docks its first child element to one side. + /// public abstract class DockLayoutGroup : LayoutGroup { + /// + /// The dock side. + /// public enum Side { + /// + /// Top. + /// Top = 0, + /// + /// Right. + /// Right = 1, + /// + /// Bottom. + /// Bottom = 2, + /// + /// Left. + /// Left = 3, } [SerializeField] + [Tooltip("The docking side of the first child element.")] private Side m_side; + /// + /// The docking side of the first child element. + /// public Side DockSide { get { return m_side; } set { base.SetProperty(ref m_side, value); } } [SerializeField] + [Tooltip("The slide index. The children slide along the cross axis.")] private float m_slideIndex; + /// + /// The slide index. The children slide along the axis. + /// public float SlideIndex { get { return m_slideIndex; } set { base.SetProperty(ref m_slideIndex, value); } } + /// public sealed override void CalculateLayoutInputHorizontal() { base.CalculateLayoutInputHorizontal(); } + /// public sealed override void CalculateLayoutInputVertical() { } + /// public sealed override void SetLayoutHorizontal() { SetChildrenAlongAxis(0); } + /// public sealed override void SetLayoutVertical() { SetChildrenAlongAxis(1); } private float GetSlidePosition(float groupHeight, float dockHeight) { @@ -68,6 +98,11 @@ namespace Cryville.Common.Unity.UI { } } + /// + /// Gets the length of the first child element along the axis. + /// + /// The size of the layout group. + /// protected abstract float GetDockElementSize(Vector2 groupSize); } } diff --git a/Assets/Cryville/Common/Unity/UI/DockOccupiedRatioLayoutGroup.cs b/Assets/Cryville/Common/Unity/UI/DockOccupiedRatioLayoutGroup.cs index 6a2fad5..8d5781b 100644 --- a/Assets/Cryville/Common/Unity/UI/DockOccupiedRatioLayoutGroup.cs +++ b/Assets/Cryville/Common/Unity/UI/DockOccupiedRatioLayoutGroup.cs @@ -1,9 +1,16 @@ using UnityEngine; namespace Cryville.Common.Unity.UI { + /// + /// A that sets the occupied ratio of the docking element. + /// public sealed class DockOccupiedRatioLayoutGroup : DockLayoutGroup { [SerializeField] + [Tooltip("The occupied ratio of the docking element.")] private float m_dockOccupiedRatio = 1; + /// + /// The occupied ratio of the docking element. + /// public float DockOccupiedRatio { get { return m_dockOccupiedRatio; } set { base.SetProperty(ref m_dockOccupiedRatio, value); } diff --git a/Assets/Cryville/Common/Unity/UI/GridLayoutSizeFitter.cs b/Assets/Cryville/Common/Unity/UI/GridLayoutSizeFitter.cs index a3a3f2d..76a3f4a 100644 --- a/Assets/Cryville/Common/Unity/UI/GridLayoutSizeFitter.cs +++ b/Assets/Cryville/Common/Unity/UI/GridLayoutSizeFitter.cs @@ -2,11 +2,17 @@ using UnityEngine.UI; namespace Cryville.Common.Unity.UI { + /// + /// Fits the size of a with its cells. + /// [RequireComponent(typeof(GridLayoutGroup))] public class GridLayoutSizeFitter : MonoBehaviour { RectTransform rectTransform; GridLayoutGroup gridLayoutGroup; Canvas canvas; + /// + /// The item count per line. + /// public int GroupItemCount = 3; #pragma warning disable IDE0051 diff --git a/Assets/Cryville/Common/Unity/UI/ImageSliced3.cs b/Assets/Cryville/Common/Unity/UI/ImageSliced3.cs index a131118..4f54096 100644 --- a/Assets/Cryville/Common/Unity/UI/ImageSliced3.cs +++ b/Assets/Cryville/Common/Unity/UI/ImageSliced3.cs @@ -10,6 +10,7 @@ namespace Cryville.Common.Unity.UI { [ExecuteInEditMode] public class ImageSliced3 : MaskableGraphic { [SerializeField] + [Tooltip("The sliced sprite.")] private Sprite m_sprite; /// /// The sliced sprite. @@ -45,6 +46,7 @@ namespace Cryville.Common.Unity.UI { DiagonalRight = 5, } [SerializeField] + [Tooltip("The mode how a sliced image is generated when it is too compact.")] private CompactMode m_compact; /// /// The mode how a sliced image is generated when it is too compact. diff --git a/Assets/Cryville/Common/Unity/UI/LayoutAspectRatioFitter.cs b/Assets/Cryville/Common/Unity/UI/LayoutAspectRatioFitter.cs index 8056d30..d36b5f8 100644 --- a/Assets/Cryville/Common/Unity/UI/LayoutAspectRatioFitter.cs +++ b/Assets/Cryville/Common/Unity/UI/LayoutAspectRatioFitter.cs @@ -2,9 +2,16 @@ using UnityEngine.UI; namespace Cryville.Common.Unity.UI { + /// + /// Fits the length of an axis of an element with respect to the children count and the shared aspect ratio. + /// public class LayoutAspectRatioFitter : MonoBehaviour { [SerializeField] + [Tooltip("The aspect ratio per element.")] private float m_aspectRatioPerElement = 1; + /// + /// The aspect ratio per element. + /// public float AspectRatioPerElement { get { return m_aspectRatioPerElement; } set { m_aspectRatioPerElement = value; } diff --git a/Assets/Cryville/Common/Unity/UI/ProgressBar.cs b/Assets/Cryville/Common/Unity/UI/ProgressBar.cs index d94c66e..1f184c0 100644 --- a/Assets/Cryville/Common/Unity/UI/ProgressBar.cs +++ b/Assets/Cryville/Common/Unity/UI/ProgressBar.cs @@ -2,16 +2,27 @@ using UnityEngine.UI; namespace Cryville.Common.Unity.UI { + /// + /// A non-interactive that has an internal tweening behaviour. + /// public class ProgressBar : Slider { [SerializeField][Range(0f, 1f)] + [Tooltip("The tweening parameter.")] float m_smooth = 0; + /// + /// The tweening parameter. + /// public float Smooth { get { return m_smooth; } set { m_smooth = value; } } [SerializeField] + [Tooltip("The target value.")] float m_targetValue; + /// + /// Gets the current displayed value or sets the target value. + /// public override float value { get { return base.value; } set { m_targetValue = value; } diff --git a/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs b/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs index bcb98b0..74db3a1 100644 --- a/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs +++ b/Assets/Cryville/Common/Unity/UI/ScrollableItemGrid.cs @@ -3,61 +3,84 @@ using UnityEngine; using UnityEngine.UI; namespace Cryville.Common.Unity.UI { + /// + /// A handler for loading an item. + /// + /// The zero-based index of the item. + /// The game object for the item instantiated from the item template. + /// + public delegate bool LoadItemHandler(int index, GameObject gameObject); + /// + /// A scrollable grid that dynamically loads its items. + /// public sealed class ScrollableItemGrid : MonoBehaviour { [SerializeField] + [Tooltip("The item template.")] private GameObject m_itemTemplate; + /// + /// The item template. + /// public GameObject ItemTemplate { get { return m_itemTemplate; } set { m_itemTemplate = value; OnTemplateUpdate(); } } - public Func LoadItem { private get; set; } - - public enum Corner { - UpperLeft = 0, - UpperRight = 1, - LowerLeft = 2, - LowerRight = 3, - } - [SerializeField] - private Corner m_startCorner; // TODO - public Corner StartCorner { - get { return m_startCorner; } - set { m_startCorner = value; OnFrameUpdate(); } - } + /// + /// The handler for loading an item. + /// + public LoadItemHandler LoadItem { private get; set; } + /// + /// Axis. + /// public enum Axis { - Horizontal = 0, Vertical = 1, + /// + /// Horizontal (x) axis. + /// + Horizontal = 0, + /// + /// Vertical (y) axis. + /// + Vertical = 1, } [SerializeField] + [Tooltip("The main axis.")] private Axis m_startAxis; + /// + /// The main axis. + /// public Axis StartAxis { get { return m_startAxis; } set { m_startAxis = value; OnFrameUpdate(); } } [SerializeField] - private Vector2 m_spacing; // TODO - public Vector2 Spacing { - get { return m_spacing; } - set { m_spacing = value; OnFrameUpdate(); } - } - - [SerializeField] + [Tooltip("The item count.")] private int m_itemCount = 3; + /// + /// The item count. + /// public int ItemCount { get { return m_itemCount; } set { m_itemCount = value; OnRefresh(); } } [SerializeField] + [Tooltip("The item count per line.")] private int m_lineItemCount = 3; + /// + /// The item count per line. + /// public int LineItemCount { get { return m_lineItemCount; } set { m_lineItemCount = value; OnFrameUpdate(); } } [SerializeField] + [Tooltip("The length of the cross axis per line.")] private float m_lineHeight = 100; + /// + /// The length of the cross axis per line. + /// public float LineHeight { get { return m_lineHeight; } set { m_lineHeight = value; OnFrameUpdate(); } @@ -78,6 +101,9 @@ namespace Cryville.Common.Unity.UI { ); } } + /// + /// The maximum count of visible lines. + /// public int VisibleLines { get { return Mathf.CeilToInt(VisibleSize.y / m_lineHeight) + 1;