Пример #1
0
    void Update()
    {
        rayOrigin = rectTransform.position;
        ray       = Camera.main.ScreenPointToRay(rayOrigin);

        if (Physics.Raycast(ray.origin, ray.direction, out hitInfo, hitDistance, layerMask))
        {
            if (hitObject == null)
            {
                hitObject         = hitInfo.collider;
                hitObjectMaterial = hitObject.GetComponent <Renderer>().material;
                initialColor      = hitObjectMaterial.color;
            }

            isHighlighted = true;
            previousHit   = currentHit;
            currentHit    = hitObject.name;
            overlayPrefab.SetActive(true);                                                              // Add to AR
            overlayPrefab.GetComponent <Transform>().position = rayOrigin + new Vector3(100, 0, 0);     // Add to AR
            DataReader.DataPoint glyphInfo = scatterplotData.GetGlyphData(short.Parse(hitObject.name)); // Add to AR
            glyphDataText.text = "  Point:" + hitObject.name + "\n" +
                                 "  x:  " + glyphInfo.X + "\n" +
                                 "  y:  " + glyphInfo.Y + "\n" +
                                 "  z:  " + glyphInfo.Z; // Add to AR
            if (currentRaycastTimer > RaycastTimer && !isScaled)
            {
                scatterplotData.AdjustGlyphScale(short.Parse(hitObject.name));
                isScaled = true;
            }

            if (previousHit != null && previousHit.Equals(currentHit))
            {
                currentRaycastTimer++;
            }

            if (!isScaled)
            {
                hitObjectMaterial.color = highlightColor;
            }
            GetComponent <AxisRaycast>().EnableRays();
            GetComponent <AxisRaycast>().UpdateLineRenderer(hitObject.transform); // Add to AR
        }
        else
        {
            isHighlighted       = false;
            isScaled            = false;
            currentRaycastTimer = 0;
            overlayPrefab.SetActive(false);             // Add to AR
            GetComponent <AxisRaycast>().DisableRays(); // Add to AR
            if (hitObject != null)
            {
                if (!scatterplotData.GetColorStatus(short.Parse(hitObject.name)))
                {
                    scatterplotData.SetClusterColors();
                }
                hitObject         = null;
                hitObjectMaterial = null;
            }
        }
    }
    void Update()
    {
        // Create a vector at the center of our camera's viewport
        Vector3 rayOrigin = fpsCam.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0f));

        if (overlayPrefab != null)
        {
            overlayPrefab.transform.LookAt(fpsCam.transform);
        }

        if (laserLine.enabled)
        {
            // Declare a raycast hit to store information about what our raycast has hit
            RaycastHit hit;

            // Set the start position for our visual effect for our laser to the position of gunEnd
            laserLine.SetPosition(0, rayShooterPosition.position);

            // Check if our raycast has hit anything
            if (Physics.Raycast(rayOrigin, fpsCam.transform.forward, out hit, rayCasteRange, layerMask))
            {
                GetComponent <AxisRaycast>().EnableRays();
                GetComponent <AxisRaycast>().UpdateLineRenderer(hit.collider.transform);

                // Set the end position for our laser line
                laserLine.SetPosition(1, hit.point);
                //Debug.Log("color1:" + previousGameObjectColor);

                overlayPrefab.SetActive(true); // Add to AR
                //overlayPrefab.GetComponent<Transform>().position = rayOrigin + new Vector3(100, 0, 0); // Add to AR

                DataReader.DataPoint glyphInfo = scatterplotGenerator.GetGlyphData(Int32.Parse(hit.collider.gameObject.name)); // Add to AR
                glyphDataText.text = "  Point:" + hit.collider.gameObject.name + "\n" +
                                     "  x:  " + glyphInfo.X + "\n" +
                                     "  y:  " + glyphInfo.Y + "\n" +
                                     "  z:  " + glyphInfo.Z; // Add to AR

                if (previousGameObject != hit.collider.gameObject)
                {
                    resetGameObject();
                    previousGameObject      = hit.collider.gameObject;
                    previousGameObjectColor = previousGameObject.GetComponent <MeshRenderer>().material.color;
                }
                previousGameObject.GetComponent <MeshRenderer>().material.color = new Color(230, 224, 209);


                //tooltips.SetActive(true);
                //mainToolTip.GetComponent<TextMeshPro>().SetText(previousGameObject.name);
                //xyToolTip.GetComponent<TextMeshPro>().SetText(previousGameObject.name);
                //yzToolTip.GetComponent<TextMeshPro>().SetText(previousGameObject.name);
                //xzToolTip.GetComponent<TextMeshPro>().SetText(previousGameObject.name);
                //Debug.Log("color2:"+previousGameObjectColor);
            }
            else
            {
                //tooltips.SetActive(false);
                // If we did not hit anything, set the end of the line to a position directly in front of the camera at the distance of weaponRange
                overlayPrefab.SetActive(false);
                GetComponent <AxisRaycast>().DisableRays();
                laserLine.SetPosition(1, rayOrigin + (fpsCam.transform.forward * rayCasteRange));
                resetGameObject();
            }
        }
        else
        {
            //Reset gameobject
            resetGameObject();
            if (previousGameObject != null)
            {
                GetComponent <AxisRaycast>().UpdateLineRenderer(previousGameObject.transform);
            }
        }
    }