Пример #1
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                // Get model
                GameObject model = this.GameObject.FindChild("OutdoorLadderModel");

                // Scale model
                model.transform.localScale *= 100.0f;

                // Add prefab identifier
                var prefabId = this.GameObject.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = this.ClassID;

                // Add large world entity
                PrefabsHelper.SetDefaultLargeWorldEntity(this.GameObject, LargeWorldEntity.CellLevel.Far);

                // Add tech tag
                var techTag = this.GameObject.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Add collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size   = new Vector3(0.3f, 2.7f, 0.07f);
                collider.center = new Vector3(collider.center.x, collider.center.y + 0.55f, collider.center.z - 0.24f);

                // Set proper shaders and materials
                Shader  marmosetUber = Shader.Find("MarmosetUBER");
                Texture illum1       = AssetsHelper.Assets.LoadAsset <Texture>("base_ladder_01");
                Texture normal1      = AssetsHelper.Assets.LoadAsset <Texture>("base_ladder_01_normal");
                var     renderers    = this.GameObject.GetComponentsInChildren <Renderer>();
                if (renderers != null && renderers.Length > 0)
                {
                    foreach (Renderer rend in renderers)
                    {
                        foreach (Material tmpMat in rend.materials)
                        {
                            tmpMat.shader = marmosetUber;
                            if (tmpMat.name.StartsWith("base_ladder_01"))
                            {
                                tmpMat.SetTexture("_BumpMap", normal1);
#if SUBNAUTICA
                                tmpMat.SetTexture("_Illum", illum1);
                                tmpMat.SetFloat("_EmissionLM", 0.05f);
                                tmpMat.EnableKeyword("MARMO_EMISSION");
#endif
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                        }
                    }
                }

                // Add contructable
                Constructable constructable = this.GameObject.AddComponent <Constructable>();
                constructable.allowedInBase           = false;
                constructable.allowedInSub            = false;
                constructable.allowedOutside          = true;
                constructable.allowedOnCeiling        = true;
                constructable.allowedOnWall           = true;
                constructable.allowedOnGround         = true;
                constructable.allowedOnConstructables = true;
#if BELOWZERO
                constructable.allowedUnderwater = true;
#endif
                constructable.controlModelState     = true;
                constructable.deconstructionAllowed = true;
                constructable.rotationEnabled       = true;
                constructable.model            = model;
                constructable.techType         = this.TechType;
                constructable.surfaceType      = VFXSurfaceTypes.metal;
                constructable.placeMinDistance = 0.6f;
                constructable.placeMaxDistance = 10.0f;
                constructable.enabled          = true;

                // Add constructable bounds
                ConstructableBounds bounds = this.GameObject.AddComponent <ConstructableBounds>();

                // Add sky applier
#if BELOWZERO
                BaseModuleLighting bml = this.GameObject.GetComponent <BaseModuleLighting>();
                if (bml == null)
                {
                    bml = this.GameObject.GetComponentInChildren <BaseModuleLighting>();
                }
                if (bml == null)
                {
                    bml = this.GameObject.AddComponent <BaseModuleLighting>();
                }
#endif
                SkyApplier applier = this.GameObject.GetComponent <SkyApplier>();
                if (applier == null)
                {
                    applier = this.GameObject.GetComponentInChildren <SkyApplier>();
                }
                if (applier == null)
                {
                    applier = this.GameObject.AddComponent <SkyApplier>();
                }
                applier.renderers    = renderers;
                applier.anchorSky    = Skies.Auto;
                applier.updaterIndex = 0;
#if SUBNAUTICA
                applier.emissiveFromPower = true; // Emissive from power
#endif
                applier.enabled = true;

                // Add outdoor ladder controller
                OutdoorLadderController controller = this.GameObject.AddComponent <OutdoorLadderController>();

                // Associate recipe to the new TechType
                SMLHelper.V2.Handlers.CraftDataHandler.SetTechData(this.TechType, this.Recipe);

                // Add new TechType to the buildables
                SMLHelper.V2.Handlers.CraftDataHandler.AddBuildable(this.TechType);
                SMLHelper.V2.Handlers.CraftDataHandler.AddToGroup(TechGroup.ExteriorModules, TechCategory.ExteriorModule, this.TechType);

                // Set the buildable prefab
                SMLHelper.V2.Handlers.PrefabHandler.RegisterPrefab(this);

                // Set the custom sprite
                SMLHelper.V2.Handlers.SpriteHandler.RegisterSprite(this.TechType, SpriteManager.Get(TechType.BaseLadder));

                this.IsRegistered = true;
            }
        }
Пример #2
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                // Get objects
                GameObject model = this.GameObject.FindChild("Model");

                // Rotate model
                //model.transform.localEulerAngles = new Vector3(model.transform.localEulerAngles.x - 90f, model.transform.localEulerAngles.y, model.transform.localEulerAngles.z);

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

                // Apply shaders and materials
                var     renderers    = this.GameObject.GetAllComponentsInChildren <Renderer>();
                Shader  marmosetUber = Shader.Find("MarmosetUBER");
                Texture normal1      = AssetsHelper.Assets.LoadAsset <Texture>("precursor_lab_warper_normal");
                Texture spec1        = AssetsHelper.Assets.LoadAsset <Texture>("precursor_lab_warper_spec");
                Texture illum1       = AssetsHelper.Assets.LoadAsset <Texture>("precursor_lab_warper_illum");
                if (renderers.Length > 0)
                {
                    foreach (Renderer rend in renderers)
                    {
                        if (rend.materials.Length > 0)
                        {
                            foreach (Material tmpMat in rend.materials)
                            {
                                if (string.Compare(tmpMat.name, "precursor_lab_warper_liquid (Instance)", true, CultureInfo.InvariantCulture) != 0 && !tmpMat.name.StartsWith("precursor_lab_warper_tube_", true, CultureInfo.InvariantCulture))
                                {
                                    tmpMat.shader = marmosetUber;
                                    if (string.Compare(tmpMat.name, "precursor_lab_warper (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_SpecTex", spec1);
                                        tmpMat.SetTexture("_BumpMap", normal1);
                                        tmpMat.SetTexture("_Illum", illum1);
                                        tmpMat.SetFloat("_EmissionLM", 1f);

                                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_EMISSION");
                                        tmpMat.EnableKeyword("_ZWRITE_ON");
                                    }
                                    else if (string.Compare(tmpMat.name, "precursor_lab_warper_box (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_SpecTex", spec1);
                                        tmpMat.SetTexture("_BumpMap", normal1);
                                        tmpMat.SetTexture("_Illum", illum1);
                                        tmpMat.SetFloat("_EmissionLM", 1f);

                                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_EMISSION");
                                        tmpMat.EnableKeyword("_ZWRITE_ON");
                                    }
                                }
                            }
                        }
                    }
                }

                // Add prefab identifier
                var prefabId = this.GameObject.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = this.ClassID;

                // Add large world entity
                PrefabsHelper.SetDefaultLargeWorldEntity(this.GameObject);

                // Add tech tag
                var techTag = this.GameObject.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Add collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size   = new Vector3(0.0075f, 0.0075f, 0.038f);
                collider.center = new Vector3(collider.center.x, collider.center.y, collider.center.z + 0.019f);

                // Add sky applier
#if BELOWZERO
                BaseModuleLighting bml = this.GameObject.GetComponent <BaseModuleLighting>();
                if (bml == null)
                {
                    bml = this.GameObject.GetComponentInChildren <BaseModuleLighting>();
                }
                if (bml == null)
                {
                    bml = this.GameObject.AddComponent <BaseModuleLighting>();
                }
#endif
                SkyApplier applier = this.GameObject.AddComponent <SkyApplier>();
                applier.renderers    = renderers;
                applier.anchorSky    = Skies.Auto;
                applier.updaterIndex = 0;

                // Add contructable
                Constructable constructable = this.GameObject.AddComponent <Constructable>();
                constructable.allowedInBase           = true;
                constructable.allowedInSub            = true;
                constructable.allowedOnCeiling        = true;
                constructable.allowedOnWall           = true;
                constructable.allowedOnConstructables = true;
                constructable.allowedOutside          = false;
                constructable.allowedOnGround         = false;
#if BELOWZERO
                constructable.allowedUnderwater = true;
#endif
                constructable.controlModelState     = true;
                constructable.deconstructionAllowed = true;
                constructable.rotationEnabled       = true;
                constructable.model            = model;
                constructable.techType         = this.TechType;
                constructable.placeMinDistance = 0.6f;
                constructable.enabled          = true;

                // Add constructable bounds
                ConstructableBounds bounds = this.GameObject.AddComponent <ConstructableBounds>();
                //bounds.bounds.position = new Vector3(bounds.bounds.position.x, bounds.bounds.position.y + 0.032f, bounds.bounds.position.z);

                // Add warper specimen controller
                var warperSpecimenController = this.GameObject.AddComponent <WarperSpecimenController>();

                // Define unlock conditions
                if (ConfigSwitcher.AddItemsWhenDiscovered)
                {
                    SMLHelper.V2.Handlers.KnownTechHandler.SetAnalysisTechEntry(TechType.PrecursorWarper, new TechType[] { this.TechType });
                }

                // Associate recipe to the new TechType
                SMLHelper.V2.Handlers.CraftDataHandler.SetTechData(this.TechType, this.Recipe);

                // Add new TechType to the buildables
                SMLHelper.V2.Handlers.CraftDataHandler.AddBuildable(this.TechType);
                SMLHelper.V2.Handlers.CraftDataHandler.AddToGroup(TechGroup.Miscellaneous, TechCategory.Misc, this.TechType);

                // Set the buildable prefab
                SMLHelper.V2.Handlers.PrefabHandler.RegisterPrefab(this);

                // Set the custom sprite
                SMLHelper.V2.Handlers.SpriteHandler.RegisterSprite(this.TechType, AssetsHelper.Assets.LoadAsset <Sprite>("warper_icon_1"));

                this.IsRegistered = true;
            }
        }
Пример #3
0
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

            // Scale
            foreach (Transform tr in prefab.transform)
            {
                tr.transform.localScale *= 0.4f;
            }

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

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

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

            if (prefabId == null)
            {
                if ((prefabId = prefab.GetComponentInChildren <PrefabIdentifier>()) == null)
                {
                    prefabId = prefab.AddComponent <PrefabIdentifier>();
                }
            }
            prefabId.ClassId = this.ClassID;

            // Clean all the crap
            GameObject.DestroyImmediate(prefab.GetComponent <Rigidbody>());
            GameObject.DestroyImmediate(prefab.GetComponent <ConstructionObstacle>());

            // Set large world entity
            prefab.GetComponent <LargeWorldEntity>().cellLevel = LargeWorldEntity.CellLevel.Near;

            // Ajust collider
            BoxCollider c = prefab.GetComponentInChildren <BoxCollider>();

            c.size = new Vector3(c.size.x * 0.5f, c.size.y, c.size.z * 0.5f);
            // 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 = true;
            constructible.rotationEnabled         = true;
            constructible.deconstructionAllowed   = true;
            constructible.controlModelState       = true;
            constructible.model            = prefab.FindChild("precursor_deco_props_01");
            constructible.placeMinDistance = 0.6f;
            constructible.enabled          = true;

            // Add constructable bounds
            prefab.AddComponent <ConstructableBounds>();

            // Update sky applier
#if BELOWZERO
            BaseModuleLighting bml = prefab.GetComponent <BaseModuleLighting>();
            if (bml == null)
            {
                bml = prefab.GetComponentInChildren <BaseModuleLighting>();
            }
            if (bml == null)
            {
                bml = prefab.AddComponent <BaseModuleLighting>();
            }
#endif
            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);
        }
Пример #4
0
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

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

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

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

            if (prefabId == null)
            {
                if ((prefabId = prefab.GetComponentInChildren <PrefabIdentifier>()) == null)
                {
                    prefabId = prefab.AddComponent <PrefabIdentifier>();
                }
            }
            prefabId.ClassId = this.ClassID;

            if (!ConfigSwitcher.JackSepticEye_asBuildable)
            {
                // Retrieve collider
                GameObject model    = prefab.FindChild("jacksepticeye");
                Collider   collider = model.GetComponentInChildren <Collider>();

                // We can pick this item
                var 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          = false;
                placeTool.allowedOnCeiling       = false;
                placeTool.allowedOnConstructable = true;
                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
                var fabricating = prefab.FindChild("jacksepticeye").AddComponent <VFXFabricating>();
                fabricating.localMinY   = -0.1f;
                fabricating.localMaxY   = 0.6f;
                fabricating.posOffset   = new Vector3(0f, 0f, 0.04f);
                fabricating.eulerOffset = new Vector3(0f, 0f, 0f);
                fabricating.scaleFactor = 1f;
            }
            else
            {
                Constructable constructible = prefab.GetComponent <Constructable>();
                constructible.allowedOutside   = ConfigSwitcher.AllowBuildOutside;
                constructible.placeMinDistance = 0.5f;
            }

            // Update sky applier
#if BELOWZERO
            BaseModuleLighting bml = prefab.AddComponent <BaseModuleLighting>();
            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;
#else
            PrefabsHelper.SetDefaultSkyApplier(prefab, null, Skies.Auto, false, true);
#endif

            return(prefab);
        }
Пример #5
0
        public override GameObject GetGameObject()
        {
            GameObject prefab    = GameObject.Instantiate(this.GameObject);
            GameObject container = GameObject.Instantiate(this.CargoCrateContainer);
            GameObject model     = prefab.FindChild("submarine_locker_04");

            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.001f, 0.001f, 0.001f);
            container.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);
            container.SetActive(true);

            // Update colliders
            GameObject  builderTrigger  = container.FindChild("Builder Trigger");
            GameObject  objectTrigger   = container.FindChild("Collider");
            BoxCollider builderCollider = builderTrigger.GetComponent <BoxCollider>();

            builderCollider.isTrigger = false;
            builderCollider.enabled   = false;
            BoxCollider objectCollider = objectTrigger.GetComponent <BoxCollider>();

            objectCollider.isTrigger = false;
            objectCollider.enabled   = false;

            // Delete constructable bounds
            ConstructableBounds cb = container.GetComponent <ConstructableBounds>();

            GameObject.DestroyImmediate(cb);

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

            techTag.type = this.TechType;

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

            prefabId.ClassId = this.ClassID;

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

            GameObject.DestroyImmediate(rb);

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

            collider.size   = new Vector3(0.4f, 2.0f, 0.5f);
            collider.center = new Vector3(0.0f, 1.0f, 0.0f);

            // Update large world entity
            PrefabsHelper.UpdateExistingLargeWorldEntities(prefab);

            // Update sky applier
#if BELOWZERO
            SkyApplier[] sas = prefab.GetComponentsInChildren <SkyApplier>();
            while (prefab.GetComponentInChildren <SkyApplier>() != null)
            {
                GameObject.DestroyImmediate(prefab.GetComponentInChildren <SkyApplier>());
            }
            if (prefab.GetComponent <SkyApplier>() != null)
            {
                GameObject.DestroyImmediate(prefab.GetComponent <SkyApplier>());
            }
            while (prefab.GetComponentInChildren <BaseModuleLighting>() != null)
            {
                GameObject.DestroyImmediate(prefab.GetComponentInChildren <BaseModuleLighting>());
            }
            if (prefab.GetComponent <BaseModuleLighting>() != null)
            {
                GameObject.DestroyImmediate(prefab.GetComponent <BaseModuleLighting>());
            }

            BaseModuleLighting bml = prefab.AddComponent <BaseModuleLighting>();
            SkyApplier         sa  = prefab.AddComponent <SkyApplier>();
            sa.renderers = prefab.GetComponentsInChildren <Renderer>();
            sa.anchorSky = Skies.Auto;
#else
            PrefabsHelper.SetDefaultSkyApplier(prefab);
#endif

            // 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.rotationEnabled         = true;
            constructible.deconstructionAllowed   = true;
            constructible.controlModelState       = true;
            constructible.model            = model;
            constructible.placeMinDistance = 0.6f;

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

            // Add model controler
            var decorativeLockerController = prefab.AddComponent <DecorativeLockerController>();

            return(prefab);
        }
Пример #6
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                GameObject aquarium = Resources.Load <GameObject>("Submarine/Build/Aquarium");

                // Retrieve model node
                GameObject model = this.GameObject.FindChild("model");

                // Move model
                model.transform.localPosition = new Vector3(model.transform.localPosition.x, model.transform.localPosition.y - 0.04f, model.transform.localPosition.z + 0.03f);

                // Disable light at start
                var reactorRodLight = this.GameObject.GetComponentInChildren <Light>();
                reactorRodLight.intensity = 1.0f;
                reactorRodLight.range     = 10.0f;
                reactorRodLight.color     = Color.white;
                reactorRodLight.enabled   = false;

                // Add prefab identifier
                var prefabId = this.GameObject.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = this.ClassID;

                // Add large world entity
                var lwe = this.GameObject.AddComponent <LargeWorldEntity>();
                lwe.cellLevel = LargeWorldEntity.CellLevel.Near;

                // Add tech tag
                var techTag = this.GameObject.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Add box collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size   = new Vector3(0.18f, 0.36f, 0.18f);
                collider.center = new Vector3(collider.center.x, collider.center.y + 0.22f, collider.center.z);

                // Get glass material
                Material   glass      = null;
                Renderer[] aRenderers = aquarium.GetComponentsInChildren <Renderer>(true);
                foreach (Renderer aRenderer in aRenderers)
                {
                    foreach (Material aMaterial in aRenderer.materials)
                    {
                        if (aMaterial.name.StartsWith("Aquarium_glass", StringComparison.OrdinalIgnoreCase))
                        {
                            glass = aMaterial;
                            break;
                        }
                    }
                    if (glass != null)
                    {
                        break;
                    }
                }

                // Set proper shaders (for crafting animation)
                Shader  shader        = Shader.Find("MarmosetUBER");
                Texture normalTexture = AssetsHelper.Assets.LoadAsset <Texture>("nuclear_reactor_rod_normal");
                Texture specTexture   = AssetsHelper.Assets.LoadAsset <Texture>("nuclear_reactor_rod_spec");
                Texture illumTexture  = AssetsHelper.Assets.LoadAsset <Texture>("nuclear_reactor_rod_illum_white");

                List <Renderer> renderers = new List <Renderer>();
                this.GameObject.GetComponentsInChildren <Renderer>(renderers);
                foreach (Renderer renderer in renderers)
                {
                    if (renderer.name == "nuclear_reactor_rod_mesh")
                    {
                        // Associate MarmosetUBER shader
                        renderer.sharedMaterial.shader = shader;
                        renderer.material.shader       = shader;

                        // Update normal map
                        renderer.sharedMaterial.SetTexture("_BumpMap", normalTexture);
                        renderer.material.SetTexture("_BumpMap", normalTexture);

                        // Update spec map
                        renderer.sharedMaterial.SetTexture("_SpecTex", specTexture);
                        renderer.material.SetTexture("_SpecTex", specTexture);

                        // Update emission map
                        renderer.sharedMaterial.SetTexture("_Illum", illumTexture);
                        renderer.material.SetTexture("_Illum", illumTexture);

                        // Increase emission map strength
                        renderer.sharedMaterial.SetColor("_GlowColor", Color.white);
                        renderer.sharedMaterial.SetFloat("_GlowStrength", 1.0f);
                        renderer.material.SetColor("_GlowColor", Color.white);
                        renderer.material.SetFloat("_GlowStrength", 1.0f);

                        // Enable emission
                        renderer.sharedMaterial.EnableKeyword("MARMO_NORMALMAP");
                        renderer.sharedMaterial.EnableKeyword("MARMO_EMISSION");
                        renderer.sharedMaterial.EnableKeyword("MARMO_SPECMAP");
                        renderer.sharedMaterial.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                        renderer.material.EnableKeyword("MARMO_NORMALMAP");
                        renderer.material.EnableKeyword("MARMO_EMISSION");
                        renderer.material.EnableKeyword("MARMO_SPECMAP");
                        renderer.material.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                    }
                    else if (renderer.name == "nuclear_reactor_rod_glass" && glass != null)
                    {
                        renderer.material = glass;
                    }
                }

                // Add sky applier
#if BELOWZERO
                BaseModuleLighting bml = this.GameObject.AddComponent <BaseModuleLighting>();
                var skyapplier         = this.GameObject.GetComponent <SkyApplier>();
                if (skyapplier == null)
                {
                    skyapplier = this.GameObject.GetComponentInChildren <SkyApplier>();
                }
                if (skyapplier == null)
                {
                    skyapplier = this.GameObject.AddComponent <SkyApplier>();
                }
                skyapplier.renderers = this.GameObject.GetComponentsInChildren <Renderer>();
                skyapplier.anchorSky = Skies.Auto;
#else
                var skyapplier = this.GameObject.GetComponent <SkyApplier>();
                if (skyapplier == null)
                {
                    skyapplier = this.GameObject.AddComponent <SkyApplier>();
                }
                skyapplier.renderers = this.GameObject.GetComponentsInChildren <Renderer>();
                skyapplier.anchorSky = Skies.Auto;
#endif

                // Add contructable
                var constructible = this.GameObject.AddComponent <Lamp_C>();
                constructible.allowedInBase           = true;
                constructible.allowedInSub            = true;
                constructible.allowedOutside          = true;
                constructible.allowedOnCeiling        = true;
                constructible.allowedOnGround         = true;
                constructible.allowedOnConstructables = true;
                constructible.allowedOnWall           = true;
#if BELOWZERO
                constructible.allowedUnderwater = true;
#endif
                constructible.controlModelState     = true;
                constructible.deconstructionAllowed = true;
                constructible.rotationEnabled       = true;
                constructible.model    = model;
                constructible.techType = this.TechType;
                constructible.enabled  = true;

                // Add constructable bounds
                var bounds = this.GameObject.AddComponent <ConstructableBounds>();
                bounds.bounds.position = new Vector3(bounds.bounds.position.x, bounds.bounds.position.y + 0.003f, bounds.bounds.position.z);

                // Add lamp brightness controler
                var lampBrightness = this.GameObject.AddComponent <ReactorLampBrightness>();

                // Associate recipe to the new TechType
                SMLHelper.V2.Handlers.CraftDataHandler.SetTechData(this.TechType, this.Recipe);

                // Add new TechType to the buildables
                SMLHelper.V2.Handlers.CraftDataHandler.AddBuildable(this.TechType);
                SMLHelper.V2.Handlers.CraftDataHandler.AddToGroup(TechGroup.ExteriorModules, TechCategory.ExteriorLight, this.TechType, TechType.Spotlight);

                // Set the buildable prefab
                SMLHelper.V2.Handlers.PrefabHandler.RegisterPrefab(this);

                // Set the custom sprite
                SMLHelper.V2.Handlers.SpriteHandler.RegisterSprite(this.TechType, AssetsHelper.Assets.LoadAsset <Sprite>("reactorrod_white"));

                this.IsRegistered = true;
            }
        }
Пример #7
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                GameObject aquarium = Resources.Load <GameObject>("Submarine/Build/Aquarium");

                // Retrieve model node
                GameObject model = this.GameObject.FindChild("prawnsuit");

                // Move model
                model.transform.localPosition = new Vector3(model.transform.localPosition.x, model.transform.localPosition.y - 0.002f, model.transform.localPosition.z);

                // Add prefab identifier
                var prefabId = this.GameObject.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = this.ClassID;

                // Add large world entity
                PrefabsHelper.SetDefaultLargeWorldEntity(this.GameObject);

                // Add tech tag
                var techTag = this.GameObject.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Add box collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                //collider.radius = 0.0375f;
                collider.size   = new Vector3(0.04f, 0.115f, 0.04f);
                collider.center = new Vector3(collider.center.x, collider.center.y + 0.0575f, collider.center.z);

                // Get glass material
                Material   glass      = null;
                Renderer[] aRenderers = aquarium.GetComponentsInChildren <Renderer>(true);
                foreach (Renderer aRenderer in aRenderers)
                {
                    foreach (Material aMaterial in aRenderer.materials)
                    {
                        if (aMaterial.name.StartsWith("Aquarium_glass", StringComparison.OrdinalIgnoreCase))
                        {
                            glass = aMaterial;
                            break;
                        }
                    }
                    if (glass != null)
                    {
                        break;
                    }
                }

                // Set proper shaders (for crafting animation)
                Shader  shader     = Shader.Find("MarmosetUBER");
                Texture normal     = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_01_normal");
                Texture spec       = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_01_spec");
                Texture colorMask  = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_01_colorMask");
                Texture illum      = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_01_illum");
                Texture normal2    = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_01_fp_normal");
                Texture illum2     = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_01_fp_illum");
                Texture normal3    = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_Arm_Propulsion_Cannon_normal");
                Texture colorMask3 = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_Arm_Propulsion_Cannon_colorMask");
                Texture illum3     = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_Arm_Propulsion_Cannon_illum");
                Texture normal4    = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_grappling_arm_normal");
                Texture colorMask4 = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_grappling_arm_colorMask");
                Texture illum4     = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_grappling_arm_illum");
                Texture normal5    = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_01_glass_normal");
                Texture normal6    = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_storage_01_normal");
                Texture colorMask6 = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_storage_01_colorMask");
                Texture illum6     = AssetsHelper.Assets.LoadAsset <Texture>("exosuit_storage_01_illum");
                Texture normal7    = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_torpedo_launcher_arm_normal");
                Texture colorMask7 = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_torpedo_launcher_arm_colorMask");
                Texture illum7     = AssetsHelper.Assets.LoadAsset <Texture>("Exosuit_torpedo_launcher_arm_illum");
                Texture normal8    = AssetsHelper.Assets.LoadAsset <Texture>("engine_power_cell_ion_normal");
                Texture spec8      = AssetsHelper.Assets.LoadAsset <Texture>("engine_power_cell_ion_spec");
                Texture illum8     = AssetsHelper.Assets.LoadAsset <Texture>("engine_power_cell_ion_illum");
                Texture normal9    = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_torpedo_01_normal");
                Texture spec9      = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_torpedo_01_spec");
                Texture normal10   = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_upgrade_slots_01_normal");
                Texture spec10     = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_upgrade_slots_01_spec");
                Texture illum10    = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_upgrade_slots_01_illum");
                Texture normal11   = AssetsHelper.Assets.LoadAsset <Texture>("submarine_engine_power_cells_01_normal");
                Texture spec11     = AssetsHelper.Assets.LoadAsset <Texture>("submarine_engine_power_cells_01_spec");
                Texture illum11    = AssetsHelper.Assets.LoadAsset <Texture>("submarine_engine_power_cells_01_illum");

                Renderer[] renderers = this.GameObject.GetAllComponentsInChildren <Renderer>();
                foreach (Renderer renderer in renderers)
                {
                    if (renderer.name.StartsWith("Exosuit_cabin_01_glass", true, CultureInfo.InvariantCulture))
                    {
                        renderer.material = glass;
                    }
                    else if (renderer.materials != null)
                    {
                        foreach (Material tmpMat in renderer.materials)
                        {
                            // Associate MarmosetUBER shader
                            if (string.Compare(tmpMat.name, "exosuit_cabin_01_glass (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.EnableKeyword("MARMO_SIMPLE_GLASS");
                                tmpMat.EnableKeyword("WBOIT");
                            }
                            else if (string.Compare(tmpMat.name, "exosuit_01_glass (Instance)", true, CultureInfo.InvariantCulture) != 0)
                            {
                                tmpMat.shader = shader;
                            }

                            if (string.Compare(tmpMat.name, "exosuit_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal);
                                tmpMat.SetTexture("_ColorMask", colorMask);
                                tmpMat.SetTexture("_SpecTex", spec);
                                tmpMat.SetTexture("_Illum", illum);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable color mask
                                tmpMat.EnableKeyword("MARMO_VERTEX_COLOR");
                                // Enable specular
                                //tmpMat.EnableKeyword("MARMO_SPECULAR_ON");
                                tmpMat.EnableKeyword("MARMO_SPECULAR_IBL");
                                tmpMat.EnableKeyword("MARMO_SPECULAR_DIRECT");
                                tmpMat.EnableKeyword("MARMO_SPECMAP");
                                tmpMat.EnableKeyword("MARMO_MIP_GLOSS");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "exosuit_01_fp (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal2);
                                tmpMat.SetTexture("_Illum", illum2);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "Exosuit_Arm_Propulsion_Cannon (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal3);
                                tmpMat.SetTexture("_ColorMask", colorMask3);
                                tmpMat.SetTexture("_Illum", illum3);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable color mask
                                tmpMat.EnableKeyword("MARMO_VERTEX_COLOR");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "Exosuit_grappling_arm (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal4);
                                tmpMat.SetTexture("_ColorMask", colorMask4);
                                tmpMat.SetTexture("_Illum", illum4);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable color mask
                                tmpMat.EnableKeyword("MARMO_VERTEX_COLOR");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }

                            /*
                             * else if (tmpMat.name.CompareTo("exosuit_01_glass (Instance)") == 0)
                             * {
                             *  tmpMat.SetTexture("_BumpMap", normal5);
                             *
                             *  tmpMat.EnableKeyword("MARMO_SIMPLE_GLASS");
                             *  tmpMat.EnableKeyword("MARMO_NORMALMAP");
                             *  tmpMat.EnableKeyword("WBOIT");
                             *  tmpMat.EnableKeyword("_ZWRITE_ON");
                             * }
                             * else if (tmpMat.name.CompareTo("exosuit_cabin_01_glass (Instance)") == 0)
                             * {
                             *  tmpMat.EnableKeyword("MARMO_SIMPLE_GLASS");
                             *  tmpMat.EnableKeyword("WBOIT");
                             * }
                             */
                            else if (string.Compare(tmpMat.name, "exosuit_storage_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal6);
                                tmpMat.SetTexture("_ColorMask", colorMask6);
                                tmpMat.SetTexture("_Illum", illum6);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable color mask
                                tmpMat.EnableKeyword("MARMO_VERTEX_COLOR");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "Exosuit_torpedo_launcher_arm (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal7);
                                tmpMat.SetTexture("_ColorMask", colorMask7);
                                tmpMat.SetTexture("_Illum", illum7);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable color mask
                                tmpMat.EnableKeyword("MARMO_VERTEX_COLOR");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "power_cell_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal8);
                                tmpMat.SetTexture("_SpecTex", spec8);
                                tmpMat.SetTexture("_Illum", illum8);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable specular
                                tmpMat.EnableKeyword("MARMO_SPECULAR_IBL");
                                tmpMat.EnableKeyword("MARMO_SPECULAR_DIRECT");
                                tmpMat.EnableKeyword("MARMO_SPECMAP");
                                tmpMat.EnableKeyword("MARMO_MIP_GLOSS");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "seamoth_torpedo_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal9);
                                tmpMat.SetTexture("_SpecTex", spec9);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable specular
                                tmpMat.EnableKeyword("MARMO_SPECULAR_IBL");
                                tmpMat.EnableKeyword("MARMO_SPECULAR_DIRECT");
                                tmpMat.EnableKeyword("MARMO_SPECMAP");
                                tmpMat.EnableKeyword("MARMO_MIP_GLOSS");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "seamoth_upgrade_slots_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal10);
                                tmpMat.SetTexture("_SpecTex", spec10);
                                tmpMat.SetTexture("_Illum", illum10);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable specular
                                tmpMat.EnableKeyword("MARMO_SPECULAR_IBL");
                                tmpMat.EnableKeyword("MARMO_SPECULAR_DIRECT");
                                tmpMat.EnableKeyword("MARMO_SPECMAP");
                                tmpMat.EnableKeyword("MARMO_MIP_GLOSS");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                            else if (string.Compare(tmpMat.name, "submarine_engine_power_cells_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                            {
                                tmpMat.SetTexture("_BumpMap", normal11);
                                tmpMat.SetTexture("_SpecTex", spec11);
                                tmpMat.SetTexture("_Illum", illum11);
                                tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                // Enable specular
                                tmpMat.EnableKeyword("MARMO_SPECULAR_IBL");
                                tmpMat.EnableKeyword("MARMO_SPECULAR_DIRECT");
                                tmpMat.EnableKeyword("MARMO_SPECMAP");
                                tmpMat.EnableKeyword("MARMO_MIP_GLOSS");
                                // Enable normal map
                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                // Enable emission map
                                tmpMat.EnableKeyword("MARMO_EMISSION");
                                // Enable Z write
                                tmpMat.EnableKeyword("_ZWRITE_ON");
                            }
                        }
                    }
                }

                // Add sky applier
#if BELOWZERO
                BaseModuleLighting bml = this.GameObject.GetComponent <BaseModuleLighting>();
                if (bml == null)
                {
                    bml = this.GameObject.GetComponentInChildren <BaseModuleLighting>();
                }
                if (bml == null)
                {
                    bml = this.GameObject.AddComponent <BaseModuleLighting>();
                }
#endif
                SkyApplier applier = this.GameObject.GetComponent <SkyApplier>();
                if (applier == null)
                {
                    applier = this.GameObject.GetComponentInChildren <SkyApplier>();
                }
                if (applier == null)
                {
                    applier = this.GameObject.AddComponent <SkyApplier>();
                }
                applier.renderers    = renderers;
                applier.anchorSky    = Skies.Auto;
                applier.updaterIndex = 0;
                SkyApplier[] appliers = this.GameObject.GetComponentsInChildren <SkyApplier>();
                if (appliers != null && appliers.Length > 0)
                {
                    foreach (SkyApplier ap in appliers)
                    {
                        ap.renderers    = renderers;
                        ap.anchorSky    = Skies.Auto;
                        ap.updaterIndex = 0;
                    }
                }

                // Add contructable
                var constructible = this.GameObject.AddComponent <Constructable>();
                constructible.allowedInBase           = true;
                constructible.allowedInSub            = true;
                constructible.allowedOutside          = true;
                constructible.allowedOnCeiling        = false;
                constructible.allowedOnGround         = true;
                constructible.allowedOnConstructables = true;
#if BELOWZERO
                constructible.allowedUnderwater = true;
#endif
                constructible.controlModelState     = true;
                constructible.deconstructionAllowed = true;
                constructible.rotationEnabled       = true;
                constructible.model            = model;
                constructible.techType         = this.TechType;
                constructible.placeMinDistance = 0.6f;
                constructible.enabled          = true;

                // Add constructable bounds
                var bounds = this.GameObject.AddComponent <ConstructableBounds>();
                bounds.bounds.position = new Vector3(bounds.bounds.position.x, bounds.bounds.position.y + 0.002f, bounds.bounds.position.z);

                // Add model controler
                var exosuitDollControler = this.GameObject.AddComponent <ExosuitDollController>();

                #region Disable right arms (except hand arm)

                GameObject rightArm           = model.FindChild("ExosuitArmRight");
                GameObject rightArmRig        = rightArm.FindChild("exosuit_01_armRight 1").FindChild("ArmRig 1");
                GameObject rightTorpedoArm    = rightArmRig.FindChild("exosuit_arm_torpedoLauncher_geo 1");
                GameObject rightDrillArm      = rightArmRig.FindChild("exosuit_drill_geo 1");
                GameObject rightGrapplinArm   = rightArmRig.FindChild("exosuit_grapplingHook_geo 1");
                GameObject rightGrapplinHand  = rightArmRig.FindChild("exosuit_grapplingHook_hand_geo 1");
                GameObject rightHandArm       = rightArmRig.FindChild("exosuit_hand_geo 1");
                GameObject rightPropulsionArm = rightArmRig.FindChild("exosuit_propulsion_geo 1");

                // Disable right torpedo arm
                List <Renderer> rightTorpedoArmRenderers = new List <Renderer>();
                rightTorpedoArm.GetComponentsInChildren <Renderer>(rightTorpedoArmRenderers);
                if (!rightTorpedoArmRenderers.Contains(rightTorpedoArm.GetComponent <Renderer>()))
                {
                    rightTorpedoArmRenderers.Add(rightTorpedoArm.GetComponent <Renderer>());
                }
                foreach (Renderer rend in rightTorpedoArmRenderers)
                {
                    rend.enabled = false;
                }

                // Disable right drill arm
                rightDrillArm.GetComponent <Renderer>().enabled = false;

                // Disable right grapplin arm
                List <Renderer> rightGrapplinArmRenderers = new List <Renderer>();
                rightGrapplinHand.GetComponentsInChildren <Renderer>(rightGrapplinArmRenderers);
                if (!rightGrapplinArmRenderers.Contains(rightGrapplinHand.GetComponent <Renderer>()))
                {
                    rightGrapplinArmRenderers.Add(rightGrapplinHand.GetComponent <Renderer>());
                }
                foreach (Renderer rend in rightGrapplinArmRenderers)
                {
                    rend.enabled = false;
                }
                rightGrapplinArm.GetComponent <Renderer>().enabled = false;

                // Disable right propulsion arm
                rightPropulsionArm.GetComponent <Renderer>().enabled = false;

                #endregion

                #region Disable left arms (except hand arm)

                GameObject leftArm           = model.FindChild("ExosuitArmLeft");
                GameObject leftArmRig        = leftArm.FindChild("exosuit_01_armRight").FindChild("ArmRig");
                GameObject leftTorpedoArm    = leftArmRig.FindChild("exosuit_arm_torpedoLauncher_geo");
                GameObject leftDrillArm      = leftArmRig.FindChild("exosuit_drill_geo");
                GameObject leftGrapplinArm   = leftArmRig.FindChild("exosuit_grapplingHook_geo");
                GameObject leftGrapplinHand  = leftArmRig.FindChild("exosuit_grapplingHook_hand_geo");
                GameObject leftHandArm       = leftArmRig.FindChild("exosuit_hand_geo");
                GameObject leftPropulsionArm = leftArmRig.FindChild("exosuit_propulsion_geo");

                // Disable left torpedo arm
                List <Renderer> leftTorpedoArmRenderers = new List <Renderer>();
                leftTorpedoArm.GetComponentsInChildren <Renderer>(leftTorpedoArmRenderers);
                if (!leftTorpedoArmRenderers.Contains(leftTorpedoArm.GetComponent <Renderer>()))
                {
                    leftTorpedoArmRenderers.Add(leftTorpedoArm.GetComponent <Renderer>());
                }
                foreach (Renderer rend in leftTorpedoArmRenderers)
                {
                    rend.enabled = false;
                }

                // Disable left drill arm
                leftDrillArm.GetComponent <Renderer>().enabled = false;

                // Disable right grapplin arm
                List <Renderer> leftGrapplinArmRenderers = new List <Renderer>();
                leftGrapplinHand.GetComponentsInChildren <Renderer>(leftGrapplinArmRenderers);
                if (!leftGrapplinArmRenderers.Contains(leftGrapplinHand.GetComponent <Renderer>()))
                {
                    leftGrapplinArmRenderers.Add(leftGrapplinHand.GetComponent <Renderer>());
                }
                foreach (Renderer rend in leftGrapplinArmRenderers)
                {
                    rend.enabled = false;
                }
                leftGrapplinArm.GetComponent <Renderer>().enabled = false;

                // Disable right propulsion arm
                leftPropulsionArm.GetComponent <Renderer>().enabled = false;

                #endregion

                // Add new TechType to the buildables
                SMLHelper.V2.Handlers.CraftDataHandler.AddBuildable(this.TechType);
                SMLHelper.V2.Handlers.CraftDataHandler.AddToGroup(TechGroup.Miscellaneous, TechCategory.Misc, this.TechType);

                // Set the buildable prefab
                SMLHelper.V2.Handlers.PrefabHandler.RegisterPrefab(this);

                // Set the custom sprite
                SMLHelper.V2.Handlers.SpriteHandler.RegisterSprite(this.TechType, SpriteManager.Get(TechType.Exosuit));

                // Associate recipe to the new TechType
                SMLHelper.V2.Handlers.CraftDataHandler.SetTechData(this.TechType, this.Recipe);

                this.IsRegistered = true;
            }
        }
Пример #8
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                GameObject model = this.GameObject.FindChild("CyclopsDoll");

                // Scale model
                model.transform.localScale *= 0.12f;

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

                // Add prefab identifier
                var prefabId = this.GameObject.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = this.ClassID;

                // Add large world entity
                PrefabsHelper.SetDefaultLargeWorldEntity(this.GameObject);

                // Add tech tag
                var techTag = this.GameObject.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Add collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size   = new Vector3(0.06f, 0.148f, 0.42f);
                collider.center = new Vector3(collider.center.x - 0.02f, collider.center.y + 0.135f, collider.center.z - 0.105f);

                // Get shaders/textures
                Shader marmosetUber = Shader.Find("MarmosetUBER");
                if (normals == null)
                {
                    normals = new Dictionary <string, Texture>();
                    foreach (KeyValuePair <string, string> elem in normalnames)
                    {
                        normals.Add(elem.Key, AssetsHelper.Assets.LoadAsset <Texture>(elem.Value));
                    }
                }

                // Get glass material
                GameObject aquarium   = Resources.Load <GameObject>("Submarine/Build/Aquarium");
                Material   glass      = null;
                Renderer[] aRenderers = aquarium.GetComponentsInChildren <Renderer>(true);
                foreach (Renderer aRenderer in aRenderers)
                {
                    foreach (Material aMaterial in aRenderer.materials)
                    {
                        if (aMaterial.name.StartsWith("Aquarium_glass", StringComparison.OrdinalIgnoreCase))
                        {
                            glass = aMaterial;
                            break;
                        }
                    }
                    if (glass != null)
                    {
                        break;
                    }
                }

                // Set proper shaders/textures
                var renderers = this.GameObject.GetAllComponentsInChildren <Renderer>();
                if (renderers.Length > 0)
                {
#if DEBUG_CYCLOPS_DOLL
                    Logger.Log("DEBUG: Printing renderers:");
#endif
                    foreach (Renderer rend in renderers)
                    {
                        if (rend.name.StartsWith("Cyclops_submarine_exterior_glass", true, CultureInfo.InvariantCulture) ||
                            rend.name.StartsWith("glass", true, CultureInfo.InvariantCulture))
                        {
                            rend.material = glass;
                        }
                        else if (rend.materials.Length > 0)
                        {
#if DEBUG_CYCLOPS_DOLL
                            Logger.Log("DEBUG: Found renderer name=[" + rend.name + "] type=[" + rend.GetType().ToString() + "]");
#endif
                            foreach (Material tmpMat in rend.materials)
                            {
#if DEBUG_CYCLOPS_DOLL
                                Logger.Log("DEBUG: \t=> material name=[" + tmpMat.name + "]");
#endif
                                tmpMat.shader = marmosetUber;
                                if (tmpMat.name.StartsWith("cyclops_submarine_exterior_decals_01_24", false, CultureInfo.InvariantCulture))
                                {
                                    tmpMat.SetFloat("_EnableCutOff", 1.0f);
                                    tmpMat.SetFloat("_Cutoff", 0.1f);
                                    tmpMat.EnableKeyword("MARMO_ALPHA_CLIP");
                                }
                                else if (normals != null)
                                {
                                    foreach (KeyValuePair <string, string> elem in normalnames)
                                    {
                                        if (tmpMat.name.StartsWith(elem.Key, false, CultureInfo.InvariantCulture))
                                        {
                                            if (elem.Value != null && normals.ContainsKey(elem.Value) && normals[elem.Value] != null)
                                            {
                                                tmpMat.SetTexture("_BumpMap", normals[elem.Value]);
                                                tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                                tmpMat.EnableKeyword("_ZWRITE_ON");
                                            }
#if DEBUG_CYCLOPS_DOLL
                                            else
                                            {
                                                Logger.Log("DEBUG: Warning missing cyclops texture.");
                                            }
#endif
                                            break;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                // Add contructable
                Constructable constructable = this.GameObject.AddComponent <Constructable>();
                constructable.allowedInBase           = true;
                constructable.allowedInSub            = true;
                constructable.allowedOutside          = true;
                constructable.allowedOnCeiling        = false;
                constructable.allowedOnGround         = true;
                constructable.allowedOnConstructables = true;
#if BELOWZERO
                constructable.allowedUnderwater = true;
#endif
                constructable.controlModelState     = true;
                constructable.deconstructionAllowed = true;
                constructable.rotationEnabled       = true;
                constructable.model            = model;
                constructable.techType         = this.TechType;
                constructable.surfaceType      = VFXSurfaceTypes.metal;
                constructable.placeMinDistance = 0.6f;
                constructable.enabled          = true;

                // Add constructable bounds
                ConstructableBounds bounds = this.GameObject.AddComponent <ConstructableBounds>();
                bounds.bounds.size *= 0.9f;
                Vector3 pos = bounds.bounds.position;
                bounds.bounds.position = new Vector3(pos.x - 0.02f, pos.y + 0.135f, pos.z - 0.105f);

                // Add sky applier
#if BELOWZERO
                BaseModuleLighting bml = this.GameObject.GetComponent <BaseModuleLighting>();
                if (bml == null)
                {
                    bml = this.GameObject.GetComponentInChildren <BaseModuleLighting>();
                }
                if (bml == null)
                {
                    bml = this.GameObject.AddComponent <BaseModuleLighting>();
                }
#endif
                SkyApplier applier = this.GameObject.AddComponent <SkyApplier>();
                if (applier != null)
                {
                    applier.renderers    = renderers;
                    applier.anchorSky    = Skies.Auto;
                    applier.updaterIndex = 0;
                }

                // Add size controler
                CyclopsDollController controller = this.GameObject.AddComponent <CyclopsDollController>();

                // Associate recipe to the new TechType
                SMLHelper.V2.Handlers.CraftDataHandler.SetTechData(this.TechType, this.Recipe);

                // Add new TechType to the buildables
                SMLHelper.V2.Handlers.CraftDataHandler.AddBuildable(this.TechType);
                SMLHelper.V2.Handlers.CraftDataHandler.AddToGroup(TechGroup.Miscellaneous, TechCategory.Misc, this.TechType);

                // Set the buildable prefab
                SMLHelper.V2.Handlers.PrefabHandler.RegisterPrefab(this);

                // Set the custom sprite
                SMLHelper.V2.Handlers.SpriteHandler.RegisterSprite(this.TechType, SpriteManager.Get(TechType.Cyclops));

                this.IsRegistered = true;
            }
        }
Пример #9
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                GameObject aquarium = Resources.Load <GameObject>("Submarine/Build/Aquarium");

                // Move model
                GameObject model = this.GameObject.FindChild("Model");
                model.transform.localPosition = new Vector3(model.transform.localPosition.x, model.transform.localPosition.y + 0.032f, model.transform.localPosition.z);

                // Add prefab identifier
                var prefabId = this.GameObject.AddComponent <PrefabIdentifier>();
                prefabId.ClassId = this.ClassID;

                // Add large world entity
                PrefabsHelper.SetDefaultLargeWorldEntity(this.GameObject);

                // Add tech tag
                var techTag = this.GameObject.AddComponent <TechTag>();
                techTag.type = this.TechType;

                // Add collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size   = new Vector3(0.07f, 0.054f, 0.07f);
                collider.center = new Vector3(collider.center.x, collider.center.y + 0.027f, collider.center.z);

                // Get glass material
                Material   glass      = null;
                Renderer[] aRenderers = aquarium.GetComponentsInChildren <Renderer>(true);
                foreach (Renderer aRenderer in aRenderers)
                {
                    foreach (Material aMaterial in aRenderer.materials)
                    {
                        if (aMaterial.name.StartsWith("Aquarium_glass", StringComparison.OrdinalIgnoreCase))
                        {
                            glass = aMaterial;
                            break;
                        }
                    }
                    if (glass != null)
                    {
                        break;
                    }
                }

                // Set proper shaders (for crafting animation)
                Shader  marmosetUber = Shader.Find("MarmosetUBER");
                Texture normal1      = AssetsHelper.Assets.LoadAsset <Texture>("power_cell_01_normal");
                Texture spec1        = AssetsHelper.Assets.LoadAsset <Texture>("power_cell_01_spec");
                Texture illum1       = AssetsHelper.Assets.LoadAsset <Texture>("power_cell_01_illum");
                Texture normal2      = AssetsHelper.Assets.LoadAsset <Texture>("Submersible_SeaMoth_normal");
                Texture spec2        = AssetsHelper.Assets.LoadAsset <Texture>("Submersible_SeaMoth_spec");
                Texture illum2       = AssetsHelper.Assets.LoadAsset <Texture>("Submersible_SeaMoth_illum");
                Texture normal3      = AssetsHelper.Assets.LoadAsset <Texture>("Submersible_SeaMoth_indoor_normal");
                Texture illum3       = AssetsHelper.Assets.LoadAsset <Texture>("Submersible_SeaMoth_indoor_illum");
                Texture normal4      = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_storage_01_normal");
                Texture normal5      = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_storage_02_normal");
                Texture illum5       = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_storage_02_illum");
                Texture normal6      = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_power_cell_slot_01_normal");
                Texture spec6        = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_power_cell_slot_01_spec");
                Texture normal7      = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_torpedo_01_normal");
                Texture spec7        = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_torpedo_01_spec");
                Texture normal8      = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_torpedo_01_hatch_01_normal");
                Texture spec8        = AssetsHelper.Assets.LoadAsset <Texture>("seamoth_torpedo_01_hatch_01_spec");

                var renderers = this.GameObject.GetAllComponentsInChildren <Renderer>();
                if (renderers.Length > 0)
                {
                    foreach (Renderer rend in renderers)
                    {
                        if (rend.name.StartsWith("Submersible_SeaMoth_glass_geo", true, CultureInfo.InvariantCulture))
                        {
                            rend.material = glass;
                        }
                        else if (rend.materials.Length > 0)
                        {
                            foreach (Material tmpMat in rend.materials)
                            {
                                if (string.Compare(tmpMat.name, "Submersible_SeaMoth_Glass_interior (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                {
                                    tmpMat.EnableKeyword("MARMO_SIMPLE_GLASS");
                                    tmpMat.EnableKeyword("WBOIT");
                                }
                                else if (string.Compare(tmpMat.name, "Submersible_SeaMoth_Glass (Instance)", true, CultureInfo.InvariantCulture) != 0)
                                {
                                    tmpMat.shader = marmosetUber;
                                    if (string.Compare(tmpMat.name, "power_cell_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal1);
                                        tmpMat.SetTexture("_SpecTex", spec1);
                                        tmpMat.SetTexture("_Illum", illum1);
                                        tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_EMISSION");
                                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                                    }
                                    else if (string.Compare(tmpMat.name, "Submersible_SeaMoth (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal2);
                                        tmpMat.SetTexture("_SpecTex", spec2);
                                        tmpMat.SetTexture("_Illum", illum2);
                                        tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_EMISSION");
                                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                                    }
                                    else if (string.Compare(tmpMat.name, "Submersible_SeaMoth_indoor (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal3);
                                        tmpMat.SetTexture("_Illum", illum3);
                                        tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_EMISSION");
                                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                                    }
                                    else if (string.Compare(tmpMat.name, "seamoth_storage_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal4);

                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                                    }
                                    else if (string.Compare(tmpMat.name, "seamoth_storage_02 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal5);
                                        tmpMat.SetTexture("_Illum", illum5);
                                        tmpMat.SetFloat("_EmissionLM", 0.75f); // Set always visible

                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_EMISSION");
                                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                                    }
                                    else if (string.Compare(tmpMat.name, "seamoth_power_cell_slot_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal6);
                                        tmpMat.SetTexture("_SpecTex", spec6);

                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                                    }
                                    else if (string.Compare(tmpMat.name, "seamoth_torpedo_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal7);
                                        tmpMat.SetTexture("_SpecTex", spec7);

                                        tmpMat.EnableKeyword("MARMO_NORMALMAP");
                                        tmpMat.EnableKeyword("MARMO_SPECMAP");
                                        tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                                    }
                                    else if (string.Compare(tmpMat.name, "seamoth_torpedo_01_hatch_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                    {
                                        tmpMat.SetTexture("_BumpMap", normal8);
                                        tmpMat.SetTexture("_SpecTex", spec8);

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

                // Add contructable
                Constructable constructable = this.GameObject.AddComponent <Constructable>();
                constructable.allowedInBase           = true;
                constructable.allowedInSub            = true;
                constructable.allowedOutside          = true;
                constructable.allowedOnCeiling        = false;
                constructable.allowedOnGround         = true;
                constructable.allowedOnConstructables = true;
#if BELOWZERO
                constructable.allowedUnderwater = true;
#endif
                constructable.controlModelState     = true;
                constructable.deconstructionAllowed = true;
                constructable.rotationEnabled       = true;
                constructable.model            = model;
                constructable.techType         = this.TechType;
                constructable.placeMinDistance = 0.6f;
                constructable.enabled          = true;

                // Add constructable bounds
                ConstructableBounds bounds = this.GameObject.AddComponent <ConstructableBounds>();
                bounds.bounds.position = new Vector3(bounds.bounds.position.x, bounds.bounds.position.y + 0.032f, bounds.bounds.position.z);

                // Add sky applier
#if BELOWZERO
                BaseModuleLighting bml = this.GameObject.GetComponent <BaseModuleLighting>();
                if (bml == null)
                {
                    bml = this.GameObject.GetComponentInChildren <BaseModuleLighting>();
                }
                if (bml == null)
                {
                    bml = this.GameObject.AddComponent <BaseModuleLighting>();
                }
#endif
                SkyApplier applier = this.GameObject.GetComponent <SkyApplier>();
                if (applier == null)
                {
                    applier = this.GameObject.GetComponentInChildren <SkyApplier>();
                }
                if (applier == null)
                {
                    applier = this.GameObject.AddComponent <SkyApplier>();
                }
                applier.renderers    = renderers;
                applier.anchorSky    = Skies.Auto;
                applier.updaterIndex = 0;
                SkyApplier[] appliers = this.GameObject.GetComponentsInChildren <SkyApplier>();
                if (appliers != null && appliers.Length > 0)
                {
                    foreach (SkyApplier ap in appliers)
                    {
                        ap.renderers    = renderers;
                        ap.anchorSky    = Skies.Auto;
                        ap.updaterIndex = 0;
                    }
                }

                // Add lights/model controler
                SeamothDollController controller = this.GameObject.AddComponent <SeamothDollController>();

                // Add new TechType to the buildables
                SMLHelper.V2.Handlers.CraftDataHandler.AddBuildable(this.TechType);
                SMLHelper.V2.Handlers.CraftDataHandler.AddToGroup(TechGroup.Miscellaneous, TechCategory.Misc, this.TechType);

                // Set the buildable prefab
                SMLHelper.V2.Handlers.PrefabHandler.RegisterPrefab(this);

                // Set the custom sprite
                SMLHelper.V2.Handlers.SpriteHandler.RegisterSprite(this.TechType, SpriteManager.Get(TechType.Seamoth));

                // Associate recipe to the new TechType
                SMLHelper.V2.Handlers.CraftDataHandler.SetTechData(this.TechType, this.Recipe);

                this.IsRegistered = true;
            }
        }