Exemple #1
0
    public static Texture2D CopyTexture(Texture2D srcTex, Texture2D tarTex, Rect drawRect)
    {
        Rect srcRect = new Rect(0f, 0f, (float)srcTex.get_width(), (float)srcTex.get_height());

        if (drawRect.get_x() < 0f)
        {
            srcRect.set_x(srcRect.get_x() - drawRect.get_x());
            srcRect.set_width(srcRect.get_width() + drawRect.get_x());
            drawRect.set_width(drawRect.get_width() + drawRect.get_x());
            drawRect.set_x(0f);
        }
        if (drawRect.get_y() < 0f)
        {
            srcRect.set_y(srcRect.get_y() - drawRect.get_y());
            srcRect.set_height(srcRect.get_height() + drawRect.get_y());
            drawRect.set_height(drawRect.get_height() + drawRect.get_y());
            drawRect.set_y(0f);
        }
        if ((float)tarTex.get_width() < drawRect.get_x() + drawRect.get_width())
        {
            srcRect.set_width(srcRect.get_width() - (drawRect.get_x() + drawRect.get_width() - (float)tarTex.get_width()));
            drawRect.set_width(drawRect.get_width() - (drawRect.get_x() + drawRect.get_width() - (float)tarTex.get_width()));
        }
        if ((float)tarTex.get_height() < drawRect.get_y() + drawRect.get_height())
        {
            srcRect.set_height(srcRect.get_height() - (drawRect.get_y() + drawRect.get_height() - (float)tarTex.get_height()));
            drawRect.set_height(drawRect.get_height() - (drawRect.get_y() + drawRect.get_height() - (float)tarTex.get_height()));
        }
        return(NgTexture.CopyTexture(srcTex, srcRect, tarTex, drawRect));
    }
Exemple #2
0
    public static Texture2D CopyTexture(Texture2D srcTex, Texture2D tarTex, Rect drawRect)
    {
        Rect srcRect = new Rect(0f, 0f, (float)srcTex.width, (float)srcTex.height);

        if (drawRect.x < 0f)
        {
            srcRect.x      -= drawRect.x;
            srcRect.width  += drawRect.x;
            drawRect.width += drawRect.x;
            drawRect.x      = 0f;
        }
        if (drawRect.y < 0f)
        {
            srcRect.y       -= drawRect.y;
            srcRect.height  += drawRect.y;
            drawRect.height += drawRect.y;
            drawRect.y       = 0f;
        }
        if ((float)tarTex.width < drawRect.x + drawRect.width)
        {
            srcRect.width  -= drawRect.x + drawRect.width - (float)tarTex.width;
            drawRect.width -= drawRect.x + drawRect.width - (float)tarTex.width;
        }
        if ((float)tarTex.height < drawRect.y + drawRect.height)
        {
            srcRect.height  -= drawRect.y + drawRect.height - (float)tarTex.height;
            drawRect.height -= drawRect.y + drawRect.height - (float)tarTex.height;
        }
        return(NgTexture.CopyTexture(srcTex, srcRect, tarTex, drawRect));
    }
Exemple #3
0
 public static int FindTextureIndex(List <Texture2D> findList, Texture2D findTex)
 {
     for (int i = 0; i < findList.get_Count(); i++)
     {
         if (NgTexture.CompareTexture(findList.get_Item(i), findTex))
         {
             return(i);
         }
     }
     return(-1);
 }
Exemple #4
0
 public static Texture2D FindTexture(List <Texture2D> findList, Texture2D findTex)
 {
     for (int i = 0; i < findList.get_Count(); i++)
     {
         if (NgTexture.CompareTexture(findList.get_Item(i), findTex))
         {
             return(findList.get_Item(i));
         }
     }
     return(null);
 }
Exemple #5
0
 public static Texture2D FindTexture(List <Texture2D> findList, Texture2D findTex)
 {
     for (int i = 0; i < findList.Count; i++)
     {
         if (NgTexture.CompareTexture(findList[i], findTex))
         {
             return(findList[i]);
         }
     }
     return(null);
 }
Exemple #6
0
    // ---------------------------------------------------------------------
    public string EndCapture(Texture2D[] SpriteTextures)
    {
#if UNITY_WEBPLAYER
        Debug.LogError("In WEB_PLAYER mode, you cannot run the FXMaker.");
        Debug.Break();
        return(null);
#else
        int       nTexSize      = m_nResultTextureSize;
        int       nCapSize      = m_nResultCaptureSize;
        int       nMaxCount     = (nTexSize / nCapSize) * (nTexSize / nCapSize);
        int       nTexHeight    = (m_nSaveFrameCount <= nMaxCount / 2 ? nTexSize / 2 : nTexSize);
        Texture2D spriteTexture = new Texture2D(nTexSize, nTexHeight, TextureFormat.ARGB32, false);
        int       nSaveCount    = 0;

        for (int x = 0; x < spriteTexture.width; x++)
        {
            for (int y = 0; y < spriteTexture.height; y++)
            {
                spriteTexture.SetPixel(x, y, Color.black);
            }
        }

        for (int n = m_nSkipFrameCount; n < m_nTotalFrameCount; n++, nSaveCount++)
        {
            Color[] srcColors = SpriteTextures[n].GetPixels(0);

            if (m_ShaderType == SHADER_TYPE.ALPHA_BLENDED || m_ShaderType == SHADER_TYPE.ALPHA_BLENDED_MOBILE)
            {
                srcColors = NgAtlas.ConvertAlphaTexture(srcColors, true, FXMakerOption.inst.m_AlphaWeightCurve, 1, 1, 1);
            }
            spriteTexture.SetPixels(((nSaveCount) % (nTexSize / nCapSize)) * nCapSize, nTexHeight - (((nSaveCount) / (nTexSize / nCapSize) + 1) * nCapSize), nCapSize, nCapSize, srcColors);
            Object.DestroyImmediate(SpriteTextures[n]);
        }

        byte[] bytes = spriteTexture.EncodeToPNG();
        string texBasePath;
        if (FXMakerLayout.m_bDevelopState)
        {
            texBasePath = FXMakerMain.inst.GetResourceDir(FXMakerMain.TOOLDIR_TYPE.SPRITE_TOOL);
        }
        else
        {
            texBasePath = FXMakerMain.inst.GetResourceDir(FXMakerMain.TOOLDIR_TYPE.SPRITE_USER);
        }
        string pathTexture = NgTexture.UniqueTexturePath(texBasePath, m_SelectedPrefabName);

        // save texture
        File.WriteAllBytes(pathTexture, bytes);
        AssetDatabase.Refresh();
        NgTexture.ReimportTexture(pathTexture, m_bGUITexture, m_wrapMode, m_filterMode, m_anisoLevel, m_nSpriteTextureSizes[(int)m_fSpriteTextureIndex], m_SpriteTextureFormat[(int)m_fSpriteTextureFormatIdx]);
        Object.DestroyImmediate(spriteTexture);

        // Create Prefab
        if (m_bCreatePrefab)
        {
            string     pathMaterial = CreateMaterial(pathTexture);
            Material   newMat       = (Material)AssetDatabase.LoadAssetAtPath(pathMaterial, typeof(Material));
            GameObject newPrefab    = (GameObject)Instantiate(FXMakerMain.inst.m_FXMakerSpritePrefab);

            newPrefab.transform.rotation = Quaternion.identity;
            newPrefab.GetComponent <Renderer>().material = newMat;
            NcSpriteAnimation spriteCom = newPrefab.GetComponent <NcSpriteAnimation>();
            spriteCom.m_bBuildSpriteObj = true;
            spriteCom.m_nFrameCount     = m_nSaveFrameCount;
            spriteCom.m_fFps            = m_nResultFps;
            spriteCom.m_nTilingX        = m_nResultTextureSize / m_nResultCaptureSize;
            spriteCom.m_nTilingY        = (m_nSaveFrameCount <= spriteCom.m_nTilingX * spriteCom.m_nTilingX / 2 ? spriteCom.m_nTilingX / 2 : spriteCom.m_nTilingX);
            spriteCom.m_PlayMode        = m_PlayMode;
            spriteCom.m_bLoop           = m_bLoop;
            spriteCom.m_nLoopStartFrame = 0;
            spriteCom.m_nLoopFrameCount = spriteCom.m_nFrameCount;
            spriteCom.m_nLoopingCount   = 0;

            spriteCom.m_bAutoDestruct = !m_bLoop;

            NcCurveAnimation curveCom = newPrefab.GetComponent <NcCurveAnimation>();
            if (curveCom.GetCurveInfoCount() != 3)
            {
                Debug.LogError("FXMakerMain.inst.m_FxmSpritePrefab : curveCom Count Error!!!");
            }

            curveCom.GetCurveInfo(0).m_bEnabled = false;                        // both
            curveCom.GetCurveInfo(1).m_bEnabled = false;                        // fadein
            curveCom.GetCurveInfo(2).m_bEnabled = false;                        // fadeout
            curveCom.m_bAutoDestruct            = false;
            curveCom.m_fDurationTime            = spriteCom.GetDurationTime();

            if (m_bFadeIn && m_bFadeOut)
            {
                curveCom.GetCurveInfo(0).m_bEnabled = true;
            }
            else
            {
                if (m_bFadeIn)
                {
                    curveCom.GetCurveInfo(1).m_bEnabled = true;
                }
                if (m_bFadeOut)
                {
                    curveCom.GetCurveInfo(2).m_bEnabled = true;
                }
            }

            string     basePath     = AssetDatabase.GetAssetPath(FXMakerMain.inst.GetOriginalEffectPrefab());
            string     prefabPath   = UniquePrefabPath(NgFile.TrimFilenameExt(basePath));
            GameObject createPrefab = PrefabUtility.CreatePrefab(prefabPath, newPrefab);
            Destroy(newPrefab);

            // Create Thumb
            CreateSpriteThumb(createPrefab, pathTexture);

            AssetDatabase.SaveAssets();

            return(prefabPath);
        }
        else
        {
            return(pathTexture);
        }
#endif
    }
Exemple #7
0
    public static NcSpriteFactory.NcFrameInfo[] TrimTexture(Texture2D srcTex, bool bTrimBlack, bool bTrimAlpha, int nTileX, int nTileY, int nStartFrame, 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 % 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, 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);
    }