Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- public class AnnotationTest : MonoBehaviour
- {
- private static List<AnnotationTest> instances;
- public Camera ARcam;
- public GameObject mesh;
- public GameObject panel;
- public GameObject button;
- public GameObject realPanel;
- public GameObject image;
- public GameObject sphere1;
- public GameObject sphere2;
- public GameObject sphere3;
- // Use this for initialization
- void Start()
- {
- Debug.Log("Start");
- image.SetActive(false);
- realPanel.SetActive(false);
- panel.SetActive(false);
- button.SetActive(false);
- //panel.transform.position = ARcam.transform.position;
- //panel.transform.position += new Vector3(1185, 720, 0);
- panel.transform.parent = null;
- panel.transform.position = new Vector3(856, 683, 244);
- panel.transform.rotation = Quaternion.Euler(0, 225, 0);
- image.transform.parent = null;
- image.transform.rotation = Quaternion.Euler(0, 45, 0);
- image.transform.position = new Vector3(608, 340, 653);
- //image.transform.rotation = Quaternion.Euler(0, 45, 0);
- //if (transform.childCount == 0 || transform.FindChild("__dialog") == null)
- //{
- // Debug.LogError("No child GameObject found! - Component will be disabled");
- // this.enabled = false;
- //}
- //SetShowAnnotation(false);
- if (instances == null)
- instances = new List<AnnotationTest>();
- instances.Add(this);
- }
- // Update is called once per frame
- void Update()
- {
- Screen.orientation = ScreenOrientation.Portrait;
- if (Input.GetMouseButtonDown(0))
- {
- //SetShowAnnotation(false); //Hide all annotations, if the user clicks somewhere
- Ray ray = Camera.main.ScreenPointToRay(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
- RaycastHit hit;
- Physics.Raycast(ray, out hit);
- if (hit.collider != null)
- {
- Debug.Log("Hit collider");
- } else
- {
- Debug.Log("No hit.");
- }
- if (hit.collider != null && hit.collider.gameObject.Equals(gameObject))
- { //We were hit
- Debug.Log("We were hit");
- HideAllAnnotations();
- SetShowAnnotation(true);
- }
- }
- for (int i = 0; i < Input.touchCount; i++)
- {
- Touch touch = Input.GetTouch(i);
- if (touch.phase == TouchPhase.Began)
- {
- //SetShowAnnotation(false); //Hide all annotations, if the user taps somewhere
- Ray ray = Camera.main.ScreenPointToRay(new Vector2(touch.position.x, touch.position.y));
- RaycastHit hit;
- Physics.Raycast(ray, out hit);
- if (hit.collider != null && hit.collider.gameObject.Equals(gameObject))
- { //We were hit
- HideAllAnnotations();
- SetShowAnnotation(true);
- }
- }
- }
- }
- public void SetShowAnnotation(bool show)
- {
- Debug.Log("Showing annotation = " + show + " (" + gameObject.name + ")");
- //transform.GetChild(0).gameObject.SetActive(show);
- panel.SetActive(show);
- realPanel.SetActive(show);
- button.SetActive(show);
- image.SetActive(show);
- mesh.SetActive(!show);
- sphere1.SetActive(!show);
- sphere2.SetActive(!show);
- sphere3.SetActive(!show);
- //transform.FindChild("__dialog_test").gameObject.SetActive(show);
- }
- public static void HideAllAnnotations()
- {
- foreach (AnnotationTest instance in instances)
- {
- Debug.Log("Hide All Annotations called");
- instance.SetShowAnnotation(false);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement