Ejemplo n.º 1
0
    public NativeTexture(string fileName, bool fromStreamingAssets = false)
    {
#if UNITY_ANDROID
        _loader = PngLib.CreateLoader();
        if (!fromStreamingAssets)
        {
            if (!PngLib.LoadWithPath(_loader, fileName))
            {
                Debug.LogError("Load With Path Error");
                return;
            }
        }
        else
        {
            if (!PngLib.LoadFromStreamingAssets(_loader, fileName))
            {
                Debug.LogError("Load From StreamingAssets Error");
                return;
            }
        }

        Width  = PngLib.GetWidth(_loader);
        Height = PngLib.GetHeight(_loader);
        Tex    = new Texture2D(Width, Height, TextureFormat.RGBA32, false);
        PngLib.SetTexture(_loader, Tex.GetNativeTexturePtr());
        NativeTextureManager.Instance.UpdateTexture();
#elif UNITY_IOS
        _loader = PngLib.CreateLoader();
        if (!fromStreamingAssets)
        {
            PngLib.Load(_loader, fileName);
        }
        else
        {
            PngLib.Load(_loader, Path.Combine(Application.streamingAssetsPath, fileName));
        }
        Width  = PngLib.GetWidth(_loader);
        Height = PngLib.GetHeight(_loader);
        Tex    = Texture2D.CreateExternalTexture(Width, Height, TextureFormat.ARGB32, false, true,
                                                 PngLib.GetTexturePtr(_loader));
#endif
    }
Ejemplo n.º 2
0
    public NativeTexture(string fileName)
    {
#if UNITY_ANDROID
        _loader = PngLib.CreateLoader();
        if (!PngLib.LoadWithPath(_loader, fileName))
        {
            Debug.LogError("Load With Path Error");
            return;
        }
        Width  = PngLib.GetWidth(_loader);
        Height = PngLib.GetHeight(_loader);
        Tex    = new Texture2D(Width, Height, TextureFormat.RGBA32, false);
        PngLib.SetTexture(_loader, Tex.GetNativeTexturePtr());
        NativeTextureManager.Instance.UpdateTexture();
#elif UNITY_IOS
        _loader = PngLib.CreateLoader();
        PngLib.Load(_loader, fileName);
        Width  = PngLib.GetWidth(_loader);
        Height = PngLib.GetHeight(_loader);
        Tex    = Texture2D.CreateExternalTexture(Width, Height, TextureFormat.ARGB32, false, true,
                                                 PngLib.GetTexturePtr(_loader));
#endif
    }