void AddFence(GameObject gao, AdditionalTypeFlags type, Material mat, Color color, float height, List <MeshFilter> addMeshes, float fenceHeight = 4f)
        {
            int numBars = 3;

            for (int i = 0; i < numBars; i++)
            {
                GameObject sgao = new GameObject($"Fence {i}");
                sgao.layer = LayerMask.NameToLayer("3D Collision");
                sgao.transform.SetParent(gao.transform);
                sgao.transform.localScale = Vector3.one;
                switch (type)
                {
                case AdditionalTypeFlags.FenceUpLeft:
                    sgao.transform.localPosition = new Vector3(-(0.5f - 0.05f), height, ((float)(i + 0.5f)) / (numBars) - 0.5f);
                    break;

                case AdditionalTypeFlags.FenceUpRight:
                    sgao.transform.localPosition = new Vector3(((float)(i + 0.5f)) / (numBars) - 0.5f, height, 0.5f - 0.05f);
                    break;

                case AdditionalTypeFlags.FenceDownRight:
                    sgao.transform.localPosition = new Vector3((0.5f - 0.05f), height, ((float)(i + 0.5f)) / (numBars) - 0.5f);
                    break;

                case AdditionalTypeFlags.FenceDownLeft:
                    sgao.transform.localPosition = new Vector3(((float)(i + 0.5f)) / (numBars) - 0.5f, height, -(0.5f - 0.05f));
                    break;
                }
                MeshFilter smf = sgao.AddComponent <MeshFilter>();
                smf.mesh = GeometryHelpers.CreateBoxDifferentHeights(0.1f, fenceHeight, fenceHeight, fenceHeight, fenceHeight);
                addMeshes.Add(smf);

                /*MeshRenderer smr = sgao.AddComponent<MeshRenderer>();
                 * smr.sharedMaterial = mat;*/
            }
        }
        public MeshFilter GetGameObject(GameObject parent, int x, int y, Material mat, Unity_IsometricCollisionTile[] collisionData, int levelWidth, int levelHeight, List <MeshFilter> addMeshes)
        {
            GameObject gao = new GameObject();

            gao.name = DebugText;

            gao.layer = LayerMask.NameToLayer("3D Collision");
            gao.transform.SetParent(parent.transform);
            gao.transform.localScale    = Vector3.one;
            gao.transform.localPosition = new Vector3(x + 0.5f, 0, -y - 0.5f);

            Color color;

            if (CollisionColors.ContainsKey(Type))
            {
                color = new Color(CollisionColors[Type].r, CollisionColors[Type].g, CollisionColors[Type].b);
            }
            else
            {
                UnityEngine.Random.InitState((int)Type);
                color = UnityEngine.Random.ColorHSV(0, 1, 0.2f, 1f, 0.8f, 1.0f);
            }
            if ((x + y) % 2 == 1)
            {
                float h, s, v;
                Color.RGBToHSV(color, out h, out s, out v);
                v    -= 0.025f;
                color = Color.HSVToRGB(h, s, v);
            }

            MeshFilter mf = gao.AddComponent <MeshFilter>();

            switch (Type)
            {
            case CollisionType.GBAVV_Slope_4:
                // Regular slope
                float AddHeight = Height + 0.1875f;
                switch (GBAVV_Rotation)
                {
                case 0:
                    mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, Height, Height, AddHeight, AddHeight, color: color);
                    break;

                case 1:
                    mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, AddHeight, Height, Height, AddHeight, color: color);
                    break;

                case 2:
                    mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, AddHeight, AddHeight, Height, Height, color: color);
                    break;

                case 3:
                    mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, Height, AddHeight, AddHeight, Height, color: color);
                    break;

                default:
                    break;
                }
                break;

            case CollisionType.GBAVV_SlopeCorner_5:     // Regular slope corner
                // TODO
                mf.mesh = GeometryHelpers.CreateSlopeCornerOutward(1, Height, Height + 0.1875f, GBAVV_Rotation ?? 0, color: color);
                break;

            case CollisionType.GBAVV_Corner_6:
            case CollisionType.GBAVV_Corner_12:
            case CollisionType.GBAVV_Corner_17:
            case CollisionType.GBAVV_Corner_19:
            case CollisionType.GBAVV_Corner_21:
            case CollisionType.GBAVV_Corner_22:
            case CollisionType.GBAVV_Corner_24:
            case CollisionType.GBAVV_Corner_25:
            case CollisionType.GBAVV_Corner_26:
            case CollisionType.GBAVV_Corner_28:
            case CollisionType.GBAVV_Corner_30:
            case CollisionType.GBAVV_Corner_32:
            case CollisionType.GBAVV_Corner_35:
                mf.mesh = GeometryHelpers.CreateDoubleSplitBox(1, Height, (GBAVV_AdditionalHeight ?? 0f) + Height, GBAVV_Rotation ?? 0, color: color);
                break;

            case CollisionType.GBAVV_Ramp_CornerInward_2:
            case CollisionType.GBAVV_Ramp_CornerInward_15:
            case CollisionType.GBAVV_Ramp_CornerInward_29:
            case CollisionType.GBAVV_Ramp_CornerInward_33:     // Corner inward
                mf.mesh = GeometryHelpers.CreateRampCornerInward(1, Height, Height + 0.1875f, 5, GBAVV_Rotation ?? 0, color: color);
                break;

            case CollisionType.GBAVV_Ramp_CornerOutward_20:
            case CollisionType.GBAVV_Ramp_CornerOutward_31:
            case CollisionType.GBAVV_Ramp_CornerOutward_34:     // Corner outward
                mf.mesh = GeometryHelpers.CreateRampCornerOutward(1, Height, Height + 0.1875f, 5, GBAVV_Rotation ?? 0, color: color);
                break;

            case CollisionType.GBAVV_Ramp_1:
                mf.mesh = GeometryHelpers.CreateRamp(1, Height, Height + 0.1875f, 5, GBAVV_Rotation ?? 0, color: color);
                break;

            case CollisionType.GBAVV_Fence_13:
            case CollisionType.GBAVV_Fence_16:
            case CollisionType.GBAVV_Fence_18:
            case CollisionType.GBAVV_Fence_23:
                mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, Height, Height, Height, Height, color: color);
                var addType = AdditionalTypeFlags.FenceDownRight;
                switch ((GBAVV_Rotation ?? 0) % 4)
                {
                case 0: addType = AdditionalTypeFlags.FenceDownRight; break;

                case 1: addType = AdditionalTypeFlags.FenceDownLeft; break;

                case 2: addType = AdditionalTypeFlags.FenceUpLeft; break;

                case 3: addType = AdditionalTypeFlags.FenceUpRight; break;
                }
                AddFence(gao, addType, mat, color, Height, addMeshes, fenceHeight: (GBAVV_AdditionalHeight ?? 0));
                break;

            default:
                switch (Shape)
                {
                case ShapeType.SlopeUpRight:
                    mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, Height + 1, Height + 1, Height, Height, color: color);
                    break;

                case ShapeType.SlopeUpLeft:
                    mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, Height + 1, Height, Height, Height + 1, color: color);
                    break;

                default:
                    mf.mesh = GeometryHelpers.CreateBoxDifferentHeights(1, Height, Height, Height, Height, color: color);
                    break;
                }
                break;
            }

            /*MeshRenderer mr = gao.AddComponent<MeshRenderer>();
             * mr.sharedMaterial = mat;*/
            if (AddType.HasFlag(AdditionalTypeFlags.FenceUpLeft_RHR))
            {
                var neighborBlock = x > 0 ? collisionData[y * levelWidth + (x - 1)] : null;
                var maxHeight     = Math.Max(Height, neighborBlock?.Height ?? 0);
                AddFence(gao, AdditionalTypeFlags.FenceUpLeft, mat, color, maxHeight, addMeshes);
            }
            if (AddType.HasFlag(AdditionalTypeFlags.FenceUpRight_RHR))
            {
                var neighborBlock = y > 0 ? collisionData[(y - 1) * levelWidth + x] : null;
                var maxHeight     = Math.Max(Height, neighborBlock?.Height ?? 0);
                AddFence(gao, AdditionalTypeFlags.FenceUpRight, mat, color, maxHeight, addMeshes);
            }
            if (AddType.HasFlag(AdditionalTypeFlags.FenceUpLeft))
            {
                AddFence(gao, AdditionalTypeFlags.FenceUpLeft, mat, color, Height, addMeshes);
            }
            if (AddType.HasFlag(AdditionalTypeFlags.FenceUpRight))
            {
                AddFence(gao, AdditionalTypeFlags.FenceUpRight, mat, color, Height, addMeshes);
            }
            if (AddType.HasFlag(AdditionalTypeFlags.FenceDownRight))
            {
                AddFence(gao, AdditionalTypeFlags.FenceDownRight, mat, color, Height, addMeshes);
            }
            if (AddType.HasFlag(AdditionalTypeFlags.FenceDownLeft))
            {
                AddFence(gao, AdditionalTypeFlags.FenceDownLeft, mat, color, Height, addMeshes);
            }

            if (AddType.HasFlag(AdditionalTypeFlags.ClimbUpLeft))
            {
                var neighborBlock = x + 1 < levelWidth ? collisionData[y * levelWidth + (x + 1)] : null;
                var baseHeight    = neighborBlock?.Height ?? 0;
                AddClimb(gao, AdditionalTypeFlags.ClimbUpLeft, mat, color, Height, baseHeight, addMeshes);
            }
            if (AddType.HasFlag(AdditionalTypeFlags.ClimbUpRight))
            {
                var neighborBlock = y + 1 < levelHeight ? collisionData[(y + 1) * levelWidth + x] : null;
                var baseHeight    = neighborBlock?.Height ?? 0;
                AddClimb(gao, AdditionalTypeFlags.ClimbUpRight, mat, color, Height, baseHeight, addMeshes);
            }
            return(mf);
        }