Пример #1
0
        private void Update()
        {
            if (!_isGrabbing)
            {
                RaycastHit[] hit = new RaycastHit[1];
                if (Physics.RaycastNonAlloc(_pointerRay.position, _pointerRay.forward, hit) > 0)
                {
                    MediaPlayerButton wb = hit[0].transform.GetComponent <MediaPlayerButton>();
                    if (wb != null)
                    {
                        if (_lastButtonHit == null)
                        {
                            wb.OnRaycastEnter?.Invoke(hit[0].point);
                            _lastButtonHit      = wb;
                            _pointerLight.color = _pointerLightColorHit;
                        }
                        else if (_lastButtonHit == wb)
                        {
                            _lastButtonHit.OnRaycastContinue?.Invoke(hit[0].point);
                        }
                        else
                        {
                            _lastButtonHit.OnRaycastExit?.Invoke(hit[0].point);
                            _lastButtonHit = null;
                        }
                    }
                    else
                    {
                        if (_lastButtonHit != null)
                        {
                            _lastButtonHit.OnRaycastExit?.Invoke(hit[0].point);
                            _lastButtonHit = null;
                        }
                        _pointerLight.color = _pointerLightColorNoHit;
                    }
                    UpdatePointer(hit[0].point);
                }
                else
                {
                    _lastButtonHit = null;
                    ClearPointer();
                }
            }
            else if (_isGrabbing)
            {
                // _isGrabbing already guarantees that _lastButtonHit is not null
                // but just in case the actual button gets destroyed in
                // the middle of the grab, let's still check

                if (_lastButtonHit != null && _lastButtonHit.OnControllerDrag != null)
                {
                    _lastButtonHit.OnControllerDrag(_controllerConnectionHandler.ConnectedController);
                }
            }
        }
Пример #2
0
        void Update()
        {
            if (!_isGrabbing)
            {
                RaycastHit[] hit = new RaycastHit[1];
                // RayCast
                // RayCastAll
                // Debug.Log(_pointerRay.position);
                //Debug.Log(_pointerRay.forward);

                //cube.transform.position = _pointerRay.position + _pointerRay.forward;

                //RaycastHit hit1;
                // Does the ray intersect any objects excluding the player layer
                //if (Physics.Raycast(_pointerRay.position, _pointerRay.forward, out hit1, Mathf.Infinity))
                //{

                //    Debug.Log("Did Hit");
                //}

                if (Physics.RaycastNonAlloc(_pointerRay.position, _pointerRay.forward, hit) > 0)
                {
                    //MediaPlayerButton wb = hit[0].transform.GetComponent<MediaPlayerButton>();
                    Debug.Log("Did Hit2");

                    if (hit[0].transform && hit[0].transform.gameObject)
                    {
                        GameObject g = hit[0].transform.gameObject; //  "GrameObject1-5"
                        Debug.Log("g:" + g.name);
                        GameObject g_parent = null;
                        if (g.transform.parent && g.transform.parent.gameObject)
                        {
                            g_parent = g.transform.parent.gameObject; // "Scene"
                            Debug.Log("g_parent:" + g_parent.name);

                            //Debug.unityLogger.Log("islands", "initial g:" + g.name);
                        }
                        else
                        {
                            Debug.Log("No parent");
                        }
                        while (g_parent && g_parent.name != "Scene")
                        {
                            g        = g_parent;
                            g_parent = g.transform.parent.gameObject;
                        }
                        Debug.Log("g:" + g.name);

                        // g should have the full island
                        // Outline of the full island
                        Outline o = g.GetComponent <Outline>();

                        // Check for null
                        if (o != null)
                        {
                            Debug.Log("Hit " + hit[0].collider.gameObject.name);
                            if (!o.isActiveAndEnabled)
                            {
                                o.enabled = true;
                            }
                        }
                    }
                    else
                    {
                    }


                    //if (wb != null)
                    //{
                    //    if (_lastButtonHit == null)
                    //    {
                    //        if (wb.OnRaycastEnter != null)
                    //        {
                    //            wb.OnRaycastEnter(hit[0].point);
                    //        }
                    //        _lastButtonHit = wb;
                    //        _pointerLight.color = _pointerLightColorHit;
                    //    }
                    //    else if (_lastButtonHit == wb)
                    //    {
                    //        if (_lastButtonHit.OnRaycastContinue != null)
                    //        {
                    //            _lastButtonHit.OnRaycastContinue(hit[0].point);
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (_lastButtonHit.OnRaycastExit != null)
                    //        {
                    //            _lastButtonHit.OnRaycastExit(hit[0].point);
                    //        }
                    //        _lastButtonHit = null;
                    //    }
                    //}
                    //else
                    //{
                    //    if (_lastButtonHit != null)
                    //    {
                    //        if (_lastButtonHit.OnRaycastExit != null)
                    //        {
                    //            _lastButtonHit.OnRaycastExit(hit[0].point);
                    //        }
                    //        _lastButtonHit = null;
                    //    }
                    //    _pointerLight.color = _pointerLightColorNoHit;
                    //}
                    UpdatePointer(hit[0].point);
                }
                else
                {
                    //_lastButtonHit = null;
                    ClearPointer();

                    //clear all outlines
                    foreach (GameObject island in islands)
                    {
                        Outline outline = island.GetComponent <Outline>();
                        if (outline.isActiveAndEnabled)
                        {
                            Debug.Log("Clear outline of " + island.name);
                            outline.enabled = false;
                        }
                    }
                }
            }
            else if (_isGrabbing)
            {
                Debug.Log("isgrabbing");
                Debug.unityLogger.Log("islands", "Isgrabbing");

                // _isGrabbing already guarantees that _lastButtonHit is not null
                // but just in case the actual button gets destroyed in
                // the middle of the grab, let's still check

                if (_lastButtonHit != null && _lastButtonHit.OnControllerDrag != null)
                {
                    _lastButtonHit.OnControllerDrag(_controllerConnectionHandler.ConnectedController);
                }
            }
        }
Пример #3
0
        void Update()
        {
            if (!_isGrabbing)
            {
                RaycastHit[] hit = new RaycastHit[1];

                if (Physics.RaycastNonAlloc(_pointerRay.position, _pointerRay.forward, hit) > 0)
                {
                    if (hit[0].transform && hit[0].transform.gameObject)
                    {
                        GameObject g = hit[0].transform.gameObject; //  "GrameObject1-5"
                        Debug.Log("DEBUG: hitted object name: " + g.name);

                        if (g.CompareTag("Knight") || g.transform.parent.gameObject.CompareTag("Knight") || g.transform.parent.parent.gameObject.CompareTag("Knight"))
                        {
                            if (g.CompareTag("Knight"))
                            {
                                knight = g;
                            }
                            else if (g.transform.parent.gameObject.CompareTag("Knight"))
                            {
                                knight = g.transform.parent.gameObject;
                            }
                            else
                            {
                                knight = g.transform.parent.parent.gameObject;
                            }
                            crate = false;
                        }
                        else if (g.CompareTag("Crate") || g.transform.parent.gameObject.CompareTag("Crate") || g.transform.parent.gameObject.CompareTag("Crate"))
                        {
                            crate = true;
                            if (g.CompareTag("Crate"))
                            {
                                crateObject = g;
                            }
                            else if (g.transform.parent.gameObject.CompareTag("Crate"))
                            {
                                crateObject = g.transform.parent.gameObject;
                            }
                            else
                            {
                                crateObject = g.transform.parent.parent.gameObject;
                            }
                            knight = null;
                        }
                        else
                        {
                            knight = null;
                            crate  = false;
                            GameObject g_parent = null;
                            if (g.transform.parent && g.transform.parent.gameObject)
                            {
                                g_parent = g.transform.parent.gameObject; // "Scene"
                            }

                            while (g_parent && g_parent.name != "Scene")
                            {
                                g        = g_parent;
                                g_parent = g.transform.parent.gameObject;
                            }

                            if (g.name.StartsWith("GameObject"))
                            {
                                // g should have the full island
                                // Outline of the full island
                                Outline o = g.GetComponent <Outline>();
                                island = g;
                                // Check for null
                                if (o != null)
                                {
                                    Debug.Log("Hit " + hit[0].collider.gameObject.name);
                                    if (!o.isActiveAndEnabled)
                                    {
                                        o.enabled = true;
                                    }
                                }
                            }
                        }
                    }

                    UpdatePointer(hit[0].point);
                }
                else
                {
                    //_lastButtonHit = null;
                    ClearPointer();

                    //clear all outlines
                    foreach (GameObject island in islands)
                    {
                        Outline outline = island.GetComponent <Outline>();
                        if (outline.isActiveAndEnabled)
                        {
                            Debug.Log("Clear outline of " + island.name);
                            outline.enabled = false;
                        }
                    }
                }
            }
            else if (_isGrabbing)
            {
                Debug.Log("isgrabbing");
                Debug.unityLogger.Log("islands", "Isgrabbing");

                // _isGrabbing already guarantees that _lastButtonHit is not null
                // but just in case the actual button gets destroyed in
                // the middle of the grab, let's still check

                if (_lastButtonHit != null && _lastButtonHit.OnControllerDrag != null)
                {
                    _lastButtonHit.OnControllerDrag(_controllerConnectionHandler.ConnectedController);
                }
            }
        }