using System;
using UnityEditor;
using UnityEngine;
namespace XGame.Editor.Asset.Addressable
{
public abstract class AddressableAssetEntry : IComparable
{
public enum EntryType
{
None = 0,
Fold,
File
}
///
/// 路径
///
public string Path { private set; get; }
///
/// 显示的名字
///
public string ShowName { private set; get; }
///
/// 文件夹开启标志
///
public bool IsFoldout { set; get; }
public virtual EntryType EnType => EntryType.None;
private AddressableAssetEntry parent;
public AddressableAssetEntry Parent
{
set
{
parent = value;
OnSetParent();
}
get => parent;
}
protected AddressableAssetEntry(string path)
{
Path = path;
ShowName = System.IO.Path.GetFileNameWithoutExtension(path);
}
public void GUI()
{
bool hasParent = parent != null;
if (hasParent)
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space(10);
}
OnGUI();
if (hasParent)
{
EditorGUILayout.EndHorizontal();
}
}
public void Clear()
{
OnClear();
}
protected abstract void OnSetParent();
protected abstract void OnGUI();
protected abstract void OnClear();
public int CompareTo(object obj)
{
int result = 0;
if (obj is AddressableAssetEntry compare)
{
result = EnType - compare.EnType;
if (result == 0)
{
result = string.Compare(ShowName, compare.ShowName, StringComparison.OrdinalIgnoreCase);
}
}
return result;
}
}
}