Example #1
0
 public ActionResult EditTagUnlinkGridViewPartialUpdate(TechTag item)
 {
     using (var db = new InnosixEntities())
     {
         var model = db.TechTag;
         if (ModelState.IsValid)
         {
             try
             {
                 var modelItem = model.FirstOrDefault(it => it.Id == item.Id);
                 if (modelItem != null)
                 {
                     UpdateModel(modelItem);
                     db.SaveChanges();
                 }
             }
             catch (Exception e)
             {
                 ViewData["EditError"] = e.Message;
             }
         }
         else
         {
             ViewData["EditError"] = "Please, correct all errors.";
         }
         return(PartialView("_EditTagUnlinkGridViewPartial", model.ToList()));
     }
 }
Example #2
0
        public static void Postfix(uGUI_SignInput __instance)
        {
            GameObject gameObject = __instance.gameObject.FindAncestor <PrefabIdentifier>().gameObject;
            NitroxId   id         = NitroxEntity.GetId(gameObject);
            TechTag    tag        = gameObject.GetComponent <TechTag>();

            switch (tag.type)
            {
            case TechType.SmallStorage:
                // In the water
                EntitySignMetadata entitySignMetadata = new(__instance.text, __instance.colorIndex, __instance.scaleIndex, __instance.elementsState, __instance.IsBackground());
                Resolve <Entities>().BroadcastMetadataUpdate(id, entitySignMetadata);
                break;

            case TechType.SmallLocker:
                // On wall
                SignMetadata signMetadata = new(__instance.text, __instance.colorIndex, __instance.scaleIndex, __instance.elementsState, __instance.IsBackground());
                Resolve <Building>().MetadataChanged(id, signMetadata);
                break;

            default:
                Log.Warn($"[{nameof(uGUI_SignInput_OnDeselect_Patch)}] no case planned for tech type {tag.type}");
                break;
            }
        }
Example #3
0
        // Token: 0x0600000D RID: 13 RVA: 0x00002290 File Offset: 0x00000490
        public GameObject GetHullPlate()
        {
            bool       flag = this.Texture == null;
            GameObject result;

            if (flag)
            {
                result = null;
            }
            else
            {
                GameObject   gameObject  = Resources.Load <GameObject>("Submarine/Build/DioramaHullPlate");
                GameObject   gameObject2 = UnityEngine.Object.Instantiate <GameObject>(gameObject);
                MeshRenderer component   = Radical.FindChild(gameObject2, "Icon").GetComponent <MeshRenderer>();
                component.material.mainTexture = this.Texture;
                PrefabIdentifier component2 = gameObject2.GetComponent <PrefabIdentifier>();
                component2.ClassId = this.Info.InternalName;
                TechTag component3 = gameObject2.GetComponent <TechTag>();
                component3.type = this.TechType;
                Constructable component4 = gameObject2.GetComponent <Constructable>();
                component4.techType = this.TechType;
                result = gameObject2;
            }
            return(result);
        }
Example #4
0
        public ActionResult AcceptAdditionalTag(string tagName)
        {
            using (var db = new InnosixEntities())
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var tags = db.TechTag;

                        if (tags.Any(t => t.TagName == tagName))
                        {
                            ViewBag.Message = $"Tag with name: {tagName}, already exists";
                            return(View("AdditionalTags"));
                        }

                        var newTag = new TechTag
                        {
                            TagName = tagName
                        };

                        db.TechTag.Add(newTag);
                        db.SaveChanges();

                        var tcsWithAddTag = db.TCBasicInfo.Include(t => t.TCTechnology)
                                            .Where(t => t.TCTechnology.AdditionalTechTags.Contains(tagName))
                                            .ToList();

                        foreach (var tc in tcsWithAddTag)
                        {
                            var tagList = tc.TCTechnology.AdditionalTechTags.Split(',').Select(t => t.Trim()).ToList();
                            tagList.Remove(tagName);
                            tc.TCTechnology.AdditionalTechTags = string.Join(",", tagList);

                            db.Entry(tc).State = EntityState.Modified;
                            var newTagId = db.TechTag.First(t => t.TagName == tagName).Id;
                            tc.TechTagToTC.Add(new TechTagToTC {
                                TechTagId = newTagId
                            });
                            db.SaveChanges();
                        }

                        transaction.Commit();
                    }
                    catch (Exception ex)
                    {
                        ViewData["EditError"] = ex.Message;
                        transaction.Rollback();
                    }

                    ViewBag.Message = $"Tag with name: {tagName}, added";
                    return(View("AdditionalTags"));
                }
        }
Example #5
0
        public ActionResult UpdateTag(TechTag tag)
        {
            if (!ModelState.IsValid)
            {
                return(View("Index"));
            }

            using (var db = new InnosixEntities())
            {
                db.Entry(tag).State = EntityState.Modified;
                db.SaveChanges();
            }

            return(RedirectToAction("Index"));
        }
Example #6
0
        public void OnProtoDeserialize(ProtobufSerializer serializer)
        {
            Constructable constructable = GetComponent <Constructable>();

            if (constructable != null)
            {
                constructable.techType = techType;
            }

            TechTag techTag = GetComponent <TechTag>();

            if (techTag != null)
            {
                techTag.type = techType;
            }
        }
Example #7
0
        public override GameObject GetGameObject()
        {
            // Get the ElectricalDefense module prefab and instantiate it
            string     path   = "WorldEntities/Tools/SeamothElectricalDefense";
            GameObject prefab = Resources.Load <GameObject>(path);
            GameObject obj    = GameObject.Instantiate(prefab);

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

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

            return(obj);
        }
Example #8
0
        private static void CreatureStart_Postfix(Creature __instance)
        {
            if (usedCreatures.Contains(__instance) || FishHandler.fishTechTypes.Count == 0)
            {
                return;
            }

            TechTag tag = __instance.GetComponent <TechTag>();

            if (tag && FishHandler.fishTechTypes.Contains(tag.type))
            {
                return;
            }

            if (Random.value < 0.1f)
            {
                CoroutineHost.StartCoroutine(SpawnCustomFish(__instance));
            }
        }
        public static InventoryItem SpawnCyclopsModule(TechType techTypeID)
        {
            GameObject gameObject;

            if (techTypeID < TechType.Databox) // This is a standard upgrade module
            {
                gameObject = GameObject.Instantiate(CraftData.GetPrefabForTechType(techTypeID));
            }
            else if (ModulesEnabled) // Safety check in case these are disabled in the config
            {
                if (!CyclopsModulesByTechType.ContainsKey(techTypeID))
                {
                    return(null); // error condition
                }
                // Get the CyclopsModule child class instance associated to this TechType
                CyclopsModule cyclopsModule = CyclopsModulesByTechType[techTypeID];

                // Instantiate a new prefab of the appripriate template TechType
                gameObject = cyclopsModule.GetGameObject();

                // Set the TechType value on the TechTag
                TechTag tag = gameObject.GetComponent <TechTag>();
                if (tag != null)
                {
                    tag.type = techTypeID;
                }
                else // Add if needed since this is how these are identified throughout the mod
                {
                    gameObject.AddComponent <TechTag>().type = techTypeID;
                }

                // Set the ClassId
                gameObject.GetComponent <PrefabIdentifier>().ClassId = cyclopsModule.NameID;
            }
            else
            {
                return(null); // error condition
            }

            Pickupable pickupable = gameObject.GetComponent <Pickupable>().Pickup(false);

            return(new InventoryItem(pickupable));
        }
Example #10
0
        private static void CreatureStart_Postfix(Creature __instance)
        {
            if (usedCreatures.Contains(__instance) || FishHandler.fishTechTypes.Count == 0)
            {
                return;
            }

            TechTag tag = __instance.GetComponent <TechTag>();

            if (tag && FishHandler.fishTechTypes.Contains(tag.type))
            {
                return;
            }

            if (Random.value < 0.1f)
            {
                int      randomIndex = Random.Range(0, FishHandler.fishTechTypes.Count);
                TechType randomFish  = FishHandler.fishTechTypes[randomIndex];
#if SUBNAUTICA_EXP
                GameObject fish = null;
#else
                GameObject fish = CraftData.InstantiateFromPrefab(randomFish);
#endif
                // Deletes the fish if it is a ground creature spawned in water
                if (fish.GetComponent <WalkOnGround>() && !__instance.GetComponent <WalkOnGround>())
                {
                    GameObject.Destroy(fish);
                    return;
                }

                // Deletes the fish if it is a water creature spawned on ground
                if (!fish.GetComponent <WalkOnGround>() && __instance.GetComponent <WalkOnGround>())
                {
                    GameObject.Destroy(fish);
                    return;
                }

                fish.transform.position = __instance.transform.position;

                usedCreatures.Add(__instance);
            }
        }
Example #11
0
        public void Awake()
        {
            //Debug.Log($"Spawning fragment at position: {transform.position}");

            signal = Instantiate(Resources.Load <GameObject>("worldentities/environment/generated/signal"));

            techTag = gameObject.GetComponent <TechTag>();

            SignalPing signalPing = signal.GetComponent <SignalPing>();

            signalPing.enabled = false;

            pingInstance = signal.GetComponent <PingInstance>();

            pingInstance.displayPingInManager = true;
            pingInstance.pingType             = PingType.Signal;
            pingInstance.visible = true;
            pingInstance.minDist = 5;
            pingInstance.maxDist = 10;
            pingInstance.origin  = transform;
        }
Example #12
0
        public static void Postfix(Creature __instance)
        {
            if (usedCreatures.Contains(__instance) || fishTechTypes.Count == 0)
            {
                return;
            }
            TechTag tag = __instance.GetComponent <TechTag>();

            if (tag)
            {
                if (fishTechTypes.Contains(tag.type))
                {
                    return;
                }
            }
            if (Random.value < 0.1f)
            {
                Console.WriteLine($"[FishFramework] Selecting fish out of {fishTechTypes.Count} total types");
                int      randomIndex = Random.Range(0, fishTechTypes.Count);
                TechType randomFish  = fishTechTypes[randomIndex];

                GameObject fish = CraftData.InstantiateFromPrefab(randomFish);
                // Deletes the fish if it is a ground creature spawned in water
                if (fish.GetComponent <WalkOnGround>() && !__instance.GetComponent <WalkOnGround>())
                {
                    GameObject.Destroy(fish);
                    return;
                }
                // Deletes the fish if it is a water creature spawned on ground
                if (!fish.GetComponent <WalkOnGround>() && __instance.GetComponent <WalkOnGround>())
                {
                    GameObject.Destroy(fish);
                    return;
                }
                fish.transform.position = __instance.transform.position;

                usedCreatures.Add(__instance);
            }
        }
Example #13
0
        public override GameObject GetGameObject()
        {
            var BaseDrillModule = new GameObject
            {
                name = NameID
            };

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

            prefabId.ClassId = NameID;
            prefabId.name    = FriendlyName;

            // Add tech tag
            TechTag techTag = BaseDrillModule.AddComponent <TechTag>();

            techTag.type = this.TechType;


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

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

            constructible.model = BasedrillMesh;
            BasedrillMesh.AddComponent <BaseDrillMesh>();
            BasedrillMesh.transform.SetParent(BaseDrillModule.transform);
            return(BaseDrillModule);
        }
Example #14
0
        public ActionResult CreateTag(string tagName)
        {
            using (var db = new InnosixEntities())
            {
                var tags = db.TechTag;
                if (ModelState.IsValid)
                {
                    try
                    {
                        var tag = new TechTag
                        {
                            TagName = tagName
                        };

                        if (tags.Any(t => t.TagName == tagName))
                        {
                            ViewBag.Message = $"Tag with name {tagName} already exists";
                            return(View("Index"));
                        }

                        tags.Add(tag);
                        db.SaveChanges();

                        ViewBag.Message = $"Tag with name {tagName} created succesfully";
                    }
                    catch (Exception ex)
                    {
                        ViewData["EditError"] = ex.Message;
                    }
                }
                else
                {
                    ViewData["EditError"] = "Please, correct all errors.";
                }

                return(View("Index"));
            }
        }
Example #15
0
        private IEnumerator Setup()
        {
            Log.LogDebug($"RegeneratingPowerSource.Setup() start");
            int i = 0;

            while (source == null || sourceType == TechType.None)
            {
                if (source == null)
                {
                    source = this.gameObject?.GetComponent <Battery>();
                }
                if (sourceType == TechType.None)
                {
                    TechTag tt = this.gameObject?.GetComponent <TechTag>();
                    sourceType = (tt != null ? tt.type : TechType.None);
                }
                Log.LogDebug($"RegeneratingPowerSource: source = {(source != null ? source.GetInstanceID() : "null")}, sourceType = {sourceType.AsString()}, attempt {++i}");
                yield return(new WaitForEndOfFrame());
            }

            base.InvokeRepeating("UpdatePower", RegenerationInterval, RegenerationInterval);
            yield break;
        }
Example #16
0
 public ActionResult EditTagUnlinkGridViewPartialAddNew(TechTag item)
 {
     using (var db = new InnosixEntities())
     {
         var model = db.TechTag;
         if (ModelState.IsValid)
         {
             try
             {
                 model.Add(item);
                 db.SaveChanges();
             }
             catch (Exception e)
             {
                 ViewData["EditError"] = e.Message;
             }
         }
         else
         {
             ViewData["EditError"] = "Please, correct all errors.";
         }
         return(PartialView("_EditTagUnlinkGridViewPartial", model.ToList()));
     }
 }
Example #17
0
        public override GameObject GetGameObject()
        {
            // Instantiate CyclopsFabricator object
            var fabricatorPrefab = GameObject.Instantiate(Fabricator_Decorations.OriginalFabricator);

            // Update prefab name
            fabricatorPrefab.name = this.ClassID;

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

            if (prefabId == null)
            {
                prefabId = fabricatorPrefab.AddComponent <PrefabIdentifier>();
            }
            prefabId.ClassId = this.ClassID;
            prefabId.name    = LanguageHelper.GetFriendlyWord("DecorationsFabricatorName");

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

            if (techTag == null)
            {
                techTag = fabricatorPrefab.AddComponent <TechTag>();
            }
            techTag.type = this.TechType;

            // Adjust position
            GameObject model = fabricatorPrefab.FindChild("submarine_fabricator_01");

            model.transform.localPosition = new Vector3(model.transform.localPosition.x, model.transform.localPosition.y, model.transform.localPosition.z + 0.035f);

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

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

            // Associate power relay
            GhostCrafter ghost      = fabricator.GetComponent <GhostCrafter>();
            var          powerRelay = new PowerRelay();
            FieldInfo    fieldInfo  = typeof(GhostCrafter).GetField("powerRelay", BindingFlags.NonPublic | BindingFlags.Instance);

            fieldInfo.SetValue(ghost, powerRelay); // This isn't correct, but nothing else seems to work.

            // Set where this can be built.
            Constructable constructible = fabricatorPrefab.GetComponent <Constructable>();

            constructible.allowedInBase           = true;
            constructible.allowedInSub            = true;
            constructible.allowedOutside          = ConfigSwitcher.AllowBuildOutside;
            constructible.allowedOnCeiling        = false;
            constructible.allowedOnGround         = false;
            constructible.allowedOnConstructables = false;
            constructible.controlModelState       = true;
            constructible.techType = this.TechType;

            // Set the custom texture
            SkinnedMeshRenderer skinnedMeshRenderer = fabricatorPrefab.GetComponentInChildren <SkinnedMeshRenderer>();

            skinnedMeshRenderer.material.mainTexture = this.ColoredTexture;

            return(fabricatorPrefab);
        }
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

            // Update TechTag
            TechTag techTag = prefab.GetComponent <TechTag>();

            techTag.type = this.TechType;

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

            prefabId.ClassId = this.ClassID;

            // Update StorageContainer
            StorageContainer sc = prefab.GetComponent <StorageContainer>();

            sc.height = 2;

            // Update Planter
            var planter = prefab.GetComponent <Planter>();

            if (planter != null)
            {
                planter.isIndoor    = false;
                planter.environment = Planter.PlantEnvironment.Water;
            }

            // Update constructable
            Constructable constructable = prefab.GetComponent <Constructable>();

            constructable.allowedOutside   = true;
            constructable.allowedInBase    = ConfigSwitcher.AllowOutdoorLongPlanterInside;
            constructable.allowedInSub     = ConfigSwitcher.AllowOutdoorLongPlanterInside;
            constructable.placeMinDistance = 0.8f;

            // Update constructable bounds
            ConstructableBounds bounds = prefab.GetComponent <ConstructableBounds>();

            bounds.bounds.extents  = new Vector3(bounds.bounds.extents.x * 0.3f, bounds.bounds.extents.y * 0.4f, bounds.bounds.extents.z);
            bounds.bounds.position = new Vector3(bounds.bounds.position.x + 0.3f, bounds.bounds.position.y * 0.4f, bounds.bounds.position.z);

            float xPad             = 1.22f; //0.5f;
            float yPad             = -0.25f;
            float scaleRatio       = 0.4f;
            float heightScaleRatio = 0.5f;

            // Update box collider
            GameObject  objectTrigger  = prefab.FindChild("collider");
            BoxCollider objectCollider = objectTrigger.GetComponent <BoxCollider>();

            objectCollider.size = new Vector3(objectCollider.size.x * scaleRatio, objectCollider.size.y * heightScaleRatio, objectCollider.size.z);
            //objectCollider.center = new Vector3(objectCollider.center.x + pad, objectCollider.center.y, objectCollider.center.z);

            // Update model
            GameObject model = prefab.FindChild("model");

            model.transform.localScale = new Vector3(model.transform.localScale.x * scaleRatio, model.transform.localScale.y * heightScaleRatio, model.transform.localScale.z);
            //model.transform.localPosition = new Vector3(model.transform.localPosition.x + pad, model.transform.localPosition.y, model.transform.localPosition.z);
            //model.transform.localRotation = new Quaternion(model.transform.localRotation.x, model.transform.localRotation.y + 20.0f, model.transform.localRotation.z, model.transform.localRotation.w);

            GameObject slots = prefab.FindChild("slots");

            foreach (Transform tr in slots.transform)
            {
                tr.localPosition = new Vector3(tr.localPosition.x + xPad, tr.localPosition.y + yPad, tr.localPosition.z);
            }
            GameObject slotsSmall = prefab.FindChild("slots_small");

            foreach (Transform tr in slotsSmall.transform)
            {
                tr.localPosition = new Vector3(tr.localPosition.x + xPad, tr.localPosition.y + yPad, tr.localPosition.z);
            }

            // 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);
        }
Example #19
0
        public static void Patch()
        {
            Debug.Log("Patching base clocks");
            QPatch.harmony = HarmonyInstance.Create("com.baseclocks.mod");
            BaseClocksConfig.Load();
            OptionsPanelHandler.RegisterModOptions(new BaseClocksModOptions());

            AssetBundle assetBundle = AssetBundle.LoadFromFile("./QMods/BaseClocks/clocks");

            s_ModPath = "./QMods/BaseClocks";

            GameObject sign     = Resources.Load <GameObject>("Submarine/Build/Sign");
            Font       signFont = sign.GetComponentInChildren <Text>(true).font;

            Shader   marmosetUber    = Shader.Find("MarmosetUBER");
            Material marmosetUberMat = new Material(marmosetUber);

#if LOG
            string desktopPath = System.Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            string fullpath    = string.Concat(desktopPath, "/MarmosetUBERProperties.txt");

            using (System.IO.TextWriter tw = System.IO.File.CreateText(fullpath))
            {
                PrintShaderProperty("_Color", marmosetUberMat, tw);
                PrintShaderProperty("_ReflectColor", marmosetUberMat, tw);
                tw.Line();

                PrintShaderProperty("_Cube", marmosetUberMat, tw);
                PrintShaderProperty("_MainTex", marmosetUberMat, tw);
                tw.Line();

                PrintShaderProperty("_MarmoSpecEnum", marmosetUberMat, tw);
                tw.Line();

                PrintShaderProperty("_Roughness", marmosetUberMat, tw);
                PrintShaderProperty("_Glossiness", marmosetUberMat, tw);
                PrintShaderProperty("_Gloss", marmosetUberMat, tw);
                PrintShaderProperty("_Metal", marmosetUberMat, tw);
                PrintShaderProperty("_Metallic", marmosetUberMat, tw);
                PrintShaderProperty("_Metalness", marmosetUberMat, tw);
                PrintShaderProperty("_Metallicness", marmosetUberMat, tw);
                PrintShaderProperty("_ReflectColor", marmosetUberMat, tw);
                PrintShaderProperty("_Reflectivity", marmosetUberMat, tw);
                tw.Line();

                PrintShaderProperty("_Spec", marmosetUberMat, tw);
                PrintShaderProperty("_SpecTex", marmosetUberMat, tw);
                PrintShaderProperty("_SpecColor", marmosetUberMat, tw);
                PrintShaderProperty("_SpecColor2", marmosetUberMat, tw);
                PrintShaderProperty("_SpecColor3", marmosetUberMat, tw);
                PrintShaderProperty("_SpecCubeIBL", marmosetUberMat, tw);
                PrintShaderProperty("_SpecInt", marmosetUberMat, tw);
                PrintShaderProperty("_SpecGlossMap", marmosetUberMat, tw);
                PrintShaderProperty("_Specular", marmosetUberMat, tw);
                PrintShaderProperty("_Shininess", marmosetUberMat, tw);
                PrintShaderProperty("_SpecularAmount", marmosetUberMat, tw);
                tw.Line();

                PrintShaderProperty("_EnableGlow", marmosetUberMat, tw);
                PrintShaderProperty("_SIGMap", marmosetUberMat, tw);

                PrintShaderProperty("_AffectedByDayNightCycle", marmosetUberMat, tw);
                tw.Line();

                PrintShaderProperty("_SelfIllumination", marmosetUberMat, tw);
                PrintShaderProperty("_EnableGlow", marmosetUberMat, tw);
                PrintShaderProperty("_GlowColor", marmosetUberMat, tw);
                PrintShaderProperty("_Illum", marmosetUberMat, tw);
                PrintShaderProperty("_GlowStrength", marmosetUberMat, tw);
                PrintShaderProperty("_GlowStrengthNight", marmosetUberMat, tw);

                tw.Line();

                PrintShaderProperty("_Fresnel", marmosetUberMat, tw);
                PrintShaderProperty("_FresnelFade", marmosetUberMat, tw);

                tw.Line();

                PrintShaderProperty("_BaseLight", marmosetUberMat, tw);
                PrintShaderProperty("_AO", marmosetUberMat, tw);
                tw.Close();
            }
#endif

            //Analogue clock
            GameObject analogueBaseClock = assetBundle.LoadAsset <GameObject>("Actual Time Analog Clock UGUI");

            SMLHelper.V2.Utility.PrefabUtils.AddBasicComponents(ref analogueBaseClock, k_ClassID);

            ReplaceMaterialShader(analogueBaseClock, marmosetUber, true, true);

            ApplySkyApplier(analogueBaseClock);

            Constructable constructable = analogueBaseClock.AddComponent <Constructable>();

            constructable.allowedOnWall   = true;
            constructable.allowedInSub    = true;
            constructable.allowedOnGround = false;
            constructable.allowedOutside  = false;
            constructable.model           = analogueBaseClock.transform.GetChild(0).gameObject;

            DestroyPhysicsComponents(analogueBaseClock);

            ConstructableBounds constructableBounds = analogueBaseClock.AddComponent <ConstructableBounds>();

            TechTag           techTag = analogueBaseClock.AddComponent <TechTag>();
            BaseAnalogueClock actualTimeAnalogueClock = analogueBaseClock.AddComponent <BaseAnalogueClock>();

            actualTimeAnalogueClock.HourHand   = analogueBaseClock.transform.GetChild(1).GetChild(1);
            actualTimeAnalogueClock.MinuteHand = analogueBaseClock.transform.GetChild(1).GetChild(2);
            actualTimeAnalogueClock.SecondHand = analogueBaseClock.transform.GetChild(1).GetChild(3);

            TechData techData = new TechData();
            techData.Ingredients.Add(new Ingredient(TechType.Titanium, 1));
            techData.Ingredients.Add(new Ingredient(TechType.CopperWire, 1));

            BaseClockBuildable analogueClockBuildable = new BaseClockBuildable(k_ClassID, "Analogue Clock", "An Analogue clock.", "analogueClock.png", analogueBaseClock.gameObject, techData);
            analogueClockBuildable.Patch();
            Debug.Log("Patched analogueClockBuildable");

            //Digital clock
            GameObject digitalBaseClock = assetBundle.LoadAsset <GameObject>("Actual Time Digital Clock UGUI");

            SMLHelper.V2.Utility.PrefabUtils.AddBasicComponents(ref digitalBaseClock, k_ClassID_Digital);

            ReplaceMaterialShader(digitalBaseClock, marmosetUber);

            ApplySkyApplier(digitalBaseClock);

            constructable = digitalBaseClock.AddComponent <Constructable>();

            constructable.allowedOnWall   = true;
            constructable.allowedInSub    = true;
            constructable.allowedOnGround = false;
            constructable.allowedOutside  = false;
            constructable.model           = digitalBaseClock.transform.GetChild(0).gameObject;

            DestroyPhysicsComponents(digitalBaseClock);

            constructableBounds = digitalBaseClock.AddComponent <ConstructableBounds>();

            techTag = digitalBaseClock.AddComponent <TechTag>();

            BaseDigitalClock digitalClock = digitalBaseClock.AddComponent <BaseDigitalClock>();
            digitalClock.Text       = digitalBaseClock.transform.GetChild(1).GetChild(0).GetComponent <Text>();
            digitalClock.PeriodText = digitalBaseClock.transform.GetChild(1).GetChild(1).GetComponent <Text>();
            digitalClock.SetFont(signFont);

            techData = new TechData();
            techData.Ingredients.Add(new Ingredient(TechType.Titanium, 1));
            techData.Ingredients.Add(new Ingredient(TechType.CopperWire, 1));

            LanguageHandler.SetLanguageLine(BaseClock.k_SetGameTime, "Set to Normal Time");
            LanguageHandler.SetLanguageLine(BaseClock.k_SetSystemTime, "Set to System Time");

            BaseClockBuildable digitalClockBuildable = new BaseClockBuildable(k_ClassID_Digital, "Digital Clock", "A Digital clock.", "digitalClock.png", digitalClock.gameObject, techData);
            digitalClockBuildable.Patch();
            Debug.Log("Patched digitalClockBuildable");

#if INCLUDE_TEST_BUILDABLES
            //Material balls.
            techType = TechTypePatcher.AddTechType(k_ClassID_Materials, "Material Balls", "Material Test");

            GameObject materialBalls = assetBundle.LoadAsset <GameObject>("Material Balls");

            Utility.AddBasicComponents(ref materialBalls, k_ClassID_Materials);
            DestroyPhysicsComponents(materialBalls);

            constructable = materialBalls.AddComponent <Constructable>();

            constructable.allowedOnWall           = false;
            constructable.allowedInSub            = true;
            constructable.allowedOnGround         = true;
            constructable.allowedOnCeiling        = false;
            constructable.allowedOnConstructables = false;
            constructable.allowedOutside          = true;
            constructable.model = materialBalls.transform.GetChild(0).gameObject;

            constructable.name = "Material Balls";

            constructableBounds = materialBalls.AddComponent <ConstructableBounds>();

            techTag      = materialBalls.AddComponent <TechTag>();
            techTag.type = techType;

            ReplaceMaterialShader(materialBalls, marmosetUber, false, true);
            AddSkyApplier(materialBalls);

            materialBalls.AddComponent <MaterialLogger>();

            CustomPrefabHandler.customPrefabs.Add(new CustomPrefab(k_ClassID_Materials, "Submarine/Build/MaterialBalls", materialBalls, techType));

            techDataHelper = new TechDataHelper();
            techDataHelper._ingredients = new List <IngredientHelper>();
            techDataHelper._ingredients.Add(new IngredientHelper(TechType.Titanium, 1));
            techDataHelper._techType = techType;

            CraftDataPatcher.customTechData.Add(techType, techDataHelper);
            CraftDataPatcher.customBuildables.Add(techType);

            dictionary[TechGroup.InteriorModules][TechCategory.InteriorModule].Add(techType);

            //Texture test.
            techType = TechTypePatcher.AddTechType(k_ClassID_TextureTest, "Texture Test", "Texture Test");

            GameObject textureTest = assetBundle.LoadAsset <GameObject>("Texture Test");

            Utility.AddBasicComponents(ref textureTest, k_ClassID_TextureTest);
            DestroyPhysicsComponents(textureTest);

            constructable = textureTest.AddComponent <Constructable>();

            constructable.allowedOnWall           = true;
            constructable.allowedInSub            = true;
            constructable.allowedOnGround         = false;
            constructable.allowedOnCeiling        = false;
            constructable.allowedOnConstructables = false;
            constructable.allowedOutside          = false;
            constructable.model = textureTest.transform.GetChild(0).gameObject;

            constructable.name = "Texture Test";

            constructableBounds = textureTest.AddComponent <ConstructableBounds>();

            techTag      = textureTest.AddComponent <TechTag>();
            techTag.type = techType;

            ReplaceMaterialShader(textureTest, marmosetUber, true, true);

            AddSkyApplier(textureTest);

            textureTest.AddComponent <MaterialLogger>();

            CustomPrefabHandler.customPrefabs.Add(new CustomPrefab(k_ClassID_TextureTest, "Submarine/Build/TextureTest", textureTest, techType));

            techDataHelper = new TechDataHelper();
            techDataHelper._ingredients = new List <IngredientHelper>();
            techDataHelper._ingredients.Add(new IngredientHelper(TechType.Titanium, 1));
            techDataHelper._techType = techType;

            CraftDataPatcher.customTechData.Add(techType, techDataHelper);
            CraftDataPatcher.customBuildables.Add(techType);

            dictionary[TechGroup.InteriorModules][TechCategory.InteriorModule].Add(techType);
#endif
#if LOG
            //Print small locker objects and components to desktop.
            fullpath = string.Concat(desktopPath, "/FabricatorComponents.txt");

            GameObject fabricator     = Resources.Load <GameObject>("Submarine/Build/Fabricator");
            GameObject medicalCabinet = Resources.Load <GameObject>("Submarine/Build/MedicalCabinet");

            if (fabricator != null)
            {
                using (System.IO.TextWriter tw = System.IO.File.CreateText(fullpath))
                {
                    PrintComponents(fabricator, tw);
                    tw.Close();
                }
                MaterialLogger.LogMaterialsToDesktop(fabricator);
            }

            fullpath = string.Concat(desktopPath, "/SignComponents.txt");

            if (sign != null)
            {
                using (System.IO.TextWriter tw = System.IO.File.CreateText(fullpath))
                {
                    PrintComponents(sign, tw);
                    tw.Close();
                }
            }

            fullpath = string.Concat(desktopPath, "/MedicalCabinetComponents.txt");
            if (medicalCabinet != null)
            {
                using (System.IO.TextWriter tw = System.IO.File.CreateText(fullpath))
                {
                    PrintComponents(medicalCabinet, tw);
                    tw.Close();
                }
                MaterialLogger.LogMaterialsToDesktop(medicalCabinet);
            }

            MaterialLogger.LogMaterialsToDesktop(analogueBaseClock);


            Resources.UnloadAsset(sign);
            Resources.UnloadAsset(fabricator);
            Resources.UnloadAsset(medicalCabinet);
            MonoBehaviour.Destroy(marmosetUberMat);
#endif
        }
Example #20
0
        private GameObject PreProcessPrefab(GameObject prefab)
        {
            Constructable constructible = null;
            GhostCrafter  crafter;

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

            case Models.Workbench:
                crafter = prefab.GetComponent <Workbench>();
                break;

#if SUBNAUTICA
            case Models.MoonPool:
                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:
                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.EnsureComponent <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);
        }
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

            // Update TechTag
            TechTag techTag = prefab.GetComponent <TechTag>();

            techTag.type = this.TechType;

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

            prefabId.ClassId = this.ClassID;

            // Update StorageContainer
            StorageContainer sc = prefab.GetComponent <StorageContainer>();

            sc.height = 2;

            // Update constructable
            if (ConfigSwitcher.AllowIndoorLongPlanterOutside)
            {
                Constructable constructable = prefab.GetComponent <Constructable>();
                constructable.allowedOutside = true;
            }

            // Update constructable bounds
            ConstructableBounds bounds = prefab.GetComponent <ConstructableBounds>();

            bounds.bounds.extents  = new Vector3(bounds.bounds.extents.x * 0.5f, bounds.bounds.extents.y, bounds.bounds.extents.z);
            bounds.bounds.position = new Vector3(bounds.bounds.position.x + 0.5f, bounds.bounds.position.y, bounds.bounds.position.z);

            // Update box collider
            GameObject  builderTrigger  = prefab.FindChild("Builder Trigger");
            GameObject  objectTrigger   = prefab.FindChild("Collider");
            BoxCollider builderCollider = builderTrigger.GetComponent <BoxCollider>();
            BoxCollider objectCollider  = objectTrigger.GetComponent <BoxCollider>();

            builderCollider.size   = new Vector3(builderCollider.size.x * 0.5f, builderCollider.size.y, builderCollider.size.z);
            objectCollider.size    = new Vector3(objectCollider.size.x * 0.5f, objectCollider.size.y, objectCollider.size.z);
            builderCollider.center = new Vector3(builderCollider.center.x + 0.5f, builderCollider.center.y, builderCollider.center.z);
            objectCollider.center  = new Vector3(objectCollider.center.x + 0.5f, objectCollider.center.y, objectCollider.center.z);

            // Update model
            GameObject model = prefab.FindChild("model");

            model.transform.localScale    = new Vector3(model.transform.localScale.x * 0.5f, model.transform.localScale.y, model.transform.localScale.z);
            model.transform.localPosition = new Vector3(model.transform.localPosition.x + 0.5f, model.transform.localPosition.y, model.transform.localPosition.z);
            model.transform.localRotation = new Quaternion(model.transform.localRotation.x, model.transform.localRotation.y + 20.0f, model.transform.localRotation.z, model.transform.localRotation.w);

            // Update grass
            GameObject tray   = model.FindChild("Base_interior_Planter_Tray_01");
            GameObject grass1 = tray.FindChild("pot_generic_plant_03");
            GameObject grass2 = tray.FindChild("pot_generic_plant_04");

            grass1.GetComponent <MeshRenderer>().enabled = false;
            grass2.GetComponent <MeshRenderer>().enabled = false;

            // Translate prefab
            //prefab.transform.localPosition = new Vector3(prefab.transform.localPosition.x + 0.6f, prefab.transform.localPosition.y, prefab.transform.localPosition.z);

            // Update sky applier
            PrefabsHelper.SetDefaultSkyApplier(prefab);

            return(prefab);
        }
Example #22
0
        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    = this.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
            GhostCrafter fabricator = prefab.GetComponent <Fabricator>();

            fabricator.craftTree    = this.TreeTypeID;
            fabricator.handOverText = Language.main.Get(HandOverKey);

            // 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/CyclopsNuclearUpgrades/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.powerRelay = powerRelay;

            return(prefab);
        }
Example #23
0
        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);
        }
Example #24
0
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);
            GameObject model  = prefab.FindChild("discovery_lab_cart_01");

            prefab.name = this.ClassID;

            // Set TechTag
            TechTag techTag = prefab.AddComponent <TechTag>();

            techTag.type = this.TechType;

            // Update prefab identifier
            PrefabIdentifier prefabId = prefab.GetComponent <PrefabIdentifier>();

            prefabId.ClassId = this.ClassID;

            GameObject cube = prefab.FindChild("Cube");

            GameObject.DestroyImmediate(cube);

            // Remove rigid body
            Rigidbody rb = prefab.GetComponent <Rigidbody>();

            GameObject.DestroyImmediate(rb);

            // Add box collider
            BoxCollider collider = model.AddComponent <BoxCollider>();

            collider.size   = new Vector3(1.026103f, 0.6288151f, 0.91f); // -90X: Y<=>Z
            collider.center = new Vector3(0.005f, 0.001f, 0.455f);       // -90X: Y<=>Z

            // Update large world entity
            LargeWorldEntity lwe = prefab.GetComponent <LargeWorldEntity>();

            lwe.cellLevel = LargeWorldEntity.CellLevel.Near;

            // Get renderers
            Renderer[] rend = prefab.GetComponentsInChildren <Renderer>();

            if (!ConfigSwitcher.LabCart_asBuildable)
            {
                // Set proper shaders for crafting animation
                foreach (Renderer renderer in rend)
                {
                    renderer.material.shader = Shader.Find("MarmosetUBER");
                }

                // We can pick this item
                Pickupable pickupable = prefab.AddComponent <Pickupable>();
                pickupable.isPickupable = true;
                pickupable.randomizeRotationWhenDropped = true;

                // We can place this item
                prefab.AddComponent <CustomPlaceToolController>();
                var placeTool = prefab.AddComponent <GenericPlaceTool>();
                placeTool.allowedInBase          = true;
                placeTool.allowedOnBase          = true;
                placeTool.allowedOnCeiling       = false;
                placeTool.allowedOnConstructable = false;
                placeTool.allowedOnGround        = true;
                placeTool.allowedOnRigidBody     = true;
                placeTool.allowedOnWalls         = false;
                placeTool.allowedOutside         = ConfigSwitcher.AllowPlaceOutside;
                placeTool.rotationEnabled        = true;
                placeTool.enabled              = true;
                placeTool.hasAnimations        = false;
                placeTool.hasBashAnimation     = false;
                placeTool.hasFirstUseAnimation = false;
                placeTool.mainCollider         = collider;
                placeTool.pickupable           = pickupable;

                // Add fabricating animation
                VFXFabricating fabricating = model.AddComponent <VFXFabricating>();
                fabricating.localMinY   = -0.1f;
                fabricating.localMaxY   = 0.9f;
                fabricating.posOffset   = new Vector3(0f, 0f, 0.04f);
                fabricating.eulerOffset = new Vector3(-90f, 0f, 0f);
                fabricating.scaleFactor = 0.5f;
            }
            else
            {
                // Set as constructible
                Constructable constructible = prefab.AddComponent <Constructable>();
                constructible.techType                = this.TechType;
                constructible.allowedOnWall           = false;
                constructible.allowedInBase           = true;
                constructible.allowedInSub            = true;
                constructible.allowedOutside          = ConfigSwitcher.AllowBuildOutside;
                constructible.allowedOnCeiling        = false;
                constructible.allowedOnGround         = true;
                constructible.allowedOnConstructables = false;
                constructible.deconstructionAllowed   = true;
                constructible.controlModelState       = true;
                constructible.model = model;

                // Add constructible bounds
                ConstructableBounds bounds = prefab.AddComponent <ConstructableBounds>();
            }

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

            applier.anchorSky = Skies.Auto;
            applier.renderers = rend;

            return(prefab);
        }
        public override GameObject GetGameObject()
        {
            // Instantiate CyclopsFabricator object
            var cyclopsFabPrefab = GameObject.Instantiate(Resources.Load <GameObject>("Submarine/Build/CyclopsFabricator"));

            // Retrieve sub game objects
            GameObject cyclopsFabLight = cyclopsFabPrefab.FindChild("fabricatorLight");
            GameObject cyclopsFabModel = cyclopsFabPrefab.FindChild("submarine_fabricator_03");

            // Update prefab name
            cyclopsFabPrefab.name = NameID;

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

            prefabId.ClassId = NameID;
            prefabId.name    = FriendlyName;

            // Add tech tag
            TechTag techTag = cyclopsFabPrefab.AddComponent <TechTag>();

            techTag.type = this.TechType;

            // Translate CyclopsFabricator model and light
            cyclopsFabModel.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
            cyclopsFabLight.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

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

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

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

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

            // Associate power relay
            GhostCrafter ghost      = fabricator.GetComponent <GhostCrafter>();
            var          powerRelay = new PowerRelay(); // This isn't correct, but nothing else seems to work.

            ghost.SetPrivateField("powerRelay", powerRelay);

            // Add constructable - This prefab normally isn't constructed.
            Constructable constructible = cyclopsFabPrefab.AddComponent <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
            constructible.model    = cyclopsFabModel;

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

            GameObject result;

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

                result = request.GetResult();

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

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

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

            GameObjectClone.name = TechTypeName;

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

            prefabIdentifier.ClassId = TechTypeName;

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

            techTag.type = TechType;

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

            resourceTracker.overrideTechType = TechType.Fragment;

            ModifyGameObject();

            AddFragmentTracker(GameObjectClone);

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

            gameObject.Set(GameObjectClone);

            yield break;
        }
Example #27
0
        public override GameObject GetGameObject()
        {
#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): A");
#endif
            GameObject prefab = GameObject.Instantiate(this.GameObject);
#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): B");
#endif
            GameObject barstoolPrefab = GameObject.Instantiate(this.barstoolgo);

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): C");
#endif
            prefab.name = this.ClassID;

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): D");
#endif
            // Modify tech tag
            TechTag techTag = prefab.GetComponent <TechTag>();
            if (techTag == null)
            {
                techTag = prefab.AddComponent <TechTag>();
            }
            techTag.type = this.TechType;

            // Modify prefab identifier
            var prefabId = prefab.GetComponent <PrefabIdentifier>();
            prefabId.ClassId = this.ClassID;

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): E");
#endif
            // Scale
            prefab.transform.localScale *= 0.5f;
            foreach (Transform tr in prefab.transform)
            {
                tr.localPosition = new Vector3(tr.localPosition.x, tr.localPosition.y + 0.3f, tr.localPosition.z);
            }

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): F");
#endif
            // Add large world entity
            var lwe = prefab.GetComponent <LargeWorldEntity>();
            if (lwe == null)
            {
                lwe = prefab.AddComponent <LargeWorldEntity>();
            }
            lwe.cellLevel = LargeWorldEntity.CellLevel.Near;

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): G");
#endif
            // Disable renderers
            Renderer[] renderers = prefab.GetComponentsInChildren <Renderer>();
            foreach (Renderer rend in renderers)
            {
                rend.enabled = false;
            }
            barstoolPrefab.transform.parent           = prefab.transform;
            barstoolPrefab.transform.localPosition    = new Vector3(0.0f, 0.07f, 0.0f);
            barstoolPrefab.transform.localScale       = new Vector3(1000.0f, 1000.0f, 1000.0f);
            barstoolPrefab.transform.localEulerAngles = new Vector3(270.0f, 0.0f, 0.0f);
            barstoolPrefab.SetActive(true);

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): H");
#endif
            // Get bench
            var bench = prefab.GetComponent <Bench>();
            bench.cinematicController.animatedTransform.localPosition = new Vector3(bench.cinematicController.animatedTransform.localPosition.x, bench.cinematicController.animatedTransform.localPosition.y + 1.76f, bench.cinematicController.animatedTransform.localPosition.z - 0.1f);

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): I");
#endif
            // Set proper shaders
            renderers = prefab.GetComponentsInChildren <Renderer>();
            foreach (Renderer renderer in renderers)
            {
                foreach (Material tmpMat in renderer.materials)
                {
                    // Associate MarmosetUBER shader
                    tmpMat.shader = Shader.Find("MarmosetUBER");
                    if (tmpMat.name.StartsWith("Stool_Leather", true, CultureInfo.InvariantCulture))
                    {
                        tmpMat.EnableKeyword("MARMO_SPECULAR_IBL");
                        tmpMat.EnableKeyword("MARMO_SPECULAR_DIRECT");
                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                    }
                    else if (tmpMat.name.StartsWith("Stool_Metal", true, CultureInfo.InvariantCulture))
                    {
                        tmpMat.SetTexture("_SpecTex", metal_spec);
                        tmpMat.SetTexture("_MetallicGlossMap", metal_spec);
                        tmpMat.SetTexture("_BumpMap", metal_normal);

                        tmpMat.EnableKeyword("MARMO_SPECULAR_IBL");
                        tmpMat.EnableKeyword("MARMO_SPECULAR_DIRECT");
                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                        tmpMat.EnableKeyword("MARMO_MIP_GLOSS");
                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                    }
                }
            }

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): J");
#endif
            // Update sky applier
            var skyapplier = prefab.GetComponent <SkyApplier>();
            skyapplier.renderers = renderers;
            skyapplier.anchorSky = Skies.Auto;

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): K");
#endif
            // Update contructable
            var constructible = prefab.GetComponent <Constructable>();
            constructible.allowedInBase           = true;
            constructible.allowedInSub            = true;
            constructible.allowedOutside          = true;
            constructible.allowedOnCeiling        = false;
            constructible.allowedOnGround         = true;
            constructible.allowedOnConstructables = false;
            constructible.controlModelState       = true;
            constructible.deconstructionAllowed   = true;
            constructible.rotationEnabled         = true;
            constructible.model    = prefab.FindChild("bar_stool(Clone)");
            constructible.techType = this.TechType;
            constructible.enabled  = true;

#if DEBUG_STOOL
            Logger.Log("DEBUG: BarStool->GetGameObject(): L");
#endif
            // Update constructable bounds
            //var constructableBounds = prefab.GetComponent<ConstructableBounds>();
            //constructableBounds.bounds = new OrientedBounds(new Vector3(constructableBounds.bounds.position.x, constructableBounds.bounds.position.y, constructableBounds.bounds.position.z),
            //    new Quaternion(constructableBounds.bounds.rotation.x, constructableBounds.bounds.rotation.y, constructableBounds.bounds.rotation.z, constructableBounds.bounds.rotation.w),
            //    new Vector3(constructableBounds.bounds.extents.x * 0.3f, constructableBounds.bounds.extents.y, constructableBounds.bounds.extents.z * 0.3f));

            return(prefab);
        }