// 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);
        }
    }
Ejemplo n.º 2
0
 public void OnClickTarget()
 {
     ObjectHotspot.ClickOnhotspot();
 }