mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-07 16:45:10 +00:00
Entitas
Entitas
This commit is contained in:
15
Assets/GameScripts/DotNet/Core/Entitas/ComponentView.cs
Normal file
15
Assets/GameScripts/DotNet/Core/Entitas/ComponentView.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class ComponentView: MonoBehaviour
|
||||
{
|
||||
public Entity Component
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 24bef9ebd1ca4a1cb8db0fba17ec5b2b
|
||||
timeCreated: 1689576818
|
@@ -28,6 +28,11 @@ namespace TEngine
|
||||
|
||||
public abstract class Entity : IDisposable
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
[UnityEngine.HideInInspector]
|
||||
public UnityEngine.GameObject ViewGO;
|
||||
#endif
|
||||
|
||||
#region Status
|
||||
[BsonIgnore]
|
||||
[IgnoreDataMember]
|
||||
@@ -107,13 +112,7 @@ namespace TEngine
|
||||
|
||||
[BsonIgnore]
|
||||
[IgnoreDataMember]
|
||||
protected virtual string ViewName
|
||||
{
|
||||
get
|
||||
{
|
||||
return this.GetType().FullName;
|
||||
}
|
||||
}
|
||||
protected virtual string ViewName => this.GetType().Name;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -222,8 +221,17 @@ namespace TEngine
|
||||
EntitiesSystem.Instance.Awake(entity);
|
||||
EntitiesSystem.Instance.StartUpdate(entity);
|
||||
}
|
||||
|
||||
|
||||
entity.IsCreated = true;
|
||||
entity.IsNew = true;
|
||||
entity.OnCreate();
|
||||
#if UNITY_EDITOR
|
||||
entity.ViewGO = new UnityEngine.GameObject(entity.ViewName);
|
||||
entity.ViewGO.AddComponent<ComponentView>().Component = entity;
|
||||
entity.ViewGO.transform.SetParent(entity.Parent == null?
|
||||
UnityEngine.GameObject.Find("[EntitySystem]").transform : entity.Parent.ViewGO.transform);
|
||||
#endif
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -246,6 +254,13 @@ namespace TEngine
|
||||
}
|
||||
entity.IsCreated = true;
|
||||
entity.IsNew = true;
|
||||
entity.OnCreate();
|
||||
#if UNITY_EDITOR
|
||||
entity.ViewGO = new UnityEngine.GameObject(entity.ViewName);
|
||||
entity.ViewGO.AddComponent<ComponentView>().Component = entity;
|
||||
entity.ViewGO.transform.SetParent(entity.Parent == null?
|
||||
UnityEngine.GameObject.Find("[EntitySystem]").transform : entity.Parent.ViewGO.transform);
|
||||
#endif
|
||||
return entity;
|
||||
}
|
||||
|
||||
@@ -375,6 +390,15 @@ namespace TEngine
|
||||
component.Parent = this;
|
||||
component.Scene = Scene;
|
||||
component.IsComponent = true;
|
||||
#if UNITY_EDITOR
|
||||
if (component.ViewGO == null)
|
||||
{
|
||||
Log.Error($"{component} ‘s component.ViewGO is null");
|
||||
return;
|
||||
}
|
||||
component.ViewGO.transform.SetParent(component.Parent == null?
|
||||
UnityEngine.GameObject.Find("[EntitySystem]").transform : component.Parent.ViewGO.transform);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -570,6 +594,10 @@ namespace TEngine
|
||||
|
||||
#endregion
|
||||
|
||||
#region OnCreate
|
||||
public virtual void OnCreate() { }
|
||||
#endregion
|
||||
|
||||
#region Dispose
|
||||
|
||||
public virtual void Dispose()
|
||||
@@ -638,6 +666,15 @@ namespace TEngine
|
||||
Entities.Remove(runtimeId);
|
||||
Scene = null;
|
||||
Return(this);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
if (this.ViewGO == null)
|
||||
{
|
||||
Log.Error($"{this} ‘s ViewGO is null");
|
||||
return;
|
||||
}
|
||||
UnityEngine.Object.Destroy(this.ViewGO);;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@@ -1,8 +1,12 @@
|
||||
#if TENGINE_NET
|
||||
using System.ComponentModel;
|
||||
using MongoDB.Bson;
|
||||
using MongoDB.Bson.IO;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Bson.Serialization.Conventions;
|
||||
using TrueSync;
|
||||
using Unity.Mathematics;
|
||||
using MongoHelper = TEngine.Core.MongoHelper;
|
||||
|
||||
namespace TEngine.Core;
|
||||
|
||||
@@ -15,10 +19,21 @@ public sealed class MongoHelper : Singleton<MongoHelper>
|
||||
// 自动注册IgnoreExtraElements
|
||||
var conventionPack = new ConventionPack {new IgnoreExtraElementsConvention(true)};
|
||||
ConventionRegistry.Register("IgnoreExtraElements", conventionPack, type => true);
|
||||
BsonSerializer.TryRegisterSerializer(typeof(float2), new StructBsonSerialize<float2>());
|
||||
BsonSerializer.TryRegisterSerializer(typeof(float3), new StructBsonSerialize<float3>());
|
||||
BsonSerializer.TryRegisterSerializer(typeof(float4), new StructBsonSerialize<float4>());
|
||||
BsonSerializer.TryRegisterSerializer(typeof(quaternion), new StructBsonSerialize<quaternion>());
|
||||
RegisterStruct<float2>();
|
||||
RegisterStruct<float3>();
|
||||
RegisterStruct<float4>();
|
||||
RegisterStruct<quaternion>();
|
||||
|
||||
RegisterStruct<FP>();
|
||||
RegisterStruct<TSVector>();
|
||||
RegisterStruct<TSVector2>();
|
||||
RegisterStruct<TSVector4>();
|
||||
RegisterStruct<TSQuaternion>();
|
||||
}
|
||||
|
||||
public static void RegisterStruct<T>() where T : struct
|
||||
{
|
||||
BsonSerializer.RegisterSerializer(typeof (T), new StructBsonSerialize<T>());
|
||||
}
|
||||
|
||||
protected override void OnLoad(int assemblyName)
|
||||
@@ -43,6 +58,43 @@ public sealed class MongoHelper : Singleton<MongoHelper>
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly JsonWriterSettings defaultSettings = new() { OutputMode = JsonOutputMode.RelaxedExtendedJson };
|
||||
|
||||
public static string ToJson(object obj)
|
||||
{
|
||||
if (obj is ISupportInitialize supportInitialize)
|
||||
{
|
||||
supportInitialize.BeginInit();
|
||||
}
|
||||
return obj.ToJson(defaultSettings);
|
||||
}
|
||||
|
||||
public static string ToJson(object obj, JsonWriterSettings settings)
|
||||
{
|
||||
if (obj is ISupportInitialize supportInitialize)
|
||||
{
|
||||
supportInitialize.BeginInit();
|
||||
}
|
||||
return obj.ToJson(settings);
|
||||
}
|
||||
|
||||
public static T FromJson<T>(string str)
|
||||
{
|
||||
try
|
||||
{
|
||||
return BsonSerializer.Deserialize<T>(str);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new Exception($"{str}\n{e}");
|
||||
}
|
||||
}
|
||||
|
||||
public static object FromJson(Type type, string str)
|
||||
{
|
||||
return BsonSerializer.Deserialize(str, type);
|
||||
}
|
||||
|
||||
public T Deserialize<T>(byte[] bytes)
|
||||
{
|
||||
|
@@ -13,7 +13,7 @@ namespace TEngine
|
||||
{
|
||||
// 初始化框架
|
||||
GameContext.Init();
|
||||
new GameObject("[TEngine.Unity]").AddComponent<GameSystem>();
|
||||
new GameObject("[EntitySystem]").AddComponent<GameSystem>();
|
||||
// 框架需要一个Scene来驱动、所以要创建一个Scene、后面所有的框架都会在这个Scene下
|
||||
// 也就是把这个Scene给卸载掉、框架的东西都会清除掉
|
||||
return Scene.Create("Unity");
|
||||
|
8
Assets/GameScripts/Editor/Entitas.meta
Normal file
8
Assets/GameScripts/Editor/Entitas.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c152230ddf4e46458f1bd516e896129
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
102
Assets/GameScripts/Editor/Entitas/ComponentViewEditor.cs
Normal file
102
Assets/GameScripts/Editor/Entitas/ComponentViewEditor.cs
Normal file
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using TEngine;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[CustomEditor(typeof(ComponentView))]
|
||||
public class ComponentViewEditor : OdinEditor
|
||||
{
|
||||
public override void OnInspectorGUI()
|
||||
{
|
||||
ComponentView componentView = (ComponentView)target;
|
||||
Entity component = componentView.Component;
|
||||
ComponentViewHelper.Draw(component);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ComponentViewHelper
|
||||
{
|
||||
private static readonly List<ITypeDrawer> typeDrawers = new List<ITypeDrawer>();
|
||||
|
||||
static ComponentViewHelper()
|
||||
{
|
||||
Assembly assembly = typeof(ComponentViewHelper).Assembly;
|
||||
foreach (Type type in assembly.GetTypes())
|
||||
{
|
||||
if (!type.IsDefined(typeof(TypeDrawerAttribute)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ITypeDrawer iTypeDrawer = (ITypeDrawer)Activator.CreateInstance(type);
|
||||
typeDrawers.Add(iTypeDrawer);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Draw(Entity entity)
|
||||
{
|
||||
try
|
||||
{
|
||||
FieldInfo[] fields = entity.GetType()
|
||||
.GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance |
|
||||
BindingFlags.FlattenHierarchy);
|
||||
|
||||
EditorGUILayout.BeginVertical();
|
||||
|
||||
EditorGUILayout.LongField("RuntimeId: ", entity.RuntimeId);
|
||||
|
||||
EditorGUILayout.LongField("Id: ", entity.Id);
|
||||
|
||||
foreach (FieldInfo fieldInfo in fields)
|
||||
{
|
||||
Type type = fieldInfo.FieldType;
|
||||
if (type.IsDefined(typeof(HideInInspector), false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (fieldInfo.IsDefined(typeof(HideInInspector), false))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
object value = fieldInfo.GetValue(entity);
|
||||
|
||||
foreach (ITypeDrawer typeDrawer in typeDrawers)
|
||||
{
|
||||
if (!typeDrawer.HandlesType(type))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
string fieldName = fieldInfo.Name;
|
||||
if (fieldName.Length > 17 && fieldName.Contains("k__BackingField"))
|
||||
{
|
||||
fieldName = fieldName.Substring(1, fieldName.Length - 17);
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
value = typeDrawer.DrawAndGetNewValue(type, fieldName, value, null);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e);
|
||||
}
|
||||
|
||||
fieldInfo.SetValue(entity, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
EditorGUILayout.EndVertical();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.Log($"component view error: {entity.GetType().FullName} {e}");
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe2aac3a6ed717d4da185a29f2d2a386
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
11
Assets/GameScripts/Editor/Entitas/ITypeDrawer.cs
Normal file
11
Assets/GameScripts/Editor/Entitas/ITypeDrawer.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public interface ITypeDrawer
|
||||
{
|
||||
bool HandlesType(Type type);
|
||||
|
||||
object DrawAndGetNewValue(Type memberType, string memberName, object value, object target);
|
||||
}
|
||||
}
|
3
Assets/GameScripts/Editor/Entitas/ITypeDrawer.cs.meta
Normal file
3
Assets/GameScripts/Editor/Entitas/ITypeDrawer.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ba82988cd3f6426cbb858d18eed4a8bb
|
||||
timeCreated: 1689578308
|
3
Assets/GameScripts/Editor/Entitas/TypeDrawer.meta
Normal file
3
Assets/GameScripts/Editor/Entitas/TypeDrawer.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 965c500db0aa46ac9a6ff0fe19a9adda
|
||||
timeCreated: 1689578308
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class AnimationCurveTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (AnimationCurve);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.CurveField(memberName, (AnimationCurve) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae2555143c20c6b49825eaa645fc626b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class BoolTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (bool);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.Toggle(memberName, (bool) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e8022a6e902073946b421230f287c214
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class BoundsTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (Bounds);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.BoundsField(memberName, (Bounds) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56a153b48484f394cae46d7f2eed3b1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class CharTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (char);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
var str = EditorGUILayout.TextField(memberName, ((char) value).ToString());
|
||||
return str.Length > 0? str[0] : default (char);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0ec6e79217cb2ea4abbd149361850719
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class ColorTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (Color);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.ColorField(memberName, (Color) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 89557fe3279f2cf43b9ab573d50af140
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class DateTimeTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (DateTime);
|
||||
}
|
||||
|
||||
// Note: This is a very basic implementation. The ToString() method conversion will cut off milliseconds.
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
var dateString = value.ToString();
|
||||
var newDateString = EditorGUILayout.TextField(memberName, dateString);
|
||||
|
||||
return newDateString != dateString
|
||||
? DateTime.Parse(newDateString)
|
||||
: value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0d0ce2464429cf4da779507e0707feb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class DictionaryIntLongTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (Dictionary<int, long>);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
Dictionary<int, long> dictionary = value as Dictionary<int, long>;
|
||||
|
||||
EditorGUILayout.LabelField($"{memberName}:");
|
||||
foreach ((int k, long v) in dictionary)
|
||||
{
|
||||
if (v == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
EditorGUILayout.LongField($" {k} :", v);
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b4f3ad48c3023dd4f9dbe2a6145be126
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class DoubleTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (double);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.DoubleField(memberName, (double) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7fb2f1ae08fdc643932c03d2fbdf7e5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,39 @@
|
||||
#if ENABLE_VIEW
|
||||
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class EntityRefTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
if (!type.IsGenericType)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (type.GetGenericTypeDefinition() == typeof (EntityRef<>))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
FieldInfo fieldInfo = memberType.GetField("entity", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
Entity entity = (Entity)fieldInfo.GetValue(value);
|
||||
GameObject go = entity?.ViewGO;
|
||||
EditorGUILayout.ObjectField(memberName, go, memberType, true);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e13b5d8e25f279649895512cc6b21123
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,24 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class EnumTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type.IsEnum;
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
if (memberType.IsDefined(typeof (FlagsAttribute), false))
|
||||
{
|
||||
return EditorGUILayout.EnumFlagsField(memberName, (Enum) value);
|
||||
}
|
||||
|
||||
return EditorGUILayout.EnumPopup(memberName, (Enum) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 29e6926674d4e6f49ad2bb925191c912
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class FloatTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (float);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.FloatField(memberName, (float) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a812828c88a51f5438ac4f10d680daec
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class IntTypeDrawer: ITypeDrawer
|
||||
{
|
||||
[TypeDrawer]
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (int);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.IntField(memberName, (int) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bd314885fe993aa4995e2664c02d4aa5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class LongTypeDrawer: ITypeDrawer
|
||||
{
|
||||
[TypeDrawer]
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (long);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.LongField(memberName, (long) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d89f15e267d1ef04896ceed73e57d8f0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class RectTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (Rect);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.RectField(memberName, (Rect) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 051d3ab57c4efe346abdff5c64a4feee
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class StringTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (string);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.DelayedTextField(memberName, (string) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 30bc09383e1bc14409c952170fe70661
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class UnityObjectTypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (UnityEngine.Object) ||
|
||||
type.IsSubclassOf(typeof (UnityEngine.Object));
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.ObjectField(memberName, (UnityEngine.Object) value, memberType, true);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a810aa11d0c17e548848c1745dbdb30c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class Vector2TypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (Vector2);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.Vector2Field(memberName, (Vector2) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fac773feb8b254c409b8568ff7fbca16
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class Vector3TypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (Vector3);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.Vector3Field(memberName, (Vector3) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b3229d49b3d935d41ae02afae1cc675f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
[TypeDrawer]
|
||||
public class Vector4TypeDrawer: ITypeDrawer
|
||||
{
|
||||
public bool HandlesType(Type type)
|
||||
{
|
||||
return type == typeof (Vector4);
|
||||
}
|
||||
|
||||
public object DrawAndGetNewValue(Type memberType, string memberName, object value, object target)
|
||||
{
|
||||
return EditorGUILayout.Vector4Field(memberName, (Vector4) value);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8455282b831decd44b5b15289adbe6db
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
6
Assets/GameScripts/Editor/Entitas/TypeDrawerAttribute.cs
Normal file
6
Assets/GameScripts/Editor/Entitas/TypeDrawerAttribute.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
using System;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public class TypeDrawerAttribute: Attribute { }
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 64d93f1343d249ea98a11ad1dfe9dc7d
|
||||
timeCreated: 1689578308
|
3
Assets/GameScripts/HotFix/GameLogic/BattleDemo.meta
Normal file
3
Assets/GameScripts/HotFix/GameLogic/BattleDemo.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab10a5a730054c5aaa942164c750abfb
|
||||
timeCreated: 1689576189
|
3
Assets/GameScripts/HotFix/GameLogic/BattleDemo/Core.meta
Normal file
3
Assets/GameScripts/HotFix/GameLogic/BattleDemo/Core.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 94212c40840344b5bd6ba4fc82097d47
|
||||
timeCreated: 1689576337
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78e93a657ea64d5d97000e8b6cc83ffc
|
||||
timeCreated: 1689576342
|
@@ -0,0 +1,20 @@
|
||||
using TEngine;
|
||||
|
||||
namespace GameLogic.BattleDemo
|
||||
{
|
||||
/// <summary>
|
||||
/// 逻辑层实体。
|
||||
/// </summary>
|
||||
public abstract class EntityLogic : Entity
|
||||
{
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e7b01c5b166445d680dc411dfbe5c781
|
||||
timeCreated: 1689576203
|
@@ -0,0 +1,15 @@
|
||||
namespace GameLogic.BattleDemo
|
||||
{
|
||||
public class PlayerEntity : EntityLogic
|
||||
{
|
||||
public override void OnCreate()
|
||||
{
|
||||
base.OnCreate();
|
||||
}
|
||||
|
||||
public override void Dispose()
|
||||
{
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9939517fe9f04f0d9c0c544fbdd43564
|
||||
timeCreated: 1689576650
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fad718b498934a5d8c63aa6d1e115485
|
||||
timeCreated: 1689576347
|
@@ -0,0 +1,14 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic.BattleDemo
|
||||
{
|
||||
/// <summary>
|
||||
/// 表现层实体。
|
||||
/// </summary>
|
||||
public abstract class EntityVisual:MonoBehaviour
|
||||
{
|
||||
public EntityLogic Entity { protected set; get;}
|
||||
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 892288dabf264b20b49b03ae91ccf5f8
|
||||
timeCreated: 1689576255
|
@@ -46,7 +46,7 @@ namespace GameLogic
|
||||
public GameClientStatus Status { get; set; } = GameClientStatus.StatusInit;
|
||||
public Scene Scene { private set; get; }
|
||||
|
||||
private string _lastAddress = null;
|
||||
private string _lastAddress = String.Empty;
|
||||
|
||||
public GameClient()
|
||||
{
|
||||
|
30
Assets/TEngine/Runtime/Utility/EnumHelper.cs
Normal file
30
Assets/TEngine/Runtime/Utility/EnumHelper.cs
Normal file
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
|
||||
namespace TEngine
|
||||
{
|
||||
public static class EnumHelper
|
||||
{
|
||||
public static int EnumIndex<T>(int value)
|
||||
{
|
||||
int i = 0;
|
||||
foreach (object v in Enum.GetValues(typeof (T)))
|
||||
{
|
||||
if ((int) v == value)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
++i;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static T FromString<T>(string str)
|
||||
{
|
||||
if (!Enum.IsDefined(typeof(T), str))
|
||||
{
|
||||
return default(T);
|
||||
}
|
||||
return (T)Enum.Parse(typeof(T), str);
|
||||
}
|
||||
}
|
||||
}
|
3
Assets/TEngine/Runtime/Utility/EnumHelper.cs.meta
Normal file
3
Assets/TEngine/Runtime/Utility/EnumHelper.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2638994be90d44a583fe978f8b92664d
|
||||
timeCreated: 1689578753
|
Reference in New Issue
Block a user