Exemple #1
0
        public override GameObject GetGameObject()
        {
            if (PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.Seamoth), out string seamothFileName))
            {
                GameObject prefab     = Resources.Load <GameObject>(seamothFileName);
                GameObject gameObject = GameObject.Instantiate(prefab);
                prefab.SetActive(false);
                gameObject.SetActive(false);

                SeaMoth seaMoth = gameObject.GetComponent <SeaMoth>();

                SeamothCloneBehaviour seamothCloneBehaviour = gameObject.EnsureComponent <SeamothCloneBehaviour>();

                typeof(SeaMoth).GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy | BindingFlags.Static).ForEach((x) => { try { x.SetValue(seamothCloneBehaviour, x.GetValue(seaMoth)); } catch { } });

                seamothCloneBehaviour.energyInterface = seaMoth.energyInterface;

                GameObject.DestroyImmediate(seaMoth);

                gameObject.SetActive(true);
                return(gameObject);
            }

            return(GameObject.CreatePrimitive(PrimitiveType.Cube));
        }
        private static float fActiveModeHealthRegenMultiplier    = 5f; // Health regeneration is multiplied by this amount in active mode


        protected void Start()
        {
            string RCFilename;

            if (thermalReactorCharge is null && PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.Exosuit), out RCFilename))
            {
                AddressablesUtility.LoadAsync <GameObject>(RCFilename).Completed += (x) =>
                {
                    GameObject gameObject1 = x.Result;
                    Exosuit    exosuit     = gameObject1?.GetComponent <Exosuit>();
                    thermalReactorCharge = exosuit?.thermalReactorCharge;
                };
            }

            if (sonarSound is null && PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.Seamoth), out RCFilename))
            {
                AddressablesUtility.LoadAsync <GameObject>(RCFilename).Completed += (x) =>
                {
                    GameObject gameObject1 = x.Result;
                    SeaMoth    seamoth     = gameObject1?.GetComponent <SeaMoth>();
                    if (seamoth?.sonarSound != null)
                    {
                        sonarSound = this.gameObject.AddComponent <FMOD_CustomEmitter>();
                        sonarSound.SetAsset(seamoth.sonarSound.asset);
                        sonarSound.UpdateEventAttributes();
                    }
                    foreach (var r in gameObject1.GetComponentsInChildren <Renderer>())
                    {
                    }
                };
            }
        }
        public void SpawnNetworkTechType(TechType type, Vector3 position, Quaternion rotation)
        {
            string classId = ClassIDForTechType[type];

            if (PrefabDatabase.TryGetPrefabFilename(classId, out string filename))
            {
                GameObject go = PhotonNetwork.Instantiate(filename, position, rotation, 0);
            }
        }
Exemple #4
0
        public void spawnresource(string prefab)
        {
            // if parameter is prefabID
            if (PrefabDatabase.TryGetPrefabFilename(prefab, out string prefabPath))
            {
                prefab = prefabPath;
            }

            Utils.CreatePrefab(Resources.Load <GameObject>(prefab));
        }
Exemple #5
0
        public override GameObject GetGameObject()
        {
            string classid = CraftData.GetClassIdForTechType(TechType.VehicleArmorPlating);

            if (PrefabDatabase.TryGetPrefabFilename(classid, out string filename))
            {
                var prefab = Resources.Load <GameObject>(filename);
                var obj    = GameObject.Instantiate(prefab);

                // Get the TechTags and PrefabIdentifiers
                var techTag          = obj.EnsureComponent <TechTag>();
                var prefabIdentifier = obj.GetComponent <PrefabIdentifier>();

                // Change them so they fit to our requirements.
                techTag.type             = TechType;
                prefabIdentifier.ClassId = ClassID;

                return(obj);
            }
            return(null);

            /*
             * // Get the ElectricalDefense module prefab and instantiate it
             * var path = "WorldEntities/Tools/Compass";
             * var prefab = Resources.Load<GameObject>(path);
             * var obj = GameObject.Instantiate(prefab);
             *
             * // Get the TechTags and PrefabIdentifiers
             * var techTag = obj.GetComponent<TechTag>();
             * var prefabIdentifier = obj.GetComponent<PrefabIdentifier>();
             *
             * // Change them so they fit to our requirements.
             * techTag.type = TechType;
             * prefabIdentifier.ClassId = ClassID;
             *
             * var pick = obj.GetComponent<Pickupable>();
             * if (pick == null)
             * {
             *  CattleLogger.Message("Pickupable is Null");
             * } else
             * {
             *  if (pick.AllowedToPickUp())
             *  {
             *      CattleLogger.Message("Allowed to pick up");
             *  } else
             *  {
             *      CattleLogger.Message("NOT Allowed to pick up");
             *  }
             * }
             *
             * return obj;
             */
        }
        protected void Start()
        {
#pragma warning disable CS0612 // Type or member is obsolete
            if (repulsionCannonFireSound is null && PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.RepulsionCannon), out var RCFilename))
            {
                AddressablesUtility.LoadAsync <GameObject>(RCFilename).Completed += (x) =>
                {
                    var gameObject1 = x.Result;
                    var component   = gameObject1?.GetComponent <RepulsionCannon>();
                    repulsionCannonFireSound = component?.shootSound;
                };
            }

            if ((stasisRifleFireSound is null || stasisRifleEvent is null) && PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.StasisRifle), out var SRFilename))
            {
                AddressablesUtility.LoadAsync <GameObject>(SRFilename).Completed += (x) =>
                {
                    var gameObject2 = x.Result;
                    var component2  = gameObject2?.GetComponent <StasisRifle>();
                    stasisRifleFireSound = component2?.fireSound;
                    stasisRifleEvent     = component2?.chargeBegin;
                };
            }

            if (modeChangeSound is null && PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.PropulsionCannon), out var PCFilename))
            {
                AddressablesUtility.LoadAsync <GameObject>(PCFilename).Completed += (x) =>
                {
                    var gameObject3 = x.Result;
                    var component3  = gameObject3?.GetComponent <PropulsionCannon>();
                    modeChangeSound = component3?.shootSound;
                };
            }

            if (laserShootSound is null && PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.Welder), out var WFilename))
            {
                AddressablesUtility.LoadAsync <GameObject>(WFilename).Completed += (x) =>
                {
                    var gameObject4 = x.Result;
                    var component4  = gameObject4?.GetComponent <Welder>();
                    laserShootSound = component4?.weldSound;
                };
            }
#pragma warning restore CS0612 // Type or member is obsolete

            laserEndParticleSystem = LaserParticles.transform.Find("Laserend").gameObject.GetComponent <ParticleSystem>();
            scaleParticleSystem    = LaserParticles.transform.Find("scale").GetComponent <ParticleSystem>();
        }
        protected void Start()
        {
            if (repulsionCannonFireSound is null)
            {
                if (PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.RepulsionCannon), out var RCFilename))
                {
                    var gameObject1 = Resources.Load <GameObject>(RCFilename);
                    var component   = gameObject1.GetComponent <RepulsionCannon>();
                    repulsionCannonFireSound = component.shootSound;
                    gameObject1.SetActive(false);
                }

                if (PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.StasisRifle), out var SRFilename))
                {
                    var gameObject2 = Resources.Load <GameObject>(SRFilename);
                    var component2  = gameObject2.GetComponent <StasisRifle>();
                    stasisRifleFireSound = component2.fireSound;
                    stasisRifleEvent     = component2.chargeBegin;
                    gameObject2.SetActive(false);
                }

                if (PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.PropulsionCannon), out var PCFilename))
                {
                    var gameObject3 = Resources.Load <GameObject>(PCFilename);
                    var component3  = gameObject3.GetComponent <PropulsionCannon>();
                    modeChangeSound = component3.shootSound;
                    gameObject3.SetActive(false);
                }

                if (PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.Welder), out var WFilename))
                {
                    var gameObject4 = Resources.Load <GameObject>(WFilename);
                    var component4  = gameObject4.GetComponent <Welder>();
                    laserShootSound = component4.weldSound;
                    gameObject4.SetActive(false);
                }

                Transform transform1;
                laserEndParticleSystem = LaserParticles.transform.Find("Laserend").gameObject.GetComponent <ParticleSystem>();
                scaleParticleSystem    = LaserParticles.transform.Find("scale").GetComponent <ParticleSystem>();
            }
            else
            {
                rigidbody.detectCollisions = true;
            }
        }
        private static void CreateButtonPrefab()
        {
            GameObject prefab  = null;
            string     classId = CraftData.GetClassIdForTechType(TechType.SmallLocker);

            string logtmp = ("InLine CreateButton Prefab - MrPurple6411 way - " + classId);

            QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Warn, logtmp);

            string filename;

            if (PrefabDatabase.TryGetPrefabFilename(classId, out filename))
            {
                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Warn, "InLine CreateButton Prefab - MrPurple6411 way - trygetprefabfilename");
                prefab = Resources.Load <GameObject>(filename);
                Mod.PrintObject(prefab, "asdf1234");
            }
            else
            {
                QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Warn, "InLine CreateButton Prefab - MrPurple6411 way - bad 1");
            }

            if (prefab != null)
            {
                /*
                 *                              GameObject smallLocker = Resources.Load<GameObject>("Submarine/Build/SmallLocker.prefab");
                 *                              //QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Warn, "InLine CreateButton Prefab - DEV Step 02");
                 *                                      //Mod.PrintObject(smallLocker, "asdf1234"); //Thats the Problem for the Null Reference Error
                 *                              QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Warn, "InLine CreateButton Prefab - DEV Step 02-01");
                 */

                var signInput = prefab.GetComponentInChildren <uGUI_SignInput>();
                var original  = signInput.transform.GetChild(1).gameObject.GetComponent <Button>();
                buttonPrefab = GameObject.Instantiate(original);
                var go = buttonPrefab.gameObject;
                GameObject.DestroyImmediate(buttonPrefab);
                buttonPrefab               = go.AddComponent <Button>();
                buttonPrefab.transition    = original.transition;
                buttonPrefab.targetGraphic = go.GetComponentInChildren <Image>();
                buttonPrefab.colors        = original.colors;
                go.SetActive(true);
            }
        }
Exemple #9
0
        private GameObject CreateGameObject(TechType techType, string classId)
        {
            GameObject prefab = null;

            if (PrefabDatabase.TryGetPrefabFilename(classId, out string filename))
            {
                prefab = Resources.Load <GameObject>(filename);
            }

            if (prefab == null)
            {
                prefab = CraftData.GetPrefabForTechType(techType, false);
                if (prefab == null)
                {
                    return(Utils.CreateGenericLoot(techType));
                }
            }

            return(Utils.SpawnFromPrefab(prefab, null));
        }
Exemple #10
0
        public void Awake()
        {
            if (completeSound is null && PrefabDatabase.TryGetPrefabFilename(CraftData.GetClassIdForTechType(TechType.Builder), out var BuilderFilename))
            {
#if SUBNAUTICA_STABLE
                var builderPrefab = Resources.Load <GameObject>(BuilderFilename).GetComponent <BuilderTool>();
                completeSound = Instantiate(builderPrefab.completeSound, gameObject.transform);
#else
                AddressablesUtility.LoadAsync <GameObject>(BuilderFilename).Completed += (x) =>
                {
                    var gameObject1   = x.Result;
                    var builderPrefab = gameObject1 != null?gameObject1.GetComponent <BuilderTool>() : null;

                    if (builderPrefab is not null)
                    {
                        completeSound = Instantiate(builderPrefab.completeSound, gameObject.transform);
                    }
                };
#endif
            }
        }
Exemple #11
0
        private static void InventoryAndWaterParkSetup()
        {
            // Setting a name for the Rockgrub
            LanguageHandler.SetTechTypeName(TechType.Rockgrub, "Rockgrub");
            // Setting a Tooltip for the Rockgrub
            LanguageHandler.SetTechTypeTooltip(TechType.Rockgrub, "A small, luminescent scavenger");

            // Setting a Sprite for the Rockgrub
            Sprite rockgrub = ImageUtils.LoadSpriteFromFile(Path.Combine(AssetsFolder, "RockGrub.png"));

            if (rockgrub != null)
            {
                SpriteHandler.RegisterSprite(TechType.Rockgrub, rockgrub);
            }
            // Setting Rockgrub's size in the Inventory
            CraftDataHandler.SetItemSize(TechType.Rockgrub, new Vector2int(1, 1));
            // Setting WPC Parameters for Rockgrub so it can grow and breed normaly
            WaterParkCreature.waterParkCreatureParameters[TechType.Rockgrub] = new WaterParkCreatureParameters(0.03f, 0.7f, 1f, 1f);
            // Setting Fuel value for the Rockgrub
            BioReactorHandler.SetBioReactorCharge(TechType.Rockgrub, 350f);
            // Totally origina.. *cough* taken from MrPurple's CYS code
            #region BiomeData stuff
            Dictionary <TechType, List <BiomeData> > rockgrubBiomeData = new Dictionary <TechType, List <BiomeData> >()
            {
                {
                    TechType.Rockgrub,
                    new List <BiomeData>()
                    {
                        new BiomeData()
                        {
                            biome       = BiomeType.SafeShallows_CaveSpecial,
                            count       = 3,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.GrassyPlateaus_CaveCeiling,
                            count       = 3,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.MushroomForest_CaveRecess,
                            count       = 5,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.MushroomForest_CaveSpecial,
                            count       = 3,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.MushroomForest_GiantTreeInteriorRecess,
                            count       = 3,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.MushroomForest_GiantTreeInteriorSpecial,
                            count       = 3,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.KooshZone_CaveWall,
                            count       = 3,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.SparseReef_DeepWall,
                            count       = 4,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.GrassyPlateaus_CaveCeiling,
                            count       = 3,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.Dunes_Rock,
                            count       = 4,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.Dunes_SandPlateau,
                            count       = 4,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.Dunes_CaveCeiling,
                            count       = 4,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.Dunes_CaveWall,
                            count       = 4,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.Mountains_CaveWall,
                            count       = 4,
                            probability = 1f
                        },
                        new BiomeData()
                        {
                            biome       = BiomeType.GrassyPlateaus_CaveFloor,
                            count       = 4,
                            probability = 1f
                        },
                    }
                }
            };
            foreach (KeyValuePair <TechType, List <BiomeData> > pair in rockgrubBiomeData)
            {
                string classId = CraftData.GetClassIdForTechType(pair.Key) ?? pair.Key.AsString();
                if (PrefabDatabase.TryGetPrefabFilename(classId, out string prefabpath))
                {
                    if (!WorldEntityDatabase.TryGetInfo(classId, out WorldEntityInfo info))
                    {
                        info = new WorldEntityInfo()
                        {
                            cellLevel  = LargeWorldEntity.CellLevel.Medium,
                            classId    = classId,
                            localScale = UnityEngine.Vector3.one,
                            prefabZUp  = false,
                            slotType   = EntitySlot.Type.Medium,
                            techType   = pair.Key
                        };
                    }
                    WorldEntityDatabaseHandler.AddCustomInfo(classId, info);
                }
                SrcData data = new SrcData()
                {
                    prefabPath = prefabpath, distribution = pair.Value
                };
                LootDistributionHandler.AddLootDistributionData(classId, data);
            }
            #endregion
        }
Exemple #12
0
            private static void LoadRecyclingPrefab(TechType originTech, TechType recyclingTech)
            {
                string originPrefab, originFile;
                var    prefabID = prefabIDPrefix + (int)recyclingTech;

                CraftDataWrapper.SetTechPrefab(recyclingTech, prefabID);
                PrefabDatabaseWrapper.PreparePrefabDatabase();
                if (CraftDataWrapper.TryGetTechPrefab(originTech, out originPrefab) && PrefabDatabase.TryGetPrefabFilename(originPrefab, out originFile))
                {
                    PrefabDatabaseWrapper.SetPrefabFile(prefabID, originFile);
                }
                else
                {
                    Logger.Warning($"Failed to load prefabID or fileName for TechType '{originTech}'.");
                }
            }
        private static IEnumerator GetPrefabForList(TechType breakable, TechType techType, float chance)
        {
            var task = CraftData.GetPrefabForTechTypeAsync(techType, false);

#if SUBNAUTICA_STABLE
            if (BreakableResource_ChooseRandomResource.prefabs.ContainsKey(breakable))
            {
                var existingPrefab = BreakableResource_ChooseRandomResource.prefabs[breakable].Find((x) => CraftData.GetTechType(x.prefab) == techType);
                if (existingPrefab != null)
                {
                    existingPrefab.chance = chance;
                }
                else
                {
                    yield return(task);

                    var gameObject = task.GetResult();
                    if (gameObject != null)
                    {
                        BreakableResource_ChooseRandomResource.prefabs[breakable].Add(new BreakableResource.RandomPrefab()
                        {
                            prefab = gameObject, chance = chance
                        });
                    }
                }
            }
            else
            {
                BreakableResource_ChooseRandomResource.prefabs[breakable] = new List <BreakableResource.RandomPrefab>();
                yield return(task);

                var gameObject = task.GetResult();
                if (gameObject != null)
                {
                    BreakableResource_ChooseRandomResource.prefabs[breakable].Add(new BreakableResource.RandomPrefab()
                    {
                        prefab = gameObject, chance = chance
                    });
                }
            }
#else
            if (!BreakableResource_ChooseRandomResource.prefabs.ContainsKey(breakable))
            {
                BreakableResource_ChooseRandomResource.prefabs[breakable] = new List <BreakableResource.RandomPrefab>();
            }

            var existingPrefab = BreakableResource_ChooseRandomResource.prefabs[breakable].Find((x) => x.prefabTechType == techType);
            if (existingPrefab != null)
            {
                existingPrefab.chance = chance;
                yield break;
            }

            yield return(task);

            var gameObject = task.GetResult();
            if (gameObject != null && PrefabDatabase.TryGetPrefabFilename(gameObject.GetComponent <PrefabIdentifier>().ClassId, out var filename))
            {
                BreakableResource_ChooseRandomResource.prefabs[breakable].Add(new BreakableResource.RandomPrefab()
                {
                    prefabTechType = techType, prefabReference = new AssetReferenceGameObject(filename), chance = chance
                });
            }
#endif
        }
Exemple #14
0
 public static string getPrefabFilename(string classId) => PrefabDatabase.TryGetPrefabFilename(classId, out string filename)? filename: null;