2023-03-26 11:20:02 +08:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-03-29 19:58:58 +08:00
|
|
|
namespace DCFApixels.DragonECS
|
2023-03-26 11:20:02 +08:00
|
|
|
{
|
2024-03-03 03:51:49 +08:00
|
|
|
[MetaColor(MetaColor.Cyan)]
|
2024-03-10 19:23:05 +08:00
|
|
|
public readonly struct UnityGameObjectConnect : IEcsComponent, IEcsComponentLifecycle<UnityGameObjectConnect>
|
2023-03-26 11:20:02 +08:00
|
|
|
{
|
2024-03-10 09:50:20 +08:00
|
|
|
public readonly EcsEntityConnect connect;
|
2023-06-29 14:26:01 +08:00
|
|
|
public readonly Transform transform;
|
2023-03-26 11:20:02 +08:00
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-03-10 10:20:44 +08:00
|
|
|
get { return connect.name; }
|
2023-03-26 11:20:02 +08:00
|
|
|
}
|
2024-03-10 10:20:44 +08:00
|
|
|
public bool IsConnected
|
|
|
|
|
{
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
2024-03-10 19:23:05 +08:00
|
|
|
get { return connect != null; }
|
2024-03-10 10:20:44 +08:00
|
|
|
}
|
|
|
|
|
internal UnityGameObjectConnect(EcsEntityConnect connect)
|
2023-03-26 11:20:02 +08:00
|
|
|
{
|
2024-03-10 09:50:20 +08:00
|
|
|
this.connect = connect;
|
|
|
|
|
transform = connect.transform;
|
2023-03-26 11:20:02 +08:00
|
|
|
}
|
2024-03-10 19:23:05 +08:00
|
|
|
|
|
|
|
|
void IEcsComponentLifecycle<UnityGameObjectConnect>.Enable(ref UnityGameObjectConnect component)
|
|
|
|
|
{
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
|
|
|
|
void IEcsComponentLifecycle<UnityGameObjectConnect>.Disable(ref UnityGameObjectConnect component)
|
|
|
|
|
{
|
|
|
|
|
if (component.connect != null)
|
|
|
|
|
{
|
|
|
|
|
component.connect.Disconnect();
|
|
|
|
|
}
|
|
|
|
|
component = default;
|
|
|
|
|
}
|
2023-03-26 11:20:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum GameObjectIcon : byte
|
|
|
|
|
{
|
|
|
|
|
NONE,
|
|
|
|
|
Label_Gray,
|
|
|
|
|
Label_Blue,
|
|
|
|
|
Label_Teal,
|
|
|
|
|
Label_Green,
|
|
|
|
|
Label_Yellow,
|
|
|
|
|
Label_Orange,
|
|
|
|
|
Label_Red,
|
|
|
|
|
Label_Purple,
|
|
|
|
|
Circle_Gray,
|
|
|
|
|
Circle_Blue,
|
|
|
|
|
Circle_Teal,
|
|
|
|
|
Circle_Green,
|
|
|
|
|
Circle_Yellow,
|
|
|
|
|
Circle_Orange,
|
|
|
|
|
Circle_Red,
|
|
|
|
|
Circle_Purple,
|
|
|
|
|
Diamond_Gray,
|
|
|
|
|
Diamond_Blue,
|
|
|
|
|
Diamond_Teal,
|
|
|
|
|
Diamond_Green,
|
|
|
|
|
Diamond_Yellow,
|
|
|
|
|
Diamond_Orange,
|
|
|
|
|
Diamond_Red,
|
|
|
|
|
Diamond_Purple
|
|
|
|
|
}
|
|
|
|
|
public static class GameObjectIconConsts
|
|
|
|
|
{
|
|
|
|
|
public const int RAW_LABEL_ICON_LAST = (int)GameObjectIcon.Label_Purple;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class GameObjectRefExt
|
|
|
|
|
{
|
2024-03-03 03:51:49 +08:00
|
|
|
public static entlong NewEntityWithGameObject(this EcsWorld self, string name = "Entity", GameObjectIcon icon = GameObjectIcon.NONE)
|
2023-03-26 11:20:02 +08:00
|
|
|
{
|
2024-03-03 03:51:49 +08:00
|
|
|
entlong result = self.NewEntityLong();
|
2023-03-26 11:20:02 +08:00
|
|
|
GameObject newGameObject = new GameObject(name);
|
2024-03-10 09:50:20 +08:00
|
|
|
newGameObject.AddComponent<EcsEntityConnect>().ConnectWith(result, false);
|
2023-03-26 11:20:02 +08:00
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
if (icon != GameObjectIcon.NONE)
|
|
|
|
|
{
|
|
|
|
|
string contentName;
|
|
|
|
|
int number = (int)icon - 1;
|
|
|
|
|
if (number < GameObjectIconConsts.RAW_LABEL_ICON_LAST)
|
|
|
|
|
{
|
|
|
|
|
contentName = $"sv_label_{number}";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
number -= GameObjectIconConsts.RAW_LABEL_ICON_LAST;
|
|
|
|
|
contentName = $"sv_icon_dot{number}_pix16_gizmo";
|
|
|
|
|
}
|
|
|
|
|
GUIContent iconContent = EditorGUIUtility.IconContent(contentName);
|
|
|
|
|
EditorGUIUtility.SetIconForObject(newGameObject, (Texture2D)iconContent.image);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|