예제 #1
0
    // OnGUICrosshair
    public void  OnGUICrosshair()
    {
        if ((DisplayCrosshair == true) && (CollisionWithGeometry == false))
        {
            FadeVal += Time.deltaTime / FadeTime;
        }
        else
        {
            FadeVal -= Time.deltaTime / FadeTime;
        }

        FadeVal = Mathf.Clamp(FadeVal, 0.0f, 1.0f);

        // Check to see if crosshair influences mouse rotation
        if (PlayerController != null)
        {
            PlayerController.SetAllowMouseRotation(false);
        }

        if ((ImageCrosshair != null) && (FadeVal != 0.0f))
        {
            // Assume cursor is on-screen (unless it goes into the dead-zone)
            // Other systems will check this to see if it is false for example
            // allowing rotation to take place
            if (PlayerController != null)
            {
                PlayerController.SetAllowMouseRotation(true);
            }

            GUI.color = new Color(1, 1, 1, FadeVal * FadeScale);

            // Calculate X
            XL += Input.GetAxis("Mouse X") * ScaleSpeedX;
            if (XL < DeadZoneX)
            {
                if (PlayerController != null)
                {
                    PlayerController.SetAllowMouseRotation(false);
                }

                XL = DeadZoneX - 0.001f;
            }
            else if (XL > (Screen.width - DeadZoneX))
            {
                if (PlayerController != null)
                {
                    PlayerController.SetAllowMouseRotation(false);
                }

                XL = ScreenWidth - DeadZoneX + 0.001f;
            }

            // Calculate Y
            YL -= Input.GetAxis("Mouse Y") * ScaleSpeedY;
            if (YL < DeadZoneY)
            {
                //CursorOnScreen = false;
                if (YL < 0.0f)
                {
                    YL = 0.0f;
                }
            }
            else if (YL > ScreenHeight - DeadZoneY)
            {
                //CursorOnScreen = false;
                if (YL > ScreenHeight)
                {
                    YL = ScreenHeight;
                }
            }

            // Finally draw cursor
            bool allowMouseRotation = true;
            if (PlayerController != null)
            {
                PlayerController.GetAllowMouseRotation(ref allowMouseRotation);
            }

            if (allowMouseRotation == true)
            {
                // Left
                GUI.DrawTexture(new Rect(XL - (ImageCrosshair.width * 0.5f),
                                         YL - (ImageCrosshair.height * 0.5f),
                                         ImageCrosshair.width,
                                         ImageCrosshair.height),
                                ImageCrosshair);
            }

            GUI.color = Color.white;
        }
    }