180 lines
5.5 KiB
C#
180 lines
5.5 KiB
C#
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Ichni.RhythmGame.Beatmap;
|
||
using Sirenix.OdinInspector;
|
||
using UnityEngine;
|
||
|
||
namespace Ichni.RhythmGame
|
||
{
|
||
public abstract partial class GameElement : SerializedMonoBehaviour, IBaseElement, IComparable<GameElement>
|
||
{
|
||
#region [属性和标记] Essential & Tracking Info
|
||
//物体名
|
||
public string elementName;
|
||
|
||
//标识 GUID
|
||
public Guid elementGuid;
|
||
|
||
//标签
|
||
public List<string> tags;
|
||
|
||
//物理层级优先级
|
||
public virtual int HierarchyPriority => 0;
|
||
|
||
//存档类
|
||
public BaseElement_BM matchedBM { get; set; }
|
||
#endregion
|
||
|
||
#region [层级从属结构] Hierarchy & Children
|
||
//父游戏物体
|
||
public GameElement parentElement;
|
||
|
||
//子物体列表
|
||
public List<GameElement> childElementList = new List<GameElement>();
|
||
#endregion
|
||
|
||
#region [附着子模块集] Components List
|
||
//次级模块
|
||
public List<SubmoduleBase> submoduleList = new List<SubmoduleBase>();
|
||
#endregion
|
||
|
||
#region [生命周期与构造] Initialization
|
||
/// <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();
|
||
}
|
||
|
||
if (this is IHaveTransformSubmodule transformSource && !GameManager.Instance.activeTransformSubmodules.Contains(transformSource))
|
||
{
|
||
GameManager.Instance.activeTransformSubmodules.Add(transformSource);
|
||
}
|
||
|
||
if (this is IHaveColorSubmodule colorSource && !GameManager.Instance.activeColorSubmodules.Contains(colorSource))
|
||
{
|
||
GameManager.Instance.activeColorSubmodules.Add(colorSource);
|
||
}
|
||
|
||
if (this is IHaveDirtyMarkSubmodule dirtySource && !GameManager.Instance.activeDirtyMarkSubmodules.Contains(dirtySource))
|
||
{
|
||
GameManager.Instance.activeDirtyMarkSubmodules.Add(dirtySource);
|
||
}
|
||
|
||
SetParent(parentElement);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 设置次级模块
|
||
/// </summary>
|
||
public virtual void SetDefaultSubmodules()
|
||
{
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region [生命周期:激活阶段] Lifecycle Events Extensions
|
||
/// <summary>
|
||
/// 在所有物体生成完毕后,执行的初始化方法
|
||
/// </summary>
|
||
public virtual void AfterInitialize()
|
||
{
|
||
matchedBM?.AfterExecute();
|
||
|
||
if (this is IHaveTransformSubmodule transformSource)
|
||
{
|
||
transformSource.transformSubmodule.CheckAndRemoveObservers();
|
||
}
|
||
|
||
if(this is IHaveColorSubmodule colorSource)
|
||
{
|
||
colorSource.colorSubmodule.CheckAndRemoveObservers();
|
||
}
|
||
}
|
||
|
||
public virtual void BeforeStart()
|
||
{
|
||
if (this is IHaveTransformSubmodule transformSource)
|
||
{
|
||
transformSource.UpdateTransform(false);
|
||
}
|
||
|
||
if (this is IHaveColorSubmodule colorSource)
|
||
{
|
||
colorSource.UpdateColor(false);
|
||
}
|
||
|
||
Refresh();
|
||
}
|
||
|
||
public virtual void WhenStart()
|
||
{
|
||
|
||
}
|
||
#endregion
|
||
|
||
#region [工具方法] Global Methods
|
||
/// <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);
|
||
}
|
||
#endregion
|
||
}
|
||
|
||
#region [额外交互及存档重写预留] Editor Interaction & Interfaces Overrides
|
||
public abstract partial class GameElement //存档,删除,复制,粘贴
|
||
{
|
||
|
||
public virtual void Refresh()
|
||
{
|
||
|
||
}
|
||
|
||
/// <summary>
|
||
/// 当物体被删除时执行的方法
|
||
/// </summary>
|
||
public virtual void OnDelete()
|
||
{
|
||
if (this is IHaveTransformSubmodule transformSource)
|
||
{
|
||
GameManager.Instance.activeTransformSubmodules.Remove(transformSource);
|
||
}
|
||
if (this is IHaveColorSubmodule colorSource)
|
||
{
|
||
GameManager.Instance.activeColorSubmodules.Remove(colorSource);
|
||
}
|
||
if (this is IHaveDirtyMarkSubmodule dirtySource)
|
||
{
|
||
GameManager.Instance.activeDirtyMarkSubmodules.Remove(dirtySource);
|
||
}
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
} |