コード例 #1
0
    private void OnTriggerEnter(Collider other)
    {
        if (isFocusGrabbed)
        {
            return;
        }
        if (other.transform.gameObject.GetComponent <Vodget>())
        {
            Vodget hitVodget = other.transform.gameObject.GetComponent <Vodget>();
            SetCursor();

            // if there's no obj selected before
            if (grabbedObject == null)
            {
                grabPoint     = transform.position;
                grabbedObject = hitVodget;
                hitVodget.Focus(this, true);
            }

            // if the hit object is not the obj the one that selector previously focused
            else if (grabbedObject != other.transform.gameObject)
            {
                if (grabbedObject)
                {
                    grabbedObject.Focus(this, false);
                }

                grabbedObject = hitVodget;
                hitVodget.Focus(this, true);
                grabPoint = transform.position;
            }

            // if the hit object is the same as the obj
            else
            {
                //hitVodget.Focus(this, true);
            }
        }
    }
コード例 #2
0
    // Update is called once per frame
    void Update()
    {
        if (!isFocusGrabbed)
        {
            if (Physics.Raycast(transform.position, transform.forward, out hit, int.MaxValue))
            {
                Vodget hitVodget = hit.transform.gameObject.GetComponent <Vodget>();
                if (hitVodget)
                {
                    // if there's no obj selected before
                    if (!hitVodget.isSelected)
                    {
                        if (grabbedVodget == null)
                        {
                            grabPoint     = hit.point;
                            grabbedVodget = hitVodget;
                            SetCursor();
                            hitVodget.Focus(this, true);
                        }

                        // if the hit object is not the obj the one that selector previously focused
                        else if (grabbedVodget != hitVodget)
                        {
                            if (grabbedVodget)
                            {
                                grabbedVodget.Focus(this, false);
                            }

                            grabbedVodget = hitVodget;
                            SetCursor();
                            hitVodget.Focus(this, true);
                            grabPoint = hit.point;
                        }
                    }
                }

                // ray hit, but not hitting at a vodget
                else
                {
                    if (grabbedVodget != null)
                    {
                        grabbedVodget.Focus(this, false);
                        grabbedVodget = null;
                    }
                }
            }

            //ray hit nothing
            else
            {
                //not shooting at any vodget
                if (grabbedVodget != null)
                {
                    SetCursor();
                    grabbedVodget.Focus(this, false);
                    grabbedVodget = null;
                }
            }
        }

        if (grabbedVodget)
        {
            SetCursor();
            grabbedVodget.FocusUpdate(this);
        }
    }