public override GameObject GetGameObject()
 {
     return(GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.ReinforcedDiveSuit)));
 }
예제 #2
0
        public override GameObject GetGameObject()
        {
            if (sharkPrefabCache)
            {
                return(sharkPrefabCache);
            }

            Console.WriteLine("Beginning shark load");

            Exosuit    exo        = CraftData.GetPrefabForTechType(TechType.Exosuit).GetComponent <Exosuit>();
            SeaMoth    sea        = CraftData.GetPrefabForTechType(TechType.Seamoth).GetComponent <SeaMoth>();
            GameObject ionCrystal = CraftData.GetPrefabForTechType(TechType.PrecursorIonCrystal);

            GameObject shark = MainPatch.bundle.LoadAsset <GameObject>("SharkPrefab.prefab");

            List <string> exclusions = new List <string>
            {
                "Window",
                "Sonar",
                "EnergyBlade",
                "VolumeLight",
                "Shield"
            };

            Material newMat  = new Material(ionCrystal.GetComponentInChildren <MeshRenderer>().material);
            Vector4  fakesss = newMat.GetVector("_FakeSSSparams");

            fakesss.y = 0f;
            newMat.SetVector("_FakeSSSparams", fakesss);

            foreach (Renderer rend in shark.GetComponentsInChildren <MeshRenderer>())
            {
                if (exclusions.IndexOf(rend.name) == -1)
                {
                    rend.material.shader = Shader.Find("MarmosetUBER");
                }

                if (rend.name == "EnergyBlade")
                {
                    rend.material          = newMat;
                    rend.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
                }
            }

            Console.WriteLine("Setting up component");

            Shark sharkComp = shark.EnsureComponent <Shark>();

            sharkComp.playerSits     = true;
            sharkComp.playerPosition = shark.transform.Find("Scaler/SeatPosition").gameObject;
            sharkComp.handLabel      = "Pilot 5H-4RK";
            sharkComp.controlSheme   = Vehicle.ControlSheme.Submersible;
            sharkComp.mainAnimator   = shark.EnsureComponent <Animator>();
            sharkComp.mainAnimator.runtimeAnimatorController = sea.mainAnimator.runtimeAnimatorController;
            sharkComp.oxygenEnergyCost = 0f;

            sharkComp.bladeControl = shark.EnsureComponent <SharkBladeControl>();

            while (shark.GetComponent <FMOD_CustomLoopingEmitter>())
            {
                GameObject.Destroy(shark.GetComponent <FMOD_CustomLoopingEmitter>());
            }

            sharkComp.chargeUp = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.chargeUp.followParent = true;
            sharkComp.chargeUp.asset        = sea.pulseChargeSound.asset;
            sharkComp.boost = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.boost.followParent      = true;
            sharkComp.boost.asset             = exo.loopingJetSound.asset;
            sharkComp.boost.assetStop         = exo.loopingJetSound.assetStop;
            sharkComp.normalMove              = shark.AddComponent <FMOD_CustomLoopingEmitter>();
            sharkComp.normalMove.followParent = true;
            sharkComp.normalMove.asset        = sea.engineSound.engineRpmSFX.asset;
            sharkComp.chargeFinished          = sea.seamothElectricalDefensePrefab.GetComponent <ElectricalDefense>().defenseSound;
            sharkComp.splash = sea.splashSound;

            sharkComp.welcomeNotification             = shark.EnsureComponent <VoiceNotification>();
            sharkComp.welcomeNotification.text        = "5H-4RK: Welcome aboard, Captain";
            sharkComp.welcomeNotification.minInterval = exo.welcomeNotification.minInterval;
            sharkComp.welcomeNotification.sound       = exo.welcomeNotification.sound;

            sharkComp.rightHandPlug = sharkComp.transform.Find("Scaler/HandTargets/Right");
            sharkComp.leftHandPlug  = sharkComp.transform.Find("Scaler/HandTargets/Left");
            sharkComp.window        = shark.transform.Find("Scaler/SharkMesh/Sonar").gameObject;

            Console.WriteLine("Adding control");

            SharkControl control = shark.EnsureComponent <SharkControl>();

            control.shark       = sharkComp;
            control.sound       = shark.EnsureComponent <SharkSound>();
            control.sound.shark = sharkComp;

            Console.WriteLine("Adding health");

            LiveMixin     mixin = shark.EnsureComponent <LiveMixin>();
            LiveMixinData data  = ScriptableObject.CreateInstance <LiveMixinData>();

            mixin.health              = 100f;
            data.maxHealth            = 100f;
            data.destroyOnDeath       = false;
            data.weldable             = true;
            data.canResurrect         = false;
            data.invincibleInCreative = true;
            mixin.data          = data;
            sharkComp.liveMixin = mixin;

            Console.WriteLine("Adding forces");

            WorldForces worldForces = shark.EnsureComponent <WorldForces>();

            worldForces.aboveWaterGravity = 9.8f;
            worldForces.underwaterDrag    = 1f;
            worldForces.underwaterGravity = 0f;
            worldForces.aboveWaterDrag    = 0.5f;
            worldForces.useRigidbody      = shark.GetComponent <Rigidbody>();

            sharkComp.worldForces = worldForces;

            Console.WriteLine("Setting up other components");

            shark.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global;
            shark.EnsureComponent <SkyApplier>().renderers       = shark.GetComponentsInChildren <Renderer>();
            shark.EnsureComponent <TechTag>().type             = TechType;
            shark.EnsureComponent <PrefabIdentifier>().ClassId = ClassID;
            var vfx        = shark.EnsureComponent <VFXConstructing>();
            var seamothvfx = sea.GetComponentInChildren <VFXConstructing>();

            vfx.blurOffset         = seamothvfx.blurOffset;
            vfx.lineWidth          = seamothvfx.lineWidth;
            vfx.alphaDetailTexture = seamothvfx.alphaDetailTexture;
            vfx.alphaEnd           = seamothvfx.alphaEnd;
            vfx.alphaScale         = seamothvfx.alphaScale;
            vfx.alphaTexture       = seamothvfx.alphaTexture;
            vfx.constructSound     = seamothvfx.constructSound;
            vfx.surfaceSplashSound = seamothvfx.surfaceSplashSound;
            vfx.delay                 = seamothvfx.delay;
            vfx.surfaceSplashFX       = seamothvfx.surfaceSplashFX;
            vfx.surfaceSplashVelocity = seamothvfx.surfaceSplashVelocity;

            var fx = sharkComp.fxControl = shark.EnsureComponent <SharkFXControl>();

            fx.shark   = sharkComp;
            fx.zoomFX  = shark.transform.Find("Scaler/FX/Boost").GetComponent <ParticleSystem>();
            fx.drillFX = shark.transform.Find("Scaler/FX/DrillParticleParent/DrillParticle").GetComponent <ParticleSystem>();
            fx.blinkFX = shark.transform.Find("Scaler/FX/BlinkParticles").GetComponent <ParticleSystem>();

            /*
             * VFXVolumetricLight lightfx = shark.EnsureComponent<VFXVolumetricLight>();
             * lightfx.volumGO = shark.transform.Find("Scaler/SharkMesh/VolumeLight").gameObject;
             * var seamothlight = sea.volumeticLights[0];
             * lightfx.coneMat = new Material(seamothlight.coneMat);
             * lightfx.sphereMat = new Material(seamothlight.sphereMat);
             * lightfx.volumGO.GetComponent<MeshRenderer>().material = lightfx.coneMat;
             * lightfx.intensity = seamothlight.intensity;
             * lightfx.startFallof = seamothlight.startFallof;
             * lightfx.startOffset = seamothlight.startOffset;
             * lightfx.softEdges = seamothlight.softEdges;
             * lightfx.nearClip = seamothlight.nearClip;
             * lightfx.lightSource = shark.transform.Find("Scaler/Headlights/Spot Light").GetComponent<Light>();
             */

            for (int i = 0; i < shark.transform.childCount; i++)
            {
                if (shark.transform.GetChild(i).name.Contains("buildbotpath"))
                {
                    GameObject.Destroy(shark.transform.GetChild(i).gameObject);
                }
            }

            foreach (BuildBotPath path in sea.GetComponentsInChildren <BuildBotPath>())
            {
                Transform newPathParent = new GameObject("buildbotpath").transform;
                newPathParent.parent           = shark.transform;
                newPathParent.localPosition    = Vector3.zero;
                newPathParent.localEulerAngles = Vector3.zero;
                BuildBotPath newPath = newPathParent.gameObject.AddComponent <BuildBotPath>();

                newPath.points = new Transform[path.points.Length];

                int num = 0;
                foreach (Transform trans in path.points)
                {
                    GameObject clone = new GameObject("pathnode" + num);
                    clone.transform.parent        = newPathParent;
                    clone.transform.localPosition = trans.localPosition;
                    clone.transform.localRotation = trans.localRotation;
                    newPath.points[num]           = clone.transform;
                    num++;
                }
            }

            Console.WriteLine("Setting up headlights");

            Transform headLightParent = shark.transform.Find("Scaler/Headlights");

            ToggleLights lights = shark.EnsureComponent <ToggleLights>();

            lights.lightsParent    = headLightParent.gameObject;
            lights.onSound         = sea.toggleLights.lightsOnSound.asset;
            lights.offSound        = sea.toggleLights.lightsOffSound.asset;
            lights.energyPerSecond = 0f;
            sharkComp.lights       = lights;

            Console.WriteLine("Adding smooth cam");

            SharkCameraSmooth camControl = shark.EnsureComponent <SharkCameraSmooth>();

            camControl.shark = sharkComp;
            control.cam      = camControl;

            Console.WriteLine("Adding battery power");

            Transform energyParent = shark.transform.Find("Scaler/BatteryPower").transform;



            sharkComp.energyInterface = shark.EnsureComponent <EnergyInterface>();

            EnergyMixin energy = energyParent.gameObject.EnsureComponent <EnergyMixin>();

            lights.energyMixin             = energy;
            energy.allowBatteryReplacement = true;
            energy.compatibleBatteries     = new List <TechType>
            {
                Shark.internalBattery
            };
            energy.defaultBattery = Shark.internalBattery;

            EnergyMixin.BatteryModels model = new EnergyMixin.BatteryModels();
            model.model = energyParent.Find("PowerCube").gameObject;
            model.model.GetComponent <MeshFilter>().mesh = MainPatch.bundle.LoadAsset <GameObject>("ioncube.obj").GetComponentInChildren <MeshFilter>().mesh;
            MeshRenderer meshRend = model.model.GetComponent <MeshRenderer>();

            meshRend.material = new Material(ionCrystal.GetComponentInChildren <MeshRenderer>().material);
            model.model.transform.localScale = ionCrystal.GetComponentInChildren <MeshFilter>().transform.lossyScale;
            model.techType       = Shark.internalBattery;
            energy.batteryModels = new EnergyMixin.BatteryModels[]
            {
                model,
            };

            energy.controlledObjects = new GameObject[] { };
            energy.storageRoot       = energyParent.gameObject.EnsureComponent <ChildObjectIdentifier>();

            sharkComp.energyInterface.sources = new EnergyMixin[]
            {
                energy
            };

            var energySlot = energyParent.Find("InteractionHandler").gameObject.EnsureComponent <SharkEnergySlot>();

            energySlot.shark = sharkComp;

            Console.WriteLine("Setting up upgrade modules");

            sharkComp.modulesRoot = shark.transform.Find("Scaler/UpgradeModules").gameObject.EnsureComponent <ChildObjectIdentifier>();

            sharkComp.weapons = shark.EnsureComponent <SharkGunControl>();
            sharkComp.weapons.weaponFXParent   = shark.transform.Find("Scaler/Weapons").gameObject;
            sharkComp.weapons.weaponModel      = shark.transform.Find("Scaler/SharkMesh/Lasers").gameObject;
            sharkComp.weapons.upgradeInstalled = false;

            sharkComp.blink                 = shark.EnsureComponent <SharkBlinkControl>();
            sharkComp.blink.blinkSound      = CraftData.GetPrefabForTechType(TechType.PropulsionCannon).GetComponent <PropulsionCannon>().shootSound;
            sharkComp.shield                = shark.EnsureComponent <SharkShieldControl>();
            sharkComp.shield.shieldRenderer = shark.transform.Find("Scaler/SharkMesh/Shield").gameObject;

            sharkComp.drill = shark.EnsureComponent <SharkDrillControl>();
            sharkComp.drill.upgradeModels = shark.transform.Find("Scaler/SharkMesh/DrillMeshes").gameObject;

            StorageContainer drillStorage = sharkComp.drill.storageContainer = shark.transform.Find("Scaler/StorageContainerParent").gameObject.EnsureComponent <StorageContainer>();

            drillStorage.storageRoot  = sharkComp.drill.storageContainer.gameObject.EnsureComponent <ChildObjectIdentifier>();
            drillStorage.width        = 4;
            drillStorage.height       = 5;
            drillStorage.storageLabel = "Drill Storage";
            drillStorage.hoverText    = "OpenStorage";
            drillStorage.container    = null;
            drillStorage.CreateContainer();

            var upgradeconsole = sharkComp.modulesRoot.gameObject.EnsureComponent <VehicleUpgradeConsoleInput>();

            sharkComp.upgradesInput = upgradeconsole;
            upgradeconsole.slots    = new VehicleUpgradeConsoleInput.Slot[4];

            Transform modules = sharkComp.modulesRoot.transform;

            upgradeconsole.flap      = modules.Find("Flap");
            upgradeconsole.collider  = modules.GetComponent <Collider>();
            upgradeconsole.timeClose = 0f;
            upgradeconsole.timeOpen  = 0f;

            int j = 0;

            foreach (string slot in sharkComp.slotIDs)
            {
                if (!Equipment.slotMapping.ContainsKey(slot))
                {
                    Equipment.slotMapping.Add(slot, (EquipmentType)MainPatch.sharkTech);
                }

                GameObject nextSlot = shark.transform.Find("Scaler/SharkMesh/Upgrades/Slot" + (j + 1)).gameObject;

                upgradeconsole.slots[j] = new VehicleUpgradeConsoleInput.Slot()
                {
                    id    = slot,
                    model = nextSlot
                };
                j++;
            }

            Console.WriteLine("Adding GUI");

            shark.EnsureComponent <SharkTestGUI>().shark = sharkComp;

            sharkComp.crushDamage                 = shark.EnsureComponent <CrushDamage>();
            sharkComp.crushDamage.crushDepth      = 500f;
            sharkComp.crushDamage.kBaseCrushDepth = 500f;
            sharkComp.crushDamage.liveMixin       = sharkComp.liveMixin;

            shark.EnsureComponent <SharkUIControl>().shark = sharkComp;

            sharkComp.impactdmg = shark.EnsureComponent <DealDamageOnImpact>();
            sharkComp.impactdmg.damageTerrain      = true;
            sharkComp.impactdmg.mirroredSelfDamage = true;

            Console.WriteLine("Beacon");

            PingType pingType = (PingType)MainPatch.sharkTech;

            GameObject   pingObj = Object.Instantiate(Resources.Load <GameObject>("VFX/xSignal"), shark.transform.position, Quaternion.identity);
            PingInstance ping    = pingObj.GetComponent <PingInstance>();

            ping.SetLabel("5H-4RK");
            ping.displayPingInManager = true;
            ping.pingType             = pingType;
            ping._label = "5H-4RK";
            ping.SetVisible(true);
            pingObj.transform.parent           = shark.transform;
            pingObj.transform.localPosition    = Vector3.zero;
            pingObj.transform.localEulerAngles = Vector3.zero;

            Console.WriteLine("Patching into cached pingtypestrings");

            if (!PingManager.sCachedPingTypeStrings.valueToString.ContainsKey(pingType))
            {
                PingManager.sCachedPingTypeStrings.valueToString.Add(pingType, "SharkPing");
            }

            sharkPrefabCache = shark;

            return(shark);
        }
        public override GameObject GetGameObject()
        {
            GameObject prefab = CraftData.GetPrefabForTechType(BaseItem);

            return(GameObject.Instantiate(prefab));
        }
예제 #4
0
        public override GameObject GetGameObject()
        {
            GameObject prefab = CraftData.GetPrefabForTechType(PrefabTemplate);

            return(Object.Instantiate(prefab));
        }
        public static void playToothSound()
        {
            System.Random random = new System.Random();

            FMODUWE.PlayOneShot(CraftData.GetPrefabForTechType(TechType.Stalker).GetComponent <Stalker>().loseToothSound, new Vector3(Player.main.transform.position.x - random.Next(-8, 8), Player.main.transform.position.y - random.Next(-8, 7), Player.main.transform.position.z - random.Next(-7, 8)), 1f);
        }
예제 #6
0
 public Exosuite2(string classId, string friendlyName, string description, GameObject prefab = null, TechType techToCopy = TechType.None, TechType unlockedBy = TechType.None) : base(classId, friendlyName, description)
 {
     Prefab     = prefab ?? (techToCopy != TechType.None ? CraftData.GetPrefabForTechType(techToCopy, false) : CraftData.GetPrefabForTechType(TechType.None, false));
     TechToCopy = techToCopy;
     UnlockedBy = unlockedBy;
 }
			public override GameObject GetGameObject()
			{
				GameObject originalPrefab = CraftData.GetPrefabForTechType(TechType.SmallLocker);
				GameObject prefab = GameObject.Instantiate(originalPrefab);
				var storageAccess = prefab.AddComponent<VehicleStorageAccess>();
				storageAccess.textPrefab = GameObject.Instantiate(prefab.GetComponentInChildren<Text>());
예제 #8
0
    // Token: 0x06000016 RID: 22 RVA: 0x00003018 File Offset: 0x00001218
    public void OnConsoleCommand_waterparkspawn(NotificationCenter.Notification n)
    {
        bool flag = !Player.main.currentWaterPark;

        if (flag)
        {
            ErrorMessage.AddDebug("Not currently inside a waterpark!");
        }
        else
        {
            bool flag2 = n != null && n.data != null && n.data.Count > 0;
            if (flag2)
            {
                string   text = (string)n.data[0];
                TechType techType;
                bool     flag3 = UWE.Utils.TryParseEnum <TechType>(text, out techType);
                if (flag3)
                {
                    bool flag4 = CraftData.IsAllowed(techType);
                    if (flag4)
                    {
                        GameObject prefabForTechType = CraftData.GetPrefabForTechType(techType, true);
                        bool       flag5             = prefabForTechType != null;
                        if (flag5)
                        {
                            bool flag6 = prefabForTechType.GetComponent <Creature>();
                            if (flag6)
                            {
                                int  num = 1;
                                int  num2;
                                bool flag7 = n.data.Count > 1 && int.TryParse((string)n.data[1], out num2);
                                if (flag7)
                                {
                                    num = num2;
                                }
                                bool flag8 = n.data.Count > 2;
                                if (flag8)
                                {
                                    float num3 = float.Parse((string)n.data[2]);
                                }
                                Debug.Log(string.Format("Spawning {0} {1}", num, techType));
                                for (int i = 0; i < num; i++)
                                {
                                    WaterParkCreature.Born(techType, Player.main.currentWaterPark, Player.main.transform.position);
                                }
                            }
                            else
                            {
                                ErrorMessage.AddDebug("Not valid creature!");
                            }
                        }
                        else
                        {
                            ErrorMessage.AddDebug("Could not find prefab for TechType = " + techType);
                        }
                    }
                }
                else
                {
                    ErrorMessage.AddDebug("Could not parse " + text + " as TechType");
                }
            }
        }
    }
예제 #9
0
 public override GameObject GetGameObject()
 {
     return(GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.DepletedReactorRod)));
 }
예제 #10
0
        private void DrawHostilesMenu()
        {
            if (reaper == null)
            {
                if (GUILayout.Button("Spawn Reaper"))
                {
                    GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.ReaperLeviathan, true);
                    GameObject gameObject        = Utils.CreatePrefab(prefabForTechType);
                    LargeWorldEntity.Register(gameObject);
                    CrafterLogic.NotifyCraftEnd(gameObject, TechType.ReaperLeviathan);
                    gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
                    reaper = gameObject.GetComponentInChildren <ReaperLeviathan>();
                    gameObject.transform.position += 50f * gameObject.transform.forward;
                }
            }
            else
            {
                GUILayout.Space(10);

                if (GUILayout.Button("Reaper Components"))
                {
                    foreach (Component c in reaper.GetComponentsInChildren(typeof(Component)))
                    {
                        Log.Print("Component: " + c + " on go: " + c.gameObject.name);
                    }
                }

                if (GUILayout.Button("Delete Reaper"))
                {
                    Destroy(reaper.gameObject);
                }

                GUILayout.Space(10);
            }

            if (crabsquid == null)
            {
                if (GUILayout.Button("Spawn Crabsquid"))
                {
                    GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.CrabSquid, true);
                    GameObject gameObject        = Utils.CreatePrefab(prefabForTechType);
                    LargeWorldEntity.Register(gameObject);
                    CrafterLogic.NotifyCraftEnd(gameObject, TechType.CrabSquid);
                    gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
                    crabsquid = gameObject.GetComponentInChildren <CrabSquid>();
                    gameObject.transform.position += 50f * gameObject.transform.forward;
                }
            }
            else
            {
                GUILayout.Space(10);

                if (GUILayout.Button("Crabsquid Components"))
                {
                    foreach (Component c in crabsquid.GetComponentsInChildren(typeof(Component)))
                    {
                        Log.Print("Component: " + c + " on go: " + c.gameObject.name);
                    }
                }

                if (GUILayout.Button("Delete Crabsquid"))
                {
                    Destroy(crabsquid.gameObject);
                }

                GUILayout.Space(10);
            }

            if (ghostlevi == null)
            {
                if (GUILayout.Button("Spawn Ghost Levi"))
                {
                    GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.GhostLeviathan, true);
                    GameObject gameObject        = Utils.CreatePrefab(prefabForTechType);
                    LargeWorldEntity.Register(gameObject);
                    CrafterLogic.NotifyCraftEnd(gameObject, TechType.GhostLeviathan);
                    gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
                    ghostlevi = gameObject.GetComponentInChildren <GhostLeviathan>();
                    gameObject.transform.position += 50f * gameObject.transform.forward;
                }
            }
            else
            {
                GUILayout.Space(10);

                if (GUILayout.Button("Ghost Levi Components"))
                {
                    foreach (Component c in ghostlevi.GetComponentsInChildren(typeof(Component)))
                    {
                        Log.Print("Component: " + c + " on go: " + c.gameObject.name);
                    }
                }

                if (GUILayout.Button("Delete Ghost Levi"))
                {
                    Destroy(ghostlevi.gameObject);
                }

                GUILayout.Space(10);
            }

            if (seaDragon == null)
            {
                if (GUILayout.Button("Spawn Seadragon"))
                {
                    GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.SeaDragon, true);
                    GameObject gameObject        = Utils.CreatePrefab(prefabForTechType);
                    LargeWorldEntity.Register(gameObject);
                    CrafterLogic.NotifyCraftEnd(gameObject, TechType.SeaDragon);
                    gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
                    seaDragon = gameObject.GetComponentInChildren <SeaDragon>();
                    gameObject.transform.position += 50f * gameObject.transform.forward;
                }
            }
            else
            {
                GUILayout.Space(10);

                if (GUILayout.Button("Seadragon Components"))
                {
                    foreach (Component c in seaDragon.GetComponentsInChildren(typeof(Component)))
                    {
                        Log.Print("Component: " + c + " on go: " + c.gameObject.name);
                    }
                }

                if (GUILayout.Button("Delete Seadragon"))
                {
                    Destroy(seaDragon.gameObject);
                }

                GUILayout.Space(10);
            }

            if (warper == null)
            {
                if (GUILayout.Button("Spawn warper"))
                {
                    GameObject prefabForTechType = CraftData.GetPrefabForTechType(TechType.Warper, true);
                    GameObject gameObject        = Utils.CreatePrefab(prefabForTechType);
                    LargeWorldEntity.Register(gameObject);
                    CrafterLogic.NotifyCraftEnd(gameObject, TechType.Warper);
                    gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
                    warper = gameObject.GetComponentInChildren <Warper>();
                    gameObject.transform.position += 50f * gameObject.transform.forward;
                }
            }
            else
            {
                GUILayout.Space(10);

                if (GUILayout.Button("Warper Components"))
                {
                    foreach (Component c in warper.GetComponentsInChildren(typeof(Component)))
                    {
                        Log.Print("Component: " + c + " on go: " + c.gameObject.name);
                    }
                }

                if (GUILayout.Button("Delete Warper"))
                {
                    Destroy(warper.gameObject);
                }

                GUILayout.Space(10);
            }
        }
예제 #11
0
        private static void AddInventory(TechType techType, int count = 1, bool bNoMessage = false, bool bSpawnIfCantAdd = true)
        {
            // Ripped<cough>based upon MrPurple6411's method Deconstruct_Patch from the BuilderModule
            if (Player.main.isPiloting)
            {
#if SUBNAUTICA_STABLE
                //GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false);
                GameObject prefabForTechType = CraftData.GetPrefabForTechType(techType, true);
                GameObject gameObject        = (prefabForTechType != null) ? global::Utils.SpawnFromPrefab(prefabForTechType, null) : global::Utils.CreateGenericLoot(techType);
#elif BELOWZERO
                GameObject gameObject = CraftData.InstantiateFromPrefab(null, techType, false); // Coming back to this months later, I didn't think this worked in BZ, because it's not async. But apparently it does...
#endif
                Pickupable pickup = gameObject.GetComponent <Pickupable>();
                if (pickup != null)
                {
                    pickup.Initialize();

                    // This is kind of messy but it's an easy way to get the cross-game code running. In SN1 modules will always == null so the block won't run; but it'll still compile.
#if SUBNAUTICA_STABLE
                    Equipment modules = null;
#elif BELOWZERO
                    SeaTruckUpgrades upgrades = Player.main.GetComponentInParent <SeaTruckUpgrades>();
                    Equipment        modules  = upgrades?.modules;
#endif
                    if (modules != null && TechTypeHandler.TryGetModdedTechType("SeaTruckStorage", out TechType storageType))
                    {
                        //HashSet<string> TruckSlotIDs = modules.equipment.Keys.ToSet<string>();
                        List <string> TruckSlotIDs = null;
                        modules.GetSlots(EquipmentType.SeaTruckModule, TruckSlotIDs);
                        foreach (string slot in TruckSlotIDs)
                        {
                            InventoryItem item = modules.GetItemInSlot(slot);
                            if (item.item.GetTechType() == storageType)
                            {
                                //InventoryItem item = modules.GetItemInSlot(slot);

                                if (item.item.TryGetComponent(out SeamothStorageContainer seamothStorageContainer))
                                {
                                    InventoryItem newItem = new InventoryItem(pickup);
                                    if (seamothStorageContainer.container.AddItem(newItem) != null)
                                    {
                                        string name = Language.main.Get(pickup.GetTechName());
                                        ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                        //uGUI_IconNotifier.main.Play(pickup.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);
                                        uGUI_IconNotifier.main.Play(techType, uGUI_IconNotifier.AnimationType.From, null);
                                        pickup.PlayPickupSound();
#if !RELEASE
                                        Logger.Log(Logger.Level.Debug, $"Adding tech {techType} to Seatruck storage");
#endif
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        Vehicle thisVehicle = Player.main.GetVehicle();
                        if (thisVehicle != null)
                        {
                            if (thisVehicle is Exosuit exo)
                            {
                                StorageContainer storageContainer = exo.storageContainer;

                                if (storageContainer != null)
                                {
                                    int lastCount = storageContainer.container.GetCount(techType);
                                    storageContainer.container.AddItem(pickup);
                                    int techCount = storageContainer.container.GetCount(techType);
#if !RELEASE
                                    Logger.Log(Logger.Level.Debug, $"Adding tech {techType.AsString().PadLeft(15)} to Exosuit storage; previous count {lastCount}, new count {techCount}");
#endif
                                    if (techCount - lastCount == 1)
                                    {
                                        string name = Language.main.Get(pickup.GetTechName());
                                        ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));

                                        uGUI_IconNotifier.main.Play(pickup.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);
                                        pickup.PlayPickupSound();
                                        return;
                                    }
                                }
                            }

                            else if (thisVehicle is SeaMoth seamoth)
                            {
                                //bool storageCheck = false;
                                List <IItemsContainer> containers = new List <IItemsContainer>();
                                seamoth.GetAllStorages(containers);
                                //for (int i = 0; i < 12; i++)
                                InventoryItem newItem = new InventoryItem(pickup);
                                foreach (IItemsContainer storage in containers)
                                {
                                    try
                                    {
                                        //ItemsContainer storage = seamoth.GetStorageInSlot(i, TechType.VehicleStorageModule);
                                        if (storage is ItemsContainer iContainer)
                                        {
                                            int lastCount = iContainer.GetCount(techType);
                                            iContainer.AddItem(pickup);
                                            int techCount = iContainer.GetCount(techType);
#if !RELEASE
                                            Logger.Log(Logger.Level.Debug, $"Adding tech {techType.AsString().PadLeft(15)} to Seamoth storage; previous count {lastCount}, new count {techCount}");
#endif
                                            if (techCount - lastCount == 1)
                                            {
                                                string name = Language.main.Get(pickup.GetTechName());
                                                ErrorMessage.AddMessage(Language.main.GetFormat("VehicleAddedToStorage", name));
                                                uGUI_IconNotifier.main.Play(pickup.GetTechType(), uGUI_IconNotifier.AnimationType.From, null);

                                                pickup.PlayPickupSound();
                                                //storageCheck = true;
                                                return;
                                            }
                                        }
                                    }
                                    catch (Exception e)
                                    {
#if !RELEASE
                                        Logger.Log(Logger.Level.Debug, $"Exception adding tech {techType} to Seamoth storage: {e.ToString()}");
#endif
                                        continue;
                                    }
                                }

                                /*if (storageCheck)
                                 * {
                                 *  return;
                                 * }*/
                            }
                        }
                    }
                }
            }
#if !RELEASE
            Logger.Log(Logger.Level.Debug, $"Adding tech {techType} to player inventory");
#endif
            CraftData.AddToInventory(techType, count, bNoMessage, bSpawnIfCantAdd);
        }
예제 #12
0
 public override GameObject GetGameObject() => GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.VehicleArmorPlating));
예제 #13
0
 public override GameObject GetGameObject()
 {
     return(CraftData.GetPrefabForTechType(TechType.MapRoomUpgradeScanRange));
 }
예제 #14
0
        public override GameObject GetGameObject()
        {
            var prefab = CraftData.GetPrefabForTechType(TechType.ReinforcedGloves);

            return(ModifyAndInstantiateGameObject(prefab));
        }
예제 #15
0
        public void AddNewTechObject(TechType techType)
        {
            SetDirty(true);

            GameObject newChild = null;

            OutputWindow_Log(MESSAGE_TEXT[MESSAGES.TRY_TO_ADD_A_TECH_OBJECT], (int)techType, techType.ToString());

            try
            {
                newChild = Instantiate(CraftData.GetPrefabForTechType(techType), Vector3.zero, Quaternion.Euler(Vector3.zero));
            }
            catch
            {
                OutputWindow_Log(WARNING_TEXT[WARNINGS.OBJECT_CANNOT_INSTANTIATE], LogType.Error, (int)techType, techType.ToString());
                SetDirty(false);
                return;
            }

            ReleaseObjectDrawing();

            newChild.transform.SetParent(baseObject.transform, false);
            newChild.transform.SetLocalsToZero();
            string objectName = newChild.name;

            newChild.name = "newChild_" + objectName;

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

                bool isValid = false;

                foreach (Type type in ValidTypes)
                {
                    if (componentType == type)
                    {
                        isValid = true;
                        break;
                    }
                }

                if (isValid)
                {
                    if (componentType == typeof(Locomotion))
                    {
                        ((Locomotion)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    if (componentType == typeof(SplineFollowing))
                    {
                        ((SplineFollowing)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    if (componentType == typeof(SwimBehaviour))
                    {
                        ((SwimBehaviour)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    if (componentType == typeof(LiveMixin))
                    {
                        ((LiveMixin)component).enabled = false;
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_STATE_MODIFIED], LogType.Warning, GetComponentShortType(component), "False");
                    }
                    continue;
                }
                else
                {
                    try
                    {
                        DestroyImmediate(component);
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_REMOVED], LogType.Warning, GetComponentShortType(component), newChild.name);
                    }
                    catch
                    {
                        OutputWindow_Log(MESSAGE_TEXT[MESSAGES.COMPONENT_CANNOT_REMOVED], LogType.Error, GetComponentShortType(component), newChild.name);
                    }
                }
            }

            RefreshTransformsList();
            OnObjectChange(newChild);

            OutputWindow_Log(MESSAGE_TEXT[MESSAGES.NEW_TECH_OBJECT_ADDED], newChild.name, newChild.transform.parent.name, newChild.transform.root.name);
        }
예제 #16
0
 public override GameObject GetGameObject()
 {
     return(GameObject.Instantiate(CraftData.GetPrefabForTechType(Original)));
 }
        public override GameObject GetGameObject()
        {
            GameObject    prefab;
            Constructable constructible = null;
            GhostCrafter  crafter;

            switch (FabricatorDetails.Model)
            {
            case ModelTypes.Fabricator:
                prefab  = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.Fabricator));
                crafter = prefab.GetComponent <Fabricator>();
                break;

            case ModelTypes.Workbench:
                prefab  = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.Workbench));
                crafter = prefab.GetComponent <Workbench>();
                break;

            case ModelTypes.MoonPool:
                prefab  = GameObject.Instantiate(Resources.Load <GameObject>("Submarine/Build/CyclopsFabricator"));
                crafter = prefab.GetComponent <Fabricator>();

                // Add prefab ID because CyclopsFabricator normaly doesn't have one
                PrefabIdentifier prefabId = prefab.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = FabricatorDetails.ItemID;
                prefabId.name    = FabricatorDetails.DisplayName;

                // Add tech tag because CyclopsFabricator normaly doesn't have one
                TechTag techTag = prefab.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Retrieve sub game objects
                GameObject cyclopsFabLight = prefab.FindChild("fabricatorLight");
                GameObject cyclopsFabModel = prefab.FindChild("submarine_fabricator_03");
                // Translate CyclopsFabricator model and light
                prefab.transform.localPosition = new Vector3(cyclopsFabModel.transform.localPosition.x,        // Same X position
                                                             cyclopsFabModel.transform.localPosition.y - 0.8f, // Push towards the wall slightly
                                                             cyclopsFabModel.transform.localPosition.z);       // Same Z position
                prefab.transform.localPosition = new Vector3(cyclopsFabLight.transform.localPosition.x,        // Same X position
                                                             cyclopsFabLight.transform.localPosition.y - 0.8f, // Push towards the wall slightly
                                                             cyclopsFabLight.transform.localPosition.z);       // Same Z position
                // Add constructable - This prefab normally isn't constructed.
                constructible       = prefab.AddComponent <Constructable>();
                constructible.model = cyclopsFabModel;
                break;

            default:
                throw new InvalidOperationException("ModelType in CustomFabricator does not correspond to a valid fabricator type");
            }

            crafter.craftTree    = FabricatorDetails.TreeTypeID;
            crafter.handOverText = $"Use {FabricatorDetails.DisplayName}";

            if (constructible is null)
            {
                constructible = prefab.GetComponent <Constructable>();
            }

            constructible.allowedInBase           = FabricatorDetails.AllowedInBase;
            constructible.allowedInSub            = FabricatorDetails.AllowedInCyclops;
            constructible.allowedOutside          = false;
            constructible.allowedOnCeiling        = false;
            constructible.allowedOnGround         = FabricatorDetails.Model == ModelTypes.Workbench;
            constructible.allowedOnWall           = FabricatorDetails.Model != ModelTypes.Workbench;
            constructible.allowedOnConstructables = false;
            constructible.controlModelState       = true;
            constructible.rotationEnabled         = false;
            constructible.techType = this.TechType; // This was necessary to correctly associate the recipe at building time

            SkyApplier skyApplier = prefab.GetComponent <SkyApplier>();

            skyApplier.renderers = prefab.GetComponentsInChildren <Renderer>();
            skyApplier.anchorSky = Skies.Auto;

            if (FabricatorDetails.HasColorValue)
            {
                SkinnedMeshRenderer skinnedMeshRenderer = prefab.GetComponentInChildren <SkinnedMeshRenderer>();
                skinnedMeshRenderer.material.color = FabricatorDetails.ColorTint; // Tint option available
            }

            // Associate power relay
            var powerRelay = new PowerRelay();

            // This is actually a dirty hack
            // The problem is that the parent SubRoot isn't correctly associated at this time.
            // The power relay should be getting set in the GhostCrafter Start() method.
            // But the parent components are coming up null.
            crafter.powerRelay = powerRelay;

            return(prefab);
        }
예제 #18
0
        public override GameObject GetGameObject()
        {
            if (prefab == null)
            {
                prefab = QPatch.bundle.LoadAsset <GameObject>("turbineprefab.prefab");

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

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

                //A collider for the turbine pole and builder tool
                var collider = prefab.AddComponent <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.AddComponent <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").AddComponent <Light>();

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

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

                turbine.soundLoop = QPatch.bundle.LoadAsset <AudioClip>("turbineloop");
                PowerRelay powerRelay = CraftData.GetPrefabForTechType(TechType.SolarPanel).GetComponent <PowerRelay>();
                if (powerRelay != null)
                {
                    turbine.relayPrefab = powerRelay;
                }
                turbine.Activate();
            }
            return(prefab);
        }
        public override GameObject GetGameObject()
        {
            // Instantiate Fabricator object
            var prefab = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.Fabricator));

            // Update prefab name
            prefab.name = NameID;

            // Add prefab ID
            PrefabIdentifier prefabId = prefab.GetComponent <PrefabIdentifier>();

            if (prefabId != null)
            {
                prefabId.ClassId = NameID;
                prefabId.name    = FriendlyName;
            }

            // Add tech tag
            TechTag techTag = prefab.GetComponent <TechTag>();

            if (techTag != null)
            {
                techTag.type = this.TechType;
            }

            // Update sky applier
            SkyApplier skyApplier = prefab.GetComponent <SkyApplier>();

            skyApplier.renderers = prefab.GetComponentsInChildren <Renderer>();
            skyApplier.anchorSky = Skies.Auto;

            // Associate custom craft tree to the fabricator
            Fabricator fabricator = prefab.GetComponent <Fabricator>();

            fabricator.craftTree    = this.TreeTypeID;
            fabricator.handOverText = HandOverText;

            // Modify existing constructable - This is just a modified Fabricator which already had a Constructible component.
            Constructable constructible = prefab.GetComponent <Constructable>();

            constructible.allowedInBase           = true;
            constructible.allowedInSub            = true;
            constructible.allowedOutside          = false;
            constructible.allowedOnCeiling        = false;
            constructible.allowedOnGround         = false;
            constructible.allowedOnWall           = true;
            constructible.allowedOnConstructables = false;
            constructible.controlModelState       = true;
            constructible.rotationEnabled         = false;
            constructible.techType = this.TechType; // This was necessary to correctly associate the recipe at building time

            // Set the custom texture
            Texture2D           customTexture       = ImageUtils.LoadTextureFromFile(@"./QMods/MoreCyclopsUpgrades/Assets/NuclearFabricatorT.png");
            SkinnedMeshRenderer skinnedMeshRenderer = prefab.GetComponentInChildren <SkinnedMeshRenderer>();

            skinnedMeshRenderer.material.mainTexture = customTexture;

            // Associate power relay
            var powerRelay = new PowerRelay();

            // This is actually a dirty hack
            // The problem is that the parent SubRoot isn't correctly associated at this time.
            // The power relay should be getting set in the GhostCrafter Start() method.
            // But the parent components are coming up null.
            (fabricator as GhostCrafter).SetPrivateField("powerRelay", powerRelay, BindingFlags.Instance);

            return(prefab);
        }
예제 #20
0
        /// <summary>
        /// The in-game <see cref="GameObject"/>.
        /// </summary>
        /// <returns></returns>
        public override GameObject GetGameObject()
        {
            GameObject    prefab;
            Constructable constructible = null;
            GhostCrafter  crafter;

            switch (this.Model)
            {
            case Models.Fabricator:
            default:
                prefab  = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.Fabricator));
                crafter = prefab.GetComponent <Fabricator>();
                break;

            case Models.Workbench:
                prefab  = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.Workbench));
                crafter = prefab.GetComponent <Workbench>();
                break;

#if SUBNAUTICA
            case Models.MoonPool:
                prefab  = GameObject.Instantiate(Resources.Load <GameObject>("Submarine/Build/CyclopsFabricator"));
                crafter = prefab.GetComponent <Fabricator>();

                // Add prefab ID because CyclopsFabricator normaly doesn't have one
                PrefabIdentifier prefabId = prefab.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = this.ClassID;
                prefabId.name    = this.FriendlyName;

                // Add tech tag because CyclopsFabricator normaly doesn't have one
                TechTag techTag = prefab.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Retrieve sub game objects
                GameObject cyclopsFabLight = prefab.FindChild("fabricatorLight");
                GameObject cyclopsFabModel = prefab.FindChild("submarine_fabricator_03");
                // Translate CyclopsFabricator model and light
                prefab.transform.localPosition = new Vector3(cyclopsFabModel.transform.localPosition.x,        // Same X position
                                                             cyclopsFabModel.transform.localPosition.y - 0.8f, // Push towards the wall slightly
                                                             cyclopsFabModel.transform.localPosition.z);       // Same Z position
                prefab.transform.localPosition = new Vector3(cyclopsFabLight.transform.localPosition.x,        // Same X position
                                                             cyclopsFabLight.transform.localPosition.y - 0.8f, // Push towards the wall slightly
                                                             cyclopsFabLight.transform.localPosition.z);       // Same Z position
                // Add constructable - This prefab normally isn't constructed.
                constructible       = prefab.AddComponent <Constructable>();
                constructible.model = cyclopsFabModel;
                break;
#endif
            case Models.Custom:
                prefab  = GetCustomCrafterPreFab();
                crafter = prefab.EnsureComponent <Fabricator>();
                break;
            }

            crafter.craftTree    = this.TreeTypeID;
            crafter.handOverText = $"Use {this.FriendlyName}";

            if (constructible is null)
            {
                constructible = prefab.GetComponent <Constructable>();
            }

            constructible.allowedInBase           = this.AllowedInBase;
            constructible.allowedInSub            = this.AllowedInCyclops;
            constructible.allowedOutside          = this.AllowedOutside;
            constructible.allowedOnCeiling        = this.AllowedOnCeiling;
            constructible.allowedOnGround         = this.AllowedOnGround;
            constructible.allowedOnWall           = this.AllowedOnWall;
            constructible.allowedOnConstructables = false;
            constructible.controlModelState       = true;
            constructible.rotationEnabled         = this.RotationEnabled;
            constructible.techType = this.TechType; // This was necessary to correctly associate the recipe at building time

            SkyApplier skyApplier = prefab.GetComponent <SkyApplier>();
            skyApplier.renderers = prefab.GetComponentsInChildren <Renderer>();
            skyApplier.anchorSky = Skies.Auto;

            if (this.UseCustomTint)
            {
                SkinnedMeshRenderer skinnedMeshRenderer = prefab.GetComponentInChildren <SkinnedMeshRenderer>();
                skinnedMeshRenderer.material.color = this.ColorTint; // Tint option available
            }

            crafter.powerRelay = PowerSource.FindRelay(prefab.transform);

            return(prefab);
        }
예제 #21
0
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.Glass));

            return(prefab);
        }
예제 #22
0
        public override GameObject GetGameObject()
        {
            GameObject obj = MainPatch.bundle.LoadAsset <GameObject>("Assets/AlienRifle/Alien Rifle.prefab");

            obj.GetOrAddComponent <PrefabIdentifier>().ClassId   = ClassID;
            obj.GetOrAddComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Near;
            obj.GetOrAddComponent <TechTag>().type            = TechType;
            obj.GetOrAddComponent <Pickupable>().isPickupable = true;
            SkyApplier sky = obj.GetOrAddComponent <SkyApplier>();

            sky.renderers = obj.GetComponentsInChildren <MeshRenderer>();
            sky.anchorSky = Skies.Auto;

            GameObject originalRifle = Resources.Load <GameObject>("WorldEntities/Doodads/Precursor/Prison/Relics/Alien_relic_07");
            Material   newMat        = originalRifle.GetComponentInChildren <MeshRenderer>().material;

            sky.renderers[0].materials = new Material[] { newMat, newMat };

            sky.renderers[0].GetComponent <MeshFilter>().mesh = originalRifle.GetComponentInChildren <MeshFilter>().mesh;

            VFXFabricating vfx = obj.transform.Find("RifleMesh").gameObject.GetOrAddComponent <VFXFabricating>();

            vfx.localMinY   = -0.4f;
            vfx.localMaxY   = 0.2f;
            vfx.posOffset   = new Vector3(-0.054f, 0.1f, -0.06f);
            vfx.eulerOffset = new Vector3(0f, 0f, 90f);
            vfx.scaleFactor = 1f;

            WorldForces forces = obj.GetOrAddComponent <WorldForces>();

            forces.underwaterGravity       = 0f;
            forces.useRigidbody            = obj.GetOrAddComponent <Rigidbody>();
            forces.useRigidbody.useGravity = false;

            RifleTool rifle = obj.GetOrAddComponent <RifleTool>();

            rifle.mainCollider             = obj.GetComponentInChildren <Collider>();
            rifle.ikAimRightArm            = true;
            rifle.ikAimLeftArm             = true;
            rifle.useLeftAimTargetOnPlayer = true;
            rifle.chargeEffect             = rifle.transform.Find("chargeparticles").GetComponent <ParticleSystem>();
            rifle.shootEffect  = rifle.transform.Find("shooteffect").GetComponent <ParticleSystem>();
            rifle.chargeMeter  = obj.transform.Find("HUD/ChargeBar");
            rifle.bulletPrefab = obj.transform.Find("BulletPrefab").gameObject;

            rifle.energyMixin = obj.GetOrAddComponent <EnergyMixin>();
            rifle.energyMixin.allowBatteryReplacement = true;
            rifle.energyMixin.compatibleBatteries     = new List <TechType>()
            {
                TechType.PrecursorIonBattery
            };

            rifle.energyMixin.defaultBattery = TechType.None;
            rifle.energyMixin.batteryModels  = new EnergyMixin.BatteryModels[]
            {
                new EnergyMixin.BatteryModels()
                {
                    model    = obj.transform.Find("Battery").gameObject,
                    techType = TechType.PrecursorIonBattery
                }
            };
            rifle.energyMixin.storageRoot = obj.transform.Find("Battery").gameObject.GetOrAddComponent <ChildObjectIdentifier>();

            GameObject seamoth = CraftData.GetPrefabForTechType(TechType.Seamoth);

            rifle.sonarSound               = obj.GetOrAddComponent <FMOD_CustomEmitter>();
            rifle.sonarSound.asset         = seamoth.GetComponent <SeaMoth>().sonarSound.asset;
            rifle.sonarSound.playOnAwake   = false;
            rifle.sonarSound.followParent  = true;
            rifle.sonarSound.restartOnPlay = true;

            rifle.shootSound               = CraftData.GetPrefabForTechType(TechType.RepulsionCannon).GetComponent <RepulsionCannon>().shootSound;
            rifle.chargeSound              = obj.GetOrAddComponent <FMOD_CustomLoopingEmitter>();
            rifle.chargeSound.asset        = seamoth.GetComponent <SeaMoth>().pulseChargeSound.asset;
            rifle.chargeSound.followParent = true;
            rifle.sonarSound.restartOnPlay = true;

            rifle.Awake();

            return(obj);
        }
예제 #23
0
        public override GameObject GetGameObject()
        {
            //Instantiates a copy of the prefab that is loaded from the AssetBundle loaded above.
            GameObject _prefab = GameObject.Instantiate(Utils.Helper.Bundle.LoadAsset <GameObject>("HabitatTest.prefab"));

            _prefab.name = Constant.HabitatTest_ClassID;
            //Need a tech tag for most prefabs
            var techTag = _prefab.AddComponent <TechTag>();

            techTag.type = TechType;

            _prefab.EnsureComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global;
            _prefab.EnsureComponent <PrefabIdentifier>().ClassId   = ClassID;

            //Collider for the turbine pole and builder tool
            //var collider = _prefab.AddComponent<BoxCollider>();
            //collider.center = new Vector3(-0.1f, 1.2f, 00f);
            //collider.size = new Vector3(3f, 2.35f, 2f);

            //Update all shaders
            ApplySubnauticaShaders(_prefab);

            // Add constructable - This prefab normally isn't constructed.
            ConstructableBase constructible = _prefab.AddComponent <ConstructableBase>();

            constructible.constructedAmount       = 1;
            constructible.allowedInBase           = false;
            constructible.allowedInSub            = false;
            constructible.allowedOutside          = true;
            constructible.allowedOnCeiling        = false;
            constructible.allowedOnGround         = true;
            constructible.allowedOnWall           = false;
            constructible.allowedOnConstructables = false;
            constructible.techType             = this.TechType;
            constructible.rotationEnabled      = true;
            constructible.placeDefaultDistance = 6f;
            constructible.placeMinDistance     = 0.5f;
            constructible.placeMaxDistance     = 15f;
            constructible.surfaceType          = VFXSurfaceTypes.metal;
            constructible.model        = _prefab;//.transform.GetChild(0).gameObject;
            constructible.forceUpright = true;
            //_prefab.AddComponent<LayerSelector>();

            //_prefab.AddComponent<Rigidbody>();
            //var constructableBase = _prefab.AddComponent<ConstructableBase>();
            //var prefabIdentifier = _prefab.AddComponent<PrefabIdentifier>();


            PowerRelay baseRoom  = CraftData.GetPrefabForTechType(TechType.BaseRoom).GetComponent <PowerRelay>();
            var        baseGhost = GameObjectFinder.FindByName(_prefab, "Habitat_Proxy");
            var        baseG     = baseGhost.AddComponent <global::Base>();

            baseG = baseRoom.GetComponent <global::Base>();
            //baseG.isGhost = false;
            var baseGC = baseGhost.AddComponent <BaseAddCellGhost>();

            baseGC = baseRoom.GetComponent <BaseAddCellGhost>();
            //baseGC.cellType = Base.CellType.Moonpool;
            //baseGC.minHeightFromTerrain = 2;
            //baseGC.maxHeightFromTerrain = 10;
            //_prefab.AddComponent<BehaviourLOD>();
            //_prefab.AddComponent<PowerRelay>();
            //_prefab.AddComponent<LiveMixin>();
            //_prefab.AddComponent<Stabilizer>();
            //_prefab.AddComponent<DealDamageOnImpact>();
            //_prefab.AddComponent<SubWaterPlane>();
            //_prefab.AddComponent<CrushDamage>();

            return(_prefab);
        }
예제 #24
0
 public static GameObject prefabCopy(TechType techType) => Object.Instantiate(CraftData.GetPrefabForTechType(techType));
예제 #25
0
        public override GameObject GetGameObject()
        {
            var prefab = CraftData.GetPrefabForTechType(TechType.Compass);

            return(Object.Instantiate(prefab));
        }
예제 #26
0
 /// <summary>
 /// Using this constructor you can choose to pass through a <see cref="GameObject"/> Prefab of your own or call one of the prefabs already ingame by passing through a <see cref="TechType"/>.
 /// You can also Pass through a list of <see cref="LootDistributionData.BiomeData"/> to manualy set where your prefab will spawn OR if you pass through a <see cref="TechType"/> without a list then it will copy the spawn locations from that type if it does naturally spawn.
 /// NOTE! you cannot use the TechType clone to copy the loot distribution of mod added fragments.
 /// </summary>
 /// <param name="classId"></param>
 /// <param name="friendlyName"></param>
 /// <param name="description"></param>
 /// <param name="biomeData"></param>
 /// <param name="techToCopy"></param>
 public FragmentPrefab(string classId, string friendlyName, string description, GameObject prefab = null, TechType techToCopy = TechType.None, List <BiomeData> biomeData = null) : base(classId, friendlyName, description)
 {
     Prefab     = prefab ?? (techToCopy != TechType.None ? CraftData.GetPrefabForTechType(techToCopy, false) : CraftData.GetPrefabForTechType(TechType.Fragment, false));
     BiomeData  = biomeData ?? new List <BiomeData>();
     TechToCopy = techToCopy;
 }
예제 #27
0
        public override GameObject GetGameObject()
        {
            try
            {
                if (GetPrefabs())
                {
                    var prefab = GameObject.Instantiate(Prefab);

                    //Scale the object
                    prefab.transform.localScale += new Vector3(0.24f, 0.24f, 0.24f);

                    var size   = new Vector3(2.493512f, 1.875936f, 1.439421f);
                    var center = new Vector3(0.07963049f, 1.088284f, 0f);

                    GameObjectHelpers.AddConstructableBounds(prefab, size, center);

                    var model = prefab.FindChild("model");

                    //========== Allows the building animation and material colors ==========//
                    Shader     shader     = Shader.Find("MarmosetUBER");
                    Renderer[] renderers  = prefab.GetComponentsInChildren <Renderer>();
                    SkyApplier skyApplier = prefab.EnsureComponent <SkyApplier>();
                    skyApplier.renderers = renderers;
                    skyApplier.anchorSky = Skies.Auto;
                    //========== Allows the building animation and material colors ==========//

                    // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN
                    var lwe = prefab.AddComponent <LargeWorldEntity>();
                    lwe.cellLevel = LargeWorldEntity.CellLevel.Far;

                    // Add constructible
                    var constructable = prefab.AddComponent <Constructable>();

                    constructable.allowedOutside          = true;
                    constructable.allowedInBase           = true;
                    constructable.allowedOnGround         = true;
                    constructable.allowedOnWall           = false;
                    constructable.rotationEnabled         = true;
                    constructable.allowedOnCeiling        = false;
                    constructable.allowedInSub            = false;
                    constructable.allowedOnConstructables = false;
                    constructable.model    = model;
                    constructable.techType = TechType;



                    PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>();
                    prefabID.ClassId = ClassID;

                    //AddBubbles(prefab);

                    PowerRelay solarPowerRelay = CraftData.GetPrefabForTechType(TechType.SolarPanel).GetComponent <PowerRelay>();

                    var ps = prefab.AddComponent <PowerSource>();
                    ps.maxPower = 500f;

                    var pFX = prefab.AddComponent <PowerFX>();
                    pFX.vfxPrefab   = solarPowerRelay.powerFX.vfxPrefab;
                    pFX.attachPoint = prefab.transform;

                    var pr = prefab.AddComponent <PowerRelay>();
                    pr.powerFX             = pFX;
                    pr.maxOutboundDistance = 15;
                    pr.internalPowerSource = ps;

                    prefab.AddComponent <TechTag>().type = TechType;
                    prefab.AddComponent <AlterraGenController>();


                    Resources.UnloadAsset(solarPowerRelay);

                    //Apply the glass shader here because of autosort lockers for some reason doesnt like it.
                    MaterialHelpers.ApplyGlassShaderTemplate(prefab, "_glass", Mod.ModName);
                    return(prefab);
                }
            }
            catch (Exception e)
            {
                QuickLogger.Error(e.Message);
            }

            return(null);
        }
        public override GameObject GetGameObject()
        {
            if (processedPrefab is null)
            {
                GameObject prefab     = Main.assetBundle.LoadAsset <GameObject>("TechPistol.prefab");
                GameObject gameObject = GameObject.Instantiate(prefab, Vector3.zero, Quaternion.identity, false);

                MeshRenderer[] componentsInChildren = gameObject.GetComponentsInChildren <MeshRenderer>();
                foreach (MeshRenderer meshRenderer in componentsInChildren)
                {
                    if (meshRenderer.name.StartsWith("Gun") || meshRenderer.name.StartsWith("Target"))
                    {
                        Texture emissionMap = meshRenderer.material.GetTexture("_EmissionMap");
                        Texture specMap     = meshRenderer.material.GetTexture("_MetallicGlossMap");

                        meshRenderer.material.shader = Shader.Find("MarmosetUBER");
                        meshRenderer.material.EnableKeyword("MARMO_EMISSION");
                        meshRenderer.material.EnableKeyword("MARMO_SPECMAP");
                        meshRenderer.material.SetTexture(ShaderPropertyID._Illum, emissionMap);
                        meshRenderer.material.SetTexture(ShaderPropertyID._SpecTex, specMap);
                        meshRenderer.material.SetColor("_GlowColor", new Color(1f, 1f, 1f));
                        meshRenderer.material.SetFloat(ShaderPropertyID._GlowStrength, 1f);
                        meshRenderer.material.SetFloat(ShaderPropertyID._GlowStrengthNight, 1f);
                    }
                }

                EnergyMixin energyMixin = gameObject.GetComponent <EnergyMixin>();
                List <EnergyMixin.BatteryModels> batteryModels = new List <EnergyMixin.BatteryModels>();
                foreach (TechType techType in modelsToMake)
                {
                    GameObject batteryprefab = CraftData.GetPrefabForTechType(techType, false);
                    GameObject model         = GameObject.Instantiate(batteryprefab);
                    batteryprefab.SetActive(false);
                    model.SetActive(false);

                    GameObject.DestroyImmediate(model.GetComponentInChildren <WorldForces>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <Rigidbody>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <Battery>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <LargeWorldEntity>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <TechTag>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <EntityTag>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <Pickupable>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <Collider>());
                    GameObject.DestroyImmediate(model.GetComponentInChildren <SkyApplier>());

                    if (model.TryGetComponent <PrefabIdentifier>(out PrefabIdentifier prefabIdentifier))
                    {
                        string classId = prefabIdentifier.ClassId;
                        GameObject.DestroyImmediate(prefabIdentifier);
                        ChildObjectIdentifier childObjectIdentifier = model.EnsureComponent <ChildObjectIdentifier>();
                        childObjectIdentifier.ClassId = classId;
                    }

                    model.SetActive(false);

                    bool cellCheck = techType.AsString().ToLower().Contains("cell");

                    Vector3 position = cellCheck ? new Vector3(0f, 1.45f, 0.95f) : new Vector3(0f, 1.46f, 0.95f);
                    Vector3 scale    = cellCheck ? new Vector3(0.15f, 0.15f, 0.15f) : new Vector3(0.3f, 0.3f, 0.3f);

                    model.transform.SetParent(energyMixin.storageRoot.transform);
                    model.transform.SetPositionAndRotation(gameObject.transform.position, gameObject.transform.rotation);
                    model.transform.localPosition    = position;
                    model.transform.localEulerAngles = new Vector3(270f, 0f, 0f);
                    model.transform.localScale       = scale;

                    batteryModels.Add(new EnergyMixin.BatteryModels
                    {
                        techType = techType,
                        model    = model
                    });
                }

                energyMixin.compatibleBatteries = compatibleTech;
                energyMixin.batteryModels       = batteryModels.ToArray();

                gameObject.GetComponent <Rigidbody>().detectCollisions = false;
                gameObject.GetComponent <PrefabIdentifier>().ClassId   = base.ClassID;
                gameObject.GetComponent <TechTag>().type         = base.TechType;
                gameObject.GetComponent <SkyApplier>().renderers = gameObject.GetComponentsInChildren <Renderer>(true);

                processedPrefab = gameObject;
                GameObject.DontDestroyOnLoad(processedPrefab);
            }
            return(GameObject.Instantiate(processedPrefab));
        }
        public override GameObject GetGameObject()
        {
            GameObject prefab = CraftData.GetPrefabForTechType(TechType.CyclopsShieldModule);

            return(GameObject.Instantiate(prefab));
        }
        private void Initialize()
        {
            _buildable = GetComponent <Constructable>() ?? GetComponentInParent <Constructable>();

            if (FindComponents())
            {
                QuickLogger.Debug($"Turbine Components Found", true);

                _prefabID = GetComponentInParent <PrefabIdentifier>();

                var currentBiome = BiomeManager.GetBiome();

                if (!string.IsNullOrEmpty(currentBiome))
                {
                    var data = BiomeManager.GetBiomeData(currentBiome);
                }

                AISolutionsData.Instance.OnRotationChanged += AiSolutionsDataOnOnRotationChanged;

                if (HealthManager == null)
                {
                    HealthManager = gameObject.GetComponent <AIJetStreamT242HealthManager>() ?? GetComponentInParent <AIJetStreamT242HealthManager>();
                }


                HealthManager.Initialize(this);
                HealthManager.SetHealth(100);
                HealthManager.SetDamageModel(_damage);

                if (PowerManager == null)
                {
                    PowerManager          = GetComponentInParent <AIJetStreamT242PowerManager>() ?? GetComponent <AIJetStreamT242PowerManager>();
                    PowerManager.maxPower = 300;
                }



                if (PowerRelay == null)
                {
                    PowerRelay = gameObject.AddComponent <PowerRelay>();

                    PowerRelay.internalPowerSource = PowerManager;
                    PowerRelay.maxOutboundDistance = 15;
                    PowerRelay.dontConnectToRelays = false;


                    PowerFX    yourPowerFX = gameObject.AddComponent <PowerFX>();
                    PowerRelay powerRelay  = CraftData.GetPrefabForTechType(TechType.SolarPanel).GetComponent <PowerRelay>();

                    yourPowerFX.vfxPrefab   = powerRelay.powerFX.vfxPrefab;
                    yourPowerFX.attachPoint = gameObject.transform;
                    PowerRelay.powerFX      = yourPowerFX;

                    Resources.UnloadAsset(powerRelay);
                }

                PowerManager.Initialize(this);

                AnimationManager = gameObject.GetComponentInParent <AIJetStreamT242AnimationManager>();

                BeaconManager = gameObject.GetComponentInParent <BeaconController>();

                if (_display == null)
                {
                    _display = GetComponent <AIJetStreamT242Display>() ?? GetComponentInParent <AIJetStreamT242Display>();
                }

                IsInitialized = true;
                //_currentBiome = BiomeManager.GetBiome();
            }
            else
            {
                IsInitialized = false;
                throw new MissingComponentException("Failed to find all components");
            }

            if (!IsInitialized)
            {
                return;
            }

            PowerManager.OnKillBattery += Unsubscribe;
        }