Exemplo n.º 1
0
        private static void OnGameObjectsAdded(GameObjectGroupEventArgs args)
        {
            // Gather a list of components to activate
            int objCount = 0;
            List <ICmpInitializable> initList = new List <ICmpInitializable>();

            foreach (GameObject obj in args.Objects)
            {
                if (!obj.ActiveSingle)
                {
                    continue;
                }
                obj.GatherInitComponents(initList, false);
                objCount++;
            }

            // If we collected components from more than one object, sort by exec order.
            // Otherwise, we can safely assume that the list is already sorted.
            if (objCount > 1)
            {
                Component.ExecOrder.SortTypedItems(initList, item => item.GetType(), false);
            }

            // Invoke the init event on all gathered components in the right order
            foreach (ICmpInitializable component in initList)
            {
                component.OnActivate();
            }

            // Fire a global event to indicate that the new objects are ready
            if (GameObjectsAdded != null)
            {
                GameObjectsAdded(current, args);
            }
        }
Exemplo n.º 2
0
 private void Scene_GameObjectsUnregistered(object sender, GameObjectGroupEventArgs e)
 {
     if (e.Objects.Contains(this.camObj))
     {
         this.SetCurrentCamera(null);
     }
 }
Exemplo n.º 3
0
 private void objectManager_GameObjectsRemoved(object sender, GameObjectGroupEventArgs e)
 {
     foreach (GameObject obj in e.Objects)
     {
         this.RemoveFromManagers(obj);
         obj.ParentScene = null;
     }
     if (this.IsCurrent)
     {
         OnGameObjectsRemoved(e);
     }
 }
Exemplo n.º 4
0
 private void objectManager_GameObjectsAdded(object sender, GameObjectGroupEventArgs e)
 {
     foreach (GameObject obj in e.Objects)
     {
         this.AddToManagers(obj);
         obj.ParentScene = this;
     }
     if (this.IsCurrent)
     {
         OnGameObjectsAdded(e);
     }
 }
Exemplo n.º 5
0
        private static void OnGameObjectsRemoved(GameObjectGroupEventArgs args)
        {
            // ToDo: Remove this event in v3.0
            foreach (GameObject obj in args.Objects)
            {
                if (GameObjectRemoved != null)
                {
                    GameObjectRemoved(current, new GameObjectEventArgs(obj));
                }
            }

            // Fire a global event to indicate that the objects are going to be shut down
            if (GameObjectsRemoved != null)
            {
                GameObjectsRemoved(current, args);
            }

            // Gather a list of components to deactivate
            int objCount = 0;
            List <ICmpInitializable> initList = new List <ICmpInitializable>();

            foreach (GameObject obj in args.Objects)
            {
                if (!obj.ActiveSingle && !obj.Disposed)
                {
                    continue;
                }
                obj.GatherInitComponents(initList, false);
                objCount++;
            }

            // If we collected components from more than one object, sort by exec order.
            // Otherwise, we can safely assume that the list is already sorted.
            if (objCount > 1)
            {
                Component.ExecOrder.SortTypedItems(initList, item => item.GetType(), true);
            }
            else
            {
                initList.Reverse();
            }

            // Invoke the init event on all gathered components in the right order
            foreach (ICmpInitializable component in initList)
            {
                component.OnShutdown(Component.ShutdownContext.Deactivate);
            }
        }
Exemplo n.º 6
0
        private void objectManager_GameObjectsRemoved(object sender, GameObjectGroupEventArgs e)
        {
            foreach (GameObject obj in e.Objects)
            {
                this.RemoveFromManagers(obj);
                obj.Scene = null;
            }

            // Fire global event for current main scene
            if (this.IsCurrent && GameObjectsRemoved != null)
            {
                GameObjectsRemoved(current, e);
            }

            // If the scene is active, deactivate any removed objects
            if (this.active)
            {
                // Gather a list of components to deactivate
                int objCount = 0;
                List <ICmpInitializable> initList = new List <ICmpInitializable>();
                foreach (GameObject obj in e.Objects)
                {
                    if (!obj.ActiveSingle && !obj.Disposed)
                    {
                        continue;
                    }
                    obj.GatherInitComponents(initList, false);
                    objCount++;
                }

                // If we collected components from more than one object, sort by exec order.
                // Otherwise, we can safely assume that the list is already sorted.
                if (objCount > 1)
                {
                    Component.ExecOrder.SortTypedItems(initList, item => item.GetType(), true);
                }
                else
                {
                    initList.Reverse();
                }

                // Invoke the init event on all gathered components in the right order
                foreach (ICmpInitializable component in initList)
                {
                    component.OnDeactivate();
                }
            }
        }
Exemplo n.º 7
0
        private static void OnGameObjectsRemoved(GameObjectGroupEventArgs args)
        {
            if (GameObjectsRemoved != null)
            {
                GameObjectsRemoved(current, args);
            }

            // ToDo: Remove this event in v3.0
            foreach (GameObject obj in args.Objects)
            {
                if (GameObjectRemoved != null)
                {
                    GameObjectRemoved(current, new GameObjectEventArgs(obj));
                }
                if (obj.Active || obj.Disposed)
                {
                    obj.OnDeactivate();
                }
            }
        }
Exemplo n.º 8
0
 private void OnSceneOnGameObjectsAdded(object sender, GameObjectGroupEventArgs args)
 {
     GameObjectsAdded?.Invoke(sender, args);
 }
Exemplo n.º 9
0
 private void Scene_GameObjectsAdded(object sender, GameObjectGroupEventArgs args)
 {
     InjectGameObjects(args.Objects);
 }