Ejemplo n.º 1
0
        public static EgoComponent AddGameObject(GameObject gameObject)
        {
            var egoComponent = AddGameObjectToChildren(gameObject.transform);

            EgoEvents <AddedGameObject> .AddEvent(new AddedGameObject(gameObject, egoComponent));

            return(egoComponent);
        }
Ejemplo n.º 2
0
        public static void DestroyGameObject(EgoComponent egoComponent)
        {
            var gameObject = egoComponent.gameObject;

            EgoEvents <DestroyedGameObject> .AddEvent(new DestroyedGameObject(gameObject, egoComponent));

            EgoCleanUp.Destroy(egoComponent.gameObject);
        }
Ejemplo n.º 3
0
        public static void SetParent(EgoComponent parent, EgoComponent child)
        {
            if (child == null)
            {
                Debug.LogWarning("Cannot set the Parent of a null Child");
            }

            EgoEvents <SetParent> .AddEvent(new SetParent(parent, child));
        }
Ejemplo n.º 4
0
        public static C AddComponent <C>(EgoComponent egoComponent) where C : Component
        {
            C component = null;

            if (!egoComponent.TryGetComponents <C>(out component))
            {
                component = egoComponent.gameObject.AddComponent <C>();
                egoComponent.mask[ComponentIDs.Get(typeof(C))] = true;
                EgoEvents <AddedComponent <C> > .AddEvent(new AddedComponent <C>(component, egoComponent));
            }

            return(component);
        }
Ejemplo n.º 5
0
        public static bool DestroyComponent <C>(EgoComponent egoComponent) where C : Component
        {
            C component = null;

            if (!egoComponent.TryGetComponents <C>(out component))
            {
                return(false);
            }

            var e = new DestroyedComponent <C>(component, egoComponent);

            EgoEvents <DestroyedComponent <C> > .AddEvent(e);

            EgoCleanUp <C> .Destroy(egoComponent, component);

            return(true);
        }
Ejemplo n.º 6
0
        public static void Update()
        {
            // Update all Systems
            foreach (var system in _systems)
            {
#if UNITY_EDITOR
                if (system.enabled)
                {
                    system.Update();
                }
#else
                system.Update();
#endif
            }

            // Invoke all queued Events
            EgoEvents.Invoke();

            // Clean up Destroyed Components & GameObjects
            EgoCleanUp.CleanUp();
        }
Ejemplo n.º 7
0
        public static void Start()
        {
            var sceneCount = SceneManager.sceneCount;

            for (var sceneIndex = 0; sceneIndex < sceneCount; sceneIndex++)
            {
                var scene           = SceneManager.GetSceneAt(sceneIndex);
                var rootGameObjects = scene.GetRootGameObjects();

                // Attach an EgoComponent Component to every GameObject in the scene
                foreach (var go in rootGameObjects)
                {
                    InitEgoComponent(go);
                }

                // Add every GameObject to any relevant system
                foreach (var system in _systems)
                {
                    foreach (var go in rootGameObjects)
                    {
                        var egoComponent = go.GetComponent <EgoComponent>();
                        system.CreateBundles(egoComponent);
                    }
                }
            }

            EgoEvents.Start();

            // Start all Systems
            foreach (var system in _systems)
            {
                system.Start();
            }

            // Invoke all queued Events
            EgoEvents.Invoke();

            // Clean up Destroyed Components & GameObjects
            EgoCleanUp.CleanUp();
        }