| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224 |
- using System;
- namespace ETModel
- {
- public static class EntityFactory
- {
- public static Entity CreateWithParent(Type type, Entity parent)
- {
- Entity component = Game.ObjectPool.Fetch(type);
- component.Domain = parent.Domain;
- component.Id = component.InstanceId;
- component.Parent = parent;
-
- Game.EventSystem.Awake(component);
- return component;
- }
- public static T CreateWithParent<T>(Entity parent) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = parent.Domain;
- component.Id = component.InstanceId;
- component.Parent = parent;
-
- Game.EventSystem.Awake(component);
- return component;
- }
- public static T CreateWithParent<T, A>(Entity parent, A a) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = parent.Domain;
- component.Id = component.InstanceId;
- component.Parent = parent;
-
- Game.EventSystem.Awake(component, a);
- return component;
- }
- public static T CreateWithParent<T, A, B>(Entity parent, A a, B b) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = parent.Domain;
- component.Id = component.InstanceId;
- component.Parent = parent;
-
- Game.EventSystem.Awake(component, a, b);
- return component;
- }
- public static T CreateWithParent<T, A, B, C>(Entity parent, A a, B b, C c, bool fromPool = true) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = parent.Domain;
- component.Id = component.InstanceId;
- component.Parent = parent;
-
- Game.EventSystem.Awake(component, a, b, c);
- return component;
- }
- public static T CreateWithParent<T, A, B, C, D>(Entity parent, A a, B b, C c, D d, bool fromPool = true) where T : Entity
- {
- Type type = typeof(T);
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = parent.Domain;
- component.Id = component.InstanceId;
- component.Parent = parent;
-
- Game.EventSystem.Awake(component, a, b, c, d);
- return component;
- }
-
-
- public static Entity Create(Entity domain, Type type)
- {
- Entity component = Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = component.InstanceId;
-
- Game.EventSystem.Awake(component);
- return component;
- }
- public static T Create<T>(Entity domain) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = component.InstanceId;
- Game.EventSystem.Awake(component);
- return component;
- }
- public static T Create<T, A>(Entity domain, A a) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = component.InstanceId;
- Game.EventSystem.Awake(component, a);
- return component;
- }
- public static T Create<T, A, B>(Entity domain, A a, B b) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = component.InstanceId;
- Game.EventSystem.Awake(component, a, b);
- return component;
- }
- public static T Create<T, A, B, C>(Entity domain, A a, B b, C c) where T : Entity
- {
- Type type = typeof (T);
- T component = (T) Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = component.InstanceId;
- Game.EventSystem.Awake(component, a, b, c);
- return component;
- }
- public static T CreateWithId<T>(Entity domain, long id) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = id;
- Game.EventSystem.Awake(component);
- return component;
- }
- public static T CreateWithId<T, A>(Entity domain, long id, A a) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = id;
- Game.EventSystem.Awake(component, a);
- return component;
- }
- public static T CreateWithId<T, A, B>(Entity domain, long id, A a, B b) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = id;
- Game.EventSystem.Awake(component, a, b);
- return component;
- }
- public static T CreateWithId<T, A, B, C>(Entity domain, long id, A a, B b, C c) where T : Entity
- {
- Type type = typeof (T);
-
- T component = (T)Game.ObjectPool.Fetch(type);
- component.Domain = domain ?? component;
- component.Id = id;
- Game.EventSystem.Awake(component, a, b, c);
- return component;
- }
-
- #if SERVER
- public static Scene CreateScene(long id, string name, SceneType sceneType, Scene parent = null)
- {
- Scene scene = (Scene)Game.ObjectPool.Fetch(typeof(Scene));
- scene.Id = id;
-
- Game.EventSystem.Remove(scene.InstanceId);
-
- // 高14位是进程id
- scene.InstanceId = IdGenerater.GenerateSceneInstanceId(id);
-
- Game.EventSystem.RegisterSystem(scene);
-
- if (parent != null)
- {
- scene.Parent = parent;
- }
- scene.Domain = scene;
- scene.Name = name;
- scene.SceneType = sceneType;
-
- return scene;
- }
- #endif
-
- public static Scene CreateScene(SceneType sceneType, string name, Scene parent = null,long id = 0)
- {
- Scene scene = (Scene)Game.ObjectPool.Fetch(typeof(Scene));
- scene.Id = id != 0 ? id : IdGenerater.GenerateId();
- scene.Name = name;
- scene.SceneType = sceneType;
- if (parent != null)
- {
- scene.Parent = parent;
- }
- scene.Domain = scene;
- return scene;
- }
- }
- }
|