Esempio n. 1
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetMouseButton(0))
     {
         if (useStandardColliders)
         {
             RaycastHit hit;
             sw.Reset();
             sw.Start();
             if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
             {
                 hit.transform.GetComponent <Renderer>().material.color = new Color(1, 0, 0, 1);
             }
             sw.Stop();
             Debug.Log("Standard Collider search completed in " + sw.ElapsedMilliseconds + " ms");
         }
         else
         {
             APARaycastHit hit;
             if (APARaycast.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit))
             {
                 hit.transform.GetComponent <Renderer>().material.color = new Color(1, 0, 0, 1);
                 lastHitPos = hit.point;
             }
             else
             {
                 Debug.LogWarning("Miss! " + APARaycast.intersectionErrorType);
                 Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
                 Debug.DrawRay(r.origin, r.direction, Color.green, 100);
             }
         }
     }
 }
Esempio n. 2
0
    static public bool RayVsSceneMaterial(Ray r, out APARaycastHit hit, out MaterialStruct material)
    {
        hit      = null;
        material = null;

        if (APARaycast.Raycast(r, out hit))
        {
            Debug.Log("Hit " + hit.transform.gameObject.name);

            // Find The Material
            var     go         = hit.transform.gameObject;
            var     goMat      = go.GetComponent <Renderer>().material;
            var     matMainTex = goMat.mainTexture as Texture2D;
            Vector2 pixelUv    = hit.textureCoord;
            pixelUv.x *= matMainTex.width;
            pixelUv.y *= matMainTex.height;

            var pixelColour = matMainTex.GetPixel((int)pixelUv.x, (int)pixelUv.y);
            material = FindMaterialStructFromColour(pixelColour);

            return(true);
        }
        else
        {
            // Debug.Log("Miss! " + APARaycast.intersectionErrorType);

            return(false);
        }
    }
Esempio n. 3
0
    GameObject GetPickedBrick(Touch touch)
    {
        RaycastHit[] hits = Physics.RaycastAll(Camera.main.ScreenPointToRay(touch.position));

        List <GameObject> candidates = new List <GameObject>();
        Bounds            bounds     = new Bounds();

        foreach (RaycastHit hit in hits)
        {
            if (hit.transform.gameObject != skipObj)
            {
                candidates.Add(hit.transform.gameObject);
                bounds.Encapsulate(hit.transform.gameObject.GetComponent <Brick>().AABB);
            }
        }

        if (candidates.Count > 0)
        {
            APARaycastHit preciseHit;
            APAObjectDictionary.singleton.Init(bounds, candidates);

            if (APARaycast.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out preciseHit))
            {
                preciseHit.transform.GetComponent <Renderer>().material.color = new Color(1, 0, 0, 1);
                return(preciseHit.transform.gameObject);
            }
        }

        return(null);
    }