From 9fb8b228244565680ea954ad138f25ff00273151 Mon Sep 17 00:00:00 2001 From: AstrlJelly Date: Mon, 19 Feb 2024 02:06:49 -0500 Subject: [PATCH] things are very nearly working! however i just hit an insane hurdle. how do i modify a dropdown while still being able to access the index/int value of that param directly. UGHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH --- .../Editor/EventProperties/Button.prefab | 1 + .../Editor/EventProperties/Float.prefab | 6 +- Assets/Scenes/Editor.unity | 10 +-- Assets/Scripts/GameManager.cs | 11 +-- .../EventSelector/EventParameterManager.cs | 90 +++++-------------- .../EventSelector/EventPropertyPrefab.cs | 8 +- .../PropertyPrefabs/BoolPropertyPrefab.cs | 8 +- .../PropertyPrefabs/ButtonPropertyPrefab.cs | 17 ++-- .../PropertyPrefabs/ColorPropertyPrefab.cs | 8 +- .../PropertyPrefabs/DropdownPropertyPrefab.cs | 58 ++++++------ .../PropertyPrefabs/NumberPropertyPrefab.cs | 24 +---- .../PropertyPrefabs/StringPropertyPrefab.cs | 4 +- .../Scripts/LevelEditor/Timeline/Timeline.cs | 15 ++-- Assets/Scripts/Minigames.cs | 90 ++++++++++++++++--- Assets/Scripts/Util/EntityTypes.cs | 59 ++++++++++-- 15 files changed, 222 insertions(+), 187 deletions(-) diff --git a/Assets/Resources/Prefabs/Editor/EventProperties/Button.prefab b/Assets/Resources/Prefabs/Editor/EventProperties/Button.prefab index 3c1c44372..d4d625e4c 100644 --- a/Assets/Resources/Prefabs/Editor/EventProperties/Button.prefab +++ b/Assets/Resources/Prefabs/Editor/EventProperties/Button.prefab @@ -55,6 +55,7 @@ MonoBehaviour: caption: {fileID: 161819469598736649} parameterManager: {fileID: 0} propertyName: + buttonText: {fileID: 1122443660375095464} --- !u!114 &1492239408036616687 MonoBehaviour: m_ObjectHideFlags: 0 diff --git a/Assets/Resources/Prefabs/Editor/EventProperties/Float.prefab b/Assets/Resources/Prefabs/Editor/EventProperties/Float.prefab index 9f2425743..0345dacd4 100644 --- a/Assets/Resources/Prefabs/Editor/EventProperties/Float.prefab +++ b/Assets/Resources/Prefabs/Editor/EventProperties/Float.prefab @@ -421,7 +421,7 @@ RectTransform: m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 10, y: 0} m_Pivot: {x: 0.5, y: 0.5} @@ -885,7 +885,7 @@ RectTransform: m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} - m_AnchorMax: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 0} m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 20, y: 0} m_Pivot: {x: 0.5, y: 0.5} @@ -943,7 +943,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!224 &872153477128913844 RectTransform: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index 4a700d3b5..c9d9b3cbe 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -13012,7 +13012,7 @@ MonoBehaviour: m_TargetGraphic: {fileID: 171581557} m_HandleRect: {fileID: 171581556} m_Direction: 2 - m_Value: 1 + m_Value: 0 m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: @@ -24624,7 +24624,7 @@ MonoBehaviour: m_HandleRect: {fileID: 1589389271} m_Direction: 2 m_Value: 1 - m_Size: 0.44222867 + m_Size: 1 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -30367,7 +30367,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0.5} m_AnchorMax: {x: 1, y: 0.5} - m_AnchoredPosition: {x: 0, y: 186.98236} + m_AnchoredPosition: {x: 0, y: 121.30615} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 1} --- !u!222 &1154875945 @@ -39827,8 +39827,8 @@ MonoBehaviour: m_TargetGraphic: {fileID: 1220118245} m_HandleRect: {fileID: 1220118244} m_Direction: 2 - m_Value: 1 - m_Size: 1 + m_Value: 1.0000005 + m_Size: 0.60682213 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: diff --git a/Assets/Scripts/GameManager.cs b/Assets/Scripts/GameManager.cs index ede245f42..3e42293f5 100644 --- a/Assets/Scripts/GameManager.cs +++ b/Assets/Scripts/GameManager.cs @@ -40,7 +40,7 @@ namespace HeavenStudio public string currentGame { get; private set; } public GameObject minigameObj { get; private set; } public Minigame minigame { get; private set; } - public Animator[] mgAnimators { get; private set; } + public Animator[] minigameAnimators { get; set; } public RiqEntity lastSection { get; private set; } public RiqEntity currentSection { get; private set; } @@ -631,13 +631,9 @@ namespace HeavenStudio } } - public void PlayAnimationArbitrary(string animator, string animation, float scale) + public void PlayAnimationArbitrary(int animator, int animation, float scale) { - // if possible (efficient enough) id like to find the object recursively, but for now this works - Transform animTrans = minigameObj.transform.Find(animator); - if (animTrans != null && animTrans.TryGetComponent(out var anim)) { - anim.DoScaledAnimationAsync(animation, scale); - } + } public void ToggleInputs(bool inputs) @@ -1142,7 +1138,6 @@ namespace HeavenStudio minigameObj.transform.parent = eventCaller.GamesHolder.transform; minigameObj.transform.localScale = originalScale; minigameObj.name = game; - mgAnimators = minigameObj.transform.GetComponentsInChildren(); SetCurrentGame(game, useMinigameColor); } diff --git a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs index 08c9b0f77..b9082c907 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/EventParameterManager.cs @@ -2,13 +2,10 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -using HeavenStudio.Editor.Track; using Jukebox; -using Jukebox.Legacy; using System.Linq; using System; -using System.Windows.Forms.VisualStyles; -using System.Windows.Forms; +using static HeavenStudio.EntityTypes; namespace HeavenStudio.Editor { @@ -26,6 +23,7 @@ namespace HeavenStudio.Editor [SerializeField] private GameObject DropdownP; [SerializeField] private GameObject ColorP; [SerializeField] private GameObject StringP; + private static Dictionary PropertyPrefabs; public RiqEntity entity; @@ -40,6 +38,18 @@ namespace HeavenStudio.Editor private void Awake() { instance = this; + + if (PropertyPrefabs == null) { + PropertyPrefabs = new() { + { typeof(Integer), IntegerP }, + { typeof(Float), FloatP }, + { typeof(Dropdown), DropdownP }, + { typeof(Button), ButtonP }, + { typeof(Color), ColorP }, + { typeof(bool), BooleanP }, + { typeof(string), StringP }, + }; + } } private void Start() @@ -74,15 +84,6 @@ namespace HeavenStudio.Editor AddParams(entity); } - static string TrackToThemeColour(int track) => track switch - { - 1 => EditorTheme.theme.properties.Layer2Col, - 2 => EditorTheme.theme.properties.Layer3Col, - 3 => EditorTheme.theme.properties.Layer4Col, - 4 => EditorTheme.theme.properties.Layer5Col, - _ => EditorTheme.theme.properties.Layer1Col - }; - private void AddParams(RiqEntity entity) { string[] split = entity.datamodel.Split('/'); @@ -95,7 +96,7 @@ namespace HeavenStudio.Editor eventSelector.SetActive(false); this.entity = entity; - string col = TrackToThemeColour((int)entity["track"]); + string col = EditorTheme.theme.properties.LayerColors[(int)entity["track"]]; Editor.instance.SetGameEventTitle($"Properties for {action.displayName} on Beat {entity.beat.ToString("F2")} on Track {(int)entity["track"] + 1}"); DestroyParams(); @@ -104,11 +105,8 @@ namespace HeavenStudio.Editor for (int i = 0; i < action.parameters.Count; i++) { - object param = action.parameters[i].parameter; - string caption = action.parameters[i].propertyCaption; - string propertyName = action.parameters[i].propertyName; - string tooltip = action.parameters[i].tooltip; - ePrefabs.Add(propertyName, AddParam(propertyName, param, caption, tooltip)); + var p = action.parameters[i]; + ePrefabs.Add(p.propertyName, AddParam(p.propertyName, p.parameter, p.caption, p.tooltip)); } foreach (var p in action.parameters) @@ -133,57 +131,15 @@ namespace HeavenStudio.Editor private GameObject AddParam(string propertyName, object type, string caption, string tooltip = "") { - GameObject input; - - var objType = type.GetType(); - - if (objType == typeof(EntityTypes.Integer)) - { - input = InitPrefab(IntegerP, tooltip); - var property = input.GetComponent(); - property.SetProperties(propertyName, type, caption); - } - else if (objType == typeof(EntityTypes.Float)) - { - input = InitPrefab(FloatP, tooltip); - var property = input.GetComponent(); - property.SetProperties(propertyName, type, caption); - } - else if (objType == typeof(EntityTypes.Button)) - { - input = InitPrefab(ButtonP, tooltip); - var property = input.GetComponent(); - property.SetProperties(propertyName, type, caption); - } - else if (objType == typeof(bool)) - { - input = InitPrefab(BooleanP, tooltip); - var property = input.GetComponent(); - property.SetProperties(propertyName, type, caption); - } - else if (objType.IsEnum || objType == typeof(string[])) - { - input = InitPrefab(DropdownP, tooltip); - var property = input.GetComponent(); - property.SetProperties(propertyName, type, caption); - } - else if (objType == typeof(Color)) - { - input = InitPrefab(ColorP, tooltip); - var property = input.GetComponent(); - property.SetProperties(propertyName, type, caption); - } - else if (objType == typeof(string)) - { - input = InitPrefab(StringP, tooltip); - var property = input.GetComponent(); - property.SetProperties(propertyName, type, caption); - } - else - { + if (!PropertyPrefabs.TryGetValue(type.GetType(), out GameObject propertyPrefab)) { Debug.LogError("Can't make property interface of type: " + type.GetType()); return null; } + + GameObject input = InitPrefab(propertyPrefab, tooltip); + EventPropertyPrefab property = input.GetComponent(); + property.SetProperties(propertyName, type, caption); + return input; } diff --git a/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs index 9c83f3454..ecedad77f 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/EventPropertyPrefab.cs @@ -6,8 +6,6 @@ using System; using System.Linq; using TMPro; - -using HeavenStudio.Util; using Jukebox; namespace HeavenStudio.Editor @@ -20,10 +18,7 @@ namespace HeavenStudio.Editor public string propertyName; public List propertyCollapses = new List(); - public void SetProperties(string propertyName, object type, string caption) {} - public virtual void SetCollapses(object type) { } - - public void InitProperties(string propertyName, string caption) + public virtual void SetProperties(string propertyName, object type, string caption) { this.parameterManager = EventParameterManager.instance; this.propertyName = propertyName; @@ -32,6 +27,7 @@ namespace HeavenStudio.Editor this.caption.text = _captionText; } + public virtual void SetCollapses(object type) { } public void UpdateCollapse(object type) { diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs index d62435d42..d6636232a 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/BoolPropertyPrefab.cs @@ -6,10 +6,6 @@ using System; using System.Linq; using TMPro; - -using HeavenStudio.Util; -using HeavenStudio.Editor; - namespace HeavenStudio.Editor { public class BoolPropertyPrefab : EventPropertyPrefab @@ -20,9 +16,9 @@ namespace HeavenStudio.Editor private bool _defaultValue; - new public void SetProperties(string propertyName, object type, string caption) + public override void SetProperties(string propertyName, object type, string caption) { - InitProperties(propertyName, caption); + base.SetProperties(propertyName, type, caption); _defaultValue = (bool)type; toggle.isOn = Convert.ToBoolean(parameterManager.entity[propertyName]); diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ButtonPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ButtonPropertyPrefab.cs index 16fb22afc..fad873068 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ButtonPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ButtonPropertyPrefab.cs @@ -5,9 +5,7 @@ using UnityEngine.UI; using System; using System.Linq; using TMPro; - -using HeavenStudio.Util; -using HeavenStudio.Editor; +using Jukebox; namespace HeavenStudio.Editor { @@ -16,14 +14,18 @@ namespace HeavenStudio.Editor [Header("Boolean")] [Space(10)] // public Button buttonObj; + public TMP_Text buttonText; public EntityTypes.Button button; + public RiqEntity entity; - new public void SetProperties(string propertyName, object type, string caption) + public override void SetProperties(string propertyName, object type, string caption) { - InitProperties(propertyName, caption); + base.SetProperties(propertyName, type, caption); + entity = parameterManager.entity; if (type is EntityTypes.Button button) { this.button = button; + buttonText.text = button.defaultLabel; } else { Debug.LogError("ButtonPropertyPrefab was unable to use " + type.GetType() + " as a Button."); return; @@ -32,7 +34,10 @@ namespace HeavenStudio.Editor public void OnClick() { - button.onClick.Invoke(); + string text = button.onClick.Invoke(entity); + if (text != null) { + buttonText.text = text; + } } } } \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs index cc6a17625..c3eb6f6f2 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/ColorPropertyPrefab.cs @@ -6,10 +6,6 @@ using System; using System.Linq; using TMPro; - -using HeavenStudio.Util; -using HeavenStudio.Editor; - namespace HeavenStudio.Editor { public class ColorPropertyPrefab : EventPropertyPrefab @@ -24,9 +20,9 @@ namespace HeavenStudio.Editor private Color _defaultColor; - new public void SetProperties(string propertyName, object type, string caption) + public override void SetProperties(string propertyName, object type, string caption) { - InitProperties(propertyName, caption); + base.SetProperties(propertyName, type, caption); hex.onSelect.AddListener( _ => diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/DropdownPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/DropdownPropertyPrefab.cs index 87979a4fc..e445a89a5 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/DropdownPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/DropdownPropertyPrefab.cs @@ -6,8 +6,6 @@ using System; using System.Linq; using TMPro; -using HeavenStudio.Util; -using HeavenStudio.Editor; using HeavenStudio.Common; namespace HeavenStudio.Editor @@ -17,52 +15,46 @@ namespace HeavenStudio.Editor [Header("Dropdown")] [Space(10)] public LeftClickTMP_Dropdown dropdown; - private Array values; + // private string[] values; + private List names; + private List<(int, string)> values; private int _defaultValue; private bool openedDropdown = false; - new public void SetProperties(string propertyName, object type, string caption) + public override void SetProperties(string propertyName, object type, string caption) { - InitProperties(propertyName, caption); + base.SetProperties(propertyName, type, caption); - var enumType = type.GetType(); - values = Enum.GetValues(enumType); - var enumNames = Enum.GetNames(enumType).ToList(); - _defaultValue = (int)type; + // var enumType = type.GetType(); + // values = Enum.GetValues(enumType).Cast().ToArray(); + // names = Enum.GetNames(enumType).ToList(); + // _defaultValue = (int)type; // Can we assume non-holey enum? // If we can we can simplify to dropdown.value = (int) parameterManager.entity[propertyName] - var currentlySelected = (int) parameterManager.entity[propertyName]; - var selected = values - .Cast() - .ToList() - .FindIndex(val => (int) val == currentlySelected); + // var currentlySelected = (int) parameterManager.entity[propertyName]; + // var selected = values + // .Cast() + // .ToList() + // .FindIndex(val => (int) val == currentlySelected); - dropdown.AddOptions(enumNames); - dropdown.value = selected; + if (type is not EntityTypes.Dropdown dropdownEntity) return; - dropdown.onValueChanged.AddListener(_ => - { - parameterManager.entity[propertyName] = GetValue(); - if (GetValue() != _defaultValue) + names = dropdownEntity.values; + dropdown.AddOptions(names); + dropdown.value = (int)parameterManager.entity[propertyName]; + + dropdown.onValueChanged.AddListener(newValue => { - this.caption.text = _captionText + "*"; + parameterManager.entity[propertyName] = newValue; + Debug.Log("newValue : " + newValue); + this.caption.text = (newValue != _defaultValue) ? (_captionText + "*") : _captionText; } - else - { - this.caption.text = _captionText; - } - } ); } - public int GetValue() - { - return (int)values.GetValue(dropdown.value); - } - public void ResetValue() { dropdown.value = _defaultValue; @@ -70,8 +62,8 @@ namespace HeavenStudio.Editor public override void SetCollapses(object type) { - dropdown.onValueChanged.AddListener(_ => UpdateCollapse(GetValue())); - UpdateCollapse(GetValue()); + dropdown.onValueChanged.AddListener(_ => UpdateCollapse(type)); + UpdateCollapse(type); } private void Update() diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs index f7ae3f4e0..9846af080 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/NumberPropertyPrefab.cs @@ -6,11 +6,6 @@ using System; using System.Linq; using TMPro; - -using HeavenStudio.Util; -using HeavenStudio.Editor; -using static HeavenStudio.EntityTypes; - namespace HeavenStudio.Editor { public class NumberPropertyPrefab : EventPropertyPrefab @@ -22,9 +17,9 @@ namespace HeavenStudio.Editor private float _defaultValue; - new public void SetProperties(string propertyName, object type, string caption) + public override void SetProperties(string propertyName, object type, string caption) { - InitProperties(propertyName, caption); + base.SetProperties(propertyName, type, caption); switch (type) { @@ -141,19 +136,8 @@ namespace HeavenStudio.Editor switch (type) { case EntityTypes.Integer integer: - slider.onValueChanged.AddListener( - _ => - { - UpdateCollapse((int)slider.value); - } - ); - - inputField.onEndEdit.AddListener( - _ => - { - UpdateCollapse((int)slider.value); - } - ); + slider.onValueChanged.AddListener(_ => UpdateCollapse((int)slider.value)); + inputField.onEndEdit.AddListener(_ => UpdateCollapse((int)slider.value)); UpdateCollapse((int)slider.value); diff --git a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs index f05fcf465..85a741713 100644 --- a/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs +++ b/Assets/Scripts/LevelEditor/EventSelector/PropertyPrefabs/StringPropertyPrefab.cs @@ -21,9 +21,9 @@ namespace HeavenStudio.Editor private string _defaultValue; - new public void SetProperties(string propertyName, object type, string caption) + public override void SetProperties(string propertyName, object type, string caption) { - InitProperties(propertyName, caption); + base.SetProperties(propertyName, type, caption); _defaultValue = (string)type; diff --git a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs index 75e3a80a4..d7394bbdb 100644 --- a/Assets/Scripts/LevelEditor/Timeline/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline/Timeline.cs @@ -890,16 +890,19 @@ namespace HeavenStudio.Editor.Track { object returnVal = ep[i].parameter; - var propertyType = returnVal.GetType(); - if (propertyType == typeof(EntityTypes.Integer)) + if (returnVal is EntityTypes.Integer intVal) { - returnVal = ((EntityTypes.Integer)ep[i].parameter).val; + returnVal = intVal.val; } - else if (propertyType == typeof(EntityTypes.Float)) + else if (returnVal is EntityTypes.Float floatVal) { - returnVal = ((EntityTypes.Float)ep[i].parameter).val; + returnVal = floatVal.val; } - else if (propertyType.IsEnum) + else if (returnVal is EntityTypes.Dropdown dropdownVal) + { + returnVal = dropdownVal.defaultValue; + } + else if (returnVal.GetType().IsEnum) { returnVal = (int)ep[i].parameter; } diff --git a/Assets/Scripts/Minigames.cs b/Assets/Scripts/Minigames.cs index 52ebbf49b..e70520018 100644 --- a/Assets/Scripts/Minigames.cs +++ b/Assets/Scripts/Minigames.cs @@ -15,9 +15,8 @@ using Jukebox; using SatorImaging.UnitySourceGenerator; using System; -using System.Linq; -using System.Reflection; using System.IO; +using System.Linq; namespace HeavenStudio { @@ -673,7 +672,7 @@ namespace HeavenStudio { public string propertyName; public object parameter; - public string propertyCaption; + public string caption; public string tooltip; public List collapseParams; @@ -682,12 +681,15 @@ namespace HeavenStudio /// /// The name of the variable that's being changed. /// The value of the parameter - /// The name shown in the editor. Can be anything you want. - public Param(string propertyName, object parameter, string propertyCaption, string tooltip = "", List collapseParams = null) + /// The name shown in the editor. Can be anything you want. + public Param(string propertyName, object parameter, string caption, string tooltip = "", List collapseParams = null) { this.propertyName = propertyName; - this.parameter = parameter; - this.propertyCaption = propertyCaption; + this.parameter = parameter switch { + // Enum param => new EntityTypes.Dropdown(param), + _ => parameter, + }; + this.caption = caption; this.tooltip = tooltip; this.collapseParams = collapseParams; } @@ -835,7 +837,7 @@ namespace HeavenStudio new Minigame("vfx", "Visual Effects", "", false, true, new List() { - new GameAction("flash", "Flash", 1f, true, + new GameAction("flash", "Flash/Fade", 1f, true, new List() { new Param("colorA", Color.white, "Start Color", "Set the color at the start of the event."), @@ -1160,12 +1162,18 @@ namespace HeavenStudio new GameAction("play animation", "Play Animation", 0.5f, false, new List() { - new Param("getAnimators", new EntityTypes.Button("Get Animators", delegate { - string gameName = GameManager.instance.currentGame; - return gameName; - }), "Button", "Specify which animator in the scene to play an animation on. (i.e \"Plalin\" or \"Game/Paddlers/Player\")"), - new Param("animator", "", "Animator", "Specify which animator in the scene to play an animation on. (i.e \"Plalin\" or \"Game/Paddlers/Player\")"), - new Param("animation", "", "Animation", "Specify the name of the animation to play."), + new Param("getAnimators", new EntityTypes.Button("No Game", e => { + var gm = GameManager.instance; + Minigame game = gm.GetGameInfo(gm.currentGame); + if (game != null) { + gm.minigameAnimators = gm.minigameObj.transform.GetComponentsInChildren(); + e["animators"].values = gm.minigameAnimators.Select(x => x.name).ToList(); + e["animations"] = gm.minigameAnimators[0].runtimeAnimatorController.animationClips.Select(x => x.name).ToList(); + } + return game?.displayName ?? "No Game"; + }), "Button", "Get all the animators in the current minigame scene. (Make sure to have the minigame you want loaded!)"), + new Param("animators", new EntityTypes.Dropdown(0, "N/A"), "Animator", "Specify which animator in the scene to play an animation on. (i.e \"Plalin\" or \"Game/Paddlers/Player\")"), + new Param("animations", new EntityTypes.Dropdown(0, "N/A"), "Animation", "Specify the name of the animation to play."), new Param("scale", new EntityTypes.Float(0, 5, 0.5f), "Animation Scale", "The time scale of the animation. Higher values are faster."), }, delegate { @@ -1199,3 +1207,57 @@ namespace HeavenStudio } } } + +public class EnumProcessor +{ + private readonly Enum enumValue; + + public EnumProcessor(Enum value) + { + if (!value.GetType().IsEnum) + { + throw new ArgumentException("Value must be an enum type."); + } + + this.enumValue = value; + } + + public void ProcessEnumValue() + { + Type enumType = this.enumValue.GetType().DeclaringType; + + if (enumType != null) + { + Console.WriteLine("EnumType: " + enumType.Name); + } + + Console.WriteLine("EnumValue: " + this.enumValue); + } +} + +public class EnumExamples +{ + public enum EnumExample + { + EnumValue1, + EnumValue2 + } + + public enum EnumAnotherExample + { + DifferentValue1, + DifferentValue2 + } + + public static void Main() + { + EnumProcessor processor1 = new EnumProcessor(EnumExample.EnumValue1); + EnumProcessor processor2 = new EnumProcessor(EnumAnotherExample.DifferentValue1); + + // Call the method for EnumExample + processor1.ProcessEnumValue(); + + // Call the method for EnumAnotherExample + processor2.ProcessEnumValue(); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Util/EntityTypes.cs b/Assets/Scripts/Util/EntityTypes.cs index d1ffb7c63..830681d88 100644 --- a/Assets/Scripts/Util/EntityTypes.cs +++ b/Assets/Scripts/Util/EntityTypes.cs @@ -1,6 +1,8 @@ using System; using System.Collections; using System.Collections.Generic; +using System.Linq; +using Jukebox; using UnityEngine; namespace HeavenStudio @@ -27,7 +29,7 @@ namespace HeavenStudio public float val; public float max; - public Float(float min, float max, float val = 0f) + public Float(float min, float max, float val = 0) { this.min = min; this.val = val; @@ -35,18 +37,65 @@ namespace HeavenStudio } } + // this will eventually replace Float and Integer + public struct Number + { + public float snap; + public float min; + public float val; + public float max; + + public Number(float snap, float min, float max, float val = 0) + { + this.snap = snap; + this.min = min; + this.val = val; + this.max = max; + } + + public Number(float min, float max, float val = 0) + { + this.snap = 0.001f; + this.min = min; + this.val = val; + this.max = max; + } + } + public struct Button { - public string buttonLabel; - public Func onClick; + public string defaultLabel; + public Func onClick; - public Button(string buttonLabel, Func onClick) + public Button(string defaultLabel, Func onClick) { - this.buttonLabel = buttonLabel; + this.defaultLabel = defaultLabel; this.onClick = onClick; } } + public struct Dropdown + { + public int defaultValue; + public List values; + + // params List<> when 😢 + public Dropdown(int defaultValue, params string[] values) + { + this.defaultValue = defaultValue; + this.values = values.ToList(); + } + + public Dropdown(Enum value) + { + this.defaultValue = 0; + // Debug.Log(value); + // Debug.Log(value.GetType()); + // Debug.Log(value.GetType().DeclaringType); + this.values = Enum.GetNames(value.GetType()).ToList(); + } + } + public struct Resource { public enum ResourceType