2024-10-11 10:12:15 +08:00
|
|
|
|
|
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
#endif
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace Ether
|
|
|
|
|
{
|
|
|
|
|
[DisallowMultipleComponent]
|
|
|
|
|
public class Entity : SerializedMonoBehaviour
|
|
|
|
|
{
|
2024-10-30 17:58:20 +08:00
|
|
|
|
[Header("实例配置")]
|
2024-10-11 10:12:15 +08:00
|
|
|
|
[LabelText("唯一Key值")]
|
2024-10-30 17:58:20 +08:00
|
|
|
|
[PropertyOrder(-10)]
|
2024-10-11 10:12:15 +08:00
|
|
|
|
public string key;
|
|
|
|
|
[LabelText("不销毁对象")]
|
2024-10-30 17:58:20 +08:00
|
|
|
|
[PropertyOrder(-9)]
|
2024-10-11 10:12:15 +08:00
|
|
|
|
public bool dontDestroy;
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
EntityManager.Inst.AddEntity(this);
|
|
|
|
|
|
|
|
|
|
if (dontDestroy)
|
|
|
|
|
{
|
|
|
|
|
GameObject.DontDestroyOnLoad(this);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-11-01 14:07:47 +08:00
|
|
|
|
protected virtual void OnClear()
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-11 10:12:15 +08:00
|
|
|
|
private void OnDestroy()
|
|
|
|
|
{
|
|
|
|
|
EntityManager.Inst.RemoveEntity(this);
|
2024-11-01 14:07:47 +08:00
|
|
|
|
OnClear();
|
2024-10-11 10:12:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnApplicationQuit()
|
|
|
|
|
{
|
|
|
|
|
DestroyImmediate(gameObject);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnValidate()
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrEmpty(key))
|
|
|
|
|
{
|
|
|
|
|
GenerateKey();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-30 17:58:20 +08:00
|
|
|
|
[PropertySpace(5, 20)]
|
2024-10-11 10:12:15 +08:00
|
|
|
|
[ButtonGroup("ButtonGroup")]
|
|
|
|
|
[Button("生成唯一Key", ButtonSizes.Medium)]
|
2024-10-30 17:58:20 +08:00
|
|
|
|
[PropertyOrder(-8)]
|
2024-10-11 10:12:15 +08:00
|
|
|
|
public void GenerateKey()
|
|
|
|
|
{
|
|
|
|
|
// 获取当前时间戳并转换为int类型
|
|
|
|
|
//System.DateTime startTime = new System.DateTime(1970, 1, 1);
|
|
|
|
|
//System.TimeSpan timeSinceStartTime = System.DateTime.Now - startTime;
|
|
|
|
|
//id = (long)timeSinceStartTime.TotalMilliseconds;
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
key = GUID.Generate().ToString();
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|