Last active
April 4, 2018 08:32
-
-
Save nicloay/cfa365f3ffec52e0cf0b8efb16060b46 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using PaintCraft.Canvas.Configs; | |
using System.IO; | |
namespace PaintCraft.Canvas.Configs{ | |
[CreateAssetMenu(menuName = "PaintCraft/StreamingColoringPageConfig")] | |
public class StreamingColoringPageConfig : AdvancedPageConfig | |
{ | |
public Sprite Icon; | |
public string OutlinePngPath; | |
public string RegionPngPath; | |
Texture2D outlineTexture; | |
Texture2D regionTexture; | |
#region implemented abstract members of PageConfig | |
public override Vector2 GetSize() | |
{ | |
return new Vector2(OutlineTexture.width, OutlineTexture.height); | |
} | |
#endregion | |
#region implemented abstract members of AdvancedPageConfig | |
public override Texture2D OutlineTexture | |
{ | |
get | |
{ | |
if (outlineTexture == null){ | |
outlineTexture = GetStreamingTexture(OutlinePngPath); | |
} | |
return outlineTexture; | |
} | |
} | |
public override Texture2D RegionTexture | |
{ | |
get | |
{ | |
if (regionTexture == null){ | |
regionTexture = GetStreamingTexture(RegionPngPath); | |
} | |
return regionTexture; | |
} | |
} | |
#endregion | |
Texture2D GetStreamingTexture(string texturePath){ | |
string path = Path.Combine(Application.streamingAssetsPath, texturePath); | |
if (!path.Contains("://")) | |
{ | |
path = "file://" + path; | |
} | |
Debug.Log("Path >>> "+path); | |
WWW www = new WWW(path); | |
while (!www.isDone) | |
{ | |
//wait | |
} | |
if (!string.IsNullOrEmpty(www.error)) | |
{ | |
Debug.LogError(www.error); | |
} | |
byte[] bytes = www.bytes; | |
Texture2D result = new Texture2D(1,1, TextureFormat.RGBA32, false); | |
#if UNITY_5_4 || UNITY_5_4_OR_NEWER | |
result.LoadImage(bytes, true); | |
#else | |
result.LoadImage(bytes); | |
#endif | |
return result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment