From 81ee9a8eca9d8d65e0238be8bf44c5b4998cca11 Mon Sep 17 00:00:00 2001 From: Braedon Date: Tue, 11 Jan 2022 22:29:27 -0500 Subject: [PATCH] Event colors --- Assets/Scenes/Editor.unity | 30 ++++++++--- Assets/Scripts/LevelEditor/Editor.cs | 2 + .../Scripts/LevelEditor/GridGameSelector.cs | 5 +- Assets/Scripts/LevelEditor/Timeline.cs | 26 ++++++++++ .../Scripts/LevelEditor/TimelineEventObj.cs | 52 ++++++++++++++++++- 5 files changed, 107 insertions(+), 8 deletions(-) diff --git a/Assets/Scenes/Editor.unity b/Assets/Scenes/Editor.unity index c8d3ae1d..227ead0a 100644 --- a/Assets/Scenes/Editor.unity +++ b/Assets/Scenes/Editor.unity @@ -1223,6 +1223,7 @@ GameObject: m_Component: - component: {fileID: 547319783} - component: {fileID: 547319786} + - component: {fileID: 547319784} m_Layer: 5 m_Name: Viewport m_TagString: Untagged @@ -1250,6 +1251,20 @@ RectTransform: m_AnchoredPosition: {x: 0, y: 0} m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0, y: 1} +--- !u!114 &547319784 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 547319782} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 3312d7739989d2b4e91e6319e9a96d76, type: 3} + m_Name: + m_EditorClassIdentifier: + m_Padding: {x: 0, y: 0, z: 0, w: 0} + m_Softness: {x: 0, y: 0} --- !u!222 &547319786 CanvasRenderer: m_ObjectHideFlags: 0 @@ -1257,7 +1272,7 @@ CanvasRenderer: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 547319782} - m_CullTransparentMesh: 1 + m_CullTransparentMesh: 0 --- !u!1 &555373788 GameObject: m_ObjectHideFlags: 0 @@ -1789,7 +1804,7 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.6, g: 0.6, b: 0.7490196, a: 1} + m_Color: {r: 0.84705883, g: 0.84705883, b: 1, a: 1} m_RaycastTarget: 1 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 @@ -2332,6 +2347,9 @@ MonoBehaviour: PosPreviewRef: {fileID: 2142375787} Icon: {fileID: 820032006} length: 0 + NormalCol: {r: 0.8470589, g: 0.8470589, b: 1, a: 1} + SelectedCol: {r: 0.8470589, g: 1, b: 1, a: 1} + DeleteCol: {r: 0.89019614, g: 0.7254902, b: 0.7254902, a: 1} --- !u!222 &798021451 CanvasRenderer: m_ObjectHideFlags: 0 @@ -4719,7 +4737,7 @@ RectTransform: m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} m_AnchoredPosition: {x: 0, y: 0} - m_SizeDelta: {x: -0.060000002, y: -6} + m_SizeDelta: {x: 0, y: 0} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1921041736 MonoBehaviour: @@ -4734,14 +4752,14 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: m_Material: {fileID: 0} - m_Color: {r: 0.8470589, g: 0.8470589, b: 1, a: 1} - m_RaycastTarget: 1 + m_Color: {r: 0, g: 0, b: 0, a: 0.2} + m_RaycastTarget: 0 m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0} m_Maskable: 1 m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Sprite: {fileID: 0} + m_Sprite: {fileID: 21300000, guid: f9232c079e126cd48a7344b23eaf42a5, type: 3} m_Type: 1 m_PreserveAspect: 0 m_FillCenter: 1 diff --git a/Assets/Scripts/LevelEditor/Editor.cs b/Assets/Scripts/LevelEditor/Editor.cs index 3ed56ca8..aa341dee 100644 --- a/Assets/Scripts/LevelEditor/Editor.cs +++ b/Assets/Scripts/LevelEditor/Editor.cs @@ -21,6 +21,8 @@ namespace RhythmHeavenMania.Editor [Header("Components")] [SerializeField] private Timeline Timeline; + public static List EventObjs = new List(); + public static Editor instance { get; private set; } private void Start() diff --git a/Assets/Scripts/LevelEditor/GridGameSelector.cs b/Assets/Scripts/LevelEditor/GridGameSelector.cs index 8f7bf280..0706f0ce 100644 --- a/Assets/Scripts/LevelEditor/GridGameSelector.cs +++ b/Assets/Scripts/LevelEditor/GridGameSelector.cs @@ -112,7 +112,10 @@ namespace RhythmHeavenMania.Editor private void SetColor(int ind) { - for (int i = 0; i < EventRef.transform.parent.childCount; i++) EventRef.transform.parent.GetChild(i).GetComponent().color = Color.white; + for (int i = 0; i < EventRef.transform.parent.childCount; i++) + { + EventRef.transform.parent.GetChild(i).GetComponent().color = Color.white; + } EventRef.transform.parent.GetChild(ind + 1).GetComponent().color = Color.cyan; } diff --git a/Assets/Scripts/LevelEditor/Timeline.cs b/Assets/Scripts/LevelEditor/Timeline.cs index f37bcd22..1f3a6ff8 100644 --- a/Assets/Scripts/LevelEditor/Timeline.cs +++ b/Assets/Scripts/LevelEditor/Timeline.cs @@ -223,10 +223,36 @@ namespace RhythmHeavenMania.Editor { eventObj.OnDown(); } + + Editor.EventObjs.Add(eventObj); + // entity.eventObj = g.GetComponent(); // entity.track = (int)(g.transform.localPosition.y / 51.34f * -1); } + public void DestroyEventObject(TimelineEventObj eventObj) + { + var e = GameManager.instance.Beatmap.entities.Find(c => c.eventObj == eventObj); + GameManager.instance.Beatmap.entities.Remove(e); + GameManager.instance.SortEventsList(); + Destroy(eventObj.gameObject); + + Editor.EventObjs.Remove(eventObj); + } + + #endregion + + #region Commands + + public void Move() + { + } + + public void Undo() + { + + } + #endregion } } \ No newline at end of file diff --git a/Assets/Scripts/LevelEditor/TimelineEventObj.cs b/Assets/Scripts/LevelEditor/TimelineEventObj.cs index dce6452d..b98c8fef 100644 --- a/Assets/Scripts/LevelEditor/TimelineEventObj.cs +++ b/Assets/Scripts/LevelEditor/TimelineEventObj.cs @@ -25,9 +25,31 @@ namespace RhythmHeavenMania.Editor private int enemyIndex; public float length; private bool eligibleToMove = false; + private bool lastVisible; + + [Header("Colors")] + public Color NormalCol; + public Color SelectedCol; + public Color DeleteCol; private void Update() { + // Optimizations + + bool visible = GetComponent().IsVisibleFrom(Camera.main); + + if (visible != lastVisible) + { + for (int i = 0; i < this.transform.childCount; i++) + { + this.transform.GetChild(i).gameObject.SetActive(visible); + } + } + + lastVisible = visible; + + // ------------- + if (Conductor.instance.NotStopped()) { Cancel(); @@ -43,16 +65,25 @@ namespace RhythmHeavenMania.Editor mousePos = Camera.main.ScreenToWorldPoint(mousePos); this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0); - this.transform.localPosition = new Vector3(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), Mathp.Round2Nearest(this.transform.localPosition.y, 51.34f)); + this.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.y, 51.34f), -51.34f * 3, 0)); if (lastPos != transform.localPosition) OnMove(); lastPos = this.transform.localPosition; + + SetColor(1); + } + else + { + SetColor(0); } if (Input.GetMouseButtonUp(0)) OnUp(); + + if (Input.GetKeyDown(KeyCode.Delete)) + Timeline.instance.DestroyEventObject(this); } private void OnMove() @@ -110,5 +141,24 @@ namespace RhythmHeavenMania.Editor if (eligibleToMove) OnComplete(); Cancel(); } + + public void SetColor(int type) + { + Color c = Color.white; + switch (type) + { + case 0: + c = NormalCol; + break; + case 1: + c = SelectedCol; + break; + case 2: + c = DeleteCol; + break; + } + + transform.GetChild(0).GetComponent().color = c; + } } } \ No newline at end of file