自动更新型DUI扩展,将Time变量挪出TImeline UI,Effect效果容器修缮,移除Note的transform模块,Scene Camera优化
This commit is contained in:
@@ -18,11 +18,6 @@ namespace Ichni.Editor
|
||||
/// 参数名,通过反射获取饿修改对应变量的值
|
||||
/// </summary>
|
||||
public string parameterName;
|
||||
|
||||
/// <summary>
|
||||
/// 是否始终更新,如果子类可能用到此变量,则在子类中写Update即可(注意,如果最后仅有Text用到此变量,直接移动它到Text即可)
|
||||
/// </summary>
|
||||
public bool isAlwaysUpdated;
|
||||
|
||||
public virtual void Initialize(IBaseElement baseElement, string title, string parameterName)
|
||||
{
|
||||
@@ -54,4 +49,21 @@ namespace Ichni.Editor
|
||||
|
||||
//public abstract void ApplyParameters();
|
||||
}
|
||||
|
||||
public interface IHaveAutoUpdate
|
||||
{
|
||||
public bool isAutoUpdate { get; set; }
|
||||
public bool isReceiving { get; set; }
|
||||
public void SetAutoUpdate(bool enable);
|
||||
|
||||
public void UpdateContent()
|
||||
{
|
||||
if(isAutoUpdate && isReceiving)
|
||||
{
|
||||
ApplyContent();
|
||||
}
|
||||
}
|
||||
|
||||
public void ApplyContent();
|
||||
}
|
||||
}
|
||||
@@ -8,18 +8,51 @@ using UnityEngine.Events;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIParameterInputField : DynamicUIElement
|
||||
public class DynamicUIInputField : DynamicUIElement, IHaveAutoUpdate
|
||||
{
|
||||
public TMP_InputField inputField;
|
||||
|
||||
public bool isAutoUpdate { get; set; }
|
||||
public bool isReceiving { get; set; }
|
||||
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
|
||||
{
|
||||
base.Initialize(baseElement, title, parameterName);
|
||||
inputField.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString(); //获取对应变量的值
|
||||
|
||||
inputField.onEndEdit.AddListener(ApplyParameters);
|
||||
if (parameterName != string.Empty)
|
||||
{
|
||||
ApplyContent();
|
||||
inputField.onEndEdit.AddListener(ApplyParameters);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
(this as IHaveAutoUpdate).UpdateContent();
|
||||
}
|
||||
|
||||
public void SetDefaultValue(string text)
|
||||
{
|
||||
inputField.text = text;
|
||||
}
|
||||
|
||||
public T GetValue<T>()
|
||||
{
|
||||
return (T)Convert.ChangeType(inputField.text, typeof(T));
|
||||
}
|
||||
|
||||
public void SetAutoUpdate(bool enable)
|
||||
{
|
||||
isAutoUpdate = enable;
|
||||
isReceiving = true;
|
||||
|
||||
inputField.onSelect.AddListener(_ => isReceiving = false);
|
||||
inputField.onDeselect.AddListener(_ => isReceiving = true);
|
||||
}
|
||||
|
||||
public void ApplyContent()
|
||||
{
|
||||
inputField.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString(); //获取对应变量的值
|
||||
}
|
||||
|
||||
private void ApplyParameters(string text)
|
||||
{
|
||||
Type type = connectedBaseElement.GetType().GetField(parameterName).FieldType;
|
||||
@@ -7,22 +7,32 @@ using UnityEngine;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIParameterText : DynamicUIElement
|
||||
public class DynamicUIParameterText : DynamicUIElement, IHaveAutoUpdate
|
||||
{
|
||||
public TMP_Text text;
|
||||
public bool isAutoUpdate { get; set; }
|
||||
public bool isReceiving { get; set; }
|
||||
|
||||
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
|
||||
{
|
||||
base.Initialize(baseElement, title, parameterName);
|
||||
text.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString();
|
||||
ApplyContent();
|
||||
}
|
||||
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (isAlwaysUpdated)
|
||||
{
|
||||
text.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString();
|
||||
}
|
||||
(this as IHaveAutoUpdate).UpdateContent();
|
||||
}
|
||||
|
||||
public void SetAutoUpdate(bool enable)
|
||||
{
|
||||
isAutoUpdate = enable;
|
||||
isReceiving = true;
|
||||
}
|
||||
|
||||
public void ApplyContent()
|
||||
{
|
||||
text.text = connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement).ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame;
|
||||
@@ -10,27 +11,66 @@ using UnityEngine.UIElements.Experimental;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class DynamicUIVector3InputField : DynamicUIElement
|
||||
public class DynamicUIVector3InputField : DynamicUIElement, IHaveAutoUpdate
|
||||
{
|
||||
public TMP_InputField inputFieldX;
|
||||
public TMP_InputField inputFieldY;
|
||||
public TMP_InputField inputFieldZ;
|
||||
public bool isAutoUpdate { get; set; }
|
||||
public bool isReceiving { get; set; }
|
||||
|
||||
public override void Initialize(IBaseElement baseElement, string title, string parameterName)
|
||||
{
|
||||
base.Initialize(baseElement, title, parameterName);
|
||||
if (parameterName != string.Empty)
|
||||
{
|
||||
ApplyContent();
|
||||
|
||||
inputFieldX.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
inputFieldY.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
inputFieldZ.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
(this as IHaveAutoUpdate).UpdateContent();
|
||||
}
|
||||
|
||||
public void SetDefaultValue(Vector3 value)
|
||||
{
|
||||
inputFieldX.text = value.x.ToString();
|
||||
inputFieldY.text = value.y.ToString();
|
||||
inputFieldZ.text = value.z.ToString();
|
||||
}
|
||||
|
||||
public Vector3 GetValue()
|
||||
{
|
||||
return new Vector3(float.Parse(inputFieldX.text), float.Parse(inputFieldY.text), float.Parse(inputFieldZ.text));
|
||||
}
|
||||
|
||||
public void SetAutoUpdate(bool enable)
|
||||
{
|
||||
isAutoUpdate = enable;
|
||||
isReceiving = true;
|
||||
|
||||
inputFieldX.onSelect.AddListener(_ => isReceiving = false);
|
||||
inputFieldY.onSelect.AddListener(_ => isReceiving = false);
|
||||
inputFieldZ.onSelect.AddListener(_ => isReceiving = false);
|
||||
|
||||
inputFieldX.onDeselect.AddListener(_ => isReceiving = true);
|
||||
inputFieldY.onDeselect.AddListener(_ => isReceiving = true);
|
||||
inputFieldZ.onDeselect.AddListener(_ => isReceiving = true);
|
||||
}
|
||||
|
||||
public void ApplyContent()
|
||||
{
|
||||
Vector3 pos = (Vector3)connectedBaseElement.GetType().GetField(parameterName).GetValue(connectedBaseElement); //获取对应变量的值
|
||||
inputFieldX.text = pos.x.ToString();
|
||||
inputFieldY.text = pos.y.ToString();
|
||||
inputFieldZ.text = pos.z.ToString();
|
||||
|
||||
inputFieldX.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
inputFieldY.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
inputFieldZ.onEndEdit.AddListener(_ => ApplyParameters());
|
||||
}
|
||||
public override void DeviverSet(int i){
|
||||
//我什么也不做
|
||||
}
|
||||
|
||||
private void ApplyParameters()
|
||||
{
|
||||
Vector3 newValue = new Vector3(float.Parse(inputFieldX.text), float.Parse(inputFieldY.text), float.Parse(inputFieldZ.text));
|
||||
@@ -44,5 +84,9 @@ namespace Ichni.Editor
|
||||
inputFieldY.onEndEdit.AddListener(_ => action());
|
||||
inputFieldZ.onEndEdit.AddListener(_ => action());
|
||||
}
|
||||
|
||||
public override void DeviverSet(int i){
|
||||
//我什么也不做
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,38 +66,49 @@ namespace Ichni.Editor
|
||||
return toggle;
|
||||
}
|
||||
|
||||
public DynamicUIGetterInputField GenerateGetterInputField(DynamicUIContainer container,
|
||||
string title, string defaultText)
|
||||
public DynamicUIInputField GenerateInputField(DynamicUIContainer container,
|
||||
string title, string defaultText = "") //不与参数绑定的InputField
|
||||
{
|
||||
DynamicUIGetterInputField getterInputField = Object
|
||||
.Instantiate(EditorManager.instance.basePrefabs.getterInputField, container.rect)
|
||||
.GetComponent<DynamicUIGetterInputField>();
|
||||
getterInputField.Initialize(null, title, string.Empty);
|
||||
getterInputField.SetDefaultText(defaultText);
|
||||
container.dynamicUIElements.Add(getterInputField);
|
||||
return getterInputField;
|
||||
DynamicUIInputField inputField = Object
|
||||
.Instantiate(EditorManager.instance.basePrefabs.parameterInputField, container.rect)
|
||||
.GetComponent<DynamicUIInputField>();
|
||||
inputField.Initialize(null, title, string.Empty);
|
||||
inputField.SetDefaultValue(defaultText);
|
||||
container.dynamicUIElements.Add(inputField);
|
||||
return inputField;
|
||||
}
|
||||
|
||||
public DynamicUIParameterInputField GenerateParameterInputField(IBaseElement baseElement,
|
||||
DynamicUIContainer container,
|
||||
string title, string parameterName)
|
||||
public DynamicUIInputField GenerateInputField(IBaseElement baseElement,
|
||||
DynamicUIContainer container, string title, string parameterName, bool isAutoUpdate = false) //与参数绑定的InputField
|
||||
{
|
||||
DynamicUIParameterInputField parameterInputField = Object
|
||||
DynamicUIInputField inputField = Object
|
||||
.Instantiate(EditorManager.instance.basePrefabs.parameterInputField, container.rect)
|
||||
.GetComponent<DynamicUIParameterInputField>();
|
||||
parameterInputField.Initialize(baseElement, title, parameterName);
|
||||
container.dynamicUIElements.Add(parameterInputField);
|
||||
return parameterInputField;
|
||||
.GetComponent<DynamicUIInputField>();
|
||||
inputField.Initialize(baseElement, title, parameterName);
|
||||
container.dynamicUIElements.Add(inputField);
|
||||
return inputField;
|
||||
}
|
||||
|
||||
public DynamicUIVector3InputField GenerateVector3InputField(DynamicUIContainer container, string title,
|
||||
Vector3 defaultVector3 = default)
|
||||
{
|
||||
DynamicUIVector3InputField vector3InputField =
|
||||
Object.Instantiate(EditorManager.instance.basePrefabs.vector3InputField, container.rect)
|
||||
.GetComponent<DynamicUIVector3InputField>();
|
||||
vector3InputField.Initialize(null, title, string.Empty);
|
||||
vector3InputField.SetDefaultValue(defaultVector3);
|
||||
container.dynamicUIElements.Add(vector3InputField);
|
||||
return vector3InputField;
|
||||
}
|
||||
|
||||
public DynamicUIVector3InputField GenerateVector3InputField(IBaseElement baseElement,
|
||||
DynamicUIContainer container,
|
||||
string title, string parameterName)
|
||||
DynamicUIContainer container, string title, string parameterName, bool isAutoUpdate = false)
|
||||
{
|
||||
DynamicUIVector3InputField vector3InputField =
|
||||
Object.Instantiate(EditorManager.instance.basePrefabs.vector3InputField, container.rect)
|
||||
.GetComponent<DynamicUIVector3InputField>();
|
||||
vector3InputField.Initialize(baseElement, title, parameterName);
|
||||
vector3InputField.SetAutoUpdate(isAutoUpdate);
|
||||
container.dynamicUIElements.Add(vector3InputField);
|
||||
return vector3InputField;
|
||||
}
|
||||
@@ -148,14 +159,13 @@ namespace Ichni.Editor
|
||||
}
|
||||
|
||||
public DynamicUIParameterText GenerateParameterText(IBaseElement baseElement, DynamicUIContainer container,
|
||||
string title,
|
||||
string parameterName, bool isAlwaysUpdate = false)
|
||||
string title, string parameterName, bool isAutoUpdate = false)
|
||||
{
|
||||
DynamicUIParameterText parameterText = Object
|
||||
.Instantiate(EditorManager.instance.basePrefabs.parameterText, container.rect)
|
||||
.GetComponent<DynamicUIParameterText>();
|
||||
parameterText.Initialize(baseElement, title, parameterName);
|
||||
parameterText.isAlwaysUpdated = isAlwaysUpdate;
|
||||
parameterText.SetAutoUpdate(isAutoUpdate);
|
||||
container.dynamicUIElements.Add(parameterText);
|
||||
return parameterText;
|
||||
}
|
||||
|
||||
23
Assets/Scripts/DynamicUI/Timeline/MusicPlayModule.cs
Normal file
23
Assets/Scripts/DynamicUI/Timeline/MusicPlayModule.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class MusicPlayModule : MonoBehaviour
|
||||
{
|
||||
public Button playButton;
|
||||
public Button pauseButton;
|
||||
public Button stopButton;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
playButton.onClick.AddListener(EditorManager.instance.musicPlayer.PlayMusic);
|
||||
pauseButton.onClick.AddListener(EditorManager.instance.musicPlayer.PauseMusic);
|
||||
stopButton.onClick.AddListener(EditorManager.instance.musicPlayer.StopMusic);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Ichni.RhythmGame;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
{
|
||||
public class MusicPlayer : MonoBehaviour
|
||||
{
|
||||
public bool isPlaying;
|
||||
public AudioSource audioSource;
|
||||
|
||||
public Button playButton;
|
||||
public Button pauseButton;
|
||||
public Button stopButton;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
audioSource = GetComponent<AudioSource>();
|
||||
playButton.onClick.AddListener(PlayMusic);
|
||||
pauseButton.onClick.AddListener(PauseMusic);
|
||||
stopButton.onClick.AddListener(StopMusic);
|
||||
}
|
||||
|
||||
public void PlayMusic()
|
||||
{
|
||||
isPlaying = !isPlaying;
|
||||
Trail.SetAllTrails(true, false);
|
||||
EditorManager.instance.songInformation.songTime = audioSource.time;
|
||||
if( isPlaying)audioSource.Play();
|
||||
else audioSource.Pause();
|
||||
}
|
||||
|
||||
public void PauseMusic()
|
||||
{
|
||||
isPlaying = false;
|
||||
Trail.SetAllTrails(false, false);
|
||||
EditorManager.instance.songInformation.songTime = audioSource.time;
|
||||
audioSource.Pause();
|
||||
}
|
||||
|
||||
public void StopMusic()
|
||||
{
|
||||
isPlaying = false;
|
||||
Trail.SetAllTrails(false, true);
|
||||
EditorManager.instance.songInformation.songTime = 0;
|
||||
audioSource.Stop();
|
||||
EditorManager.instance.uiManager.timeline.timePointerModule.SetRange(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,9 +44,8 @@ namespace Ichni.Editor
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (timeline.musicPlayer.isPlaying)
|
||||
if (EditorManager.instance.musicPlayer.isPlaying)
|
||||
{
|
||||
songInformation.songTime = timeline.musicPlayer.audioSource.time;
|
||||
SetRange(songInformation.songTime);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ using TMPro;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace Ichni.Editor
|
||||
@@ -23,7 +24,7 @@ namespace Ichni.Editor
|
||||
|
||||
public GameObject timelineTabRect;
|
||||
public TimePointerModule timePointerModule;
|
||||
public MusicPlayer musicPlayer;
|
||||
public MusicPlayModule musicPlayModule;
|
||||
|
||||
|
||||
public TMP_InputField TimeField;
|
||||
@@ -32,7 +33,7 @@ namespace Ichni.Editor
|
||||
public RectTransform GetinputArea;
|
||||
public void Update()
|
||||
{
|
||||
if (musicPlayer.isPlaying) UpdateTime();
|
||||
if (EditorManager.instance.musicPlayer.isPlaying) UpdateTime();
|
||||
|
||||
if (RectTransformUtility.RectangleContainsScreenPoint(GetinputArea, Mouse.current.position.ReadValue()))
|
||||
{
|
||||
@@ -85,8 +86,8 @@ namespace Ichni.Editor
|
||||
|
||||
public void SetTime(string time)
|
||||
{
|
||||
musicPlayer.PauseMusic();
|
||||
musicPlayer.audioSource.time = float.Parse(time);
|
||||
EditorManager.instance.musicPlayer.PauseMusic();
|
||||
EditorManager.instance.musicPlayer.audioSource.time = float.Parse(time);
|
||||
EditorManager.instance.songInformation.songTime = float.Parse(time);
|
||||
|
||||
timePointerModule.UpdatePointers();
|
||||
@@ -95,15 +96,13 @@ namespace Ichni.Editor
|
||||
}
|
||||
public void SetBeat(string beat)
|
||||
{
|
||||
musicPlayer.PauseMusic();
|
||||
musicPlayer.audioSource.time = float.Parse(beat) * timePerBeat;
|
||||
EditorManager.instance.musicPlayer.PauseMusic();
|
||||
EditorManager.instance.musicPlayer.audioSource.time = float.Parse(beat) * timePerBeat;
|
||||
EditorManager.instance.songInformation.songTime = float.Parse(beat) * timePerBeat;
|
||||
|
||||
timePointerModule.UpdatePointers();
|
||||
timePointerModule.SetRange(songTime);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user