Beispiel #1
0
        private void RenderDict(string dictId, WordDictionary dict)
        {
            float minY = ItemsNode.transform.localPosition.y;

            //Debug.Log("up minY=" + minY);

            foreach (var n in ItemsNode.GetComponentsInChildren <DictionaryNodeBehavior>())
            {
                if (n.gameObject.activeSelf && n.transform.localPosition.y < minY)
                {
                    minY = n.transform.localPosition.y - 100;
                }
            }

            var node = PrefabsHelper.InstantiateDictionaryNode(ItemsNode.transform);

            var item = node.GetComponent <DictionaryNodeBehavior>();

            item.Label.text   = dict.Name;
            item.DictionaryId = dictId;

            minY -= 10;

            Debug.Log("up minY=" + minY);

            node.transform.localPosition = new Vector3(0, minY);

            //Debug.Log("up parent" + ItemsNode.transform);
        }
Beispiel #2
0
        private static void PositionLadder(ref Vector3 position, ref Quaternion rotation, Transform foundation, int initialDirection = 0, bool initialInverted = false)
        {
            rotation = foundation.rotation;
            Vector3 newAngles = rotation.eulerAngles;
            int     direction = CurrentDirection;

            for (int i = 0; i < initialDirection; i++)
            {
                direction++;
                if (direction > 3)
                {
                    direction = 0;
                }
            }
            CurrentInverted = Input.GetKey(KeyCode.T);
            bool doInvert = initialInverted ? !CurrentInverted : CurrentInverted;

            if (doInvert)
            {
                position             = PrefabsHelper.Translate(foundation.position, foundation.rotation, LadderPositionsAlt[direction].Key);
                rotation.eulerAngles = new Vector3(newAngles.x, newAngles.y + LadderPositionsAlt[direction].Value, newAngles.z);
            }
            else
            {
                position             = PrefabsHelper.Translate(foundation.position, foundation.rotation, LadderPositions[direction].Key);
                rotation.eulerAngles = new Vector3(newAngles.x, newAngles.y + LadderPositions[direction].Value, newAngles.z);
            }
            TempLadderDirections[position] = new KeyValuePair <int, bool>(direction, doInvert);
        }
Beispiel #3
0
    private void Shot(bool value)
    {
        var bullet = PrefabsHelper.CreatePrefab(PrefabEnum.Bullet, ShipModel.transform.position, this.transform.rotation);
        var rig    = bullet.GetComponent <Rigidbody>();

        rig.velocity = transform.rotation * Vector3.forward * Speed * 20;
    }
Beispiel #4
0
    private void GenerateAsteroid()
    {
        var bullet = PrefabsHelper.CreatePrefab(PrefabEnum.AsteroidBig, this.transform.position);
        var rig    = bullet.GetComponent <Rigidbody>();

        rig.velocity = Vector3.left * 100;
    }
Beispiel #5
0
 public static bool OnConsoleCommand_spawn_Prefix(NotificationCenter.Notification n)
 {
     if (n != null && n.data != null && n.data.Count > 0)
     {
         string text = (string)n.data[0];
         if (UWE.Utils.TryParseEnum <TechType>(text, out TechType techType) && techType != TechType.None)
         {
             if (CraftData.IsAllowed(techType))
             {
                 foreach (IDecorationItem item in DecorationsMod.DecorationItems)
                 {
                     // If item being spawned is one of our decoration items.
                     if (techType == item.TechType)
                     {
                         // If item being spawned is one of our new flora.
                         if (!string.IsNullOrEmpty(item.ClassID) && CustomFlora.AllPlants.Contains(item.ClassID))
                         {
                             GameObject prefabForTechType = CraftData.GetPrefabForTechType(techType, true);
                             if (prefabForTechType != null)
                             {
                                 int num = 1;
                                 int num2;
                                 if (n.data.Count > 1 && int.TryParse((string)n.data[1], out num2))
                                 {
                                     num = num2;
                                 }
                                 float maxDist = 12f;
                                 if (n.data.Count > 2)
                                 {
                                     maxDist = float.Parse((string)n.data[2]);
                                 }
                                 Debug.LogFormat("Spawning {0} {1}", new object[] { num, techType });
                                 for (int i = 0; i < num; i++)
                                 {
                                     GameObject gameObject = global::Utils.CreatePrefab(prefabForTechType, maxDist, i > 0);
                                     LargeWorldEntity.Register(gameObject);
                                     CrafterLogic.NotifyCraftEnd(gameObject, techType);
                                     gameObject.SendMessage("StartConstruction", SendMessageOptions.DontRequireReceiver);
                                     // Hide plant, show seed and enable pickupable
                                     PrefabsHelper.HidePlantAndShowSeed(gameObject.transform, item.ClassID);
                                 }
                             }
                             else
                             {
                                 ErrorMessage.AddDebug("Could not find prefab for TechType = " + techType);
                             }
                             // Dont call original function if item being spawned is one of our new flora.
                             return(false);
                         }
                         break;
                     }
                 }
             }
         }
     }
     // Give back execution to original function.
     return(true);
 }
        private void InitAnimation(GameObject go)
        {
            if (!Running)
            {
#if DEBUG_FLORA
                PrefabIdentifier id = go.GetComponent <PrefabIdentifier>();
                if (id != null)
                {
                    Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + go.name + "] id=[" + id.Id + "] position x=[" + go.transform.localPosition.x + "] y=[" + go.transform.localPosition.y + "] z=[" + go.transform.localPosition.z + "] => Initializing");
                }
                else
                {
                    Logger.Log("DEBUG: LandTree1Controller.Update(): gameObject name=[" + go.name + "] position x=[" + go.transform.localPosition.x + "] y=[" + go.transform.localPosition.y + "] z=[" + go.transform.localPosition.z + "] => Initializing");
                }
#endif
                if (StaticPrefab != null)
                {
                    // Configure static renderer
                    StaticPrefab.transform.parent           = go.transform;
                    StaticPrefab.transform.localPosition    = new Vector3(0.0f, 0.0f, 0.0f);
                    StaticPrefab.transform.localScale       = new Vector3(12f, 12f, 12f);
                    StaticPrefab.transform.localEulerAngles = new Vector3(0.0f, 0.0f, 0.0f);

                    // Update sky applier
                    SkyApplier skyApplier = go.GetComponent <SkyApplier>();
                    skyApplier.renderers = go.GetComponentsInChildren <Renderer>();
                    skyApplier.anchorSky = Skies.Auto;

                    StaticPrefab.SetActive(true);
                }
                // Hide seed model and show plant model
                PrefabsHelper.ShowPlantAndHideSeed(_grownPlant.gameObject.transform);
                // Store init values
                _initTimeValue = DayNightCycle.main.timePassed;
                foreach (Transform tr in go.transform)
                {
                    bool isStatic = tr.name.StartsWith("Land_tree_01_static", true, CultureInfo.InvariantCulture);
                    if (_origScale == Vector3.zero && !isStatic)
                    {
                        _origScale = new Vector3(tr.localScale.x, tr.localScale.y, tr.localScale.z);
                    }
                    else if (_origStaticScale == Vector3.zero && isStatic)
                    {
                        _origStaticScale = new Vector3(tr.localScale.x, tr.localScale.y, tr.localScale.z);
                    }
                }
                // Init trees sizes
                foreach (Transform tr in go.transform)
                {
                    tr.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f);
                }
                Running = true;
            }
        }
Beispiel #7
0
    private void CreateSparks(Vector2 position, Color color)
    {
        var sparks = PrefabsHelper.InstantiateSparks();
        var sprite = Engine.Field.Sprites[(int)position.x, (int)position.y];
        var ps     = sparks.GetComponent <ParticleSystem>();

        ps.renderer.material.color = color;
        ps.maxParticles            = new CryptoRandom().Next(4, 10);
        sparks.transform.position  = sprite.transform.position;
        Destroy(sparks, ps.startLifetime);
    }
Beispiel #8
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;

            // We can pick this item
            PrefabsHelper.SetDefaultPickupable(prefab);

            // We can place this item
            var cpt = prefab.GetComponent <CustomPlaceToolController>();

            if (cpt == null)
            {
                cpt = prefab.AddComponent <CustomPlaceToolController>();
            }
            prefab.AddComponent <Egg14_PT>();
            PrefabsHelper.SetDefaultPlaceTool(prefab);

            // Add fabricating animation
            var fabricating = prefab.AddComponent <VFXFabricating>();

            fabricating.localMinY   = -0.2f;
            fabricating.localMaxY   = 0.8f;
            fabricating.posOffset   = new Vector3(0f, 0.05f, 0.04f);
            fabricating.eulerOffset = new Vector3(0f, 0f, 0f);
            fabricating.scaleFactor = 1f;

            return(prefab);
        }
Beispiel #9
0
 public static bool OnConsoleCommand_item_Prefix(NotificationCenter.Notification n)
 {
     if (n != null && n.data != null && n.data.Count > 0)
     {
         string text = (string)n.data[0];
         if (UWE.Utils.TryParseEnum <TechType>(text, out TechType techType) && techType != TechType.None)
         {
             if (CraftData.IsAllowed(techType))
             {
                 foreach (IDecorationItem item in DecorationsMod.DecorationItems)
                 {
                     // If item being spawned is one of our decoration items.
                     if (techType == item.TechType)
                     {
                         // If item being spawned is one of our new flora.
                         if (!string.IsNullOrEmpty(item.ClassID) && CustomFlora.AllPlants.Contains(item.ClassID))
                         {
                             int num = 1;
                             if (n.data.Count > 1 && int.TryParse((string)n.data[1], out int num2))
                             {
                                 num = num2;
                             }
                             for (int i = 0; i < num; i++)
                             {
                                 GameObject gameObject = CraftData.InstantiateFromPrefab(techType, false);
                                 if (gameObject != null)
                                 {
                                     gameObject.transform.position = MainCamera.camera.transform.position + MainCamera.camera.transform.forward * 3f;
                                     CrafterLogic.NotifyCraftEnd(gameObject, techType);
                                     Pickupable component = gameObject.GetComponent <Pickupable>();
                                     if (component != null && !Inventory.main.Pickup(component, false))
                                     {
                                         ErrorMessage.AddError(Language.main.Get("InventoryFull"));
                                         // Hide plant, show seed and enable pickupable
                                         PrefabsHelper.HidePlantAndShowSeed(gameObject.transform, item.ClassID);
                                     }
                                 }
                             }
                             // Dont call original function if item being spawned is one of our new flora.
                             return(false);
                         }
                         break;
                     }
                 }
             }
         }
     }
     // Give back execution to original function.
     return(true);
 }
        public static void Drop_Postfix(Pickupable __instance)
        {
            if (__instance.gameObject != null)
            {
                // Get current item PID
                var pid = __instance.gameObject.GetComponent <PrefabIdentifier>();

                // If current item is one of our new flora
                if (pid != null && !string.IsNullOrEmpty(pid.ClassId) && CustomFlora.AllPlants.Contains(pid.ClassId))
                {
                    PrefabsHelper.HidePlantAndShowSeed(__instance.gameObject.transform, pid.ClassId); // Hide plant, show seed and enable pickupable
                }
            }
        }
 public static void CalculateBiome_Postfix(ref string __result)
 {
     if (__result != null && __result.Contains("deepGrandReef"))
     {
         // Check if we are in Deep Grand Reef (every 20 seconds).
         if (!lastBiomeWasDeepGrandReef || (Time.time > lastTimeCheck + 20.0f))
         {
             lastTimeCheck             = Time.time;
             lastBiomeWasDeepGrandReef = true;
             PrefabsHelper.HideDegasiBase();
         }
     }
     else
     {
         lastBiomeWasDeepGrandReef = false;
     }
 }
Beispiel #12
0
        public static void RefreshAquariumSkyAppliers(Aquarium aquarium, bool remove = false)
        {
            var pid = aquarium?.gameObject?.GetComponent <PrefabIdentifier>();

#if DEBUG_AQUARIUM
            Logger.Log("DEBUG: Entering RefreshAquariumSkyAppliers for aquarium ClassID=[" + (!string.IsNullOrEmpty(pid?.ClassId) ? pid.ClassId : "?") + "]");
#endif
            // If current item is our custom aquarium (or if it's the regular aquarium and "FixAquariumLighting" is enabled).
            if (pid != null && !string.IsNullOrEmpty(pid.ClassId) &&
                (pid.ClassId == "AquariumSmall" || (ConfigSwitcher.FixAquariumLighting && pid.ClassId == AquariumClassId)))
            {
                GameObject model = aquarium.gameObject.FindChild("model");
                if (model != null)
                {
                    PrefabsHelper.FixAquariumFishesSkyApplier(model.FindChild("Aquarium_animation").FindChild("root"), remove);
                    PrefabsHelper.FixAquariumFishesSkyApplier(model.FindChild("Aquarium_animation2").FindChild("root"), remove);
                }
            }
        }
Beispiel #13
0
        public static void AddItem_Postfix(Aquarium __instance, InventoryItem item)
        {
            var pid = __instance?.gameObject?.GetComponent <PrefabIdentifier>();

#if DEBUG_AQUARIUM
            Logger.Log("DEBUG: Entering AddItem_Postfix for aquarium ClassID=[" + (!string.IsNullOrEmpty(pid?.ClassId) ? pid.ClassId : "?") + "]");
#endif
            // If current item is our custom aquarium (or if it's the regular aquarium and "FixAquariumLighting" is enabled).
            if (pid != null && !string.IsNullOrEmpty(pid.ClassId) &&
                (pid.ClassId == "AquariumSmall" || (ConfigSwitcher.FixAquariumLighting && pid.ClassId == "6d71afaa-09b6-44d3-ba2d-66644ffe6a99")))
            {
                GameObject model = __instance.gameObject.FindChild("model");
                if (model != null)
                {
                    PrefabsHelper.FixAquariumFishesSkyApplier(model.FindChild("Aquarium_animation").FindChild("root"));
                    PrefabsHelper.FixAquariumFishesSkyApplier(model.FindChild("Aquarium_animation2").FindChild("root"));
                }
            }
        }
        public static bool OnHandClick_Prefix(Pickupable __instance, GUIHand hand)
        {
            if (__instance.gameObject != null)
            {
                // Get current item PID
                var pid = __instance.gameObject.GetComponent <PrefabIdentifier>();

                // If current item is one of our new flora
                if (pid != null && !string.IsNullOrEmpty(pid.ClassId) && CustomFlora.AllPlants.Contains(pid.ClassId))
                {
                    // If hand is free and item allowed to pickup
                    if (hand.IsFreeToInteract() && ((bool)allowedToPickUpMethod.Invoke(__instance, null) == true))
                    {
                        // Try pickup flora
                        if (Inventory.Get().Pickup(__instance, false))
                        {
                            // Show plant, hide seed and disable pickupable now that plant has been picked up
                            PrefabsHelper.ShowPlantAndHideSeed(__instance.gameObject.transform, pid.ClassId);
                            // Play grab animation
                            Player.main.PlayGrab();
                            // Refresh waterpark status
                            WaterParkItem component = __instance.GetComponent <WaterParkItem>();
                            if (component == null)
                            {
                                component = __instance.gameObject.GetComponent <WaterParkItem>();
                            }
                            if (component != null)
                            {
                                component.SetWaterPark(null);
                            }
                        }
                        else
                        {
                            ErrorMessage.AddWarning(Language.main.Get("InventoryFull"));
                        }
                    }
                    // Don't call origin function if current item is one of our new flora
                    return(false);
                }
            }
            // Give back execution to origin function
            return(true);
        }
Beispiel #15
0
    private void OnCollisionEnter(Collision collision)
    {
        var collider = collision.collider.gameObject;

        Destroy(this.gameObject);
        if (collider.layer == 9)
        {
            var type     = collider.GetComponent <AsteroidController>().AsteroidType;
            var position = collider.transform.position;
            Destroy(collider);

            switch (type)
            {
            case AsteroidTypeEnum.Small:
                Aggregator.Publish("AddPoints", 1);
                break;

            case AsteroidTypeEnum.Medium:
                Aggregator.Publish("AddPoints", 2);

                for (int i = 0; i < 2; i++)
                {
                    CreateAsteroid(PrefabEnum.AsteroidSmall, position);
                }

                break;

            case AsteroidTypeEnum.Big:
                Aggregator.Publish("AddPoints", 3);

                for (int i = 0; i < 2; i++)
                {
                    PrefabsHelper.CreatePrefab(PrefabEnum.AsteroidMedium, position);
                }
                break;

            default:
                break;
            }
        }
    }
Beispiel #16
0
    public void Awake()
    {
        const int height = 1024;
        var       width  = height * FindObjectOfType <Camera>().aspect;
        var       step   = new Vector2(width / Size.x, height / (Size.y + 2));

        Sprites = new UISprite[(int)Size.x, (int)Size.y];

        for (var x = 0; x < Size.x; x++)
        {
            for (var y = 0; y < Size.y; y++)
            {
                var cell = PrefabsHelper.InstantiateCell();

                cell.transform.parent        = FieldParent;
                cell.transform.localPosition = new Vector2(x * step.x - width / 2f + step.x / 2f, y * step.y - height / 2f + step.y / 2f);
                cell.transform.localScale    = new Vector2(step.x, step.y);
                Sprites[x, y] = cell.GetComponent <UISprite>();
            }
        }

        Reset();
    }
Beispiel #17
0
        private static int GetFacingDirection(Transform foundation, Vector3 hitPoint)
        {
            int   facing = 0;
            float min    = Vector3.Distance(hitPoint, PrefabsHelper.Translate(foundation.position, foundation.rotation, NorthLadder));
            float dist   = Vector3.Distance(hitPoint, PrefabsHelper.Translate(foundation.position, foundation.rotation, EastLadder));

            if (dist < min)
            {
                min    = dist;
                facing = 1;
            }
            dist = Vector3.Distance(hitPoint, PrefabsHelper.Translate(foundation.position, foundation.rotation, SouthLadder));
            if (dist < min)
            {
                min    = dist;
                facing = 2;
            }
            dist = Vector3.Distance(hitPoint, PrefabsHelper.Translate(foundation.position, foundation.rotation, WestLadder));
            if (dist < min)
            {
                facing = 3;
            }
            return(facing);
        }
Beispiel #18
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                GameObject model = this.GameObject.FindChild("Model");

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

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

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

                // Add collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size   = new Vector3(0.3f, 0.1f, 0.2f);
                collider.center = new Vector3(collider.center.x, collider.center.y + 0.05f, collider.center.z);

                // Set proper shaders (for crafting animation)
                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");
                Texture normal2      = AssetsHelper.Assets.LoadAsset <Texture>("warper_normal");
                Texture spec2        = AssetsHelper.Assets.LoadAsset <Texture>("warper_spec");
                Texture illum2       = AssetsHelper.Assets.LoadAsset <Texture>("warper_illum");
                Texture normal3      = AssetsHelper.Assets.LoadAsset <Texture>("warper_entrails_normal");
                Texture spec3        = AssetsHelper.Assets.LoadAsset <Texture>("warper_entrails_spec");
                Texture illum3       = AssetsHelper.Assets.LoadAsset <Texture>("warper_entrails_illum");
                var     renderers    = this.GameObject.GetComponentsInChildren <Renderer>();
                foreach (Renderer rend in renderers)
                {
                    if (rend.materials.Length > 0)
                    {
                        foreach (Material tmpMat in rend.materials)
                        {
                            if (string.Compare(tmpMat.name, "precursor_lab_warper_tube_01 (Instance)", true, CultureInfo.InvariantCulture) != 0 &&
                                string.Compare(tmpMat.name, "precursor_lab_warper_tube_02 (Instance)", true, CultureInfo.InvariantCulture) != 0 &&
                                string.Compare(tmpMat.name, "precursor_lab_warper_liquid (Instance)", true, CultureInfo.InvariantCulture) != 0)
                            {
                                tmpMat.shader = marmosetUber;
                                if (string.Compare(tmpMat.name, "precursor_lab_warper (Instance)", true, CultureInfo.InvariantCulture) == 0 ||
                                    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"); // Enable Z write
                                }
                                else if (string.Compare(tmpMat.name, "Warper (Instance)", true, CultureInfo.InvariantCulture) == 0 ||
                                         string.Compare(tmpMat.name, "Warper_alpha (Instance)", true, CultureInfo.InvariantCulture) == 0)
                                {
                                    tmpMat.SetTexture("_SpecTex", spec2);
                                    tmpMat.SetTexture("_BumpMap", normal2);
                                    tmpMat.SetTexture("_Illum", illum2);
                                    tmpMat.SetFloat("_EmissionLM", 1f);

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

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

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

                // Add sky applier
                PrefabsHelper.SetDefaultSkyApplier(this.GameObject, renderers);

                // We can pick this item
                PrefabsHelper.SetDefaultPickupable(this.GameObject);

                // We can place this item
                this.GameObject.AddComponent <CustomPlaceToolController>();
                var placeTool = this.GameObject.AddComponent <GenericPlaceTool>();
                placeTool.allowedInBase          = true;
                placeTool.allowedOnConstructable = true;
                placeTool.allowedOnRigidBody     = true;
                placeTool.allowedOnBase          = true;
                placeTool.allowedOnGround        = true;
                placeTool.allowedOnCeiling       = false;
                placeTool.allowedOnWalls         = false;
                placeTool.allowedOutside         = ConfigSwitcher.AllowPlaceOutside;
                placeTool.rotationEnabled        = true;
                placeTool.enabled              = true;
                placeTool.hasAnimations        = false;
                placeTool.hasBashAnimation     = false;
                placeTool.hasFirstUseAnimation = false;
                placeTool.ghostModelPrefab     = this.GameObject;
                placeTool.mainCollider         = collider;
                placeTool.pickupable           = this.GameObject.GetComponent <Pickupable>();
                placeTool.drawTime             = 0.5f;
                placeTool.dropTime             = 1;
                placeTool.holsterTime          = 0.35f;

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

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

                // Add the new TechType to Hand Equipment type.
                SMLHelper.V2.Handlers.CraftDataHandler.SetEquipmentType(this.TechType, EquipmentType.Hand);

                // Set quick slot type.
                SMLHelper.V2.Handlers.CraftDataHandler.SetQuickSlotType(this.TechType, QuickSlotType.Selectable);

                // 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_5"));

                this.IsRegistered = true;
            }
        }
        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;
            }
        }
Beispiel #20
0
        private void BeginGame()
        {
            foreach (var table in FindObjectsOfType <Table>())
            {
                Destroy(table.gameObject);
            }

            List <List <Person> > tables;

            if (Level.Generator)
            {
                tables = GenerateTables(Level.TableNumber, Level.Target, Level.Сomplexity);
            }
            else if (Level.Type == LevelType.Memo)
            {
                if (Level.Memorize)
                {
                    tables = Level.Tables = InitializeTables(Level);
                }
                else
                {
                    tables = Level.Tables;

                    if (tables.Count <= 3)
                    {
                        List <List <Person> > worst, best;
                        int max, complexity;

                        Analize(tables, out worst, out best, out max, out complexity);

                        tables = best;
                    }
                    else // Fix slow analization on mobile
                    {
                        var persons = new List <Person>();

                        foreach (var table in tables)
                        {
                            persons.Add(table[0]);
                            persons.Add(table[1]);
                        }

                        persons.Shuffle();

                        for (var i = 0; i < tables.Count; i++)
                        {
                            tables[i][0] = persons[i];
                            tables[i][1] = persons[i + tables.Count];
                        }
                    }
                }
            }
            else
            {
                tables = InitializeTables(Level);
            }

            Timeout = Level.Memorize ? DateTime.Now.AddSeconds(Level.MemoizeTime) : DateTime.Now.AddSeconds(Level.Time);
            Swaps   = 0;

            RemoveUnusedHobbies(tables);

            for (var i = 0; i < Level.TableNumber; i++)
            {
                var table      = PrefabsHelper.Instantiate(Level.TableName, Get <Play>().GameTransform);
                var characters = table.GetComponentsInChildren <Character>();

                characters[0].Initialize(tables[i][0]);
                characters[1].Initialize(tables[i][1]);

                table.transform.localPosition = GameData.TablePositions[Level.TableNumber][i];
                table.transform.localScale    = GameData.TableScales[Level.TableNumber] * Vector3.one;
            }

            if (Level.Type == LevelType.Memo && Level.Memorize)
            {
                Level.FormationHash = GetFormation(tables);
            }

            State = GameState.Playing;
        }
        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);
        }
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

            if (!ConfigSwitcher.AlienRelic7Animation)
            {
                prefab.GetComponentInChildren <Animator>().enabled = false;
            }

            // Get objects
            GameObject relicHlpr = prefab.FindChild("alien_relic_07_hlpr");

            // Scale
            foreach (Transform tr in prefab.transform)
            {
                tr.transform.localScale *= 0.75f;
            }
            // Rotate
            relicHlpr.transform.localEulerAngles = new Vector3(relicHlpr.transform.localEulerAngles.x, relicHlpr.transform.localEulerAngles.y + 90f, relicHlpr.transform.localEulerAngles.z);
            // Translate
            relicHlpr.transform.localPosition = new Vector3(relicHlpr.transform.localPosition.x, relicHlpr.transform.localPosition.y + 0.19f, relicHlpr.transform.localPosition.z);

            // 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;

            // Remove rigid body to prevent bugs

            /*
             * var rbs = prefab.GetComponentsInChildren<Rigidbody>();
             * if (rbs != null && rbs.Length > 0)
             *  foreach (var rbp in rbs)
             *      GameObject.DestroyImmediate(rbp);
             * var rb = prefab.GetComponent<Rigidbody>();
             * if (rb != null)
             *  GameObject.DestroyImmediate(rb);
             */

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

            // Scale colliders
            var collider = prefab.GetComponent <CapsuleCollider>();

            collider.radius        = 0.1f;
            collider.height        = 0.1f;
            collider.contactOffset = 0.1f;
            collider.isTrigger     = true;
            foreach (BoxCollider c in prefab.GetComponentsInChildren <BoxCollider>())
            {
                c.size     *= 0.5f;
                c.isTrigger = true;
            }

            // We can pick this item
            var pickupable = prefab.GetComponent <Pickupable>();

            if (pickupable == null)
            {
                pickupable = prefab.AddComponent <Pickupable>();
            }
            pickupable.isPickupable = true;
            pickupable.randomizeRotationWhenDropped = true;

            // We can place this item
            prefab.AddComponent <CustomPlaceToolController>();
            //var placeTool = prefab.GetComponent<PlaceTool>();
            //if (placeTool != null)
            //    GameObject.DestroyImmediate(placeTool);
            var placeTool = prefab.AddComponent <GenericPlaceTool>();

            placeTool.allowedInBase          = true;
            placeTool.allowedOnBase          = true;
            placeTool.allowedOnCeiling       = false;
            placeTool.allowedOnConstructable = true;
            placeTool.allowedOnGround        = true;
            placeTool.allowedOnRigidBody     = true;
            placeTool.allowedOnWalls         = true;
            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.AddComponent <VFXFabricating>();

            fabricating.localMinY   = -0.2f;
            fabricating.localMaxY   = 0.4f;
            fabricating.posOffset   = new Vector3(0f, 0f, 0f);
            fabricating.eulerOffset = new Vector3(0f, 0f, 0f);
            fabricating.scaleFactor = 0.7f;

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

            prefab.name = this.ClassID;

            GameObject.DestroyImmediate(prefab.GetComponent <PickPrefab>());
            GameObject.DestroyImmediate(prefab.GetComponent <LiveMixin>());

            PrefabsHelper.AddNewGenericSeed(ref prefab);

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

            // Scale
            float scaleRatio = 0.75f;

            model.transform.localScale *= scaleRatio;

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

            // Add EntityTag
            var entityTag = prefab.AddComponent <EntityTag>();

            entityTag.slotType = EntitySlot.Type.Small;

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

            techTag.type = this.TechType;

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

            prefabId.ClassId = this.ClassID;

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

            lwe.cellLevel = LargeWorldEntity.CellLevel.Near;

            // Add world forces
            var worldForces = prefab.AddComponent <WorldForces>();

            worldForces.handleGravity     = true;
            worldForces.aboveWaterGravity = 9.81f;
            worldForces.underwaterGravity = 1.0f;
            worldForces.handleDrag        = true;
            worldForces.aboveWaterDrag    = 0.0f;
            worldForces.underwaterDrag    = 10.0f;
            worldForces.useRigidbody      = rb;

            // Add pickupable
            var pickupable = prefab.AddComponent <Pickupable>();

            pickupable.isPickupable   = true;
            pickupable.destroyOnDeath = true;
#if BELOWZERO
            pickupable.isLootCube = false;
#else
            pickupable.cubeOnPickup = false;
#endif
            pickupable.randomizeRotationWhenDropped = true;
            pickupable.usePackUpIcon = false;

            // Add eatable
            Eatable eatable = null;
            if (ConfigSwitcher.config_MarbleMelonTiny.Eatable)
            {
                eatable            = prefab.AddComponent <Eatable>();
                eatable.foodValue  = ConfigSwitcher.config_MarbleMelonTiny.FoodValue;
                eatable.waterValue = ConfigSwitcher.config_MarbleMelonTiny.WaterValue;
#if SUBNAUTICA
                eatable.stomachVolume = 10.0f;
                eatable.allowOverfill = false;
#endif
                eatable.decomposes   = ConfigSwitcher.config_MarbleMelonTiny.Decomposes;
                eatable.kDecayRate   = ConfigSwitcher.config_MarbleMelonTiny.KDecayRate;
                eatable.despawns     = ConfigSwitcher.config_MarbleMelonTiny.Despawns;
                eatable.despawnDelay = ConfigSwitcher.config_MarbleMelonTiny.DespawnDelay;
            }

            // Add plantable
            var plantable = prefab.AddComponent <Plantable>();
            plantable.aboveWater               = true;
            plantable.underwater               = false;
            plantable.isSeedling               = true;
            plantable.plantTechType            = this.TechType;
            plantable.size                     = Plantable.PlantSize.Small;
            plantable.pickupable               = pickupable;
            plantable.eatable                  = eatable;
            plantable.model                    = prefab; // prefab.FindChild("farming_plant_01_02");
            plantable.linkedGrownPlant         = new GrownPlant();
            plantable.linkedGrownPlant.seed    = plantable;
            plantable.linkedGrownPlant.seedUID = "MarbleMelonTinyFruit";

            // Add live mixin
            var liveMixin = prefab.AddComponent <LiveMixin>();
            liveMixin.health = ConfigSwitcher.config_MarbleMelonTiny.Health;
            liveMixin.data   = ScriptableObject.CreateInstance <LiveMixinData>();
            liveMixin.data.broadcastKillOnDeath = false;
            liveMixin.data.canResurrect         = false;
            liveMixin.data.destroyOnDeath       = true;
#if SUBNAUTICA
            liveMixin.data.explodeOnDestroy = false;
#endif
            liveMixin.data.invincibleInCreative  = false;
            liveMixin.data.minDamageForSound     = 10.0f;
            liveMixin.data.passDamageDataOnDeath = true;
            liveMixin.data.weldable  = false;
            liveMixin.data.knifeable = false;
            liveMixin.data.maxHealth = ConfigSwitcher.config_MarbleMelonTiny.Health;
            //liveMixin.startHealthPercent = 1.0f;

            // Adjust sky applier
            SkyApplier sa = prefab.GetComponent <SkyApplier>();
            sa.renderers = prefab.GetComponentsInChildren <MeshRenderer>();
            sa.anchorSky = Skies.Auto;
            sa.dynamic   = true;

            // Adjust colliders
            CapsuleCollider cc = prefab.GetComponentInChildren <CapsuleCollider>();
            cc.radius *= scaleRatio;
            cc.height *= scaleRatio;
            SphereCollider sc = prefab.GetComponentInChildren <SphereCollider>();
            sc.radius *= scaleRatio;

            // Add generic plant controller
            PlantGenericController plantController = prefab.AddComponent <PlantGenericController>();
            plantController.GrowthDuration = ConfigSwitcher.config_MarbleMelonTiny.GrowthDuration;
            plantController.Health         = ConfigSwitcher.config_MarbleMelonTiny.Health;
            plantController.Knifeable      = ConfigSwitcher.config_MarbleMelonTiny.Knifeable;

            CustomFloraSerializer customSerializer = prefab.AddComponent <CustomFloraSerializer>();

            // Hide plant and show seed
            PrefabsHelper.HidePlantAndShowSeed(prefab.transform, this.ClassID);

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

            prefab.name = this.ClassID;

            // Translate
            foreach (Transform tr in prefab.transform)
            {
                tr.localPosition = new Vector3(tr.localPosition.x, tr.localPosition.y + 0.25f, tr.localPosition.z);
            }

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

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

            // Remove unwanted components
            EntityTag entityTag = prefab.GetComponent <EntityTag>();

            if (entityTag != null)
            {
                GameObject.DestroyImmediate(entityTag);
            }
            EcoTarget ecoTarget = prefab.GetComponent <EcoTarget>();

            if (ecoTarget != null)
            {
                GameObject.DestroyImmediate(ecoTarget);
            }
            ResourceTracker resourceTracker = prefab.GetComponent <ResourceTracker>();

            if (resourceTracker != null)
            {
                GameObject.DestroyImmediate(resourceTracker);
            }
            WorldForces worldForces = prefab.GetComponent <WorldForces>();

            if (worldForces != null)
            {
                GameObject.DestroyImmediate(worldForces);
            }

            // 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;

            // Remove Cube object to prevent physics
            GameObject cube = prefab.FindChild("Cube");

            if (cube != null)
            {
                GameObject.DestroyImmediate(cube);
            }

            // Remove rigid body to prevent physics bugs
            var rb = prefab.GetComponent <Rigidbody>();

            if (rb != null)
            {
                GameObject.DestroyImmediate(rb);
            }

            // Add box collider
            var collider = prefab.GetComponent <BoxCollider>();

            if (collider == null)
            {
                Collider[] colliders = prefab.GetComponentsInChildren <Collider>();
                if (colliders != null)
                {
                    foreach (Collider c in colliders)
                    {
                        GameObject.DestroyImmediate(c);
                    }
                }
                collider = prefab.AddComponent <BoxCollider>();
            }
            collider.size      = new Vector3(0.7f, 0.7f, 0.7f);
            collider.center    = new Vector3(collider.center.x - 0.15f, collider.center.y + 1.0f, collider.center.z - 1.0f);
            collider.isTrigger = true;

            // We can pick this item
            var pickupable = prefab.GetComponent <Pickupable>();

            if (pickupable == null)
            {
                pickupable = prefab.AddComponent <Pickupable>();
            }
            pickupable.isPickupable = true;
            pickupable.randomizeRotationWhenDropped = true;

            // We can place this item
            prefab.AddComponent <CustomPlaceToolController>();
            var placeTool = prefab.GetComponent <PlaceTool>();

            if (placeTool != null)
            {
                GameObject.DestroyImmediate(placeTool);
            }
            placeTool = prefab.AddComponent <GenericPlaceTool>();
            placeTool.allowedInBase          = true;
            placeTool.allowedOnBase          = true;
            placeTool.allowedOnCeiling       = false;
            placeTool.allowedOnConstructable = true;
            placeTool.allowedOnGround        = true;
            placeTool.allowedOnRigidBody     = true;
            placeTool.allowedOnWalls         = true;
            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;

            // Update sky applier
            PrefabsHelper.ReplaceSkyApplier(prefab, true);

            // Add fabricating animation
            var fabricating = prefab.AddComponent <VFXFabricating>();

            fabricating.localMinY   = -0.2f;
            fabricating.localMaxY   = 0.6f;
            fabricating.posOffset   = new Vector3(0.1f, 0.141f, 0.3f);
            fabricating.eulerOffset = new Vector3(0f, 0f, 0f);
            fabricating.scaleFactor = 0.2f;

            return(prefab);
        }
Beispiel #25
0
        public void Update()
        {
#if (DEBUG_FLORA || DEBUG_FLORA_ENTRY || DEBUG_FLORA_ANIMATION)
            PrefabIdentifier id = GetComponent <PrefabIdentifier>();
#endif
#if DEBUG_FLORA_ENTRY
            if (id != null)
            {
                Logger.Log("DEBUG: Entering PlantGenericController.Update() for gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]");
            }
            else
            {
                Logger.Log("DEBUG: Entering PlantGenericController.Update() for gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]");
            }
#endif

            if (_plant == null)
            {
                _plant = GetComponent <Plantable>();
            }
            if (_grownPlant == null)
            {
                _grownPlant = GetComponent <GrownPlant>();
            }

            if (_grownPlant == null && _plant != null)
            {
                if (_plant.linkedGrownPlant != null)
                {
#if DEBUG_FLORA
                    Logger.Log("DEBUG: PlantGenericController.Update() Associating grown plant in gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "]");
#endif
                    _grownPlant      = _plant.linkedGrownPlant;
                    _grownPlant.seed = _plant;
                }
            }
            if (_grownPlant != null)
            {
                if (!Running)
                {
#if DEBUG_FLORA
                    if (id != null)
                    {
                        Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Initializing");
                    }
                    else
                    {
                        Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Initializing");
                    }
#endif
                    // Hide seed model and show plant model
                    PrefabsHelper.ShowPlantAndHideSeed(_grownPlant.gameObject.transform);
                    // Store init values
                    _initTimeValue = DayNightCycle.main.timePassed;
                    foreach (Transform tr in _grownPlant.gameObject.transform)
                    {
                        _origScale = new Vector3(tr.localScale.x, tr.localScale.y, tr.localScale.z);
                        break;
                    }
                    // If we need to add a temporary collider, do it before scaling
                    if (EnableColliders)
                    {
                        var coveTreeModel = _grownPlant.gameObject.FindChild("lost_river_cove_tree_01");
                        if (coveTreeModel != null)
                        {
                            _tmpCollider = coveTreeModel.AddComponent <BoxCollider>();
                            if (_tmpCollider != null)
                            {
                                _tmpCollider.size   = new Vector3(7.0f, 20.0f, 7.0f);
                                _tmpCollider.center = new Vector3(_tmpCollider.center.x, _tmpCollider.center.y + 10.0f, _tmpCollider.center.z);
                            }
                        }
                    }
                    // Init tree/plant size
                    foreach (Transform tr in _grownPlant.gameObject.transform)
                    {
                        if (tr.name != "Generic_plant_seed")
                        {
                            tr.localScale = new Vector3(0.0001f, 0.0001f, 0.0001f);
                        }
                    }

                    // Init colliders size
                    if (RestoreColliders)
                    {
                        Collider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <Collider>();
                        foreach (Collider collider in colliders)
                        {
                            collider.transform.localScale *= 1000.0f;
                            collider.enabled = true;
                        }
                    }
                    if (RestoreRadius)
                    {
                        SphereCollider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <SphereCollider>();
                        foreach (SphereCollider collider in colliders)
                        {
                            collider.radius *= 1000.0f;
                            collider.enabled = true;
                        }
                    }
                    if (RestoreBoxColliders)
                    {
                        BoxCollider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <BoxCollider>();
                        foreach (BoxCollider collider in colliders)
                        {
                            collider.size   *= 1000.0f;
                            collider.enabled = true;
                        }
                    }

                    Running = true;
                }
                else
                {
                    // Animation
                    _progress = ((float)(DayNightCycle.main.timePassed - _initTimeValue) / GrowthDuration) + _passedProgress;
#if DEBUG_FLORA_ANIMATION
                    if (id != null)
                    {
                        Logger.Log("DEBUG: PlantGenericController.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "]");
                    }
                    else
                    {
                        Logger.Log("DEBUG: PlantGenericController.Update(): PROGRESS gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => progress=[" + _progress + "] pastProgress=[" + _passedProgress + "] originScale x=[" + _origScale.x + "] y=[" + _origScale.y + "] z=[" + _origScale.z + "]");
                    }
#endif
                    if (_grownPlant.gameObject.transform.localPosition.x > 4500.0f && _grownPlant.gameObject.transform.localPosition.z > 4500.0f)
                    {
#if DEBUG_FLORA
                        if (id != null)
                        {
                            Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component");
                        }
                        else
                        {
                            Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.gameObject.transform.localPosition.x + "] y=[" + _grownPlant.gameObject.transform.localPosition.y + "] z=[" + _grownPlant.gameObject.transform.localPosition.z + "] => Disabling animation component");
                        }
#endif
                        this.enabled = false;
                    }
                    else
                    {
                        if (_progress < 1.0f)
                        {
                            foreach (Transform tr in _grownPlant.gameObject.transform)
                            {
                                if (tr.name != "Generic_plant_seed")
                                {
                                    tr.localScale = new Vector3(_origScale.x * _progress, _origScale.y * _progress, _origScale.z * _progress);
                                }
                            }
                        }
                        else
                        {
#if DEBUG_FLORA
                            if (id != null)
                            {
                                Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] id=[" + id.Id + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Set final size");
                            }
                            else
                            {
                                Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + _grownPlant.gameObject.name + "] position x=[" + _grownPlant.transform.localPosition.x + "] y=[" + _grownPlant.transform.localPosition.y + "] z=[" + _grownPlant.transform.localPosition.z + "] => Set final size");
                            }
#endif
                            // Set final size
                            _progress = 1.0f;
                            foreach (Transform tr in _grownPlant.gameObject.transform)
                            {
                                if (tr.name != "Generic_plant_seed")
                                {
                                    tr.localScale = new Vector3(_origScale.x, _origScale.y, _origScale.z);
                                }
                            }

                            // Set final colliders
                            if (EnableColliders)
                            {
                                // Disable temporary collider
                                if (_tmpCollider != null)
                                {
                                    _tmpCollider.enabled = false;
                                    GameObject.DestroyImmediate(_tmpCollider);
                                }
                                // Enable origin colliders
                                Collider[] colliders = _grownPlant.gameObject.GetComponentsInChildren <Collider>();
                                foreach (Collider collider in colliders)
                                {
                                    collider.enabled = true;
                                }
                            }

                            // Enable knifeable
                            LiveMixin liveMixin = _grownPlant.gameObject.GetComponent <LiveMixin>();
                            liveMixin.data.knifeable = Knifeable;

                            // Disable controller
                            this.enabled = false;
                        }
                    }
                }
            }
            else
            {
#if DEBUG_FLORA
                if (id != null)
                {
                    Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + this.gameObject.name + "] id=[" + id.Id + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Disabling controller");
                }
                else
                {
                    Logger.Log("DEBUG: PlantGenericController.Update(): gameObject name=[" + this.gameObject.name + "] position x=[" + this.gameObject.transform.localPosition.x + "] y=[" + this.gameObject.transform.localPosition.y + "] z=[" + this.gameObject.transform.localPosition.z + "] => No grown plant: Disabling controller");
                }
#endif
                this.enabled = false;
            }
        }
Beispiel #26
0
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                // Get model
                GameObject model = this.GameObject.FindChild("docking_clerical_penholder");

                // Scale
                model.transform.localScale *= 4f;
                // Translate
                model.transform.localPosition = new Vector3(model.transform.localPosition.x, model.transform.localPosition.y + 0.001f, model.transform.localPosition.z);
                // Rotate
                //model.transform.localEulerAngles = new Vector3(model.transform.localEulerAngles.x, model.transform.localEulerAngles.y + -25.0f, model.transform.localEulerAngles.z);

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

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

                // Add collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size          = new Vector3(0.1f, 0.1f, 0.1f);
                collider.contactOffset = 0.01f;
                //collider.center = new Vector3(collider.center.x - 0.15f, collider.center.y + 0.1f, collider.center.z);
                collider.enabled = true;

                // Set proper shaders (for crafting animation)
                Shader  marmosetUber = Shader.Find("MarmosetUBER");
                Texture normal       = AssetsHelper.Assets.LoadAsset <Texture>("docking_clerical_01_normal");
                var     renderers    = this.GameObject.GetComponentsInChildren <Renderer>();
                foreach (Renderer rend in renderers)
                {
                    foreach (Material tmpMat in rend.materials)
                    {
                        tmpMat.shader = marmosetUber;
                        if (string.Compare(tmpMat.name, "docking_clerical_01 (Instance)", true, CultureInfo.InvariantCulture) == 0)
                        {
                            tmpMat.SetTexture("_BumpMap", normal);
                            tmpMat.EnableKeyword("MARMO_NORMALMAP");
                            tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                        }
                    }
                }

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

                // Add rigid body
                PrefabsHelper.SetDefaultRigidBody(this.GameObject);
                Rigidbody rb = this.GameObject.GetComponent <Rigidbody>();
                rb.mass = 0.4f;

                // Add sky applier
                PrefabsHelper.SetDefaultSkyApplier(this.GameObject, renderers);

                // We can pick this item
                PrefabsHelper.SetDefaultPickupable(this.GameObject);

                // We can place this item
                PrefabsHelper.SetDefaultPlaceTool(this.GameObject, collider);

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

                // Add the new TechType to Hand Equipment type.
                SMLHelper.V2.Handlers.CraftDataHandler.SetEquipmentType(this.TechType, EquipmentType.Hand);

                // Set quick slot type.
                SMLHelper.V2.Handlers.CraftDataHandler.SetQuickSlotType(this.TechType, QuickSlotType.Selectable);

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

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

                this.IsRegistered = true;
            }
        }
        public override GameObject GetGameObject()
        {
            GameObject prefab = GameObject.Instantiate(this.GameObject);

            prefab.name = this.ClassID;

            // Remove unwanted elements
            GameObject.DestroyImmediate(prefab.GetComponent <Rigidbody>());
            GameObject.DestroyImmediate(prefab.GetComponent <ImmuneToPropulsioncannon>());

            // Rotate model
            GameObject model = prefab.FindChild("Creatures_eggs_17");

            model.transform.localEulerAngles = new Vector3(model.transform.localEulerAngles.x - 90f, model.transform.localEulerAngles.y, model.transform.localEulerAngles.z);
            // Scale model
            model.transform.localScale *= 0.8f;

#if BELOWZERO
            MeshRenderer[] renderers = model.GetComponents <MeshRenderer>();
            if (renderers != null)
            {
                foreach (MeshRenderer rend in renderers)
                {
                    if (rend.materials != null)
                    {
                        foreach (Material mat in rend.materials)
                        {
                            mat.shader = marmosetUber;
                            if (mat.name.StartsWith("Creatures_eggs_17"))
                            {
                                mat.SetTexture("_BumpMap", normal);
                                mat.EnableKeyword("MARMO_NORMALMAP");
                                mat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                            }
                        }
                    }
                }
            }
#endif

            // Scale collider
            CapsuleCollider c = prefab.GetComponentInChildren <CapsuleCollider>();
            c.radius *= 0.5f;
            c.height *= 0.5f;

            // 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;

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

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

            // We can pick this item
            PrefabsHelper.SetDefaultPickupable(prefab);

            // We can place this item
            //prefab.AddComponent<EggSeaDragon_PT>();
            PrefabsHelper.SetDefaultPlaceTool(prefab);

            // Add fabricating animation
            var fabricating = prefab.AddComponent <VFXFabricating>();
            fabricating.localMinY   = -0.2f;
            fabricating.localMaxY   = 0.8f;
            fabricating.posOffset   = new Vector3(0f, 0.03f, -0.15f);
            fabricating.eulerOffset = new Vector3(0f, 0f, 0f);
            fabricating.scaleFactor = 0.35f;

            return(prefab);
        }
        public override void RegisterItem()
        {
            if (this.IsRegistered == false)
            {
                GameObject model = this.GameObject.FindChild("Lost_river_sea_dragon_skeleton");

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

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

                // Rotate model
                model.transform.localEulerAngles = new Vector3(model.transform.localEulerAngles.x, model.transform.localEulerAngles.y + 90.0f, model.transform.localEulerAngles.z + 35.0f);

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

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

                // Add collider
                var collider = this.GameObject.AddComponent <BoxCollider>();
                collider.size = new Vector3(0.6f, 0.5f, 0.6f);

                // Set proper shaders (for crafting animation)
                Shader  marmosetUber = Shader.Find("MarmosetUBER");
                Texture normal       = AssetsHelper.Assets.LoadAsset <Texture>("Lost_river_sea_dragon_skeleton_bones_normal");
                Texture normal2      = AssetsHelper.Assets.LoadAsset <Texture>("Lost_river_sea_dragon_skeleton_skull_normal");
                var     renderers    = this.GameObject.GetComponentsInChildren <Renderer>();
                foreach (Renderer rend in renderers)
                {
                    foreach (Material tmpMat in rend.materials)
                    {
                        tmpMat.shader = marmosetUber;
                        if (string.Compare(tmpMat.name, "Lost_river_sea_dragon_skeleton_bones (Instance)", true, CultureInfo.InvariantCulture) == 0)
                        {
                            tmpMat.SetTexture("_BumpMap", normal);
                            tmpMat.EnableKeyword("MARMO_NORMALMAP");
                            tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                        }
                        else if (string.Compare(tmpMat.name, "Lost_river_sea_dragon_skeleton_skull (Instance)", true, CultureInfo.InvariantCulture) == 0)
                        {
                            tmpMat.SetTexture("_BumpMap", normal2);
                            tmpMat.EnableKeyword("MARMO_NORMALMAP");
                            tmpMat.EnableKeyword("_ZWRITE_ON"); // Enable Z write
                        }
                    }
                }

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

                // Add rigid body
                PrefabsHelper.SetDefaultRigidBody(this.GameObject);

                // Add sky applier
                PrefabsHelper.SetDefaultSkyApplier(this.GameObject, renderers);

                // We can pick this item
                PrefabsHelper.SetDefaultPickupable(this.GameObject);

                // We can place this item
                PrefabsHelper.SetDefaultPlaceTool(this.GameObject, collider);

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

                // Set item occupies 4 slots
                SMLHelper.V2.Handlers.CraftDataHandler.SetItemSize(this.TechType, new Vector2int(2, 2));

                // Add the new TechType to Hand Equipment type
                SMLHelper.V2.Handlers.CraftDataHandler.SetEquipmentType(this.TechType, EquipmentType.Hand);

                // Set quick slot type
                SMLHelper.V2.Handlers.CraftDataHandler.SetQuickSlotType(this.TechType, QuickSlotType.Selectable);

                // 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>("seadragonskeletonicon"));

                this.IsRegistered = true;
            }
        }
Beispiel #29
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;
            }
        }
        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);
        }