Esempio n. 1
0
 public virtual void Start()
 {
     if (this.objectToNotify)
     {
         this.actScript = (s3dInteractor)this.objectToNotify.GetComponent(typeof(s3dInteractor));
     }
 }
Esempio n. 2
0
 public virtual void processTap(RaycastHit theHit, bool gotHit, int tapType)
 {
     setTexture(clickTexture);
     if (clickSound)
     {
         GetComponent <AudioSource>().PlayOneShot(clickSound);
     }
     if (activeObj && (!gotHit || (activeObj != theHit.transform.gameObject)))     // if there's currently an active object and there was a tap but no hit - then deactivate this object
     {
         actScript = (s3dInteractor)activeObj.GetComponent(typeof(s3dInteractor)); // or if there's currently an active object and there was a tap that hit another object - then deactivate this object
         if (actScript)
         {
             actScript.deactivateObject();
         }
     }
     else
     {
         if (gotHit) // if there's not a currently active object and there was a tap with a hit on an active object - then activate it
         {
             actScript = (s3dInteractor)theHit.transform.gameObject.GetComponent(typeof(s3dInteractor));
             if (actScript)
             {
                 actScript.tapAction(theHit, tapType);
             }
         }
     }
     StartCoroutine(unclickTexture());
 }
Esempio n. 3
0
 public virtual void processRollover(RaycastHit theHit, bool onObject)
 {
     if (onObject)
     {
         s3dInteractor actScript = (s3dInteractor)theHit.transform.gameObject.GetComponent(typeof(s3dInteractor));
         actScript.rolloverText(theHit, true, s3dTexture.obPosition);
         prevRolloverObject = theHit.transform.gameObject;
     }
     else
     {
         actScript = (s3dInteractor)prevRolloverObject.transform.gameObject.GetComponent(typeof(s3dInteractor));
         actScript.rolloverText(theHit, false, s3dTexture.obPosition);
         prevRolloverObject = null;
     }
 }
Esempio n. 4
0
    public virtual void findDistanceUnderObject()
    {
        Vector2       dPosition    = default(Vector2);
        RaycastHit    hit          = default(RaycastHit);
        float         nearDistance = Mathf.Infinity;
        s3dInteractor actScript    = null;

        if ((camera3D.format3D == (mode3D)0) && !camera3D.sideBySideSqueezed)
        {
            dPosition = new Vector2((obPosition.x / 2) + 0.25f, obPosition.y); // 0 = left, 0.5 = center, 1 = right
        }
        else
        {
            dPosition = obPosition;
        }
        checkpoints[0] = dPosition;                                     // raycast against object center
        checkpoints[1] = dPosition + new Vector2(-corner.x, -corner.y); // raycast against object corners
        checkpoints[2] = dPosition + new Vector2(corner.x, -corner.y);
        checkpoints[3] = dPosition + new Vector2(corner.x, corner.y);
        checkpoints[4] = dPosition + new Vector2(-corner.x, corner.y);
        // raycast against all objects
        int cor = 0;

        while (cor < 5)
        {
            Ray ray = camera3D.GetComponent <Camera>().ViewportPointToRay(checkpoints[cor]);
            if (Physics.Raycast(ray, out hit, 100f))
            {
                Debug.DrawRay(ray.origin, ray.direction * hit.distance, new Color(0, 1, 0, 1));
                Plane   camPlane        = new Plane(camera3D.GetComponent <Camera>().transform.forward, camera3D.GetComponent <Camera>().transform.position);
                Vector3 thePoint        = ray.GetPoint(hit.distance);
                float   currentDistance = camPlane.GetDistanceToPoint(thePoint);
                if (currentDistance < nearDistance)
                {
                    nearDistance = currentDistance;
                }
            }
            cor++;
        }
        if (nearDistance < Mathf.Infinity)
        {
            objectDistance = Mathf.Clamp(nearDistance, minimumDistance, maximumDistance);
        }
        objectDistance = Mathf.Max(objectDistance, camera3D.GetComponent <Camera>().nearClipPlane);
        setScreenParallax();
    }
Esempio n. 5
0
    public virtual void castForObjects()
    {
        Vector2       dPosition = default(Vector2);
        RaycastHit    hit       = default(RaycastHit);
        s3dInteractor actScript = null;

        if ((camera3D.format3D == (mode3D)0) && !camera3D.sideBySideSqueezed)
        {
            dPosition = new Vector2((s3dTexture.obPosition.x / 2) + 0.25f, s3dTexture.obPosition.y); // 0 = left, 0.5 = center, 1 = right
        }
        else
        {
            dPosition = s3dTexture.obPosition;
        }
        Ray ray = camera3D.GetComponent <Camera>().ViewportPointToRay(dPosition);

        if (Physics.Raycast(ray, out hit, 100f))
        {
            Debug.DrawRay(ray.origin, ray.direction * hit.distance, new Color(0, 1, 0, 0));
            // if there's currently an activeObj, notify it of hit position
            if (activeObj && followActiveObject)
            {
                actScript = (s3dInteractor)activeObj.GetComponent(typeof(s3dInteractor));
                if (actScript)
                {
                    actScript.updatePosition(hit.point);
                }
                // if activeObj, tell any attached aimObject.js scripts to point at it
                gameObject.SendMessage("PointAt", activeObj.transform.position, SendMessageOptions.DontRequireReceiver);
            }
            else
            {
                // if no activeObj, tell any attached aimObject.js scripts to point at hitpoint
                gameObject.SendMessage("PointAt", hit.point, SendMessageOptions.DontRequireReceiver);
            }
        }
        // next, raycast against objects in interactive layer (for taps)
        ray = camera3D.GetComponent <Camera>().ViewportPointToRay(dPosition);
        if (trackMouseXYPosition)
        {
            if (Physics.Raycast(ray, out hit, clickDistance, (int)interactiveLayerMask))
            {
                if (Input.GetMouseButtonDown(0))
                {
                    processTap(hit, true, 1); // tapped on object
                }
                else
                {
                    processRollover(hit, true); // rolled over object
                }
            }
            else
            {
                if (Input.GetMouseButtonDown(0))
                {
                    processTap(hit, false, 1); // if there's no hit, process clicks anyway to deactivate active objects
                }
                else
                {
                    if (prevRolloverObject != null)
                    {
                        processRollover(hit, false); // lost rolled over object
                    }
                }
            }
        }
        if (useTouchpad && readyForTap)
        {
            if (Physics.Raycast(ray, out hit, clickDistance, (int)interactiveLayerMask))
            {
                if (touchpad.tap > 0)
                {
                    processTap(hit, true, touchpad.tap); // tapped on object
                }
                else
                {
                    processRollover(hit, true); // rolled over object
                }
            }
            else
            {
                if (touchpad.tap > 0)
                {
                    processTap(hit, false, touchpad.tap); // if there's no hit, process clicks anyway to deactivate active objects
                }
                else
                {
                    if (prevRolloverObject != null)
                    {
                        processRollover(hit, false); // lost rolled over object
                    }
                }
            }
            touchpad.reset();
            readyForTap = false;
            StartCoroutine(pauseAfterTap());
        }
    }