Advertisement
Guest User

Untitled

a guest
Dec 5th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4.  
  5. public class AnnotationTest : MonoBehaviour
  6. {
  7.  
  8. private static List<AnnotationTest> instances;
  9.  
  10. public Camera ARcam;
  11.  
  12. public GameObject mesh;
  13.  
  14. public GameObject panel;
  15.  
  16. public GameObject button;
  17.  
  18. public GameObject realPanel;
  19.  
  20. public GameObject image;
  21.  
  22. public GameObject sphere1;
  23. public GameObject sphere2;
  24. public GameObject sphere3;
  25.  
  26. // Use this for initialization
  27. void Start()
  28. {
  29. Debug.Log("Start");
  30. image.SetActive(false);
  31. realPanel.SetActive(false);
  32. panel.SetActive(false);
  33. button.SetActive(false);
  34. //panel.transform.position = ARcam.transform.position;
  35. //panel.transform.position += new Vector3(1185, 720, 0);
  36.  
  37. panel.transform.parent = null;
  38.  
  39. panel.transform.position = new Vector3(856, 683, 244);
  40.  
  41. panel.transform.rotation = Quaternion.Euler(0, 225, 0);
  42.  
  43. image.transform.parent = null;
  44.  
  45. image.transform.rotation = Quaternion.Euler(0, 45, 0);
  46.  
  47. image.transform.position = new Vector3(608, 340, 653);
  48.  
  49. //image.transform.rotation = Quaternion.Euler(0, 45, 0);
  50. //if (transform.childCount == 0 || transform.FindChild("__dialog") == null)
  51. //{
  52. // Debug.LogError("No child GameObject found! - Component will be disabled");
  53. // this.enabled = false;
  54. //}
  55. //SetShowAnnotation(false);
  56. if (instances == null)
  57. instances = new List<AnnotationTest>();
  58. instances.Add(this);
  59.  
  60. }
  61.  
  62. // Update is called once per frame
  63. void Update()
  64. {
  65. Screen.orientation = ScreenOrientation.Portrait;
  66. if (Input.GetMouseButtonDown(0))
  67. {
  68. //SetShowAnnotation(false); //Hide all annotations, if the user clicks somewhere
  69. Ray ray = Camera.main.ScreenPointToRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
  70. RaycastHit hit;
  71.  
  72. Physics.Raycast(ray, out hit);
  73. if (hit.collider != null)
  74. {
  75. Debug.Log("Hit collider");
  76. } else
  77. {
  78. Debug.Log("No hit.");
  79. }
  80. if (hit.collider != null && hit.collider.gameObject.Equals(gameObject))
  81. { //We were hit
  82. Debug.Log("We were hit");
  83. HideAllAnnotations();
  84. SetShowAnnotation(true);
  85. }
  86. }
  87.  
  88. for (int i = 0; i < Input.touchCount; i++)
  89. {
  90. Touch touch = Input.GetTouch(i);
  91. if (touch.phase == TouchPhase.Began)
  92. {
  93. //SetShowAnnotation(false); //Hide all annotations, if the user taps somewhere
  94. Ray ray = Camera.main.ScreenPointToRay(new Vector2(touch.position.x, touch.position.y));
  95. RaycastHit hit;
  96.  
  97. Physics.Raycast(ray, out hit);
  98. if (hit.collider != null && hit.collider.gameObject.Equals(gameObject))
  99. { //We were hit
  100. HideAllAnnotations();
  101. SetShowAnnotation(true);
  102. }
  103. }
  104. }
  105. }
  106.  
  107. public void SetShowAnnotation(bool show)
  108. {
  109. Debug.Log("Showing annotation = " + show + " (" + gameObject.name + ")");
  110. //transform.GetChild(0).gameObject.SetActive(show);
  111. panel.SetActive(show);
  112. realPanel.SetActive(show);
  113. button.SetActive(show);
  114. image.SetActive(show);
  115. mesh.SetActive(!show);
  116. sphere1.SetActive(!show);
  117. sphere2.SetActive(!show);
  118. sphere3.SetActive(!show);
  119. //transform.FindChild("__dialog_test").gameObject.SetActive(show);
  120. }
  121.  
  122. public static void HideAllAnnotations()
  123. {
  124. foreach (AnnotationTest instance in instances)
  125. {
  126. Debug.Log("Hide All Annotations called");
  127. instance.SetShowAnnotation(false);
  128. }
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement