Files
ichni_Creator_Studio/Assets/Scripts/DynamicUI/DynamicUIElements/Simple/DynamicUIElement.cs

75 lines
2.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using Ichni.RhythmGame;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
namespace Ichni.Editor
{
public abstract class DynamicUIElement : MonoBehaviour
{
Inspector Inspector => EditorManager.instance.uiManager.inspector;
public TMP_Text title;
public CanvasGroup canvasGroup;
public IBaseElement connectedBaseElement;
/// <summary>
/// 参数名,通过反射获取饿修改对应变量的值
/// </summary>
public string parameterName;
public virtual void Initialize(IBaseElement baseElement, string title, string parameterName)
{
if (canvasGroup == null) canvasGroup = gameObject.AddComponent<CanvasGroup>();
this.connectedBaseElement = baseElement;
this.parameterName = parameterName;
if (title != string.Empty)
{
this.title.text = title;
}
else
{
this.title.gameObject.SetActive(false);
}
}
public DynamicUIElement Mark(string mark = "Default", IHaveInspection inspection = null)
{
inspection ??= Inspector;
if (mark == "Default")
{
mark = title.text;
}
inspection.MarkedElements.TryAdd(mark, this);
return this;
}
public abstract DynamicUIElement AddListenerFunction(UnityAction action);
}
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();
}
public interface ICanSetLinkedBaseElement
{
public void SetLinkedBaseElement(IBaseElement baseElement, string parameterName);
}
}