Ejemplo n.º 1
0
        public static IEnumerator AddLifepodInventory(StorageContainer container, List <TechType> newTechTypes)
        {
            if (!Main.config.useDropPodInventory)
            {
                yield break;
            }

            if (AlreadyInitialised())
            {
                yield break;
            }

            foreach (TechType tt in newTechTypes)
            {
                Log.LogDebug($"Adding item {tt.AsString()} to drop pod locker");
#if SUBNAUTICA_STABLE
                GameObject    go             = CraftData.InstantiateFromPrefab(tt);
                InventoryItem inventoryItem2 = new InventoryItem(go.GetComponent <Pickupable>());
#elif BELOWZERO
                TaskResult <GameObject> result = new TaskResult <GameObject>();
                yield return(CraftData.InstantiateFromPrefabAsync(tt, result, false));

                InventoryItem inventoryItem2 = new InventoryItem(result.Get().GetComponent <Pickupable>());
#endif

                inventoryItem2.item.Initialize();
                container.container.UnsafeAdd(inventoryItem2);
            }
            yield break;
        }
Ejemplo n.º 2
0
        protected IEnumerator AddInventoryAsync(TechType techType, IOut <GameObject> result = null)
        {
#if SUBNAUTICA_STABLE
            GameObject go = CraftData.InstantiateFromPrefab(techType, false);
#elif BELOWZERO
            TaskResult <GameObject> instResult = new TaskResult <GameObject>();
            yield return(CraftData.InstantiateFromPrefabAsync(techType, instResult, false));

            GameObject go = instResult.Get();
#endif
            Pickupable component = go?.GetComponent <Pickupable>();
            if (component != null)
            {
                Inventory.main.ForcePickup(component);
            }
            else
            {
                Log.LogError($"DiverPerimeterDefenceBehaviour.AddInventoryAsync(): Failed to instantiate inventory item for TechType {techType.AsString()}");
            }

            if (result != null)
            {
                result.Set(go);
            }
            yield break;
        }
Ejemplo n.º 3
0
        private static IEnumerator RespawnCoroutine(Respawn __instance)
        {
            float timePassed = (float)DayNightCycle.main.timePassed;
            float waitTime   = (float)System.Math.Round(__instance.spawnTime - timePassed);

            yield return(new WaitForSecondsRealtime(waitTime));



            ////
            // Game's original method
            ////
            int num = UWE.Utils.OverlapSphereIntoSharedBuffer(__instance.transform.position, 1.5f, -1, QueryTriggerInteraction.UseGlobal);

            for (int i = 0; i < num; i++)
            {
                if (UWE.Utils.sharedColliderBuffer[i].GetComponentInParent <Base>() != null)
                {
                    UnityEngine.Object.Destroy(__instance.gameObject);
                    yield break;
                }
            }
            TaskResult <GameObject> result     = new TaskResult <GameObject>();
            IEnumerator             enumerator = CraftData.InstantiateFromPrefabAsync(__instance.techType, result, false);

            yield return(enumerator);

            GameObject gameObject = result.Get();

            gameObject.transform.SetPositionAndRotation(__instance.transform.position, __instance.transform.rotation);

            for (int j = 0; j < __instance.addComponents.Count; j++)
            {
                Type type = Type.GetType(__instance.addComponents[j]);
                if (type != null)
                {
                    gameObject.AddComponent(type);
                }
            }
            gameObject.SetActive(true);
            if (__instance.transform.parent == null || __instance.transform.parent.GetComponentInParent <LargeWorldEntity>() == null)
            {
                if (LargeWorldStreamer.main)
                {
                    LargeWorldStreamer.main.cellManager.RegisterEntity(gameObject);
                }
            }
            else
            {
                if (LargeWorldStreamer.main)
                {
                    LargeWorldStreamer.main.cellManager.UnregisterEntity(gameObject);
                }
                gameObject.transform.parent = __instance.transform.parent;
            }

            UnityEngine.Object.Destroy(__instance.gameObject);
            result = null;
        }
Ejemplo n.º 4
0
        protected IEnumerator AddInventoryAsync(TechType techType, IOut <GameObject> result)
        {
            TaskResult <GameObject> instResult = new TaskResult <GameObject>();

            yield return(CraftData.InstantiateFromPrefabAsync(techType, instResult, false));

            GameObject go        = instResult.Get();
            Pickupable component = (go != null ? go.GetComponent <Pickupable>() : null);

            if (component != null)
            {
                Inventory.main.ForcePickup(component);
            }
            else
            {
                Log.LogError($"DiverPerimeterDefenceBehaviour.AddInventoryAsync(): Failed to instantiate inventory item for TechType {techType.AsString()}");
            }

            result.Set(go);
            yield break;
        }
        public static IEnumerator CreateMainMenuTestObjectAsync(TechType techType)
        {
            TaskResult <GameObject> prefabResult = new TaskResult <GameObject>();

            yield return(CraftData.InstantiateFromPrefabAsync(techType, prefabResult, false));

            GameObject clone = prefabResult.Get();

            if (__TESTOBJECT__ == null)
            {
                __TESTOBJECT__ = new GameObject("__TESTOBJECT__");

                __TESTOBJECT__.SetActive(false);

                __TESTOBJECT__.AddComponent <PrefabTest>();
            }

            clone.transform.SetParent(__TESTOBJECT__.transform);

            clone.GetComponent <Rigidbody>().isKinematic = true;

            clone.transform.position = new Vector3(-0.40f, 2.20f, 2.80f);

            clone.transform.rotation = Quaternion.Euler(0, 90, 0);

            try
            {
                SkyApplier skyApplier = clone.GetComponent <SkyApplier>();

                UnityEngine.Object.Destroy(skyApplier);
            }
            catch (Exception ex)
            {
                Debug.LogException(ex);
            }

            foreach (Component component in clone.GetComponents <MonoBehaviour>())
            {
                Type componentType = component.GetType();

                if (componentType == typeof(Rigidbody))
                {
                    continue;
                }
                if (componentType == typeof(WorldForces))
                {
                    continue;
                }
                if (componentType == typeof(PrefabTest))
                {
                    continue;
                }

                UnityEngine.Object.DestroyImmediate(component);
            }

            if (clone.TryGetComponent(out SwimBehaviour swimBehaviour))
            {
                UnityEngine.Object.DestroyImmediate(swimBehaviour);
            }

            if (clone.TryGetComponent(out SplineFollowing splineFollowing))
            {
                UnityEngine.Object.DestroyImmediate(splineFollowing);
            }

            if (clone.TryGetComponent(out Locomotion locomotion))
            {
                UnityEngine.Object.DestroyImmediate(locomotion);
            }

            __TESTOBJECT__.SetActive(true);
        }