Entity object parameters testing

This commit is contained in:
Braedon
2022-02-03 17:20:26 -05:00
parent 95637635f6
commit e0db2a446e
27 changed files with 1413 additions and 264 deletions

View File

@ -22,6 +22,8 @@ namespace RhythmHeavenMania.Editor
private bool clickedInTimeline = false;
private TMPro.TMP_Text sizeText;
public static BoxSelection instance { get; private set; }
private void Awake()
@ -36,6 +38,8 @@ namespace RhythmHeavenMania.Editor
Color boxCol = EditorTheme.theme.properties.BoxSelectionCol.Hex2RGB();
boxVisual.GetComponent<Image>().color = new Color(boxCol.r, boxCol.g, boxCol.b, 0.3f);
boxVisual.transform.GetChild(0).GetComponent<Image>().color = EditorTheme.theme.properties.BoxSelectionOutlineCol.Hex2RGB();
sizeText = boxVisual.transform.GetChild(1).GetComponent<TMPro.TMP_Text>();
}
private void Update()
@ -57,9 +61,9 @@ namespace RhythmHeavenMania.Editor
}
if (boxVisual.rect.width * boxVisual.transform.localScale.x >= 0.5f)
boxVisual.transform.GetChild(1).GetComponent<TMPro.TMP_Text>().text = $"{string.Format("{0:0.000}", boxVisual.rect.width * boxVisual.transform.localScale.x)}";
sizeText.text = $"{string.Format("{0:0.000}", boxVisual.rect.width * boxVisual.transform.localScale.x)}";
else
boxVisual.transform.GetChild(1).GetComponent<TMPro.TMP_Text>().text = string.Empty; // i'm lazy
sizeText.text = string.Empty; // i'm lazy
// click
@ -162,7 +166,7 @@ namespace RhythmHeavenMania.Editor
public Vector3 MousePosition()
{
var mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
var mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
// var mousePos = new Vector2();
// RectTransformUtility.ScreenPointToLocalPointInRectangle(timelineContent, Input.mousePosition, Camera.main, out mousePos);
return new Vector3(mousePos.x, mousePos.y, 0);

View File

@ -50,6 +50,7 @@ namespace RhythmHeavenMania.Editor
[Header("Properties")]
private bool changedMusic = false;
private bool loadedMusic = false;
private string currentRemixPath = "";
private int lastEditorObjectsCount = 0;
private bool fullscreen;
@ -95,20 +96,6 @@ namespace RhythmHeavenMania.Editor
public void LateUpdate()
{
// This is buggy
/*if (Conductor.instance.isPlaying || Conductor.instance.isPaused)
{
GetComponent<Selections>().enabled = false;
GetComponent<Selector>().enabled = false;
GetComponent<BoxSelection>().enabled = false;
}
else
{
GetComponent<Selections>().enabled = true;
GetComponent<Selector>().enabled = true;
GetComponent<BoxSelection>().enabled = true;
}*/
if (Input.GetKeyDown(KeyCode.Tab))
{
Fullscreen();
@ -147,23 +134,38 @@ namespace RhythmHeavenMania.Editor
}
if (Timeline.instance.timelineState.selected == true)
if (Input.GetMouseButtonUp(0))
{
List<TimelineEventObj> selectedEvents = Timeline.instance.eventObjs.FindAll(c => c.selected == true && c.eligibleToMove == true);
if (Input.GetMouseButtonUp(0))
{
List<TimelineEventObj> selectedEvents = Timeline.instance.eventObjs.FindAll(c => c.selected == true && c.eligibleToMove == true);
if (selectedEvents.Count > 0)
{
List<TimelineEventObj> result = new List<TimelineEventObj>();
for (int i = 0; i < selectedEvents.Count; i++)
{
if (selectedEvents[i].isCreating == false)
{
result.Add(selectedEvents[i]);
}
selectedEvents[i].OnUp();
}
CommandManager.instance.Execute(new Commands.Move(result));
}
}
}
if (Input.GetMouseButtonUp(1))
{
List<TimelineEventObj> selectedEvents = Timeline.instance.eventObjs.FindAll(c => c.selected == true);
if (selectedEvents.Count > 0)
{
List<TimelineEventObj> result = new List<TimelineEventObj>();
for (int i = 0; i < selectedEvents.Count; i++)
{
if (selectedEvents[i].isCreating == false)
{
result.Add(selectedEvents[i]);
}
selectedEvents[i].OnUp();
// EventParameterManager.instance.StartParams(selectedEvents[i].entity);
}
CommandManager.instance.Execute(new Commands.Move(result));
}
}
@ -192,6 +194,14 @@ namespace RhythmHeavenMania.Editor
}
lastEditorObjectsCount = GameManager.instance.BeatmapEntities();
if (Application.isEditor)
{
if (Input.GetKeyDown(KeyCode.S))
{
SaveRemix(false);
}
}
}
public static Sprite GameIcon(string name)
@ -217,11 +227,6 @@ namespace RhythmHeavenMania.Editor
}
}
);
// byte[] bytes = OggVorbis.VorbisPlugin.GetOggVorbis(Conductor.instance.musicSource.clip, 1);
// print(bytes.Length);
// OggVorbis.VorbisPlugin.Save(@"C:/Users/Braedon/Downloads/test.ogg", Conductor.instance.musicSource.clip, 1);
}
private async Task<AudioClip> LoadClip(string path)
@ -301,7 +306,7 @@ namespace RhythmHeavenMania.Editor
{
using (FileStream zipFile = File.Open(path, FileMode.Create))
{
using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Update, true))
using (var archive = new ZipArchive(zipFile, ZipArchiveMode.Update))
{
var levelFile = archive.CreateEntry("remix.json", System.IO.Compression.CompressionLevel.NoCompression);
using (var zipStream = levelFile.Open())
@ -362,6 +367,7 @@ namespace RhythmHeavenMania.Editor
stream.CopyTo(ms);
bytes = ms.ToArray();
Conductor.instance.musicSource.clip = OggVorbis.VorbisPlugin.ToAudioClip(bytes, "music");
loadedMusic = true;
}
}
}
@ -410,17 +416,6 @@ namespace RhythmHeavenMania.Editor
return json;
}
public void DebugSave()
{
// temp
#if UNITY_EDITOR
string path = UnityEditor.AssetDatabase.GetAssetPath(GameManager.instance.txt);
path = Application.dataPath.Remove(Application.dataPath.Length - 6, 6) + path;
System.IO.File.WriteAllText(path, JsonConvert.SerializeObject(GameManager.instance.Beatmap));
Debug.Log("Saved to " + path);
#endif
}
public void SetGameEventTitle(string txt)
{
GameEventSelectorTitle.text = txt;

View File

@ -0,0 +1,76 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace RhythmHeavenMania.Editor
{
public class EventParameterManager : MonoBehaviour
{
[Header("General References")]
[SerializeField] private GameObject eventSelector;
[Header("Property Prefabs")]
[SerializeField] private GameObject IntegerP;
public Beatmap.Entity entity;
public static EventParameterManager instance { get; set; }
private void Awake()
{
instance = this;
}
public void StartParams(Beatmap.Entity entity)
{
AddParams(entity);
}
private void AddParams(Beatmap.Entity entity)
{
var minigame = EventCaller.instance.GetMinigame(entity.datamodel.Split(0));
int actionIndex = minigame.actions.IndexOf(minigame.actions.Find(c => c.actionName == entity.datamodel.Split(1)));
Minigames.GameAction action = minigame.actions[actionIndex];
if (action.parameters != null)
{
eventSelector.SetActive(false);
this.entity = entity;
Editor.instance.SetGameEventTitle($"Properties for {entity.datamodel}");
for (int i = 1; i < transform.childCount; i++)
{
Destroy(transform.GetChild(i).gameObject);
}
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;
AddParam(propertyName, param, caption);
}
}
}
private void AddParam(string propertyName, object type, string caption)
{
GameObject prefab = IntegerP;
if (type.GetType() == typeof(EntityTypes.Integer))
{
prefab = IntegerP;
}
GameObject input = Instantiate(prefab);
input.transform.SetParent(this.gameObject.transform);
input.SetActive(true);
input.transform.localScale = Vector2.one;
var property = input.GetComponent<EventPropertyPrefab>();
property.SetProperties(propertyName, type, caption);
}
}
}

View File

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

View File

@ -0,0 +1,37 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace RhythmHeavenMania.Editor
{
public class EventPropertyPrefab : MonoBehaviour
{
public TMP_Text caption;
public Slider slider;
public TMP_InputField inputField;
private string propertyName;
[SerializeField] private EventParameterManager parameterManager;
public void SetProperties(string propertyName, object type, string caption)
{
this.propertyName = propertyName;
this.caption.text = caption;
var integer = ((EntityTypes.Integer)type);
slider.minValue = integer.min;
slider.maxValue = integer.max;
}
public void TestChange()
{
inputField.text = slider.value.ToString();
parameterManager.entity[propertyName] = (int)slider.value;
}
}
}

View File

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

View File

@ -541,7 +541,7 @@ namespace RhythmHeavenMania.Editor.Track
{
if (Input.GetMouseButton(1))
{
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: 1.0x";
PlaybackSpeed.transform.GetChild(3).GetComponent<TMP_Text>().text = $"Playback Speed: 1x";
PlaybackSpeed.value = 1f;
}
}

View File

@ -146,20 +146,20 @@ namespace RhythmHeavenMania.Editor.Track
{
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
// lastPos_ = transform.localPosition;
lastPos_ = transform.localPosition;
// 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));
moveTemp.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
moveTemp.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(moveTemp.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(moveTemp.transform.localPosition.y));
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));
// moveTemp.transform.position = new Vector3(mousePos.x - startPosX, mousePos.y - startPosY - 0.40f, 0);
// moveTemp.transform.localPosition = new Vector3(Mathf.Clamp(Mathp.Round2Nearest(moveTemp.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(moveTemp.transform.localPosition.y));
if (lastPos != moveTemp.transform.localPosition)
if (lastPos != transform.localPosition)
{
OnMove();
this.transform.DOLocalMove(new Vector3(Mathf.Clamp(Mathp.Round2Nearest(moveTemp.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(moveTemp.transform.localPosition.y)), 0.15f).SetEase(Ease.OutExpo);
// this.transform.DOLocalMove(new Vector3(Mathf.Clamp(Mathp.Round2Nearest(moveTemp.transform.localPosition.x, 0.25f), 0, Mathf.Infinity), Timeline.instance.SnapToLayer(moveTemp.transform.localPosition.y)), 0.15f).SetEase(Ease.OutExpo);
}
lastPos = moveTemp.transform.localPosition;
lastPos = transform.localPosition;
}
}
else if (resizingLeft)
@ -231,20 +231,23 @@ namespace RhythmHeavenMania.Editor.Track
public void OnDown()
{
if (selected && Timeline.instance.timelineState.selected)
if (Input.GetMouseButton(0))
{
lastPos_ = transform.localPosition;
for (int i = 0; i < Timeline.instance.eventObjs.Count; i++)
if (selected && Timeline.instance.timelineState.selected)
{
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
Timeline.instance.eventObjs[i].startPosX = mousePos.x - Timeline.instance.eventObjs[i].transform.position.x;
Timeline.instance.eventObjs[i].startPosY = mousePos.y - Timeline.instance.eventObjs[i].transform.position.y;
}
lastPos_ = transform.localPosition;
moving = true;
// lastMovePos = transform.localPosition;
// OnComplete();
for (int i = 0; i < Timeline.instance.eventObjs.Count; i++)
{
Vector3 mousePos = Editor.instance.EditorCamera.ScreenToWorldPoint(Input.mousePosition);
Timeline.instance.eventObjs[i].startPosX = mousePos.x - Timeline.instance.eventObjs[i].transform.position.x;
Timeline.instance.eventObjs[i].startPosY = mousePos.y - Timeline.instance.eventObjs[i].transform.position.y;
}
moving = true;
// lastMovePos = transform.localPosition;
// OnComplete();
}
}
}