Improved selection, just cleaner overall

This commit is contained in:
Braedon 2022-01-17 18:54:25 -05:00
parent 9dd141a6b2
commit f0f09e44b9
9 changed files with 271 additions and 193 deletions

View file

@ -0,0 +1,153 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: ce56e4dbb13e1644aa983b6dd170e4a7, type: 3}
m_Name: Newtonsoft.Json-for-Unity.Converters
m_EditorClassIdentifier:
useUnityContractResolver: 1
useAllOutsideConverters: 1
outsideConverters: []
useAllUnityConverters: 1
unityConverters:
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.AI.NavMesh.NavMeshQueryFilterConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.AI.NavMesh.NavMeshTriangulationConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Camera.CullingGroupEventConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Geometry.BoundsConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Geometry.BoundsIntConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Geometry.PlaneConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Geometry.RectConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Geometry.RectIntConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Geometry.RectOffsetConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Hashing.Hash128Converter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.Color32Converter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.ColorConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.Matrix4x4Converter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.QuaternionConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.SphericalHarmonicsL2Converter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.Vector2Converter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.Vector2IntConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.Vector3Converter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.Vector3IntConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Math.Vector4Converter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.NativeArray.NativeArrayConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Physics.JointDriveConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Physics.JointLimitsConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Physics.SoftJointLimitConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Physics2D.ColliderDistance2DConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Physics2D.ContactFilter2DConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Random.RandomStateConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Scripting.LayerMaskConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.UnityConverters.Scripting.RangeIntConverter
settings: []
useAllJsonNetConverters: 0
jsonNetConverters:
- enabled: 1
converterName: Newtonsoft.Json.Converters.StringEnumConverter
settings: []
- enabled: 1
converterName: Newtonsoft.Json.Converters.VersionConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.BinaryConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.BsonObjectIdConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.DataSetConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.DataTableConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.DiscriminatedUnionConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.EntityKeyMemberConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.ExpandoObjectConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.IsoDateTimeConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.JavaScriptDateTimeConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.KeyValuePairConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.RegexConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.UnixDateTimeConverter
settings: []
- enabled: 0
converterName: Newtonsoft.Json.Converters.XmlNodeConverter
settings: []

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c181e3a7c3288a34aa0136325914c33f
NativeFormatImporter:
externalObjects: {}
mainObjectFileID: 11400000
userData:
assetBundleName:
assetBundleVariant:

View file

@ -4184,6 +4184,9 @@ MonoBehaviour:
PosPreview: {fileID: 0}
PosPreviewRef: {fileID: 2142375787}
Icon: {fileID: 820032006}
selectedImage: {fileID: 2127582758}
outline: {fileID: 1231936949}
resizeGraphic: {fileID: 880758902}
length: 0
selected: 0
mouseHovering: 0
@ -4212,6 +4215,22 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Delegates:
- eventID: 4
callback:
m_PersistentCalls:
m_Calls:
- m_Target: {fileID: 798021450}
m_TargetAssemblyTypeName: RhythmHeavenMania.Editor.TimelineEventObj, Assembly-CSharp
m_MethodName: OnClick
m_Mode: 1
m_Arguments:
m_ObjectArgument: {fileID: 0}
m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine
m_IntArgument: 0
m_FloatArgument: 0
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- eventID: 2
callback:
m_PersistentCalls:
m_Calls:
@ -4413,7 +4432,7 @@ RectTransform:
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_SizeDelta: {x: -0.08, y: -1.2399993}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!1 &903653564
GameObject:
@ -6930,7 +6949,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
@ -7648,7 +7667,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
@ -9359,7 +9378,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
@ -9509,7 +9528,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:

View file

@ -35,8 +35,11 @@ namespace RhythmHeavenMania.Editor
private void Update()
{
if (Selections.instance.eventsSelected.Count > 0 && Timeline.instance.IsEventsDragging())
if (Selections.instance.eventsSelected.Count > 0 && Timeline.instance.InteractingWithEvents())
{
startPosition = Vector2.zero;
endPosition = Vector2.zero;
DrawVisual();
return;
}
@ -45,7 +48,6 @@ namespace RhythmHeavenMania.Editor
startPosition = Vector2.zero;
endPosition = Vector2.zero;
DrawVisual();
SelectEvents();
return;
}
@ -126,10 +128,12 @@ namespace RhythmHeavenMania.Editor
{
int selected = 0;
if (!Input.GetKeyDown(KeyCode.LeftShift)) Selections.instance.DeselectAll();
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
{
TimelineEventObj e = GameManager.instance.Beatmap.entities[i].eventObj;
if (selectionBox.Overlaps(GetWorldRect(e.GetComponent<RectTransform>())))
{
Selections.instance.DragSelect(e);

View file

@ -30,7 +30,6 @@ namespace RhythmHeavenMania.Editor
{
DeselectAll();
eventsSelected.Add(eventToAdd);
eventToAdd.Select();
}
public void ShiftClickSelect(TimelineEventObj eventToAdd)
@ -38,13 +37,11 @@ namespace RhythmHeavenMania.Editor
if (!eventsSelected.Contains(eventToAdd))
{
eventsSelected.Add(eventToAdd);
eventToAdd.Select();
}
/*else
else
{
eventsSelected.Remove(eventToAdd);
eventToAdd.DeSelect();
}*/
}
}
public void DragSelect(TimelineEventObj eventToAdd)
@ -52,17 +49,11 @@ namespace RhythmHeavenMania.Editor
if (!eventsSelected.Contains(eventToAdd))
{
eventsSelected.Add(eventToAdd);
eventToAdd.Select();
}
}
public void DeselectAll()
{
for (int i = 0; i < eventsSelected.Count; i++)
{
eventsSelected[i].DeSelect();
}
eventsSelected.Clear();
}
@ -71,7 +62,6 @@ namespace RhythmHeavenMania.Editor
if (eventsSelected.Contains(eventToDeselect))
{
eventsSelected.Remove(eventToDeselect);
eventToDeselect.DeSelect();
}
}
}

View file

@ -14,5 +14,10 @@ namespace RhythmHeavenMania.Editor
{
instance = this;
}
private void Update()
{
}
}
}

View file

@ -337,7 +337,6 @@ namespace RhythmHeavenMania.Editor
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
g.transform.position = new Vector3(mousePos.x, mousePos.y, 0);
Beatmap.Entity en = new Beatmap.Entity();
en.datamodel = eventName;
en.eventObj = eventObj;
@ -346,7 +345,7 @@ namespace RhythmHeavenMania.Editor
GameManager.instance.SortEventsList();
Selections.instance.ClickSelect(eventObj);
eventObj.isDragging = true;
eventObj.moving = true;
}
else
{
@ -374,9 +373,9 @@ namespace RhythmHeavenMania.Editor
return Timeline.instance.eventObjs.FindAll(c => c.mouseHovering == true).Count > 0;
}
public bool IsEventsDragging()
public bool InteractingWithEvents()
{
return eventObjs.FindAll(c => c.isDragging == true).Count > 0 || eventObjs.FindAll(c => c.resizing == true).Count > 0;
return eventObjs.FindAll(c => c.moving == true).Count > 0 || eventObjs.FindAll(c => c.resizing == true).Count > 0;
}
public float SnapToLayer(float y)

View file

@ -12,7 +12,6 @@ namespace RhythmHeavenMania.Editor
{
private float startPosX;
private float startPosY;
public bool isDragging;
private Vector3 lastPos;
private RectTransform rectTransform;
@ -21,6 +20,9 @@ namespace RhythmHeavenMania.Editor
[SerializeField] private RectTransform PosPreview;
[SerializeField] private RectTransform PosPreviewRef;
[SerializeField] public Image Icon;
[SerializeField] private Image selectedImage;
[SerializeField] private RectTransform outline;
[SerializeField] private RectTransform resizeGraphic;
[Header("Properties")]
private Beatmap.Entity entity;
@ -31,6 +33,7 @@ namespace RhythmHeavenMania.Editor
public bool mouseHovering;
public bool resizable;
public bool resizing;
public bool moving;
[Header("Colors")]
public Color NormalCol;
@ -41,14 +44,13 @@ namespace RhythmHeavenMania.Editor
if (!resizable)
{
Destroy(transform.GetChild(6).gameObject);
Destroy(transform.GetChild(7).gameObject);
Destroy(transform.GetChild(1).gameObject);
Destroy(resizeGraphic.gameObject);
}
}
private void Update()
{
selected = Selections.instance.eventsSelected.Contains(this);
entity = GameManager.instance.Beatmap.entities.Find(a => a.eventObj == this);
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition, Camera.main);
@ -72,6 +74,12 @@ namespace RhythmHeavenMania.Editor
SetColor(GetTrack());
if (Conductor.instance.NotStopped())
{
Cancel();
return;
}
if (selected)
{
if (Input.GetKeyDown(KeyCode.Delete))
@ -80,61 +88,25 @@ namespace RhythmHeavenMania.Editor
Timeline.instance.DestroyEventObject(entity);
}
transform.GetChild(3).gameObject.SetActive(true);
for (int i = 0; i < transform.GetChild(4).childCount; i++)
selectedImage.gameObject.SetActive(true);
for (int i = 0; i < outline.childCount; i++)
{
transform.GetChild(4).GetChild(i).GetComponent<Image>().color = Color.cyan;
}
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector3[] v = new Vector3[4];
rectTransform.GetWorldCorners(v);
if (mouseHovering)
{
if (mousePos.x > transform.position.x && mousePos.x < transform.position.x + 0.1f)
{
}
else if (mousePos.x > v[3].x - 0.1f && mousePos.x < v[3].x)
{
}
outline.GetChild(i).GetComponent<Image>().color = Color.cyan;
}
}
else
{
transform.GetChild(3).gameObject.SetActive(false);
selectedImage.gameObject.SetActive(false);
for (int i = 0; i < transform.GetChild(4).childCount; i++)
transform.GetChild(4).GetChild(i).GetComponent<Image>().color = new Color32(0, 0, 0, 51);
}
if (Conductor.instance.NotStopped())
{
Cancel();
return;
for (int i = 0; i < outline.childCount; i++)
outline.GetChild(i).GetComponent<Image>().color = new Color32(0, 0, 0, 51);
}
if (!resizing)
{
if (Input.GetMouseButtonDown(0) && Timeline.instance.IsMouseAboveEvents())
if (Input.GetMouseButtonUp(0) && Timeline.instance.CheckIfMouseInTimeline())
{
if (selected)
{
Vector3 mousePos;
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
startPosX = mousePos.x - this.transform.position.x;
startPosY = mousePos.y - this.transform.position.y;
isDragging = true;
}
}
else if (Input.GetMouseButtonUp(0))
{
if (!mouseHovering && !isDragging && !BoxSelection.instance.selecting)
if (!mouseHovering && !moving && !BoxSelection.instance.selecting)
{
if (!Input.GetKey(KeyCode.LeftShift))
{
@ -144,11 +116,9 @@ namespace RhythmHeavenMania.Editor
OnUp();
}
if (isDragging && selected)
if (moving && selected)
{
Vector3 mousePos;
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
this.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
this.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(this.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(this.transform.localPosition.y));
@ -162,6 +132,53 @@ namespace RhythmHeavenMania.Editor
}
#region ClickEvents
public void OnClick()
{
if (Input.GetKey(KeyCode.LeftShift))
{
Selections.instance.ShiftClickSelect(this);
}
else
{
Selections.instance.ClickSelect(this);
}
}
public void OnDown()
{
if (!selected) return;
Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
startPosX = mousePos.x - this.transform.position.x;
startPosY = mousePos.y - this.transform.position.y;
moving = true;
}
public void OnUp()
{
if (selected)
{
moving = false;
if (eligibleToMove)
{
OnComplete();
}
Cancel();
}
}
private void Cancel()
{
eligibleToMove = false;
}
#endregion
#region ResizeEvents
public void DragEnter()
@ -211,7 +228,6 @@ namespace RhythmHeavenMania.Editor
public void DragRight()
{
if (!resizing) return;
// if (!mouseHovering) return;
Vector2 sizeDelta = rectTransform.sizeDelta;
@ -268,59 +284,8 @@ namespace RhythmHeavenMania.Editor
#endregion
#region ClickEvents
public void OnDown()
{
if (!selected)
{
if (Input.GetKey(KeyCode.LeftShift))
{
Selections.instance.ShiftClickSelect(this);
}
else
{
Selections.instance.ClickSelect(this);
}
// Selector.instance.Click(this);
}
}
public void OnUp()
{
if (selected)
{
isDragging = false;
if (eligibleToMove)
{
OnComplete();
}
Cancel();
}
}
private void Cancel()
{
eligibleToMove = false;
}
#endregion
#region Selection
public void Select()
{
selected = true;
}
public void DeSelect()
{
selected = false;
}
#endregion
#region Extra

View file

@ -1,66 +1 @@
{
"bpm": 128,
"entities": [
{
"beat": 14,
"length": 128,
"datamodel": "karateman/bop"
},
{
"beat": 16,
"datamodel": "karateman/kick"
},
{
"beat": 20,
"datamodel": "karateman/pot"
},
{
"beat": 22,
"datamodel": "karateman/pot"
},
{
"beat": 24,
"datamodel": "karateman/pot"
},
{
"beat": 26,
"datamodel": "karateman/pot"
},
{
"beat": 28,
"datamodel": "karateman/pot"
},
{
"beat": 30,
"datamodel": "karateman/bulb"
},
{
"beat": 32,
"datamodel": "karateman/kick"
},
{
"beat": 34,
"datamodel": "karateman/pot"
},
{
"beat": 36,
"datamodel": "karateman/pot"
},
{
"beat": 38,
"datamodel": "karateman/pot"
},
{
"beat": 40,
"datamodel": "karateman/pot"
},
{
"beat": 42,
"datamodel": "karateman/bulb"
},
{
"beat": 44,
"datamodel": "karateman/kick"
}
]
}
{"bpm":128.0,"entities":[{"beat":14.0,"track":3,"length":128.0,"datamodel":"karateman/bop"},{"beat":16.0,"track":1,"datamodel":"karateman/kick"},{"beat":20.0,"track":1,"datamodel":"karateman/pot"},{"beat":22.0,"track":2,"datamodel":"karateman/pot"},{"beat":24.0,"track":2,"datamodel":"karateman/pot"},{"beat":26.0,"track":1,"datamodel":"karateman/pot"},{"beat":28.0,"track":1,"datamodel":"karateman/pot"},{"beat":30.0,"track":3,"datamodel":"karateman/bulb"},{"beat":32.0,"track":0,"datamodel":"karateman/kick"},{"beat":34.0,"track":0,"datamodel":"karateman/pot"},{"beat":36.0,"track":0,"datamodel":"karateman/pot"},{"beat":38.0,"track":3,"datamodel":"karateman/pot"},{"beat":40.0,"track":2,"datamodel":"karateman/pot"},{"beat":42.0,"track":1,"datamodel":"karateman/bulb"},{"beat":44.0,"track":3,"datamodel":"karateman/kick"},{"beat":48.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":50.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":52.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":54.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":56.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":58.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":60.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":62.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":64.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":66.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":68.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":70.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":72.0,"track":2,"length":2.0,"datamodel":"karateman/pot"},{"beat":74.0,"track":1,"length":2.0,"datamodel":"karateman/bulb"},{"beat":76.0,"track":2,"length":4.5,"datamodel":"karateman/kick"},{"beat":80.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":82.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":84.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":86.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":88.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":90.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":92.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":94.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":96.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":98.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":100.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":102.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":104.0,"track":1,"length":2.0,"datamodel":"karateman/pot"},{"beat":106.0,"track":1,"length":2.0,"datamodel":"karateman/bulb"},{"beat":108.0,"track":1,"length":4.5,"datamodel":"karateman/kick"},{"beat":112.0,"track":2,"length":2.0,"datamodel":"karateman/pot"}]}