2025-06-03 02:42:28 -04:00
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using Ichni.RhythmGame.Beatmap;
|
|
|
|
|
using Sirenix.OdinInspector;
|
2025-07-21 05:42:20 -04:00
|
|
|
using UnityEngine;
|
2025-06-03 02:42:28 -04:00
|
|
|
|
|
|
|
|
namespace Ichni.RhythmGame
|
|
|
|
|
{
|
2025-07-26 04:20:25 -04:00
|
|
|
public abstract partial class GameElement : SerializedMonoBehaviour, IBaseElement, IComparable<GameElement>
|
2025-06-03 02:42:28 -04:00
|
|
|
{
|
|
|
|
|
//物体名
|
|
|
|
|
public string elementName;
|
|
|
|
|
|
|
|
|
|
//标识 GUID
|
|
|
|
|
public Guid elementGuid;
|
|
|
|
|
|
|
|
|
|
//标签
|
|
|
|
|
public List<string> tags;
|
|
|
|
|
|
|
|
|
|
//父游戏物体
|
|
|
|
|
public GameElement parentElement;
|
|
|
|
|
|
|
|
|
|
//子物体列表
|
|
|
|
|
public List<GameElement> childElementList = new List<GameElement>();
|
|
|
|
|
|
|
|
|
|
//次级模块
|
|
|
|
|
public List<SubmoduleBase> submoduleList = new List<SubmoduleBase>();
|
|
|
|
|
|
|
|
|
|
//存档类
|
|
|
|
|
public BaseElement_BM matchedBM { get; set; }
|
|
|
|
|
|
|
|
|
|
public virtual int HierarchyPriority => 0;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 首次初始化
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="name">物体名</param>
|
|
|
|
|
public virtual void Initialize(string name, Guid elementGuid, List<string> tags,
|
|
|
|
|
bool isFirstGenerated, GameElement parentElement)
|
|
|
|
|
{
|
|
|
|
|
this.elementName = name;
|
|
|
|
|
this.elementGuid = elementGuid;
|
|
|
|
|
this.tags = tags;
|
|
|
|
|
GameManager.instance.beatmapContainer.gameElementList.Add(this);
|
|
|
|
|
submoduleList = new List<SubmoduleBase>();
|
|
|
|
|
|
|
|
|
|
if (isFirstGenerated)
|
|
|
|
|
{
|
|
|
|
|
SetDefaultSubmodules();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
SetParent(parentElement);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置次级模块
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void SetDefaultSubmodules()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
2025-07-21 05:42:20 -04:00
|
|
|
|
2025-06-03 02:42:28 -04:00
|
|
|
/// <summary>
|
|
|
|
|
/// 在所有物体生成完毕后,执行的初始化方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void AfterInitialize()
|
|
|
|
|
{
|
2025-07-21 05:42:20 -04:00
|
|
|
matchedBM?.AfterExecute();
|
|
|
|
|
|
|
|
|
|
if (this is IHaveTransformSubmodule transformSource)
|
|
|
|
|
{
|
|
|
|
|
transformSource.transformSubmodule.CheckAndRemoveObservers();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this is IHaveColorSubmodule colorSource)
|
|
|
|
|
{
|
|
|
|
|
colorSource.colorSubmodule.CheckAndRemoveObservers();
|
|
|
|
|
}
|
2025-06-03 02:42:28 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 设置父物体
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="parentElement">父物体</param>
|
|
|
|
|
public void SetParent(GameElement parentElement)
|
|
|
|
|
{
|
|
|
|
|
if (parentElement != null)
|
|
|
|
|
{
|
|
|
|
|
parentElement.childElementList.Add(this);
|
|
|
|
|
this.parentElement = parentElement;
|
|
|
|
|
transform.SetParent(parentElement.transform);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int CompareTo(GameElement other)
|
|
|
|
|
{
|
|
|
|
|
return HierarchyPriority.CompareTo(other.HierarchyPriority);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public abstract partial class GameElement //存档,删除,复制,粘贴
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public virtual void Refresh()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 用于生成存档
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void SaveBM()
|
|
|
|
|
{
|
|
|
|
|
throw new NotImplementedException();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 当物体被删除时执行的方法
|
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual void OnDelete()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Beatmap
|
|
|
|
|
{
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public abstract class GameElement_BM : BaseElement_BM
|
|
|
|
|
{
|
|
|
|
|
[System.NonSerialized]
|
|
|
|
|
public static Dictionary<Guid, GameElement_BM> identifier = new(); //存档类的标识符
|
|
|
|
|
|
|
|
|
|
[System.NonSerialized]
|
|
|
|
|
public GameElement matchedElement; //存档类对应的游戏物体
|
|
|
|
|
|
|
|
|
|
public string elementName;
|
|
|
|
|
public List<string> tags;
|
|
|
|
|
public Guid elementGuid;
|
|
|
|
|
|
|
|
|
|
public GameElement_BM()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public GameElement_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement)
|
|
|
|
|
{
|
|
|
|
|
this.elementName = elementName;
|
|
|
|
|
this.elementGuid = elementGuid;
|
|
|
|
|
this.tags = tags;
|
|
|
|
|
|
|
|
|
|
this.attachedElementGuid = attachedElement?.elementGuid ?? Guid.Empty;
|
|
|
|
|
|
|
|
|
|
identifier.TryAdd(this.elementGuid, this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameElement_BM GetElementBM(Guid id)
|
|
|
|
|
{
|
|
|
|
|
if (identifier.TryGetValue(id, out GameElement_BM element_BM))
|
|
|
|
|
{
|
|
|
|
|
return element_BM;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static GameElement GetElement(Guid id)
|
|
|
|
|
{
|
|
|
|
|
if (identifier.TryGetValue(id, out GameElement_BM element_BM))
|
|
|
|
|
{
|
|
|
|
|
return element_BM.matchedElement;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 复制物体
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="attached">父物体</param>
|
|
|
|
|
public abstract GameElement DuplicateBM(GameElement attached);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static List<BaseElement_BM> GetAllAttachedBaseElements(GameElement_BM gameElement, List<BaseElement_BM> clip)
|
|
|
|
|
{
|
|
|
|
|
Guid elementGuid = gameElement.elementGuid;
|
|
|
|
|
List<BaseElement_BM> result = new List<BaseElement_BM>();
|
|
|
|
|
foreach (BaseElement_BM element in clip)
|
|
|
|
|
{
|
|
|
|
|
if (element.attachedElementGuid == elementGuid)
|
|
|
|
|
{
|
|
|
|
|
result.Add(element);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|