├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md └── source └── EZS ├── EntityCommandBuffer.cs ├── EntityCommandBuffer.cs.meta ├── EzDI.meta ├── EzDI ├── Container.cs ├── Container.cs.meta ├── Context.cs ├── Context.cs.meta ├── DependencyContainer.cs ├── DependencyContainer.cs.meta ├── DependencyInjection.cs ├── DependencyInjection.cs.meta ├── EzDI.asmdef ├── EzDI.asmdef.meta ├── Injector.cs └── Injector.cs.meta ├── NoBurst.cs ├── NoBurst.cs.meta ├── ObjectPool.cs ├── ObjectPool.cs.meta ├── RunTime.meta ├── RunTime ├── Archetype.cs ├── Archetype.cs.meta ├── Collections.cs ├── Collections.cs.meta ├── Delegates.cs ├── Delegates.cs.meta ├── EZS.asmdef ├── EZS.asmdef.meta ├── EcsComponent.cs ├── EcsComponent.cs.meta ├── Entities.cs ├── Entities.cs.meta ├── EntitiesWithout1.cs ├── EntitiesWithout1.cs.meta ├── EntitiesWithout2.cs ├── EntitiesWithout2.cs.meta ├── Entity.cs ├── Entity.cs.meta ├── EntityExtension.cs ├── EntityExtension.cs.meta ├── EntityType.cs ├── EntityType.cs.meta ├── JobsAndNativeExtensions.cs ├── JobsAndNativeExtensions.cs.meta ├── Systems.cs ├── Systems.cs.meta ├── World.cs ├── World.cs.meta ├── fEntities.cs └── fEntities.cs.meta ├── SourceGenerator.meta ├── SourceGenerator ├── Generator.dll ├── Generator.dll.meta ├── Generator.zip └── Generator.zip.meta ├── Unity.meta ├── Unity ├── BuildDebug.meta ├── BuildDebug │ ├── EntityInfo.cs │ └── EntityInfo.cs.meta ├── DebugInfo.cs ├── DebugInfo.cs.meta ├── EZSUnity.asmdef ├── EZSUnity.asmdef.meta ├── Editor.meta ├── Editor │ ├── Blueprint.meta │ ├── Blueprint │ │ ├── BlueprintEditor.cs │ │ └── BlueprintEditor.cs.meta │ ├── ComponentInspectorInternal.cs │ ├── ComponentInspectorInternal.cs.meta │ ├── ComponentSearchPopup.cs │ ├── ComponentSearchPopup.cs.meta │ ├── ComponentTypesList.cs │ ├── ComponentTypesList.cs.meta │ ├── EZSEditor.asmdef │ ├── EZSEditor.asmdef.meta │ ├── EcsDebugWindow.cs │ ├── EcsDebugWindow.cs.meta │ ├── EntityGUI.cs │ ├── EntityGUI.cs.meta │ ├── EntityInspectorWindow.cs │ ├── EntityInspectorWindow.cs.meta │ ├── EzsDebugConfigs.cs │ ├── EzsDebugConfigs.cs.meta │ ├── Graph.cs │ ├── Graph.cs.meta │ ├── Inspectors.meta │ ├── Inspectors │ │ ├── AnimationCurveInspector.cs │ │ ├── AnimationCurveInspector.cs.meta │ │ ├── BoolInspector.cs │ │ ├── BoolInspector.cs.meta │ │ ├── Color32Inspector.cs │ │ ├── Color32Inspector.cs.meta │ │ ├── ColorInspector.cs │ │ ├── ColorInspector.cs.meta │ │ ├── ComponentInspector.cs │ │ ├── ComponentInspector.cs.meta │ │ ├── DoubleInspector.cs │ │ ├── DoubleInspector.cs.meta │ │ ├── EntityInspector.cs │ │ ├── EntityInspector.cs.meta │ │ ├── EnumInspector.cs │ │ ├── EnumInspector.cs.meta │ │ ├── FloatInspector.cs │ │ ├── FloatInspector.cs.meta │ │ ├── GradientInspector.cs │ │ ├── GradientInspector.cs.meta │ │ ├── Inspectors.cs │ │ ├── Inspectors.cs.meta │ │ ├── IntInspector.cs │ │ ├── IntInspector.cs.meta │ │ ├── LayerMaskInspector.cs │ │ ├── LayerMaskInspector.cs.meta │ │ ├── ListInspector.cs │ │ ├── ListInspector.cs.meta │ │ ├── QuaternionInspector.cs │ │ ├── QuaternionInspector.cs.meta │ │ ├── StringInspector.cs │ │ ├── StringInspector.cs.meta │ │ ├── TypeInspector.cs │ │ ├── TypeInspector.cs.meta │ │ ├── UnityObjectInspector.cs │ │ ├── UnityObjectInspector.cs.meta │ │ ├── Vector2Inspector.cs │ │ ├── Vector2Inspector.cs.meta │ │ ├── Vector3Inspector.cs │ │ ├── Vector3Inspector.cs.meta │ │ ├── Vector4Inspector.cs │ │ └── Vector4Inspector.cs.meta │ ├── ListDrawer.cs │ ├── ListDrawer.cs.meta │ ├── MonoEntityEditor.cs │ ├── MonoEntityEditor.cs.meta │ ├── ScriptTemplates.meta │ ├── ScriptTemplates │ │ ├── 44-ECS123__Class Component-NewComponent.cs.txt │ │ ├── 44-ECS123__Class Component-NewComponent.cs.txt.meta │ │ ├── 45-ECS123__Struct Component-NewComponent.cs.txt │ │ └── 45-ECS123__Struct Component-NewComponent.cs.txt.meta │ ├── SystemsDebugInspector.cs │ ├── SystemsDebugInspector.cs.meta │ ├── WorldDebugInspector.cs │ └── WorldDebugInspector.cs.meta ├── EntityBlueprint.cs ├── EntityBlueprint.cs.meta ├── Images.meta ├── Images │ ├── EZS_LOGO.png │ ├── EZS_LOGO.png.meta │ ├── EcsComponentIcon.png │ └── EcsComponentIcon.png.meta ├── Inactive.cs ├── Inactive.cs.meta ├── MonoConverter.cs ├── MonoConverter.cs.meta ├── MonoEntity.cs ├── MonoEntity.cs.meta ├── PooledEvent.cs ├── PooledEvent.cs.meta ├── SyncTransformSystem.cs ├── SyncTransformSystem.cs.meta ├── SyncTransformSystem2.cs ├── SyncTransformSystem2.cs.meta ├── SystemColorAttribute.cs ├── SystemColorAttribute.cs.meta ├── SystemsDebugMono.cs ├── SystemsDebugMono.cs.meta ├── WorldDebug.cs └── WorldDebug.cs.meta ├── WargonKit.cs └── WargonKit.cs.meta /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Mm]emoryCaptures/ 12 | 13 | # Never ignore Asset meta data 14 | !/[Aa]ssets/**/*.meta 15 | 16 | # Uncomment this line if you wish to ignore the asset store tools plugin 17 | # /[Aa]ssets/AssetStoreTools* 18 | 19 | # Autogenerated Jetbrains Rider plugin 20 | [Aa]ssets/Plugins/Editor/JetBrains* 21 | 22 | # Visual Studio cache directory 23 | .vs/ 24 | 25 | # Gradle cache directory 26 | .gradle/ 27 | 28 | # Autogenerated VS/MD/Consulo solution and project files 29 | ExportedObj/ 30 | .consulo/ 31 | *.csproj 32 | *.unityproj 33 | *.sln 34 | *.suo 35 | *.tmp 36 | *.user 37 | *.userprefs 38 | *.pidb 39 | *.booproj 40 | *.svd 41 | *.pdb 42 | *.mdb 43 | *.opendb 44 | *.VC.db 45 | 46 | # Unity3D generated meta files 47 | *.pidb.meta 48 | *.pdb.meta 49 | *.mdb.meta 50 | 51 | # Unity3D generated file on crash reports 52 | sysinfo.txt 53 | 54 | # Builds 55 | *.apk 56 | *.unitypackage 57 | 58 | # Crashlytics generated file 59 | crashlytics-build.properties 60 | 61 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Wargon 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) 2 | 3 | ![EZS_LOGO_22](https://user-images.githubusercontent.com/37613162/113684924-62cd8e80-96ce-11eb-8069-6923d4972dd1.png) 4 | # EZS 5 | 6 | C# Entity Component System (ECS) based on struct components 7 | 8 | Inspired by [Entities](https://docs.unity3d.com/Packages/com.unity.entities@0.17/manual/index.html) 9 | 10 | # How install: 11 | Just copy source folder in assets folder of your game 12 | 13 | # How it works: 14 | 15 | Init World and Systems 16 | ```C# 17 | var world = new World(); 18 | MonoConverter.Init(world); // Turn on unity integration 19 | var systems = new Systems(world); 20 | systems .Add(new PlayerMoveSystem()) //Add update/init/destroy system 21 | .AddReactive(new HealSystem()) //Add reactive system 22 | .AddReactive(new DamageSystem()); //Add reactive system 23 | 24 | //You can use multiple Systems objects with one world 25 | var systemsFixed = new Systems(world); 26 | var systemsLate = new Systems(world); 27 | #if UNITY_EDITOR 28 | var debug = new DebugInfo(world); // Turn on debug 29 | #endif 30 | systems.Init(); 31 | systemsFixed.Init(); 32 | systemsLate.Init(); 33 | 34 | ``` 35 | Call update of systems in your update loop 36 | ```C# 37 | private void Update() 38 | { 39 | systems.OnUpdate(); 40 | } 41 | private void FixedUpdate() 42 | { 43 | systemsFixed.OnUpdate(); 44 | } 45 | private void LateUpdate() 46 | { 47 | systemsLate.OnUpdate(); 48 | } 49 | ``` 50 | 51 | 52 | Work with entities 53 | ```C# 54 | //create new entity 55 | var entity = world.CreateEntity() 56 | 57 | //add component 58 | entity.Add(new Health{ value = 100 }); 59 | 60 | //check is entity has type of component 61 | entity.Has() 62 | 63 | //get component 64 | ref var health = ref entity.Get() 65 | 66 | //remove component 67 | entity.Remove() 68 | 69 | //check is entity alive or destroyed 70 | entity.IsNull(); 71 | 72 | //destroy entity 73 | entity.Destroy(); 74 | ``` 75 | # Components: 76 | Components are just struct or class with public fields\ 77 | (better use structs, most likely in the future framework will support only structs) 78 | Examples: 79 | ```C# 80 | [EcsComponent] // attribute for visual debugging and attachment components to entity from inspector 81 | public struct Health 82 | { 83 | public int value; 84 | } 85 | ``` 86 | # Systems : 87 | 88 | 1. Update systems 89 | ```C# 90 | //Type of systems that will execute every time when you call systems.OnUpdate(); 91 | //Update systems must be partial, because the framework uses a source generator now. 92 | public partial class UpdateExampleSystem : UpdateSystem 93 | { 94 | public override void Update() 95 | { 96 | entities.Each((Entity entity, Heal heal, Health health) => 97 | { 98 | //some logic 99 | }); 100 | } 101 | } 102 | ``` 103 | 104 | 2. Reactive systems 105 | ```C# 106 | //Call system when component added to some entity 107 | public class DamageSystem : OnAdd 108 | { 109 | public override void Execute(in Enitity entity) 110 | { 111 | //some logic 112 | } 113 | } 114 | ``` 115 | ```C# 116 | //Call system when component removed from some entity 117 | public class OnRemoveSystem : OnRemove 118 | { 119 | public override void Execute(in Enitity entity) 120 | { 121 | //some logic 122 | } 123 | } 124 | ``` 125 | 126 | 3. Init systems 127 | ```C# 128 | //Call system at start of world live 129 | public class InitExampleSystem : InitSystem 130 | { 131 | public override void Execute() 132 | { 133 | entities.Each((Entity entity, ref Health heath, ref Damaged damage) => 134 | { 135 | //some logic 136 | }); 137 | } 138 | } 139 | ``` 140 | 141 | 4. Destroy systems 142 | ```C# 143 | //Call system during the destruction of the world 144 | public class DestroyExampleSystem : DestroySystem 145 | { 146 | public override void Execute() 147 | { 148 | entities.Each((Health heath, Damaged damage) => 149 | { 150 | //some logic 151 | }); 152 | } 153 | } 154 | ``` 155 | # System Loops: Each, Jobs, Without: 156 | 1. entities.Each((..........)=>{....}); 157 | ```C# 158 | //execute logic for each entity that has the components specified in it 159 | 160 | public partial class SingleThreadExampleUpdateSystem : UpdateSystem 161 | { 162 | public override void Update() 163 | { 164 | entities.Each((Rigidbody rb, BoxCollider box) => 165 | { 166 | //some logic 167 | }); 168 | } 169 | } 170 | 171 | ``` 172 | 2. Jobs 173 | ```C# 174 | 175 | public partial class MultiThreadExampleUpdateSystem : UpdateSystem 176 | { 177 | private EntityQuery query; 178 | private Pool pool; 179 | protected override void OnCreate() { 180 | query = world.GetQuery().With(); 181 | pool = world.GetPool(); 182 | } 183 | public override void Update() 184 | { 185 | var job = new TestJob 186 | { 187 | nativeQuery = query.AsNative(), 188 | nativePool = pool.AsNative() 189 | }; 190 | job.Schedule(query.Count, 1).Complete(); 191 | } 192 | [BurstCompile] 193 | struct TestJob : IJobParallelFor 194 | { 195 | public NativeQuery nativeQuery; 196 | public NativePool nativePool; 197 | public void Execute(int index) 198 | { 199 | //when we work with entities from Jobs, entities representing as integer (Int32) 200 | var entity = nativeQuery.GetEntity(index); 201 | ref var data = ref nativePool.Get(entity); 202 | } 203 | } 204 | } 205 | 206 | ``` 207 | 3. You can filter entities not only by including components, but also by excluding 208 | ```C# 209 | public partial class WithoutSystemExample : UpdateSystem 210 | { 211 | public override void Update() 212 | { 213 | //ref keyword if you use struct as component 214 | entities.Without().EachThreaded((Position pos, RayCast ray, Impact impact, CanReflect reflect, BossTag tag) => 215 | { 216 | //some logic 217 | }); 218 | 219 | entities.Without().Each((Rigidbody rb, BoxCollider box) => 220 | { 221 | //some logic 222 | }); 223 | } 224 | } 225 | ``` 226 | 4. WithOwner 227 | ```C# 228 | public partial class AbilityExampleSystem : UpdateSystem 229 | { 230 | public override void Update() 231 | { 232 | entities.Each((Bullet bullet, CollisionEvent collision, Owner owner) => 233 | { 234 | // WithOwner take as parameter id of owner entity 235 | entities.WithOwner(owner.id).Each((ExplosionOnCollisionAbility ability) => 236 | { 237 | //some logic 238 | }); 239 | }); 240 | } 241 | } 242 | ``` 243 | # How systems filter entities: 244 | Each entity has its own archetype. As many components as an entity has, there are as many components in an archetype. When we add/remove component form entity or change it's owner, the entity changes its archetype and marking as dirty. After execution of system it will be placed in matching queries, and removed from that are not matching. 245 | 246 | ```C# 247 | var query = world.GetQuery().With().Without(); 248 | var entity = world.CreateEntity(); // empty archetype 249 | entity.Add(new EnemyTag()) // archetype(EnemyTag). Our entity match with our query, after system executin it will be added to our query. 250 | entity.Add(new PlayerTag()) // archetype(EnemyTag,PlayerTag). Now our entity not matching our query. and entity won't be added to it. 251 | 252 | ``` 253 | 254 | # Unity Integration: 255 | Entity Wrapper 256 | 257 | ![image](https://user-images.githubusercontent.com/37613162/168055056-b42cb0d8-a9f5-44e6-bb6d-2f351bdd117c.png) 258 | 259 | Systems 260 | 261 | ![image](https://user-images.githubusercontent.com/37613162/168055250-086ee037-642e-4c0f-a366-2218aeacb189.png) 262 | 263 | # Example project 264 | [Turn Base Game](https://github.com/AlexWargon/TurnBasedGameEcs) 265 | -------------------------------------------------------------------------------- /source/EZS/EntityCommandBuffer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ed23472aa521c164aba10c56c5ecbc54 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/EzDI.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d20748705bfe4ed0b29dcb7293d8bbbc 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/EzDI/Container.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Wargon.DI 4 | { 5 | public class Container 6 | { 7 | private readonly Type containerType; 8 | private readonly object dependency; 9 | private readonly DiType diType; 10 | 11 | public Container(Type type, object dependency, DiType diType) 12 | { 13 | containerType = type; 14 | this.dependency = dependency; 15 | this.diType = diType; 16 | } 17 | 18 | public object Get() 19 | { 20 | return diType switch 21 | { 22 | DiType.Single => dependency, 23 | DiType.Global => DependencyContainer.Globals[containerType], 24 | DiType.New => Activator.CreateInstance(containerType), 25 | _ => throw new ArgumentOutOfRangeException() 26 | }; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /source/EZS/EzDI/Container.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f18bc8e7f1744f493b783529a17a8a9 3 | timeCreated: 1649270995 -------------------------------------------------------------------------------- /source/EZS/EzDI/Context.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Reflection; 4 | using System.Runtime.CompilerServices; 5 | using UnityEngine; 6 | 7 | namespace Wargon.DI 8 | { 9 | public class Context 10 | { 11 | private readonly MethodInfo constructor; 12 | private readonly Type contextType; 13 | private readonly Type[] contructorParametersTypes; 14 | private readonly DependencyContainer di; 15 | private readonly List<(string, Type, DiType)> fieldsToInject = new List<(string, Type, DiType)>(); 16 | private readonly bool isMonoBehaviourWithConstructor; 17 | private bool binded; 18 | private BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance; 19 | public Context(Type type, DependencyContainer di) { 20 | 21 | contextType = type; 22 | this.di = di; 23 | if (typeof(MonoBehaviour).IsAssignableFrom(type)) 24 | { 25 | constructor = type.GetMethod("Construct"); 26 | if (constructor != null) 27 | { 28 | var parameters = constructor.GetParameters(); 29 | contructorParametersTypes = new Type[constructor.GetParameters().Length]; 30 | for (var i = 0; i < contructorParametersTypes.Length; i++) 31 | contructorParametersTypes[i] = parameters[i].ParameterType; 32 | isMonoBehaviourWithConstructor = true; 33 | } 34 | } 35 | 36 | var fields = type.GetFields(bindingFlags); 37 | foreach (var fieldInfo in fields) 38 | { 39 | // if (FieldHasAttribute(fieldInfo)) 40 | // { 41 | // var diType = DiType.New; 42 | // if (di.HasGlobal(fieldInfo.FieldType)) 43 | // diType = DiType.Global; 44 | // else if (di.HasSingle(fieldInfo.FieldType)) 45 | // diType = DiType.Single; 46 | // 47 | // fieldsToInject.Add((fieldInfo.Name, fieldInfo.FieldType, diType)); 48 | // //Log.Show(new Color(0.98f, 0.42f, 1f), $"Field [{fieldInfo.FieldType}] of [{contextType.Name}] added like must be injected"); 49 | // } 50 | var diType = DiType.New; 51 | if (di.HasGlobal(fieldInfo.FieldType)) 52 | diType = DiType.Global; 53 | else if (di.HasSingle(fieldInfo.FieldType)) 54 | diType = DiType.Single; 55 | 56 | fieldsToInject.Add((fieldInfo.Name, fieldInfo.FieldType, diType)); 57 | } 58 | } 59 | 60 | private static bool FieldHasAttribute(FieldInfo fieldInfo) 61 | { 62 | return fieldInfo.GetCustomAttributes(typeof(InjectAttribute), true).Length > 0; 63 | } 64 | 65 | public void Inject(T obj) where T : class 66 | { 67 | //if(binded) return; 68 | for (var i = 0; i < fieldsToInject.Count; i++) 69 | { 70 | switch (fieldsToInject[i].Item3) 71 | { 72 | case DiType.New: 73 | if(di.HasSingle(fieldsToInject[i].Item2)) 74 | contextType.GetField(fieldsToInject[i].Item1,bindingFlags)?.SetValue(obj, di.GetContainer(fieldsToInject[i].Item2).Get()); 75 | //else Debug.LogError($"{fieldsToInject[i].Item1} can't be inhected. There no isntance in DI"); 76 | 77 | break; 78 | case DiType.Single: 79 | if(di.HasSingle(fieldsToInject[i].Item2)) 80 | contextType.GetField(fieldsToInject[i].Item1,bindingFlags)?.SetValue(obj, di.GetContainer(fieldsToInject[i].Item2).Get()); 81 | //else Debug.LogError($"{fieldsToInject[i].Item1} can't be inhected. There no isntance in DI"); 82 | break; 83 | case DiType.Global: 84 | if(di.HasGlobal((fieldsToInject[i].Item2))) 85 | contextType.GetField(fieldsToInject[i].Item1,bindingFlags)?.SetValue(obj, DependencyContainer.Globals[fieldsToInject[i].Item2]); 86 | //else Debug.LogError($"{fieldsToInject[i].Item1} can't be inhected. There no isntance in DI"); 87 | break; 88 | } 89 | //Log.Show(new Color(0.49f, 0.62f, 1f), $"Field [{fieldsToInject[i].Item2}] Binded to [{contextType.Name}]"); 90 | } 91 | if (isMonoBehaviourWithConstructor) 92 | { 93 | var newParams = new object[contructorParametersTypes.Length]; 94 | for (var i = 0; i < newParams.Length; i++) 95 | newParams[i] = di.GetContainer(fieldsToInject[i].Item2).Get(); 96 | constructor.Invoke(obj, newParams); 97 | } 98 | //Log.Show(Color.yellow, $"[{contextType}] Binded"); 99 | //binded = true; 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /source/EZS/EzDI/Context.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b8bb6c3bb1b44088388fffcbbc436bc 3 | timeCreated: 1649270986 -------------------------------------------------------------------------------- /source/EZS/EzDI/DependencyContainer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.CompilerServices; 4 | using UnityEngine; 5 | using Object = UnityEngine.Object; 6 | 7 | namespace Wargon.DI 8 | { 9 | public class DependencyContainer : IDisposable 10 | { 11 | private static readonly Dictionary globals = new Dictionary(); 12 | public static Dictionary Globals => globals; 13 | private readonly Dictionary containers = new Dictionary(); 14 | private readonly Dictionary contexts = new Dictionary(); 15 | 16 | public void Dispose() { 17 | containers.Clear(); 18 | contexts.Clear(); 19 | } 20 | public void DisposeAll() { 21 | containers.Clear(); 22 | contexts.Clear(); 23 | globals.Clear(); 24 | } 25 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 26 | public T New() where T : class, new() 27 | { 28 | var newObj = new T(); 29 | var type = typeof(T); 30 | if (!contexts.ContainsKey(type)) contexts.Add(type, new Context(type, this)); 31 | contexts[type].Inject(newObj); 32 | return newObj; 33 | } 34 | 35 | public void Resolve(Type type, object item) 36 | { 37 | if (!contexts.ContainsKey(type)) contexts.Add(type, new Context(type, this)); 38 | contexts[type].Inject(item); 39 | } 40 | 41 | 42 | public void Resolve(T item) where T : class 43 | { 44 | var type = typeof(T); 45 | if (!contexts.ContainsKey(type)) contexts.Add(type, new Context(type, this)); 46 | contexts[type].Inject(item); 47 | } 48 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 49 | public void ResolveObject(object item) 50 | { 51 | var type = item.GetType(); 52 | if (!contexts.ContainsKey(type)) contexts.Add(type, new Context(type, this)); 53 | contexts[type].Inject(item); 54 | } 55 | public T Instatiate(T prefab, Vector3 position, Quaternion rotation) where T : MonoBehaviour 56 | { 57 | var component = Object.Instantiate(prefab, position, rotation); 58 | Resolve(component); 59 | return component; 60 | } 61 | 62 | public T Instatiate() where T : MonoBehaviour 63 | { 64 | var newObj = new GameObject(); 65 | var newComponent = newObj.AddComponent(); 66 | Resolve(newComponent); 67 | newObj.name = newComponent.GetType().Name; 68 | return newComponent; 69 | } 70 | 71 | public T Instatiate(Vector3 position, Quaternion rotation) where T : MonoBehaviour 72 | { 73 | var newObj = new GameObject(); 74 | var newComponent = newObj.AddComponent(); 75 | Resolve(newComponent); 76 | newObj.name = newComponent.GetType().Name; 77 | newObj.transform.position = position; 78 | newObj.transform.rotation = rotation; 79 | return newComponent; 80 | } 81 | 82 | public void AddAsSingle(T toInject) where T : class 83 | { 84 | containers.Add(typeof(T), new Container(typeof(T), toInject, DiType.Single)); 85 | } 86 | 87 | public T GetSingle() where T : class { 88 | return (T)containers[typeof(T)].Get(); 89 | } 90 | public void Add() where T : class 91 | { 92 | containers.Add(typeof(T), new Container(typeof(T), null, DiType.New)); 93 | } 94 | 95 | public void AddAsGlobal(T toInject) where T : class 96 | { 97 | if (!globals.ContainsKey(typeof(T))) { 98 | globals.Add(typeof(T), toInject); 99 | } 100 | else { 101 | if(toInject is MonoBehaviour m) 102 | Object.Destroy(m.gameObject); 103 | } 104 | } 105 | 106 | public bool HasGlobal(Type type) 107 | { 108 | return globals.ContainsKey(type); 109 | } 110 | 111 | public bool HasSingle(Type type) 112 | { 113 | return containers.ContainsKey(type); 114 | } 115 | 116 | public Container GetContainer() 117 | { 118 | return containers[typeof(T)]; 119 | } 120 | 121 | public Container GetContainer(Type type) 122 | { 123 | return containers[type]; 124 | } 125 | 126 | } 127 | public enum DiType 128 | { 129 | New, 130 | Single, 131 | Global 132 | } 133 | } -------------------------------------------------------------------------------- /source/EZS/EzDI/DependencyContainer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d09031534154206990bed6bb88d503b 3 | timeCreated: 1649270721 -------------------------------------------------------------------------------- /source/EZS/EzDI/DependencyInjection.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | using UnityEngine.SceneManagement; 4 | 5 | public class DependencyInjection : MonoBehaviour 6 | { 7 | // public Dependency1 dependency1; 8 | // public Dependency2 dependency2; 9 | // public Dependency3 Dependency3; 10 | // 11 | // public TestDI testDi; 12 | 13 | public void Awake() 14 | { 15 | // var ezDi = new EzDI(); 16 | // ezDi.AddAsSingle(dependency1); 17 | // ezDi.AddAsGlobal(dependency2); 18 | // ezDi.AddAsSingle(Dependency3); 19 | // ezDi.Add(); 20 | // 21 | // ezDi.Bind(testDi); 22 | // Timer t = Timer.New(); 23 | // t.Action(() => 24 | // { 25 | // ezDi.Instatiate(testDi,Vector3.one, Quaternion.identity); 26 | // }) 27 | // .WaitFor(0.1f) 28 | // .Repeat() 29 | // .Start(); 30 | } 31 | } 32 | 33 | [AttributeUsage(AttributeTargets.Field | AttributeTargets.Method)] 34 | public class InjectAttribute : Attribute 35 | { 36 | public InjectAttribute() 37 | { 38 | 39 | } 40 | } -------------------------------------------------------------------------------- /source/EZS/EzDI/DependencyInjection.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b1dae4002af999f42a7ac143743ae3fb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/EzDI/EzDI.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EzDI" 3 | } 4 | -------------------------------------------------------------------------------- /source/EZS/EzDI/EzDI.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 56ce43a9832964d49916c6313907e218 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /source/EZS/EzDI/Injector.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | namespace Wargon.DI 4 | { 5 | public static class Injector { 6 | private static DependencyContainer _dependencyContainerInstance; 7 | public static DependencyContainer GetOrCreate() 8 | { 9 | if(_dependencyContainerInstance == null) 10 | _dependencyContainerInstance = new DependencyContainer(); 11 | return _dependencyContainerInstance; 12 | } 13 | public static T New() where T : class, new() => GetOrCreate().New(); 14 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 15 | public static void Resolve(T item) where T : class => GetOrCreate().Resolve(item); 16 | 17 | public static void ResolveObject(object item) => GetOrCreate().ResolveObject(item); 18 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 19 | public static void AddAsSingle(T toInject) where T : class => GetOrCreate().AddAsSingle(toInject); 20 | 21 | public static T GetAsSignle() where T : class => GetOrCreate().GetSingle(); 22 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 23 | public static void AddAsGlobal(T toInject) where T : class => GetOrCreate().AddAsGlobal(toInject); 24 | public static void Dispose() => GetOrCreate().Dispose(); 25 | public static void DisposeAll() => GetOrCreate().DisposeAll(); 26 | } 27 | } -------------------------------------------------------------------------------- /source/EZS/EzDI/Injector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1308f2341c374a268852c160e3527edc 3 | timeCreated: 1649270710 -------------------------------------------------------------------------------- /source/EZS/NoBurst.cs: -------------------------------------------------------------------------------- 1 | [EcsComponent] 2 | public struct NoBurst 3 | { 4 | } -------------------------------------------------------------------------------- /source/EZS/NoBurst.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44b813beefae45c7be3ea0a22abf20b2 3 | timeCreated: 1696104662 -------------------------------------------------------------------------------- /source/EZS/ObjectPool.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09224857f7bd4471b752c123234037a7 3 | timeCreated: 1696104662 -------------------------------------------------------------------------------- /source/EZS/RunTime.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1d8a4f686522ce84f8afcdaad2dd24c1 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/RunTime/Archetype.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7a3609bf91394fdcb3068cdb7e0b08e8 3 | timeCreated: 1677769820 -------------------------------------------------------------------------------- /source/EZS/RunTime/Collections.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 16f756fbb503ca048a30858a5bd600e9 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/Delegates.cs: -------------------------------------------------------------------------------- 1 | namespace Wargon.ezs.Delegates 2 | { 3 | public delegate void gLambda(T1 t1); 4 | public delegate void gLambda(T1 t1,T2 t2); 5 | public delegate void gLambda(T1 t1,T2 t2,T3 t3); 6 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4); 7 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5); 8 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6); 9 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7); 10 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8); 11 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9); 12 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9,T10 t10); 13 | public delegate void gLambda(T1 t1,T2 t2,T3 t3,T4 t4,T5 t5,T6 t6,T7 t7,T8 t8,T9 t9,T10 t10,T11 t11); 14 | 15 | } 16 | 17 | namespace Wargon.ezs 18 | { 19 | public static partial class EntitiesExtensions 20 | { 21 | 22 | // ReSharper disable Unity.PerformanceAnalysis 23 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 24 | where T1: struct 25 | { 26 | return entities; 27 | } 28 | 29 | 30 | 31 | // ReSharper disable Unity.PerformanceAnalysis 32 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 33 | where T1: struct 34 | where T2: struct 35 | { 36 | return entities; 37 | } 38 | 39 | 40 | 41 | // ReSharper disable Unity.PerformanceAnalysis 42 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 43 | where T1: struct 44 | where T2: struct 45 | where T3: struct 46 | { 47 | return entities; 48 | } 49 | 50 | 51 | 52 | // ReSharper disable Unity.PerformanceAnalysis 53 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 54 | where T1: struct 55 | where T2: struct 56 | where T3: struct 57 | where T4: struct 58 | { 59 | return entities; 60 | } 61 | 62 | 63 | 64 | // ReSharper disable Unity.PerformanceAnalysis 65 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 66 | where T1: struct 67 | where T2: struct 68 | where T3: struct 69 | where T4: struct 70 | where T5: struct 71 | { 72 | return entities; 73 | } 74 | 75 | 76 | 77 | // ReSharper disable Unity.PerformanceAnalysis 78 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 79 | where T1: struct 80 | where T2: struct 81 | where T3: struct 82 | where T4: struct 83 | where T5: struct 84 | where T6: struct 85 | { 86 | return entities; 87 | } 88 | 89 | 90 | 91 | // ReSharper disable Unity.PerformanceAnalysis 92 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 93 | where T1: struct 94 | where T2: struct 95 | where T3: struct 96 | where T4: struct 97 | where T5: struct 98 | where T6: struct 99 | where T7: struct 100 | { 101 | return entities; 102 | } 103 | 104 | 105 | 106 | // ReSharper disable Unity.PerformanceAnalysis 107 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 108 | where T1: struct 109 | where T2: struct 110 | where T3: struct 111 | where T4: struct 112 | where T5: struct 113 | where T6: struct 114 | where T7: struct 115 | where T8: struct 116 | { 117 | return entities; 118 | } 119 | 120 | 121 | 122 | // ReSharper disable Unity.PerformanceAnalysis 123 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 124 | where T1: struct 125 | where T2: struct 126 | where T3: struct 127 | where T4: struct 128 | where T5: struct 129 | where T6: struct 130 | where T7: struct 131 | where T8: struct 132 | where T9: struct 133 | { 134 | return entities; 135 | } 136 | 137 | 138 | 139 | // ReSharper disable Unity.PerformanceAnalysis 140 | public static EntitiesEach Each(this EntitiesEach entities, Delegates.gLambda callback) 141 | where T1: struct 142 | where T2: struct 143 | where T3: struct 144 | where T4: struct 145 | where T5: struct 146 | where T6: struct 147 | where T7: struct 148 | where T8: struct 149 | where T9: struct 150 | where T10:struct 151 | { 152 | return entities; 153 | } 154 | 155 | 156 | 157 | } 158 | } 159 | 160 | 161 | 162 | namespace Wargon.ezs 163 | { 164 | public static partial class EntitiesExtensions 165 | { 166 | 167 | // ReSharper disable Unity.PerformanceAnalysis 168 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 169 | where T1: struct 170 | { 171 | return entities; 172 | } 173 | 174 | // ReSharper disable Unity.PerformanceAnalysis 175 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 176 | where T1: struct 177 | where T2: struct 178 | { 179 | return entities; 180 | } 181 | 182 | // ReSharper disable Unity.PerformanceAnalysis 183 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 184 | where T1: struct 185 | where T2: struct 186 | where T3: struct 187 | { 188 | return entities; 189 | } 190 | 191 | // ReSharper disable Unity.PerformanceAnalysis 192 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 193 | where T1: struct 194 | where T2: struct 195 | where T3: struct 196 | where T4: struct 197 | { 198 | return entities; 199 | } 200 | 201 | // ReSharper disable Unity.PerformanceAnalysis 202 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 203 | where T1: struct 204 | where T2: struct 205 | where T3: struct 206 | where T4: struct 207 | where T5: struct 208 | { 209 | return entities; 210 | } 211 | 212 | // ReSharper disable Unity.PerformanceAnalysis 213 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 214 | where T1: struct 215 | where T2: struct 216 | where T3: struct 217 | where T4: struct 218 | where T5: struct 219 | where T6: struct 220 | { 221 | return entities; 222 | } 223 | 224 | // ReSharper disable Unity.PerformanceAnalysis 225 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 226 | where T1: struct 227 | where T2: struct 228 | where T3: struct 229 | where T4: struct 230 | where T5: struct 231 | where T6: struct 232 | where T7: struct 233 | { 234 | return entities; 235 | } 236 | 237 | // ReSharper disable Unity.PerformanceAnalysis 238 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 239 | where T1: struct 240 | where T2: struct 241 | where T3: struct 242 | where T4: struct 243 | where T5: struct 244 | where T6: struct 245 | where T7: struct 246 | where T8: struct 247 | { 248 | return entities; 249 | } 250 | 251 | // ReSharper disable Unity.PerformanceAnalysis 252 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 253 | where T1: struct 254 | where T2: struct 255 | where T3: struct 256 | where T4: struct 257 | where T5: struct 258 | where T6: struct 259 | where T7: struct 260 | where T8: struct 261 | where T9: struct 262 | { 263 | return entities; 264 | } 265 | 266 | // ReSharper disable Unity.PerformanceAnalysis 267 | public static EntitiesEach Each(this EntitiesEach entities,Delegates.gLambda callback) 268 | where T1: struct 269 | where T2: struct 270 | where T3: struct 271 | where T4: struct 272 | where T5: struct 273 | where T6: struct 274 | where T7: struct 275 | where T8: struct 276 | where T9: struct 277 | where T10: struct 278 | { 279 | return entities; 280 | } 281 | 282 | } 283 | } 284 | 285 | -------------------------------------------------------------------------------- /source/EZS/RunTime/Delegates.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1b2c743d292438941b1d83ee827c9ffc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/EZS.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EZS", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:d8b63aba1907145bea998dd612889d6b", 6 | "GUID:2665a8d13d1b3f18800f46e256720795", 7 | "GUID:56ce43a9832964d49916c6313907e218", 8 | "GUID:e0cd26848372d4e5c891c569017e11f1" 9 | ], 10 | "includePlatforms": [], 11 | "excludePlatforms": [], 12 | "allowUnsafeCode": true, 13 | "overrideReferences": false, 14 | "precompiledReferences": [], 15 | "autoReferenced": true, 16 | "defineConstraints": [], 17 | "versionDefines": [], 18 | "noEngineReferences": false 19 | } -------------------------------------------------------------------------------- /source/EZS/RunTime/EZS.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bf13737622ae9074bb70c7b01500f994 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /source/EZS/RunTime/EcsComponent.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Wargon.ezs; 3 | 4 | [Serializable] 5 | [AttributeUsage(AttributeTargets.Struct)] 6 | public sealed class EcsComponentAttribute : Attribute 7 | { 8 | public EcsComponentAttribute() 9 | { 10 | } 11 | } 12 | [AttributeUsage(AttributeTargets.Field)] 13 | public sealed class StringHashAttribute : Attribute { 14 | public StringHashAttribute() { 15 | 16 | } 17 | } 18 | 19 | public sealed class SwapComponentAttribute : Attribute { 20 | public Type swapTarget; 21 | public SwapComponentAttribute(Type swap) { 22 | swapTarget = swap; 23 | } 24 | } 25 | 26 | -------------------------------------------------------------------------------- /source/EZS/RunTime/EcsComponent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3f4dad11a0c506f41bc9a2bfcd3d440c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/Entities.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9c682faea7dbdf346a569543393b32c8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/EntitiesWithout1.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 96e7e9a10eb6f0f48931c00e9e74022b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/EntitiesWithout2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 660e37fc34d8b1f41a95f300672eac3e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/Entity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75730f0f2b6ac6640b46e70a78ea0ed3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/EntityExtension.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | 4 | 5 | namespace Wargon.ezs { 6 | public static class EntityExtension 7 | { 8 | public static void AddBoxed(this Entity entity, object component) 9 | { 10 | if (component == null) 11 | { 12 | UnityEngine.Debug.LogError($"Try add null component on entity {entity.id} " + Environment.NewLine + 13 | "Looks like some component on prefab was currupted :C"); 14 | return; 15 | } 16 | var type = component.GetType(); 17 | var typeId = ComponentType.GetID(type); 18 | ref var data = ref entity.GetEntityData(); 19 | if (data.version != entity.version) 20 | throw new Exception("ENTITY NULL OR DESTROYED. Method: Entity.AddBoxed()"); 21 | 22 | if (!data.Has(typeId)) { 23 | var pool = entity.World.GetPoolByID(typeId); 24 | pool.SetBoxed(component, entity.id); 25 | pool.Add(entity.id); 26 | data.archetype.TransferAdd(ref data, typeId); 27 | entity.World.OnAddComponent(typeId, in entity); 28 | } 29 | } 30 | /// 31 | /// Set new owner 32 | /// 33 | /// 34 | /// 35 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 36 | public static void SetOwner(this ref Entity e, Entity newOwner) { 37 | if (newOwner.IsNULL()) { 38 | throw new Exception("You are trying set null reference entity as Owner"); 39 | } 40 | ref var data = ref e.GetEntityData(); 41 | var typeId = ComponentType.ID; 42 | var pool = e.World.OwnerPool; 43 | var nativePool = e.World.OwnerNativePool; 44 | if (data.archetype.owner == -1) { 45 | pool.Set(new Owner{Value = newOwner}, e.id); 46 | pool.Add(e.id); 47 | nativePool.Set(new OwnerNative{id = newOwner.id}, e.id); 48 | nativePool.Add(e.id); 49 | data.archetype.TransferOwnerAdd(ref data, typeId, newOwner.id); 50 | } 51 | else { 52 | if(data.archetype.owner == newOwner.id) return; 53 | pool.Get(e.id).Value = newOwner; 54 | nativePool.Get(e.id).id = newOwner.id; 55 | data.archetype.TransferOwnerChange(ref data, newOwner.id); 56 | } 57 | } 58 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 59 | public static bool HasOwner(this ref Entity entity) { 60 | return !entity.IsNULL() && entity.GetEntityData().archetype.owner != -1; 61 | } 62 | 63 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 64 | public static Entity GetOwner(this ref Entity entity) { 65 | ref var world = ref entity.World; 66 | ref var data = ref entity.GetEntityData(); 67 | if (data.archetype.owner != -1) return world.OwnerPool.Get(entity.id).Value; 68 | throw new Exception($"ENTITY {entity.id} HAS NO OWNER! Method: Entity.GetOwner()"); 69 | } 70 | 71 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 72 | public static Entity GetOwnerDanger(this ref Entity entity) { 73 | ref var world = ref entity.World; 74 | return world.OwnerPool.Get(entity.id).Value; 75 | } 76 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 77 | public static Entity[] GetChildren(this Entity entity) { 78 | return entity.World.Entities.GetOwnerQuery(entity.id).GetEntityQuery(); 79 | } 80 | 81 | public static Entity Copy(this ref Entity entity) { 82 | var w = entity.World; 83 | var e = w.CreateEntity(); 84 | ref var data = ref entity.GetEntityData(); 85 | foreach (var dataComponentType in data.archetype.mask) { 86 | var pool = w.GetPoolByID(dataComponentType); 87 | pool.Copy(entity.id, e.id); 88 | w.OnAddComponent(dataComponentType, in e); 89 | } 90 | 91 | e.GetEntityData().archetype = data.archetype; 92 | return e; 93 | } 94 | public static Entity Copy2(this ref Entity entity) { 95 | ref var data = ref entity.GetEntityData(); 96 | var e = data.archetype.Copy(entity); 97 | return e; 98 | } 99 | } 100 | } -------------------------------------------------------------------------------- /source/EZS/RunTime/EntityExtension.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2f14dd8f3c494c46945f68dd92434179 3 | timeCreated: 1655422096 -------------------------------------------------------------------------------- /source/EZS/RunTime/EntityType.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db15c3e9a902dcb4f8112413b0687f92 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/JobsAndNativeExtensions.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Unity.Jobs; 3 | using UnityEngine.Jobs; 4 | 5 | namespace Wargon.ezs { 6 | public static class JobsAndNativeExtensions { 7 | public static bool TryComplete(this Unity.Jobs.JobHandle @this) 8 | { 9 | if (!@this.IsCompleted) return false; 10 | @this.Complete(); return true; 11 | } 12 | 13 | 14 | 15 | 16 | public static Unity.Collections.NativeParallelMultiHashMap Clone(this ref Unity.Collections.NativeParallelMultiHashMap @this, Unity.Collections.Allocator alloc) 17 | where TKey : unmanaged, IEquatable 18 | where TValue : unmanaged 19 | { 20 | 21 | Unity.Collections.NativeParallelMultiHashMap cloneHashMap = new Unity.Collections.NativeParallelMultiHashMap(@this.Count(), alloc); 22 | 23 | Unity.Collections.NativeParallelMultiHashMapIterator it; 24 | Unity.Collections.NativeArray keys = @this.GetKeyArray(Unity.Collections.Allocator.Temp); 25 | TKey key; 26 | TValue value; 27 | 28 | for (int k = 0, count = keys.Length; k < count; k++) 29 | { 30 | key = keys[k]; 31 | if (@this.TryGetFirstValue(key, out value, out it)) 32 | { 33 | cloneHashMap.Add(key, value); 34 | while (@this.TryGetNextValue(out value, ref it)) 35 | { 36 | cloneHashMap.Add(key, value); 37 | } 38 | } 39 | } 40 | 41 | keys.Dispose(); 42 | 43 | return cloneHashMap; 44 | } 45 | } 46 | public static class IJobForExtensions { 47 | public static ref JobHandle ScheduleInSystem(this ref TJob job, int count, UpdateSystem system) where TJob : struct, IJobFor { 48 | system.Dependencies = job.Schedule(count, system.Root.Dependency); 49 | system.Root.Dependency = system.Dependencies; 50 | return ref system.Root.Dependency; 51 | } 52 | public static ref JobHandle ScheduleParalleInSystem(this ref TJob job, int count, UpdateSystem system) where TJob : struct, IJobFor { 53 | system.Dependencies = job.ScheduleParallel(count, 1, system.Root.Dependency); 54 | system.Root.Dependency = system.Dependencies; 55 | return ref system.Root.Dependency; 56 | } 57 | } 58 | public static class IJobParallelForExtensions { 59 | public static ref JobHandle ScheduleInSystem(this ref TJob job, int count, UpdateSystem system) where TJob : struct, IJobParallelFor { 60 | system.Dependencies = job.Schedule(count, 1, system.Root.Dependency); 61 | system.Root.Dependency = system.Dependencies; 62 | return ref system.Root.Dependency; 63 | } 64 | } 65 | public static class IJobParallelForTransformExtensions { 66 | public static ref JobHandle ScheduleInSystem(this ref TJob job, TransformAccessArray array, UpdateSystem system) where TJob : struct, IJobParallelForTransform { 67 | system.Dependencies = job.Schedule(array, system.Root.Dependency); 68 | system.Root.Dependency = system.Dependencies; 69 | return ref system.Root.Dependency; 70 | } 71 | } 72 | } -------------------------------------------------------------------------------- /source/EZS/RunTime/JobsAndNativeExtensions.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6407d8156fc5471ebe41beb0e99b0af5 3 | timeCreated: 1704959221 -------------------------------------------------------------------------------- /source/EZS/RunTime/Systems.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ee5872d10ef83b74a8e92b8d12a19436 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/World.cs: -------------------------------------------------------------------------------- 1 |  2 | using Unity.Collections; 3 | using UnityEngine; 4 | 5 | namespace Wargon.ezs 6 | { 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Runtime.CompilerServices; 10 | public class Configs 11 | { 12 | public static int ComponentCacheSize = 512; 13 | public static int EntityCacheSize = 512; 14 | public static int PoolsCacheSize = 64; 15 | public static int EntityTypesCacheSize = 64; 16 | } 17 | 18 | public static class Worlds 19 | { 20 | private static World[] WorldsPool; 21 | private static int WorldsCount; 22 | 23 | static Worlds() 24 | { 25 | WorldsPool = new World[4]; 26 | WorldsCount = 0; 27 | } 28 | public static World New() 29 | { 30 | var world = new World(); 31 | WorldsPool[WorldsCount] = world; 32 | world.ID = WorldsCount; 33 | WorldsCount++; 34 | return world; 35 | } 36 | public static World GetWorld(int id) 37 | { 38 | return WorldsPool[id]; 39 | } 40 | } 41 | public struct DestroyEntity{} 42 | [EcsComponent] 43 | public struct Owner { 44 | public Entity Value; 45 | } 46 | 47 | public struct OwnerNative { 48 | public int id; 49 | } 50 | public struct EntityConvertedEvent {} 51 | public partial class World 52 | { 53 | public int ID; 54 | public readonly int ComponentCacheSize; 55 | public readonly int EntityCacheSize; 56 | public readonly int PoolsCacheSize; 57 | public readonly int EntityTypesCachSize; 58 | public Entity[] entities; 59 | public Entities Entities; 60 | private IPool[] ComponentPools; 61 | private int poolsAmount; 62 | private Dictionary EventBuffers; 63 | private int eventBuffersAmount; 64 | public int totalEntitiesCount; 65 | public int aliveEntitiesCount; 66 | public bool Alive; 67 | private EntityData[] entitiesData; 68 | private DynamicArray freeEntities; 69 | private Systems[] systems; 70 | private int systemsCount; 71 | private int freeEntitiesCount = 0; 72 | private event Action OnDestroy; 73 | 74 | public int GetFreeEntitiesCount() => freeEntities.Count; 75 | public World() 76 | { 77 | ComponentCacheSize = Configs.ComponentCacheSize; 78 | EntityCacheSize = Configs.EntityCacheSize; 79 | PoolsCacheSize = Configs.PoolsCacheSize; 80 | EntityTypesCachSize = Configs.EntityTypesCacheSize; 81 | ComponentPools = new IPool[PoolsCacheSize]; 82 | entitiesData = new EntityData[EntityCacheSize]; 83 | entities = new Entity[EntityCacheSize]; 84 | freeEntities = new DynamicArray(EntityCacheSize); 85 | systems = new Systems[4]; 86 | Entities = new Entities(this); 87 | Alive = true; 88 | 89 | EventBuffers = new Dictionary(8); 90 | eventBuffersAmount = 0; 91 | 92 | GetPool(); 93 | ownerPool = GetPool(); 94 | ownerNativePool = GetPool(); 95 | CreateFirstArchetype(); 96 | var zeroE = CreateEntity(); 97 | zeroE.Add(new Owner(){Value = new Entity(){id = -99999, version = -99999, World = this}}); 98 | 99 | } 100 | 101 | private readonly Pool ownerPool; 102 | private readonly Pool ownerNativePool; 103 | internal Pool OwnerPool => ownerPool; 104 | internal Pool OwnerNativePool => ownerNativePool; 105 | 106 | public int GetSystemsCount() => systemsCount; 107 | public void AddSystems(Systems add) 108 | { 109 | add.id = systemsCount; 110 | if (systems[add.id]!=null) return; 111 | systems[systemsCount] = add; 112 | systemsCount++; 113 | } 114 | 115 | public Systems[] GetAllSystems() 116 | { 117 | return systems; 118 | } 119 | 120 | public T GetSystem() where T : UpdateSystem { 121 | for (int i = 0; i < systemsCount; i++) { 122 | ref var s = ref systems[i]; 123 | for (int j = 0; j < s.updateSystemsList.Count; j++) { 124 | ref var system = ref s.updateSystemsList.Items[j]; 125 | if (system is T TS) 126 | return TS; 127 | } 128 | } 129 | 130 | throw new Exception($"System of type {typeof(T).Name} is not initialized on not exist"); 131 | } 132 | internal object GetSystem(Type type) { 133 | for (int i = 0; i < systemsCount; i++) { 134 | ref var s = ref systems[i]; 135 | for (int j = 0; j < s.updateSystemsList.Count; j++) { 136 | ref var system = ref s.updateSystemsList.Items[j]; 137 | if (system.GetType().Name == type.Name) 138 | return system; 139 | } 140 | } 141 | 142 | throw new Exception($"System of type {type.Name} is not initialized on not exist"); 143 | } 144 | public void Destroy() 145 | { 146 | for (var i = 0; i < systemsCount; i++) 147 | { 148 | systems[i].Destroy(); 149 | } 150 | for (int i = 0; i < poolsAmount-1; i++) { 151 | ref var pool = ref ComponentPools[i]; 152 | pool?.Dispose(); 153 | } 154 | OnDestroy?.Invoke(); 155 | OnDestroy = null; 156 | Array.Clear(entities, 0, totalEntitiesCount); 157 | Array.Clear(entitiesData, 0, totalEntitiesCount); 158 | Array.Clear(freeEntities.Items, 0, freeEntitiesCount); 159 | Array.Clear(ComponentPools, 0, ComponentPools.Length); 160 | Entities.Clear(); 161 | Array.Clear(systems,0, systemsCount); 162 | totalEntitiesCount = 0; 163 | 164 | Alive = false; 165 | } 166 | 167 | public void SubOnDestroy(Action callback) 168 | { 169 | OnDestroy += callback; 170 | } 171 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 172 | public ref EntityData GetEntityData(int entityId) 173 | { 174 | return ref entitiesData[entityId]; 175 | } 176 | 177 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 178 | public Entity CreateEntity() 179 | { 180 | Entity entity; 181 | entity.World = this; 182 | if (freeEntities.Count == 0) 183 | { 184 | if (entitiesData.Length == totalEntitiesCount) 185 | { 186 | Array.Resize(ref entities, entities.Length + 256); 187 | Array.Resize(ref entitiesData, entitiesData.Length + 256); 188 | } 189 | 190 | entity.id = totalEntitiesCount; 191 | ref var data = ref entitiesData[entity.id]; 192 | data.version = 1; 193 | entity.version = data.version; 194 | entities[entity.id] = entity; 195 | data.id = entity.id; 196 | data.archetype = emptyArchetype; 197 | totalEntitiesCount++; 198 | } 199 | else 200 | { 201 | entity.id = freeEntities.Items[--freeEntities.Count]; 202 | ref var data = ref entitiesData[entity.id]; 203 | entity.version = data.version; 204 | data.id = entity.id; 205 | data.archetype = emptyArchetype; 206 | entities[entity.id] = entity; 207 | } 208 | aliveEntitiesCount++; 209 | return entity; 210 | } 211 | 212 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 213 | public Entity CreateEntity(Archetype archetype) 214 | { 215 | Entity entity; 216 | entity.World = this; 217 | if (freeEntities.Count == 0) 218 | { 219 | if (entitiesData.Length == totalEntitiesCount) 220 | { 221 | Array.Resize(ref entities, entities.Length + 256); 222 | Array.Resize(ref entitiesData, entitiesData.Length + 256); 223 | } 224 | 225 | entity.id = totalEntitiesCount; 226 | ref var data = ref entitiesData[entity.id]; 227 | data.version = 1; 228 | entity.version = data.version; 229 | entities[entity.id] = entity; 230 | data.id = entity.id; 231 | data.archetype = archetype; 232 | totalEntitiesCount++; 233 | } 234 | else 235 | { 236 | entity.id = freeEntities.Items[--freeEntities.Count]; 237 | ref var data = ref entitiesData[entity.id]; 238 | entity.version = data.version; 239 | data.id = entity.id; 240 | data.archetype = emptyArchetype; 241 | entities[entity.id] = entity; 242 | } 243 | aliveEntitiesCount++; 244 | return entity; 245 | } 246 | 247 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 248 | internal void OnDestroyEntity(in Entity entity) 249 | { 250 | freeEntities.Add(entity.id); 251 | aliveEntitiesCount--; 252 | } 253 | 254 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 255 | public int GetTotalEntitiesCount() 256 | { 257 | return totalEntitiesCount; 258 | } 259 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 260 | public int GetAliveEntntiesCount() { 261 | return aliveEntitiesCount; 262 | } 263 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 264 | public Pool GetPool() where T: struct 265 | { 266 | var typeID = ComponentType.ID; 267 | if (ComponentPools.Length <= typeID) 268 | { 269 | var length = ComponentPools.Length << 1; 270 | while (length <= typeID) 271 | length <<= 1; 272 | Array.Resize(ref ComponentPools, length); 273 | } 274 | var pool = (Pool)ComponentPools[typeID]; 275 | 276 | if (pool == null) 277 | { 278 | pool = new Pool(ComponentCacheSize); 279 | ComponentPools[typeID] = pool; 280 | poolsAmount++; 281 | } 282 | return pool; 283 | } 284 | 285 | 286 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 287 | public IPool GetPoolByID(int typeID) 288 | { 289 | if (ComponentPools.Length <= typeID) 290 | { 291 | var length = ComponentPools.Length << 1; 292 | while (length <= typeID + 2) 293 | length <<= 1; 294 | Array.Resize(ref ComponentPools, length); 295 | } 296 | var pool = ComponentPools[typeID]; 297 | if (pool == null) { 298 | var poolType = typeof(Pool<>); 299 | pool = (IPool) Activator.CreateInstance(poolType.MakeGenericType(ComponentType.GetTypeValue(typeID)), ComponentCacheSize); 300 | ComponentPools[typeID] = pool; 301 | poolsAmount++; 302 | } 303 | return pool; 304 | } 305 | 306 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 307 | public IPool[] GetAllPoolsInternal() { 308 | return ComponentPools; 309 | } 310 | 311 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 312 | public EventBuffer GetBuffer() where T: struct, IEvent { 313 | var type = typeof(T); 314 | if (EventBuffers.TryGetValue(type, out var buffer)) 315 | return (EventBuffer)buffer; 316 | buffer = new EventBuffer(128); 317 | EventBuffers.Add(type, buffer); 318 | return (EventBuffer)buffer; 319 | } 320 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 321 | internal IEventBuffer GetBuffer(Type type) { 322 | if (EventBuffers.TryGetValue(type, out var buffer)) 323 | return buffer; 324 | var bufferType = typeof(EventBuffer<>); 325 | var fullType = bufferType.MakeGenericType(type); 326 | buffer = (IEventBuffer) Activator.CreateInstance(fullType, 128); 327 | EventBuffers.Add(type, buffer); 328 | return buffer; 329 | } 330 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 331 | public ref Entity GetEntity(int id) 332 | { 333 | return ref entities[id]; 334 | } 335 | 336 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 337 | internal void OnAddComponent(int type, in Entity entity) 338 | { 339 | for (var i = 0; i < systemsCount; i++) 340 | systems[i].OnAdd(type, in entity); 341 | } 342 | 343 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 344 | internal void OnRemoveComponent(int type, in Entity entity) 345 | { 346 | for (var i = 0; i < systemsCount; i++) 347 | systems[i].OnRemove(type, in entity); 348 | } 349 | 350 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 351 | public void OnCreateEntityType(EntityType entityType) 352 | { 353 | // for (var i = 0; i < entitiesCount; i++) 354 | // { 355 | // ref var entityData = ref entitiesData[i]; 356 | // if(IsCompile(entityType, entityData)) 357 | // entityType.Add(entityData.id); 358 | // } 359 | } 360 | } 361 | } 362 | -------------------------------------------------------------------------------- /source/EZS/RunTime/World.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b35d9670b246fb54880f5ece5040d2dd 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/RunTime/fEntities.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.CompilerServices; 4 | 5 | namespace Wargon.ezs { 6 | 7 | public struct EntitiesEach { } 8 | 9 | public static partial class EntitiesExtensions { 10 | 11 | public static EntitiesEach With(this EntitiesEach entities) where T1 : struct { 12 | return entities; 13 | } 14 | 15 | public static EntitiesEach WithAll(this EntitiesEach entities) where T1 : struct where T2 : struct { 16 | return entities; 17 | } 18 | 19 | public static EntitiesEach WithAll(this EntitiesEach entities) 20 | where T1 : struct where T2 : struct where T3 : struct { 21 | return entities; 22 | } 23 | 24 | public static EntitiesEach Without(this EntitiesEach entities) where T1 : struct { 25 | return entities; 26 | } 27 | 28 | public static EntitiesEach Without(this EntitiesEach entities) where T1 : struct where T2 : struct { 29 | return entities; 30 | } 31 | 32 | public static EntitiesEach Without(this EntitiesEach entities) 33 | where T1 : struct where T2 : struct where T3 : struct { 34 | return entities; 35 | } 36 | 37 | public static EntitiesEach Any(this EntitiesEach entities) where T1 : struct where T2 : struct { 38 | return entities; 39 | } 40 | 41 | public static EntitiesEach Any(this EntitiesEach entities) 42 | where T1 : struct where T2 : struct where T3 : struct { 43 | return entities; 44 | } 45 | 46 | public static EntitiesEach WithOwner(this EntitiesEach entities, int id) { 47 | return entities; 48 | } 49 | 50 | // public static EntitiesEach WithOwner(this EntitiesEach entities, Entity entity) { 51 | // return entities; 52 | // } 53 | 54 | public static EntitiesEach WithJob(this EntitiesEach entities) { 55 | return entities; 56 | } 57 | 58 | public static EntitiesEach WithJobParallel(this EntitiesEach entities) { 59 | return entities; 60 | } 61 | } 62 | } -------------------------------------------------------------------------------- /source/EZS/RunTime/fEntities.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 96e6977143bd4835952d29c3009eacc0 3 | timeCreated: 1658034387 -------------------------------------------------------------------------------- /source/EZS/SourceGenerator.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f1340432b9e045379fd780460536f741 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/SourceGenerator/Generator.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexWargon/EZS/722469f2e6ae79837e971ef8d4aab535c0e4f3c6/source/EZS/SourceGenerator/Generator.dll -------------------------------------------------------------------------------- /source/EZS/SourceGenerator/Generator.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 14ff7282580dde7458c0fe49748b3df8 3 | labels: 4 | - RoslynAnalyzer 5 | PluginImporter: 6 | externalObjects: {} 7 | serializedVersion: 2 8 | iconMap: {} 9 | executionOrder: {} 10 | defineConstraints: [] 11 | isPreloaded: 0 12 | isOverridable: 0 13 | isExplicitlyReferenced: 0 14 | validateReferences: 1 15 | platformData: 16 | - first: 17 | : Any 18 | second: 19 | enabled: 0 20 | settings: 21 | Exclude Android: 0 22 | Exclude Editor: 1 23 | Exclude Linux64: 1 24 | Exclude OSXUniversal: 1 25 | Exclude Win: 1 26 | Exclude Win64: 1 27 | - first: 28 | Android: Android 29 | second: 30 | enabled: 1 31 | settings: 32 | AndroidSharedLibraryType: Executable 33 | CPU: ARMv7 34 | - first: 35 | Any: 36 | second: 37 | enabled: 0 38 | settings: {} 39 | - first: 40 | Editor: Editor 41 | second: 42 | enabled: 0 43 | settings: 44 | CPU: AnyCPU 45 | DefaultValueInitialized: true 46 | OS: AnyOS 47 | - first: 48 | Standalone: Linux64 49 | second: 50 | enabled: 0 51 | settings: 52 | CPU: None 53 | - first: 54 | Standalone: OSXUniversal 55 | second: 56 | enabled: 0 57 | settings: 58 | CPU: None 59 | - first: 60 | Standalone: Win 61 | second: 62 | enabled: 0 63 | settings: 64 | CPU: None 65 | - first: 66 | Standalone: Win64 67 | second: 68 | enabled: 0 69 | settings: 70 | CPU: None 71 | - first: 72 | Windows Store Apps: WindowsStoreApps 73 | second: 74 | enabled: 0 75 | settings: 76 | CPU: AnyCPU 77 | userData: 78 | assetBundleName: 79 | assetBundleVariant: 80 | -------------------------------------------------------------------------------- /source/EZS/SourceGenerator/Generator.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexWargon/EZS/722469f2e6ae79837e971ef8d4aab535c0e4f3c6/source/EZS/SourceGenerator/Generator.zip -------------------------------------------------------------------------------- /source/EZS/SourceGenerator/Generator.zip.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 352ecc62360690548960cdc898c1015f 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /source/EZS/Unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8510afd62905489da58352312399028d 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/Unity/BuildDebug.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb37ec368f1636c4a8231f162afb0e18 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/Unity/BuildDebug/EntityInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.UI; 5 | 6 | public class EntityInfo : MonoBehaviour { 7 | public Text id; 8 | public Text componentsCount; 9 | 10 | } 11 | 12 | public class FieldView { 13 | public Text label; 14 | public Text fieldValue; 15 | public void Show(object value) { 16 | label.text = value.GetType().Name; 17 | fieldValue.text = value.ToString(); 18 | } 19 | } -------------------------------------------------------------------------------- /source/EZS/Unity/BuildDebug/EntityInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8df0d036d34b6c74fb0e0937c1e5457e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/DebugInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEngine; 3 | using UnityEngine.SceneManagement; 4 | using Wargon.ezs; 5 | 6 | namespace Wargon.ezs.Unity 7 | { 8 | public class DebugInfo 9 | { 10 | private List systemListeners; 11 | 12 | public DebugInfo(World world) 13 | { 14 | systemListeners = new List(); 15 | var systemsPool = world.GetAllSystems(); 16 | var worldDebug = new GameObject("ECS World Debug").AddComponent(); 17 | SceneManager.sceneUnloaded += scnene => 18 | { 19 | if (!worldDebug) return; 20 | if(worldDebug.gameObject!=null) 21 | Object.Destroy(worldDebug.gameObject); 22 | }; 23 | Object.DontDestroyOnLoad(worldDebug); 24 | worldDebug.world = world; 25 | worldDebug.transform.SetSiblingIndex(0); 26 | //Debug.Log($"systems count {world.GetSystemsCount()}"); 27 | for (var i = 0; i < world.GetSystemsCount(); i++) 28 | { 29 | var systems = systemsPool[i]; 30 | var newListener = new SystemsDebug(systems, world); 31 | systems.SetListener(newListener); 32 | systemListeners.Add(newListener); 33 | } 34 | } 35 | 36 | } 37 | } 38 | 39 | 40 | -------------------------------------------------------------------------------- /source/EZS/Unity/DebugInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b67e0f55fab22cb4aa9172a139b4706f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/EZSUnity.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EZSUnity", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:bf13737622ae9074bb70c7b01500f994" 6 | ], 7 | "includePlatforms": [], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": false, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [], 14 | "versionDefines": [], 15 | "noEngineReferences": false 16 | } -------------------------------------------------------------------------------- /source/EZS/Unity/EZSUnity.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cd9b1ccf2fd24c448aba94a4ec4ed95c 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 633e41cb725840f4b8753ad453716fb2 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Blueprint.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 090f4bd92dd6d754382fde9048881353 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Blueprint/BlueprintEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity { 5 | [CustomEditor(typeof(EntityBlueprint))] 6 | public class BlueprintEditor : Editor 7 | { 8 | private GUIContent addComponentText; 9 | private GUIStyle addComponentButtonStyle; 10 | private Rect addButtonRect; 11 | private int entitiesCount; 12 | private bool flowed = true; 13 | public override void OnInspectorGUI() { 14 | EntityGUI.Init(); 15 | 16 | var blueprint = target as EntityBlueprint; 17 | 18 | 19 | EditorGUI.BeginChangeCheck(); 20 | addComponentText = new GUIContent("Add Component"); 21 | addComponentButtonStyle = GUI.skin.button; 22 | 23 | // EntityGUI.Vertical(GUI.skin.box, () => 24 | // { 25 | // EntityGUI.Horizontal(() => 26 | // { 27 | // flowed = EditorGUILayout.Foldout(flowed, $"ECS Components [{monoEntity.ComponentsCount.ToString()}]"); 28 | // 29 | // if (GUILayout.Button(new GUIContent("Clear", "Remove All Components"))) 30 | // RemoveAll(); 31 | // }); 32 | // 33 | // if (!flowed) return; 34 | // addButtonRect = GUILayoutUtility.GetRect(addComponentText, addComponentButtonStyle); 35 | // if (GUI.Button(addButtonRect, addComponentText, addComponentButtonStyle)) 36 | // { 37 | // addButtonRect.y -= 20f; 38 | // PopupWindow.Show(addButtonRect, new ComponentSearchPopup(AddComponent, manyEntities, entitiesCount)); 39 | // } 40 | // DrawComponents(); 41 | // }); 42 | 43 | 44 | } 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Blueprint/BlueprintEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 787f17d43312cb54c980293b2fad8deb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ComponentInspectorInternal.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8ad33c6bc54473443919c7dfa3544ccf 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ComponentSearchPopup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Linq; 3 | using UnityEditor; 4 | using UnityEditor.IMGUI.Controls; 5 | using UnityEngine; 6 | 7 | namespace Wargon.ezs.Unity 8 | { 9 | public class ComponentSearchPopup : PopupWindowContent 10 | { 11 | private const string COMPONENT_ICON_PATH = "Assets/EZS/Unity/Images/EcsComponentIcon.png"; 12 | private readonly SearchField addComponentsField; 13 | private readonly GUIStyle buttonStyle; 14 | private string[] componentList; 15 | private readonly int entitiesCount; 16 | private readonly Texture2D icon; 17 | private readonly GUIStyle labelStyle; 18 | private readonly MonoEntity[] manyEntities; 19 | private readonly Action OnAddComponent; 20 | private Vector2 scrollPos; 21 | private string searchComponent; 22 | 23 | public ComponentSearchPopup(Action action, MonoEntity[] entities, int count) 24 | { 25 | addComponentsField = new SearchField(); 26 | addComponentsField.SetFocus(); 27 | searchComponent = string.Empty; 28 | componentList = new string[] { }; 29 | buttonStyle = GUI.skin.customStyles[455]; 30 | buttonStyle.alignment = TextAnchor.MiddleLeft; 31 | buttonStyle.fontStyle = FontStyle.Normal; 32 | buttonStyle.onHover.background = EntityGUI.NewTexture(2, 2, new Color(0f, 1f, 0.03f)); 33 | buttonStyle.onHover.textColor = Color.black; 34 | buttonStyle.fontSize = 13; 35 | buttonStyle.hover.background = EntityGUI.NewTexture(2, 2, new Color(0f, 1f, 0.03f)); 36 | icon = EditorGUIUtility.Load(COMPONENT_ICON_PATH) as Texture2D; 37 | 38 | labelStyle = GUI.skin.customStyles[468]; 39 | labelStyle.fontStyle = FontStyle.Bold; 40 | OnAddComponent = action; 41 | manyEntities = entities; 42 | entitiesCount = count; 43 | } 44 | 45 | public override Vector2 GetWindowSize() 46 | { 47 | return new Vector2(250, 350); 48 | } 49 | 50 | public override void OnGUI(Rect rect) 51 | { 52 | searchComponent = addComponentsField.OnToolbarGUI(EditorGUILayout.GetControlRect(), searchComponent); 53 | componentList = ComponentTypesList.GetAllInArray() 54 | .Where(x => x.Contains(searchComponent, StringComparison.OrdinalIgnoreCase)).ToArray(); 55 | 56 | EditorGUILayout.LabelField("Components", labelStyle); 57 | scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(250), GUILayout.Height(306)); 58 | 59 | for (var i = 0; i < componentList.Length; i++) DrawComponentBtn(componentList[i]); 60 | EditorGUILayout.EndScrollView(); 61 | } 62 | 63 | private void DrawComponentBtn(string name) 64 | { 65 | var content = new GUIContent(name, icon); 66 | 67 | if (GUILayout.Button(content, buttonStyle)) 68 | { 69 | for (var i = 0; i < entitiesCount; i++) 70 | { 71 | var entity = manyEntities[i]; 72 | OnAddComponent?.Invoke(name, entity!); 73 | } 74 | 75 | editorWindow.Close(); 76 | } 77 | } 78 | } 79 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ComponentSearchPopup.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1f0bf587e1449e5bf4386b5d7453f44 3 | timeCreated: 1623325455 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ComponentTypesList.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Reflection; 5 | using UnityEngine; 6 | 7 | namespace Wargon.ezs.Unity { 8 | public static class ComponentTypesList { 9 | private static Dictionary Colors; 10 | private static readonly List Types = new(); 11 | public static readonly HashSet NamesHash = new(); 12 | private static string[] TypesArray; 13 | private static Type[] typesValue; 14 | private static bool inited; 15 | 16 | public static int Count => Types.Count; 17 | public static bool IsNUll => !inited; 18 | 19 | public static string Get(int index) { 20 | return Types[index]; 21 | } 22 | 23 | public static List GetAll() { 24 | return Types; 25 | } 26 | 27 | public static string[] GetAllInArray() { 28 | return TypesArray; 29 | } 30 | 31 | public static Color GetColorStyle(Type type) { 32 | return Colors[type]; 33 | } 34 | 35 | public static Type[] GetTypes() { 36 | return typesValue; 37 | } 38 | 39 | public static void Init() { 40 | if (inited) return; 41 | var assemblies = AppDomain.CurrentDomain.GetAssemblies(); 42 | var listOfComponents = new List(); 43 | foreach (var assembly in assemblies) { 44 | var componentsFromAssebly = GetTypesWithAttribute(typeof(EcsComponentAttribute), assembly).ToArray(); 45 | Array.Sort(componentsFromAssebly, (x, y) => string.Compare(x.Name, y.Name, StringComparison.Ordinal)); 46 | foreach (var type in componentsFromAssebly) { 47 | listOfComponents.Add(type); 48 | Add($"{type}"); 49 | } 50 | } 51 | 52 | typesValue = listOfComponents.ToArray(); 53 | listOfComponents.Clear(); 54 | Types.Sort(); 55 | TypesArray = Types.ToArray(); 56 | for (var i = 0; i < TypesArray.Length; i++) NamesHash.Add(TypesArray[i]); 57 | SetColorStyles(typesValue); 58 | inited = true; 59 | } 60 | 61 | private static void SetColorStyles(Type[] types) { 62 | if (Colors == null) Colors = new Dictionary(); 63 | if (Colors.Count > 1) 64 | Colors.Clear(); 65 | for (int i = 0, iMax = types.Length; i < iMax; i++) { 66 | var h = (float)i / Count; 67 | var componentColor = Color.HSVToRGB(h, 0.7f, 0.8f); 68 | componentColor.a = 0.15f; 69 | Colors.Add(types[i], componentColor); 70 | } 71 | } 72 | 73 | private static void Add(string name) { 74 | if (!Types.Contains(name)) 75 | Types.Add(name); 76 | } 77 | 78 | private static IEnumerable GetTypesWithAttribute(Type attributeType, Assembly assembly) { 79 | foreach (var type in assembly.GetTypes()) 80 | if (type.GetCustomAttributes(attributeType, true).Length > 0) 81 | yield return type; 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ComponentTypesList.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 39c982712a0f88a4dac57fa90f7dccdc 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EZSEditor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "EZSEditor", 3 | "rootNamespace": "", 4 | "references": [ 5 | "GUID:bf13737622ae9074bb70c7b01500f994", 6 | "GUID:d8b63aba1907145bea998dd612889d6b", 7 | "GUID:cd9b1ccf2fd24c448aba94a4ec4ed95c" 8 | ], 9 | "includePlatforms": [ 10 | "Editor" 11 | ], 12 | "excludePlatforms": [], 13 | "allowUnsafeCode": true, 14 | "overrideReferences": false, 15 | "precompiledReferences": [], 16 | "autoReferenced": true, 17 | "defineConstraints": [], 18 | "versionDefines": [], 19 | "noEngineReferences": false 20 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EZSEditor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aa574d55cf618164ea0f83aace8a7ebb 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EcsDebugWindow.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEditor.IMGUI.Controls; 4 | using UnityEngine; 5 | 6 | namespace Wargon.ezs.Unity 7 | { 8 | [InitializeOnLoad] 9 | public class EcsDebugWindow : EditorWindow 10 | { 11 | private static EntityInspectorWindow inspectorWindow; 12 | private readonly List EntityDrawers = new List(); 13 | private World _world; 14 | 15 | private int entityCountOld; 16 | private SearchField filterComponentsField; 17 | private string filterComponentString; 18 | private Entity FocusedEntity; 19 | private Vector2 scrollPos; 20 | 21 | private void OnEnable() 22 | { 23 | filterComponentsField = new SearchField(); 24 | filterComponentsField.SetFocus(); 25 | filterComponentString = string.Empty; 26 | } 27 | 28 | private void OnGUI() 29 | { 30 | var world = MonoConverter.GetWorld(); 31 | if (world is not { Alive: true }) 32 | { 33 | GUILayout.Label("NO WORLDS"); 34 | 35 | return; 36 | } 37 | 38 | scrollPos = EditorGUILayout.BeginScrollView(scrollPos, GUILayout.Width(position.width), 39 | GUILayout.Height(position.height)); 40 | DrawEntityList(world); 41 | EditorGUILayout.EndScrollView(); 42 | } 43 | 44 | private void OnInspectorUpdate() 45 | { 46 | if (_world == null) return; 47 | if (entityCountOld != _world.totalEntitiesCount) 48 | Repaint(); 49 | } 50 | 51 | [MenuItem("EZS/EcsDebugWindow")] 52 | public static void ShowWindow() 53 | { 54 | GetWindow(typeof(EcsDebugWindow), false, "Entities", true); 55 | inspectorWindow = (EntityInspectorWindow) GetWindow(typeof(EntityInspectorWindow), false, "Entity Inspector", true); 56 | } 57 | 58 | private static void OnFocusEntity(Entity entity) 59 | { 60 | EntityInspectorWindow.Entity = entity; 61 | } 62 | 63 | private void DrawEntityList(World world) 64 | { 65 | filterComponentString = 66 | filterComponentsField.OnGUI(EditorGUILayout.GetControlRect(), filterComponentString); 67 | _world = world; 68 | var entities = _world.entities; 69 | entityCountOld = _world.totalEntitiesCount; 70 | if (EntityDrawers.Count < _world.totalEntitiesCount) 71 | while (EntityDrawers.Count < _world.totalEntitiesCount) 72 | EntityDrawers.Add(new EntityView(_world, OnFocusEntity)); 73 | for (var i = 0; i < _world.totalEntitiesCount; i++) 74 | EntityDrawers[i].Draw(entities[i], filterComponentString); 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EcsDebugWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5b1fed9fcbca5154d9ccb84f533f7fb8 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EntityGUI.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace Wargon.ezs.Unity 7 | { 8 | public static class EntityGUI 9 | { 10 | private static Dictionary colorBoxesByType; 11 | private static bool colored = true; 12 | private static readonly Color Default = new Color(0.6f, 0.6f, 0.6f, 0.18f); 13 | private static readonly GUIStyle DEFAULT_STYLE = GUI.skin.box; 14 | [MenuItem("EZS/Colored On|Off")] 15 | private static void SetColored() 16 | { 17 | colored = !colored; 18 | } 19 | 20 | static EntityGUI() { 21 | EditorApplication.playModeStateChanged += EditorApplicationOnplayModeStateChanged; 22 | Init(); 23 | } 24 | 25 | private static void EditorApplicationOnplayModeStateChanged(PlayModeStateChange obj) { 26 | inited = false; 27 | } 28 | 29 | private static bool inited; 30 | 31 | public static void Init() 32 | { 33 | if(inited) return; 34 | 35 | colorBoxesByType = new Dictionary(); 36 | ComponentTypesList.Init(); 37 | InitColorStyles(); 38 | //Debug.Log("ENTITY GUI RELOAD"); 39 | inited = true; 40 | } 41 | private static void InitColorStyles() 42 | { 43 | var types = ComponentTypesList.GetTypes(); 44 | for (int i = 0, iMax = ComponentTypesList.Count; i < iMax; i++) 45 | { 46 | var newType = types[i]; 47 | var componentColor = ComponentTypesList.GetColorStyle(newType); 48 | var style = new GUIStyle(GUI.skin.box) {normal = {background = NewTexture(2, 2, componentColor)}}; 49 | colorBoxesByType.Add(types[i], style); 50 | } 51 | } 52 | 53 | public static GUIStyle GetColorStyleByType(Type type) { 54 | if (!colorBoxesByType.ContainsKey(type)) 55 | return DEFAULT_STYLE; 56 | return colorBoxesByType[type]; 57 | } 58 | 59 | public static Texture2D NewTexture(int width, int height, Color color) 60 | { 61 | var pixels = new Color[width * height]; 62 | for (var i = 0; i < pixels.Length; ++i) pixels[i] = color; 63 | var result = new Texture2D(width, height); 64 | result.SetPixels(pixels); 65 | result.Apply(); 66 | return result; 67 | } 68 | 69 | public static void Horizontal(GUIStyle style, Action body = null, params GUILayoutOption[] options) 70 | { 71 | GUILayout.BeginHorizontal(style, options); 72 | body?.Invoke(); 73 | GUILayout.EndHorizontal(); 74 | } 75 | 76 | public static void Horizontal(Action body = null, params GUILayoutOption[] options) 77 | { 78 | GUILayout.BeginHorizontal(options); 79 | body?.Invoke(); 80 | GUILayout.EndHorizontal(); 81 | } 82 | 83 | public static void Vertical(GUIStyle style, Action body = null, params GUILayoutOption[] options) 84 | { 85 | GUILayout.BeginVertical(style, options); 86 | body?.Invoke(); 87 | GUILayout.EndVertical(); 88 | } 89 | 90 | public static void Vertical(Action body = null, params GUILayoutOption[] options) 91 | { 92 | GUILayout.BeginVertical(options); 93 | body?.Invoke(); 94 | GUILayout.EndVertical(); 95 | } 96 | 97 | private static Styles styles; 98 | 99 | public static Styles Styles 100 | { 101 | get 102 | { 103 | if (styles == null) 104 | styles = new Styles(); 105 | return styles; 106 | } 107 | } 108 | 109 | } 110 | public class Styles 111 | { 112 | private GUIStyle font1; 113 | public GUIStyle Impact 114 | { 115 | get 116 | { 117 | if (font1 == null) 118 | { 119 | font1 = new GUIStyle(); 120 | font1.font = Font.CreateDynamicFontFromOSFont("Impact",14); 121 | } 122 | 123 | return font1; 124 | } 125 | } 126 | } 127 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EntityGUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f2a3ead80c20010418baf9e46f73e683 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EntityInspectorWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Runtime.CompilerServices; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace Wargon.ezs.Unity 7 | { 8 | public class EntityInspectorWindow : EditorWindow 9 | { 10 | public static Entity Entity; 11 | 12 | private void OnGUI() 13 | { 14 | EntityGUI.Init(); 15 | DrawInspector(); 16 | } 17 | private void Update() 18 | { 19 | Repaint(); 20 | } 21 | 22 | private static void DrawInspector() 23 | { 24 | if(!Application.isPlaying) return; 25 | //if(Entity==default) return; 26 | if (Entity.IsNULL()) 27 | { 28 | GUILayout.Label("ENTITY DEAD "); 29 | return; 30 | } 31 | ref var data = ref Entity.GetEntityData(); 32 | 33 | var componentsCount = data.ComponentsCount; 34 | GUILayout.BeginVertical(GUI.skin.box); 35 | 36 | //EditorGUILayout.LabelField($"Entity ID : {entity.id.ToString()}"); 37 | EditorGUILayout.LabelField($"Components : [{componentsCount}]", EditorStyles.boldLabel); 38 | unsafe { 39 | var index = 0; 40 | foreach (var componentTypeID in data.archetype.Mask) { 41 | ComponentInspectorInternal.DrawComponentBox(Entity, index, componentTypeID); 42 | index++; 43 | } 44 | } 45 | GUILayout.EndVertical(); 46 | } 47 | } 48 | public class EntityView 49 | { 50 | private readonly GUIStyle buttonStyle; 51 | private readonly World world; 52 | private EntityData data; 53 | private string name; 54 | private readonly Action OnFocusEntity; 55 | 56 | public EntityView(World world, Action onFocusEntity) 57 | { 58 | this.world = world; 59 | buttonStyle = GUI.skin.button; 60 | buttonStyle.alignment = TextAnchor.MiddleLeft; 61 | buttonStyle.fontStyle = FontStyle.Bold; 62 | buttonStyle.fontSize = 12; 63 | buttonStyle.fixedHeight = 20f; 64 | data = default; 65 | name = string.Empty; 66 | OnFocusEntity = onFocusEntity; 67 | } 68 | 69 | private void EntityToString(Entity entity) 70 | { 71 | name = $" ID:{entity.id}"; 72 | data = entity.GetEntityData(); 73 | unsafe { 74 | foreach (var dataComponentType in data.archetype.Mask) 75 | { 76 | var pool = world.GetPoolByID(dataComponentType); 77 | var component = pool.GetBoxed(entity.id); 78 | if (component != null) 79 | name += $"; {component.GetType()}"; 80 | } 81 | } 82 | 83 | } 84 | 85 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 86 | private bool Has(string filter) 87 | { 88 | if (filter == null) return true; 89 | return filter == string.Empty || name.Contains(filter, StringComparison.OrdinalIgnoreCase); 90 | } 91 | 92 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 93 | public void Draw(Entity entity, string filter) 94 | { 95 | if (!Has(filter)) return; 96 | if(entity.IsNULL()) return; 97 | if (name == string.Empty) 98 | EntityToString(entity); 99 | if (GUILayout.Button(name, buttonStyle)) OnFocusEntity?.Invoke(entity); 100 | } 101 | } 102 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EntityInspectorWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9d7d15ce60014d658f53c985751c8665 3 | timeCreated: 1624419436 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EzsDebugConfigs.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | 3 | namespace Wargon.ezs.Unity 4 | { 5 | [InitializeOnLoad] 6 | public class EzsDebugConfigs 7 | { 8 | public bool Colored; 9 | 10 | static EzsDebugConfigs() 11 | { 12 | ComponentTypesList.Init(); 13 | ComponentInspectorInternal.Init(); 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/EzsDebugConfigs.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ef0c7c673004d2d8e5846dd77e6a367 3 | timeCreated: 1644124956 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Graph.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | public class Graph 6 | { 7 | private readonly Vector3[] _cachedLinePointVerticies; 8 | private readonly GUIStyle _centeredStyle; 9 | private readonly GUIStyle _labelTextStyle; 10 | private readonly Vector3[] _linePoints; 11 | private float anchorRadius = 1f; 12 | private string axisFormat = "{0:0.0}"; 13 | private float axisRounding = 1f; 14 | private int gridLines = 1; 15 | private string labelFormat = "{0:0.0}"; 16 | private Color lineColor = new Color(0f, 1f, 0.5f); 17 | private int rightLinePadding = -15; 18 | private readonly float xBorder = 48f; 19 | private readonly float yBorder = 20f; 20 | 21 | public Graph(int dataLength) 22 | { 23 | _labelTextStyle = new GUIStyle(GUI.skin.label); 24 | _labelTextStyle.alignment = TextAnchor.UpperRight; 25 | _centeredStyle = new GUIStyle(); 26 | _centeredStyle.alignment = TextAnchor.UpperCenter; 27 | _centeredStyle.normal.textColor = Color.white; 28 | _linePoints = new Vector3[dataLength]; 29 | _cachedLinePointVerticies = new Vector3[4] 30 | { 31 | new Vector3(-1f, 1f, 0.0f) * anchorRadius, 32 | new Vector3(1f, 1f, 0.0f) * anchorRadius, 33 | new Vector3(1f, -1f, 0.0f) * anchorRadius, 34 | new Vector3(-1f, -1f, 0.0f) * anchorRadius 35 | }; 36 | } 37 | 38 | public void Draw(float[] data, float height) 39 | { 40 | var rect = GUILayoutUtility.GetRect(EditorGUILayout.GetControlRect().width, height); 41 | var top = rect.y + yBorder; 42 | var floor = rect.y + rect.height - yBorder; 43 | var availableHeight = floor - top; 44 | var max = data.Length != 0 ? data.Max() : 0.0f; 45 | if (max % (double) axisRounding != 0.0) 46 | max = (float) (max + (double) axisRounding - max % (double) axisRounding); 47 | DrawGridLines(top, rect.width, availableHeight, max); 48 | DrawAvg(data, top, floor, rect.width, availableHeight, max); 49 | DrawLine(data, floor, rect.width, availableHeight, max); 50 | } 51 | 52 | private void DrawGridLines(float top, float width, float availableHeight, float max) 53 | { 54 | var color = Handles.color; 55 | Handles.color = Color.grey; 56 | var num1 = gridLines + 1; 57 | var num2 = availableHeight / num1; 58 | for (var index = 0; index <= num1; ++index) 59 | { 60 | var y = top + num2 * index; 61 | Handles.DrawLine(new Vector2(xBorder, y), new Vector2(width - rightLinePadding, y)); 62 | GUI.Label(new Rect(0.0f, y - 8f, xBorder - 2f, 50f), 63 | string.Format(axisFormat, (float) (max * (1.0 - index / (double) num1))), _labelTextStyle); 64 | } 65 | 66 | Handles.color = color; 67 | } 68 | 69 | private void DrawAvg(float[] data, float top, float floor, float width, float availableHeight, float max) 70 | { 71 | var color = Handles.color; 72 | Handles.color = Color.yellow; 73 | var num = data.Average(); 74 | var y = floor - availableHeight * (num / max); 75 | Handles.DrawLine(new Vector2(xBorder, y), new Vector2(width - rightLinePadding, y)); 76 | Handles.color = color; 77 | } 78 | 79 | private void DrawLine(float[] data, float floor, float width, float availableHeight, float max) 80 | { 81 | var num1 = (width - xBorder - rightLinePadding) / data.Length; 82 | var color = Handles.color; 83 | var position = new Rect(); 84 | var flag = false; 85 | var num2 = 0.0f; 86 | Handles.color = lineColor; 87 | Handles.matrix = Matrix4x4.identity; 88 | HandleUtility.handleMaterial.SetPass(0); 89 | for (var index = 0; index < data.Length; ++index) 90 | { 91 | var num3 = data[index]; 92 | var y = floor - availableHeight * (num3 / max); 93 | var vector2_1 = new Vector2(xBorder + num1 * index, y); 94 | _linePoints[index] = new Vector3(vector2_1.x, vector2_1.y, 0.0f); 95 | var num4 = 1f; 96 | if (!flag) 97 | { 98 | var num5 = anchorRadius * 3f; 99 | var num6 = anchorRadius * 6f; 100 | var vector2_2 = vector2_1 - Vector2.up * 0.5f; 101 | position = new Rect(vector2_2.x - num5, vector2_2.y - num5, num6, num6); 102 | if (position.Contains(Event.current.mousePosition)) 103 | { 104 | flag = true; 105 | num2 = num3; 106 | num4 = 3f; 107 | } 108 | } 109 | 110 | Handles.matrix = Matrix4x4.TRS(_linePoints[index], Quaternion.identity, Vector3.one * num4); 111 | Handles.DrawAAConvexPolygon(_cachedLinePointVerticies); 112 | } 113 | 114 | Handles.matrix = Matrix4x4.identity; 115 | Handles.DrawAAPolyLine(3f, data.Length, _linePoints); 116 | if (flag) 117 | { 118 | position.y -= 16f; 119 | position.width += 50f; 120 | position.x -= 25f; 121 | GUI.Label(position, string.Format(labelFormat, num2), _centeredStyle); 122 | } 123 | 124 | Handles.color = color; 125 | } 126 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Graph.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 464fc4e922827034bb25dd36cd099a0d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f50405dfa40f23d4cbcb76a7b35cb768 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/AnimationCurveInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class AnimationCurveInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | 11 | return null; 12 | } 13 | 14 | protected override object DrawInternal(string fieldName, ref AnimationCurve field) 15 | { 16 | return EditorGUILayout.CurveField($" {fieldName}", field); 17 | } 18 | 19 | protected override AnimationCurve DrawGenericInternal(string fieldName, ref AnimationCurve field) { 20 | return EditorGUILayout.CurveField($" {fieldName}", field); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/AnimationCurveInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59edaf909ac64c388ef6e13194c64c87 3 | timeCreated: 1641699634 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/BoolInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class BoolInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | throw new System.NotImplementedException(); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref bool item) 14 | { 15 | return EditorGUILayout.Toggle($" {fieldName}", item); 16 | } 17 | 18 | protected override bool DrawGenericInternal(string fieldName, ref bool field) { 19 | return EditorGUILayout.Toggle($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/BoolInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e245201789124dc38507c50c9600bb9e 3 | timeCreated: 1641699572 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Color32Inspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class Color32Inspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | throw new System.NotImplementedException(); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Color32 field) 14 | { 15 | return EditorGUILayout.ColorField($" {fieldName}", field); 16 | } 17 | 18 | protected override Color32 DrawGenericInternal(string fieldName, ref Color32 field) { 19 | return EditorGUILayout.ColorField($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Color32Inspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f74e140f3cd442c0baee6d922e543713 3 | timeCreated: 1641700071 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/ColorInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class ColorInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | throw new System.NotImplementedException(); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Color field) 14 | { 15 | return EditorGUILayout.ColorField($" {fieldName}", field); 16 | } 17 | 18 | protected override Color DrawGenericInternal(string fieldName, ref Color field) { 19 | return EditorGUILayout.ColorField($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/ColorInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6869752420740758844bbcbffbba139 3 | timeCreated: 1641699764 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/ComponentInspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEditorInternal; 5 | using UnityEngine; 6 | using Object = UnityEngine.Object; 7 | 8 | namespace Wargon.ezs.Unity 9 | { 10 | 11 | public interface IComponentInspector 12 | { 13 | Type ComponentType { get;} 14 | void OnCreate(); 15 | object Draw(object component); 16 | } 17 | 18 | public abstract class ComponentInspector : IComponentInspector 19 | { 20 | private Type componentType; 21 | protected T target; 22 | Type IComponentInspector.ComponentType => componentType; 23 | 24 | public ComponentInspector() 25 | { 26 | componentType = typeof(T); 27 | } 28 | 29 | public virtual void OnCreate(){} 30 | public object Draw(object component) 31 | { 32 | var obj = (T)component; 33 | return DrawInternal(ref obj); 34 | } 35 | 36 | protected abstract ref T DrawInternal(ref T component); 37 | } 38 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/ComponentInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0d0e21f4cb9141118e737a0f9f83eedb 3 | timeCreated: 1653948597 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/DoubleInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class DoubleInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | throw new System.NotImplementedException(); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref double field) 14 | { 15 | return EditorGUILayout.DoubleField($" {fieldName}", field); 16 | } 17 | 18 | protected override double DrawGenericInternal(string fieldName, ref double field) { 19 | return EditorGUILayout.DoubleField($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/DoubleInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7fe6fff1650344b998adb8d425d5b6b7 3 | timeCreated: 1641699590 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/EntityInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class EntityInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | throw new System.NotImplementedException(); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Entity field) 14 | { 15 | EditorGUILayout.BeginVertical(); 16 | 17 | if (field.IsNULL() || field.World == null) 18 | { 19 | EditorGUILayout.LabelField($" {fieldName} : NULL ENTITY"); 20 | EditorGUILayout.EndVertical(); 21 | return field; 22 | } 23 | if (field.Has()) 24 | { 25 | EditorGUI.BeginDisabledGroup(true); 26 | EditorGUILayout.ObjectField(" View", field.Get().Value, typeof(MonoEntity), true); 27 | EditorGUI.EndDisabledGroup(); 28 | } 29 | else 30 | { 31 | EditorGUILayout.LabelField($" {fieldName}"); 32 | EditorGUILayout.IntField(" Entity ID", field.id); 33 | EditorGUILayout.IntField(" Entity GEN", field.InternalGetGeneration()); 34 | } 35 | 36 | EditorGUILayout.EndVertical(); 37 | return field; 38 | } 39 | 40 | protected override Entity DrawGenericInternal(string fieldName, ref Entity field) { 41 | EditorGUILayout.BeginVertical(); 42 | 43 | if (field.IsNULL() || field.World == null) 44 | { 45 | EditorGUILayout.LabelField($" {fieldName} : NULL ENTITY"); 46 | EditorGUILayout.EndVertical(); 47 | return field; 48 | } 49 | if (field.Has()) 50 | { 51 | EditorGUI.BeginDisabledGroup(true); 52 | EditorGUILayout.ObjectField(" View", field.Get().Value, typeof(MonoEntity), true); 53 | EditorGUI.EndDisabledGroup(); 54 | } 55 | else 56 | { 57 | EditorGUILayout.LabelField($" {fieldName}"); 58 | EditorGUILayout.IntField(" Entity ID", field.id); 59 | EditorGUILayout.IntField(" Entity GEN", field.InternalGetGeneration()); 60 | } 61 | 62 | EditorGUILayout.EndVertical(); 63 | return field; 64 | } 65 | } 66 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/EntityInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7e97f7b61b7d48f68d8476020a6c2d0b 3 | timeCreated: 1641699652 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/EnumInspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace Wargon.ezs.Unity 6 | { 7 | public class EnumInspector : TypeInspector 8 | { 9 | public override object DrawCollectionElement(Rect rect, object element, int index) 10 | { 11 | throw new NotImplementedException(); 12 | } 13 | 14 | protected override object DrawInternal(string fieldName, ref Enum field) 15 | { 16 | return EditorGUILayout.EnumPopup($" {fieldName}", field); 17 | } 18 | 19 | protected override Enum DrawGenericInternal(string fieldName, ref Enum field) { 20 | return EditorGUILayout.EnumPopup($" {fieldName}", field); 21 | } 22 | } 23 | 24 | public class EnumFlagInspector : TypeInspector 25 | { 26 | public override object DrawCollectionElement(Rect rect, object element, int index) 27 | { 28 | throw new NotImplementedException(); 29 | } 30 | 31 | protected override object DrawInternal(string fieldName, ref Enum field) 32 | { 33 | return EditorGUILayout.EnumFlagsField($" {fieldName}", field); 34 | } 35 | 36 | protected override Enum DrawGenericInternal(string fieldName, ref Enum field) { 37 | return EditorGUILayout.EnumFlagsField($" {fieldName}", field); 38 | } 39 | } 40 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/EnumInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 74e6cbaf21a64837b6679cb80a768780 3 | timeCreated: 1641699601 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/FloatInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEditor.UIElements; 3 | using UnityEngine; 4 | using UnityEngine.UIElements; 5 | 6 | namespace Wargon.ezs.Unity 7 | { 8 | public class FloatInspector : TypeInspector 9 | { 10 | public override object DrawCollectionElement(Rect rect, object element, int index) 11 | { 12 | throw new System.NotImplementedException(); 13 | } 14 | 15 | protected override object DrawInternal(string fieldName, ref float field) 16 | { 17 | return EditorGUILayout.FloatField($" {fieldName}", field); 18 | } 19 | 20 | protected override float DrawGenericInternal(string fieldName, ref float field) { 21 | return EditorGUILayout.FloatField($" {fieldName}", field); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/FloatInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6dae75cc8db24f5f838420097a7a4ef5 3 | timeCreated: 1641699595 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/GradientInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class GradientInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | return null; 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Gradient field) 14 | { 15 | return EditorGUILayout.GradientField($" {fieldName}", field); 16 | } 17 | 18 | protected override Gradient DrawGenericInternal(string fieldName, ref Gradient field) { 19 | return EditorGUILayout.GradientField($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/GradientInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 595d1757c1394132a2135c856ee39609 3 | timeCreated: 1641699800 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Inspectors.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Wargon.ezs.Unity { 4 | public static class Inspectors { 5 | public static class Field { 6 | public static AnimationCurveInspector AnimationCurve = new AnimationCurveInspector(); 7 | public static BoolInspector Bool = new BoolInspector(); 8 | public static Color32Inspector Color32 = new Color32Inspector(); 9 | public static ColorInspector Color = new ColorInspector(); 10 | public static DoubleInspector Double = new DoubleInspector(); 11 | public static EntityInspector Entity = new EntityInspector(); 12 | public static EnumInspector Enum = new EnumInspector(); 13 | public static FloatInspector Float = new FloatInspector(); 14 | public static GradientInspector Gradient = new GradientInspector(); 15 | public static IntInspector Int = new IntInspector(); 16 | public static LayerMaskInspector Layer = new LayerMaskInspector(); 17 | public static ListInspector List = new ListInspector(); 18 | public static QuaternionInspector Quaternion = new QuaternionInspector(); 19 | public static StringInspector String = new StringInspector(); 20 | public static Vector2Inspector Vector2 = new Vector2Inspector(); 21 | public static Vector3Inspector Vector3 = new Vector3Inspector(); 22 | public static Vector4Inspector Vector4 = new Vector4Inspector(); 23 | public static Float2Inspector Float2 = new Float2Inspector(); 24 | public static Float3Inspector Float3 = new Float3Inspector(); 25 | private static Dictionary UnityObjectInspectors = 26 | new Dictionary(); 27 | 28 | public static UnityObjectInspector UnityObject() { 29 | if (UnityObjectInspectors.TryGetValue(nameof(T), out var inspector)) 30 | return inspector; 31 | UnityObjectInspectors.Add(nameof(T), UnityObjectInspector.New(typeof(T))); 32 | return UnityObjectInspectors[nameof(T)]; 33 | } 34 | 35 | private static readonly Dictionary _inspecors = new Dictionary(); 36 | public static TypeInspector Get() { 37 | 38 | return (TypeInspector)_inspecors[nameof(T)]; 39 | } 40 | 41 | public static void Draw(string fieldName, ref T fieldValue) { 42 | var inspecor = Get(); 43 | inspecor.DrawGeneric(fieldName, ref fieldValue); 44 | } 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Inspectors.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 981e2159eb16464fb5362249ecd15efd 3 | timeCreated: 1669257960 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/IntInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class IntInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | return EditorGUI.IntField(rect, $"element [{index}]", (int)element); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref int field) 14 | { 15 | return EditorGUILayout.IntField($" {fieldName}", field); 16 | } 17 | 18 | protected override int DrawGenericInternal(string fieldName, ref int field) { 19 | return EditorGUILayout.IntField($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/IntInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d9bd975ffa8a4f9b97ce7f31f133b451 3 | timeCreated: 1641699582 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/LayerMaskInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEditorInternal; 3 | using UnityEngine; 4 | 5 | namespace Wargon.ezs.Unity 6 | { 7 | public class LayerMaskInspector : TypeInspector 8 | { 9 | public override object DrawCollectionElement(Rect rect, object element, int index) 10 | { 11 | throw new System.NotImplementedException(); 12 | } 13 | 14 | protected override object DrawInternal(string fieldName, ref LayerMask field) 15 | { 16 | LayerMask tempMask = EditorGUILayout.MaskField($" {fieldName}", 17 | InternalEditorUtility.LayerMaskToConcatenatedLayersMask(field), InternalEditorUtility.layers); 18 | return InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask); 19 | } 20 | 21 | protected override LayerMask DrawGenericInternal(string fieldName, ref LayerMask field) { 22 | LayerMask tempMask = EditorGUILayout.MaskField($" {fieldName}", 23 | InternalEditorUtility.LayerMaskToConcatenatedLayersMask(field), InternalEditorUtility.layers); 24 | return InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask); 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/LayerMaskInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d7acbc3c6b9544a081c9442118b616bf 3 | timeCreated: 1641699607 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/ListInspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using UnityEditor; 4 | using UnityEditorInternal; 5 | using UnityEngine; 6 | using Object = UnityEngine.Object; 7 | 8 | namespace Wargon.ezs.Unity 9 | { 10 | public class ListInspector : TypeInspector 11 | { 12 | private Type elementType; 13 | private ReorderableList list; 14 | private bool locked; 15 | private string nameOfField; 16 | private IList target; 17 | 18 | public void Init(Type elementType) 19 | { 20 | if (list != null) return; 21 | this.elementType = elementType; 22 | list = new ReorderableList(target, this.elementType, true, true, true, true); 23 | list.drawElementCallback = DrawListItems; 24 | list.drawHeaderCallback = DrawHeader; 25 | list.showDefaultBackground = false; 26 | list.onReorderCallback = reorderableList => { locked = !reorderableList.draggable; }; 27 | if (this.elementType == typeof(Object) || this.elementType.IsSubclassOf(typeof(Object))) 28 | list.onAddCallback = list => 29 | { 30 | if (!list.list.IsFixedSize) 31 | { 32 | list.list.Add(null); 33 | } 34 | else 35 | { 36 | var array = list.list as Array; 37 | Resize(ref array, array.Length + 1); 38 | list.list = array; 39 | } 40 | }; 41 | } 42 | 43 | private static void Resize(ref Array array, int newSize) 44 | { 45 | var elementType = array.GetType().GetElementType(); 46 | var newArray = Array.CreateInstance(elementType, newSize); 47 | Array.Copy(array, newArray, Math.Min(array.Length, newArray.Length)); 48 | array = newArray; 49 | } 50 | 51 | public void SetTarget(IList target) 52 | { 53 | this.target = target; 54 | list.list = target; 55 | } 56 | 57 | private void DrawListItems(Rect rect, int index, bool isActive, bool isFocused) 58 | { 59 | if (locked) return; 60 | var element = target[index]; 61 | ComponentInspectorInternal.SetCollectionElement(rect, element, index, $"{nameOfField} [{index}]", elementType, 62 | target); 63 | } 64 | 65 | private void DrawHeader(Rect rect) 66 | { 67 | EditorGUI.LabelField(rect, nameOfField); 68 | } 69 | 70 | public override object DrawCollectionElement(Rect rect, object element, int index) 71 | { 72 | var o = (IList) element; 73 | element = DrawInternal(nameOfField, ref o); 74 | return element; 75 | } 76 | 77 | protected override object DrawInternal(string fieldName, ref IList field) 78 | { 79 | target = field; 80 | list.list = field; 81 | nameOfField = fieldName; 82 | list.DoLayoutList(); 83 | return target; 84 | } 85 | 86 | protected override IList DrawGenericInternal(string fieldName, ref IList field) { 87 | return (IList)DrawInternal(fieldName, ref field); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/ListInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a2a6ec67160f4a3cb03d034524f965a8 3 | timeCreated: 1641699660 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/QuaternionInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class QuaternionInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | throw new System.NotImplementedException(); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Quaternion field) 14 | { 15 | var vec = QuaternionToVector4(field); 16 | var tempVec = EditorGUILayout.Vector4Field($" {fieldName}", vec); 17 | return Vector4ToQuaternion(tempVec); 18 | } 19 | 20 | protected override Quaternion DrawGenericInternal(string fieldName, ref Quaternion field) { 21 | var vec = QuaternionToVector4(field); 22 | var tempVec = EditorGUILayout.Vector4Field($" {fieldName}", vec); 23 | return Vector4ToQuaternion(tempVec); 24 | } 25 | 26 | private static Vector4 QuaternionToVector4(Quaternion rot) 27 | { 28 | return new Vector4(rot.x, rot.y, rot.z, rot.w); 29 | } 30 | 31 | private static Quaternion Vector4ToQuaternion(Vector4 vec) 32 | { 33 | return new Quaternion(vec.x, vec.y, vec.z, vec.w); 34 | } 35 | } 36 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/QuaternionInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3291580cd4ca4134b9674d604f93e464 3 | timeCreated: 1641699639 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/StringInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class StringInspector : TypeInspector 7 | { 8 | 9 | public override object DrawCollectionElement(Rect rect, object element, int index) 10 | { 11 | return EditorGUI.TextField(rect, $"element [{index}]", element as string); 12 | } 13 | 14 | protected override object DrawInternal(string fieldName, ref string field) { 15 | return EditorGUILayout.TextField (fieldName, field); 16 | } 17 | 18 | protected override string DrawGenericInternal(string fieldName, ref string field) { 19 | return EditorGUILayout.TextField (fieldName, field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/StringInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 30da718b29ad4ff99bcec670f104e62b 3 | timeCreated: 1641699646 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/TypeInspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public interface ITypeInspector 7 | { 8 | Type GetTypeOfField(); 9 | void SetTypeOfField(Type value); 10 | object Draw(string fieldName, object field); 11 | object DrawCollectionElement(Rect rect, object element, int index); 12 | } 13 | 14 | public abstract class TypeInspector : ITypeInspector 15 | { 16 | public Type FieldType; 17 | public Type GetTypeOfField() 18 | { 19 | return FieldType; 20 | } 21 | public TypeInspector() 22 | { 23 | FieldType = typeof(T); 24 | } 25 | 26 | public void SetTypeOfField(Type value) 27 | { 28 | FieldType = value; 29 | } 30 | 31 | public object Draw(string fieldName, object field) 32 | { 33 | var v = (T) field; 34 | 35 | return DrawInternal(fieldName, ref v); 36 | } 37 | 38 | public abstract object DrawCollectionElement(Rect rect, object element, int index); 39 | 40 | protected abstract object DrawInternal(string fieldName, ref T field); 41 | 42 | public T DrawGeneric(string fieldName, ref T field) { 43 | var v = field; 44 | return DrawGenericInternal(fieldName, ref field); 45 | } 46 | 47 | protected abstract T DrawGenericInternal(string fieldName, ref T field); 48 | } 49 | 50 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/TypeInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5f3256dd4baa6d24e8988baa785c9b6d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/UnityObjectInspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class UnityObjectInspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | return EditorGUI.ObjectField(rect,$"element [{index}]", element as Object, FieldType, true); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Object field) 14 | { 15 | return EditorGUILayout.ObjectField($" {fieldName}", field, FieldType, true); 16 | } 17 | 18 | protected override Object DrawGenericInternal(string fieldName, ref Object field) { 19 | return EditorGUILayout.ObjectField($" {fieldName}", field, FieldType, true); 20 | } 21 | 22 | public static UnityObjectInspector New(System.Type type) 23 | { 24 | var inspector = new UnityObjectInspector(); 25 | inspector.SetTypeOfField(type); 26 | return inspector; 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/UnityObjectInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bff8f6dbc6664fcc8d6150db22983a81 3 | timeCreated: 1653769611 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Vector2Inspector.cs: -------------------------------------------------------------------------------- 1 | using Unity.Mathematics; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace Wargon.ezs.Unity 6 | { 7 | public class Vector2Inspector : TypeInspector 8 | { 9 | public override object DrawCollectionElement(Rect rect, object element, int index) 10 | { 11 | throw new System.NotImplementedException(); 12 | } 13 | 14 | protected override object DrawInternal(string fieldName, ref Vector2 field) 15 | { 16 | return EditorGUILayout.Vector2Field($" {fieldName}", field); 17 | } 18 | 19 | protected override Vector2 DrawGenericInternal(string fieldName, ref Vector2 field) { 20 | return EditorGUILayout.Vector2Field($" {fieldName}", field); 21 | } 22 | } 23 | public class Float2Inspector : TypeInspector 24 | { 25 | public override object DrawCollectionElement(Rect rect, object element, int index) 26 | { 27 | throw new System.NotImplementedException(); 28 | } 29 | 30 | protected override object DrawInternal(string fieldName, ref float2 field) 31 | { 32 | var vector = EditorGUILayout.Vector2Field($" {fieldName}", new Vector2(field.x, field.y)); 33 | return new float2(vector.x, vector.y); 34 | } 35 | 36 | protected override float2 DrawGenericInternal(string fieldName, ref float2 field) { 37 | var vector = EditorGUILayout.Vector2Field($" {fieldName}", new Vector2(field.x, field.y)); 38 | return new float2(vector.x, vector.y); 39 | } 40 | } 41 | public class Float3Inspector : TypeInspector 42 | { 43 | public override object DrawCollectionElement(Rect rect, object element, int index) 44 | { 45 | throw new System.NotImplementedException(); 46 | } 47 | 48 | protected override object DrawInternal(string fieldName, ref float3 field) 49 | { 50 | var vector = EditorGUILayout.Vector3Field($" {fieldName}", new Vector3(field.x, field.y, field.z)); 51 | return new float3(vector.x, vector.y, field.z); 52 | } 53 | 54 | protected override float3 DrawGenericInternal(string fieldName, ref float3 field) { 55 | var vector = EditorGUILayout.Vector3Field($" {fieldName}", new Vector3(field.x, field.y, field.z)); 56 | return new float3(vector.x, vector.y, field.z); 57 | } 58 | } 59 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Vector2Inspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09a8c10bda85479d9f4de0251368e88b 3 | timeCreated: 1641699613 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Vector3Inspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class Vector3Inspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | return EditorGUI.Vector3Field(rect, $"element [1]", (Vector3)element); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Vector3 field) 14 | { 15 | return EditorGUILayout.Vector3Field($" {fieldName}", field); 16 | } 17 | 18 | protected override Vector3 DrawGenericInternal(string fieldName, ref Vector3 field) { 19 | return EditorGUILayout.Vector3Field($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Vector3Inspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bbe843af92b54208920a4d836ed48d8e 3 | timeCreated: 1641699618 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Vector4Inspector.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class Vector4Inspector : TypeInspector 7 | { 8 | public override object DrawCollectionElement(Rect rect, object element, int index) 9 | { 10 | throw new System.NotImplementedException(); 11 | } 12 | 13 | protected override object DrawInternal(string fieldName, ref Vector4 field) 14 | { 15 | return EditorGUILayout.Vector4Field($" {fieldName}", field); 16 | } 17 | 18 | protected override Vector4 DrawGenericInternal(string fieldName, ref Vector4 field) { 19 | return EditorGUILayout.Vector4Field($" {fieldName}", field); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/Inspectors/Vector4Inspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9b277977306942089e08f88ea080fcdc 3 | timeCreated: 1641699624 -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ListDrawer.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using UnityEditor; 5 | using UnityEditorInternal; 6 | using UnityEngine; 7 | using System.Linq; 8 | using Wargon.ezs; 9 | using Wargon.ezs.Unity; 10 | using Object = UnityEngine.Object; 11 | 12 | public class ListDrawer 13 | { 14 | private ReorderableList rList; 15 | private static Rect listRect = new Rect(Vector2.zero, Vector2.one * 500f); 16 | public ListDrawer(IList list, Type type) 17 | { 18 | rList = new ReorderableList(list, type); 19 | if (list.Count < 1) 20 | list.Add(null); 21 | // rList.drawHeaderCallback = (rect) => EditorGUI.LabelField(rect, type.Name); 22 | // rList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => 23 | // { 24 | // rect.y += 2f; 25 | // rect.height = EditorGUIUtility.singleLineHeight; 26 | // //EditorGUI.PropertyField(rect, rList.list., objectLabel); 27 | // 28 | // EditorGUILayout.ObjectField($" sss", rList.list[index] as Object, type, false); 29 | //}; 30 | rList.drawHeaderCallback = DrawHeader; 31 | rList.drawElementCallback = DrawListItems; 32 | //rList.onAddCallback = reorderableList => reorderableList.list.Add(null); 33 | } 34 | 35 | public IList Draw(Vector2 pos) 36 | { 37 | listRect.position = pos; 38 | rList.DoList(listRect); 39 | return rList.list; 40 | } 41 | void DrawListItems(Rect rect, int index, bool isActive, bool isFocused) 42 | { 43 | var element = rList.list[index]; //The element in the list 44 | 45 | // Create a property field and label field for each property. 46 | 47 | // The 'mobs' property. Since the enum is self-evident, I am not making a label field for it. 48 | // The property field for mobs (width 100, height of a single line) 49 | //EditorGUILayout.ObjectField($" sss", element as Object, element.GetType(), false); 50 | SetFieldValue(element, $"{element.GetType().Name} [{index}]"); 51 | } 52 | void DrawHeader(Rect rect) 53 | { 54 | string name = "Wave"; 55 | EditorGUI.LabelField(rect, name); 56 | } 57 | private static void SetFieldValue(object fieldValue, string fieldName) 58 | { 59 | switch (fieldValue) 60 | { 61 | case LayerMask field: 62 | LayerMask tempMask = EditorGUILayout.MaskField(fieldName, 63 | InternalEditorUtility.LayerMaskToConcatenatedLayersMask(field), 64 | InternalEditorUtility.layers); 65 | fieldValue = InternalEditorUtility.ConcatenatedLayersMaskToLayerMask(tempMask); 66 | break; 67 | case Enum field: 68 | fieldValue = EditorGUILayout.EnumFlagsField($" {fieldName}", field); 69 | break; 70 | case int field: 71 | fieldValue = EditorGUILayout.IntField($" {fieldName}", field); 72 | break; 73 | case float field: 74 | fieldValue = EditorGUILayout.FloatField($" {fieldName}", field); 75 | break; 76 | case bool field: 77 | fieldValue = EditorGUILayout.Toggle($" {fieldName}", field); 78 | break; 79 | case double field: 80 | fieldValue = EditorGUILayout.DoubleField($" {fieldName}", field); 81 | break; 82 | case Vector2 field: 83 | fieldValue = EditorGUILayout.Vector2Field($" {fieldName}", field); 84 | break; 85 | case Vector3 field: 86 | fieldValue = EditorGUILayout.Vector3Field($" {fieldName}", field); 87 | break; 88 | case Vector4 field: 89 | fieldValue = EditorGUILayout.Vector4Field($" {fieldName}", field); 90 | break; 91 | 92 | case AnimationCurve field: 93 | fieldValue = EditorGUILayout.CurveField($" {fieldName}", field); 94 | break; 95 | 96 | case string field: 97 | fieldValue = EditorGUILayout.TextField($" {fieldName}", field); 98 | break; 99 | case Entity field: 100 | EditorGUILayout.BeginVertical(); 101 | if (field.IsNULL()) 102 | { 103 | EditorGUILayout.LabelField($" {fieldName} : NULL"); 104 | EditorGUILayout.EndVertical(); 105 | break; 106 | } 107 | 108 | if (field.Has()) 109 | { 110 | EditorGUI.BeginDisabledGroup(true); 111 | EditorGUILayout.ObjectField($" View", field.Get().Value, typeof(MonoEntity), true); 112 | EditorGUI.EndDisabledGroup(); 113 | } 114 | else 115 | { 116 | EditorGUILayout.LabelField($" {fieldName}"); 117 | EditorGUILayout.IntField(" Entity ID", field.id); 118 | EditorGUILayout.IntField(" Entity GEN", field.InternalGetGeneration()); 119 | } 120 | 121 | EditorGUILayout.EndVertical(); 122 | break; 123 | 124 | case IList field: 125 | // EditorGUILayout.BeginVertical(); 126 | // var elementType = field.GetType().GetElementType(); 127 | // 128 | // int j = 0; 129 | // if (field.Count < 1) 130 | // field.Add(null); 131 | // 132 | // foreach (var o in field) 133 | // { 134 | // SetCollectionElement(o, $"{fieldName} [{j}]", elementType); 135 | // j++; 136 | // } 137 | // EditorGUILayout.EndVertical(); 138 | 139 | break; 140 | } 141 | 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ListDrawer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fb49dde507b0ed4e8bbc039271a9473 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/MonoEntityEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | using System; 4 | using System.Linq; 5 | using System.Reflection; 6 | using PopupWindow = UnityEditor.PopupWindow; 7 | 8 | namespace Wargon.ezs.Unity { 9 | 10 | [CustomEditor(typeof(MonoEntity), true), CanEditMultipleObjects] 11 | public class MonoEntityEditor : Editor 12 | { 13 | private MonoEntity monoEntity; 14 | private MonoEntity[] manyEntities = new MonoEntity[16]; 15 | private bool flowed = true; 16 | private GUIContent addComponentText; 17 | private GUIStyle addComponentButtonStyle; 18 | private Rect addButtonRect; 19 | private int entitiesCount; 20 | private UnityEngine.Object currentDragObject = null; 21 | 22 | public override bool RequiresConstantRepaint() { 23 | if (monoEntity == null) return false; 24 | //if (monoEntity.Entity == default(Entity)) return false; 25 | return monoEntity.runTime || base.RequiresConstantRepaint(); 26 | } 27 | 28 | public override void OnInspectorGUI() 29 | { 30 | EntityGUI.Init(); 31 | //editMany = targets.Length > 1; 32 | entitiesCount = targets.Length; 33 | for (var i = 0; i < entitiesCount; i++) 34 | { 35 | manyEntities[i] = (MonoEntity) targets[i]; 36 | } 37 | monoEntity = (MonoEntity) targets[0]; 38 | // if (GUILayout.Button("TEST JSON")) { 39 | // Debug.Log(monoEntity.ToJson()); 40 | // } 41 | // 42 | // monoEntity.json = EditorGUILayout.ObjectField("Json", monoEntity.json, typeof(TextAsset), true) as TextAsset; 43 | // if (GUILayout.Button("FROM JSON")) { 44 | // monoEntity.FromJson(monoEntity.json); 45 | // } 46 | if(monoEntity.runTime) 47 | EditorGUILayout.LabelField($"{monoEntity.Entity.GetArchetype().ToString()}"); 48 | 49 | EditorGUI.BeginChangeCheck(); 50 | addComponentText = new GUIContent("Add Component"); 51 | addComponentButtonStyle = GUI.skin.button; 52 | 53 | if (monoEntity.runTime) 54 | { 55 | EditorGUILayout.BeginHorizontal(); 56 | EditorGUILayout.Space(); 57 | if (GUILayout.Button(new GUIContent("Kill Entity"),GUILayout.Width(154), GUILayout.Height(24))) 58 | monoEntity.Entity.Destroy(); 59 | EditorGUILayout.Space(); 60 | EditorGUILayout.EndHorizontal(); 61 | } 62 | else 63 | { 64 | EditorGUILayout.BeginHorizontal(); 65 | monoEntity.destroyComponent = EditorGUILayout.Toggle("Destroy MonoBeh", monoEntity.destroyComponent); 66 | monoEntity.destroyObject = EditorGUILayout.Toggle("Destroy GO", monoEntity.destroyObject); 67 | EditorGUILayout.EndHorizontal(); 68 | } 69 | 70 | EditorGUILayout.BeginHorizontal(); 71 | EditorGUILayout.LabelField("Run Time", monoEntity.runTime ? "✔" : "✘", EditorStyles.largeLabel); 72 | EditorGUILayout.LabelField(monoEntity.runTime ? $"ID:{monoEntity.Entity.id.ToString()}" : "ID:X"); 73 | EditorGUILayout.EndHorizontal(); 74 | 75 | 76 | EntityGUI.Vertical(GUI.skin.box, () => 77 | { 78 | if (monoEntity.runTime) 79 | { 80 | if (monoEntity.Entity.IsNULL()) 81 | { 82 | EditorGUILayout.LabelField("ENTITY DEAD", EditorStyles.whiteLargeLabel); 83 | return; 84 | } 85 | } 86 | 87 | EntityGUI.Horizontal(() => 88 | { 89 | flowed = EditorGUILayout.Foldout(flowed, $"ECS Components [{monoEntity.ComponentsCount.ToString()}]"); 90 | 91 | if (GUILayout.Button(new GUIContent("Clear", "Remove All Components"))) 92 | RemoveAll(); 93 | }); 94 | 95 | if (!flowed) return; 96 | addButtonRect = GUILayoutUtility.GetRect(addComponentText, addComponentButtonStyle); 97 | if (GUI.Button(addButtonRect, addComponentText, addComponentButtonStyle)) 98 | { 99 | addButtonRect.y -= 20f; 100 | PopupWindow.Show(addButtonRect, new ComponentSearchPopup(AddComponent, manyEntities, entitiesCount)); 101 | } 102 | DrawComponents(); 103 | }); 104 | 105 | DragAndDropComponent(); 106 | 107 | EditorGUILayout.LabelField("EZS", EditorStyles.whiteMiniLabel); 108 | if (EditorGUI.EndChangeCheck()) 109 | EditorUtility.SetDirty(target); 110 | 111 | } 112 | 113 | private void DragAndDropComponent() 114 | { 115 | var dragObj = DragAndDrop.objectReferences; 116 | if (dragObj.Length > 1) 117 | { 118 | foreach (var o in dragObj) 119 | { 120 | currentDragObject = o; 121 | } 122 | } 123 | 124 | if (Event.current.rawType != EventType.DragExited) return; 125 | dragObj = DragAndDrop.objectReferences; 126 | foreach (var o in dragObj) 127 | { 128 | currentDragObject = o; 129 | } 130 | if (dragObj.Length < 1) 131 | currentDragObject = null; 132 | 133 | DragAndDrop.AcceptDrag(); 134 | if (currentDragObject == null) return; 135 | if (ComponentTypesList.NamesHash.Contains(currentDragObject.name)) 136 | { 137 | AddComponent(currentDragObject.name, monoEntity); 138 | } 139 | } 140 | 141 | 142 | private static object NewObject(Type type) { 143 | return Activator.CreateInstance(type); 144 | } 145 | 146 | private Type GetComponentType(string typeName) { 147 | //return Type.GetType(type + ",Assembly-CSharp", true); 148 | return AppDomain.CurrentDomain.GetAssemblies() 149 | .Select(x => Assembly.Load(x.FullName)) 150 | .Select(x => x.GetType(typeName)) 151 | .FirstOrDefault(x => x != null); 152 | 153 | } 154 | 155 | private void RemoveAll() { 156 | monoEntity.Components.Clear(); 157 | EditorUtility.SetDirty(target); 158 | } 159 | 160 | private void AddComponent(string componentName, MonoEntity entity) { 161 | if (entity.runTime) 162 | AddComponentRuntime(componentName,entity); 163 | else 164 | AddComponentEditor(componentName,entity); 165 | EditorUtility.SetDirty(target); 166 | } 167 | 168 | private void AddComponentEditor(string componentName, MonoEntity entity) 169 | { 170 | var type = GetComponentType(componentName); 171 | if (entity.Components.HasType(type)) { 172 | //Debug.LogError($"ENTITY ALREADY HAS '{type}' COMPONENT"); 173 | return; 174 | } 175 | 176 | var resolver = NewObject(type); 177 | //Debug.Log(resolver.GetType()); 178 | entity.Components.Add(resolver); 179 | } 180 | 181 | private void AddComponentRuntime(string componentName, MonoEntity entity) 182 | { 183 | var type = GetComponentType(componentName); 184 | unsafe { 185 | if (entity.Entity.GetEntityData().archetype.Mask.Contains(ComponentType.GetID(type))) { 186 | Debug.LogError($"ENTITY ALREADY HAS '{type}' COMPONENT"); 187 | return; 188 | } 189 | } 190 | 191 | 192 | var component= NewObject(type); 193 | entity.Entity.AddBoxed(component); 194 | entity.Components.Add(component); 195 | } 196 | 197 | private void DrawComponents() 198 | { 199 | if (monoEntity.runTime) { 200 | var archetype = monoEntity.Entity.GetArchetype(); 201 | foreach (var i in archetype.Mask) { 202 | var component = monoEntity.Entity.World.GetPoolByID(i).GetBoxed(monoEntity.id); 203 | ComponentInspectorInternal.DrawComponentRun(monoEntity, target, component); 204 | } 205 | } 206 | else { 207 | for (var i = 0; i < monoEntity.ComponentsCount; i++) { 208 | var component = monoEntity.Components[i]; 209 | if (component == null) return; 210 | ComponentInspectorInternal.DrawComponentEditor(monoEntity, target, component, i); 211 | } 212 | } 213 | //Resolve(monoEntity); 214 | // for (var index = 0; index < monoEntity.ComponentsCount; index++) 215 | // { 216 | // ComponentInspectorInternal.DrawComponentBox(monoEntity, index, manyEntities, entitiesCount, target); 217 | // } 218 | } 219 | 220 | private void Resolve(MonoEntity monoEntity) 221 | { 222 | monoEntity.Components.RemoveAll(x => x == null); 223 | } 224 | } 225 | public static class StringExtensions 226 | { 227 | public static bool Contains(this string source, string toCheck, StringComparison comp) 228 | { 229 | return source?.IndexOf(toCheck, comp) >= 0; 230 | } 231 | } 232 | public static class ListExtension 233 | { 234 | public static bool HasType(this System.Collections.IList list, Type whatHas) 235 | { 236 | var i = 0; 237 | var count = list.Count; 238 | for (i = 0; i < count; i++) 239 | { 240 | if (list[i] == null) return false; 241 | if (list[i].GetType() == whatHas) 242 | return true; 243 | } 244 | return false; 245 | } 246 | } 247 | } 248 | 249 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/MonoEntityEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1e1ad059b3bf1544cbd2164de48b9e8b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ScriptTemplates.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ffbec4e20733e9f41b27cfeeeee5c1a0 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ScriptTemplates/44-ECS123__Class Component-NewComponent.cs.txt: -------------------------------------------------------------------------------- 1 | [EcsComponent] 2 | public class #SCRIPTNAME#{ 3 | #NOTRIM# 4 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ScriptTemplates/44-ECS123__Class Component-NewComponent.cs.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fa03dc901ce5bf44980814e2fc8f4bf6 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ScriptTemplates/45-ECS123__Struct Component-NewComponent.cs.txt: -------------------------------------------------------------------------------- 1 | [EcsComponent] 2 | public struct #SCRIPTNAME#{ 3 | #NOTRIM# 4 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/ScriptTemplates/45-ECS123__Struct Component-NewComponent.cs.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59a735becc26c584abe6386ed296d3e7 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/SystemsDebugInspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | 6 | namespace Wargon.ezs.Unity 7 | { 8 | [CustomEditor(typeof(SystemsDebugMono))] 9 | public class SystemsDebugInspector : Editor 10 | { 11 | private const int SYSTEM_MONITOR_DATA_LENGTH = 140; 12 | private static bool showSystemsMonitor = true; 13 | private int lastRenderedFrameCount; 14 | private GUIContent pauseButtonContent; 15 | private bool selected; 16 | 17 | private Queue systemMonitorData; 18 | private SystemsDebug SystemsDebug; 19 | private SystemsDebugMono systemsDebugMono; 20 | private Graph systemsMonitor; 21 | private SystemView[] systemViews; 22 | 23 | private void OnEnable() 24 | { 25 | systemsDebugMono = (SystemsDebugMono) target; 26 | } 27 | 28 | public override void OnInspectorGUI() 29 | { 30 | //base.OnInspectorGUI(); 31 | DrawSystemsMonitor(systemsDebugMono.Systems); 32 | } 33 | 34 | public override bool RequiresConstantRepaint() 35 | { 36 | return true; 37 | } 38 | 39 | private void UpdateNameTime() 40 | { 41 | if(systemsDebugMono!=null) 42 | systemsDebugMono.gameObject.name = $"ECS Systems Debug {systemsDebugMono.Systems.executeTime: 0.000} ms"; 43 | } 44 | 45 | private void DrawSystemsMonitor(SystemsDebug systemsDebug) 46 | { 47 | if (systemsMonitor == null) 48 | { 49 | systemsMonitor = new Graph(SYSTEM_MONITOR_DATA_LENGTH); 50 | systemMonitorData = new Queue(new float[SYSTEM_MONITOR_DATA_LENGTH]); 51 | } 52 | 53 | if (systemViews == null) { 54 | systemViews = new SystemView[systemsDebug.Systems.updateSystemsList.Count]; 55 | for (var i = 0; i < systemViews.Length; i++) { 56 | systemViews[i].tenTimes = new Queue(); 57 | } 58 | } 59 | 60 | EditorGUILayout.BeginHorizontal(); 61 | EditorGUILayout.BeginVertical(); 62 | EditorGUILayout.LabelField("Execution duration", $"{systemsDebug.executeTime: 0.000} ms"); 63 | 64 | EditorGUILayout.EndVertical(); 65 | 66 | if (pauseButtonContent == null) 67 | pauseButtonContent = EditorGUIUtility.IconContent("PauseButton On"); 68 | 69 | systemsDebug.Systems.Alive = GUILayout.Toggle(systemsDebug.Systems.Alive, pauseButtonContent, "CommandLeft"); 70 | 71 | EditorGUILayout.EndHorizontal(); 72 | if (!EditorApplication.isPaused) 73 | AddDuration((float) systemsDebug.executeTime); 74 | systemsMonitor.Draw(systemMonitorData.ToArray(), 120f); 75 | 76 | EditorGUILayout.BeginHorizontal(GUI.skin.box); 77 | EditorGUILayout.LabelField($"Systems: [{systemsDebug.Systems.updateSystemsList.Count}]"); 78 | EditorGUILayout.LabelField("time ms: | max time ms:"); 79 | EditorGUILayout.EndHorizontal(); 80 | 81 | 82 | var burstSystemsStyle = new GUIStyle(EditorStyles.textField); 83 | burstSystemsStyle.normal.textColor = new Color(1f, 0.46f, 0f); 84 | 85 | for (var i = 0; i < systemViews.Length; i++) 86 | { 87 | ref var system = ref systemViews[i]; 88 | var systemType = systemsDebug.Systems.updateSystemsList[i].GetType(); 89 | system.name = systemType.Name; 90 | system.timems = systemsDebug.executeTimes[i]; 91 | if(systemType == typeof(RemoveComponentSystem)) continue; 92 | //system.SetNewTime(system.timems); 93 | EditorGUILayout.BeginHorizontal(GUI.skin.box); 94 | 95 | if (systemType.IsDefined(typeof(SystemColorAttribute), false)) { 96 | systemsDebug.active[i] = EditorGUILayout.Toggle(systemsDebug.active[i]); 97 | DrawSystemWithColor(systemType, ref system); 98 | } 99 | else if(systemType != typeof(RemoveComponentSystem)) 100 | { 101 | systemsDebug.active[i] = EditorGUILayout.Toggle(systemsDebug.active[i]); 102 | EditorGUILayout.LabelField(system.name); 103 | EditorGUILayout.LabelField($"{(system.timems > 0.001 ? system.timems : 0.000): 0.000} ms"); 104 | } 105 | 106 | EditorGUILayout.EndHorizontal(); 107 | } 108 | } 109 | 110 | private static void DrawSystemWithColor(Type systemType, ref SystemView system) { 111 | var atribute = (SystemColorAttribute) Attribute.GetCustomAttribute(systemType, typeof(SystemColorAttribute)); 112 | var style = new GUIStyle(EditorStyles.textField) {normal = {textColor = atribute.color}}; 113 | EditorGUILayout.LabelField(system.name, style); 114 | EditorGUILayout.LabelField($"{(system.timems/* > 0.002 ? system.time : 0.000*/): 0.000} ms", style); 115 | } 116 | 117 | private SystemView[] SortByTime(SystemView[] array) 118 | { 119 | Array.Sort(array, (x, y) => y.timems.CompareTo(x.timems)); 120 | return array; 121 | } 122 | 123 | private SystemView[] SortByName(SystemView[] array) 124 | { 125 | Array.Sort(array, (x, y) => string.Compare(y.name, x.name, StringComparison.Ordinal)); 126 | return array; 127 | } 128 | private SystemView[] SortByAvarage(SystemView[] array) 129 | { 130 | Array.Sort(array, (x, y) => y.timems.CompareTo(x.avarage)); 131 | return array; 132 | } 133 | private void AddDuration(float duration) 134 | { 135 | if (Time.renderedFrameCount == lastRenderedFrameCount) 136 | return; 137 | lastRenderedFrameCount = Time.renderedFrameCount; 138 | if (systemMonitorData.Count >= SYSTEM_MONITOR_DATA_LENGTH) 139 | { 140 | double num = systemMonitorData.Dequeue(); 141 | } 142 | 143 | systemMonitorData.Enqueue(duration); 144 | } 145 | 146 | private struct SystemView 147 | { 148 | public double timems; 149 | public double maxTime; 150 | public Queue tenTimes; 151 | public double mid; 152 | public string name; 153 | public bool active; 154 | private int lastTimeIndex; 155 | private int timesCount; 156 | public double avarage; 157 | public void SetNewTime(double value) { 158 | tenTimes.Enqueue(value); 159 | if (tenTimes.Count == 20) { 160 | tenTimes.Dequeue(); 161 | } 162 | } 163 | 164 | public double GetAvarage() { 165 | avarage = 0; 166 | foreach (var tenTime in tenTimes) { 167 | avarage += tenTime; 168 | } 169 | 170 | avarage /= tenTimes.Count; 171 | return avarage; 172 | } 173 | } 174 | } 175 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/SystemsDebugInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: dfcac7ce2d9dbbe4e92aa7ea06170948 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/WorldDebugInspector.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Runtime.CompilerServices; 4 | using System.Text; 5 | using UnityEditor; 6 | using UnityEditor.IMGUI.Controls; 7 | using UnityEngine; 8 | using UnityEngine.Profiling; 9 | 10 | namespace Wargon.ezs.Unity 11 | { 12 | [CustomEditor(typeof(WorldDebug))] 13 | public class WorldDebugInspector : Editor 14 | { 15 | private List EntityDrawers = new List(); 16 | private SearchField filterComponentsField; 17 | string filterComponentString; 18 | private bool showEntities; 19 | private bool showArchetypes; 20 | private bool showQueries; 21 | private Vector2 scrollPos; 22 | private void OnEnable() 23 | { 24 | filterComponentsField = new SearchField(); 25 | filterComponentsField.SetFocus(); 26 | filterComponentString = string.Empty; 27 | } 28 | 29 | public override bool RequiresConstantRepaint() 30 | { 31 | return true; 32 | } 33 | 34 | public override void OnInspectorGUI() 35 | { 36 | var debug = target as WorldDebug; 37 | var world = debug.world; 38 | 39 | 40 | //var sss = Profiler.GetMonoUsedSizeLong(); 41 | var floatMemory = Profiler.GetMonoUsedSizeLong() / 1048576f; 42 | var mb = floatMemory.ToStringNonAlloc("0.00"); 43 | 44 | EditorGUILayout.LabelField($"RAM ALLOCATED : {mb} MB"); 45 | EditorGUILayout.LabelField($"Total Entity Count : {world.GetTotalEntitiesCount().ToString()}"); 46 | EditorGUILayout.LabelField($"Alive Entity Count : {world.GetAliveEntntiesCount().ToString()}"); 47 | EditorGUILayout.LabelField($"Free Entity Count : {world.GetFreeEntitiesCount().ToString()}"); 48 | EditorGUILayout.LabelField($"Archetypes Count : {world.ArchetypesCount().ToString()}"); 49 | EditorGUILayout.LabelField($"Systems Count : {world.GetAllSystems()[0].updateSystemsList.Count.ToString()}"); 50 | EditorGUILayout.Space(); 51 | //DrawPools(world); 52 | EditorGUILayout.Space(); 53 | filterComponentString = filterComponentsField.OnGUI(EditorGUILayout.GetControlRect(), filterComponentString); 54 | showEntities = EditorGUILayout.Foldout(showEntities, "Entities"); 55 | showArchetypes = EditorGUILayout.Foldout(showArchetypes, "Archetypes"); 56 | showQueries = EditorGUILayout.Foldout(showQueries, "Queries"); 57 | if (showEntities) { 58 | var entities = world.entities; 59 | EditorGUILayout.BeginVertical(); 60 | scrollPos = EditorGUILayout.BeginScrollView(scrollPos); 61 | var eCount = Screen.height / 20; 62 | if (EntityDrawers.Count < eCount) 63 | { 64 | while (EntityDrawers.Count < world.totalEntitiesCount) 65 | EntityDrawers.Add(new EntityDrawer(world)); 66 | } 67 | for (var i = 1; i < eCount; i++) 68 | { 69 | EntityDrawers[i].Draw(entities[i],filterComponentString); 70 | } 71 | EditorGUILayout.EndScrollView(); 72 | EditorGUILayout.EndVertical(); 73 | GUILayout.FlexibleSpace(); 74 | } 75 | 76 | if (showArchetypes) { 77 | var archetypes = world.GetAllArchetypes(); 78 | for (var i = 0; i < archetypes.Count; i++) { 79 | ref var archetype = ref archetypes.Items[i]; 80 | EditorGUILayout.LabelField($"Archetype ID : {archetype.ID}"); 81 | // unsafe { 82 | // for (int j = 0; j < archetype.QueriesCount; j++) { 83 | // var q = archetype.Queries.ElementAt(i); 84 | // EditorGUILayout.LabelField(q->ToString()); 85 | // } 86 | // } 87 | 88 | // foreach (var i1 in archetype.Mask) { 89 | // var type = ComponentType.GetTypeValue(i1); 90 | // EntityGUI.Vertical(EntityGUI.GetColorStyleByType(type), () => { 91 | // EditorGUILayout.LabelField($"{type.Name}"); 92 | // }); 93 | // } 94 | } 95 | } 96 | 97 | if (showQueries) { 98 | var qs = world.GetAllQueries(); 99 | 100 | for (int i = 0; i < qs.Count; i++) { 101 | EditorGUILayout.LabelField(qs.Items[i].ToString()); 102 | EditorGUILayout.LabelField($"Count:{qs.Items[i].Count}"); 103 | } 104 | } 105 | 106 | } 107 | 108 | private void DrawPools(World world) 109 | { 110 | var pools = world.GetAllPoolsInternal(); 111 | for (var i = 0; i < pools.Length; i++) 112 | { 113 | if (pools[i] != null) 114 | { 115 | EditorGUILayout.LabelField("_________________________________________________________"); 116 | EditorGUILayout.LabelField($" Pool<{ComponentType.GetTypeValue(pools[i].TypeID).Name}>.Size : {pools[i].GetSize()}"); 117 | EditorGUILayout.LabelField($" Pool<{ComponentType.GetTypeValue(pools[i].TypeID).Name}>.Count : {pools[i].Count}"); 118 | } 119 | } 120 | } 121 | } 122 | 123 | public class EntityDrawer 124 | { 125 | private bool toggled; 126 | private readonly World world; 127 | private readonly GUIStyle buttonStyle; 128 | 129 | private string name; 130 | public EntityDrawer(World world) 131 | { 132 | this.world = world; 133 | //buttonStyle = GUI.skin.customStyles[223]; 134 | buttonStyle = GUI.skin.customStyles[528]; 135 | buttonStyle.alignment = TextAnchor.MiddleLeft; 136 | buttonStyle.fontStyle = FontStyle.Bold; 137 | buttonStyle.fontSize = 12; 138 | buttonStyle.fixedHeight = 20f; 139 | 140 | name = string.Empty; 141 | _stringBuilder = new StringBuilder(); 142 | } 143 | 144 | private readonly StringBuilder _stringBuilder; 145 | private void EntityToString(Entity entity) 146 | { 147 | _stringBuilder.Append($" ID:{entity.id}"); 148 | ref var data = ref entity.GetEntityData(); 149 | foreach (var dataComponentType in data.archetype.Mask) 150 | { 151 | var pool = world.GetPoolByID(dataComponentType); 152 | var component = pool.GetBoxed(entity.id); 153 | if (component != null) { 154 | name += $"; {component.GetType()}"; 155 | _stringBuilder.Append($"; {component.GetType()}"); 156 | } 157 | } 158 | name = _stringBuilder.ToString(); 159 | _stringBuilder.Clear(); 160 | } 161 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 162 | private bool Has(string filter) 163 | { 164 | if (filter == null) return true; 165 | return filter == string.Empty || name.Contains(filter, StringComparison.OrdinalIgnoreCase); 166 | } 167 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 168 | public void Draw(Entity entity, string filter) 169 | { 170 | if(!Has(filter)) return; 171 | if (name == String.Empty) 172 | name = $"e:{entity.id}"; 173 | if (GUILayout.Button(name, buttonStyle)) 174 | { 175 | toggled = !toggled; 176 | } 177 | if(toggled) 178 | WorldEntityDrawer.Draw(entity); 179 | } 180 | } 181 | 182 | public static class WorldEntityDrawer 183 | { 184 | public static void Draw(Entity entity) 185 | { 186 | ref var data = ref entity.GetEntityData(); 187 | var componentsCount = data.ComponentsCount; 188 | GUILayout.BeginVertical(GUI.skin.box); 189 | 190 | GUILayout.Label($"Entity ID :{entity.id}"); 191 | //EditorGUILayout.LabelField($"Entity ID : {entity.id.ToString()}"); 192 | EditorGUILayout.LabelField($"ECS Components : [{componentsCount}]", EditorStyles.boldLabel); 193 | var index = 0; 194 | foreach (var componentTypeID in data.archetype.Mask) { 195 | ComponentInspectorInternal.DrawComponentBox(entity, index, componentTypeID); 196 | index++; 197 | } 198 | GUILayout.EndVertical(); 199 | } 200 | } 201 | 202 | public static class FloatToString 203 | { 204 | private const string floatFormat = "0.0"; 205 | private static float decimalMultiplier = 1f; 206 | private static string[] negativeBuffer = new string[0]; 207 | private static string[] positiveBuffer = new string[0]; 208 | public static bool Inited 209 | { 210 | get 211 | { 212 | return negativeBuffer.Length > 0 || positiveBuffer.Length > 0; 213 | } 214 | } 215 | 216 | public static float MinValue 217 | { 218 | get 219 | { 220 | return -(negativeBuffer.Length - 1).FromIndex(); 221 | } 222 | } 223 | 224 | public static float MaxValue 225 | { 226 | get 227 | { 228 | return (positiveBuffer.Length - 1).FromIndex(); 229 | } 230 | } 231 | 232 | public static void Init(float minNegativeValue, float maxPositiveValue, int decimals = 1) 233 | { 234 | decimalMultiplier = Pow(10, Mathf.Clamp(decimals, 1, 5)); 235 | 236 | int negativeLength = minNegativeValue.ToIndex(); 237 | int positiveLength = maxPositiveValue.ToIndex(); 238 | 239 | if (negativeLength >= 0) 240 | { 241 | negativeBuffer = new string[negativeLength]; 242 | for (int i = 0; i < negativeLength; i++) 243 | { 244 | negativeBuffer[i] = (-i).FromIndex().ToString(floatFormat); 245 | } 246 | } 247 | 248 | if (positiveLength >= 0) 249 | { 250 | positiveBuffer = new string[positiveLength]; 251 | for (int i = 0; i < positiveLength; i++) 252 | { 253 | positiveBuffer[i] = i.FromIndex().ToString(floatFormat); 254 | } 255 | } 256 | } 257 | 258 | public static string ToStringNonAlloc(this float value) 259 | { 260 | int valIndex = value.ToIndex(); 261 | 262 | if (value < 0 && valIndex < negativeBuffer.Length) 263 | { 264 | return negativeBuffer[valIndex]; 265 | } 266 | 267 | if (value >= 0 && valIndex < positiveBuffer.Length) 268 | { 269 | return positiveBuffer[valIndex]; 270 | } 271 | 272 | return value.ToString(); 273 | } 274 | 275 | public static string ToStringNonAlloc(this float value, string format) 276 | { 277 | int valIndex = value.ToIndex(); 278 | 279 | if (value < 0 && valIndex < negativeBuffer.Length) 280 | { 281 | return negativeBuffer[valIndex]; 282 | } 283 | 284 | if (value >= 0 && valIndex < positiveBuffer.Length) 285 | { 286 | return positiveBuffer[valIndex]; 287 | } 288 | 289 | return value.ToString(format); 290 | } 291 | 292 | public static int ToInt(this float f) 293 | { 294 | return (int)f; 295 | } 296 | 297 | public static float ToFloat(this int i) 298 | { 299 | return (float)i; 300 | } 301 | 302 | private static int Pow(int f, int p) 303 | { 304 | for (int i = 1; i < p; i++) 305 | { 306 | f *= f; 307 | } 308 | return f; 309 | } 310 | 311 | private static int ToIndex(this float f) 312 | { 313 | return Mathf.Abs((f * decimalMultiplier).ToInt()); 314 | } 315 | 316 | private static float FromIndex(this int i) 317 | { 318 | return (i.ToFloat() / decimalMultiplier); 319 | } 320 | } 321 | } 322 | -------------------------------------------------------------------------------- /source/EZS/Unity/Editor/WorldDebugInspector.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 46f7ff86ac0101c4089d633dee69ab8c 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/EntityBlueprint.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | namespace Wargon.ezs.Unity { 6 | [CreateAssetMenu(fileName = "EntityBlueprint", menuName = "EZS/EntityBlueprint", order = 1)] 7 | public class EntityBlueprint : ScriptableObject { 8 | [SerializeReference] public List Components; 9 | private int[] types = Array.Empty(); 10 | private Entity entityToCopy; 11 | private bool initialized; 12 | public Entity CreateEntity() { 13 | if(!initialized) Initialize(); 14 | var world = MonoConverter.GetWorld(); 15 | var e = world.CreateEntity(); 16 | if (entityToCopy.IsNULL()) { 17 | for (var i = 0; i < types.Length; i++) { 18 | if (!AddComponent(e, Components[i], types[i])) { 19 | Debug.LogError($"Cant add component {Components[i].GetType()} in index {i}"); 20 | } 21 | } 22 | entityToCopy = e; 23 | } 24 | else { 25 | e = entityToCopy.Copy(); 26 | } 27 | return e; 28 | } 29 | 30 | private void Initialize() { 31 | types = new int[Components.Count]; 32 | for (var i = types.Length - 1; i >= 0; i--) { 33 | types[i] = ComponentType.GetID(Components[i].GetType()); 34 | } 35 | 36 | initialized = true; 37 | } 38 | private bool AddComponent(Entity entity, object component, int typeId) { 39 | ref var data = ref entity.GetEntityData(); 40 | // if (data.componentTypes.Add(typeId)) { 41 | // data.componentsCount++; 42 | // var pool = entity.World.GetPoolByID(typeId); 43 | // pool.SetBoxed(component, entity.id); 44 | // pool.Add(entity.id); 45 | // entity.World.OnAddComponent(typeId, in entity); 46 | // return true; 47 | // } 48 | return false; 49 | } 50 | 51 | } 52 | } -------------------------------------------------------------------------------- /source/EZS/Unity/EntityBlueprint.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9eb3d40bce954f358f4f7cfa4c357d4f 3 | timeCreated: 1692226355 -------------------------------------------------------------------------------- /source/EZS/Unity/Images.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 93bba1b7b588cf2478135739f02de573 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /source/EZS/Unity/Images/EZS_LOGO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexWargon/EZS/722469f2e6ae79837e971ef8d4aab535c0e4f3c6/source/EZS/Unity/Images/EZS_LOGO.png -------------------------------------------------------------------------------- /source/EZS/Unity/Images/EZS_LOGO.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b000d57751797a046bb2b8e8279a5237 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 11 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 0 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | vTOnly: 0 27 | grayScaleToAlpha: 0 28 | generateCubemap: 6 29 | cubemapConvolution: 0 30 | seamlessCubemap: 0 31 | textureFormat: 1 32 | maxTextureSize: 2048 33 | textureSettings: 34 | serializedVersion: 2 35 | filterMode: 1 36 | aniso: 1 37 | mipBias: 0 38 | wrapU: 1 39 | wrapV: 1 40 | wrapW: 1 41 | nPOTScale: 0 42 | lightmap: 0 43 | compressionQuality: 50 44 | spriteMode: 1 45 | spriteExtrude: 1 46 | spriteMeshType: 1 47 | alignment: 0 48 | spritePivot: {x: 0.5, y: 0.5} 49 | spritePixelsToUnits: 32 50 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 51 | spriteGenerateFallbackPhysicsShape: 1 52 | alphaUsage: 1 53 | alphaIsTransparency: 1 54 | spriteTessellationDetail: -1 55 | textureType: 8 56 | textureShape: 1 57 | singleChannelComponent: 0 58 | flipbookRows: 1 59 | flipbookColumns: 1 60 | maxTextureSizeSet: 0 61 | compressionQualitySet: 0 62 | textureFormatSet: 0 63 | ignorePngGamma: 0 64 | applyGammaDecoding: 0 65 | platformSettings: 66 | - serializedVersion: 3 67 | buildTarget: DefaultTexturePlatform 68 | maxTextureSize: 64 69 | resizeAlgorithm: 0 70 | textureFormat: -1 71 | textureCompression: 1 72 | compressionQuality: 50 73 | crunchedCompression: 0 74 | allowsAlphaSplitting: 0 75 | overridden: 0 76 | androidETC2FallbackOverride: 0 77 | forceMaximumCompressionQuality_BC6H_BC7: 0 78 | - serializedVersion: 3 79 | buildTarget: Standalone 80 | maxTextureSize: 64 81 | resizeAlgorithm: 0 82 | textureFormat: -1 83 | textureCompression: 1 84 | compressionQuality: 50 85 | crunchedCompression: 0 86 | allowsAlphaSplitting: 0 87 | overridden: 0 88 | androidETC2FallbackOverride: 0 89 | forceMaximumCompressionQuality_BC6H_BC7: 0 90 | - serializedVersion: 3 91 | buildTarget: Android 92 | maxTextureSize: 64 93 | resizeAlgorithm: 0 94 | textureFormat: -1 95 | textureCompression: 1 96 | compressionQuality: 50 97 | crunchedCompression: 0 98 | allowsAlphaSplitting: 0 99 | overridden: 0 100 | androidETC2FallbackOverride: 0 101 | forceMaximumCompressionQuality_BC6H_BC7: 0 102 | - serializedVersion: 3 103 | buildTarget: WebGL 104 | maxTextureSize: 64 105 | resizeAlgorithm: 0 106 | textureFormat: -1 107 | textureCompression: 1 108 | compressionQuality: 50 109 | crunchedCompression: 0 110 | allowsAlphaSplitting: 0 111 | overridden: 0 112 | androidETC2FallbackOverride: 0 113 | forceMaximumCompressionQuality_BC6H_BC7: 0 114 | spriteSheet: 115 | serializedVersion: 2 116 | sprites: [] 117 | outline: [] 118 | physicsShape: [] 119 | bones: [] 120 | spriteID: 5e97eb03825dee720800000000000000 121 | internalID: 0 122 | vertices: [] 123 | indices: 124 | edges: [] 125 | weights: [] 126 | secondaryTextures: [] 127 | spritePackingTag: 128 | pSDRemoveMatte: 0 129 | pSDShowRemoveMatteOption: 0 130 | userData: 131 | assetBundleName: 132 | assetBundleVariant: 133 | -------------------------------------------------------------------------------- /source/EZS/Unity/Images/EcsComponentIcon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AlexWargon/EZS/722469f2e6ae79837e971ef8d4aab535c0e4f3c6/source/EZS/Unity/Images/EcsComponentIcon.png -------------------------------------------------------------------------------- /source/EZS/Unity/Images/EcsComponentIcon.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a752131eeedcf8748b11765d749c8a83 3 | TextureImporter: 4 | internalIDToNameTable: [] 5 | externalObjects: {} 6 | serializedVersion: 11 7 | mipmaps: 8 | mipMapMode: 0 9 | enableMipMap: 0 10 | sRGBTexture: 1 11 | linearTexture: 0 12 | fadeOut: 0 13 | borderMipMap: 0 14 | mipMapsPreserveCoverage: 0 15 | alphaTestReferenceValue: 0.5 16 | mipMapFadeDistanceStart: 1 17 | mipMapFadeDistanceEnd: 3 18 | bumpmap: 19 | convertToNormalMap: 0 20 | externalNormalMap: 0 21 | heightScale: 0.25 22 | normalMapFilter: 0 23 | isReadable: 0 24 | streamingMipmaps: 0 25 | streamingMipmapsPriority: 0 26 | vTOnly: 0 27 | grayScaleToAlpha: 0 28 | generateCubemap: 6 29 | cubemapConvolution: 0 30 | seamlessCubemap: 0 31 | textureFormat: 1 32 | maxTextureSize: 2048 33 | textureSettings: 34 | serializedVersion: 2 35 | filterMode: 0 36 | aniso: 1 37 | mipBias: 0 38 | wrapU: 1 39 | wrapV: 1 40 | wrapW: 1 41 | nPOTScale: 0 42 | lightmap: 0 43 | compressionQuality: 50 44 | spriteMode: 1 45 | spriteExtrude: 1 46 | spriteMeshType: 1 47 | alignment: 0 48 | spritePivot: {x: 0.5, y: 0.5} 49 | spritePixelsToUnits: 32 50 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 51 | spriteGenerateFallbackPhysicsShape: 1 52 | alphaUsage: 1 53 | alphaIsTransparency: 1 54 | spriteTessellationDetail: -1 55 | textureType: 8 56 | textureShape: 1 57 | singleChannelComponent: 0 58 | flipbookRows: 1 59 | flipbookColumns: 1 60 | maxTextureSizeSet: 0 61 | compressionQualitySet: 0 62 | textureFormatSet: 0 63 | ignorePngGamma: 0 64 | applyGammaDecoding: 0 65 | platformSettings: 66 | - serializedVersion: 3 67 | buildTarget: DefaultTexturePlatform 68 | maxTextureSize: 32 69 | resizeAlgorithm: 0 70 | textureFormat: -1 71 | textureCompression: 1 72 | compressionQuality: 50 73 | crunchedCompression: 0 74 | allowsAlphaSplitting: 0 75 | overridden: 0 76 | androidETC2FallbackOverride: 0 77 | forceMaximumCompressionQuality_BC6H_BC7: 0 78 | - serializedVersion: 3 79 | buildTarget: Standalone 80 | maxTextureSize: 32 81 | resizeAlgorithm: 0 82 | textureFormat: -1 83 | textureCompression: 1 84 | compressionQuality: 50 85 | crunchedCompression: 0 86 | allowsAlphaSplitting: 0 87 | overridden: 0 88 | androidETC2FallbackOverride: 0 89 | forceMaximumCompressionQuality_BC6H_BC7: 0 90 | - serializedVersion: 3 91 | buildTarget: Android 92 | maxTextureSize: 32 93 | resizeAlgorithm: 0 94 | textureFormat: -1 95 | textureCompression: 1 96 | compressionQuality: 50 97 | crunchedCompression: 0 98 | allowsAlphaSplitting: 0 99 | overridden: 0 100 | androidETC2FallbackOverride: 0 101 | forceMaximumCompressionQuality_BC6H_BC7: 0 102 | - serializedVersion: 3 103 | buildTarget: WebGL 104 | maxTextureSize: 32 105 | resizeAlgorithm: 0 106 | textureFormat: -1 107 | textureCompression: 1 108 | compressionQuality: 50 109 | crunchedCompression: 0 110 | allowsAlphaSplitting: 0 111 | overridden: 0 112 | androidETC2FallbackOverride: 0 113 | forceMaximumCompressionQuality_BC6H_BC7: 0 114 | spriteSheet: 115 | serializedVersion: 2 116 | sprites: [] 117 | outline: [] 118 | physicsShape: [] 119 | bones: [] 120 | spriteID: 5e97eb03825dee720800000000000000 121 | internalID: 0 122 | vertices: [] 123 | indices: 124 | edges: [] 125 | weights: [] 126 | secondaryTextures: [] 127 | spritePackingTag: 128 | pSDRemoveMatte: 0 129 | pSDShowRemoveMatteOption: 0 130 | userData: 131 | assetBundleName: 132 | assetBundleVariant: 133 | -------------------------------------------------------------------------------- /source/EZS/Unity/Inactive.cs: -------------------------------------------------------------------------------- 1 | namespace Wargon.ezs.Unity { 2 | 3 | public struct Inactive { } 4 | } -------------------------------------------------------------------------------- /source/EZS/Unity/Inactive.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ecaeb1ed2f44e458625f8cbe5b2c86e 3 | timeCreated: 1696104662 -------------------------------------------------------------------------------- /source/EZS/Unity/MonoConverter.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | 3 | namespace Wargon.ezs.Unity { 4 | public static class MonoConverter { 5 | private static World world; 6 | public static bool HasWorld => world != null; 7 | public static void Init(World ecsWorld) 8 | { 9 | world = ecsWorld; 10 | } 11 | 12 | public static World GetWorld() 13 | { 14 | return world; 15 | } 16 | public static void Execute(Entity entity, List components, MonoEntity monoEntity = null) { 17 | foreach (var component in components) { 18 | if(component!=null) 19 | entity.AddBoxed(component); 20 | } 21 | entity.Add(new EntityConvertedEvent()); 22 | } 23 | } 24 | } 25 | 26 | 27 | -------------------------------------------------------------------------------- /source/EZS/Unity/MonoConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 827a8319a3f7bf14a8637fd004a36d9e 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/MonoEntity.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.Runtime.CompilerServices; 3 | using UnityEngine; 4 | 5 | namespace Wargon.ezs.Unity { 6 | [DisallowMultipleComponent][DefaultExecutionOrder(-5)] 7 | public class MonoEntity : MonoBehaviour { 8 | public Entity Entity; 9 | [SerializeReference] public List Components = new List(); 10 | public bool runTime; 11 | public bool destroyObject; 12 | public bool destroyComponent; 13 | public int id; 14 | private bool converted; 15 | private World world; 16 | private GameObject GO; 17 | public int ComponentsCount => runTime ? Entity.GetEntityData().ComponentsCount : Components.Count; 18 | private void Start() { 19 | ConvertToEntity(); 20 | } 21 | #if UNITY_EDITOR 22 | private void OnEnable() { 23 | Enable(); 24 | } 25 | private void OnDisable() { 26 | Disable(); 27 | } 28 | #endif 29 | 30 | private void OnDestroy() { 31 | if (!destroyObject) 32 | if (world != null) 33 | if (world.Alive) 34 | if (!Entity.IsNULL()) 35 | Entity.DestroyLate(); 36 | } 37 | 38 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 39 | public virtual Entity ConvertToEntity() { 40 | if (converted) return Entity; 41 | GO = gameObject; 42 | Entity = MonoConverter.GetWorld().CreateEntity(); 43 | world = Entity.World; 44 | #if UNITY_EDITOR 45 | //gameObject.name = $"{gameObject.name} ID:{Entity.id.ToString()}"; 46 | #endif 47 | id = Entity.id; 48 | MonoConverter.Execute(Entity, Components, this); 49 | converted = true; 50 | if (destroyComponent) Destroy(this); 51 | if (destroyObject) Destroy(gameObject); 52 | runTime = true; 53 | return Entity; 54 | } 55 | 56 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 57 | public ref T Get() where T : struct{ 58 | return ref Entity.Get(); 59 | } 60 | 61 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 62 | public void Remove() where T : struct { 63 | Entity.Remove(); 64 | } 65 | 66 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 67 | public void SetActive(bool state) { 68 | if (state) 69 | Enable(); 70 | else 71 | Disable(); 72 | GO.SetActive(state); 73 | } 74 | 75 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 76 | private void Disable() { 77 | if (!converted) return; 78 | if (!world.Alive) return; 79 | if (Entity.IsNULL()) return; 80 | Entity.Add(); 81 | } 82 | 83 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 84 | private void Enable() { 85 | if (!converted) return; 86 | if (Entity.Has()) 87 | Entity.Remove(); 88 | } 89 | 90 | public void DestroyWithoutEntity() { 91 | destroyObject = true; 92 | Destroy(GO); 93 | } 94 | } 95 | 96 | [EcsComponent] 97 | public struct View { 98 | public MonoEntity Value; 99 | } 100 | 101 | public static class MonoEntityExtension { 102 | 103 | public static string ToJson(this MonoEntity monoEntity) { 104 | var components = monoEntity.Components; 105 | var monoEntityJson = $"{monoEntity.name} :"; 106 | monoEntityJson += System.Environment.NewLine; 107 | for (var index = 0; index < components.Count; index++) { 108 | var component = components[index]; 109 | var type = component.GetType(); 110 | var componentJson = string.Empty; 111 | string classOrStruct = type.IsValueType ? "struct" : "class"; 112 | componentJson += $"ComponentIndex:{index} [type:{type.Name},{classOrStruct}:"; 113 | componentJson += System.Environment.NewLine; 114 | componentJson += " Fields:"; 115 | for (var i = 0; i < type.GetFields().Length; i++) { 116 | var fieldInfo = type.GetFields()[i]; 117 | componentJson += System.Environment.NewLine; 118 | componentJson += " "; 119 | var name = fieldInfo.Name; 120 | var fieldType = fieldInfo.FieldType; 121 | var fieldValue = fieldInfo.GetValue(component); 122 | componentJson += $"fieldIndex:{i} ;"; 123 | componentJson += $"Name:{name} ;"; 124 | componentJson += $"Type:{fieldType} ;"; 125 | componentJson += $"Value:"; 126 | if (fieldValue != null) 127 | componentJson += fieldValue.ToString(); 128 | else 129 | componentJson += "NULL"; 130 | componentJson += ";"; 131 | } 132 | 133 | componentJson += "];"; 134 | monoEntityJson += componentJson; 135 | monoEntityJson += System.Environment.NewLine; 136 | } 137 | 138 | System.IO.File.WriteAllText(Application.dataPath + $"/{monoEntity.name}.json", monoEntityJson); 139 | return monoEntityJson; 140 | } 141 | 142 | public static void FromJson(this MonoEntity monoEntity, TextAsset file) { 143 | var json = file.text; 144 | string[] fLines = System.Text.RegularExpressions.Regex.Split ( json, "\n|\r|\r\n" ); 145 | for (var i = 0; i < fLines.Length; i++) { 146 | Debug.Log(i); 147 | var line = fLines[i]; 148 | if (line.Contains($"ComponentIndex:{i}")) { 149 | int pFrom = line.IndexOf("type:") + "type:".Length; 150 | int pTo = line.LastIndexOf(","); 151 | 152 | var result = line.Substring(pFrom, pTo - pFrom); 153 | Debug.Log(result); 154 | } 155 | } 156 | } 157 | 158 | } 159 | } -------------------------------------------------------------------------------- /source/EZS/Unity/MonoEntity.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6a78f753171c0d49accd35a1fc938fa 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/PooledEvent.cs: -------------------------------------------------------------------------------- 1 | [EcsComponent] 2 | public struct PooledEvent 3 | { 4 | } -------------------------------------------------------------------------------- /source/EZS/Unity/PooledEvent.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1feb7026f67e4e26a927426c7620a597 3 | timeCreated: 1696105486 -------------------------------------------------------------------------------- /source/EZS/Unity/SyncTransformSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | [EcsComponent] public struct StaticTag{} 4 | [EcsComponent] public struct TransformComponent : IEquatable { 5 | public UnityEngine.Vector3 position; 6 | public UnityEngine.Vector3 scale; 7 | public UnityEngine.Quaternion rotation; 8 | 9 | public UnityEngine.Vector3 right => rotation * UnityEngine.Vector3.right; 10 | public UnityEngine.Vector3 down => rotation * UnityEngine.Vector3.right; 11 | 12 | public UnityEngine.Vector3 up { 13 | get => rotation * UnityEngine.Vector3.up; 14 | set => rotation = UnityEngine.Quaternion.FromToRotation(UnityEngine.Vector3.up, value); 15 | } 16 | public void Rorate(UnityEngine.Vector3 eulers) { 17 | UnityEngine.Quaternion quaternion = UnityEngine.Quaternion.Euler(eulers.x, eulers.y, eulers.z); 18 | rotation *= UnityEngine.Quaternion.Inverse(this.rotation) * quaternion * this.rotation; 19 | } 20 | 21 | public void RotateAround(UnityEngine.Vector3 pos, UnityEngine.Vector3 dir, float angle) { 22 | 23 | } 24 | 25 | public bool Equals(TransformComponent other) { 26 | return position == other.position && scale == other.scale && rotation == other.rotation; 27 | } 28 | public static UnityEngine.Vector3 Down(UnityEngine.Quaternion rotation) => rotation * UnityEngine.Vector3.right; 29 | } 30 | [EcsComponent] public struct TransformRef { 31 | public UnityEngine.Transform value; 32 | } 33 | [EcsComponent] public struct NotSync{} -------------------------------------------------------------------------------- /source/EZS/Unity/SyncTransformSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4b228a1b390a44418cbf7bb1349f41f8 3 | timeCreated: 1696104667 -------------------------------------------------------------------------------- /source/EZS/Unity/SyncTransformSystem2.cs: -------------------------------------------------------------------------------- 1 | namespace Wargon.ezs.Unity { 2 | public partial class SyncTransformSystem2 : UpdateSystem { 3 | private Pool transforms; 4 | private Pool transformPure; 5 | private EntityQuery query; 6 | protected override void OnCreate() { 7 | query = world.GetQuery().With().With().Without().Without(); 8 | transforms = world.GetPool(); 9 | transformPure = world.GetPool(); 10 | } 11 | 12 | public override void Update() { 13 | //Span spanT = new Span(transformPure.items); 14 | //Span spanR = new Span(transforms.items); 15 | 16 | for (var i = 0; i < query.Count; i++) { 17 | var index = query.GetEntityIndex(i); 18 | ref var transformRef = ref transforms.items[index]; 19 | ref var transformComponent = ref transformPure.items[index]; 20 | // transformComponent.right = transformComponent.rotation * UnityEngine.Vector3.right; 21 | // transformComponent.forward = transformComponent.rotation * UnityEngine.Vector3.forward; 22 | transformRef.value.localPosition = transformComponent.position; 23 | transformRef.value.rotation = transformComponent.rotation; 24 | transformRef.value.localScale = transformComponent.scale; 25 | 26 | } 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /source/EZS/Unity/SyncTransformSystem2.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f865b5a1c27b4478b8b7325f25033cd1 3 | timeCreated: 1696104940 -------------------------------------------------------------------------------- /source/EZS/Unity/SystemColorAttribute.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | 6 | namespace Wargon.ezs { 7 | [AttributeUsage(AttributeTargets.Class)] 8 | public class SystemColorAttribute : Attribute { 9 | public Color color; 10 | private static readonly Dictionary colors = new (){ 11 | {DColor.red, Color.red}, 12 | {DColor.green, Color.green}, 13 | {DColor.blue, new Color(0f, 0.65f, 1f)}, 14 | {DColor.yellow, Color.yellow}, 15 | {DColor.cyan, Color.cyan}, 16 | {DColor.violet, new Color(0.65f, 0f, 1f)}, 17 | {DColor.orange, new Color(1f, 0.59f, 0f)}, 18 | {DColor.pink, new Color(1f, 0f, 0.57f)} 19 | }; 20 | public SystemColorAttribute(string colorName) { 21 | color = colors[colorName]; 22 | } 23 | 24 | public SystemColorAttribute(float r, float g, float b) { 25 | color = new Color(r, g, b); 26 | } 27 | public SystemColorAttribute(Color c) { 28 | color = c; 29 | } 30 | } 31 | 32 | public static class DColor { 33 | public const string red = "red"; 34 | public const string green = "green"; 35 | public const string blue = "blue"; 36 | public const string yellow = "yellow"; 37 | public const string cyan = "cyan"; 38 | public const string violet = "violet"; 39 | public const string orange = "orange"; 40 | public const string pink = "pink"; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /source/EZS/Unity/SystemColorAttribute.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fcd40e7ef4e0de54aaac17fbeb576fb3 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/SystemsDebugMono.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Runtime.CompilerServices; 4 | using UnityEngine; 5 | using UnityEngine.SceneManagement; 6 | using Wargon.ezs; 7 | using Object = UnityEngine.Object; 8 | 9 | namespace Wargon.ezs.Unity 10 | { 11 | public class SystemsDebugMono : MonoBehaviour 12 | { 13 | public SystemsDebug Systems { get; private set; } 14 | public void Init(SystemsDebug systems) 15 | { 16 | Systems = systems; 17 | } 18 | } 19 | 20 | public sealed class SystemsDebug : ISystemListener 21 | { 22 | public int index; 23 | public double executeTime; 24 | public readonly double[] executeTimes; 25 | public readonly bool[] active; 26 | private readonly Stopwatch stopwatch; 27 | private readonly Stopwatch[] stopwatches; 28 | 29 | public SystemsDebug(Systems systems, World world) 30 | { 31 | Systems = systems; 32 | //Systems.SetListener(this); 33 | var newDebugMono = new GameObject().AddComponent(); 34 | world.SubOnDestroy(() => 35 | { 36 | if(newDebugMono) 37 | Object.Destroy(newDebugMono.gameObject); 38 | }); 39 | 40 | Object.DontDestroyOnLoad(newDebugMono); 41 | newDebugMono.gameObject.name = "Systems Debug"; 42 | newDebugMono.Init(this); 43 | newDebugMono.transform.SetSiblingIndex(0); 44 | stopwatch = new Stopwatch(); 45 | stopwatches = new Stopwatch[systems.updateSystemsList.Count]; 46 | active = new bool[systems.updateSystemsList.Count]; 47 | for (var i = 0; i < stopwatches.Length; i++) { 48 | stopwatches[i] = new Stopwatch(); 49 | active[i] = true; 50 | } 51 | executeTimes = new double[systems.updateSystemsList.Count]; 52 | } 53 | 54 | public Systems Systems { [MethodImpl(MethodImplOptions.AggressiveInlining)] get; } 55 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 56 | public bool Active(int index) { 57 | return active[index]; 58 | } 59 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 60 | public void StartCheck() 61 | { 62 | stopwatch.Reset(); 63 | stopwatch.Start(); 64 | } 65 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 66 | public void StopCheck() 67 | { 68 | stopwatch.Stop(); 69 | executeTime = stopwatch.Elapsed.TotalMilliseconds; 70 | } 71 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 72 | public void StartCheck(int index) 73 | { 74 | stopwatches[index].Reset(); 75 | stopwatches[index].Start(); 76 | } 77 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 78 | public void StopCheck(int index) 79 | { 80 | stopwatches[index].Stop(); 81 | executeTimes[index] = stopwatches[index].Elapsed.TotalMilliseconds; 82 | } 83 | } 84 | } -------------------------------------------------------------------------------- /source/EZS/Unity/SystemsDebugMono.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 17185985399c4594cb32bace07205f8b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/Unity/WorldDebug.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using UnityEngine; 3 | 4 | namespace Wargon.ezs.Unity 5 | { 6 | public class WorldDebug : MonoBehaviour 7 | { 8 | public World world; 9 | private void Update() 10 | { 11 | DebugUpdate.Redraw?.Invoke(); 12 | } 13 | 14 | private void OnDestroy() 15 | { 16 | DebugUpdate.Redraw = null; 17 | } 18 | } 19 | 20 | public static class DebugUpdate 21 | { 22 | public static Action Redraw; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /source/EZS/Unity/WorldDebug.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 911c4989d8caa8e47a7e5111773a657a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /source/EZS/WargonKit.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Runtime.CompilerServices; 5 | using UnityEngine; 6 | using System.Runtime.InteropServices; 7 | using JetBrains.Annotations; 8 | 9 | using Random = UnityEngine.Random; 10 | 11 | namespace Wargon 12 | { 13 | public static class ArrayHelp { 14 | public static void BasicCounting( ref int[] array) //простой вариант сортировки подсчетом 15 | { 16 | int n = array.Length; 17 | int max = 0; 18 | for (int i = 0; i < n; i++) 19 | { 20 | if (max < array[i]) 21 | { 22 | max = array[i]; 23 | } 24 | } 25 | 26 | int[] freq = new int[max + 1]; 27 | for (int i = 0; i < max + 1; i++) 28 | { 29 | freq[i] = 0; 30 | } 31 | for (int i = 0; i < n; i++) 32 | { 33 | freq[array[i]]++; 34 | } 35 | 36 | for (int i = 0, j = 0; i <= max; i++) 37 | { 38 | while (freq[i] > 0) 39 | { 40 | array[j] = i; 41 | j++; 42 | freq[i]--; 43 | } 44 | } 45 | } 46 | } 47 | public static class Kit 48 | { 49 | public static float value => Random.value; 50 | 51 | // RANDOM ARRAY 52 | public static T[] RandomArray(this T[] arrayOne, T[] arrayTwo) 53 | { 54 | var values = new List {arrayOne, arrayTwo}; 55 | var randomIndex = Random.Range(0, values.Count); 56 | return values[randomIndex]; 57 | } 58 | 59 | // RANDOM LIST 60 | public static List RandomArray(this List arrayOne, List arrayTwo) 61 | { 62 | var values = new List> {arrayOne, arrayTwo}; 63 | var randomIndex = Random.Range(0, values.Count); 64 | return values[randomIndex]; 65 | } 66 | 67 | // RANDOM BOOL WITH CHANCE ON TRUE 68 | public static bool RandomBool(float chanceOnTrue) 69 | { 70 | return Random.value < chanceOnTrue ? true : false; 71 | } 72 | 73 | // RANDOM OBJECT FROM ARRAY OF ANY TYPE 74 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 75 | public static T GetRandomElement(this T[] array) 76 | { 77 | var randomIndex = Random.Range(0, array.Length-1); 78 | return array[randomIndex]; 79 | } 80 | 81 | public static T RandomElement(List array) 82 | { 83 | var randomIndex = Random.Range(0, array.Count-1); 84 | return array[randomIndex]; 85 | } 86 | 87 | // RANDOM ENUM 88 | public static T RandomEnum() 89 | { 90 | var values = Enum.GetValues(typeof(T)); 91 | return (T) values.GetValue(Random.Range(0, values.Length)); 92 | } 93 | 94 | public static int RandomRange(int from, int to) 95 | { 96 | return Random.Range(from, to); 97 | } 98 | 99 | public static float RandomRange(float from, float to) 100 | { 101 | return Random.Range(from, to); 102 | } 103 | 104 | public static bool EnumArrayExist(T[] whatCompare, T withWhat) 105 | { 106 | for (var i = 0; i < whatCompare.Length; i++) 107 | if (whatCompare[i].Equals(withWhat)) 108 | return true; 109 | return false; 110 | } 111 | public static bool EnumArrayExist(List whatCompare, T withWhat) 112 | { 113 | for (var i = 0; i < whatCompare.Count; i++) 114 | if (whatCompare[i].Equals(withWhat)) 115 | return true; 116 | return false; 117 | } 118 | public static bool Has(this T[] whatCompare, T withWhat) 119 | { 120 | for (int i = 0,iMax = whatCompare.Length; i < iMax; i++) 121 | if (whatCompare[i].Equals(withWhat)) 122 | return true; 123 | return false; 124 | } 125 | public static bool Hass(this Enum[] whatCompare, Enum withWhat) 126 | { 127 | for (int i = 0,iMax = whatCompare.Length; i < iMax; i++) 128 | if (whatCompare[i].Equals(withWhat)) 129 | return true; 130 | return false; 131 | } 132 | public static bool MouseDown() 133 | { 134 | return Input.GetMouseButtonDown(0); 135 | } 136 | 137 | private static Camera mainCamera; 138 | private static readonly Vector3 Offset = new Vector3(0, 0, 10); 139 | public static Vector3 MousePosition() 140 | { 141 | if(mainCamera == null) 142 | mainCamera = Camera.main; 143 | if (mainCamera == null) 144 | throw new Exception("Can't get mouse position, main camera not found!"); 145 | return mainCamera.ScreenToWorldPoint(Input.mousePosition) + Offset; 146 | } 147 | public static Vector3 MousePosition([NotNull]Camera camera) 148 | { 149 | return camera.ScreenToWorldPoint(Input.mousePosition) + Offset; 150 | } 151 | public static Vector2 Rotate(Vector2 aPoint, float aDegree) 152 | { 153 | var rad = aDegree * Mathf.Deg2Rad; 154 | var s = Mathf.Sin(rad); 155 | var c = Mathf.Cos(rad); 156 | return new Vector2( 157 | aPoint.x * c - aPoint.y * s, 158 | aPoint.y * c + aPoint.x * s); 159 | } 160 | 161 | public static Vector3 RandomVector3(float range1, float range2) { 162 | return new Vector3(Random.Range(range1, range2), Random.Range(range1, range2), 163 | Random.Range(range1, range2)); 164 | } 165 | } 166 | 167 | 168 | } 169 | 170 | public static class ListExtension 171 | { 172 | public static bool HasType(this IList list, Type whatHas) 173 | { 174 | var i = 0; 175 | var count = list.Count; 176 | for (i = 0; i < count; i++) 177 | if (list[i].GetType() == whatHas) 178 | return true; 179 | return false; 180 | } 181 | } 182 | 183 | public static class Log 184 | { 185 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 186 | public static void Show(string massage) 187 | { 188 | Debug.Log(massage); 189 | } 190 | 191 | [MethodImpl(MethodImplOptions.AggressiveInlining)] 192 | public static void Show(Color color, string massage) 193 | { 194 | #if UNITY_EDITOR 195 | Debug.Log($"{massage}"); 196 | #endif 197 | } 198 | } 199 | 200 | -------------------------------------------------------------------------------- /source/EZS/WargonKit.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8b9bfc8e86c640da9df5f1449cf50219 3 | timeCreated: 1696104668 --------------------------------------------------------------------------------