public static void UpdatePlane(MeshFilter meshFilter, float fUvScale, NcSpriteFactory.NcFrameInfo ncSpriteFrameInfo, bool bTrimCenterAlign, NcSpriteFactory.ALIGN_TYPE alignType, float fHShowRate)
    {
        Vector2 vector        = new Vector2(fUvScale * ncSpriteFrameInfo.m_FrameScale.x, fUvScale * ncSpriteFrameInfo.m_FrameScale.y);
        float   num           = (alignType != NcSpriteFactory.ALIGN_TYPE.BOTTOM) ? ((alignType != NcSpriteFactory.ALIGN_TYPE.TOP) ? 0f : (-1f * vector.y)) : (1f * vector.y);
        float   num2          = (alignType != NcSpriteFactory.ALIGN_TYPE.LEFTCENTER) ? ((alignType != NcSpriteFactory.ALIGN_TYPE.RIGHTCENTER) ? 0f : (-1f * vector.x)) : (1f * vector.x);
        Rect    frameUvOffset = ncSpriteFrameInfo.m_FrameUvOffset;

        if (bTrimCenterAlign)
        {
            frameUvOffset.center = Vector2.zero;
        }
        Vector3[] array = new Vector3[4];
        if (alignType == NcSpriteFactory.ALIGN_TYPE.LEFTCENTER && 0f < fHShowRate)
        {
            array[0] = new Vector3(frameUvOffset.xMax * vector.x * fHShowRate + num2 * fHShowRate, frameUvOffset.yMax * vector.y + num);
            array[1] = new Vector3(frameUvOffset.xMax * vector.x * fHShowRate + num2 * fHShowRate, frameUvOffset.yMin * vector.y + num);
        }
        else
        {
            array[0] = new Vector3(frameUvOffset.xMax * vector.x + num2, frameUvOffset.yMax * vector.y + num);
            array[1] = new Vector3(frameUvOffset.xMax * vector.x + num2, frameUvOffset.yMin * vector.y + num);
        }
        array[2] = new Vector3(frameUvOffset.xMin * vector.x, frameUvOffset.yMin * vector.y + num);
        array[3] = new Vector3(frameUvOffset.xMin * vector.x, frameUvOffset.yMax * vector.y + num);
        meshFilter.mesh.vertices = array;
        meshFilter.mesh.RecalculateBounds();
    }
Beispiel #2
0
    public static NcSpriteFactory.NcFrameInfo[] TrimTexture(Texture2D srcTex, bool bTrimBlack, bool bTrimAlpha, int nTileX, int nTileY, int nStartFrame, int nFrameCount, ref List <Texture2D> frameTextures, out bool bFindAlpha, out bool bFindBlack)
    {
        Rect      newRect;
        int       nFrameWidth  = srcTex.width / nTileX;
        int       nFrameHeight = srcTex.height / nTileY;
        Texture2D frameTex     = new Texture2D(nFrameWidth, nFrameHeight, TextureFormat.ARGB32, false);

        NcSpriteFactory.NcFrameInfo[] ncFrameInfos = new NcSpriteFactory.NcFrameInfo[nFrameCount];
        bFindAlpha = false;
        bFindBlack = false;

        for (int n = nStartFrame; n < nStartFrame + nFrameCount; n++)
        {
            int nIndex = n - nStartFrame;
            ncFrameInfos[nIndex] = new NcSpriteFactory.NcFrameInfo();
            frameTex.SetPixels(srcTex.GetPixels(nFrameWidth * (n % nTileX), srcTex.height - (nFrameHeight * (n / nTileX + 1)), nFrameWidth, nFrameHeight));

            if (bTrimAlpha || bTrimBlack)
            {
                bool bOutAlpha;
                bool bOutBlack;
                newRect = GetTrimRect(frameTex, bTrimAlpha, bTrimBlack, out bOutAlpha, out bOutBlack);
                if (bOutAlpha)
                {
                    bFindAlpha = true;
                }
                if (bOutBlack)
                {
                    bFindBlack = true;
                }
            }
            else
            {
                newRect = new Rect(0, 0, nFrameWidth, nFrameHeight);
            }

            Texture2D newTex = GetTrimTexture(frameTex, newRect);
            GetTrimOffsets(frameTex, newRect, ref ncFrameInfos[nIndex].m_FrameUvOffset);
            ncFrameInfos[nIndex].m_FrameScale = new Vector2(frameTex.width / 128.0f, frameTex.height / 128.0f);

            ncFrameInfos[nIndex].m_scaleFactor.x = (nFrameWidth / newRect.width) * 0.5f;
            ncFrameInfos[nIndex].m_scaleFactor.y = (nFrameHeight / newRect.height) * 0.5f;

            ncFrameInfos[nIndex].m_nFrameIndex = frameTextures.Count;
            ncFrameInfos[nIndex].m_nTexWidth   = nFrameWidth;
            ncFrameInfos[nIndex].m_nTexHeight  = nFrameHeight;

            frameTextures.Add(newTex);
        }
        Object.DestroyImmediate(frameTex);
        return(ncFrameInfos);
    }
Beispiel #3
0
    public static void UpdatePlane(MeshFilter meshFilter, float fUvScale, NcSpriteFactory.NcFrameInfo ncSpriteFrameInfo, NcSpriteFactory.ALIGN_TYPE alignType)
    {
        Vector2 vector = new Vector2(fUvScale * ncSpriteFrameInfo.m_FrameScale.x, fUvScale * ncSpriteFrameInfo.m_FrameScale.y);
        float   num    = (alignType != NcSpriteFactory.ALIGN_TYPE.BOTTOM) ? ((alignType != NcSpriteFactory.ALIGN_TYPE.TOP) ? 0f : (-1f * vector.y)) : (1f * vector.y);

        Vector3[] vertices = new Vector3[]
        {
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMax * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMax * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMax * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMin * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMin * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMin * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMin * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMax * vector.y + num)
        };
        meshFilter.mesh.vertices = vertices;
        meshFilter.mesh.RecalculateBounds();
    }
    public static void UpdatePlane(MeshFilter meshFilter, float fUvScale, NcSpriteFactory.NcFrameInfo ncSpriteFrameInfo, bool bTrimCenterAlign, NcSpriteFactory.ALIGN_TYPE alignType)
    {
        Vector2 vector        = new Vector2(fUvScale * ncSpriteFrameInfo.m_FrameScale.x, fUvScale * ncSpriteFrameInfo.m_FrameScale.y);
        float   num           = (alignType == NcSpriteFactory.ALIGN_TYPE.BOTTOM) ? (1f * vector.y) : ((alignType == NcSpriteFactory.ALIGN_TYPE.TOP) ? (-1f * vector.y) : 0f);
        Rect    frameUvOffset = ncSpriteFrameInfo.m_FrameUvOffset;

        if (bTrimCenterAlign)
        {
            frameUvOffset.center = Vector2.zero;
        }
        Vector3[] vertices = new Vector3[]
        {
            new Vector3(frameUvOffset.xMax * vector.x, frameUvOffset.yMax * vector.y + num),
            new Vector3(frameUvOffset.xMax * vector.x, frameUvOffset.yMin * vector.y + num),
            new Vector3(frameUvOffset.xMin * vector.x, frameUvOffset.yMin * vector.y + num),
            new Vector3(frameUvOffset.xMin * vector.x, frameUvOffset.yMax * vector.y + num)
        };
        meshFilter.mesh.vertices = vertices;
        meshFilter.mesh.RecalculateBounds();
    }
Beispiel #5
0
    public static void CreatePlane(MeshFilter meshFilter, float fUvScale, NcSpriteFactory.NcFrameInfo ncSpriteFrameInfo, NcSpriteFactory.ALIGN_TYPE alignType, NcSpriteFactory.MESH_TYPE m_MeshType)
    {
        Vector2 vector = new Vector2(fUvScale * ncSpriteFrameInfo.m_FrameScale.x, fUvScale * ncSpriteFrameInfo.m_FrameScale.y);
        float   num    = (alignType != NcSpriteFactory.ALIGN_TYPE.BOTTOM) ? ((alignType != NcSpriteFactory.ALIGN_TYPE.TOP) ? 0f : (-1f * vector.y)) : (1f * vector.y);

        Vector3[] vertices = new Vector3[]
        {
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMax * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMax * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMax * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMin * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMin * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMin * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.xMin * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.yMax * vector.y + num)
        };
        Color[] colors = new Color[]
        {
            Color.white,
            Color.white,
            Color.white,
            Color.white
        };
        Vector3[] normals = new Vector3[]
        {
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f)
        };
        Vector4[] tangents = new Vector4[]
        {
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f)
        };
        int[] triangles;
        if (m_MeshType == NcSpriteFactory.MESH_TYPE.BuiltIn_Plane)
        {
            triangles = new int[]
            {
                1,
                2,
                0,
                0,
                2,
                3
            };
        }
        else
        {
            triangles = new int[]
            {
                1,
                2,
                0,
                0,
                2,
                3,
                1,
                0,
                3,
                3,
                2,
                1
            };
        }
        Vector2[] uv = new Vector2[]
        {
            new Vector2(1f, 1f),
            new Vector2(1f, 0f),
            new Vector2(0f, 0f),
            new Vector2(0f, 1f)
        };
        meshFilter.mesh.Clear();
        meshFilter.mesh.vertices  = vertices;
        meshFilter.mesh.colors    = colors;
        meshFilter.mesh.normals   = normals;
        meshFilter.mesh.tangents  = tangents;
        meshFilter.mesh.triangles = triangles;
        meshFilter.mesh.uv        = uv;
        meshFilter.mesh.RecalculateBounds();
    }
Beispiel #6
0
    public static NcSpriteFactory.NcFrameInfo[] TrimTexture(Texture2D srcTex, bool bTrimBlack, bool bTrimAlpha, int nTileX, int nTileY, int nStartFrame, int nSkipFrame, int nFrameCount, ref List<Texture2D> frameTextures, ref List<Rect> frameRects, out bool bFindAlpha, out bool bFindBlack)
    {
        Rect		newRect;
        int			nFrameWidth	= srcTex.width	/ nTileX;
        int			nFrameHeight= srcTex.height	/ nTileY;
        Texture2D	frameTex	= new Texture2D(nFrameWidth, nFrameHeight, TextureFormat.ARGB32, false);

        NcSpriteFactory.NcFrameInfo[] ncFrameInfos = new NcSpriteFactory.NcFrameInfo[nFrameCount];
        bFindAlpha	= false;
        bFindBlack	= false;

        for (int n = nStartFrame; n < nStartFrame+nFrameCount; n++)
        {
            bool	bEmptyTexture = false;
            int		nIndex = n-nStartFrame;
            ncFrameInfos[nIndex] = new NcSpriteFactory.NcFrameInfo();
            frameTex.SetPixels(srcTex.GetPixels(nFrameWidth * ((n + (nIndex * nSkipFrame)) % nTileX), srcTex.height - (nFrameHeight * ((n + (nIndex * nSkipFrame)) / nTileX + 1)), nFrameWidth, nFrameHeight));

            if (bTrimAlpha || bTrimBlack)
            {
                bool bOutAlpha;
                bool bOutBlack;
                newRect = GetTrimRect(frameTex, bTrimAlpha, bTrimBlack, out bOutAlpha, out bOutBlack, out bEmptyTexture);
                if (bOutAlpha)
                    bFindAlpha	= true;
                if (bOutBlack)
                    bFindBlack	= true;
            }
            else newRect = new Rect(0, 0, nFrameWidth, nFrameHeight);

            Texture2D	newTex		= GetTrimTexture(frameTex, newRect);
            int			nTexIndex	= NgTexture.FindTextureIndex(frameTextures, newTex);

            if (0 <= nTexIndex)
            {
                Object.DestroyImmediate(newTex);
                newTex		= frameTextures[nTexIndex];
                newRect		= frameRects[nTexIndex];
            } else {
                nTexIndex = frameTextures.Count;
                frameTextures.Add(newTex);
                frameRects.Add(newRect);
            }

            GetTrimOffsets(frameTex, newRect, ref ncFrameInfos[nIndex].m_FrameUvOffset);
            ncFrameInfos[nIndex].m_FrameScale		= new Vector2(frameTex.width / 128.0f, frameTex.height / 128.0f);

            ncFrameInfos[nIndex].m_scaleFactor.x	= (nFrameWidth  / newRect.width ) * 0.5f;
            ncFrameInfos[nIndex].m_scaleFactor.y	= (nFrameHeight / newRect.height) * 0.5f;

            ncFrameInfos[nIndex].m_nFrameIndex		= nTexIndex;
            ncFrameInfos[nIndex].m_nTexWidth		= nFrameWidth;
            ncFrameInfos[nIndex].m_nTexHeight		= nFrameHeight;
            ncFrameInfos[nIndex].m_bEmptyFrame		= bEmptyTexture;
        }
        Object.DestroyImmediate(frameTex);
        return ncFrameInfos;
    }
Beispiel #7
0
    public static void CreatePlane(MeshFilter meshFilter, float fUvScale, NcSpriteFactory.NcFrameInfo ncSpriteFrameInfo, NcSpriteFactory.ALIGN_TYPE alignType, NcSpriteFactory.MESH_TYPE m_MeshType)
    {
        Vector2 vector = new Vector2(fUvScale * ncSpriteFrameInfo.m_FrameScale.x, fUvScale * ncSpriteFrameInfo.m_FrameScale.y);
        float   num    = (alignType != NcSpriteFactory.ALIGN_TYPE.BOTTOM) ? ((alignType != NcSpriteFactory.ALIGN_TYPE.TOP) ? 0f : (-1f * vector.y)) : (1f * vector.y);

        Vector3[] vertices = new Vector3[]
        {
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.get_xMax() * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.get_yMax() * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.get_xMax() * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.get_yMin() * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.get_xMin() * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.get_yMin() * vector.y + num),
            new Vector3(ncSpriteFrameInfo.m_FrameUvOffset.get_xMin() * vector.x, ncSpriteFrameInfo.m_FrameUvOffset.get_yMax() * vector.y + num)
        };
        Color[] colors = new Color[]
        {
            Color.get_white(),
                Color.get_white(),
                Color.get_white(),
                Color.get_white()
        };
        Vector3[] normals = new Vector3[]
        {
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f)
        };
        Vector4[] tangents = new Vector4[]
        {
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f)
        };
        int[] triangles;
        if (m_MeshType == NcSpriteFactory.MESH_TYPE.BuiltIn_Plane)
        {
            triangles = new int[]
            {
                1,
                2,
                0,
                0,
                2,
                3
            };
        }
        else
        {
            triangles = new int[]
            {
                1,
                2,
                0,
                0,
                2,
                3,
                1,
                0,
                3,
                3,
                2,
                1
            };
        }
        Vector2[] uv = new Vector2[]
        {
            new Vector2(1f, 1f),
            new Vector2(1f, 0f),
            new Vector2(0f, 0f),
            new Vector2(0f, 1f)
        };
        meshFilter.get_mesh().Clear();
        meshFilter.get_mesh().set_vertices(vertices);
        meshFilter.get_mesh().set_colors(colors);
        meshFilter.get_mesh().set_normals(normals);
        meshFilter.get_mesh().set_tangents(tangents);
        meshFilter.get_mesh().set_triangles(triangles);
        meshFilter.get_mesh().set_uv(uv);
        meshFilter.get_mesh().RecalculateBounds();
    }
    public static void CreatePlane(MeshFilter meshFilter, float fUvScale, NcSpriteFactory.NcFrameInfo ncSpriteFrameInfo, bool bTrimCenterAlign, NcSpriteFactory.ALIGN_TYPE alignType, NcSpriteFactory.MESH_TYPE m_MeshType, float fHShowRate)
    {
        Vector2 vector        = new Vector2(fUvScale * ncSpriteFrameInfo.m_FrameScale.x, fUvScale * ncSpriteFrameInfo.m_FrameScale.y);
        float   num           = (alignType != NcSpriteFactory.ALIGN_TYPE.BOTTOM) ? ((alignType != NcSpriteFactory.ALIGN_TYPE.TOP) ? 0f : (-1f * vector.y)) : (1f * vector.y);
        float   num2          = (alignType != NcSpriteFactory.ALIGN_TYPE.LEFTCENTER) ? ((alignType != NcSpriteFactory.ALIGN_TYPE.RIGHTCENTER) ? 0f : (-1f * vector.x)) : (1f * vector.x);
        Rect    frameUvOffset = ncSpriteFrameInfo.m_FrameUvOffset;

        if (bTrimCenterAlign)
        {
            frameUvOffset.center = Vector2.zero;
        }
        Vector3[] array = new Vector3[4];
        if (alignType == NcSpriteFactory.ALIGN_TYPE.LEFTCENTER && 0f < fHShowRate)
        {
            array[0] = new Vector3(frameUvOffset.xMax * vector.x * fHShowRate + num2 * fHShowRate, frameUvOffset.yMax * vector.y + num);
            array[1] = new Vector3(frameUvOffset.xMax * vector.x * fHShowRate + num2 * fHShowRate, frameUvOffset.yMin * vector.y + num);
        }
        else
        {
            array[0] = new Vector3(frameUvOffset.xMax * vector.x + num2, frameUvOffset.yMax * vector.y + num);
            array[1] = new Vector3(frameUvOffset.xMax * vector.x + num2, frameUvOffset.yMin * vector.y + num);
        }
        array[2] = new Vector3(frameUvOffset.xMin * vector.x + num2, frameUvOffset.yMin * vector.y + num);
        array[3] = new Vector3(frameUvOffset.xMin * vector.x + num2, frameUvOffset.yMax * vector.y + num);
        Color color = Color.white;

        if (meshFilter.mesh.colors != null && 0 < meshFilter.mesh.colors.Length)
        {
            color = meshFilter.mesh.colors[0];
        }
        Color[] colors = new Color[]
        {
            color,
            color,
            color,
            color
        };
        Vector3[] normals = new Vector3[]
        {
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f),
            new Vector3(0f, 0f, -1f)
        };
        Vector4[] tangents = new Vector4[]
        {
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f),
            new Vector4(1f, 0f, 0f, -1f)
        };
        int[] triangles;
        if (m_MeshType == NcSpriteFactory.MESH_TYPE.BuiltIn_Plane)
        {
            triangles = new int[]
            {
                1,
                2,
                0,
                0,
                2,
                3
            };
        }
        else
        {
            triangles = new int[]
            {
                1,
                2,
                0,
                0,
                2,
                3,
                1,
                0,
                3,
                3,
                2,
                1
            };
        }
        Vector2[] array2 = new Vector2[4];
        float     x      = 1f;

        if (alignType == NcSpriteFactory.ALIGN_TYPE.LEFTCENTER && 0f < fHShowRate)
        {
            x = fHShowRate;
        }
        array2[0] = new Vector2(x, 1f);
        array2[1] = new Vector2(x, 0f);
        array2[2] = new Vector2(0f, 0f);
        array2[3] = new Vector2(0f, 1f);
        meshFilter.mesh.Clear();
        meshFilter.mesh.vertices  = array;
        meshFilter.mesh.colors    = colors;
        meshFilter.mesh.normals   = normals;
        meshFilter.mesh.tangents  = tangents;
        meshFilter.mesh.triangles = triangles;
        meshFilter.mesh.uv        = array2;
        meshFilter.mesh.RecalculateBounds();
    }