Predicates.ON C# (CSharp) Метод

ON() публичный Метод

Relations
public ON ( object args ) : Vector3
args object
Результат Vector3
    public Vector3 ON(object[] args)
    {
        Vector3 outValue = Vector3.zero;
        if (args [0] is GameObject) {	// on an object
            GameObject obj = ((GameObject)args [0]);
            Bounds bounds = new Bounds ();

            // check if object is concave
            bool isConcave = false;
            Voxeme voxeme = obj.GetComponent<Voxeme> ();
            if (voxeme != null) {
                isConcave = (voxeme.voxml.Type.Concavity == "Concave");
                isConcave = (isConcave && Vector3.Dot(obj.transform.up,Vector3.up) > 0.5f);
            }
            //Debug.Log (isConcave);

            if (isConcave) {	// on concave object
                // get surface with concavity
                // which side is concavity on? - assume +Y for now
                bounds = Helper.GetObjectWorldSize (obj);

                float concavityMinY = bounds.min.y;
                foreach (Renderer renderer in obj.GetComponentsInChildren<Renderer>()) {
                    Debug.Log (renderer.gameObject.name + " " + Helper.GetObjectWorldSize (renderer.gameObject).min.y);
                    if (Helper.GetObjectWorldSize (renderer.gameObject).min.y > concavityMinY) {
                        concavityMinY = Helper.GetObjectWorldSize (renderer.gameObject).min.y;
                    }
                }

                // **check if concavity exposed
                // flip(plate), try to put object on

                outValue = new Vector3 (obj.transform.position.x,
                    concavityMinY,//bounds.min.y,
                    obj.transform.position.z);
            }
            else {	// on convex or flat object
                /*bounds = Helper.GetObjectWorldSize (obj);

                Debug.Log (Helper.VectorToParsable(bounds.center));
                Debug.Log (Helper.VectorToParsable(bounds.min));
                Debug.Log (Helper.VectorToParsable(bounds.max));*/

                bounds = Helper.GetObjectWorldSize (obj);

                outValue = new Vector3 (obj.transform.position.x,
                    bounds.max.y,
                    obj.transform.position.z);

                //GameObject mark = GameObject.CreatePrimitive(PrimitiveType.Plane);
                //mark.transform.position = outValue;
                //mark.transform.localScale = new Vector3 (.07f, .07f, .07f);
                //mark.GetComponent<MeshCollider> ().enabled = false;
            }

            /*Voxeme voxComponent = (args [0] as GameObject).GetComponent<Voxeme> ();
            if (voxComponent.isGrasped) {
                outValue = (outValue +
                    (voxComponent.graspTracker.position - voxComponent.gameObject.transform.position));
            }*/

            Debug.Log ("on: " + Helper.VectorToParsable (outValue));
        }
        else if (args [0] is Vector3) {	// on a location
            outValue = (Vector3)args[0];
        }

        return outValue;
    }

Usage Example

Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (sandboxSurface != Helper.GetMostImmediateParentVoxeme(sandboxSurface))
        {
            sandboxSurface = Helper.GetMostImmediateParentVoxeme(sandboxSurface);
        }

        if (placementState == PlacementState.Delete)
        {
            if (Input.GetMouseButtonDown(0))
            {
                if (Helper.PointOutsideMaskedAreas(
                        new Vector2(Input.mousePosition.x, Screen.height - Input.mousePosition.y),
                        new Rect[] {
                    new Rect(Screen.width - (15 + (int)(110 * fontSizeModifier / 3)) + 38 * fontSizeModifier - 60,
                             Screen.height - (35 + (int)(20 * fontSizeModifier)),
                             60, 20 * fontSizeModifier)
                }))
                {
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    // Casts the ray and get the first game object hit
                    Physics.Raycast(ray, out selectRayhit);
                    if (selectRayhit.collider != null)
                    {
                        if (selectRayhit.collider.gameObject.transform.root.gameObject == selectedObject)
                        {
                            DeleteVoxeme(selectedObject);
                            actionButtonText            = "Add Object";
                            placementState              = PlacementState.Add;
                            selected                    = -1;
                            cameraControl.allowRotation = true;
                        }
                    }
                }
            }
        }
        else if (placementState == PlacementState.Place)
        {
            if (Input.GetMouseButton(0))
            {
                Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                // Casts the ray and get the first game object hit
                Physics.Raycast(ray, out selectRayhit);
                if (selectRayhit.collider != null)
                {
                    if (selectRayhit.collider.gameObject.transform.root.gameObject == sandboxSurface)
                    {
                        Debug.Log(selectRayhit.point.y);
                        if (Mathf.Abs(selectRayhit.point.y - preds.ON(new object[] { sandboxSurface }).y) <=
                            Constants.EPSILON)
                        {
                            if ((Mathf.Abs(selectRayhit.point.x - Helper.GetObjectWorldSize(sandboxSurface).min.x) >=
                                 Helper.GetObjectWorldSize(selectedObject).extents.x) &&
                                (Mathf.Abs(selectRayhit.point.x - Helper.GetObjectWorldSize(sandboxSurface).max.x) >=
                                 Helper.GetObjectWorldSize(selectedObject).extents.x) &&
                                (Mathf.Abs(selectRayhit.point.z - Helper.GetObjectWorldSize(sandboxSurface).min.z) >=
                                 Helper.GetObjectWorldSize(selectedObject).extents.z) &&
                                (Mathf.Abs(selectRayhit.point.z - Helper.GetObjectWorldSize(sandboxSurface).max.z) >=
                                 Helper.GetObjectWorldSize(selectedObject).extents.z))
                            {
                                selectedObject.transform.position = new Vector3(selectRayhit.point.x,
                                                                                preds.ON(new object[] { sandboxSurface }).y + surfacePlacementOffset,
                                                                                selectRayhit.point.z);
                                Voxeme voxComponent = selectedObject.GetComponent <Voxeme>();
                                voxComponent.targetPosition = selectedObject.transform.position;

                                foreach (Voxeme child in voxComponent.children)
                                {
                                    if (child.isActiveAndEnabled)
                                    {
                                        if (child.gameObject != voxComponent.gameObject)
                                        {
                                            child.transform.localPosition =
                                                voxComponent.parentToChildPositionOffset[child.gameObject];
                                            child.targetPosition = child.transform.position;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (Input.GetKeyDown(KeyCode.Return))
            {
                actionButtonText            = "Add Object";
                placementState              = PlacementState.Add;
                selected                    = -1;
                cameraControl.allowRotation = true;
                selectedObject.GetComponent <Rigging>().ActivatePhysics(true);
                SetShader(selectedObject, ShaderType.Default);
            }
        }
        else if (placementState == PlacementState.Add)
        {
            if (Input.GetMouseButton(0))
            {
                if (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))
                {
                    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
                    // Casts the ray and get the first game object hit
                    Physics.Raycast(ray, out selectRayhit);
                    if (selectRayhit.collider != null)
                    {
                        if (Helper.IsSupportedBy(selectRayhit.collider.gameObject.transform.root.gameObject,
                                                 sandboxSurface))
                        {
                            if (selectRayhit.collider.gameObject.transform.root.gameObject.GetComponent <Voxeme>() !=
                                null)
                            {
                                selectedObject         = selectRayhit.collider.gameObject.transform.root.gameObject;
                                surfacePlacementOffset =
                                    (Helper.GetObjectWorldSize(selectedObject.gameObject).center.y -
                                     Helper.GetObjectWorldSize(selectedObject.gameObject).min.y) +
                                    (selectedObject.gameObject.transform.position.y -
                                     Helper.GetObjectWorldSize(selectedObject.gameObject).center.y);
                                SetShader(selectedObject, ShaderType.Highlight);
                                actionButtonText            = "Place";
                                placementState              = PlacementState.Place;
                                cameraControl.allowRotation = false;

                                if (selectedObject != null)
                                {
                                    selectedObject.GetComponent <Rigging>().ActivatePhysics(false);
                                }
                            }
                        }
                    }
                }
            }
        }
    }