private void Register() { if (_prefab != null) { var meshRenderers = _prefab.GetComponentsInChildren <MeshRenderer>(); //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renderers = _prefab.GetComponentsInChildren <Renderer>(true); SkyApplier skyApplier = _prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = _prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = _prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = _prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; _prefab.AddComponent <PlayerInteractionManager>(); _prefab.AddComponent <FMOD_CustomLoopingEmitter>(); } }
/* * The first part of setting up the mini manta vehicle. If the components are self contained and do not rely on other components * adding it here works fine. */ public static GameObject CreateMiniMantaVehicle() { GameObject vehicle = Object.Instantiate(MiniMantaVehicleAssetLoader.MINI_MANTA_VEHICLE_EXTERIOR); ApplyMaterials(vehicle); SkyApplier skyApplier = vehicle.GetOrAddComponent <SkyApplier>(); skyApplier.renderers = vehicle.GetComponentsInChildren <Renderer>(); skyApplier.anchorSky = Skies.Auto; vehicle.GetOrAddComponent <VFXSurface>(); vehicle.GetOrAddComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Global; Rigidbody rb = vehicle.GetOrAddComponent <Rigidbody>(); rb.angularDrag = 1f; rb.mass = 12000f; rb.useGravity = false; rb.centerOfMass = new Vector3(-0.1f, 0.8f, -1.7f); WorldForces forces = vehicle.GetOrAddComponent <WorldForces>(); forces.aboveWaterDrag = 0f; forces.aboveWaterGravity = 9.81f; forces.handleDrag = true; forces.handleGravity = true; forces.underwaterDrag = 0.5f; forces.underwaterGravity = 0; vehicle.GetOrAddComponent <TechTag>().type = MINI_MANTA_VEHICLE_TECH_TYPE; vehicle.GetOrAddComponent <PrefabIdentifier>().ClassId = "SubmarineMiniMantaVehicle"; return(vehicle); }
// Gets called when adding a new fish into our small aquarium (or when adding a new fish into the regular aquarium if "FixAquariumLighting" is enabled) public static void FixAquariumFishesSkyApplier(GameObject aquariumAnimRoot) { if (aquariumAnimRoot != null) { foreach (Transform tr in aquariumAnimRoot.transform) { foreach (Transform ctr in tr) { if (ctr.childCount > 0 && !string.IsNullOrEmpty(ctr.name) && ctr.name.StartsWith("fish_attach", true, CultureInfo.InvariantCulture)) { foreach (Transform fish in ctr) { if (fish.gameObject != null) { SkyApplier sa = fish.GetComponent <SkyApplier>(); if (sa == null) { sa = fish.gameObject.AddComponent <SkyApplier>(); } sa.anchorSky = Skies.Auto; sa.renderers = fish.GetAllComponentsInChildren <Renderer>(); sa.dynamic = true; sa.updaterIndex = 0; sa.enabled = true; } } } } } } }
public static bool SetDefaultSkyApplier(GameObject gameObj, Renderer[] renderers = null, Skies anchorSky = Skies.Auto, bool dynamic = false, bool emissiveFromPower = false) { if (gameObj == null) { return(false); } SkyApplier applier = gameObj.GetComponent <SkyApplier>(); if (applier == null) { applier = gameObj.AddComponent <SkyApplier>(); } if (renderers == null) { renderers = gameObj.GetComponentsInChildren <Renderer>(); } if (renderers != null) { applier.renderers = renderers; } applier.anchorSky = anchorSky; applier.dynamic = dynamic; applier.emissiveFromPower = emissiveFromPower; applier.hideFlags = HideFlags.None; applier.useGUILayout = true; applier.enabled = true; return(true); }
/// <summary> /// This game uses its own shader system and as such the shaders from UnityEditor do not work and will leave you with a black object unless in direct sunlight. /// Note: When copying prefabs from the game itself this is already setup and is only needed when importing new prefabs to the game. /// </summary> /// <param name="gameObject"></param> private static void ApplySubnauticaShaders(GameObject gameObject) { Shader shader = Shader.Find("MarmosetUBER"); List <Renderer> Renderers = gameObject.GetComponentsInChildren <Renderer>().ToList(); foreach (Renderer renderer in Renderers) { foreach (Material material in renderer.materials) { //get the old emission before overwriting the shader Texture emissionTexture = material.GetTexture("_EmissionMap"); //overwrites your prefabs shader with the shader system from the game. material.shader = shader; //These enable the item to emit a glow of its own using Subnauticas shader system. material.EnableKeyword("MARMO_EMISSION"); material.SetFloat(ShaderPropertyID._EnableGlow, 1f); material.SetTexture(ShaderPropertyID._Illum, emissionTexture); material.SetColor(ShaderPropertyID._GlowColor, new Color(1f, 1f, 1f, 1f)); } } //This applies the games sky lighting to the object when in the game but also only really works combined with the above code as well. SkyApplier skyApplier = gameObject.EnsureComponent <SkyApplier>(); skyApplier.renderers = Renderers.ToArray(); skyApplier.anchorSky = Skies.Auto; }
internal void DebugSkyApplier(SkyApplier skyApplier) { foreach (Renderer renderer in skyApplier.renderers) { print($"Renderer: {renderer.name}"); } }
private void Register() { if (_prefab != null) { var meshRenderers = _prefab.GetComponentsInChildren <MeshRenderer>(); //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renderers = _prefab.GetComponentsInChildren <Renderer>(true); SkyApplier skyApplier = _prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = _prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = true; constructable.allowedOnGround = false; constructable.allowedInSub = true; constructable.allowedInBase = true; constructable.allowedOnCeiling = false; constructable.allowedOutside = false; constructable.model = _prefab.FindChild("model"); constructable.techType = TechType; GameObjectHelpers.AddConstructableBounds(_prefab, new Vector3(0.4528692f, 0.6682342f, 0.03642998f), new Vector3(0, -0.02660185f, 0.05301314f)); } }
private void Register() { if (_prefab != null) { var meshRenderers = _prefab.GetComponentsInChildren <MeshRenderer>(); //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renderers = _prefab.GetComponentsInChildren <Renderer>(true); SkyApplier skyApplier = _prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = _prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = true; constructable.allowedOnGround = false; constructable.allowedInSub = QPatch.Configuration.AllowInCyclops; constructable.allowedInBase = true; constructable.allowedOnCeiling = false; constructable.allowedOutside = false; constructable.model = _prefab.FindChild("model"); constructable.techType = TechType; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = _prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Near; _prefab.AddComponent <FEHolderController>(); } }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate(_prefab); var container2 = GameObject.Instantiate(CreateStorage()); container2.name = "StorageContainerUnit"; container2.transform.parent = prefab.transform; //========== 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 constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; constructable.allowedOnConstructables = Player.main.GetDepth() > 1; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; //var beacon = prefab.AddComponent<Beacon>(); //beacon.label = "DeepDriller"; var center = new Vector3(0f, 1.579518f, 0f); var size = new Vector3(2.669801f, 2.776958f, 2.464836f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); //prefab.AddComponent<MonoClassTest>(); prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <FMOD_CustomLoopingEmitter>(); prefab.AddComponent <ExStorageDepotController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
public override GameObject GetGameObject() { try { var prefab = GameObject.Instantiate(_prefab); GameObjectHelpers.AddConstructableBounds(prefab, _bSize, _bCenter); 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 = true; constructable.allowedOnConstructables = false; constructable.model = model; constructable.techType = TechType; var light = prefab.GetComponentInChildren <Light>(); var lightR = prefab.AddComponent <RegistredLightSource>(); lightR.hostLight = light; PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>(); prefabID.ClassId = ClassID; AddBubbles(prefab); AddVaporBlast(prefab); prefab.AddComponent <TechTag>().type = TechType; prefab.AddComponent <HydroHarvController>(); //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); } }
private void InitAnimation(GameObject go) { if (!Running) { #if DEBUG_FLORA PrefabIdentifier id = go.GetComponent <PrefabIdentifier>(); if (id != null) { Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + go.name + "] id=[" + id.Id + "] position x=[" + go.transform.localPosition.x + "] y=[" + go.transform.localPosition.y + "] z=[" + go.transform.localPosition.z + "] => Initializing"); } else { Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + go.name + "] position x=[" + go.transform.localPosition.x + "] y=[" + go.transform.localPosition.y + "] z=[" + go.transform.localPosition.z + "] => Initializing"); } #endif if (StaticPrefab != null) { // Configure static renderer StaticPrefab.transform.parent = go.transform; StaticPrefab.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); StaticPrefab.transform.localScale = new Vector3(12f, 12f, 12f); StaticPrefab.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f); // Update sky applier SkyApplier skyApplier = go.GetComponent <SkyApplier>(); skyApplier.renderers = go.GetComponentsInChildren <Renderer>(); skyApplier.anchorSky = Skies.Auto; StaticPrefab.SetActive(true); } // Hide seed model GameObject seed = _grownPlant.gameObject.FindChild("Generic_plant_seed"); if (seed != null) { seed.GetComponent <MeshRenderer>().enabled = false; } // Store init values _initTimeValue = DayNightCycle.main.timePassed; foreach (Transform tr in go.transform) { bool isStatic = tr.name.StartsWith("Land_tree_01_static", true, CultureInfo.InvariantCulture); if (_origScale == Vector3.zero && !isStatic) { _origScale = new Vector3(tr.localScale.x, tr.localScale.y, tr.localScale.z); } else if (_origStaticScale == Vector3.zero && isStatic) { _origStaticScale = new Vector3(tr.localScale.x, tr.localScale.y, tr.localScale.z); } } // Init trees sizes foreach (Transform tr in go.transform) { tr.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f); } Running = true; } }
public override GameObject GetGameObject() { SubRoot cyclops = Player.main.currentSub; if (cyclops != null) { BioAuxCyclopsManager mgr = MCUServices.Find.AuxCyclopsManager <BioAuxCyclopsManager>(cyclops); if (mgr.TrackedBuildablesCount >= BioAuxCyclopsManager.MaxBioReactors) { ErrorMessage.AddMessage(OverLimitString()); return(null); } } if (_prefab == null) { QuickLogger.Error("_prefab is null", true); } var prefab = GameObject.Instantiate(_prefab); if (prefab == null) { QuickLogger.Error("Prefab is null", true); } GameObject model = prefab.FindChild("model"); // Update sky applier SkyApplier skyApplier = prefab.AddComponent <SkyApplier>(); skyApplier.renderers = prefab.GetComponentsInChildren <Renderer>(); skyApplier.anchorSky = Skies.Auto; //Add the constructible component to the prefab Constructable constructible = prefab.AddComponent <Constructable>(); constructible.allowedInBase = false; constructible.allowedInSub = true; // Only allowed in Cyclops constructible.allowedOutside = false; constructible.allowedOnCeiling = false; constructible.allowedOnGround = true; // Only on ground constructible.allowedOnWall = false; constructible.allowedOnConstructables = false; constructible.controlModelState = true; constructible.rotationEnabled = true; constructible.techType = this.TechType; constructible.model = model; prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; CyBioReactorMono bioReactorComponent = prefab.AddComponent <CyBioReactorMono>(); // The component that makes the magic happen return(prefab); }
public override GameObject GetGameObject() { GameObject prefab = CraftData.GetPrefabForTechType(this.PrefabType); var obj = GameObject.Instantiate(prefab); Battery battery = obj.GetComponent <Battery>(); battery._capacity = this.PowerCapacity; battery.name = $"{this.ClassID}BatteryCell"; // If "Enable batteries/powercells placement" feature from Decorations mod is ON. #if SUBNAUTICA if (CbDatabase.PlaceBatteriesFeatureEnabled && CraftData.GetEquipmentType(this.TechType) != EquipmentType.Hand) #elif BELOWZERO if (CbDatabase.PlaceBatteriesFeatureEnabled && TechData.GetEquipmentType(this.TechType) != EquipmentType.Hand) #endif { CraftDataHandler.SetEquipmentType(this.TechType, EquipmentType.Hand); // Set equipment type to Hand. CraftDataHandler.SetQuickSlotType(this.TechType, QuickSlotType.Selectable); // We can select the item. } SkyApplier skyApplier = obj.EnsureComponent <SkyApplier>(); skyApplier.renderers = obj.GetComponentsInChildren <Renderer>(true); skyApplier.anchorSky = Skies.Auto; if (CustomModelData != null) { foreach (Renderer renderer in obj.GetComponentsInChildren <Renderer>(true)) { if (CustomModelData.CustomTexture != null) { renderer.material.SetTexture(ShaderPropertyID._MainTex, this.CustomModelData.CustomTexture); } if (CustomModelData.CustomNormalMap != null) { renderer.material.SetTexture(ShaderPropertyID._BumpMap, this.CustomModelData.CustomNormalMap); } if (CustomModelData.CustomSpecMap != null) { renderer.material.SetTexture(ShaderPropertyID._SpecTex, this.CustomModelData.CustomSpecMap); } if (CustomModelData.CustomIllumMap != null) { renderer.material.SetTexture(ShaderPropertyID._Illum, this.CustomModelData.CustomIllumMap); renderer.material.SetFloat(ShaderPropertyID._GlowStrength, this.CustomModelData.CustomIllumStrength); renderer.material.SetFloat(ShaderPropertyID._GlowStrengthNight, this.CustomModelData.CustomIllumStrength); } } } this.EnhanceGameObject?.Invoke(obj); return(obj); }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate(_prefab); var meshRenderers = prefab.GetComponentsInChildren <MeshRenderer>(); //========== 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 constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; //var beacon = prefab.AddComponent<Beacon>(); var center = new Vector3(0, 3.048428f, 0); var size = new Vector3(4.821606f, 3.35228f, 4.941598f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); //beacon.label = "DeepDriller"; //prefab.AddComponent<LiveMixin>(); prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <FMOD_CustomLoopingEmitter>(); prefab.AddComponent <FCSDeepDrillerController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
public override GameObject GetGameObject() { try { var prefab = GameObject.Instantiate(_Prefab); //========== Allows the building animation and material colors ==========// Shader shader = Shader.Find("MarmosetUBER"); Renderer[] renders = prefab.GetComponentsInChildren <Renderer>(); foreach (Renderer renderer in renders) { renderer.material.shader = shader; } SkyApplier skyApplier = prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renders; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = true; constructable.allowedInBase = true; constructable.allowedOnCeiling = false; constructable.allowedOutside = false; constructable.rotationEnabled = true; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; //Get the Size and Center of a box ow collision around the mesh that will be used as bounds var center = new Vector3(0.05496028f, 1.019654f, 0.05290359f); var size = new Vector3(0.9710827f, 1.908406f, 0.4202727f); //Create or get the constructable bounds GameObjectHelpers.AddConstructableBounds(prefab, size, center); var techTag = prefab.EnsureComponent <TechTag>(); techTag.type = TechType; prefab.EnsureComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.EnsureComponent <AnimationManager>(); prefab.EnsureComponent <ARSolutionsSeaBreezeController>(); return(prefab); } catch (Exception e) { QuickLogger.Error(e.Message); return(null); } }
public override GameObject GetGameObject() { GameObject prefab = GameObject.Instantiate(_prefab); //========== Allows the building animation and material colors ==========// Renderer[] renderers = prefab.GetComponentsInChildren <Renderer>(); SkyApplier skyApplier = prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = renderers; skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// QuickLogger.Debug("Adding Constructible"); // Add constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = true; constructable.allowedOnGround = false; constructable.allowedInSub = true; constructable.allowedInBase = true; constructable.allowedOnCeiling = false; constructable.allowedOutside = false; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; // Add constructible bounds var center = new Vector3(0.2078698f, -0.04198265f, 0.2626062f); var size = new Vector3(1.412603f, 1.45706f, 0.4747875f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); QuickLogger.Debug("GetOrAdd TechTag"); // Allows the object to be saved into the game //by setting the TechTag and the PrefabIdentifier prefab.EnsureComponent <TechTag>().type = this.TechType; QuickLogger.Debug("GetOrAdd PrefabIdentifier"); prefab.EnsureComponent <PrefabIdentifier>().ClassId = this.ClassID; QuickLogger.Debug("Add GameObject CustomBatteryController"); prefab.EnsureComponent <FCSPowerStorageDisplay>(); prefab.EnsureComponent <FCSPowerStorageController>(); QuickLogger.Debug("Made GameObject"); return(prefab); }
public override GameObject GetGameObject() { GameObject prefab = Main.assetBundle.LoadAsset <GameObject>("BioPlasma.prefab"); GameObject obj = Object.Instantiate(prefab); Material warperMaterial = null; GameObject warperPiece = Resources.Load <GameObject>("WorldEntities/Environment/Precursor/LostRiverBase/Precursor_LostRiverBase_WarperLab_Extras"); Renderer[] aRenderers = warperPiece.GetComponentsInChildren <Renderer>(); foreach (var rend in aRenderers) { if (rend.name.EndsWith("part_08")) { warperMaterial = rend.material; break; } if (warperMaterial != null) { break; } } if (warperMaterial is null) { QModManager.Utility.Logger.Log(QModManager.Utility.Logger.Level.Error, "Warper Material is null!", null, true); } obj.EnsureComponent <TechTag>().type = this.TechType; obj.EnsureComponent <PrefabIdentifier>().classId = this.ClassID; obj.EnsureComponent <Pickupable>().isPickupable = true; Renderer[] renderers = obj.GetComponentsInChildren <Renderer>(); foreach (var rend in renderers) { rend.material.shader = Shader.Find("MarmosetUBER"); rend.sharedMaterial.shader = Shader.Find("MarmosetUBER"); rend.material = warperMaterial; rend.sharedMaterial = warperMaterial; } SkyApplier skyApplier = obj.EnsureComponent <SkyApplier>(); skyApplier.anchorSky = Skies.Auto; skyApplier.renderers = renderers; skyApplier.enabled = true; obj.EnsureComponent <Rigidbody>(); WorldForces wf = obj.EnsureComponent <WorldForces>(); wf.aboveWaterGravity = 0f; wf.underwaterGravity = 0f; warperPiece.SetActive(false); prefab.SetActive(false); return(obj); }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate <GameObject>(_prefab); //========== Allows the building animation and material colors ==========// SkyApplier skyApplier = prefab.EnsureComponent <SkyApplier>(); skyApplier.renderers = prefab.GetComponentsInChildren <Renderer>(); skyApplier.anchorSky = Skies.Auto; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = false; constructable.allowedOnCeiling = false; constructable.allowedOutside = true; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; constructable.forceUpright = true; constructable.placeDefaultDistance = 10f; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Global; //var beacon = prefab.AddComponent<Beacon>(); var center = new Vector3(0, 3.106274f, 0); var size = new Vector3(6.85554f, 6.670462f, 7.002856f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); //beacon.label = "DeepDriller"; //prefab.AddComponent<LiveMixin>(); prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <TechTag>().type = TechTypeID; prefab.AddComponent <FMOD_CustomLoopingEmitter>(); prefab.AddComponent <FCSDeepDrillerController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
internal static void Register() { var model = _prefab.FindChild("model"); SkyApplier skyApplier = _prefab.AddComponent <SkyApplier>(); skyApplier.renderers = model.GetComponentsInChildren <MeshRenderer>(); skyApplier.anchorSky = Skies.Auto; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = _prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Far; //========== Allows the building animation and material colors ==========// // Add constructible var constructable = _prefab.AddComponent <Constructable>(); constructable.allowedOutside = true; constructable.forceUpright = true; constructable.placeMaxDistance = 7f; constructable.placeMinDistance = 5f; constructable.placeDefaultDistance = 6f; constructable.model = model; constructable.techType = Singleton.TechType; PrefabIdentifier prefabID = _prefab.AddComponent <PrefabIdentifier>(); prefabID.ClassId = Singleton.ClassID; Rigidbody component = _prefab.EnsureComponent <Rigidbody>(); component.mass = 400f; component.angularDrag = 1f; component.drag = 1f; component.isKinematic = false; component.freezeRotation = false; component.detectCollisions = true; component.useGravity = false; _prefab.AddComponent <Stabilizer>().uprightAccelerationStiffness = 0.3f; _prefab.AddComponent <TechTag>().type = Singleton.TechType; _prefab.AddComponent <FMOD_CustomLoopingEmitter>(); _prefab.AddComponent <GaspodManager>(); _prefab.AddComponent <AnimationManager>(); _prefab.AddComponent <GaspodCollectorController>(); var wf = _prefab.AddComponent <WorldForces>(); wf.aboveWaterGravity = 9.81f; wf.underwaterDrag = 2f; wf.handleGravity = true; wf.handleDrag = true; }
public override GameObject GetGameObject() { GameObject prefab = GameObject.Instantiate(this.GameObject); GameObject container = GameObject.Instantiate(this.CargoCrateContainer); prefab.name = this.ClassID; // Update container renderers GameObject cargoCrateModel = container.FindChild("model"); Renderer[] cargoCrateRenderers = cargoCrateModel.GetComponentsInChildren <Renderer>(); container.transform.parent = prefab.transform; foreach (Renderer rend in cargoCrateRenderers) { rend.enabled = false; } container.transform.localPosition = new Vector3(0.0f, 0.0f, 0.0f); container.transform.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f); container.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f); container.SetActive(true); // Update colliders GameObject builderTrigger = container.FindChild("Builder Trigger"); GameObject collider = container.FindChild("Collider"); BoxCollider builderCollider = builderTrigger.GetComponent <BoxCollider>(); builderCollider.isTrigger = false; builderCollider.enabled = false; BoxCollider objectCollider = collider.GetComponent <BoxCollider>(); objectCollider.isTrigger = false; objectCollider.enabled = false; // Delete constructable bounds ConstructableBounds cb = container.GetComponent <ConstructableBounds>(); GameObject.DestroyImmediate(cb); // Update sky applier SkyApplier sa = prefab.GetComponent <SkyApplier>(); if (sa == null) { sa = prefab.GetComponentInChildren <SkyApplier>(); } if (sa == null) { sa = prefab.AddComponent <SkyApplier>(); } sa.renderers = prefab.GetComponentsInChildren <Renderer>(); sa.anchorSky = Skies.Auto; return(prefab); }
public override GameObject GetGameObject() { try { var prefab = GameObject.Instantiate(DSSModelPrefab.FloorMountRackPrefab); var size = new Vector3(0.5399321f, 0.9509504f, 0.5594633f); var center = new Vector3(0f, 0.5926822f, 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 constructible var constructable = prefab.AddComponent <Constructable>(); constructable.allowedOutside = false; constructable.allowedInBase = true; constructable.allowedOnGround = true; constructable.allowedOnWall = false; constructable.rotationEnabled = true; constructable.allowedOnCeiling = false; constructable.allowedInSub = true; constructable.allowedOnConstructables = false; constructable.model = model; constructable.techType = TechType; PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>(); prefabID.ClassId = ClassID; prefab.AddComponent <TechTag>().type = TechType; prefab.AddComponent <DSSRackController>(); //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() { GameObject gameObject = Main.assetBundle.LoadAsset <GameObject>("AncientSword"); foreach (Renderer renderer in gameObject.GetComponentsInChildren <Renderer>()) { renderer.material.shader = Shader.Find("MarmosetUBER"); renderer.material.SetColor("_Emission", new Color(1f, 1f, 1f)); } gameObject.AddComponent <PrefabIdentifier>().ClassId = ClassID; gameObject.AddComponent <TechTag>().type = TechType; gameObject.AddComponent <BoxCollider>().size = new Vector3(0.1f, 0.1f, 0.1f); gameObject.AddComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Near; gameObject.AddComponent <Pickupable>().isPickupable = true; Fixer fixer = gameObject.AddComponent <Fixer>(); fixer.ClassId = ClassID; fixer.techType = TechType; SkyApplier skyApplier = gameObject.AddComponent <SkyApplier>(); skyApplier.renderers = gameObject.GetComponentsInChildren <MeshRenderer>(); skyApplier.anchorSky = Skies.Auto; WorldForces worldForces = gameObject.AddComponent <WorldForces>(); Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>(); worldForces.underwaterGravity = 0; worldForces.useRigidbody = rigidbody; VFXFabricating vfxFabricating = gameObject.AddComponent <VFXFabricating>(); vfxFabricating.localMinY = -3f; vfxFabricating.localMaxY = 3f; vfxFabricating.posOffset = new Vector3(0f, 0, 0f); vfxFabricating.eulerOffset = new Vector3(0f, 90f, -90f); vfxFabricating.scaleFactor = 1f; AncientSword component = gameObject.AddComponent <AncientSword>(); var knifePrefab = Resources.Load <GameObject>("WorldEntities/Tools/Knife").GetComponent <Knife>(); component.attackSound = Object.Instantiate(knifePrefab.attackSound, gameObject.transform); component.underwaterMissSound = Object.Instantiate(knifePrefab.underwaterMissSound, gameObject.transform); component.surfaceMissSound = Object.Instantiate(knifePrefab.surfaceMissSound, gameObject.transform); return(gameObject); }
public override GameObject GetGameObject() { SubRoot cyclops = Player.main.currentSub; if (cyclops != null && cyclops.isCyclops) { CyNukeManager mgr = MCUServices.Find.AuxCyclopsManager <CyNukeManager>(cyclops); if (mgr != null && mgr.TrackedBuildablesCount >= CyNukeChargeManager.MaxReactors) { ErrorMessage.AddMessage(OverLimitMessage()); return(null); } } var prefab = GameObject.Instantiate(_cyNukReactorPrefab); GameObject consoleModel = prefab.FindChild("model"); // Update sky applier SkyApplier skyApplier = prefab.AddComponent <SkyApplier>(); skyApplier.renderers = consoleModel.GetComponentsInChildren <MeshRenderer>(); skyApplier.anchorSky = Skies.Auto; //Add the constructible component to the prefab Constructable constructible = prefab.AddComponent <Constructable>(); constructible.allowedInBase = false; constructible.allowedInSub = true; // Only allowed in Cyclops constructible.allowedOutside = false; constructible.allowedOnCeiling = false; constructible.allowedOnGround = true; // Only on ground constructible.allowedOnWall = false; constructible.allowedOnConstructables = false; constructible.controlModelState = true; constructible.rotationEnabled = true; constructible.techType = TechTypeID; constructible.model = consoleModel; //Add the prefabIdentifier PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>(); prefabID.ClassId = main.ClassID; // Add the custom component CyNukeReactorMono auxConsole = prefab.AddComponent <CyNukeReactorMono>(); // Moved to the bottom to allow constructible to be added return(prefab); }
static void Postfix(SkyApplier __instance) { if (!__instance.initialized) { return; } uGUI_BuilderMenu.EnsureTechGroupTechTypeDataInitialized(); var techType = __instance.GetComponent <Constructable>()?.techType ?? TechType.None; if (uGUI_BuilderMenu.groupsTechTypes[1].Contains(techType)) { __instance.OnEnvironmentChanged(null); } }
public override GameObject GetGameObject() { try { var prefab = GameObject.Instantiate(DSSModelPrefab.ItemDisplayPrefab); var size = new Vector3(0.6082662f, 0.8234746f, 0.2771493f); var center = new Vector3(0f, -0.003837466f, 0.1747157f); 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 constructible var constructable = prefab.AddComponent <Constructable>(); constructable.allowedOutside = false; constructable.allowedInBase = true; constructable.allowedOnGround = false; constructable.allowedOnWall = true; constructable.rotationEnabled = false; constructable.allowedOnCeiling = false; constructable.allowedInSub = true; constructable.allowedOnConstructables = false; constructable.model = model; constructable.techType = TechType; PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>(); prefabID.ClassId = ClassID; prefab.AddComponent <TechTag>().type = TechType; prefab.AddComponent <DSSItemDisplayController>(); return(prefab); } catch (Exception e) { QuickLogger.Error(e.Message); return(null); } }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate(_Prefab); var meshRenderers = prefab.GetComponentsInChildren <MeshRenderer>(); //========== 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 constructible var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = true; constructable.allowedInBase = true; constructable.allowedOnCeiling = false; constructable.allowedOutside = false; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; var center = new Vector3(0.04392624f, 1.421124f, 0f); var size = new Vector3(2.401972f, 2.700523f, 2.280661f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); prefab.EnsureComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <FMOD_CustomLoopingEmitter>(); prefab.EnsureComponent <AMMiniMedBayController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
public override GameObject GetGameObject() { GameObject prefab = null; try { prefab = GameObject.Instantiate(_prefab); //========== 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; foreach (Renderer renderer in renderers) { renderer.material.shader = shader; } //========== Allows the building animation and material colors ==========// // Add constructable var constructable = prefab.EnsureComponent <Constructable>(); constructable.allowedOnWall = false; constructable.allowedOnGround = true; constructable.allowedInSub = false; constructable.allowedInBase = true; constructable.allowedOnCeiling = false; constructable.allowedOutside = false; constructable.model = prefab.FindChild("model"); constructable.techType = TechType; constructable.rotationEnabled = true; constructable.allowedOnConstructables = true; // Add large world entity ALLOWS YOU TO SAVE ON TERRAIN var lwe = prefab.AddComponent <LargeWorldEntity>(); lwe.cellLevel = LargeWorldEntity.CellLevel.Near; prefab.AddComponent <PrefabIdentifier>().ClassId = this.ClassID; prefab.AddComponent <HorizontalDuckController>(); } catch (Exception e) { QuickLogger.Error(e.Message); } return(prefab); }
public override GameObject GetGameObject() { // We'll use this for the actual model var consolePrefab = GameObject.Instantiate(Resources.Load <GameObject>("WorldEntities/Doodads/Debris/Wrecks/Decoration/submarine_engine_console_01_wide")); GameObject consoleWide = consolePrefab.FindChild("submarine_engine_console_01_wide"); GameObject consoleModel = consoleWide.FindChild("console"); // The LabTrashcan prefab was chosen because it is very similar in size, shape, and collision model to the upgrade console model var prefab = GameObject.Instantiate(CraftData.GetPrefabForTechType(TechType.LabTrashcan)); prefab.FindChild("discovery_trashcan_01_d").SetActive(false); // Turn off this model GameObject.DestroyImmediate(prefab.GetComponent <Trashcan>()); // Don't need this GameObject.DestroyImmediate(prefab.GetComponent <StorageContainer>()); // Don't need this // Add the custom component AuxCyUpgradeConsoleMono auxConsole = prefab.AddComponent <AuxCyUpgradeConsoleMono>(); // This is to tie the model to the prefab consoleModel.transform.SetParent(prefab.transform); consoleWide.SetActive(false); consolePrefab.SetActive(false); // Rotate to the correct orientation consoleModel.transform.rotation *= Quaternion.Euler(180f, 180f, 180f); // Update sky applier SkyApplier skyApplier = prefab.GetComponent <SkyApplier>(); skyApplier.renderers = consoleModel.GetComponentsInChildren <MeshRenderer>(); skyApplier.anchorSky = Skies.Auto; Constructable constructible = prefab.GetComponent <Constructable>(); constructible.allowedInBase = false; constructible.allowedInSub = true; // Only allowed in Cyclops constructible.allowedOutside = false; constructible.allowedOnCeiling = false; constructible.allowedOnGround = true; // Only on ground constructible.allowedOnWall = false; constructible.allowedOnConstructables = false; constructible.controlModelState = true; constructible.rotationEnabled = true; constructible.techType = this.TechType; constructible.model = consoleModel; return(prefab); }
public override GameObject GetGameObject() { try { var prefab = GameObject.Instantiate(_Prefab); GameObject consoleModel = prefab.FindChild("model"); // Update sky applier SkyApplier skyApplier = prefab.AddComponent <SkyApplier>(); skyApplier.renderers = consoleModel.GetComponentsInChildren <MeshRenderer>(); skyApplier.anchorSky = Skies.Auto; //Add the constructable component to the prefab Constructable constructable = prefab.AddComponent <Constructable>(); constructable.allowedInBase = true; // Only allowed in Base constructable.allowedInSub = false; // Not allowed in Cyclops constructable.allowedOutside = false; constructable.allowedOnCeiling = false; constructable.allowedOnGround = false; // Only on ground constructable.allowedOnWall = true; constructable.allowedOnConstructables = false; constructable.controlModelState = true; constructable.rotationEnabled = false; constructable.techType = this.TechType; constructable.model = consoleModel; var center = new Vector3(-0.006649137f, 0f, 0.1839597f); var size = new Vector3(2.706617f, 1.698831f, 0.3483825f); GameObjectHelpers.AddConstructableBounds(prefab, size, center); //Add the prefabIdentifier PrefabIdentifier prefabID = prefab.AddComponent <PrefabIdentifier>(); prefabID.ClassId = this.ClassID; prefab.EnsureComponent <AIPowerCellSocketAnimator>(); prefab.EnsureComponent <AIPowerCellSocketPowerManager>(); prefab.EnsureComponent <AIPowerCellSocketController>(); return(prefab); } catch (Exception e) { QuickLogger.Error <AIPowerCellSocketBuildable>(e.Message); return(null); } }
/// <summary> /// Adds and configures the following components on the gameobject passed by reference:<para/> /// - <see cref="Rigidbody"/> /// - <see cref="LargeWorldEntity"/> /// - <see cref="Renderer"/> /// - <see cref="SkyApplier"/> /// - <see cref="WorldForces"/> /// </summary> /// <param name="_object"></param> /// <param name="classId"></param> public static void AddBasicComponents(ref GameObject _object, string classId) { Rigidbody rb = _object.AddComponent <Rigidbody>(); _object.AddComponent <PrefabIdentifier>().ClassId = classId; _object.AddComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Near; Renderer rend = _object.GetComponentInChildren <Renderer>(); rend.material.shader = Shader.Find("MarmosetUBER"); SkyApplier applier = _object.AddComponent <SkyApplier>(); applier.renderers = new Renderer[] { rend }; applier.anchorSky = Skies.Auto; WorldForces forces = _object.AddComponent <WorldForces>(); forces.useRigidbody = rb; }