Esempio n. 1
0
//	void Update(){
//		if (canvas) {
//			if (mode == Mode.Placing) {
//				canvas.SetActive (true);
//			} else {
//				canvas.SetActive (false);
//			}
//		}
//	}

    public void placeObject(GameObject go)
    {
        ParticleSystem particles;
        GameObject     particlesGO;
        Bounds         bounds;
        Renderer       _renderer = go.GetComponent <Renderer> ();

        if (_renderer)
        {
            // it's a mesh with a renderer
            bounds = _renderer.bounds;
        }
        else
        {
            // it's a contaimner
            bounds = new Bounds(transform.position, new Vector3(0.1f, 0.1f, 0.1f));
            Renderer[] renderers = go.GetComponentsInChildren <Renderer> ();
            foreach (Renderer renderer in renderers)
            {
                bounds.Encapsulate(renderer.bounds);
            }
        }
        ARHitTest.Position pos = new ARHitTest.Position();
        if (ARHitTest.HitTest(ref pos))
        {
            Debug.Log("pos : " + pos.location.ToString());
            Debug.Log("bounds.extent : " + bounds.ToString());
            go.transform.position = pos.location + new Vector3(0.0f, bounds.extents.y, 0.0f);
            go.transform.rotation = pos.rotation;
            go.SetActive(true);
            Debug.Log("transform.pos : " + go.transform.position.ToString());
            if (Placed != null)
            {
                Placed(go);
            }
//			particlesGO = currDoor.transform.root.Find ("PlasmaExplosionEffect").gameObject;
//			particlesGO.transform.position = pos.location;
//			particles = particlesGO.GetComponent<ParticleSystem> ();
//			particles.Play ();
//			StartCoroutine(playAnimationDelayed ());
        }
    }
Esempio n. 2
0
        private void Vision_OnRectanglesRecognized(object sender, RectanglesRecognizedArgs e)
        {
            var rectangles = e.rectangles.OrderByDescending(entry => entry.area).ToList();
            var found      = false;

            foreach (var rect in rectangles)
            {
                ARHitTest.CastRectangle(rect, onHit: (topLeft, topRight, bottomRight, bottomLeft) =>
                {
                    if (_marker == null)
                    {
                        _marker = Instantiate(_rectangleMarkerPrefab);
                        Debug.Assert(_marker != null, "Could not instantiate rectangle marker prefab.");

                        // Reset transform
                        _marker.transform.position   = Vector3.zero;
                        _marker.transform.rotation   = Quaternion.identity;
                        _marker.transform.localScale = Vector3.one;
                    }

                    // Assign the corners of the marker game object to the surface hit points
                    _marker.TopLeft     = topLeft;
                    _marker.TopRight    = topRight;
                    _marker.BottomRight = bottomRight;
                    _marker.BottomLeft  = bottomLeft;

                    // Closure is synchronous
                    found = true;
                });

                if (found)
                {
                    break;
                }
            }

            if (_marker != null)
            {
                // Hide the marker if no rectangles were found
                _marker.gameObject.SetActive(found);
            }
        }