2025-01-26 21:10:16 -05:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2025-02-02 08:34:54 -05:00
|
|
|
|
using Ichni.RhythmGame.Beatmap;
|
2025-01-26 21:10:16 -05:00
|
|
|
|
using Sirenix.OdinInspector;
|
2025-01-29 23:49:18 -05:00
|
|
|
|
using UniRx;
|
2025-01-26 21:10:16 -05:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ichni.RhythmGame
|
|
|
|
|
|
{
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
|
public abstract partial class BaseElement : SerializedMonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
//物体名
|
|
|
|
|
|
public string elementName;
|
|
|
|
|
|
|
|
|
|
|
|
//标识 GUID
|
|
|
|
|
|
public Guid elementGuid;
|
|
|
|
|
|
|
2025-01-30 22:45:33 -05:00
|
|
|
|
//标签
|
|
|
|
|
|
public List<string> tags;
|
|
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
//存档
|
2025-02-02 08:34:54 -05:00
|
|
|
|
public BaseElement_BM matchedBM;
|
2025-01-26 21:10:16 -05:00
|
|
|
|
|
|
|
|
|
|
//父游戏物体
|
|
|
|
|
|
public BaseElement parentElement;
|
|
|
|
|
|
|
|
|
|
|
|
//子物体列表
|
|
|
|
|
|
public List<BaseElement> childElementList = new List<BaseElement>();
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
//次级模块
|
2025-02-07 00:37:50 -05:00
|
|
|
|
public List<SubmoduleBase> submoduleList = new List<SubmoduleBase>();
|
|
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
public TimeDurationSubmodule timeDurationSubmodule;
|
|
|
|
|
|
public TransformSubmodule transformSubmodule;
|
2025-01-29 23:49:18 -05:00
|
|
|
|
public ColorSubmodule colorSubmodule;
|
2025-01-26 21:10:16 -05:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 首次初始化
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="name">物体名</param>
|
2025-02-02 08:34:54 -05:00
|
|
|
|
public virtual void Initialize(string name, Guid elementGuid, List<string> tags)
|
2025-01-26 21:10:16 -05:00
|
|
|
|
{
|
|
|
|
|
|
this.elementName = name;
|
2025-02-02 08:34:54 -05:00
|
|
|
|
this.elementGuid = elementGuid;
|
|
|
|
|
|
this.tags = tags;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
EditorManager.instance.elementList.Add(this);
|
2025-01-26 21:10:16 -05:00
|
|
|
|
//GameManager.beatMapContainer.beatMapElementList.Add(this);
|
|
|
|
|
|
//serialNumber = totalSerialNumber++;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
//SetTransformObserver();
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 在所有物体生成完毕后,执行的初始化方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void AfterInitialize()
|
|
|
|
|
|
{
|
2025-02-07 00:37:50 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 刷新物体的状态
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void Refresh()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
2025-01-30 22:45:33 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置父物体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="parentElement">父物体</param>
|
|
|
|
|
|
public void SetParent(BaseElement parentElement)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (parentElement != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
parentElement.childElementList.Add(this);
|
|
|
|
|
|
this.parentElement = parentElement;
|
|
|
|
|
|
transform.SetParent(parentElement.transform);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
public abstract partial class BaseElement
|
|
|
|
|
|
{
|
2025-01-29 23:49:18 -05:00
|
|
|
|
private void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
SetTransformObserver();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
public virtual void SetTimeDuration()
|
|
|
|
|
|
{
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
public void ApplyTimeDuration()
|
|
|
|
|
|
{
|
|
|
|
|
|
childElementList.ForEach(x => x.ApplyTimeDuration());
|
2025-02-02 08:34:54 -05:00
|
|
|
|
timeDurationSubmodule?.SetDurationFromChildren(childElementList.Select(x => x.timeDurationSubmodule)
|
|
|
|
|
|
.ToList());
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|
2025-01-29 23:49:18 -05:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置物体Transform的监听,顺序为Scale -> EulerAngles -> Position
|
|
|
|
|
|
/// 如果有一些特殊的物体(例如Camera,ElementFolder),需要自定义监听,可以重写这个方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void SetTransformObserver()
|
|
|
|
|
|
{
|
|
|
|
|
|
Observable.EveryUpdate().Subscribe(_ =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (transformSubmodule == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (transformSubmodule.scaleDirtyMark)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 offset = Vector3.zero;
|
|
|
|
|
|
foreach (Vector3 scaleOffset in transformSubmodule.scaleOffset)
|
|
|
|
|
|
{
|
|
|
|
|
|
offset += scaleOffset;
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
transformSubmodule.currentScale = transformSubmodule.originalScale + offset;
|
|
|
|
|
|
transform.localScale = transformSubmodule.currentScale;
|
|
|
|
|
|
transformSubmodule.scaleDirtyMark = false;
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
if (transformSubmodule.eulerAnglesDirtyMark)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 offset = Vector3.zero;
|
|
|
|
|
|
foreach (Vector3 eulerOffset in transformSubmodule.eulerAnglesOffset)
|
|
|
|
|
|
{
|
|
|
|
|
|
offset += eulerOffset;
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + offset;
|
|
|
|
|
|
transform.localEulerAngles = transformSubmodule.currentEulerAngles;
|
|
|
|
|
|
transformSubmodule.eulerAnglesDirtyMark = false;
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
if (transformSubmodule.positionDirtyMark)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 offset = Vector3.zero;
|
|
|
|
|
|
foreach (Vector3 posOffset in transformSubmodule.positionOffset)
|
|
|
|
|
|
{
|
|
|
|
|
|
offset += posOffset;
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
transformSubmodule.currentPosition = transformSubmodule.originalPosition + offset;
|
|
|
|
|
|
transform.localPosition = transformSubmodule.currentPosition;
|
|
|
|
|
|
transformSubmodule.positionDirtyMark = false;
|
|
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
transformSubmodule.scaleOffset.Clear();
|
|
|
|
|
|
transformSubmodule.eulerAnglesOffset.Clear();
|
|
|
|
|
|
transformSubmodule.positionOffset.Clear();
|
|
|
|
|
|
}).AddTo(gameObject);
|
|
|
|
|
|
}
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|
2025-02-02 08:34:54 -05:00
|
|
|
|
|
|
|
|
|
|
public abstract partial class BaseElement //存档,删除,复制,粘贴
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于生成存档
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract void SaveBM();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 当物体被删除时执行的方法
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public virtual void OnDelete()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 删除物体,包括所有子物体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[Button("Delete")]
|
|
|
|
|
|
public virtual void Delete()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.childElementList != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
for (int i = 0; i < childElementList.Count; i++)
|
|
|
|
|
|
{
|
|
|
|
|
|
childElementList[i].Delete(); //删除子GameElement、
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OnDelete();
|
|
|
|
|
|
|
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
|
Debug.Log("Delete " + elementName + "(" + elementGuid + ")");
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
EditorManager.instance.elementList.Remove(this); //从保存列表中剔除
|
|
|
|
|
|
this.parentElement.childElementList.Remove(this);
|
|
|
|
|
|
Destroy(gameObject); //销毁
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace Beatmap
|
|
|
|
|
|
{
|
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
|
public abstract class BaseElement_BM
|
|
|
|
|
|
{
|
|
|
|
|
|
[System.NonSerialized] public static Dictionary<Guid, BaseElement_BM> identifier; //存档类的标识符
|
|
|
|
|
|
|
|
|
|
|
|
[System.NonSerialized] public BaseElement matchedElement; //存档类对应的游戏物体
|
|
|
|
|
|
public string elementName;
|
|
|
|
|
|
public List<string> tags;
|
|
|
|
|
|
public Guid elementGuid;
|
|
|
|
|
|
public Guid attachedElementGuid;
|
|
|
|
|
|
|
|
|
|
|
|
public BaseElement_BM()
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public BaseElement_BM(string elementName, Guid elementGuid, List<string> tags, BaseElement_BM attachedElement)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.elementName = elementName;
|
|
|
|
|
|
this.elementGuid = elementGuid;
|
|
|
|
|
|
this.tags = tags;
|
|
|
|
|
|
|
|
|
|
|
|
this.attachedElementGuid = attachedElement?.elementGuid ?? Guid.Empty;
|
|
|
|
|
|
|
|
|
|
|
|
identifier.TryAdd(this.elementGuid, this);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static BaseElement_BM GetElementBM(Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (identifier.TryGetValue(id, out BaseElement_BM element_BM))
|
|
|
|
|
|
{
|
|
|
|
|
|
return element_BM;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Debug.LogAssertion("Element not found or do not have id");
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static BaseElement GetElement(Guid id)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetElementBM(id)?.matchedElement;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于从存档中生成物体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract void ExecuteBM();
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 用于复制物体
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public abstract BaseElement DuplicateBM(BaseElement parent);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|