mirror of
https://github.com/RHeavenStudio/HeavenStudio.git
synced 2025-06-12 08:27:40 +02:00
Drag n drop begun
This commit is contained in:
@ -43,7 +43,7 @@ namespace RhythmHeavenMania.Editor
|
||||
GameObject GameIcon_ = Instantiate(GridGameSelector.GetChild(0).gameObject, GridGameSelector);
|
||||
GameIcon_.GetComponent<Image>().sprite = GameIcon(EventCaller.instance.minigames[i].name);
|
||||
GameIcon_.gameObject.SetActive(true);
|
||||
GameIcon_.name = "GameIcon";
|
||||
GameIcon_.name = EventCaller.instance.minigames[i].displayName;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,20 +1,117 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
using TMPro;
|
||||
|
||||
namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
public class GridGameSelector : MonoBehaviour
|
||||
{
|
||||
public GameObject GameTitlePreview;
|
||||
public string SelectedMinigame;
|
||||
|
||||
public void OnEnter()
|
||||
[Header("Components")]
|
||||
public GameObject GameEventSelector;
|
||||
public GameObject EventRef;
|
||||
|
||||
[Header("Properties")]
|
||||
private EventCaller.MiniGame mg;
|
||||
private bool gameOpen;
|
||||
[SerializeField] private int currentEventIndex;
|
||||
private int dragTimes;
|
||||
|
||||
private void Update()
|
||||
{
|
||||
GameTitlePreview.GetComponent<Image>().enabled = true;
|
||||
if (gameOpen)
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.DownArrow))
|
||||
{
|
||||
UpdateIndex(1);
|
||||
}
|
||||
else if (Input.GetKeyDown(KeyCode.UpArrow))
|
||||
{
|
||||
UpdateIndex(-1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnExit()
|
||||
#region Events
|
||||
|
||||
public void Drag()
|
||||
{
|
||||
GameTitlePreview.GetComponent<Image>().enabled = false;
|
||||
if (Conductor.instance.NotStopped()) return;
|
||||
|
||||
if (Timeline.instance.CheckIfMouseInTimeline() && dragTimes < 1)
|
||||
{
|
||||
dragTimes++;
|
||||
Timeline.instance.AddEventObject(mg.name + "/" + mg.actions[currentEventIndex].actionName, true);
|
||||
}
|
||||
}
|
||||
|
||||
public void Drop()
|
||||
{
|
||||
if (Conductor.instance.NotStopped()) return;
|
||||
|
||||
dragTimes = 0;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
public void UpdateIndex(int amount)
|
||||
{
|
||||
currentEventIndex += amount;
|
||||
|
||||
if (currentEventIndex < 0)
|
||||
{
|
||||
currentEventIndex = mg.actions.Count - 1;
|
||||
}
|
||||
else if (currentEventIndex > mg.actions.Count - 1)
|
||||
{
|
||||
currentEventIndex = 0;
|
||||
}
|
||||
|
||||
SetColor(currentEventIndex);
|
||||
}
|
||||
|
||||
public void SelectGame(string gameName)
|
||||
{
|
||||
DestroyEvents();
|
||||
|
||||
SelectedMinigame = gameName;
|
||||
|
||||
mg = EventCaller.instance.minigames.Find(c => c.displayName == gameName);
|
||||
|
||||
for (int i = 0; i < mg.actions.Count; i++)
|
||||
{
|
||||
GameObject e = Instantiate(EventRef, EventRef.transform.parent);
|
||||
e.GetComponent<TMP_Text>().text = mg.actions[i].actionName;
|
||||
e.SetActive(true);
|
||||
}
|
||||
|
||||
gameOpen = true;
|
||||
currentEventIndex = 0;
|
||||
SetColor(0);
|
||||
}
|
||||
|
||||
private void SetColor(int ind)
|
||||
{
|
||||
for (int i = 0; i < EventRef.transform.parent.childCount; i++) EventRef.transform.parent.GetChild(i).GetComponent<TMP_Text>().color = Color.white;
|
||||
|
||||
EventRef.transform.parent.GetChild(ind + 1).GetComponent<TMP_Text>().color = Color.cyan;
|
||||
}
|
||||
|
||||
private void DestroyEvents()
|
||||
{
|
||||
for (int i = 1; i < EventRef.transform.parent.childCount; i++)
|
||||
{
|
||||
Destroy(EventRef.transform.parent.GetChild(i).gameObject);
|
||||
}
|
||||
|
||||
gameOpen = false;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0baf64619d1dc0749bfc3f9a4b8f7b47
|
||||
guid: d9d826be8d1e71d4c971f5ed377ee873
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
|
30
Assets/Scripts/LevelEditor/GridGameSelectorGame.cs
Normal file
30
Assets/Scripts/LevelEditor/GridGameSelectorGame.cs
Normal file
@ -0,0 +1,30 @@
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
public class GridGameSelectorGame : MonoBehaviour
|
||||
{
|
||||
public GameObject GameTitlePreview;
|
||||
|
||||
public GridGameSelector GridGameSelector;
|
||||
|
||||
public void OnClick()
|
||||
{
|
||||
GridGameSelector.SelectGame(this.gameObject.name);
|
||||
}
|
||||
|
||||
public void OnEnter()
|
||||
{
|
||||
GameTitlePreview.GetComponent<Image>().enabled = true;
|
||||
GameTitlePreview.transform.GetChild(0).GetComponent<TMPro.TMP_Text>().text = this.gameObject.name;
|
||||
GameTitlePreview.transform.GetChild(0).gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void OnExit()
|
||||
{
|
||||
GameTitlePreview.GetComponent<Image>().enabled = false;
|
||||
GameTitlePreview.transform.GetChild(0).gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
11
Assets/Scripts/LevelEditor/GridGameSelectorGame.cs.meta
Normal file
11
Assets/Scripts/LevelEditor/GridGameSelectorGame.cs.meta
Normal file
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0baf64619d1dc0749bfc3f9a4b8f7b47
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -26,11 +26,14 @@ namespace RhythmHeavenMania.Editor
|
||||
[SerializeField] private RectTransform TimelineEventObjRef;
|
||||
private RectTransform TimelineSongPosLine;
|
||||
|
||||
public static Timeline instance { get; private set; }
|
||||
|
||||
#region Initializers
|
||||
|
||||
public void Init()
|
||||
{
|
||||
instance = this;
|
||||
|
||||
for (int i = 0; i < GameManager.instance.Beatmap.entities.Count; i++)
|
||||
{
|
||||
var entity = GameManager.instance.Beatmap.entities[i];
|
||||
@ -178,6 +181,52 @@ namespace RhythmHeavenMania.Editor
|
||||
int milliseconds = (int)(1000 * (time - minutes * 60 - seconds));
|
||||
return string.Format("{0:00}:{1:00}:{2:000}", minutes, seconds, milliseconds);
|
||||
}
|
||||
|
||||
public bool CheckIfMouseInTimeline()
|
||||
{
|
||||
return (this.gameObject.activeSelf && RectTransformUtility.RectangleContainsScreenPoint(TimelineContent.transform.parent.gameObject.GetComponent<RectTransform>(), Input.mousePosition, Camera.main));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Functions
|
||||
|
||||
public void AddEventObject(string eventName, bool dragNDrop = false)
|
||||
{
|
||||
GameObject g = Instantiate(TimelineEventObjRef.gameObject, TimelineEventObjRef.parent);
|
||||
g.transform.localPosition = new Vector3(0, 0);
|
||||
g.transform.GetChild(1).GetComponent<TMP_Text>().text = eventName.Split('/')[1];
|
||||
|
||||
TimelineEventObj eventObj = g.GetComponent<TimelineEventObj>();
|
||||
eventObj.Icon.sprite = Editor.GameIcon(eventName.Split(0));
|
||||
|
||||
EventCaller.GameAction gameAction = EventCaller.instance.GetGameAction(EventCaller.instance.GetMinigame(eventName.Split(0)), eventName.Split(1));
|
||||
|
||||
if (gameAction != null)
|
||||
{
|
||||
g.GetComponent<RectTransform>().sizeDelta = new Vector2(gameAction.defaultLength, g.GetComponent<RectTransform>().sizeDelta.y);
|
||||
float length = gameAction.defaultLength;
|
||||
eventObj.length = length;
|
||||
}
|
||||
|
||||
g.SetActive(true);
|
||||
|
||||
Beatmap.Entity entity = new Beatmap.Entity();
|
||||
entity.datamodel = eventName;
|
||||
entity.eventObj = eventObj;
|
||||
|
||||
GameManager.instance.Beatmap.entities.Add(entity);
|
||||
GameManager.instance.SortEventsList();
|
||||
|
||||
g.transform.position = Camera.main.ScreenToWorldPoint(Input.mousePosition);
|
||||
|
||||
if (dragNDrop)
|
||||
{
|
||||
eventObj.OnDown();
|
||||
}
|
||||
// entity.eventObj = g.GetComponent<TimelineEventObj>();
|
||||
// entity.track = (int)(g.transform.localPosition.y / 51.34f * -1);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -12,7 +12,7 @@ namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
private float startPosX;
|
||||
private float startPosY;
|
||||
private bool isDragging;
|
||||
public bool isDragging;
|
||||
|
||||
private Vector3 lastPos;
|
||||
|
||||
@ -28,7 +28,7 @@ namespace RhythmHeavenMania.Editor
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Conductor.instance.isPlaying == true || Conductor.instance.isPaused)
|
||||
if (Conductor.instance.NotStopped())
|
||||
{
|
||||
Cancel();
|
||||
return;
|
||||
@ -42,26 +42,29 @@ namespace RhythmHeavenMania.Editor
|
||||
mousePos = Input.mousePosition;
|
||||
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
|
||||
PosPreview.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
|
||||
PosPreview.transform.localPosition = new Vector3(Mathp.Round2Nearest(PosPreview.transform.localPosition.x, 0.25f), Mathp.Round2Nearest(PosPreview.transform.localPosition.y, 51.34f));
|
||||
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));
|
||||
|
||||
if (lastPos != transform.localPosition)
|
||||
OnMove();
|
||||
|
||||
lastPos = PosPreview.transform.localPosition;
|
||||
lastPos = this.transform.localPosition;
|
||||
}
|
||||
|
||||
if (Input.GetMouseButtonUp(0))
|
||||
OnUp();
|
||||
}
|
||||
|
||||
private void OnMove()
|
||||
{
|
||||
if (GameManager.instance.Beatmap.entities.FindAll(c => c.beat == PosPreview.transform.localPosition.x && c.track == (int)(PosPreview.transform.localPosition.y / 51.34f * -1)).Count > 0)
|
||||
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;
|
||||
// PosPreview.GetComponent<Image>().color = Color.red;
|
||||
eligibleToMove = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
PosPreview.GetComponent<Image>().color = Color.yellow;
|
||||
// PosPreview.GetComponent<Image>().color = Color.yellow;
|
||||
eligibleToMove = true;
|
||||
}
|
||||
}
|
||||
@ -69,11 +72,11 @@ namespace RhythmHeavenMania.Editor
|
||||
private void OnComplete()
|
||||
{
|
||||
var entity = GameManager.instance.Beatmap.entities[enemyIndex];
|
||||
entity.beat = PosPreview.transform.localPosition.x;
|
||||
entity.beat = this.transform.localPosition.x;
|
||||
GameManager.instance.SortEventsList();
|
||||
entity.track = (int)(PosPreview.transform.localPosition.y / 51.34f) * -1;
|
||||
entity.track = (int)(this.transform.localPosition.y / 51.34f) * -1;
|
||||
|
||||
this.transform.localPosition = PosPreview.transform.localPosition;
|
||||
// this.transform.localPosition = this.transform.localPosition;
|
||||
// transform.DOLocalMove(PosPreview.transform.localPosition, 0.15f).SetEase(Ease.OutExpo);
|
||||
}
|
||||
|
||||
@ -87,18 +90,17 @@ namespace RhythmHeavenMania.Editor
|
||||
{
|
||||
Vector3 mousePos;
|
||||
|
||||
PosPreview = Instantiate(PosPreviewRef, PosPreviewRef.transform.parent);
|
||||
/*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;
|
||||
PosPreview.GetComponent<Image>().color = Color.yellow;*/
|
||||
|
||||
mousePos = Input.mousePosition;
|
||||
mousePos = Camera.main.ScreenToWorldPoint(mousePos);
|
||||
startPosX = mousePos.x - PosPreview.transform.position.x;
|
||||
startPosY = mousePos.y - PosPreview.transform.position.y;
|
||||
startPosX = mousePos.x - this.transform.position.x;
|
||||
startPosY = mousePos.y - this.transform.position.y;
|
||||
isDragging = true;
|
||||
|
||||
}
|
||||
|
||||
public void OnUp()
|
||||
|
Reference in New Issue
Block a user