Skip to content

Commit 51c361b

Browse files
committed
Make demo
1 parent 8cbd36d commit 51c361b

13 files changed

+742
-1
lines changed

Assets/Mochineko/StbImageSharpForUnity.Demo.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
%YAML 1.1
2+
%TAG !u! tag:unity3d.com,2011:
3+
--- !u!21 &2100000
4+
Material:
5+
serializedVersion: 8
6+
m_ObjectHideFlags: 0
7+
m_CorrespondingSourceObject: {fileID: 0}
8+
m_PrefabInstance: {fileID: 0}
9+
m_PrefabAsset: {fileID: 0}
10+
m_Name: DemoImageMaterial
11+
m_Shader: {fileID: 10752, guid: 0000000000000000f000000000000000, type: 0}
12+
m_ValidKeywords: []
13+
m_InvalidKeywords: []
14+
m_LightmapFlags: 4
15+
m_EnableInstancingVariants: 0
16+
m_DoubleSidedGI: 0
17+
m_CustomRenderQueue: -1
18+
stringTagMap: {}
19+
disabledShaderPasses: []
20+
m_SavedProperties:
21+
serializedVersion: 3
22+
m_TexEnvs:
23+
- _BumpMap:
24+
m_Texture: {fileID: 0}
25+
m_Scale: {x: 1, y: 1}
26+
m_Offset: {x: 0, y: 0}
27+
- _DetailAlbedoMap:
28+
m_Texture: {fileID: 0}
29+
m_Scale: {x: 1, y: 1}
30+
m_Offset: {x: 0, y: 0}
31+
- _DetailMask:
32+
m_Texture: {fileID: 0}
33+
m_Scale: {x: 1, y: 1}
34+
m_Offset: {x: 0, y: 0}
35+
- _DetailNormalMap:
36+
m_Texture: {fileID: 0}
37+
m_Scale: {x: 1, y: 1}
38+
m_Offset: {x: 0, y: 0}
39+
- _EmissionMap:
40+
m_Texture: {fileID: 0}
41+
m_Scale: {x: 1, y: 1}
42+
m_Offset: {x: 0, y: 0}
43+
- _MainTex:
44+
m_Texture: {fileID: 0}
45+
m_Scale: {x: 1, y: 1}
46+
m_Offset: {x: 0, y: 0}
47+
- _MetallicGlossMap:
48+
m_Texture: {fileID: 0}
49+
m_Scale: {x: 1, y: 1}
50+
m_Offset: {x: 0, y: 0}
51+
- _OcclusionMap:
52+
m_Texture: {fileID: 0}
53+
m_Scale: {x: 1, y: 1}
54+
m_Offset: {x: 0, y: 0}
55+
- _ParallaxMap:
56+
m_Texture: {fileID: 0}
57+
m_Scale: {x: 1, y: 1}
58+
m_Offset: {x: 0, y: 0}
59+
m_Ints: []
60+
m_Floats:
61+
- _BumpScale: 1
62+
- _Cutoff: 0.5
63+
- _DetailNormalMapScale: 1
64+
- _DstBlend: 0
65+
- _GlossMapScale: 1
66+
- _Glossiness: 0.5
67+
- _GlossyReflections: 1
68+
- _Metallic: 0
69+
- _Mode: 0
70+
- _OcclusionStrength: 1
71+
- _Parallax: 0.02
72+
- _SmoothnessTextureChannel: 0
73+
- _SpecularHighlights: 1
74+
- _SrcBlend: 1
75+
- _UVSec: 0
76+
- _ZWrite: 1
77+
m_Colors:
78+
- _Color: {r: 1, g: 1, b: 1, a: 1}
79+
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
80+
m_BuildTextureStacks: []

Assets/Mochineko/StbImageSharpForUnity.Demo/DemoImageMaterial.mat.meta

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
using System.Net.Http;
2+
using Cysharp.Threading.Tasks;
3+
using UnityEngine;
4+
5+
namespace Mochineko.StbImageSharpForUnity.Demo
6+
{
7+
/// <summary>
8+
/// A demonstration code of StbImageSharpForUnity loading an image from URL to <see cref="Texture2D"/>.
9+
/// </summary>
10+
internal sealed class ImageLoaderDemo : MonoBehaviour
11+
{
12+
[SerializeField] private string url;
13+
[SerializeField] private Renderer target;
14+
15+
private HttpClient httpClient;
16+
private Texture2D texture;
17+
18+
private void Awake()
19+
{
20+
httpClient = new HttpClient();
21+
}
22+
23+
private void OnDestroy()
24+
{
25+
httpClient.Dispose();
26+
}
27+
28+
private void Start()
29+
{
30+
Load();
31+
}
32+
33+
private void OnGUI()
34+
{
35+
if (GUILayout.Button($"{nameof(Load)}"))
36+
{
37+
Load();
38+
}
39+
if (GUILayout.Button($"{nameof(Clear)}"))
40+
{
41+
Clear();
42+
}
43+
}
44+
45+
private void Load()
46+
{
47+
LoadImageAsync().Forget();
48+
}
49+
50+
private void Clear()
51+
{
52+
Destroy(texture);
53+
}
54+
55+
private async UniTask LoadImageAsync()
56+
{
57+
await UniTask.SwitchToThreadPool();
58+
59+
var data = await httpClient.GetByteArrayAsync(url);
60+
61+
var imageResult = ImageDecoder.DecodeImage(data);
62+
63+
await UniTask.SwitchToMainThread();
64+
65+
texture = imageResult.ToTexture2D();
66+
67+
target.material.mainTexture = texture;
68+
}
69+
}
70+
}

Assets/Mochineko/StbImageSharpForUnity.Demo/ImageLoaderDemo.cs.meta

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "Mochineko.StbImageSharpForUnity.Demo",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:fac980d0a0def28459262c65dfd2a32d",
6+
"GUID:4b7e97d9b45fc704a97485f8a581efe8",
7+
"GUID:f51ebe6a0ceec4240a699833d6309b23"
8+
],
9+
"includePlatforms": [],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": false,
13+
"precompiledReferences": [],
14+
"autoReferenced": false,
15+
"defineConstraints": [],
16+
"versionDefines": [],
17+
"noEngineReferences": false
18+
}

Assets/Mochineko/StbImageSharpForUnity.Demo/Mochineko.StbImageSharpForUnity.Demo.asmdef.meta

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)