private void Awake()
 {
     lodGroup = GetComponent <LODGroup>();
     //LOD[] lods = new LOD[] { lodGroup.GetLODs()[0] };
     //lodGroup.SetLODs(lods);
     lodGroup.ForceLOD(1);
 }
Exemple #2
0
    static int ForceLOD(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 2);
        LODGroup obj  = LuaScriptMgr.GetNetObject <LODGroup>(L, 1);
        int      arg0 = (int)LuaScriptMgr.GetNumber(L, 2);

        obj.ForceLOD(arg0);
        return(0);
    }
        // Start is called before the first frame update
        void Start()
        {
            LODGroup lod = gameObject.GetOrCreateComponent <LODGroup>();

            if (Application.isMobilePlatform)
            {
                lod.ForceLOD(lod.lodCount - 1);
            }
        }
Exemple #4
0
    void OnGUI()
    {
        if (GUILayout.Button("Enable / Disable"))
        {
            group.enabled = !group.enabled;
        }

        if (GUILayout.Button("Default"))
        {
            group.ForceLOD(-1);
        }

        if (GUILayout.Button("Force 0"))
        {
            group.ForceLOD(0);
        }

        if (GUILayout.Button("Force 1"))
        {
            group.ForceLOD(1);
        }

        if (GUILayout.Button("Force 2"))
        {
            group.ForceLOD(2);
        }

        if (GUILayout.Button("Force 3"))
        {
            group.ForceLOD(3);
        }

        if (GUILayout.Button("Force 4"))
        {
            group.ForceLOD(4);
        }

        if (GUILayout.Button("Force 5"))
        {
            group.ForceLOD(5);
        }

        if (GUILayout.Button("Force 6"))
        {
            group.ForceLOD(6);
        }
    }
        private int CollapseReal(Vector3 origin)
        {
            if (base.transform.parent && base.transform.parent.parent)
            {
                LODGroup component = base.transform.parent.parent.GetComponent <LODGroup>();
                if (component)
                {
                    component.ForceLOD(0);
                }
            }
            int num = 0;

            foreach (Renderer renderer in (!this._destroyTarget) ? base.GetComponentsInChildren <Renderer>() : this._destroyTarget.GetComponentsInChildren <Renderer>())
            {
                GameObject gameObject = renderer.gameObject;
                if (gameObject.activeInHierarchy)
                {
                    Transform transform = renderer.transform;
                    transform.parent = null;
                    gameObject.layer = this._detachedLayer;
                    CapsuleCollider capsuleCollider = gameObject.AddComponent <CapsuleCollider>();
                    capsuleCollider.radius    = 0.1f;
                    capsuleCollider.height    = 1f;
                    capsuleCollider.direction = 2;
                    Rigidbody rigidbody = gameObject.AddComponent <Rigidbody>();
                    if (rigidbody)
                    {
                        rigidbody.AddForce(((transform.position - origin).normalized + Vector3.up) * 2f, ForceMode.Impulse);
                        rigidbody.AddRelativeTorque(Vector3.up * 2f, ForceMode.Impulse);
                        if (gameObject.CompareTag("Log"))
                        {
                            num++;
                        }
                    }
                    destroyAfter destroyAfter = gameObject.AddComponent <destroyAfter>();
                    destroyAfter.destroyTime = 2f;
                }
            }
            if (this._dustPrefab)
            {
                UnityEngine.Object.Instantiate <GameObject>(this._dustPrefab, base.transform.position, base.transform.rotation);
            }
            UnityEngine.Object.Destroy((!this._destroyTarget) ? base.gameObject : this._destroyTarget);
            return(num);
        }
    public static int ForceLOD(IntPtr l)
    {
        int result;

        try
        {
            LODGroup lodgroup = (LODGroup)LuaObject.checkSelf(l);
            int      index;
            LuaObject.checkType(l, 2, out index);
            lodgroup.ForceLOD(index);
            LuaObject.pushValue(l, true);
            result = 1;
        }
        catch (Exception e)
        {
            result = LuaObject.error(l, e);
        }
        return(result);
    }
Exemple #7
0
    //***************************************************************************************
    //Bone rotations, model modification and stick to the terrain
    void LateUpdate()
    {
        spineYaw   = Mathf.Clamp(spineYaw, -16.0F, 16.0F);
        spinePitch = Mathf.Clamp(spinePitch, -9.0F, 9.0F);

        balance   = Mathf.Lerp(balance, -ang * 4, 0.05f);
        spineRoll = spineYaw * spinePitch / 24;


        //Spine/neck/head rotations
        Spine0.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Spine1.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Spine2.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Spine3.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Spine4.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Spine5.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);

        Neck0.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Neck1.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Neck2.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Neck3.transform.rotation *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);
        Head.transform.rotation  *= Quaternion.Euler(-spinePitch, spineRoll, -spineYaw + balance);

        //Tail rotations
        Tail0.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail1.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail2.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail3.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail4.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail5.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail6.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail7.transform.rotation *= Quaternion.Euler(0, 0, -balance);
        Tail8.transform.rotation *= Quaternion.Euler(0, 0, -balance);

        //Arms balance
        Arm1.transform.rotation *= Quaternion.Euler(spinePitch * 8, 0, 0);
        Arm2.transform.rotation *= Quaternion.Euler(0, spinePitch * 8, 0);

        //Disable collision and freeze position
        if (anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|SleepLoop") ||
            anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|Sleep+") ||
            anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|Sleep-") ||
            anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|Die"))
        {
            rg.isKinematic = true;
        }
        else
        {
            rg.isKinematic = false;
        }
        rg.velocity = Vector3.zero; rg.freezeRotation = true;

        //Stick and slip on terrain
        RaycastHit hit; int terrainlayer = 1 << 8;     //terrain layer only

        if (anim.GetInteger("Idle") != 100 && Physics.Raycast(transform.position + transform.up, -transform.up, out hit, Mathf.Infinity, terrainlayer))
        {
            //jump, disable stick to the terrain
            if (!anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|StandJumpUp") &&
                !anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|RunJumpUp") &&
                !anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|JumpLoop") &&
                !anim.GetCurrentAnimatorStateInfo(0).IsName("Comp|JumpLoopAttack"))
            {
                transform.position = new Vector3(transform.position.x, Mathf.Lerp(transform.position.y, hit.point.y, 0.25f), transform.position.z);
            }

            //is on ground ?
            if (Mathf.Round(transform.position.y * 10 - hit.point.y * 10) <= 0)
            {
                anim.SetBool("Onground", true);
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.LookRotation(Vector3.Cross(transform.right, hit.normal), hit.normal), 0.1f);
            }
            else
            {
                anim.SetBool("Onground", false);
                transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, transform.eulerAngles.y, 0), 0.1f);
            }

            //slip on sloped terrain and avoid
            float xs = 0, zs = 0;
            if (Mathf.DeltaAngle(transform.eulerAngles.x, 0.0f) > 25.0f || Mathf.DeltaAngle(transform.eulerAngles.x, 0.0f) < -25.0f ||
                Mathf.DeltaAngle(transform.eulerAngles.z, 0.0f) > 25.0f || Mathf.DeltaAngle(transform.eulerAngles.z, 0.0f) < -25.0f)
            {
                xs = Mathf.Lerp(xs, -Mathf.DeltaAngle(transform.eulerAngles.x, 0.0f) / 10, 0.01f);
                zs = Mathf.Lerp(zs, Mathf.DeltaAngle(transform.eulerAngles.z, 0.0f) / 10, 0.01f);
                if (zs > 0)
                {
                    ang = Mathf.Lerp(ang, 2.0f, 0.05f);
                }
                else
                {
                    ang = Mathf.Lerp(ang, -2.0f, 0.05f);
                }
                transform.Translate(zs, 0, xs);
            }
        }

        //In game switch skin and lod
        foreach (SkinnedMeshRenderer element in rend)
        {
            if (element.isVisible)
            {
                infos = element.sharedMesh.triangles.Length / 3 + " triangles";
            }
            element.materials[0].mainTexture = skin[BodySkin.GetHashCode()];
            element.materials[1].mainTexture = eyes[EyesSkin.GetHashCode()];
            lods.ForceLOD(LodLevel.GetHashCode());
        }

        //Rescale model
        transform.localScale = new Vector3(scale, scale, scale);
        //Mass based on scale
        rg.mass = 4.0f / 0.5f * scale;
    }
    void OnGUI()
    {
        //Skin selection
        if (GUI.Button(new Rect(5, 40, 40, 20), "Skin"))
        {
            if (skinselect != 2)
            {
                skinselect++;
            }
            else
            {
                skinselect = 0;
            }
            rend[0].material.mainTexture = skin[skinselect];
            rend[1].material.mainTexture = skin[skinselect];
            rend[2].material.mainTexture = skin[skinselect];
        }

        //Eyes skin selection
        if (GUI.Button(new Rect(50, 40, 40, 20), "Eyes"))
        {
            if (eyeselect != 15)
            {
                eyeselect++;
            }
            else
            {
                eyeselect = 0;
            }
            rend[0].materials[1].mainTexture = eyes[eyeselect];
            rend[1].materials[1].mainTexture = eyes[eyeselect];
            rend[2].materials[1].mainTexture = eyes[eyeselect];
        }

        //Get mesh infos
        if (rend[0].isVisible)
        {
            infos = rend[0].sharedMesh.triangles.Length / 3 + " triangles";
        }
        else if (rend[1].isVisible)
        {
            infos = rend[1].sharedMesh.triangles.Length / 3 + " triangles";
        }
        else if (rend[2].isVisible)
        {
            infos = rend[2].sharedMesh.triangles.Length / 3 + " triangles";
        }

        //Lod mesh selection
        switch (lodselect)
        {
        case 0: if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_Auto -> " + infos))
            {
                lods.ForceLOD(0); lodselect = 1;
            }
            break;

        case 1: if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_0 -> " + infos))
            {
                lods.ForceLOD(1); lodselect = 2;
            }
            break;

        case 2: if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_1 -> " + infos))
            {
                lods.ForceLOD(2); lodselect = 3;
            }
            break;

        case 3: if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_2 -> " + infos))
            {
                lods.ForceLOD(-1); lodselect = 0;
            }
            break;
        }

        GUI.Box(new Rect(0, 170, 200, 380), "Help");
        GUI.Label(new Rect(5, 200, Screen.width, Screen.height), "Middle Mouse = Camera/Zoom");
        GUI.Label(new Rect(5, 220, Screen.width, Screen.height), "Right Mouse = Spine move");
        GUI.Label(new Rect(5, 240, Screen.width, Screen.height), "Left Mouse = Attack");
        GUI.Label(new Rect(5, 260, Screen.width, Screen.height), "W,A,S,D = Moves");
        GUI.Label(new Rect(5, 280, Screen.width, Screen.height), "LeftShift = Run");
        GUI.Label(new Rect(5, 300, Screen.width, Screen.height), "Space = Jump");
        GUI.Label(new Rect(5, 320, Screen.width, Screen.height), "E = Growl");
        GUI.Label(new Rect(5, 340, Screen.width, Screen.height), "num 1 = IdleA");
        GUI.Label(new Rect(5, 360, Screen.width, Screen.height), "num 2 = IdleB");
        GUI.Label(new Rect(5, 380, Screen.width, Screen.height), "num 3 = IdleC");
        GUI.Label(new Rect(5, 400, Screen.width, Screen.height), "num 4 = Eat");
        GUI.Label(new Rect(5, 420, Screen.width, Screen.height), "num 5 = Drink");
        GUI.Label(new Rect(5, 440, Screen.width, Screen.height), "num 6 = Sleep");
        GUI.Label(new Rect(5, 460, Screen.width, Screen.height), "num 7 = Die");
    }
Exemple #9
0
    void OnGUI()
    {
        switch (skinselect)
        {
        case 0:
            if (GUI.Button(new Rect(5, 40, 80, 20), "Skin A"))
            {
                rend[0].material.mainTexture = skin[1];
                rend[1].material.mainTexture = skin[1];
                rend[2].material.mainTexture = skin[1];
                skinselect = 1;
            }
            break;

        case 1:
            if (GUI.Button(new Rect(5, 40, 80, 20), "Skin B"))
            {
                rend[0].material.mainTexture = skin[2];
                rend[1].material.mainTexture = skin[2];
                rend[2].material.mainTexture = skin[2];
                skinselect = 2;
            }
            break;

        case 2:
            if (GUI.Button(new Rect(5, 40, 80, 20), "Skin C"))
            {
                rend[0].material.mainTexture = skin[0];
                rend[1].material.mainTexture = skin[0];
                rend[2].material.mainTexture = skin[0];
                skinselect = 0;
            }
            break;
        }

        if (rend[0].isVisible)
        {
            infos = rend[0].sharedMesh.triangles.Length / 3 + " triangles";
        }
        else if (rend[1].isVisible)
        {
            infos = rend[1].sharedMesh.triangles.Length / 3 + " triangles";
        }
        else if (rend[2].isVisible)
        {
            infos = rend[2].sharedMesh.triangles.Length / 3 + " triangles";
        }

        switch (lodselect)
        {
        case 0:
            if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_Auto -> " + infos))
            {
                lods.ForceLOD(0);
                lodselect = 1;
            }
            break;

        case 1:
            if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_0 -> " + infos))
            {
                lods.ForceLOD(1);
                lodselect = 2;
            }

            break;

        case 2:
            if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_1 -> " + infos))
            {
                lods.ForceLOD(2);
                lodselect = 3;
            }
            break;

        case 3:
            if (GUI.Button(new Rect(5, 100, 190, 30), "LOD_2 -> " + infos))
            {
                lods.ForceLOD(-1);
                lodselect = 0;
            }
            break;
        }

        GUI.Box(new Rect(0, 170, 200, 380), "Help");
        GUI.Label(new Rect(5, 200, Screen.width, Screen.height), "Middle Mouse = Camera/Zoom");
        GUI.Label(new Rect(5, 220, Screen.width, Screen.height), "Right Mouse = Spine move");
        GUI.Label(new Rect(5, 240, Screen.width, Screen.height), "Left Mouse = Rise");
        GUI.Label(new Rect(5, 260, Screen.width, Screen.height), "W,A,S,D = Moves");
        GUI.Label(new Rect(5, 280, Screen.width, Screen.height), "LeftShift = Run");
        GUI.Label(new Rect(5, 300, Screen.width, Screen.height), "Space = Steps");
        GUI.Label(new Rect(5, 320, Screen.width, Screen.height), "E = Call");
        GUI.Label(new Rect(5, 340, Screen.width, Screen.height), "num 1 = IdleA");
        GUI.Label(new Rect(5, 360, Screen.width, Screen.height), "num 2 = IdleB");
        GUI.Label(new Rect(5, 380, Screen.width, Screen.height), "num 3 = Eat");
        GUI.Label(new Rect(5, 400, Screen.width, Screen.height), "num 4 = Drink");
        GUI.Label(new Rect(5, 420, Screen.width, Screen.height), "num 5 = Sit/Sleep");
        GUI.Label(new Rect(5, 440, Screen.width, Screen.height), "num 6 = Die");
    }
        public static Texture2D GenerateBillboardNew(GameObject prefab, int width, int height, int gridSizeX,
                                                     int gridSizeY, Shader replacementShader, Color backgroundColor, Material minPostfilter,
                                                     LODLevel billboardSourceLODLevel, Quaternion rotationOffset, bool generateAo, bool recalculateNormals, float normalBlendFactor)
        {
#if UNITY_EDITOR
            bool fog = RenderSettings.fog;
            Unsupported.SetRenderSettingsUseFogNoDirty(false);
#endif

            Vector3   renderPosition = new Vector3(0, 0, 0);
            const int invisibleLayer = 31; // used for instance and camera cull

            // atlas size
            var w = width * gridSizeX;
            var h = height * gridSizeY;

            var result      = new Texture2D(w, h);
            var frameBuffer = new RenderTexture(width, height, 24);

            var filteredFrameBuffer = new RenderTexture(width, height, 24);

            var camGo = new GameObject("TempCamera");
            var cam   = camGo.AddComponent <Camera>();

            //if (generateAo)
            //{
            //    ScreenSpaceAmbientOcclusion ao = camGo.AddComponent<ScreenSpaceAmbientOcclusion>();
            //    ao.m_Radius = 0.874f;
            //    ao.m_SampleCount = ScreenSpaceAmbientOcclusion.SSAOSamples.High;
            //    ao.m_OcclusionIntensity = 4;
            //    ao.m_Blur = 4;
            //    ao.m_Downsampling = 6;
            //    ao.m_OcclusionAttenuation = 2;
            //    ao.m_MinZ = 0.0001f;
            //}

            cam.clearFlags = CameraClearFlags.Color;

            backgroundColor.a   = 0;
            cam.backgroundColor = backgroundColor;

            cam.renderingPath = RenderingPath.Forward;



            if (replacementShader != null)
            {
                cam.SetReplacementShader(replacementShader, "");
            }
            //cam.renderingPath = RenderingPath.DeferredShading;
            //cam.gameObject.AddComponent<ReadSpecularOcclusion>();

            var go = Instantiate(prefab, renderPosition, rotationOffset);
            if (recalculateNormals)
            {
                RecalculateMeshNormals(go, normalBlendFactor);
            }

            go.hideFlags = HideFlags.DontSave;

            LODGroup lodGroup = go.GetComponent <LODGroup>();
            if (lodGroup)
            {
                if (lodGroup.fadeMode == LODFadeMode.SpeedTree)
                {
                    lodGroup.ForceLOD((int)billboardSourceLODLevel);
                }
            }

            //MeshFilter meshFilter = go.GetComponent<MeshFilter>();
            //RecalculateMeshNormals(meshFilter.mesh,0);


            var children = go.GetComponentsInChildren <Transform>();
            foreach (var t in children)
            {
                t.gameObject.layer = invisibleLayer;
            }

            var   bounds  = CalculateBounds(go);
            float yOffset = FindLowestMeshYposition(go);

            cam.cullingMask  = 1 << invisibleLayer;
            cam.orthographic = true;


            //var boundsSize = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z) * 2;
            var boundsSize = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
            cam.orthographicSize = boundsSize;
            cam.nearClipPlane    = -boundsSize * 2;
            cam.farClipPlane     = boundsSize * 2;


            //cam.renderingPath = RenderingPath.DeferredShading;
            //float aspect = (float) width/(float)height;
            //float orthographicSize = boundsSize;
            //cam.projectionMatrix = Matrix4x4.Ortho(-orthographicSize * aspect, orthographicSize * aspect, -orthographicSize, orthographicSize, 0, cam.farClipPlane);


            cam.targetTexture = frameBuffer;

            cam.transform.position = renderPosition + new Vector3(0, bounds.extents.y - yOffset / 2, 0); // + yOffset/2

            var xAngleStep = 360f / gridSizeY / 4;
            var yAngleStep = 360f / gridSizeX;


            minPostfilter.SetInt("_UseGammaCorrection", 0);

#if UNITY_EDITOR
#if UNITY_2018_1_OR_NEWER
#else
            if (PlayerSettings.colorSpace == ColorSpace.Linear)
            {
                minPostfilter.SetInt("_UseGammaCorrection", 1);
            }
#endif
#endif


            for (int i = 0; i < gridSizeX; i++)
            {
                for (int j = 0; j < gridSizeY; j++)
                {
                    cam.transform.rotation = Quaternion.AngleAxis(yAngleStep * i, Vector3.up) *
                                             Quaternion.AngleAxis(xAngleStep * j, Vector3.right);
                    cam.Render();

                    RenderTexture.active = filteredFrameBuffer;

                    Graphics.Blit(frameBuffer, minPostfilter);

                    result.ReadPixels(new Rect(0, 0, frameBuffer.width, frameBuffer.height), i * width, j * height);

                    RenderTexture.active = null;
                }
            }

            DestroyImmediate(go);
            DestroyImmediate(camGo);

            result.Apply();

#if UNITY_EDITOR
            Unsupported.SetRenderSettingsUseFogNoDirty(fog);
#endif

            return(result);
        }
Exemple #11
0
        public override GameObject GetGameObject()
        {
            // Instantiate root prefab
            GameObject prefab = GameObject.Instantiate(Resources.Load <GameObject>("Submarine/Build/Aquarium"));

            prefab.name = this.ClassID;

            // Get sub objects
            GameObject model                         = prefab.FindChild("model");
            GameObject bubbles                       = prefab.FindChild("Bubbles");
            GameObject xBubbles                      = bubbles.FindChild("xBubbles");
            GameObject storage                       = prefab.FindChild("StorageRoot");
            GameObject collider                      = prefab.FindChild("Collider");
            GameObject coral                         = model.FindChild("Coral");
            GameObject coral1                        = coral.FindChild("coral_reef_grass_11");
            GameObject coral2                        = coral.FindChild("coral_reef_grass_10");
            GameObject coral3                        = coral.FindChild("coral_reef_grass_09");
            GameObject coral4                        = coral.FindChild("coral_reef_grass_07");
            GameObject coral5                        = coral.FindChild("coral_reef_plant_middle_03");
            GameObject coral6                        = coral.FindChild("coral_reef_small_deco_15_red");
            GameObject coral7                        = coral.FindChild("coral_reef_grass_03_04");
            GameObject coral8                        = coral.FindChild("coral_reef_small_deco_14");
            GameObject coral9                        = coral.FindChild("coral_reef_grass_03_03");
            GameObject coral10                       = coral.FindChild("coral_reef_grass_03_02");
            GameObject coral11                       = coral.FindChild("Coral_reef_purple_fan");
            GameObject aquariumAnim2                 = model.FindChild("Aquarium_animation2");
            GameObject aquariumAnim2Root             = aquariumAnim2.FindChild("root");
            GameObject aquariumAnim2Geo              = aquariumAnim2.FindChild("Aquarium_geo");
            GameObject aquariumAnim2GeoAquarium      = aquariumAnim2Geo.FindChild("Aquarium");
            GameObject aquariumAnim2GeoAquariumGlass = aquariumAnim2Geo.FindChild("Aquarium_glass");
            GameObject aquariumAnim2Fish1            = aquariumAnim2Root.FindChild("fish1");
            GameObject aquariumAnim2Fish2            = aquariumAnim2Root.FindChild("fish2");
            GameObject aquariumAnim2Fish3            = aquariumAnim2Root.FindChild("fish3");
            GameObject aquariumAnim2Fish4            = aquariumAnim2Root.FindChild("fish4");
            GameObject aquariumAnim2Attach4          = aquariumAnim2Fish4.FindChild("fish_attach4");
            GameObject aquariumAnim1                 = model.FindChild("Aquarium_animation");
            GameObject aquariumAnim1Root             = aquariumAnim1.FindChild("root");
            GameObject aquariumAnim1Geo              = aquariumAnim1.FindChild("Aquarium_geo");
            GameObject aquariumAnim1GeoAquarium      = aquariumAnim1Geo.FindChild("Aquarium");
            GameObject aquariumAnim1GeoAquariumGlass = aquariumAnim1Geo.FindChild("Aquarium_glass");
            GameObject aquariumAnim1Fish1            = aquariumAnim1Root.FindChild("fish1");
            GameObject aquariumAnim1Fish2            = aquariumAnim1Root.FindChild("fish2");
            GameObject aquariumAnim1Fish3            = aquariumAnim1Root.FindChild("fish3");
            GameObject aquariumAnim1Fish4            = aquariumAnim1Root.FindChild("fish4");

            // Load resources
#if BELOWZERO
            GameObject greenCoral  = Resources.Load <GameObject>("WorldEntities/flora/shared/coral_reef_small_deco_13");
            GameObject blueCoral   = Resources.Load <GameObject>("WorldEntities/flora/unused/Coral_reef_blue_coral_tubes");
            GameObject brownCoral  = Resources.Load <GameObject>("WorldEntities/flora/shared/coral_reef_brown_coral_tubes_02_01");
            GameObject brownCoral1 = Resources.Load <GameObject>("WorldEntities/flora/shared/coral_reef_brown_coral_tubes_02_03");
#else
            GameObject greenCoral  = Resources.Load <GameObject>("WorldEntities/Doodads/Coral_reef/coral_reef_small_deco_13");
            GameObject blueCoral   = Resources.Load <GameObject>("WorldEntities/Doodads/Coral_reef/Coral_reef_blue_coral_tubes");
            GameObject brownCoral  = Resources.Load <GameObject>("WorldEntities/Doodads/Coral_reef/coral_reef_brown_coral_tubes_02_01");
            GameObject brownCoral1 = Resources.Load <GameObject>("WorldEntities/Doodads/Coral_reef/coral_reef_brown_coral_tubes_02_03");
#endif

            // Setup green coral
            if (greenCoral != null)
            {
                GameObject iGreenCoral = GameObject.Instantiate(greenCoral);
                iGreenCoral.name                    = "SmallDeco13";
                iGreenCoral.transform.parent        = coral.transform;
                iGreenCoral.transform.localScale   *= 0.179f;
                iGreenCoral.transform.localPosition = new Vector3(iGreenCoral.transform.localPosition.x, iGreenCoral.transform.localPosition.y + 0.17f, iGreenCoral.transform.localPosition.z - 0.635f);
                GameObject.DestroyImmediate(iGreenCoral.GetComponent <LargeWorldEntity>());
                GameObject.DestroyImmediate(iGreenCoral.GetComponent <PrefabIdentifier>());
            }

            // Setup blue coral
            if (blueCoral != null)
            {
                coral9.GetComponent <MeshRenderer>().enabled = false;

                GameObject iBlueCoral = GameObject.Instantiate(blueCoral);
                iBlueCoral.name                    = "BlueCoralTubes1";
                iBlueCoral.transform.parent        = coral.transform;
                iBlueCoral.transform.localPosition = Vector3.zero;
                iBlueCoral.transform.localScale   *= 0.31f;
                iBlueCoral.transform.localPosition = new Vector3(iBlueCoral.transform.localPosition.x + 0.22f, iBlueCoral.transform.localPosition.y + 0.16f, iBlueCoral.transform.localPosition.z - 0.77f);
                var lwe = iBlueCoral.GetComponent <LargeWorldEntity>();
                if (lwe != null)
                {
                    GameObject.DestroyImmediate(lwe);
                }
                var lmi = iBlueCoral.GetComponent <LiveMixin>();
                if (lmi != null)
                {
                    GameObject.DestroyImmediate(lmi);
                }
                var pid = iBlueCoral.GetComponent <PrefabIdentifier>();
                if (pid != null)
                {
                    GameObject.DestroyImmediate(pid);
                }

                var blueCoralModel = iBlueCoral.FindChild("Coral_reef_blue_coral_tubes");
                var blueCoralAnim  = blueCoralModel.GetComponent <Animator>();
                var blueCoralBase  = blueCoralModel.FindChild("base1");
                var blueCoralGeos  = blueCoralModel.FindChild("geos");

                LODGroup lodBlueCoral = iBlueCoral.GetComponent <LODGroup>();
                lodBlueCoral.ForceLOD(0);
                LOD[] lods = lodBlueCoral.GetLODs();
                lodBlueCoral.SetLODs(new LOD[] { lods[0] });
                lodBlueCoral.ForceLOD(0);
                lodBlueCoral.size = 3.0f;
            }

            // Setup brown coral 2
            if (brownCoral != null)
            {
                GameObject iBrownCoral = GameObject.Instantiate(brownCoral);
                iBrownCoral.name                       = "BrownCoralTubes2";
                iBrownCoral.transform.parent           = coral.transform;
                iBrownCoral.transform.localPosition    = Vector3.zero;
                iBrownCoral.transform.localScale      *= 0.3f;
                iBrownCoral.transform.localPosition    = new Vector3(iBrownCoral.transform.localPosition.x + 0.249f, iBrownCoral.transform.localPosition.y + 0.17f, iBrownCoral.transform.localPosition.z - 0.26f);
                iBrownCoral.transform.localEulerAngles = new Vector3(iBrownCoral.transform.localEulerAngles.x, iBrownCoral.transform.localEulerAngles.y + 15f, iBrownCoral.transform.localEulerAngles.z);
                var lwe = iBrownCoral.GetComponent <LargeWorldEntity>();
                if (lwe != null)
                {
                    GameObject.DestroyImmediate(lwe);
                }
                var rbo = iBrownCoral.GetComponent <Rigidbody>();
                if (rbo != null)
                {
                    GameObject.DestroyImmediate(rbo);
                }
                var lmi = iBrownCoral.GetComponent <LiveMixin>();
                if (lmi != null)
                {
                    GameObject.DestroyImmediate(lmi);
                }
                var pid = iBrownCoral.GetComponent <PrefabIdentifier>();
                if (pid != null)
                {
                    GameObject.DestroyImmediate(pid);
                }
                var bco = iBrownCoral.GetComponentInChildren <BoxCollider>();
                if (bco != null)
                {
                    GameObject.DestroyImmediate(bco);
                }
                // Scale models
                iBrownCoral.FindChild("coral_reef_brown_coral_tubes_02_01").transform.localScale      *= 0.4f;
                iBrownCoral.FindChild("coral_reef_brown_coral_tubes_02_01_LOD1").transform.localScale *= 0.4f;
                iBrownCoral.FindChild("coral_reef_brown_coral_tubes_02_01_LOD2").transform.localScale *= 0.4f;
                iBrownCoral.FindChild("coral_reef_brown_coral_tubes_02_01_LOD3").transform.localScale *= 0.4f;

                var lodBrownCoral = iBrownCoral.GetComponent <LODGroup>();
                lodBrownCoral.ForceLOD(0);
                LOD[] lods = lodBrownCoral.GetLODs();
                lodBrownCoral.SetLODs(new LOD[] { lods[0] });
                lodBrownCoral.ForceLOD(0);
                lodBrownCoral.size = 3.0f;
            }

            // Setup brown coral 2 bis
            if (brownCoral != null)
            {
                GameObject iBrownCoralB = GameObject.Instantiate(brownCoral);
                iBrownCoralB.name                       = "BrownCoralTubes2";
                iBrownCoralB.transform.parent           = coral.transform;
                iBrownCoralB.transform.localPosition    = Vector3.zero;
                iBrownCoralB.transform.localScale      *= 0.3f;
                iBrownCoralB.transform.localPosition    = new Vector3(iBrownCoralB.transform.localPosition.x - 0.18f, iBrownCoralB.transform.localPosition.y + 0.055f, iBrownCoralB.transform.localPosition.z - 0.115f);
                iBrownCoralB.transform.localEulerAngles = new Vector3(iBrownCoralB.transform.localEulerAngles.x, iBrownCoralB.transform.localEulerAngles.y - 105.0f, iBrownCoralB.transform.localEulerAngles.z + 15.0f);
                var lwe = iBrownCoralB.GetComponent <LargeWorldEntity>();
                if (lwe != null)
                {
                    GameObject.DestroyImmediate(lwe);
                }
                var rbo = iBrownCoralB.GetComponent <Rigidbody>();
                if (rbo != null)
                {
                    GameObject.DestroyImmediate(rbo);
                }
                var lmi = iBrownCoralB.GetComponent <LiveMixin>();
                if (lmi != null)
                {
                    GameObject.DestroyImmediate(lmi);
                }
                var pid = iBrownCoralB.GetComponent <PrefabIdentifier>();
                if (pid != null)
                {
                    GameObject.DestroyImmediate(pid);
                }
                var bco = iBrownCoralB.GetComponentInChildren <BoxCollider>();
                if (bco != null)
                {
                    GameObject.DestroyImmediate(bco);
                }
                // Scale models
                iBrownCoralB.FindChild("coral_reef_brown_coral_tubes_02_01").transform.localScale      *= 0.4f;
                iBrownCoralB.FindChild("coral_reef_brown_coral_tubes_02_01_LOD1").transform.localScale *= 0.4f;
                iBrownCoralB.FindChild("coral_reef_brown_coral_tubes_02_01_LOD2").transform.localScale *= 0.4f;
                iBrownCoralB.FindChild("coral_reef_brown_coral_tubes_02_01_LOD3").transform.localScale *= 0.4f;

                var lodBrownCoral = iBrownCoralB.GetComponent <LODGroup>();
                lodBrownCoral.ForceLOD(0);
                LOD[] lods = lodBrownCoral.GetLODs();
                lodBrownCoral.SetLODs(new LOD[] { lods[0] });
                lodBrownCoral.ForceLOD(0);
                lodBrownCoral.size = 3.0f;

                iBrownCoralB.transform.localScale *= 1.4f;
            }

            // Setup brown coral 1
            if (brownCoral1 != null)
            {
                GameObject iBrownCoral1 = GameObject.Instantiate(brownCoral1);
                iBrownCoral1.name                       = "BrownCoralTubes2";
                iBrownCoral1.transform.parent           = coral.transform;
                iBrownCoral1.transform.localPosition    = Vector3.zero;
                iBrownCoral1.transform.localScale      *= 0.4f;
                iBrownCoral1.transform.localPosition    = new Vector3(iBrownCoral1.transform.localPosition.x - 0.08f, iBrownCoral1.transform.localPosition.y + 0.055f, iBrownCoral1.transform.localPosition.z - 0.1144f);
                iBrownCoral1.transform.localEulerAngles = new Vector3(iBrownCoral1.transform.localEulerAngles.x, iBrownCoral1.transform.localEulerAngles.y - 30.0f, iBrownCoral1.transform.localEulerAngles.z);
                var lwe = iBrownCoral1.GetComponent <LargeWorldEntity>();
                if (lwe != null)
                {
                    GameObject.DestroyImmediate(lwe);
                }
                var rbo = iBrownCoral1.GetComponent <Rigidbody>();
                if (rbo != null)
                {
                    GameObject.DestroyImmediate(rbo);
                }
                var lmi = iBrownCoral1.GetComponent <LiveMixin>();
                if (lmi != null)
                {
                    GameObject.DestroyImmediate(lmi);
                }
                var pid = iBrownCoral1.GetComponent <PrefabIdentifier>();
                if (pid != null)
                {
                    GameObject.DestroyImmediate(pid);
                }
                var bco = iBrownCoral1.GetComponentInChildren <BoxCollider>();
                if (bco != null)
                {
                    GameObject.DestroyImmediate(bco);
                }
                // Scale models
                iBrownCoral1.FindChild("coral_reef_brown_coral_tubes_02_03").transform.localScale      *= 0.4f;
                iBrownCoral1.FindChild("coral_reef_brown_coral_tubes_02_03_LOD1").transform.localScale *= 0.4f;
                iBrownCoral1.FindChild("coral_reef_brown_coral_tubes_02_03_LOD2").transform.localScale *= 0.4f;
                iBrownCoral1.FindChild("coral_reef_brown_coral_tubes_02_03_LOD3").transform.localScale *= 0.4f;
                // Adjust LOD
                var lodBrownCoral = iBrownCoral1.GetComponent <LODGroup>();
                if (lodBrownCoral != null)
                {
                    lodBrownCoral.ForceLOD(0);
                    LOD[] lods = lodBrownCoral.GetLODs();
                    lodBrownCoral.SetLODs(new LOD[] { lods[0] });
                    lodBrownCoral.ForceLOD(0);
                    lodBrownCoral.size = 3.0f;
                }
            }

            // Adjust corals
            coral1.SetActive(false); // petite fougere jaune (gauche)
            coral2.SetActive(false); // grande fougere jaune 1 (droite)
            coral3.SetActive(false); // grande fougere jaune 2 (droite)
            coral4.SetActive(false); // grande fougere jaune 3 (droite)
            coral5.SetActive(false); // grande plante rose (centre gauche)
            coral6.SetActive(false); // corail rouge foncé a petit points blanc (droite)
            coral7.SetActive(false); // plante rose (droite)
            coral8.SetActive(false); // corail bleu foncé a pointes en spirales et bout rouge (gauche)
            coral9.SetActive(false); // plante rose (centre gauche)
            coral10.SetActive(true); // plante rose (centre gauche)
            coral11.SetActive(true); // algue en courone bleu/violet foncée (centre gauche)
            coral.transform.localScale     *= 0.6f;
            coral10.transform.localScale   *= 0.5f;
            coral10.transform.localPosition = new Vector3(coral10.transform.localPosition.x + 0.10f, coral10.transform.localPosition.y - 0.17f, coral10.transform.localPosition.z - 0.43f);
            coral11.transform.localPosition = new Vector3(coral11.transform.localPosition.x - 0.2f, coral11.transform.localPosition.y - 0.23f, coral11.transform.localPosition.z);

            // Adjust aquarium
            aquariumAnim2Geo.transform.localScale    = new Vector3(aquariumAnim2Geo.transform.localScale.x * (1.0f / 0.239f), aquariumAnim2Geo.transform.localScale.y * (1.0f / 0.24f), aquariumAnim2Geo.transform.localScale.z * (1.0f / 0.239f));
            aquariumAnim1Geo.transform.localScale    = new Vector3(aquariumAnim1Geo.transform.localScale.x * (1.0f / 0.239f), aquariumAnim1Geo.transform.localScale.y * (1.0f / 0.24f), aquariumAnim1Geo.transform.localScale.z * (1.0f / 0.239f));
            aquariumAnim2Geo.transform.localPosition = new Vector3(aquariumAnim2Geo.transform.localPosition.x, aquariumAnim2Geo.transform.localPosition.y - (0.20f * (1.0f / 0.24f)), aquariumAnim2Geo.transform.localPosition.z);
            aquariumAnim1Geo.transform.localPosition = new Vector3(aquariumAnim1Geo.transform.localPosition.x, aquariumAnim1Geo.transform.localPosition.y - (0.20f * (1.0f / 0.24f)), aquariumAnim1Geo.transform.localPosition.z);

            aquariumAnim2Geo.transform.localScale    = new Vector3(aquariumAnim2Geo.transform.localScale.x * 0.50f, aquariumAnim2Geo.transform.localScale.y * 0.285f, aquariumAnim2Geo.transform.localScale.z * 0.16f);
            aquariumAnim1Geo.transform.localScale    = new Vector3(aquariumAnim1Geo.transform.localScale.x * 0.50f, aquariumAnim1Geo.transform.localScale.y * 0.285f, aquariumAnim1Geo.transform.localScale.z * 0.16f);
            aquariumAnim2Geo.transform.localPosition = new Vector3(aquariumAnim2Geo.transform.localPosition.x, aquariumAnim2Geo.transform.localPosition.y, aquariumAnim2Geo.transform.localPosition.z + (0.145f * (1.0f / 0.239f)));
            aquariumAnim1Geo.transform.localPosition = new Vector3(aquariumAnim1Geo.transform.localPosition.x, aquariumAnim1Geo.transform.localPosition.y, aquariumAnim1Geo.transform.localPosition.z + (0.145f * (1.0f / 0.239f)));

            aquariumAnim2GeoAquarium.transform.localPosition = new Vector3(aquariumAnim2GeoAquarium.transform.localPosition.x, aquariumAnim2GeoAquarium.transform.localPosition.y, aquariumAnim2GeoAquarium.transform.localPosition.z - ((0.145f * 2.0f) * (1.0f / 0.16f)));
            aquariumAnim1GeoAquarium.transform.localPosition = new Vector3(aquariumAnim1GeoAquarium.transform.localPosition.x, aquariumAnim1GeoAquarium.transform.localPosition.y, aquariumAnim1GeoAquarium.transform.localPosition.z - ((0.145f * 2.0f) * (1.0f / 0.16f)));

            // Adjust fish
            aquariumAnim2Attach4.transform.localScale = new Vector3(aquariumAnim2Attach4.transform.localScale.x * 2.2f, aquariumAnim2Attach4.transform.localScale.y * 2.2f, aquariumAnim2Attach4.transform.localScale.z * 2.2f);

            // Adjust animators
            Animator anim = aquariumAnim1.GetComponent <Animator>();
            anim.transform.localScale    = new Vector3(anim.transform.localScale.x * 0.239f, anim.transform.localScale.y * 0.24f, anim.transform.localScale.z * 0.239f);
            anim.transform.localPosition = new Vector3(anim.transform.localPosition.x + 0.145f, anim.transform.localPosition.y + 0.20f, anim.transform.localPosition.z);
            Animator anim2 = aquariumAnim2.GetComponent <Animator>();
            anim2.transform.localScale    = new Vector3(anim2.transform.localScale.x * 0.239f, anim2.transform.localScale.y * 0.24f, anim2.transform.localScale.z * 0.239f);
            anim2.transform.localPosition = new Vector3(anim2.transform.localPosition.x + 0.145f, anim2.transform.localPosition.y + 0.20f, anim2.transform.localPosition.z);

            // Adjust bubbles
            bubbles.transform.localScale     = new Vector3(bubbles.transform.localScale.x * 0.07f, bubbles.transform.localScale.y * 0.07f, bubbles.transform.localScale.z * 0.07f);
            xBubbles.transform.localScale    = new Vector3(xBubbles.transform.localScale.x * 0.07f, xBubbles.transform.localScale.y * 0.07f, xBubbles.transform.localScale.z * 0.07f);
            xBubbles.transform.localPosition = new Vector3(xBubbles.transform.localPosition.x + 4.0f, xBubbles.transform.localPosition.y + 1.0f, xBubbles.transform.localPosition.z);
            var ps  = xBubbles.GetComponent <ParticleSystem>();
            var psr = xBubbles.GetComponent <ParticleSystemRenderer>();
#pragma warning disable CS0618
            ps.startSize     *= 0.5f;
            ps.startLifetime *= 0.18f;
            ps.startSpeed     = 0f;
            ps.emissionRate   = 6f;
            ps.maxParticles   = 5;
            ps.playbackSpeed *= 0.4f;
#pragma warning restore CS0618
            psr.lengthScale     *= 0.35f;
            psr.maxParticleSize *= 0.35f;
            foreach (Transform tr in xBubbles.transform)
            {
                tr.localPosition = new Vector3(0.5f, 0.0f, 0.0f);
                psr = tr.GetComponent <ParticleSystemRenderer>();
                if (tr.name.StartsWith("xDots", true, CultureInfo.InvariantCulture))
                {
                    ps = tr.GetComponent <ParticleSystem>();
#pragma warning disable CS0618
                    ps.startSize     *= 0.3f;
                    ps.startLifetime *= 0.11f;
                    ps.startSpeed     = 0.3f;
                    ps.emissionRate   = 3f;
                    ps.maxParticles   = 6;
                    ps.playbackSpeed *= 0.5f;
#pragma warning restore CS0618
                    psr.lengthScale     *= 0.11f;
                    psr.maxParticleSize *= 0.11f;
                }
                else if (tr.name.StartsWith("xLateralBubbles", true, CultureInfo.InvariantCulture))
                {
                    psr.enabled = false;
                }
            }

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

            // Adjust tech tag
            var techTag = prefab.GetComponent <TechTag>();
            techTag.type = this.TechType;

            // Adjust contructable
            Constructable constructable = prefab.GetComponent <Constructable>();
            constructable.allowedInBase           = true;
            constructable.allowedInSub            = true;
            constructable.allowedOutside          = true;
            constructable.allowedOnCeiling        = false;
            constructable.allowedOnGround         = true;
            constructable.allowedOnConstructables = true;
#if BELOWZERO
            constructable.allowedUnderwater = true;
#endif
            constructable.controlModelState     = true;
            constructable.deconstructionAllowed = true;
            constructable.rotationEnabled       = true;
            //constructable.model = model;
            constructable.techType = this.TechType;
            constructable.enabled  = true;

            // Adjust constructable bounds
            ConstructableBounds bounds = prefab.GetComponent <ConstructableBounds>();
            bounds.bounds = new OrientedBounds(new Vector3((bounds.bounds.position.x * 0.16f) + (0.145f * 2.0f), bounds.bounds.position.y * 0.285f, bounds.bounds.position.z * 0.5f), bounds.bounds.rotation, new Vector3(bounds.bounds.extents.x * 0.16f, bounds.bounds.extents.y * 0.285f, bounds.bounds.extents.z * 0.5f));

            // Adjust collider
            BoxCollider c = collider.GetComponent <BoxCollider>();
            c.size   = new Vector3(c.size.x * 0.16f, c.size.y * 0.285f, c.size.z * 0.5f);
            c.center = new Vector3((c.center.x * 0.16f) + (0.145f * 2.0f), c.center.y * 0.285f, c.center.z * 0.5f);

            // Adjust aquarium
            var aquarium = prefab.GetComponent <Aquarium>();
            aquarium.storageContainer.width  = 1;
            aquarium.storageContainer.height = 1;
            aquarium.trackObjects            = new GameObject[] { aquariumAnim2Attach4 };

            // Adjust rendering
            var             sas    = prefab.GetComponents <SkyApplier>();
            List <Renderer> rendsA = new List <Renderer>();
            List <Renderer> rendsB = new List <Renderer>();
            int             i      = 0;
            foreach (SkyApplier sa in sas)
            {
                foreach (Renderer rend in sa.renderers)
                {
                    if (string.Compare(rend.name, "Aquarium", true, CultureInfo.InvariantCulture) != 0)
                    {
                        if (ConfigSwitcher.GlowingAquariumGlass && string.Compare(rend.name, "Aquarium_glass", true, CultureInfo.InvariantCulture) == 0)
                        {
                            foreach (Material mat in rend.materials)
                            {
                                mat.EnableKeyword("MARMO_EMISSION");
                                mat.EnableKeyword("MARMO_GLOW");
                                mat.SetFloat("_SpecInt", 16f);
                                mat.SetFloat("_EnableGlow", 1);
                                mat.SetColor("_GlowColor", new Color(0.79f, 0.9785799f, 1.0f, 0.08f));
                                mat.SetFloat("_GlowStrength", 0.18f);
                            }
                        }
                        if (i == 0)
                        {
                            rendsA.Add(rend);
                        }
                        else
                        {
                            rendsB.Add(rend);
                        }
                    }
                }
                i++;
            }
            sas[0].renderers = rendsA.ToArray();
            sas[1].renderers = rendsB.ToArray();
            Renderer[]      tmpRends = prefab.GetAllComponentsInChildren <Renderer>();
            List <Renderer> rends    = new List <Renderer>();
            foreach (Renderer tmpRend in tmpRends)
            {
                if (string.Compare(tmpRend.name, "Aquarium", true, CultureInfo.InvariantCulture) == 0)
                {
                    rends.Add(tmpRend);
                }
            }

            var fixedSa = prefab.AddComponent <SkyApplier>();
            fixedSa.anchorSky    = Skies.Auto;
            fixedSa.dynamic      = true;
            fixedSa.renderers    = rends.ToArray();
            fixedSa.updaterIndex = 0;

            // Adjust bubbles LOD
            var lodBubbles = bubbles.GetComponent <LODGroup>();
            lodBubbles.size *= (1.0f / 0.07f);

            // Remove unwanted elements
            GameObject.DestroyImmediate(aquariumAnim2Fish1);
            GameObject.DestroyImmediate(aquariumAnim2Fish2);
            GameObject.DestroyImmediate(aquariumAnim2Fish3);
            GameObject.DestroyImmediate(aquariumAnim1Fish1);
            GameObject.DestroyImmediate(aquariumAnim1Fish2);
            GameObject.DestroyImmediate(aquariumAnim1Fish3);
            GameObject.DestroyImmediate(aquariumAnim1Fish4);

            // Adjust prefab position
            foreach (Transform tr in prefab.transform)
            {
                tr.transform.localPosition = new Vector3(tr.transform.localPosition.x - 0.29f, tr.transform.localPosition.y, tr.transform.localPosition.z);
            }

            return(prefab);
        }
        public static Texture2D GenerateBillboardNew(GameObject prefab, int width, int height, int gridSizeX,
                                                     int gridSizeY, Shader replacementShader, Color backgroundColor, Material minPostfilter,
                                                     int billboardLodIndex, Quaternion rotationOffset)
        {
#if UNITY_EDITOR
            bool fog = RenderSettings.fog;
            Unsupported.SetRenderSettingsUseFogNoDirty(false);
#endif

            Vector3   renderPosition = new Vector3(0, 0, 0);
            const int invisibleLayer = 31; // used for instance and camera cull

            // atlas size
            var w = width * gridSizeX;
            var h = height * gridSizeY;

            var result      = new Texture2D(w, h);
            var frameBuffer = new RenderTexture(width, height, 24);

            var filteredFrameBuffer = new RenderTexture(width, height, 24);

            var camGo = new GameObject("TempCamera");
            var cam   = camGo.AddComponent <Camera>();

            cam.clearFlags = CameraClearFlags.Color;

            backgroundColor.a   = 0;
            cam.backgroundColor = backgroundColor;

            cam.renderingPath = RenderingPath.Forward;

            if (replacementShader != null)
            {
                cam.SetReplacementShader(replacementShader, "");
            }

            var go = Instantiate(prefab, renderPosition, rotationOffset);
            go.hideFlags = HideFlags.DontSave;

            LODGroup lodGroup = go.GetComponent <LODGroup>();
            if (lodGroup)
            {
                if (lodGroup.fadeMode == LODFadeMode.SpeedTree)
                {
                    int lodGroupIndex = 0;

                    switch (billboardLodIndex)
                    {
                    case 0:
                        lodGroupIndex = 2;
                        break;

                    case 1:
                        lodGroupIndex = 1;
                        break;
                    }
                    lodGroup.ForceLOD(lodGroupIndex);
                }
            }

            //MeshFilter meshFilter = go.GetComponent<MeshFilter>();
            //RecalculateMeshNormals(meshFilter.mesh,0);


            var children = go.GetComponentsInChildren <Transform>();
            foreach (var t in children)
            {
                t.gameObject.layer = invisibleLayer;
            }

            var   bounds  = CalculateBounds(go);
            float yOffset = FindLowestMeshYposition(go);

            cam.cullingMask  = 1 << invisibleLayer;
            cam.orthographic = true;

            //var boundsSize = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z) * 2;
            var boundsSize = Mathf.Max(bounds.extents.x, bounds.extents.y, bounds.extents.z);
            cam.orthographicSize = boundsSize;
            cam.nearClipPlane    = -boundsSize * 2;
            cam.farClipPlane     = boundsSize * 2;

            cam.targetTexture = frameBuffer;

            cam.transform.position = renderPosition + new Vector3(0, bounds.extents.y - yOffset / 2, 0); // + yOffset/2

            var xAngleStep = 360f / gridSizeY / 4;
            var yAngleStep = 360f / gridSizeX;


            minPostfilter.SetInt("_UseGammaCorrection", 0);

#if UNITY_EDITOR
#if UNITY_2018_1_OR_NEWER
#else
            if (PlayerSettings.colorSpace == ColorSpace.Linear)
            {
                minPostfilter.SetInt("_UseGammaCorrection", 1);
            }
#endif
#endif


            for (int i = 0; i < gridSizeX; i++)
            {
                for (int j = 0; j < gridSizeY; j++)
                {
                    cam.transform.rotation = Quaternion.AngleAxis(yAngleStep * i, Vector3.up) *
                                             Quaternion.AngleAxis(xAngleStep * j, Vector3.right);
                    cam.Render();

                    RenderTexture.active = filteredFrameBuffer;

                    Graphics.Blit(frameBuffer, minPostfilter);

                    result.ReadPixels(new Rect(0, 0, frameBuffer.width, frameBuffer.height), i * width, j * height);

                    RenderTexture.active = null;
                }
            }

            DestroyImmediate(go);
            DestroyImmediate(camGo);

            result.Apply();

#if UNITY_EDITOR
            Unsupported.SetRenderSettingsUseFogNoDirty(fog);
#endif

            return(result);
        }