protected virtual void Awake() { monoEntity = GetComponent <MonoEntity>(); if (monoEntity == null) { monoEntity = gameObject.AddComponent <MonoEntity>(); } if (component == null) { component = new TComponent(); } monoEntity.GetEntityManager().AddComponent(monoEntity.Entity, component); }
public override void StartPickingEntity() { _HideScriptingConsole(); pickingEntity = true; IDisposable pickingEntityDisposable = null; pickingEntityDisposable = Observable.EveryUpdate().Subscribe(e => { if (UnityEngine.Input.GetMouseButtonDown(0)) { RaycastHit hitInfo; if (Physics.Raycast(MainCamera.ScreenPointToRay(UnityEngine.Input.mousePosition), out hitInfo, 100)) { ECS.MonoEntity entity = hitInfo.collider.GetComponent <ECS.MonoEntity>(); if (entity != null) { //Clicked on an entity Debug.Log("Picked entity:" + entity.Entity.ID); this.Publish(new Events.PickedEntity() { entity = entity.Entity }); } } _ShowScriptingConsole(); pickingEntity = false; pickingEntityDisposable.Dispose(); } else if (UnityEngine.Input.GetKeyDown(KeyCode.Escape)) { _ShowScriptingConsole(); pickingEntity = false; pickingEntityDisposable.Dispose(); } }); AddDisposable(pickingEntityDisposable); }