diff --git a/Assets/JCSUnity/Editor/JCSUnity_EditorWindow.cs b/Assets/JCSUnity/Editor/JCSUnity_EditorWindow.cs index 64513b0d..6d6d777a 100644 --- a/Assets/JCSUnity/Editor/JCSUnity_EditorWindow.cs +++ b/Assets/JCSUnity/Editor/JCSUnity_EditorWindow.cs @@ -623,7 +623,7 @@ private static void CreateSlidePanel() Image panelImage = slidePanel.GetComponent(); if (panelImage != null) { - panelImage.color = JCS_Random.RandomColor(); + panelImage.color = JCS_Random.PickColor(); } // assign to slide panel holder. diff --git a/Assets/JCSUnity/Scripts/Util/JCS_Random.cs b/Assets/JCSUnity/Scripts/Util/JCS_Random.cs index f7a741fc..a97eb44f 100644 --- a/Assets/JCSUnity/Scripts/Util/JCS_Random.cs +++ b/Assets/JCSUnity/Scripts/Util/JCS_Random.cs @@ -7,6 +7,7 @@ * Copyright (c) 2017 by Shen, Jen-Chieh $ */ using System.Collections.Generic; +using Unity.VisualScripting; using UnityEngine; namespace JCSUnity @@ -59,7 +60,7 @@ public static float RangeInclude(float min, float max) /// Return a random color. /// /// random color object. - public static Color RandomColor(float a = 1.0f) + public static Color PickColor(float a = 1.0f) { return new Color(Range(0.0f, 1.0f), Range(0.0f, 1.0f), Range(0.0f, 1.0f), a); } @@ -103,5 +104,17 @@ public static T ChooseOneE(params T[] args) // Ellipsis int index = Range(0, args.Length); return args[index]; } + + /// + /// Return a random enum value. + /// + /// The enum type. + /// The enum value that has been randomly chosen. + public static T EnumValue() + { + var r = new System.Random(); + var v = System.Enum.GetValues(typeof(T)); + return (T)v.GetValue(r.Next(v.Length)); + } } } diff --git a/docs/ScriptReference/Util/JCS_Random.md b/docs/ScriptReference/Util/JCS_Random.md index ce62387b..c6f1ede1 100644 --- a/docs/ScriptReference/Util/JCS_Random.md +++ b/docs/ScriptReference/Util/JCS_Random.md @@ -8,6 +8,7 @@ Random library class. |:-------------|:--------------------------------------------| | Range | Default random range wrapper. | | RaneeInclude | Include the maxinum number. | -| RandomColor | Returns a random color. | +| PickColor | Returns a random color. | | ChooseOne | Choose one object from the list. | | ChooseOneE | Choose one object from the list. (Ellipsis) | +| EnumValue | Return a random enum value. |