Exemplo n.º 1
0
        public override void OnLevelUnloading()
        {
            base.OnLevelUnloading();

            //Code below destroys any created UI from the screen.
            try
            {
                UIComponent   _getui   = UIView.GetAView().FindUIComponent <UIComponent>("ChatLogPanel");
                UIComponent[] children = _getui.GetComponentsInChildren <UIComponent>();

                foreach (UIComponent child in children)
                {
                    Object.Destroy(child);
                }

                // Destroy duplicated multiplayer button
                UIComponent temp = UIView.GetAView().FindUIComponent("MPConnectionPanel");
                if (temp)
                {
                    Object.Destroy(temp);
                }

                // Destroy multiplayer join panel
                UIComponent clientJoinPanel = UIView.GetAView().FindUIComponent("MPClientJoinPanel");
                if (clientJoinPanel)
                {
                    Object.Destroy(clientJoinPanel);
                }
            }
            catch (NullReferenceException)
            {
                // Ignore, because it sometimes throws them... (Not caused by us)
                // TODO: Rework this to be more stable
            }
        }
        /// <summary>
        /// Kills a vessel.
        /// </summary>
        private static void KillVessel(Vessel killVessel, string reason)
        {
            if (killVessel == null || killVessel.state == Vessel.State.DEAD)
            {
                return;
            }

            LunaLog.Log($"[LMP]: Killing vessel {killVessel.id}. Reason: {reason}");
            SwitchVesselIfKillingActiveVessel(killVessel);

            try
            {
                if (FlightGlobals.fetch.VesselTarget?.GetVessel().id == killVessel.id)
                {
                    FlightGlobals.fetch.SetVesselTarget(null);
                }

                FlightGlobals.RemoveVessel(killVessel);
                foreach (var part in killVessel.parts)
                {
                    Object.Destroy(part.gameObject);
                }
                Object.Destroy(killVessel.gameObject);

                HighLogic.CurrentGame.flightState.protoVessels.RemoveAll(v => v == null || v.vesselID == killVessel.id);
                if (KSCVesselMarkers.fetch)
                {
                    KSCVesselMarkers.fetch.RefreshMarkers();
                }
            }
            catch (Exception killException)
            {
                LunaLog.LogError($"[LMP]: Error destroying vessel: {killException}");
            }
        }
Exemplo n.º 3
0
        static void ReplaceVehicleAI <TOldAI, TNewAI>(VehicleInfo i)
            where TOldAI : VehicleAI where TNewAI : VehicleAI
        {
            // Requires the object to have the old AI
            var oldAI = i.gameObject.GetComponent <TOldAI>();

            if (oldAI == null || oldAI.GetType() != typeof(TOldAI))
            {
                return;
            }

            // Requires the object to not already have the new AI
            var newAI = i.gameObject.GetComponent <TNewAI>();

            if (newAI != null && newAI.GetType() == typeof(TNewAI))
            {
                CODebug.Log(LogChannel.Modding, string.Format("SlowSpeed: {0} already has {1}", i.name, typeof(TNewAI)));
                return;
            }

            CODebug.Log(LogChannel.Modding, string.Format("SlowSpeed: Replacing {0}'s {1} with {2}",
                                                          i.name, typeof(TOldAI), typeof(TNewAI)));

            newAI = i.gameObject.AddComponent <TNewAI>();

            ShallowCopyTo(oldAI, newAI);

            oldAI.ReleaseAI();
            i.m_vehicleAI = newAI;
            UObject.Destroy(oldAI);
            newAI.InitializeAI();
        }
Exemplo n.º 4
0
        private static void Postfix(uGUI_BlueprintsTab __instance)
        {
            if (Core.BlueprintHideList == null)
            {
                GenerateList(__instance);
            }

            foreach (KeyValuePair <TechCategory, List <TechType> > keyValuePair in Core.BlueprintHideList)
            {
                foreach (TechType techType in keyValuePair.Value)
                {
                    if (__instance.entries.ContainsKey(keyValuePair.Key) && __instance.entries[keyValuePair.Key].entries.ContainsKey(techType))
                    {
                        uGUI_BlueprintsTab.CategoryEntry categoryEntry = __instance.entries[keyValuePair.Key];
                        uGUI_BlueprintEntry entry = __instance.entries[keyValuePair.Key].entries[techType];

                        NotificationManager.main.UnregisterTarget(entry);
                        categoryEntry.entries.Remove(techType);
                        Object.Destroy(entry.gameObject);
                        if (categoryEntry.entries.Count == 0)
                        {
                            Object.Destroy(categoryEntry.title.gameObject);
                            Object.Destroy(categoryEntry.canvas.gameObject);
                            __instance.entries.Remove(keyValuePair.Key);
                        }
                    }
                }
            }
        }
Exemplo n.º 5
0
        internal static void OnLeave(DestroyingEventArgs ev)
        {
            if (ev.Player?.UserId == null || ev.Player.IsHost || !ev.Player.IsVerified || ev.Player.IPAddress == "127.0.0.WAN" || ev.Player.IPAddress == "127.0.0.1")
            {
                return;
            }

            if (ev.Player.GameObject.TryGetComponent <HatPlayerComponent>(out var playerComponent) && playerComponent.item != null)
            {
                Object.Destroy(playerComponent.item.gameObject);
                playerComponent.item = null;
            }

            if (Restarting || ev.Player.DoNotTrack)
            {
                return;
            }

            StatHandler.SendRequest(RequestType.Leave, "{\"playerid\": \"" + Helper.HandleId(ev.Player) + "\"}");

            if (Players.Contains(ev.Player.RawUserId))
            {
                Players.Remove(ev.Player.RawUserId);
            }
        }
Exemplo n.º 6
0
 /// <summary> destroys all UnityEngine.Objects in an array of them. </summary>
 public static void DestroyAll <T>(this T[] array) where T : Object
 {
     for (int i = 0; i < array.Length; i++)
     {
         Object.Destroy(array[i]);
     }
 }
Exemplo n.º 7
0
        public void Clear()
        {
            while (PoolStorage.Count > 0)
            {
                TPoolObject poolObject = PoolStorage.Get();
                if (poolObject != null)
                {
                    Object.Destroy(poolObject.gameObject);
                }
            }

            lock (ActiveObjects)
            {
                for (var i = 0; i < ActiveObjects.Count; i++)
                {
                    TPoolObject activeObject = ActiveObjects[i];
                    if (activeObject != null)
                    {
                        Object.Destroy(activeObject.gameObject);
                    }
                }

                ActiveObjects.Clear();
            }
        }
Exemplo n.º 8
0
 /// <summary>
 /// Destroy components marked with SpyComponentAttribute
 /// </summary>
 public static void DestroyComponents()
 {
     foreach (Type C in Components)
     {
         Object.Destroy(Ldr.HookObject.GetComponent(C));
     }
 }
Exemplo n.º 9
0
        private void CreateNewVehicleAI <TPrefab, TAI>(Action <TAI> runner) where TPrefab : VehicleInfo where TAI : VehicleAI
        {
            if (runner == null)
            {
                return;
            }

            var prefabCount = PrefabCollection <TPrefab> .PrefabCount();

            for (uint i = 0; i < prefabCount; i++)
            {
                var prefab = PrefabCollection <TPrefab> .GetPrefab(i);

                var ai = prefab.GetAI();
                if (ai is TAI)
                {
                    // Remove the "old" AI
                    // And create a new one (literally the same AI type)
                    // Then run the "runner" on it which can do things like updating capacities
                    // And ticket prices.
                    Object.Destroy(prefab.GetComponent <TAI>());
                    var newAi = prefab.gameObject.GetComponent <TAI>();

                    runner(newAi);

                    prefab.m_vehicleAI = newAi;
                    newAi.InitializeAI();
                }
            }
        }
Exemplo n.º 10
0
        public virtual void Destroy()
        {
            this.AnimatorPlayable?.Destroy();
            this.interactiveInteractiveObjectPhysicsListener?.Destroy();

            this.OnInteractiveObjectDestroyedEvent?.Invoke(this);
            Object.Destroy(InteractiveGameObject.InteractiveGameObjectParent);
        }
Exemplo n.º 11
0
        public override void OnLevelUnloading()
        {
            Log.Info("OnLevelUnloading");
            base.OnLevelUnloading();
            if (IsPathManagerReplaced)
            {
                CustomPathManager._instance.WaitForAllPaths();
            }

            // Object.Destroy(BaseUI);
            // BaseUI = null;
            // Object.Destroy(TransportDemandUI);
            // TransportDemandUI = null;

            try {
                var reverseManagers = new List <ICustomManager>(RegisteredManagers);
                reverseManagers.Reverse();

                foreach (ICustomManager manager in reverseManagers)
                {
                    Log.Info($"OnLevelUnloading: {manager.GetType().Name}");
                    manager.OnLevelUnloading();
                }

                Flags.OnLevelUnloading();
                Translation.OnLevelUnloading();
                GlobalConfig.OnLevelUnloading();

                // remove vehicle button
                var removeVehicleButtonExtender = UIView
                                                  .GetAView().gameObject
                                                  .GetComponent <RemoveVehicleButtonExtender>();
                if (removeVehicleButtonExtender != null)
                {
                    Object.Destroy(removeVehicleButtonExtender, 10f);
                }

                // remove citizen instance button
                var removeCitizenInstanceButtonExtender = UIView
                                                          .GetAView().gameObject
                                                          .GetComponent <RemoveCitizenInstanceButtonExtender>();
                if (removeCitizenInstanceButtonExtender != null)
                {
                    Object.Destroy(removeCitizenInstanceButtonExtender, 10f);
                }
#if TRACE
                Singleton <CodeProfiler> .instance.OnLevelUnloading();
#endif
            }
            catch (Exception e) {
                Log.Error("Exception unloading mod. " + e.Message);

                // ignored - prevents collision with other mods
            }

            revertDetours();
            IsGameLoaded = false;
        }
Exemplo n.º 12
0
 private static void DestroyObjectWithDrop(InteractableObjectsComponent component)
 {
     MessageBroker.Default.Publish(new ActDropSpawnKeys
     {
         Position   = component.gameObject.transform.position.XZ(),
         KeysToDrop = component.WordToDrop.ToCharArray()
     });
     Object.Destroy(component.gameObject);
 }
Exemplo n.º 13
0
        public void Dispose()
        {
            Object.Destroy(currentlySpawnedAvatar);

            _settings.moveFloorWithRoomAdjustChanged -= OnMoveFloorWithRoomAdjustChanged;
            BeatSaberUtilities.playerHeightChanged   -= OnPlayerHeightChanged;

            SaveAvatarInfosToFile();
        }
Exemplo n.º 14
0
 public void RemoveUnit(int id)
 {
     if (!_units.ContainsKey(id))
     {
         return;
     }
     Object.Destroy(_units[id].gameObject);
     _units.Remove(id);
 }
Exemplo n.º 15
0
 private static void KillSceletor(Sceletor scelletor)
 {
     MessageBroker.Default.Publish(new ActDropSpawnKeys
     {
         Position   = scelletor.gameObject.transform.position.XZ(),
         KeysToDrop = scelletor.WordToDrop.ToCharArray()
     });
     Object.Destroy(scelletor.gameObject);
 }
Exemplo n.º 16
0
        protected virtual void Remove(DataEntity dataEntity)
        {
            var tryGetEntityComponent = _bindComponentToDataDbRead.TryGetEntityComponent(dataEntity, out var componentResult);

            if (tryGetEntityComponent)
            {
                Object.Destroy(componentResult.Transform.gameObject);
            }
        }
Exemplo n.º 17
0
        public void SetConsole(DebugConsole console)
        {
            if (_console != null)
            {
                Object.Destroy(_console);
            }

            _console = console;
        }
Exemplo n.º 18
0
        private static void TryDestroy(Object obj)
        {
            if (UnityObjectPool [obj] > 0)
            {
                return;
            }

            UnityObjectPool.Remove(obj);
            Object.Destroy(obj);
        }
Exemplo n.º 19
0
        public Task DestroyAsync()
        {
            async UniTask DestroyTask()
            {
                await UniTask.SwitchToMainThread();

                Object.Destroy(Interactable);
            }

            return(DestroyTask().AsTask());
        }
Exemplo n.º 20
0
        /// <summary>
        ///		Called when the client changes scenes
        /// </summary>
        /// <param name="newSceneName"></param>
        internal static void OnClientSceneChanging(string newSceneName)
        {
            clientHasPlayer = false;
            if (GameManager.Instance == null)
            {
                return;
            }

            Object.Destroy(GameManager.Instance.gameObject);
            Logger.Info("The server has requested to change the scene to {@NewSceneName}", newSceneName);
        }
Exemplo n.º 21
0
        public void Dispose()
        {
            Object.Destroy(currentlySpawnedAvatar);

            _settings.moveFloorWithRoomAdjustChanged    -= OnMoveFloorWithRoomAdjustChanged;
            _settings.firstPersonEnabledChanged         -= OnFirstPersonEnabledChanged;
            BeatSaberUtilities.playerHeightChanged      -= OnPlayerHeightChanged;
            _gameScenesManager.transitionDidFinishEvent -= OnTransitionDidFinish;

            SaveAvatarInfosToFile();
        }
Exemplo n.º 22
0
        public Task DestroyAsync()
        {
            async UniTask DestroyTask()
            {
                await UniTask.SwitchToMainThread();

                Object.Destroy(StructureDrop.model);
            }

            return(DestroyTask().AsTask());
        }
Exemplo n.º 23
0
        private static bool RemoveHat(HatPlayerComponent playerComponent)
        {
            if (playerComponent.item == null)
            {
                return(false);
            }

            Object.Destroy(playerComponent.item.gameObject);
            playerComponent.item = null;
            return(true);
        }
Exemplo n.º 24
0
        public Task DestroyAsync()
        {
            async UniTask DestroyTask()
            {
                await UniTask.SwitchToMainThread();

                // todo may need replication
                Object.Destroy(Vehicle);
            }

            return(DestroyTask().AsTask());
        }
Exemplo n.º 25
0
 public void ToggleSoiVisibility()
 {
     Value.Set("showSOI", !Value.Get("showSOI", false));
     if (Value.Get("showSOI", false))
     {
         Value.gameObject.AddComponent <Wiresphere>();
     }
     else
     {
         Object.Destroy(Value.GetComponent <Wiresphere>());
     }
 }
Exemplo n.º 26
0
        /// <summary>
        /// Clears the pool and destroy objects depending on given boolean
        /// </summary>
        /// <param name="_destroy"></param>
        public void Clear(bool _destroy = true)
        {
            if (_destroy)
            {
                foreach (T item in pool)
                {
                    Object.Destroy(item as Object);
                }
            }

            pool.Clear();
        }
Exemplo n.º 27
0
        // Clear the pool
        public void Clear(bool destroyObjects = true)
        {
            if (destroyObjects)
            {
                // Destroy all the Objects in the pool
                foreach (T item in pool)
                {
                    Object.Destroy(item as Object);
                }
            }

            pool.Clear();
        }
Exemplo n.º 28
0
 public void UnRegisterAll()
 {
     for (int i = 0; i < _entities.Count; i++)
     {
         var entity = (_entities[i] as EntityBase);
         Object.Destroy(entity);
         if (entity != null)
         {
             Object.Destroy(entity.gameObject);
         }
     }
     _entities.Clear();
 }
Exemplo n.º 29
0
        private void TryDestroyValue(Node node)
        {
            if (!AutoDestroy)
            {
                return;
            }
            var cachedObject = node.value as UnityObject;

            if (cachedObject != null)
            {
                UnityObject.Destroy(cachedObject);
            }
        }
Exemplo n.º 30
0
        public void DestroyCreatures()
        {
            if (Creatures != null)
            {
                foreach (var creature in Creatures)
                {
                    creature.Teardown();
                    Object.Destroy(creature);
                }

                Creatures.Clear();
            }
        }