/// <summary>
        /// INTERNAL ARM SPAWNING METHOD, DON'T OVERRIDE! Use ModifyGameObject() instead!
        /// Initializes the visual appearance of the arm in the open world or in the inventory.
        /// </summary>
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> request = CraftData.GetPrefabForTechTypeAsync(PrefabForClone);

            yield return(request);

            GameObject result = request.GetResult();

            if (result == null)
            {
                BZLogger.Warn("API message: Cannot instantiate prefab from TechType!");
                yield break;
            }

            PrefabClone = Object.Instantiate(result);

            PrefabClone.name = TechTypeName;

            if (ArmTemplate == ArmTemplate.ClawArm)
            {
                OverrideClawArm();
            }

            PrefabClone.transform.localScale = new Vector3(0.8f, 0.8f, 0.8f);

            PostModify();

            gameObject.Set(PrefabClone);

            yield break;
        }
Esempio n. 2
0
        public IEnumerator GetModelCloneFromPrefabAsync(TechType techType, string model, Transform newParent, bool setActive, string newName, IOut <GameObject> result)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(techType);

            yield return(task);

            GameObject clone = null;

            try
            {
                clone = UnityEngine.Object.Instantiate(FindDeepChild(task.GetResult(), model));
            }
            catch
            {
                result.Set(null);
                yield break;
            }

            clone.SetActive(setActive);
            clone.transform.SetParent(newParent, false);
            clone.name = newName;
            Utils.ZeroTransform(clone.transform);
            result.Set(clone);
            yield break;
        }
Esempio n. 3
0
        private static IEnumerator AddToVehicle(TechType techType, ItemsContainer itemsContainer)
        {
            CoroutineTask <GameObject> coroutineTask = CraftData.GetPrefabForTechTypeAsync(techType, false);

            yield return(coroutineTask);

            GameObject prefab = coroutineTask.GetResult();

            if (prefab is null)
            {
                prefab = Utils.CreateGenericLoot(techType);
            }

            GameObject gameObject = GameObject.Instantiate(prefab, null);
            Pickupable pickupable = gameObject.EnsureComponent <Pickupable>();

#if SUBNAUTICA_EXP
            TaskResult <Pickupable> result1 = new TaskResult <Pickupable>();
            yield return(pickupable.InitializeAsync(result1));

            pickupable = result1.Get();
#else
            pickupable.Initialize();
#endif
            var item = new InventoryItem(pickupable);
            itemsContainer.UnsafeAdd(item);
            string name = Language.main.GetOrFallback(techType.AsString(), techType.AsString());
            ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));
            uGUI_IconNotifier.main.Play(techType, uGUI_IconNotifier.AnimationType.From, null);
            pickupable.PlayPickupSound();

            yield break;
        }
Esempio n. 4
0
        private static IEnumerator AddItemToAlterraGen(TechType parkCreatureTechType, IFCSStorage container)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(parkCreatureTechType, false);

            yield return(task);

            GameObject prefab = task.GetResult();

            prefab.SetActive(false);

            while (!container.CanBeStored(1, parkCreatureTechType))
            {
                yield return(new WaitForSecondsRealtime(1));
            }

            GameObject gameObject = GameObject.Instantiate(prefab);

            Pickupable pickupable = gameObject.EnsureComponent <Pickupable>();

#if SUBNAUTICA_EXP
            TaskResult <Pickupable> taskResult = new TaskResult <Pickupable>();
            yield return(pickupable.PickupAsync(taskResult, false));

            pickupable = taskResult.Get();
#else
            pickupable.Pickup(false);
#endif
            container.AddItemToContainer(new InventoryItem(pickupable));

            yield break;
        }
        private static IEnumerator SpawnCreature(WaterPark waterPark, WaterParkCreature parkCreature, ItemsContainer container)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(parkCreature.pickupable.GetTechType(), false);

            yield return(task);

            GameObject prefab = task.GetResult();

            prefab.SetActive(false);
            GameObject gameObject = GameObject.Instantiate(prefab);

            Pickupable pickupable = gameObject.EnsureComponent <Pickupable>();

#if SUBNAUTICA_EXP
            TaskResult <Pickupable> taskResult = new TaskResult <Pickupable>();
            yield return(pickupable.PickupAsync(taskResult, false));

            pickupable = taskResult.Get();
#else
            pickupable.Pickup(false);
#endif
            container.AddItem(pickupable);

            yield break;
        }
        private IEnumerator ChooseRandomResourceAsync(IOut <GameObject> result)
        {
            for (int i = 0; i < drillable.resources.Length; i++)
            {
                Drillable.ResourceType resourceType = drillable.resources[i];

                if (resourceType.chance >= 1f)
                {
                    CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(resourceType.techType, true);
                    yield return(task);

                    result.Set(task.GetResult());
                    break;
                }
                if (Player.main.gameObject.GetComponent <PlayerEntropy>().CheckChance(resourceType.techType, resourceType.chance))
                {
                    CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(resourceType.techType, true);
                    yield return(task);

                    result.Set(task.GetResult());
                    break;
                }
            }
            yield break;
        }
Esempio n. 7
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            Stillsuit s;

            if (prefab == null)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.ColdSuit, verbose: true);
                yield return(task);

                prefab = task.GetResult();
                //prefab.SetActive(false); // Keep the prefab inactive until we're done editing it.

                // Editing prefab
                if (prefab.TryGetComponent <Stillsuit>(out s))
                {
                    GameObject.DestroyImmediate(s);
                }
                prefab.EnsureComponent <SurvivalsuitBehaviour>();

                ModPrefabCache.AddPrefab(prefab, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)]
                                                         // but it can still be instantiated. [unlike with SetActive(false)]
            }

            // Despite the component being removed from the prefab above, testing shows that the Survival Suits still add the water packs when they should.
            // So we're going to force-remove it here, to be safe.
            GameObject go = GameObject.Instantiate(prefab);

            if (go.TryGetComponent <Stillsuit>(out s))
            {
                GameObject.DestroyImmediate(s);
            }
            gameObject.Set(go);
        }
Esempio n. 8
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            GameObject go;

            if (processedPrefab != null)
            {
                go = GameObject.Instantiate(processedPrefab);
                go.SetActive(true);
                gameObject.Set(go);
                yield break;
            }

            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TypeToClone);

            yield return(task);

            GameObject prefab = task.GetResult();

            if (prefab != null)
            {
                processedPrefab = GameObject.Instantiate(prefab);
                processedPrefab.SetActive(false);
            }

            go = GameObject.Instantiate(processedPrefab);
            go.SetActive(true);
            gameObject.Set(go);
            yield break;
        }
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.ReinforcedGloves);

            yield return(task);

            gameObject.Set(ModifyAndInstantiateGameObject(task.GetResult()));
        }
Esempio n. 10
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(this.PrefabType);

            yield return(task);

            gameObject.Set(ModifyPrefab(task.GetResult()));
        }
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.ReinforcedDiveSuit);

            yield return(task);

            gameObject.Set(task.GetResult());
        }
Esempio n. 12
0
        public static IEnumerator getPrefabCopyAsync(TechType techType, IOut <GameObject> result, CopyOptions options = CopyOptions.Default)
        {
            $"PrefabUtils: getPrefabCopyAsync(TechType.{techType})".logDbg();
            TaskResult <GameObject> prefabResult = new();

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

            result.Set(_instantiate(prefabResult.Get(), options));
        }
Esempio n. 13
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task;
            Oxygen oxy;

            if (prefab == null)
            {
                Log.LogDebug($"HighCapacityBooster.GetGameObjectAsync: getting SuitBoosterTank prefab");
                task = CraftData.GetPrefabForTechTypeAsync(TechType.SuitBoosterTank, verbose: true);
                yield return(task);

                prefab = GameObject.Instantiate(task.GetResult());
                ModPrefabCache.AddPrefab(prefab, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)] but it can still be instantiated.
                //HighCapacityBooster.prefab = prefab;
            }

            if (highCapTank == null)
            {
                Log.LogDebug($"HighCapacityBooster.GetGameObjectAsync: getting HighCapacityTank prefab");
                task = CraftData.GetPrefabForTechTypeAsync(TechType.HighCapacityTank, verbose: true);
                yield return(task);

                highCapTank = GameObject.Instantiate(task.GetResult()); // The "capacity expansion" code in Customise Your Oxygen can't run unless the thing is instantiated. The prefabs can't be altered.
                                                                        // So unless we instantiate, we only get default capacities.
                ModPrefabCache.AddPrefab(highCapTank, false);           // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)] but it can still be instantiated.
            }

            GameObject go            = GameObject.Instantiate(prefab);
            Oxygen     highCapOxygen = highCapTank.GetComponent <Oxygen>();

            //Oxygen highCapOxygen = task.GetResult().GetComponent<Oxygen>();
            if (highCapOxygen != null)
            {
                oxy = go.EnsureComponent <Oxygen>();
                if (oxy != null)
                {
                    float oxygenCapacity = highCapOxygen.oxygenCapacity;
                    Log.LogDebug($"Found Oxygen component with capacity of {oxygenCapacity} for prefab HighCapacityTank and existing oxygen capacity of {oxy.oxygenCapacity} for prefab HighCapacityBooster.");
                    oxy.oxygenCapacity = oxygenCapacity;
                }
                else
                {
                    Log.LogError($"Could not get Oxygen component of SuitBoosterTank while generating HighCapacityBooster");
                }

                GameObject.Destroy(highCapOxygen);
            }
            else
            {
                Log.LogError($"Could not get Oxygen component of HighCapacityTank while generating HighCapacityBooster");
            }

            float oxyCap = prefab.GetComponent <Oxygen>().oxygenCapacity;

            Log.LogDebug($"GameObject created with oxygenCapacity of {oxyCap}");
            gameObject.Set(go);
        }
			public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
			{
				CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SmallLocker);
				yield return task;
				var smallLockerPrefab = task.GetResult();
				GameObject prefab = GameObject.Instantiate(smallLockerPrefab);
				var storageAccess = prefab.EnsureComponent<VehicleStorageAccess>();
				storageAccess.textPrefab = GameObject.Instantiate(smallLockerPrefab.GetComponentInChildren<TextMeshProUGUI>());
#endif

				var container = prefab.EnsureComponent<StorageContainer>();
				container.width = Mod.config.LockerWidth;
				container.height = Mod.config.LockerHeight;
				container.container.Resize(Mod.config.LockerWidth, Mod.config.LockerHeight);

				var meshRenderers = prefab.GetComponentsInChildren<MeshRenderer>();
				foreach (var meshRenderer in meshRenderers)
				{
					meshRenderer.material.color = new Color(0, 0, 1);
				}

				var label = prefab.FindChild("Label");
				DestroyImmediate(label);

				var canvas = LockerPrefabShared.CreateCanvas(prefab.transform);
				storageAccess.background = LockerPrefabShared.CreateBackground(canvas.transform);
				storageAccess.icon = LockerPrefabShared.CreateIcon(storageAccess.background.transform, PrimaryColor, 15);
				storageAccess.text = LockerPrefabShared.CreateText(storageAccess.background.transform, storageAccess.textPrefab, PrimaryColor, -40, 10, "");
				storageAccess.seamothIcon = LockerPrefabShared.CreateIcon(storageAccess.background.transform, PrimaryColor, 80);
				storageAccess.seamothCountText = LockerPrefabShared.CreateText(storageAccess.background.transform, storageAccess.textPrefab, PrimaryColor, 55, 10, "none");
				storageAccess.exosuitIcon = LockerPrefabShared.CreateIcon(storageAccess.background.transform, PrimaryColor, 80);
				storageAccess.exosuitCountText = LockerPrefabShared.CreateText(storageAccess.background.transform, storageAccess.textPrefab, PrimaryColor, 55, 10, "none");

				storageAccess.seamothIcon.rectTransform.anchoredPosition += new Vector2(-23, 0);
				storageAccess.seamothCountText.rectTransform.anchoredPosition += new Vector2(-23, 0);
				storageAccess.exosuitIcon.rectTransform.anchoredPosition += new Vector2(23, 0);
				storageAccess.exosuitCountText.rectTransform.anchoredPosition += new Vector2(23, 0);

				if (Mod.config.UseAutosortMod)
				{
					storageAccess.autosortCheckbox = CheckboxButton.CreateCheckbox(storageAccess.background.transform, PrimaryColor, storageAccess.textPrefab, "Autosort");
					storageAccess.autosortCheckbox.transform.localPosition = new Vector3(0, -104 + 19);
				}

				storageAccess.enableCheckbox = CheckboxButton.CreateCheckbox(storageAccess.background.transform, PrimaryColor, storageAccess.textPrefab, "Enabled");
				storageAccess.enableCheckbox.transform.localPosition = new Vector3(0, -104);

				storageAccess.background.gameObject.SetActive(false);

#if SN1
				return prefab;
#elif BZ
				gameObject.Set(prefab);
#endif
			}
Esempio n. 15
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(PrefabTemplate);

            yield return(task);

            GameObject prefab = task.GetResult();
            GameObject obj    = Object.Instantiate(prefab);

            gameObject.Set(obj);
        }
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (processedPrefab == null)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaglideFragment);
                yield return(task);

                GameObject prefab = GameObject.Instantiate(task.GetResult());

                MeshRenderer[]        meshRenderers        = prefab.GetAllComponentsInChildren <MeshRenderer>();
                SkinnedMeshRenderer[] skinnedMeshRenderers = prefab.GetAllComponentsInChildren <SkinnedMeshRenderer>();
                Color powerGlideColour = new Color(PowerglideEquipable.PowerglideColourR, PowerglideEquipable.PowerglideColourG, PowerglideEquipable.PowerglideColourB);

                foreach (MeshRenderer mr in meshRenderers)
                {
                    // MeshRenderers have the third-person mesh, apparently?
                    if (mr.name.Contains("SeaGlide_01_damaged"))
                    {
                        mr.material.color = powerGlideColour;
                    }
                }

                foreach (SkinnedMeshRenderer smr in skinnedMeshRenderers)
                {
                    if (smr.name.Contains("SeaGlide_geo"))
                    {
                        smr.material.color = powerGlideColour;
                    }
                }

                PrefabIdentifier prefabIdentifier = prefab.GetComponent <PrefabIdentifier>();
                prefabIdentifier.ClassId = this.ClassID;
                prefab.GetComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.VeryFar;
                prefab.EnsureComponent <TechTag>().type            = this.TechType;

                Pickupable pickupable = prefab.GetComponent <Pickupable>();
                pickupable.isPickupable = false;

                ResourceTracker resourceTracker = prefab.EnsureComponent <ResourceTracker>();
                resourceTracker.prefabIdentifier = prefabIdentifier;
                typeof(ResourceTracker).GetField("techType", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(resourceTracker, this.TechType);
                //resourceTracker.techType = this.TechType;
                resourceTracker.overrideTechType = TechType.Fragment;
                resourceTracker.rb         = prefab.GetComponent <Rigidbody>();
                resourceTracker.pickupable = pickupable;

                prefab.SetActive(true);
                processedPrefab = prefab;
                ModPrefabCache.AddPrefab(processedPrefab, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)]
                // but it can still be instantiated. [unlike with SetActive(false)]
            }

            gameObject.Set(processedPrefab);
        }
Esempio n. 17
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(Original, false);

            yield return(task);

            GameObject prefab = task.GetResult();

            gameObject.Set(GameObject.Instantiate(prefab));
            yield break;
        }
        private static IEnumerator InitializeBuilder(TechType techType)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(techType);

            yield return(task);

            GameObject prefab = task.GetResult();

            Builder.Begin(prefab);
            yield break;
        }
Esempio n. 19
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SeamothSonarModule, false);

            yield return(task);

            GameObject gameObject1 = GameObject.Instantiate(task.GetResult());

            gameObject.Set(gameObject1);

            yield break;
        }
Esempio n. 20
0
            public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SmallLocker);

                yield return(task);

                GameObject originalPrefab = task.GetResult();
                GameObject prefab         = GameObject.Instantiate(originalPrefab);

                StorageContainer container = prefab.GetComponent <StorageContainer>();

                container.width  = Mod.config.AutosorterWidth;
                container.height = Mod.config.AutosorterHeight;
                container.Resize(Mod.config.AutosorterWidth, Mod.config.AutosorterHeight);
                var meshRenderers = prefab.GetComponentsInChildren <MeshRenderer>();

                foreach (var meshRenderer in meshRenderers)
                {
                    meshRenderer.material.color = new Color(1, 0, 0);
                }

#if SUBNAUTICA
                var prefabText = prefab.GetComponentInChildren <Text>();
#elif BELOWZERO
                var prefabText = prefab.GetComponentInChildren <TextMeshProUGUI>();
#endif
                var label = prefab.FindChild("Label");
                DestroyImmediate(label);

                var autoSorter = prefab.AddComponent <AutosortLocker>();

                var canvas = LockerPrefabShared.CreateCanvas(prefab.transform);
                autoSorter.background = LockerPrefabShared.CreateBackground(canvas.transform, autoSorter.name);
                autoSorter.icon       = LockerPrefabShared.CreateIcon(autoSorter.background.transform, MainColor, 40);
                // The first number is the vertical position, the second number is the font
                autoSorter.text = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, 0, 14, "Autosorter", "Autosorter");
                autoSorter.text.rectTransform.anchoredPosition += new Vector2(20, 0);

                autoSorter.sortingText = LockerPrefabShared.CreateText(autoSorter.background.transform, prefabText, MainColor, -120, 18, "Sorting...", "Autosorter");
#if SUBNAUTICA
                autoSorter.sortingText.alignment = TextAnchor.UpperCenter;
#elif BELOWZERO
                autoSorter.sortingText.alignment = TextAlignmentOptions.Top;
#endif

                autoSorter.background.gameObject.SetActive(false);
                autoSorter.icon.gameObject.SetActive(false);
                autoSorter.text.gameObject.SetActive(false);
                autoSorter.sortingText.gameObject.SetActive(false);

                gameObject.Set(prefab);
                yield break;
            }
Esempio n. 21
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (prefab == null)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.HoverbikeJumpModule);
                yield return(task);

                prefab = GameObject.Instantiate <GameObject>(task.GetResult());
            }

            gameObject.Set(GameObject.Instantiate(prefab));
        }
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (prefab == null)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaglideFragment);
                yield return(task);

                prefab = PreparePrefab(task.GetResult());
            }

            gameObject.Set(prefab);
        }
        public override IEnumerator GetGameObjectAsync(IOut<GameObject> gameObject)
        {
            if (prefab == null)
            {
                CoroutineTask<GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.HoverbikeJumpModule);
                yield return task;
                prefab = GameObject.Instantiate<GameObject>(task.GetResult());
                ModPrefabCache.AddPrefab(prefab, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)]
                                                         // but it can still be instantiated. [unlike with SetActive(false)]
            }

            gameObject.Set(GameObject.Instantiate(prefab));
        }
Esempio n. 24
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (prefab == null)
            {
                var task = CraftData.GetPrefabForTechTypeAsync(TechType.MapRoomHUDChip);
                yield return(task);

                prefab = GameObject.Instantiate(task.GetResult());
                ModPrefabCache.AddPrefab(prefab, false);                 // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)] but it can still be instantiated.
            }

            gameObject.Set(prefab);
        }
        //public override string AssetsFolder => Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),"Assets");
        //public override string IconFileName => "MetalHandsMK1.png";
        //public override bool HasSprite => true;

        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.ColdSuitGloves);

            yield return(task);

            GameObject prefab = task.GetResult();
            GameObject obj    = GameObject.Instantiate(prefab);

            prefab.SetActive(false);

            gameObject.Set(obj);
        }
Esempio n. 26
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (prefab == null)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaTruckUpgradeEnergyEfficiency);
                yield return(task);

                prefab = GameObject.Instantiate(task.GetResult());
                Battery cell = prefab.EnsureComponent <Battery>();
                cell.name      = "SolarBackupBattery";
                cell._capacity = cellCapacity;
            }
        }
Esempio n. 27
0
        private static IEnumerator SpawnCreature(WaterPark waterPark, TechType parkCreatureTechType, ItemsContainer container)
        {
            var task = CraftData.GetPrefabForTechTypeAsync(parkCreatureTechType, false);

            yield return(task);

            var prefab = task.GetResult();

            if (prefab == null)
            {
                yield break;
            }

            prefab.SetActive(false);
            var gameObject = Object.Instantiate(prefab);

            if (container is not null)
            {
                var pickupable = gameObject.EnsureComponent <Pickupable>();
#if SUBNAUTICA_EXP
                TaskResult <Pickupable> taskResult = new TaskResult <Pickupable>();
                yield return(pickupable.PickupAsync(taskResult, false));

                pickupable = taskResult.Get();
#else
                pickupable.Pickup(false);
#endif
                gameObject.SetActive(false);
                container.AddItem(pickupable);
                yield break;
            }

            var spawnPoint = waterPark.transform.position + (Random.insideUnitSphere * 50);
            var @base      =
#if SN1
                waterPark.GetComponentInParent <Base>();
#elif BZ
                waterPark.hostBase;
#endif

            while (Vector3.Distance(@base.GetClosestPoint(spawnPoint), spawnPoint) < 25 || spawnPoint.y >= 0)
            {
                yield return(null);

                spawnPoint = @base.GetClosestPoint(spawnPoint) + (Random.insideUnitSphere * 50);
            }

            gameObject.transform.SetPositionAndRotation(spawnPoint, Quaternion.identity);
            gameObject.SetActive(true);
        }
        private static IEnumerator InitializeBuilder(TechType techType)
        {
            var task = CraftData.GetPrefabForTechTypeAsync(techType);

            yield return(task);

            var prefab = task.GetResult();

#if SN1
            Builder.Begin(prefab);
#elif BZ
            Builder.Begin(techType, prefab);
#endif
        }
Esempio n. 29
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            var task = CraftData.GetPrefabForTechTypeAsync(TechType.DioramaHullPlate);

            yield return(task);

            var _GameObject = Object.Instantiate(task.GetResult());

            var meshRenderer = _GameObject.FindChild("Icon").GetComponent <MeshRenderer>();

            meshRenderer.material.mainTexture = hullPlateTexture;
            _GameObject.name = ClassID;

            gameObject.Set(_GameObject);
        }
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (prefab == null)
            {
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SeaTruckUpgradeEnergyEfficiency);
                yield return(task);

                prefab = GameObject.Instantiate <GameObject>(task.GetResult());
                // The code is handled by the SeatruckUpdater component, rather than anything here.
                ModPrefabCache.AddPrefab(prefab, false); // This doesn't actually do any caching, but it does disable the prefab without "disabling" it - the prefab doesn't show up in the world [as with SetActive(false)]
                                                         // but it can still be instantiated. [unlike with SetActive(false)]
            }

            gameObject.Set(GameObject.Instantiate(prefab));
        }