При использовании стандартного мауслука на еееписи очень странно ведёт себя обзор мышью.
Я так понимаю что видеокарта этого ноута страмиться не считать лишних кадров, и когда картинка статична она тоже как бы уходит в режим ожидания и намного реже выполняет функцию Update.
В итоге мы имеем очень корявый обзор мышью, но что примечательно когда мы передвигаем персонажа(стандартного фпконтроллера) то видео отрисовывается плавно, но мышка по прежнему тупит.
Возникла идея - а что если часть скрипта отвечающего за опрос мыши перенести в отдельный поток, и соответственно реализация:
c# code
- Код: Выделить всё
using UnityEngine;
using System.Collections;
using System.Threading;
public class threadScript : MonoBehaviour {
//mouse block
public enum RotationAxes { MouseXAndY = 0, MouseX = 1, MouseY = 2 }
public RotationAxes axes = RotationAxes.MouseXAndY;
public float sensitivityX = 15F;
public float sensitivityY = 15F;
public float minimumX = -360F;
public float maximumX = 360F;
public float minimumY = -60F;
public float maximumY = 60F;
float xInput = 0F;
float yInput = 0F;
float xInputOld = 0F;
float yInputOld = 0F;
float averageXInput=0F;
float averageYInput=0F;
float rotationX = 0F;
float rotationY = 0F;
Quaternion originalRotation;
void mouse()
{
for(int i=10;i>0;i++)
{
if (axes == RotationAxes.MouseXAndY)
{
// Pass inputs to inputOlds first...
xInputOld=xInput;
yInputOld=yInput;
// Read the mouse input axis
xInput = Input.GetAxis("Mouse X") * sensitivityX;
yInput = Input.GetAxis("Mouse Y") * sensitivityY;
//Average new inputs with old
averageXInput = xInput + xInputOld;
averageYInput = yInput + yInputOld;
averageXInput *= 0.5f;
averageYInput *= 0.5f;
rotationX += averageXInput;
rotationY += averageYInput;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
else if (axes == RotationAxes.MouseX)
{
// Pass inputs to inputOlds first...
xInputOld=xInput;
// Read the mouse input axis
xInput = Input.GetAxis("Mouse X") * sensitivityX;
//Average new inputs with old
averageXInput = xInput + xInputOld;
averageXInput *= 0.5f;
rotationX += averageXInput;
rotationX = ClampAngle (rotationX, minimumX, maximumX);
Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
transform.localRotation = originalRotation * xQuaternion;
}
else
{
// Pass inputs to inputOlds first...
yInputOld=yInput;
// Read the mouse input axis
yInput = Input.GetAxis("Mouse Y") * sensitivityY;
//Average new inputs with old
averageYInput = yInput + yInputOld;
averageYInput *= 0.5f;
rotationY += averageYInput;
rotationY += Input.GetAxis("Mouse Y") * sensitivityY;
rotationY = ClampAngle (rotationY, minimumY, maximumY);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
transform.localRotation = originalRotation * yQuaternion;
}
}
}
//end mouse block
void Start () {
//
if (rigidbody)
rigidbody.freezeRotation = true;
originalRotation = transform.localRotation;
//
Thread oThread = new Thread(new ThreadStart(mouse));
oThread.Start();
/*while (!oThread.IsAlive);
Thread.Sleep(1); */
try
{
Debug.Log("Try to restart the print thread");
oThread.Start();
}
catch (ThreadStateException)
{
Debug.Log("ThreadStateException trying to restart print. ");
Debug.Log("Expected since aborted threads cannot be restarted.");
}
}
void Update () {}
public static float ClampAngle (float angle, float min, float max)
{
if (angle < -360F)
angle += 360F;
if (angle > 360F)
angle -= 360F;
return Mathf.Clamp (angle, min, max);
}
}
Но этот скрипт полностью убивает Юнити.
Подскажите пожалуйста, как верно реализовать фунцию аналогичную Апдейт, но такую которая вызывается независимо от каких то параметров и в отдельном потоке.
Функция FixedUpdate даже с маленьким таймером в моих руках безполезна, т.к если таймер делать воистину маленьким то оч сильно возрастает нагрузка на систему, а если оставлять 0,02 то мышка работает дёргано.