コード例 #1
0
    // Finds the closest grabbable object within range of the pinch.
    protected Collider FindClosestGrabbableObject(Vector3 pinch_position)
    {
        Collider closest = null;
        float    closest_sqr_distance = grabObjectDistance * grabObjectDistance;

        Collider[] close_things =
            Physics.OverlapSphere(pinch_position, grabObjectDistance, grabbableLayers);

        for (int j = 0; j < close_things.Length; ++j)
        {
            float sqr_distance = (pinch_position - close_things[j].transform.position).sqrMagnitude;

            if (close_things[j].rigidbody != null && sqr_distance < closest_sqr_distance &&
                !close_things[j].transform.IsChildOf(transform) &&
                close_things[j].tag != "NotGrabbable")
            {
                GrabbableObject grabbable = close_things[j].GetComponent <GrabbableObject>();
                if (grabbable == null || !grabbable.IsGrabbed())
                {
                    closest = close_things[j];
                    closest_sqr_distance = sqr_distance;
                }
            }
        }

        return(closest);
    }
コード例 #2
0
ファイル: GrabbingHand.cs プロジェクト: prosa100/vros
    // Finds the closest grabbable object within range of the pinch.
    protected Collider FindClosestGrabbableObject(Vector3 pinch_position)
    {
        //Collider[] close_things =
        // Physics.OverlapSphere(pinch_position, grabObjectDistance, grabbableLayers);

        var ray = new Ray();

        Debug.DrawRay(ray.origin, ray.direction);

        RaycastHit thing;

        if (!Physics.Raycast(Camera.main.transform.position, pinch_position - Camera.main.transform.position, out thing, grabObjectDistance, grabbableLayers))
        {
            return(null);
        }
        float dist = thing.distance;

        if (thing.transform.GetComponent <Rigidbody>() != null && dist < grabObjectDistance &&
            !thing.transform.IsChildOf(transform) &&
            thing.transform.tag != "NotGrabbable")
        {
            //
            GrabbableObject grabbable = thing.transform.GetComponent <GrabbableObject>();
            if (grabbable == null || !grabbable.IsGrabbed())
            {
                return(thing.collider);
            }
        }


        return(null);
    }
コード例 #3
0
    protected Collider GetClosestGrabbableObject(Vector3 pinch_position)
    {
        Collider closest  = null;
        Vector3  distance = new Vector3(grabObjectDistance, 0.0f, 0.0f);

        Collider[] close_things = Physics.OverlapSphere(pinch_position, grabObjectDistance, grabbableLayers);

        for (int j = 0; j < close_things.Length; ++j)
        {
            Vector3 new_distance = pinch_position - close_things[j].transform.position;
            if (close_things[j].rigidbody != null && new_distance.magnitude < distance.magnitude &&
                !close_things[j].transform.IsChildOf(transform) &&
                close_things[j].tag != "NotGrabbable")
            {
                GrabbableObject grabbable = close_things[j].GetComponent <GrabbableObject>();
                if (grabbable == null || !grabbable.IsGrabbed())
                {
                    closest  = close_things[j];
                    distance = new_distance;
                }
            }
        }

        return(closest);
    }
コード例 #4
0
    void LightUp()
    {
        if (objectCheck)
        {
            GrabbableObject gb = attachment.GetComponent <GrabbableObject>();
            // if grabbed, light up
            if (gb != null && gb.IsGrabbed() && !attachment.GetComponent <Rigidbody>().isKinematic)
            {
                Transform child  = transform.FindChild("Replace Spot Light");
                Light[]   lights = transform.GetComponentsInChildren <Light>();
                foreach (var light in lights)
                {
                    light.enabled = true;
                }
            }
            // not grabbed, light off
            else
            {
                Transform child  = transform.FindChild("Replace Spot Light");
                Light[]   lights = transform.GetComponentsInChildren <Light>();
                foreach (var light in lights)
                {
                    light.enabled = false;
                }
            }
        }
        else if (tagCheck)
        {
            bool lightUp = false;
            foreach (var obj in attachments)
            {
                GrabbableObject gb = obj.GetComponent <GrabbableObject>();
                // if grabbed, light up
                if (gb != null && gb.IsGrabbed() && !obj.GetComponent <Rigidbody>().isKinematic)
                {
                    lightUp = true;
                    break;
                }
                // not grabbed, light off
            }

            if (lightUp)
            {
                Transform child = transform.FindChild("Replace Spot Light");
                if (child != null)
                {
                    child.gameObject.SetActive(true);
                }
            }
            else
            {
                Transform child = transform.FindChild("Replace Spot Light");
                if (child != null)
                {
                    child.gameObject.SetActive(false);
                }
            }
        }
    }
コード例 #5
0
    void FixedPosicion()
    {
        //Activar muro al soltar el atomo

        //Si no tenemos el atomo agarrado
        if (!scriptAtomoGrabbable.IsGrabbed())
        {
            //Si estamos en espacio reservado para el inventario y este está activo, activamos el muro para quue no se salga
            if (this.transform.position.y < PaletaFormulacion.transform.parent.position.y + 1.5f)
            {
                if (this.espacioInventario.transform.parent.gameObject.active)
                {
                    estaInventario = true;

                    this.transform.parent = espacioInventario.transform;


                    if (LimiteSuperiorInventario != null)
                    {
                        LimiteSuperiorInventario.SetActive(true);
                        LimiteSuperiorInventario = null;
                    }
                }
                //Si estamos en la posición de la papelera, eliminamos el atomo
                if (this.transform.position.x > 3.0f)
                {
                    if (this.espacioInventario.transform.parent.parent.Find("BotonPapelera").Find("Background").GetComponent <UnityEngine.UI.Image> ().color == Color.white)
                    {
                        EliminarAtomo();
                    }
                }
            }
            else
            {
                //Si estamos fuera de la zona del inventario, activamos el limite con el inventario y activamos el script que se encarga de gestionar los enlaces de los atomos
                if (LimiteSuperiorInventario != null)
                {
                    LimiteSuperiorInventario.SetActive(true);
                    LimiteSuperiorInventario = null;
                }

                estaInventario = false;

                this.GetComponent <ControlScript> ().enabled = true;

                //Establezco el atomo como hijo de la Paleta de formulacion
                this.transform.parent = PaletaFormulacion.transform;
            }



            //Si el átomo no ha salido del inventario, lo colocamos en su hueco dentro del inventario
            if (estaInventario)
            {
                this.transform.localPosition = new Vector3(0.0f, 0.0f, -1.0f);
                this.GetComponent <ControlScript> ().enabled = false;
                this.transform.Find("BoundingBox").gameObject.SetActive(false);
            }
            else
            {
                //Activo la bounding box para permitir los enlaces al detecetar los triggers de los Bounding Box
                Invoke("ActivarBoundingBox", 1.0f);

                //Bloqueamos la posicion del atomo
                Invoke("BloquearAtomo", 0.1f);
            }
        }
        else
        {
            //Si tenemos el atomo agarrado y estamos fuera del inventario
            if (this.transform.position.y > PaletaFormulacion.transform.parent.position.y + 2.0f)
            {
                estaInventario = false;

                this.GetComponent <ControlScript> ().enabled = true;

                //Activo la bounding box para permitir los enlaces al detecetar los triggers de los Bounding Box
                Invoke("ActivarBoundingBox", 1.0f);


                this.transform.parent = PaletaFormulacion.transform;
            }
            else if (this.espacioInventario.transform.parent.parent.Find("Inventario").gameObject.active)
            {
                CancelInvoke("ActivarBoundingBox");
                this.transform.Find("BoundingBox").gameObject.SetActive(false);

                this.GetComponent <ControlScript> ().enabled = false;
            }
        }
    }