bare bones selection system

This commit is contained in:
Braedon 2022-01-12 22:59:54 -05:00
parent 81ee9a8eca
commit 99832cfc23
11 changed files with 678 additions and 355 deletions

View file

@ -50,4 +50,13 @@ public static class RendererExtensions
{
return CountCornersVisibleFrom(rectTransform, camera) > 0; // True if any corners are visible
}
public static bool MouseIsWithin(this RectTransform rectTransform)
{
var normalizedMousePosition = new Vector2(Input.mousePosition.x / Screen.width, Input.mousePosition.y / Screen.height);
return normalizedMousePosition.x > rectTransform.anchorMin.x &&
normalizedMousePosition.x < rectTransform.anchorMax.x &&
normalizedMousePosition.y > rectTransform.anchorMin.y &&
normalizedMousePosition.y < rectTransform.anchorMax.y;
}
}

View file

@ -548,7 +548,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.0472, y: 0.000017166138}
m_AnchoredPosition: {x: -0.047200024, y: 0.000017166138}
m_SizeDelta: {x: 46.9911, y: 44.84}
m_Pivot: {x: 1, y: 0.5}
--- !u!114 &258006093
@ -803,6 +803,81 @@ MonoBehaviour:
m_ChildScaleWidth: 0
m_ChildScaleHeight: 1
m_ReverseArrangement: 0
--- !u!1 &411779173
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 411779174}
- component: {fileID: 411779176}
- component: {fileID: 411779175}
m_Layer: 5
m_Name: BoxSelectGraphic
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &411779174
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 411779173}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1556269007}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 100, y: 100}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &411779175
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 411779173}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0, g: 0.83003163, b: 1, a: 0.15686275}
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_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &411779176
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 411779173}
m_CullTransparentMesh: 1
--- !u!1 &424396916
GameObject:
m_ObjectHideFlags: 0
@ -990,11 +1065,11 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Content: {fileID: 1852819573}
m_Horizontal: 1
m_Vertical: 1
m_Horizontal: 0
m_Vertical: 0
m_MovementType: 2
m_Elasticity: 0.1
m_Inertia: 1
m_Inertia: 0
m_DecelerationRate: 0.01
m_ScrollSensitivity: 1
m_Viewport: {fileID: 547319783}
@ -1021,7 +1096,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.09019608, g: 0.09019608, b: 0.09019608, a: 1}
m_RaycastTarget: 1
m_RaycastTarget: 0
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
@ -1864,7 +1939,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -0, y: -54.22}
m_AnchoredPosition: {x: 0, y: -54.22}
m_SizeDelta: {x: 0, y: 30}
m_Pivot: {x: 0, y: 1}
--- !u!114 &689207021
@ -2347,6 +2422,8 @@ MonoBehaviour:
PosPreviewRef: {fileID: 2142375787}
Icon: {fileID: 820032006}
length: 0
selected: 0
mouseHovering: 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}
@ -2371,7 +2448,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
m_Delegates:
- eventID: 2
- eventID: 4
callback:
m_PersistentCalls:
m_Calls:
@ -2496,7 +2573,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: -90}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 24.85, y: -42.51}
m_AnchoredPosition: {x: 24.850006, y: -42.509995}
m_SizeDelta: {x: 15, y: 15}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &841081097
@ -3680,6 +3757,9 @@ GameObject:
- component: {fileID: 1423699436}
- component: {fileID: 1423699438}
- component: {fileID: 1423699437}
- component: {fileID: 1423699439}
- component: {fileID: 1423699440}
- component: {fileID: 1423699441}
m_Layer: 0
m_Name: Editor
m_TagString: Untagged
@ -3736,6 +3816,45 @@ MonoBehaviour:
debugUI: 0
playOnStart: 0
editor: 1
--- !u!114 &1423699439
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1423699435}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e2b2a61b5fc830d4e906f0f059365bac, type: 3}
m_Name:
m_EditorClassIdentifier:
eventsSelected: []
--- !u!114 &1423699440
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1423699435}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: b47ca28d69cd18e429a3548426c65351, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!114 &1423699441
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1423699435}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4cad4c81175643243b3e0c481b8acfb6, type: 3}
m_Name:
m_EditorClassIdentifier:
boxVisual: {fileID: 411779174}
selecting: 0
--- !u!1 &1527251879
GameObject:
m_ObjectHideFlags: 0
@ -3771,7 +3890,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: -0, y: -25.613}
m_AnchoredPosition: {x: 0, y: -25.613007}
m_SizeDelta: {x: 1440, y: 237.341}
m_Pivot: {x: 0, y: 0.5}
--- !u!114 &1527251881
@ -3884,6 +4003,106 @@ MonoBehaviour:
m_EditorClassIdentifier:
snap: 1
count: 0
--- !u!1 &1556269003
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1556269007}
- component: {fileID: 1556269006}
- component: {fileID: 1556269005}
- component: {fileID: 1556269004}
m_Layer: 5
m_Name: BoxSelectionCanvas
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1556269004
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1556269003}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: dc42784cf147c0c48a680349fa168899, type: 3}
m_Name:
m_EditorClassIdentifier:
m_IgnoreReversedGraphics: 1
m_BlockingObjects: 0
m_BlockingMask:
serializedVersion: 2
m_Bits: 4294967295
--- !u!114 &1556269005
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1556269003}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 0cd44c1031e13a943bb63640046fad76, type: 3}
m_Name:
m_EditorClassIdentifier:
m_UiScaleMode: 0
m_ReferencePixelsPerUnit: 100
m_ScaleFactor: 1
m_ReferenceResolution: {x: 800, y: 600}
m_ScreenMatchMode: 0
m_MatchWidthOrHeight: 0
m_PhysicalUnit: 3
m_FallbackScreenDPI: 96
m_DefaultSpriteDPI: 96
m_DynamicPixelsPerUnit: 1
m_PresetInfoIsWorld: 0
--- !u!223 &1556269006
Canvas:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1556269003}
m_Enabled: 1
serializedVersion: 3
m_RenderMode: 0
m_Camera: {fileID: 2047408675}
m_PlaneDistance: 100
m_PixelPerfect: 0
m_ReceivesEvents: 1
m_OverrideSorting: 0
m_OverridePixelPerfect: 0
m_SortingBucketNormalizedSize: 0
m_AdditionalShaderChannelsFlag: 0
m_SortingLayerID: 0
m_SortingOrder: 10
m_TargetDisplay: 0
--- !u!224 &1556269007
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1556269003}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0, y: 0, z: 0}
m_Children:
- {fileID: 411779174}
m_Father: {fileID: 0}
m_RootOrder: 4
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0, y: 0}
--- !u!1 &1567318395
GameObject:
m_ObjectHideFlags: 0
@ -3918,7 +4137,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: -13.502}
m_AnchoredPosition: {x: 0, y: -13.501999}
m_SizeDelta: {x: -10, y: -37.005}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1567318397
@ -4277,7 +4496,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: -0, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 3}
m_Pivot: {x: 0, y: 0}
--- !u!114 &1671868847
@ -4443,7 +4662,7 @@ RectTransform:
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0.5}
m_AnchorMax: {x: 0, y: 0.5}
m_AnchoredPosition: {x: -0, y: -25.613}
m_AnchoredPosition: {x: 0, y: -25.613007}
m_SizeDelta: {x: 32, y: 237.341}
m_Pivot: {x: 0, y: 0.5}
--- !u!114 &1747224097
@ -4697,6 +4916,7 @@ MonoBehaviour:
m_EditorClassIdentifier:
SongBeat: {fileID: 932211468}
SongPos: {fileID: 1567318397}
eventObjs: []
TimelineSlider: {fileID: 770589360}
TimelinePlaybackBeat: {fileID: 117889364}
TimelineContent: {fileID: 1852819573}

View file

@ -0,0 +1,144 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Editor
{
public class BoxSelection : MonoBehaviour
{
[SerializeField] private RectTransform boxVisual;
private Rect selectionBox;
private Vector2 startPosition = Vector2.zero;
private Vector2 endPosition = Vector2.zero;
public bool selecting = false;
public static BoxSelection instance { get; private set; }
private void Awake()
{
instance = this;
}
private void Start()
{
DrawVisual();
}
private void Update()
{
if (Selections.instance.eventsSelected.Count > 0 && Timeline.instance.IsEventsDragging())
{
return;
}
// click
if (Input.GetMouseButtonDown(0))
{
startPosition = Input.mousePosition;
selectionBox = new Rect();
}
// dragging
if (Input.GetMouseButton(0))
{
endPosition = Input.mousePosition;
DrawVisual();
DrawSelection();
}
// release click
if (Input.GetMouseButtonUp(0))
{
startPosition = Vector2.zero;
endPosition = Vector2.zero;
DrawVisual();
SelectEvents();
}
// selecting = (selectionBox.size != Vector2.zero); -- doesn't work really
// for real time selection just move SelectEvents() to here, but that breaks some shit. might fix soon idk --pelly
}
private void DrawVisual()
{
Vector2 boxStart = startPosition;
Vector2 boxEnd = endPosition;
Vector2 boxCenter = (boxStart + boxEnd) / 2;
boxVisual.position = boxCenter;
Vector2 boxSize = new Vector2(Mathf.Abs(boxStart.x - boxEnd.x), Mathf.Abs(boxStart.y - boxEnd.y));
boxVisual.sizeDelta = boxSize;
}
private void DrawSelection()
{
// X
if (Input.mousePosition.x < startPosition.x)
{
// dragging left
selectionBox.xMin = Input.mousePosition.x;
selectionBox.xMax = startPosition.x;
}
else
{
// dragging right
selectionBox.xMin = startPosition.x;
selectionBox.xMax = Input.mousePosition.x;
}
// Y
if (Input.mousePosition.y < startPosition.y)
{
// dragging down
selectionBox.yMin = Input.mousePosition.y;
selectionBox.yMax = startPosition.y;
}
else
{
// dragging up
selectionBox.yMin = startPosition.y;
selectionBox.yMax = Input.mousePosition.y;
}
}
private void SelectEvents()
{
int selected = 0;
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
{
TimelineEventObj e = GameManager.instance.Beatmap.entities[i].eventObj;
if (selectionBox.Contains(Camera.main.WorldToScreenPoint(e.transform.position)))
{
print(RectTransformToScreenSpace(e.GetComponent<RectTransform>()));
Selections.instance.DragSelect(e);
selected++;
}
// I'm trying this fix this dammit
/*if (selectionBox.Overlaps(RectTransformToScreenSpace(e.GetComponent<RectTransform>())))
{
print(RectTransformToScreenSpace(e.GetComponent<RectTransform>()));
print(selectionBox);
Selections.instance.DragSelect(e);
selected++;
}*/
}
selecting = selected > 0;
}
public Rect RectTransformToScreenSpace(RectTransform transform)
{
Vector2 sizeTemp = Vector2.Scale(transform.rect.size, transform.localScale);
Vector2 size = new Vector2(sizeTemp.x * 100, sizeTemp.y);
return new Rect((Vector2)Camera.main.WorldToScreenPoint(transform.position) - (size * 0.5f), size);
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4cad4c81175643243b3e0c481b8acfb6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,67 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Editor
{
public class Selections : MonoBehaviour
{
public List<TimelineEventObj> eventsSelected = new List<TimelineEventObj>();
public static Selections instance { get; private set; }
private void Awake()
{
instance = this;
}
public void ClickSelect(TimelineEventObj eventToAdd)
{
DeselectAll();
eventsSelected.Add(eventToAdd);
eventToAdd.Select();
}
public void ShiftClickSelect(TimelineEventObj eventToAdd)
{
if (!eventsSelected.Contains(eventToAdd))
{
eventsSelected.Add(eventToAdd);
eventToAdd.Select();
}
/*else
{
eventsSelected.Remove(eventToAdd);
eventToAdd.DeSelect();
}*/
}
public void DragSelect(TimelineEventObj eventToAdd)
{
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();
}
public void Deselect(TimelineEventObj eventToDeselect)
{
if (eventsSelected.Contains(eventToDeselect))
{
eventsSelected.Remove(eventToDeselect);
eventToDeselect.DeSelect();
}
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: e2b2a61b5fc830d4e906f0f059365bac
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -0,0 +1,52 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Editor
{
public class Selector : MonoBehaviour
{
private bool clicked;
public static Selector instance { get; private set; }
private void Awake()
{
instance = this;
}
private void LateUpdate()
{
/*if (Input.GetMouseButtonUp(0))
{
if (!Timeline.instance.IsDraggingEvent())
{
if (clicked == false)
{
if (!Input.GetKey(KeyCode.LeftShift))
{
print('a');
Selections.instance.DeselectAll();
}
}
}
}
clicked = false;*/
}
public void Click(TimelineEventObj eventObj)
{
/*if (Input.GetKey(KeyCode.LeftShift))
{
Selections.instance.ShiftClickSelect(eventObj);
}
else
{
Selections.instance.ClickSelect(eventObj);
}
clicked = true;*/
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: b47ca28d69cd18e429a3548426c65351
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -17,6 +17,8 @@ namespace RhythmHeavenMania.Editor
[Header("Timeline Properties")]
private float lastBeatPos = 0;
private Vector2 lastMousePos;
public List<TimelineEventObj> eventObjs = new List<TimelineEventObj>();
private bool lastFrameDrag;
[Header("Timeline Components")]
[SerializeField] private RectTransform TimelineSlider;
@ -36,7 +38,7 @@ namespace RhythmHeavenMania.Editor
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
{
var entity = GameManager.instance.Beatmap.entities[i];
/*var entity = GameManager.instance.Beatmap.entities[i];
var e = GameManager.instance.Beatmap.entities[i];
EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(e.datamodel.Split(0)), e.datamodel.Split(1));
@ -57,7 +59,12 @@ namespace RhythmHeavenMania.Editor
g.SetActive(true);
entity.eventObj = g.GetComponent<TimelineEventObj>();
entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);*/
var entity = GameManager.instance.Beatmap.entities[i];
var e = GameManager.instance.Beatmap.entities[i];
AddEventObject(e.datamodel, false, new Vector3(e.beat, Mathp.Round2Nearest(Random.Range(0, -205.36f), 51.34f)), i);
}
}
@ -190,10 +197,10 @@ namespace RhythmHeavenMania.Editor
#region Functions
public void AddEventObject(string eventName, bool dragNDrop = false)
public void AddEventObject(string eventName, bool dragNDrop = false, Vector3 pos = new Vector3(), int entityId = 0)
{
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
g.transform.localPosition = new Vector3(0, 0);
g.transform.localPosition = pos;
g.transform.GetChild(1).GetComponent<TMP_Text>().text = eventName.Split('/')[1];
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
@ -210,24 +217,27 @@ namespace RhythmHeavenMania.Editor
g.SetActive(true);
Beatmap.Entity entity = new Beatmap.Entity();
entity.datamodel = eventName;
entity.eventObj = eventObj;
var entity = GameManager.instance.Beatmap.entities[entityId];
var e = GameManager.instance.Beatmap.entities[entityId];
GameManager.instance.Beatmap.entities.Add(entity);
GameManager.instance.SortEventsList();
g.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
entity.eventObj = g.GetComponent<TimelineEventObj>();
entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
if (dragNDrop)
{
g.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
eventObj.OnDown();
Beatmap.Entity en = new Beatmap.Entity();
en.datamodel = eventName;
en.eventObj = eventObj;
GameManager.instance.Beatmap.entities.Add(en);
GameManager.instance.SortEventsList();
}
Editor.EventObjs.Add(eventObj);
// entity.eventObj = g.GetComponent<TimelineEventObj>();
// entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
eventObjs.Add(eventObj);
}
public void DestroyEventObject(TimelineEventObj eventObj)
@ -240,6 +250,16 @@ namespace RhythmHeavenMania.Editor
Editor.EventObjs.Remove(eventObj);
}
public bool IsMouseAboveEvents()
{
return Timeline.instance.eventObjs.FindAll(c => c.mouseHovering == true).Count > 0;
}
public bool IsEventsDragging()
{
return Timeline.instance.eventObjs.FindAll(c => c.isDragging == true).Count > 0;
}
#endregion
#region Commands

View file

@ -26,6 +26,8 @@ namespace RhythmHeavenMania.Editor
public float length;
private bool eligibleToMove = false;
private bool lastVisible;
public bool selected;
public bool mouseHovering;
[Header("Colors")]
public Color NormalCol;
@ -34,7 +36,9 @@ namespace RhythmHeavenMania.Editor
private void Update()
{
// Optimizations
mouseHovering = RectTransformUtility.RectangleContainsScreenPoint(GetComponent<RectTransform>(), Input.mousePosition, Camera.main);
#region Optimizations
bool visible = GetComponent<RectTransform>().IsVisibleFrom(Camera.main);
@ -48,7 +52,16 @@ namespace RhythmHeavenMania.Editor
lastVisible = visible;
// -------------
#endregion
if (selected)
{
SetColor(1);
}
else
{
SetColor(0);
}
if (Conductor.instance.NotStopped())
{
@ -58,7 +71,33 @@ namespace RhythmHeavenMania.Editor
enemyIndex = GameManager.instance.Beatmap.entities.FindIndex(a => a.eventObj == this);
if (isDragging == true)
if (Input.GetMouseButtonDown(0) && Timeline.instance.IsMouseAboveEvents())
{
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 (!Input.GetKey(KeyCode.LeftShift))
{
Selections.instance.Deselect(this);
}
}
OnUp();
}
if (isDragging && selected)
{
Vector3 mousePos;
mousePos = Input.mousePosition;
@ -71,31 +110,21 @@ namespace RhythmHeavenMania.Editor
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()
{
if (GameManager.instance.Beatmap.entities.FindAll(c => c.beat == this.transform.localPosition.x && c.track == (int)(this.transform.localPosition.y / 51.34f * -1)).Count > 0)
{
// PosPreview.GetComponent<Image>().color = Color.red;
eligibleToMove = false;
}
else
{
// PosPreview.GetComponent<Image>().color = Color.yellow;
eligibleToMove = true;
}
}
@ -106,42 +135,65 @@ namespace RhythmHeavenMania.Editor
entity.beat = this.transform.localPosition.x;
GameManager.instance.SortEventsList();
entity.track = (int)(this.transform.localPosition.y / 51.34f) * -1;
// this.transform.localPosition = this.transform.localPosition;
// transform.DOLocalMove(PosPreview.transform.localPosition, 0.15f).SetEase(Ease.OutExpo);
}
private void Cancel()
{
if (PosPreview) Destroy(PosPreview.gameObject);
eligibleToMove = false;
}
#region ClickEvents
public void OnDown()
{
Vector3 mousePos;
if (!selected)
{
if (Input.GetKey(KeyCode.LeftShift))
{
Selections.instance.ShiftClickSelect(this);
}
else
{
Selections.instance.ClickSelect(this);
}
/*PosPreview = Instantiate(PosPreviewRef, PosPreviewRef.transform.parent);
PosPreview.sizeDelta = new Vector2(100 * transform.GetComponent<RectTransform>().sizeDelta.x, transform.GetComponent<RectTransform>().sizeDelta.y);
PosPreview.transform.localPosition = this.transform.localPosition;
PosPreview.GetComponent<Image>().enabled = true;
PosPreview.GetComponent<Image>().color = Color.yellow;*/
mousePos = Input.mousePosition;
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
startPosX = mousePos.x - this.transform.position.x;
startPosY = mousePos.y - this.transform.position.y;
isDragging = true;
// Selector.instance.Click(this);
}
}
public void OnUp()
{
isDragging = false;
if (selected)
{
isDragging = false;
if (eligibleToMove) OnComplete();
Cancel();
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
public void SetColor(int type)
{
Color c = Color.white;
@ -160,5 +212,13 @@ namespace RhythmHeavenMania.Editor
transform.GetChild(0).GetComponent<Image>().color = c;
}
private void OnDestroy()
{
// better safety net than canada's healthcare system
GameManager.instance.Beatmap.entities.Remove(GameManager.instance.Beatmap.entities.Find(c => c.eventObj = this));
}
#endregion
}
}

File diff suppressed because one or more lines are too long