コード例 #1
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent)
        {
            TechType       techType = entity.TechType.Enum();
            GameObject     prefab;
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId);

            if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);
                if (prefab == null)
                {
                    return(Optional <GameObject> .Of(Utils.CreateGenericLoot(techType)));
                }
            }

            GameObject gameObject = Utils.SpawnFromPrefab(prefab, null);

            gameObject.transform.position   = entity.Position;
            gameObject.transform.localScale = entity.Scale;

            if (parent.IsPresent())
            {
                gameObject.transform.SetParent(parent.Get().transform, true);
            }

            gameObject.transform.localRotation = entity.Rotation;
            gameObject.SetActive(true);

            NitroxIdentifier.SetNewId(gameObject, entity.Id);
            LargeWorldEntity.Register(gameObject);
            CrafterLogic.NotifyCraftEnd(gameObject, techType);

            return(Optional <GameObject> .Of(gameObject));
        }
コード例 #2
0
        public Optional <GameObject> Spawn(Entity entity, Optional <GameObject> parent, EntityCell cellRoot)
        {
            TechType       techType = entity.TechType.Enum();
            GameObject     prefab;
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(entity.ClassId);

            if (!prefabRequest.TryGetPrefab(out prefab)) // I realize its more code but Sorry couldnt stand all the warnings
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);
                if (prefab == null)
                {
                    return(Optional.Of(Utils.CreateGenericLoot(techType)));
                }
            }

            GameObject gameObject = Utils.SpawnFromPrefab(prefab, null);

            gameObject.transform.position   = entity.Transform.Position;
            gameObject.transform.rotation   = entity.Transform.Rotation;
            gameObject.transform.localScale = entity.Transform.LocalScale;

            NitroxEntity.SetNewId(gameObject, entity.Id);
            CrafterLogic.NotifyCraftEnd(gameObject, techType);

            if (parent.HasValue)
            {
                gameObject.transform.SetParent(parent.Value.transform, true);
            }

            if (parent.HasValue && !parent.Value.GetComponent <LargeWorldEntityCell>())
            {
                LargeWorldEntity.Register(gameObject); // This calls SetActive on the GameObject
            }
            else
            {
                gameObject.SetActive(true);
            }

            Optional <EntityMetadataProcessor> metadataProcessor = EntityMetadataProcessor.FromMetaData(entity.Metadata);

            if (metadataProcessor.HasValue)
            {
                metadataProcessor.Value.ProcessMetadata(gameObject, entity.Metadata);
            }

            return(Optional.Of(gameObject));
        }
コード例 #3
0
        private GameObject CreateGameObject(TechType techType, string classId)
        {
            GameObject     prefab;
            IPrefabRequest prefabRequest = PrefabDatabase.GetPrefabAsync(classId);

            if (!prefabRequest.TryGetPrefab(out prefab))
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);

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

            return(Utils.SpawnFromPrefab(prefab, null));
        }
コード例 #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;
        }
コード例 #5
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;
        }
コード例 #6
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);
        }