/// <summary> /// The method creates a new entity with the only component that's already attached to it. /// The component is TDisposableComponent. All entities that have that component are destroyed /// at an end of a frame with a special system. /// </summary> /// <param name="worldContext">A reference to IWorldContext implementation</param> /// <param name="name">A name of an entity (optional)</param> /// <returns>The method returns an identifier of created entity</returns> public static EntityId CreateDisposableEntity(this IWorldContext worldContext, string name = null) { IEntity entity = worldContext.GetEntityById(worldContext.CreateEntity(name)); entity.AddComponent <TDisposableComponent>(); return(entity.Id); }
/// <summary> /// The method prepares the view for initialization step /// </summary> /// <param name="worldContext">A reference to IWorldContext implementation</param> public void PreInit(IWorldContext worldContext) { WorldContext = worldContext; // create a new event which is an entity with attached component to inform system to register this view in the world's context IEntity registerViewRequestEntity = worldContext.GetEntityById(worldContext.CreateEntity()); registerViewRequestEntity.AddComponent(new TOnViewWaitForInitEventComponent { mView = this }); }
public InputSystem(IWorldContext worldContext, Camera mainCamera) { mWorldContext = worldContext; // We create a new entity which will be unique and store information about user's clicks // // For the sake of safety methods of the framework were designed in way when they return handles not references. // So when you need to get some it's better to seek for the instance via its handle mClickInfoEntity = mWorldContext.GetEntityById(mWorldContext.CreateEntity("ClickInfoEntity")); mClickInfoEntity.AddComponent <TClickComponent>(/* You can also set some initial values for the component here*/); mMainCamera = mainCamera; }
/// <summary> /// The method instantiates a new instance of a given prefab /// </summary> /// <param name="prefab">A reference to a prefab that should be created dynamically</param> /// <param name="position">A position of a new object</param> /// <param name="rotation">An orientation of an object in a space</param> /// <param name="parent">A parent of a new created object</param> /// <returns>A reference to a new created entity which is attached to a new created GameObject</returns> public IEntity Spawn(GameObject prefab, Vector3 position, Quaternion rotation, Transform parent) { GameObject gameObjectInstance = GameObject.Instantiate(prefab, position, rotation, parent); IView viewComponent = gameObjectInstance.GetComponent <IView>() ?? throw new NullReferenceException(); EntityId linkedEntityId = mWorldContext.CreateEntity(/*gameObjectInstance.name*/); IEntity linkedEntity = mWorldContext.GetEntityById(linkedEntityId); viewComponent.WorldContext = mWorldContext; linkedEntity.AddComponent(new TViewComponent { mView = viewComponent as BaseView }); viewComponent.Link(linkedEntityId); return(linkedEntity); }
public void TestUpdateMethodOfSystem_PassCorrectData_SuccessfullyProcessesData() { string entityName = "entity01"; // prepare data var e = mWorldContext.GetEntityById(mWorldContext.CreateEntity(entityName)); e.AddComponent <TOnViewWaitForInitEventComponent>(); Assert.IsNotNull(e); Assert.AreEqual(e.Name, entityName); // execute system mSystemManager.Update(0.0f); // check results Assert.DoesNotThrow(() => { Assert.IsFalse(e.HasComponent <TOnViewWaitForInitEventComponent>()); Assert.IsTrue(e.HasComponent <TViewComponent>()); }); }
public static IEntity CreateAndGetEntity(this IWorldContext worldContext, string name = null) { return(worldContext.GetEntityById(worldContext.CreateEntity(name))); }
public void TestEntitiesCreation_Pass() { // new entities that are created in continuous manner // should have increasing identifiers with a delta equals to 1 for (uint i = 0; i < 10; ++i) { Assert.AreEqual(i, (uint)mWorldContext.CreateEntity()); Assert.AreEqual(i, (uint)mWorldContext.GetEntityById((EntityId)i).Id); } }