MaxstARSDK  3.5.0
WatermarkUtil.cs
1 /*==============================================================================
2 Copyright 2017 Maxst, Inc. All Rights Reserved.
3 ==============================================================================*/
4 
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using System.Text;
9 using System.IO;
10 using UnityEngine;
11 using UnityEngine.Rendering;
12 
13 namespace maxstAR
14 {
15  internal class WatermarkUtil
16  {
17  private static WatermarkUtil instance = new WatermarkUtil();
18 
19  internal static WatermarkUtil Instance
20  {
21  get { return instance; }
22  }
23 
24  private System.IntPtr invalidImagePtr = IntPtr.Zero;
25  private System.IntPtr freeImagePtr = IntPtr.Zero;
26 
27  private WatermarkUtil()
28  {
29  invalidImagePtr = NativeSharedAPI.Signature_getInvalidImagePtr();
30  freeImagePtr = NativeSharedAPI.Signature_getFreeImagePtr();
31  }
32 
33  internal GameObject CreateWartermarkObject(int signatureType)
34  {
35  GameObject watermark = new GameObject("SDKLogo");
36 
37  Renderer tRenderer = watermark.AddComponent<MeshRenderer>();
38  tRenderer.shadowCastingMode = ShadowCastingMode.Off;
39  tRenderer.receiveShadows = false;
40  //Shader tShader = Shader.Find("Unlit/Transparent");
41  Shader tShader = Resources.Load<Shader>("Shader/TransparentSurface");
42  if (tShader == null)
43  {
44  tShader = Shader.Find("Unlit/Texture");
45  }
46  tRenderer.material = new Material(tShader);
47 
48  Texture2D texture = null;
49 
50  if (signatureType == 1) // Free signature
51  {
52  texture = new Texture2D(115, 30, TextureFormat.RGBA32, false);
53  texture.LoadRawTextureData(freeImagePtr, 115 * 30 * 4);
54  }
55  else // Invalid signature
56  {
57  texture = new Texture2D(106, 38, TextureFormat.RGBA32, false);
58  texture.LoadRawTextureData(invalidImagePtr, 115 * 30 * 4);
59  }
60 
61  texture.Apply();
62  tRenderer.material.mainTexture = texture;
63 
64  MeshFilter tMeshFilter = watermark.AddComponent<MeshFilter>();
65  tMeshFilter.mesh = new Mesh();
66  tMeshFilter.mesh.vertices = new Vector3[]
67  {
68  new Vector3(-1, 0, -1) * 0.5f,
69  new Vector3(-1, 0, 1) * 0.5f,
70  new Vector3(1, 0, -1) * 0.5f,
71  new Vector3(1, 0, 1) * 0.5f
72  };
73 
74  tMeshFilter.mesh.triangles = new int[] { 0, 1, 2, 2, 1, 3 };
75  tMeshFilter.mesh.uv = new Vector2[]
76  {
77  new Vector2(0, 0),
78  new Vector2(0, 1),
79  new Vector2(1, 0),
80  new Vector2(1, 1),
81  };
82 
83  tMeshFilter.mesh.RecalculateNormals();
84  tMeshFilter.mesh.RecalculateBounds();
85 
86  watermark.transform.localScale = new Vector3(1.0f, 1.0f, -1.0f);
87 
88  return watermark;
89  }
90  }
91 }