public void InitiateObjectHotspot() { for (int i = 0; i < NavigationContainer.transform.childCount; i++) { if (NavigationContainer.transform.GetChild(i).gameObject.activeInHierarchy) { if (NavigationContainer.transform.GetChild(i).GetComponent <SceneProperties>()) { ActiveScene = NavigationContainer.transform.GetChild(i).gameObject; } } } SetupDome.ButtonId++; BntID.text = "Btn ID :" + SetupDome.ButtonId.ToString(); GameObject Object = GameObject.Instantiate(ObjectHotspot); Object.gameObject.name = "Btn ID :" + SetupDome.ButtonId; Object.gameObject.transform.parent = ActiveScene.transform; Object.transform.localPosition = new Vector3(0, 0, 90f); Object.transform.localScale = new Vector3(1f, 1f, 1f); SelectedObjectHotspot = Object.transform.GetComponent <ObjectHotsot>(); Object.transform.GetComponent <ObjectHotsot>().AddObjectHotspot = gameObject.GetComponent <AddObjectHotspot>(); setupDome.SelectFile.GetComponent <SelectFiles>().EditScene = true; }
// Update is called once per frame void Update() { if (OH == null) { OH = gameObject.GetComponentInParent <ObjectHotsot>(); } }
// Use this for initialization private void Update() { if (ms == null) { ms = gameObject.transform.GetComponentInChildren <MeshFilter>(); gameObject.transform.parent.GetComponent <MeshRenderer>().enabled = false; if (!ms.gameObject.transform.GetComponent <BoxCollider>()) { ms.gameObject.transform.gameObject.AddComponent <BoxCollider>(); } OUTLINE = Resources.Load("PrefabForPreview/OUTLINE") as Material; ms.gameObject.tag = "ObjectModel"; ms.gameObject.layer = 8; gameObject.transform.parent.parent.GetComponent <MeshRenderer>().enabled = false; gameObject.transform.parent.parent.GetComponent <BoxCollider>().enabled = false; if (!ms.gameObject.GetComponent <BoxCollider>()) { ms.gameObject.AddComponent <BoxCollider>(); } if (!ms.gameObject.GetComponent <SelfActive>()) { ms.gameObject.AddComponent <SelfActive>(); } if (!ms.gameObject.GetComponent <ParentObjectHotspot>()) { ms.gameObject.AddComponent <ParentObjectHotspot>(); } ObjectHotsot OH = gameObject.transform.parent.GetComponentInParent <ObjectHotsot>(); OH.SelectedModel = ms.gameObject; OH.AddObjectHotspot.SelectedModel = ms.gameObject; if (ms.gameObject.transform.childCount == 0) { GameObject clone = ms.gameObject; clone.name = "clone"; GameObject ModeleClone = GameObject.Instantiate(clone); ModeleClone.name = "ModeleClone"; ModeleClone.transform.parent = ms.gameObject.transform; ModeleClone.transform.localPosition = Vector3.zero; ModeleClone.transform.localRotation = ms.gameObject.transform.localRotation; ModeleClone.transform.localScale = new Vector3(1f, 1f, 1f); ModeleClone.transform.gameObject.GetComponent <MeshRenderer>().material = OUTLINE; ModeleClone.transform.GetComponent <BoxCollider>().enabled = false; ModeleClone.transform.GetComponent <SelfActive>().enabled = false; ModeleClone.tag = "Untagged"; ModeleClone.layer = 0; } } // gameObject.GetComponent<MeshCollider>().sharedMesh = ms.mesh; }
void OnTriggerEnter(Collider collision) { if (collision.gameObject.tag == "ObjectModel") { Debug.Log(collision.gameObject.name); if (Model == null) { Model = collision.gameObject; while (OH != null) { OH = Model.GetComponentInParent <ObjectHotsot>(); OH.transform.localPosition = Vector3.zero; OH.transform.GetChild(0).GetComponent <LookAtTarget>().enabled = true; } } if (TargetFunctionType == "Navigation") { NavTo = TargetFunctionData; for (int i = 0; i < NavigationContainerPrv.transform.childCount; i++) { Debug.Log(NavigationContainerPrv.transform.GetChild(i).gameObject.name + " :: " + NavTo); Debug.Log(NavTo); if (NavTo == NavigationContainerPrv.transform.GetChild(i).GetComponent <PreviewScene>().sceneName) { NavigationContainerPrv.transform.GetChild(i).gameObject.SetActive(true); //set camera rot eulervalues to given rotationView NavigationContainerPrv.transform.GetChild(i).gameObject.GetComponent <PreviewScene>().camPos = rotationView; Model.GetComponent <ParentObjectHotspot>().OH.gameObject.transform.localPosition = Vector3.zero; Model.GetComponent <ParentObjectHotspot>().OH.gameObject.transform.GetChild(0).transform.GetComponent <LookAtTarget>().enabled = true; Model.GetComponent <ParentObjectHotspot>().OH.SelectedModel.transform.GetChild(0).gameObject.SetActive(false); } else { NavigationContainerPrv.transform.GetChild(i).gameObject.SetActive(false); } } } if (TargetFunctionType == "Text Box") { GameObject DisplayText = gameObject.transform.parent.GetComponentInChildren <HideInfo>().gameObject; DisplayText.SetActive(true); DisplayText.GetComponent <HideInfo>().RequireMsg = true; TriLib.Samples.PreviewHotspot previewHotspot = gameObject.transform.parent.GetComponent <TriLib.Samples.PreviewHotspot>(); previewHotspot.Always = true; previewHotspot.GetMsg = TargetFunctionData; gameObject.transform.GetChild(0).gameObject.SetActive(true); gameObject.transform.GetChild(0).gameObject.transform.GetChild(0).GetChild(0).GetComponent <Text>().text = previewHotspot.GetMsg; } } }
// When we click mouse then we cast 2 ray one is geting object on collider layer and the other layer is getting object on Action layer. public void OnMouseButtonDown() { if (Input.GetMouseButton(0)) { RaycastHit hit; RaycastHit hit2; Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); Vector3 ScreenPos = Camera.main.ScreenToWorldPoint(Input.mousePosition); if (Physics.Raycast(ray, out hit2, 1000f, layermask)) { Debug.Log("Get point"); Debug.Log(hit2.collider.gameObject.name); if (!preview) { if (hit2.collider.gameObject.name == "DragArea") { DragArea.SetActive(false); CameraDrag = true; } } else { if (hit2.collider.gameObject.tag == "Collider") { CameraDrag = true; } } Debug.DrawRay(transform.position + new Vector3(1f, 2f, 0), hit2.point, Color.red); var startPos = hit2.point; if (CurrentSelectedObject != null) { if (CurrentSelectedObject.transform.childCount != 0) { if (CurrentSelectedObject.transform.GetChild(0).gameObject.tag == "Hotspot") { if (!preview) { CurrentSelectedObject.transform.position = startPos; CurrentSelectedObject.transform.GetChild(0).gameObject.transform.localPosition = Vector3.zero; if (CurrentSelectedObject.GetComponent <NewActionHotspot>()) { CurrentSelectedObject.GetComponent <NewActionHotspot>().OnClickOnActionHotspot(); } if (CurrentSelectedObject.GetComponent <navigateActionHotspot>()) { CurrentSelectedObject.GetComponent <navigateActionHotspot>().OnClickOnHotspot(); } } } if (CurrentSelectedObject.transform.GetChild(0).gameObject.tag == "MenuHotspot") { if (!preview) { CurrentSelectedObject.transform.position = startPos; CurrentSelectedObject.transform.gameObject.transform.GetChild(0).localPosition = Vector3.zero; } } if (CurrentSelectedObject.transform.GetChild(0).gameObject.tag == "MediaHotspot") { if (!preview) { CurrentSelectedObject.transform.position = startPos; CurrentSelectedObject.transform.GetChild(0).gameObject.transform.localPosition = Vector3.zero; } } } if (CurrentSelectedObject.transform.gameObject.tag == "Target") { if (!preview) { CurrentSelectedObject.transform.localPosition = startPos; } } if (CurrentSelectedObject.transform.gameObject.tag == "Object") { if (!preview) { CurrentSelectedObject.transform.position = startPos; } } if (CurrentSelectedObject.transform.gameObject.tag == "Model") { if (!preview) { CurrentSelectedObject.transform.position = startPos; } } if (CurrentSelectedObject.transform.gameObject.tag == "Object") { if (preview) { CurrentSelectedObject.transform.position = startPos; } } } } // Get the hostspot to active stage. if (Physics.Raycast(ray, out hit, 1000f, layermask2)) { Debug.Log("Getting Hotspot object : " + hit.collider.gameObject.name); if (preview) { if (hit.collider.gameObject.tag == "InfoBox") { Debug.Log(hit.collider.gameObject.name); hit.collider.gameObject.transform.parent.GetComponent <HideInfo>().hide = !hit.collider.gameObject.transform.parent.GetComponent <HideInfo>().hide; } if (hit.collider.gameObject.tag == "MenuHotspot") { Debug.Log(hit.collider.gameObject.name + "Function Call"); if (hit.collider.transform.parent.GetComponent <MenuHotspot>()) { Debug.Log("Visible function"); // hit.collider.transform.parent.GetComponent<MenuHotspot>().ClickOnVisible(); } if (hit.collider.transform.GetComponent <MenuFunction>()) { Debug.Log("Navigation function"); // hit.collider.transform.GetComponent<MenuFunction>().ClickMenuHotspot(); } } } if (hit.collider.gameObject.tag == "Hotspot") { if (!preview) { hit.collider.gameObject.GetComponent <BoxCollider>().enabled = false; // hit.collider.gameObject.transform.localPosition = Vector3.zero; hit.collider.gameObject.transform.parent.localPosition = new Vector3(hit.collider.gameObject.transform.parent.localPosition.x, hit.collider.gameObject.transform.parent.localPosition.y, hit.collider.gameObject.transform.parent.localPosition.z); OnCollider = true; CurrentSelectedObject = hit.collider.gameObject.transform.parent.gameObject; ActiveHotspot = true; if (CurrentSelectedObject.transform.parent.transform.GetComponent <NewActionHotspot>()) { CurrentSelectedObject.transform.parent.transform.GetComponent <NewActionHotspot>().OnClickOnActionHotspot(); } } else { if (hit.collider.gameObject.tag == "Hotspot") { hit.collider.transform.parent.transform.GetComponent <TriLib.Samples.PreviewHotspot>().HandleTimedInput(); } } } if (hit.collider.gameObject.tag == "MenuHotspot") { Debug.Log("Menu :" + hit.collider.gameObject.name); if (!preview) { hit.collider.gameObject.GetComponent <BoxCollider>().enabled = false; // hit.collider.gameObject.transform.localPosition = Vector3.zero; hit.collider.gameObject.transform.parent.localPosition = new Vector3(hit.collider.gameObject.transform.parent.localPosition.x, hit.collider.gameObject.transform.parent.localPosition.y, hit.collider.gameObject.transform.parent.localPosition.z); OnCollider = true; CurrentSelectedObject = hit.collider.gameObject.transform.parent.gameObject; CurrentSelectedObject.GetComponent <MenuHotspot>().ClickOnMenuHotspot(); ActiveHotspot = true; } else { Debug.Log(hit.collider.gameObject.name); // hit.collider.gameObject.GetComponent<MenuHotspot>().VisibleMenu(); } } if (hit.collider.gameObject.tag == "MediaHotspot") { if (!preview) { hit.collider.gameObject.GetComponent <BoxCollider>().enabled = false; // hit.collider.gameObject.transform.localPosition = Vector3.zero; hit.collider.gameObject.transform.parent.localPosition = new Vector3(hit.collider.gameObject.transform.parent.localPosition.x, hit.collider.gameObject.transform.parent.localPosition.y, hit.collider.gameObject.transform.parent.localPosition.z); OnCollider = true; ActiveHotspot = true; if (hit.collider.gameObject.transform.GetComponentInParent <MediaHotspot>()) { // hit.collider.gameObject.transform.localPosition = Vector3.zero; CurrentSelectedObject = hit.collider.gameObject.transform.GetComponentInParent <MediaHotspot>().gameObject; CurrentSelectedObject.GetComponent <MediaHotspot>().OnClickMediaHotspot(); } else { if (hit.collider.gameObject.transform.GetComponent <MediaHotspot>() || hit.collider.gameObject.transform.GetComponent <MediaHotspotHelp>()) { // hit.collider.gameObject.transform.localPosition = Vector3.zero; CurrentSelectedObject = hit.collider.gameObject.transform.parent.gameObject; if (hit.collider.gameObject.transform.GetComponent <MediaHotspot>()) { CurrentSelectedObject.GetComponent <MediaHotspot>().OnClickMediaHotspot(); } if (hit.collider.gameObject.transform.GetComponent <MediaHotspotHelp>()) { // hit.collider.gameObject.transform.localPosition = Vector3.zero; CurrentSelectedObject.GetComponent <MediaHotspotHelp>().OnClickMediaHotspot(); } } } /* CurrentSelectedObject = hit.collider.gameObject.transform.parent.gameObject; * if (hit.collider.gameObject.transform.parent.gameObject.GetComponent<MediaHotspot>()) * { * hit.collider.gameObject.transform.localPosition = Vector3.zero; * CurrentSelectedObject = hit.collider.gameObject.transform.parent.gameObject.transform.parent.gameObject; * CurrentSelectedObject.transform.GetChild(0). * GetComponent<MediaHotspot>().OnClickMediaHotspot(); * } * else { * * CurrentSelectedObject = hit.collider.gameObject.transform.parent.gameObject; * if (CurrentSelectedObject.GetComponent<MediaHotspot>()) * { * CurrentSelectedObject.GetComponent<MediaHotspot>().OnClickMediaHotspot(); * } * if (CurrentSelectedObject.GetComponent<MediaHotspotHelp>()) * { * CurrentSelectedObject.GetComponent<MediaHotspotHelp>().OnClickMediaHotspot(); * } * OnCollider = true; * ActiveHotspot = true; * } */ ActiveHotspot = true; } else { hit.collider.gameObject.transform.parent.GetComponent <MediaHotspot>().OnClickHide(); } ActiveHotspot = true; } if (hit.collider.gameObject.tag == "MediaPlay") { hit.collider.gameObject.transform.parent.GetComponent <MediaPlaypause>().PlayAndPause(); } if (hit.collider.gameObject.tag == "MediaHide") { if (!preview) { hit.collider.gameObject.transform.parent.parent.GetComponent <MediaHotspot>().OnClickHide(); } } if (hit.collider.gameObject.tag == "Target") { if (!preview) { hit.collider.gameObject.GetComponent <SphereCollider>().enabled = false; hit.collider.gameObject.transform.localPosition = new Vector3(hit.collider.gameObject.transform.localPosition.x, hit.collider.gameObject.transform.localPosition.y, hit.collider.gameObject.transform.localPosition.z); OnCollider = true; hit.collider.gameObject.GetComponent <TargetFunction>().OnClickTarget(); CurrentSelectedObject = hit.collider.gameObject; ActiveHotspot = true; } else { // hit.collider.gameObject.transform.parent.GetComponent<MediaHotspot>().OnClickHide(); } } if (hit.collider.gameObject.tag == "Object") { if (!preview) { hit.collider.gameObject.GetComponent <BoxCollider>().enabled = true; // hit.collider.gameObject.transform.localPosition = Vector3.zero; hit.collider.gameObject.transform.localPosition = new Vector3(hit.collider.gameObject.transform.localPosition.x, hit.collider.gameObject.transform.localPosition.y, hit.collider.gameObject.transform.localPosition.z); OnCollider = true; CurrentSelectedObject = hit.collider.gameObject; if (CurrentSelectedObject.GetComponent <ObjectHotsot>()) { CurrentSelectedObject.GetComponent <ObjectHotsot>().AddObjectHotspot.EnableMenuTemplet(); } ActiveHotspot = true; } else { // hit.collider.gameObject.transform.parent.GetComponent<MediaHotspot>().OnClickHide(); } } if (hit.collider.gameObject.tag == "Model") { if (!preview) { if (hit.collider.gameObject.GetComponent <BoxCollider>()) { hit.collider.gameObject.GetComponent <BoxCollider>().enabled = false; } // hit.collider.gameObject.transform.localPosition = Vector3.zero; hit.collider.gameObject.transform.localPosition = new Vector3(hit.collider.gameObject.transform.localPosition.x, hit.collider.gameObject.transform.localPosition.y, hit.collider.gameObject.transform.localPosition.z); OnCollider = true; CurrentSelectedObject = hit.collider.gameObject; ActiveHotspot = true; } else { // hit.collider.gameObject.transform.parent.GetComponent<MediaHotspot>().OnClickHide(); } } if (hit.collider.gameObject.tag == "ObjectModel") { if (!preview) { if (hit.collider.gameObject.GetComponent <BoxCollider>()) { hit.collider.gameObject.GetComponent <BoxCollider>().enabled = false; } // hit.collider.gameObject.transform.localPosition = Vector3.zero; ObjectHotsot OH = hit.collider.gameObject.GetComponentInParent <ObjectHotsot>(); // hit.collider.gameObject.transform.localPosition = Vector3.zero; // OH.transform.parent.gameObject.transform.localPosition = new Vector3(hit.collider.gameObject.transform.localPosition.x, hit.collider.gameObject.transform.localPosition.y, hit.collider.gameObject.transform.localPosition.z); OnCollider = true; OH.ClickOnhotspot(); OH.transform.GetChild(0).GetComponent <LookAtTarget>().enabled = true; CurrentSelectedObject = OH.transform.gameObject; ActiveHotspot = true; } else { if (hit.collider.gameObject.GetComponent <BoxCollider>()) { hit.collider.gameObject.GetComponent <BoxCollider>().enabled = false; } OnCollider = true; ObjectHotsot OH = hit.collider.gameObject.GetComponentInParent <ObjectHotsot>(); OH.Target.gameObject.SetActive(true); OH.transform.GetChild(0).GetComponent <LookAtTarget>().enabled = true; Debug.Log("Raycast on objectmodel"); OH.SelectedModel.transform.GetChild(0).gameObject.GetComponent <MeshRenderer>().enabled = true; // hit.collider.gameObject.transform.localPosition = Vector3.zero; CurrentSelectedObject = OH.transform.gameObject; ActiveHotspot = true; } } } Debug.DrawRay(transform.position + new Vector3(1f, 2f, 0), hit.point, Color.blue); } }
private void OnEnable() { OH = null; Model = null; }