Exemple #1
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            IPrefabRequest request = PrefabDatabase.GetPrefabForFilenameAsync("WorldEntities/Alterra/DataBoxes/BeaconDataBox.prefab");

            yield return(request);

            request.TryGetPrefab(out GameObject prefab);

            GameObject obj = GameObject.Instantiate(prefab);

            obj.name = ClassID;
            obj.SetActive(false);

            obj.GetComponent <PrefabIdentifier>().classId = this.ClassID;

            BlueprintHandTarget blueprintHandTarget = obj.GetComponent <BlueprintHandTarget>();

            blueprintHandTarget.alreadyUnlockedTooltip = this.alreadyUnlockedTooltip;
            blueprintHandTarget.primaryTooltip         = this.primaryTooltip;
            blueprintHandTarget.secondaryTooltip       = this.secondaryTooltip;
            blueprintHandTarget.unlockTechType         = this.unlockTechType;

            obj.SetActive(true);

            gameObject.Set(obj);
        }
Exemple #2
0
        private IEnumerator LoadExosuitResourcesAsync()
        {
            IPrefabRequest request = PrefabDatabase.GetPrefabForFilenameAsync("WorldEntities/Tools/Exosuit.prefab");

            yield return(request);

            if (!request.TryGetPrefab(out GameObject prefab))
            {
                BZLogger.Debug("Cannot load Exosuit prefab!");
                yield break;
            }

            BZLogger.Debug("Exosuit prefab loaded!");

            GameObject exosuitResource = UWE.Utils.InstantiateDeactivated(prefab, transform, Vector3.zero, Quaternion.identity);

            exosuitResource.GetComponent <Exosuit>().enabled       = false;
            exosuitResource.GetComponent <Rigidbody>().isKinematic = true;
            exosuitResource.GetComponent <WorldForces>().enabled   = false;
            UWE.Utils.ZeroTransform(exosuitResource.transform);

            GameObject exoStorage = objectHelper.FindDeepChild(exosuitResource.transform, "Exosuit_01_storage");

            objectHelper.GetPrefabClone(ref exoStorage, StorageLeft.transform, true, "model", out GameObject leftStorageModel);
            leftStorageModel.SetActive(false);

            objectHelper.GetPrefabClone(ref leftStorageModel, StorageRight.transform, true, "model", out GameObject rightStorageModel);
            rightStorageModel.SetActive(false);

            BoxCollider colliderLeft = StorageLeft.AddComponent <BoxCollider>();

            colliderLeft.enabled = false;
            colliderLeft.size    = new Vector3(1.0f, 0.4f, 0.8f);

            BoxCollider colliderRight = StorageRight.AddComponent <BoxCollider>();

            colliderRight.enabled = false;
            colliderRight.size    = new Vector3(1.0f, 0.4f, 0.8f);

            ColorizationHelper.AddRendererToSkyApplier(gameObject, leftStorageModel, Skies.Auto);
            ColorizationHelper.AddRendererToColorCustomizer(gameObject, leftStorageModel, false, new int[] { 0 });

            ColorizationHelper.AddRendererToColorCustomizer(gameObject, rightStorageModel, false, new int[] { 0 });
            ColorizationHelper.AddRendererToSkyApplier(gameObject, rightStorageModel, Skies.Auto);

            Destroy(exosuitResource);

            isGraphicsReady = true;

            yield break;
        }
        private IEnumerator FinalSetup()
        {
            IPrefabRequest request = PrefabDatabase.GetPrefabForFilenameAsync("Submarine/Build/SmallLocker.prefab");

            yield return(request);

            request.TryGetPrefab(out GameObject prefab);
            lockerPrefab   = prefab;
            bPrefabsLoaded = true;

            CreatePicker();
            CreateCustomizeScreen();

            yield break;
        }
Exemple #4
0
        private IEnumerator LoadBiodomeRobotArmResourcesAsync()
        {
            IPrefabRequest request = PrefabDatabase.GetPrefabForFilenameAsync("WorldEntities/Alterra/Base/biodome_Robot_Arm.prefab");

            yield return(request);

            if (!request.TryGetPrefab(out robotArmResource))
            {
                BZLogger.Warn("Cannot load [biodome_robot_arm] prefab!");
                yield break;
            }

            BZLogger.Debug("Resource loaded: [biodome_robot_arm]");

            Utils.ZeroTransform(robotArmResource.transform);

            yield break;
        }
Exemple #5
0
        private IEnumerator LoadExosuitResourcesAsync()
        {
            IPrefabRequest request = PrefabDatabase.GetPrefabForFilenameAsync("WorldEntities/Tools/Exosuit.prefab");

            yield return(request);

            if (!request.TryGetPrefab(out GameObject prefab))
            {
                BZLogger.Warn("API message: Cannot load [Exosuit] prefab!");
                yield break;
            }

            exosuitResource = UWE.Utils.InstantiateDeactivated(prefab, GraphicsRoot.transform, Vector3.zero, Quaternion.identity);

            exosuitResource.GetComponent <Exosuit>().enabled       = false;
            exosuitResource.GetComponent <Rigidbody>().isKinematic = true;
            exosuitResource.GetComponent <WorldForces>().enabled   = false;
            UWE.Utils.ZeroTransform(exosuitResource.transform);

            yield break;
        }
Exemple #6
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (GameObjectClone != null)
            {
                gameObject.Set(GameObjectClone);
                yield break;
            }

            GameObject result;

            if (FragmentTemplate != TechType.None)
            {
                CoroutineTask <GameObject> request = CraftData.GetPrefabForTechTypeAsync(FragmentTemplate);
                yield return(request);

                result = request.GetResult();

                if (result == null)
                {
                    BZLogger.Error($"Cannot instantiate prefab from TechType '{FragmentTemplate}'!");
                    yield break;
                }

                GameObjectClone = UWE.Utils.InstantiateDeactivated(result);
            }
            else if (!string.IsNullOrEmpty(PrefabFileName))
            {
                IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabForFilenameAsync(PrefabFilePath);
                yield return(prefabRequest);

                if (prefabRequest.TryGetPrefab(out result))
                {
                    //GameObjectClone = UnityEngine.Object.Instantiate(result);
                    GameObjectClone = UWE.Utils.InstantiateDeactivated(result);
                }
                else
                {
                    BZLogger.Error($"Cannot find prefab in PrefabDatabase at path '{PrefabFilePath}!");
                    yield break;
                }
            }

            GameObjectClone.name = TechTypeName;

            PrefabIdentifier prefabIdentifier = GameObjectClone.GetComponent <PrefabIdentifier>();

            prefabIdentifier.ClassId = TechTypeName;

            TechTag techTag = GameObjectClone.GetComponent <TechTag>();

            techTag.type = TechType;

            ResourceTracker resourceTracker = GameObjectClone.GetComponent <ResourceTracker>();

            resourceTracker.overrideTechType = TechType.Fragment;

            ModifyGameObject();

            AddFragmentTracker(GameObjectClone);

            BZLogger.Debug($"GetGameObjectAsync called for fragment: {TechTypeName}");

            gameObject.Set(GameObjectClone);

            yield break;
        }
Exemple #7
0
        public override IEnumerator GetGameObjectAsync(IOut <GameObject> gameObject)
        {
            if (prefab == null)
            {
                AssetBundleRequest request = QPatch.bundle.LoadAssetAsync <GameObject>("turbineprefab.prefab");
                yield return(request);

                prefab = request.asset as GameObject;
                prefab.SetActive(false); // Keep the prefab inactive until we're done adding components

                //Need a tech tag for most prefabs
                var techTag = prefab.EnsureComponent <TechTag>();
                techTag.type = TechType;

                // Set prefab identifier, not sure what this does
                var prefabId = prefab.EnsureComponent <PrefabIdentifier>();
                prefabId.ClassId = ClassID;

                //A collider for the turbine pole and builder tool
                var collider = prefab.EnsureComponent <BoxCollider>();
                collider.size   = new Vector3(2f, 17f, 2f);
                collider.center = new Vector3(0f, 9f, 0f);

                //Update all shaders
                var renderers = prefab.GetComponentsInChildren <Renderer>();
                var shader    = Shader.Find("MarmosetUBER");

                foreach (var renderer in renderers)
                {
                    foreach (Material mat in renderer.materials)
                    {
                        mat.shader = shader;
                        mat.SetTexture("_Specular", mat.mainTexture);
                        if (mat.name.StartsWith("Mat5"))
                        {
                            mat.EnableKeyword("MARMO_EMISSION");
                            mat.SetVector("_EmissionColor", new Color(1f, 0.3f, 0f) * 1f);
                            mat.SetVector("_Illum_ST", new Vector4(1.0f, 1.0f, 0.0f, 0.0f));
                        }
                    }
                }

                var skyApplier = prefab.AddComponent <SkyApplier>();
                skyApplier.renderers = renderers;
                skyApplier.anchorSky = Skies.Auto;

                // Add constructable - This prefab normally isn't constructed.
                Constructable constructible = prefab.EnsureComponent <Constructable>();
                constructible.allowedInBase           = false;
                constructible.allowedInSub            = false;
                constructible.allowedOutside          = true;
                constructible.allowedOnCeiling        = false;
                constructible.allowedOnGround         = true;
                constructible.allowedOnWall           = false;
                constructible.allowedOnConstructables = true;
                constructible.techType             = this.TechType;
                constructible.rotationEnabled      = true;
                constructible.placeDefaultDistance = 6f;
                constructible.placeMinDistance     = 0.5f;
                constructible.placeMaxDistance     = 15f;
                constructible.surfaceType          = VFXSurfaceTypes.metal;
                constructible.model        = prefab.FindChild("Pole");
                constructible.forceUpright = true;

                prefab.FindChild("Blade Parent").EnsureComponent <Light>();

                var         bounds  = prefab.EnsureComponent <ConstructableBounds>();
                WindTurbine turbine = prefab.EnsureComponent <WindTurbine>();

                GameObject lightEmitter = new GameObject("Light Emitter");
                lightEmitter.transform.parent        = prefab.transform;
                lightEmitter.transform.localPosition = new Vector3(0f, 2f, 0f);
                var light = lightEmitter.EnsureComponent <Light>();
                light.intensity             = 1f;
                light.range                 = 20f;
                light.lightShadowCasterMode = LightShadowCasterMode.Everything;

                AssetBundleRequest request2 = QPatch.bundle.LoadAssetAsync <AudioClip>("turbineloop");
                yield return(request2);

                turbine.soundLoop = request2.asset as AudioClip;
                CoroutineTask <GameObject> task = CraftData.GetPrefabForTechTypeAsync(TechType.SolarPanel);
                yield return(task);

                PowerRelay     powerRelay = GameObject.Instantiate(task.GetResult()).GetComponent <PowerRelay>();
                IPrefabRequest req3       = PrefabDatabase.GetPrefabForFilenameAsync("Base/Ghosts/PowerSystemPreview.prefab");
                yield return(req3);

                if (req3.TryGetPrefab(out powerRelay.powerSystemPreviewPrefab))
                {
                    turbine.relayPrefab = powerRelay;
                }
                TurbineHealth turbineHealth = prefab.EnsureComponent <TurbineHealth>();
                PowerSource   powerSource   = prefab.EnsureComponent <PowerSource>();
                powerSource.maxPower           = QPatch.config.MaxPower;
                powerRelay.internalPowerSource = powerSource;
                powerRelay.dontConnectToRelays = false;
                powerRelay.maxOutboundDistance = 50;
                //powerRelay.powerSystemPreviewPrefab = Resources.Load<GameObject>("Base/Ghosts/PowerSystemPreview.prefab");
                turbine.Activate();
            }
            prefab.SetActive(true);
            gameObject.Set(prefab);
        }
Exemple #8
0
#pragma warning disable CS0618 // marked obsolete in stable branch
#endif
        static IPrefabRequest _getPrefabForFilenameAsync(string filename) => PrefabDatabase.GetPrefabForFilenameAsync(filename);