MaxstARSDK  3.5.0
MaxstUtil.cs
1 using UnityEngine;
2 using System.IO;
3 using System.Collections;
4 using System.Security.Cryptography.X509Certificates;
5 
6 public class MaxstUtil : MonoBehaviour
7 {
8  public static IEnumerator loadImageFromFileWithSizeAndTexture(string path, System.Action<int, int, Texture2D> complete)
9  {
10  WWW img_load = new WWW("file://" + path);
11 
12  yield return img_load;
13 
14  Texture2D texture = (Texture2D)img_load.texture;
15  //Image img = imageObject.GetComponentInChildren<Image>();
16  //img.sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), img.GetComponent<RectTransform>().pivot);
17 
18  if (complete != null)
19  {
20  complete(texture.width, texture.height, texture);
21  }
22  }
23 
24  public static string changeNewLine(string originalText)
25  {
26  return originalText.Replace("\\n", "\n");
27  }
28 
29  public static string deleteNewLine(string originalText)
30  {
31  return originalText.Replace("\\n", "");
32  }
33 
34  public const int TYPE_WIDTH = 0;
35  public const int TYPE_HEIGHT = 1;
36 
37  public static float GetPixelFromInch(int type, float inch)
38  {
39  switch (type)
40  {
41  case TYPE_WIDTH:
42  float wScale = (float)Screen.width / (float)Screen.currentResolution.width;
43  return inch * Screen.dpi / (wScale) * (1920f / Screen.currentResolution.width);
44  case TYPE_HEIGHT:
45  float hScale = (float)Screen.height / (float)Screen.currentResolution.height;
46  return inch * Screen.dpi / (hScale) * (1920f / Screen.currentResolution.width);
47  default:
48  return inch;
49  }
50  }
51 
52  public static float DeviceDiagonalSizeInInches()
53  {
54  float screenWidth = Screen.width / Screen.dpi;
55  float screenHeight = Screen.height / Screen.dpi;
56  float diagonalInches = Mathf.Sqrt(Mathf.Pow(screenWidth, 2) + Mathf.Pow(screenHeight, 2));
57  return diagonalInches;
58  }
59 }