forked from Unity-Technologies/iOSNativeCodeSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestNativeTexture.cs
More file actions
61 lines (48 loc) · 1.76 KB
/
Copy pathTestNativeTexture.cs
File metadata and controls
61 lines (48 loc) · 1.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class TestNativeTexture : MonoBehaviour
{
private Texture2D testTex = null;
public Renderer target = null;
#if UNITY_IPHONE && !UNITY_EDITOR
[DllImport("__Internal")]
private static extern System.IntPtr CreateNativeTexture(string filename);
[DllImport("__Internal")]
private static extern void DestroyNativeTexture(System.IntPtr tex);
#else
private static System.IntPtr CreateNativeTexture(string filename)
{
Texture2D tex = (Texture2D)UnityEditor.AssetDatabase.LoadAssetAtPath("Assets/Plugins/iOS/" + filename + ".png", typeof(Texture2D));
return tex.GetNativeTexturePtr();
}
private static void DestroyNativeTexture(System.IntPtr tex)
{
}
#endif // if UNITY_IPHONE && !UNITY_EDITOR
private string[] externalTexture = new string[] { "Test_UnityLogoLarge", "Test_Icon", "Soft" };
private int curTexIndex;
private System.IntPtr curTex;
void LoadTexture()
{
System.IntPtr texToDestroy = curTex;
curTexIndex = (curTexIndex + 1) % externalTexture.Length;
curTex = CreateNativeTexture(externalTexture[curTexIndex]);
testTex.UpdateExternalTexture(curTex);
if (texToDestroy != System.IntPtr.Zero)
DestroyNativeTexture(texToDestroy);
}
void Start()
{
testTex = Texture2D.CreateExternalTexture(128, 128, TextureFormat.ARGB32, false, false, System.IntPtr.Zero);
target.material.mainTexture = testTex;
curTexIndex = -1;
curTex = System.IntPtr.Zero;
LoadTexture();
}
void OnGUI()
{
if (GUI.Button(new Rect(10, 10, 200, 200), "Show Next"))
LoadTexture();
}
}