Есть у кого скрипты поведения камеры? У меня на Unity, реализовано что то вреде плеера, который в зависимости от настроек проигрывает сцены. И мне нужны скрипты поведения камеры, такие которые ловят красивые виды.
Пару скриптов у меня уже есть(только их надо доработать, уж слишком некрасивый код получился):
Может ещё кто предложит сценарий поведения камеры?
1 и 2 скрипт объединён в один. Код следующий:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System;
using System.Timers;
using System.Threading;
using UnityEngine.SceneManagement;
public class RTCCamera : MonoBehaviour
{
// public Transform tank;
// public float distance = 15.0f;
// public float xSpeed = 50.0f;
// public float ySpeed = 50.0f;
// public float yMinLimit = -20.0f;
// public float yMaxLimit = 40.0f;
//
// private float x;
// private float y;
//
// public float heightOffset = 3.5f;
//(GameObject.Find ("M-109")) ? GameObject.Find ("M-109"): null ;
public Transform target = null;
public Vector3 offset = new Vector3(0f,10f,0f);
public Quaternion angleoffset = new Quaternion(0.5f,0f,0f,5f) ;
float sensitivity =0.2f; // чувствительность мышки
float limit = 80; // ограничение вращения по Y
float zoom = 0.25f; // чувствительность при увеличении, колесиком мышки
public float zoomMin = 40f; // мин. увеличение
public float zoomMax = 50f; // макс. увеличение
public float Hmin = 5f;
float tempHmin ;
public float Anglemin = 0f;
public float Hmax = 30f;
float tempHmax ;
public float Anglemax = 2f;
public float HeightChangeRate = 0.1f;
public float AngleChangeRate = 0.001f;
private float X, Y;
float index = 1f;
bool zoombool = true;
public bool onStartCamera = false;
RTCTankController[] TanksList = null;
public GameObject GameObjWithList = null;
private int currentList = 0;
Vector3 relPos;
Quaternion newRot;
public float speed = 0.65f;
public float turn_speed = 1F;
// Vector3 targetRotationCamera;
string SceneName = "";
bool sum = false;
void Reset() {
target = (GameObject.Find ("M-109")) ? GameObject.Find ("M-109").transform : null ;
GameObjWithList = (GameObject.Find ("Vehicles")) ? GameObject.Find ("Vehicles"): null ;
}
void Start ()
{
// Vector3 angles = transform.eulerAngles;
// x = angles.x;
// y = angles.y;
//
// if(GetComponent<Rigidbody>() != null)
// {
// GetComponent<Rigidbody>().freezeRotation = true;
// }
if(SceneName == "Library") {
target = GameObject.Find("Vehicles").GetComponent<Vehicles>().GetActivModel();
}
tempHmin = Hmin+target.position.y;
tempHmax = Hmax+target.position.y;
SceneName = SceneManager.GetActiveScene().name;
limit = Mathf.Abs(limit);
if(limit > 90) limit = 90;
offset = new Vector3(offset.x, offset.y, -Mathf.Abs(zoomMax)/2);
if (SceneName == "ShootingOne" || SceneName=="ShootingDefeat") {
} else if (SceneName == "PathAll" || SceneName == "Distribution" || SceneName == "ShellingMovement" || SceneName == "СolumnMovement" || SceneName == "IntelligenceService" ) {
transform.position = target.position + offset;
TanksList = GameObjWithList.GetComponentsInChildren<RTCTankController>();
if (SceneName == "СolumnMovement") {
InvokeRepeating ("SwitchingGameObj_tow", 0, 5f);
} else {
InvokeRepeating("SwitchingGameObj", 0, 5f);
}
} else if (SceneName == "Library") {
transform.position = target.position + offset;
}
if (SceneName == "IntelligenceService") {
zoomMin = 410f;
zoomMax = 450f;
}
//targetRotationCamera = target.position;
}
private void SwitchingGameObj() {
onStartCamera = false;
currentList++;
}
private void SwitchingGameObj_tow() {
onStartCamera = true;
currentList++;
}
private void SwitchingFunctionCamera() {
if (onStartCamera == true)
onStartCamera = false;
else {
onStartCamera = true;
Invoke ("SwitchingFunctionCamera", 5f);
}
}
private void SwitchBetweenGameObjCamera() {
if (TanksList != null) {
if (currentList < TanksList.Length) {
target = TanksList [currentList].transform;
if (transform.position.x > target.position.x) {
transform.position = Vector3.MoveTowards(transform.position, target.position+offset, speed);
relPos = target.position - transform.position;
newRot = Quaternion.LookRotation (relPos);
transform.rotation = Quaternion.RotateTowards (transform.rotation,newRot,Time.time*speed);
} else {
Vector3 tumpVector3 = new Vector3 (offset.x,offset.y * -1f,offset.z);
transform.position = Vector3.MoveTowards(transform.position, target.position - tumpVector3, speed);
relPos = target.position - transform.position;
newRot = Quaternion.LookRotation (relPos);
transform.rotation = Quaternion.RotateTowards (transform.rotation ,newRot,Time.time*speed);
}
} else {
currentList = 0;
target = TanksList[currentList].transform;
transform.position = Vector3.MoveTowards(transform.position, target.position+offset, speed);
relPos = target.position - transform.position;
newRot = Quaternion.LookRotation (relPos);
transform.rotation = Quaternion.RotateTowards (transform.rotation,newRot,Time.time*speed);
//CancelInvoke ("SwitchingGameObj");
onStartCamera = true;
}
}
}
void Face_target(Vector3 relativePos)
{
Quaternion rotation = Quaternion.LookRotation(relativePos, Vector3.up);
transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * turn_speed); // slerp ( from.rotation, to.rotation, speed)
}
void LateUpdate()
{
// SceneName = SceneManager.GetActiveScene().name;
if (SceneName=="ShootingOne" || SceneName=="ShootingDefeat") {
} else if (SceneName=="IntelligenceService") {
SwitchBetweenGameObjCamera();
} else {
if (SceneName == "Library") {
onStartCamera = true;
if(SceneName == "Library") {
target = GameObject.Find("Vehicles").GetComponent<Vehicles>().GetActivModel();
}
}
if (onStartCamera) {
if (tempHmin != Hmin+target.position.y) { tempHmin = Hmin + target.position.y; } ;
if (tempHmax != Hmax+target.position.y) { tempHmax = Hmax + target.position.y; } ;
RotationRoundCamera ();
} else {
SwitchBetweenGameObjCamera();
}
}
// if(tank != null)
// {
//
// x += (float)(Input.GetAxis("Mouse X") * xSpeed * 0.02f);
// y -= (float)(Input.GetAxis("Mouse Y") * ySpeed * 0.02f);
//
// y = ClampAngle(y, yMinLimit, yMaxLimit);
//
// Quaternion rotation = Quaternion.Euler(y, x, 0);
// Vector3 position = rotation * (new Vector3(0.0f, heightOffset, -distance)) + tank.position;
//
// transform.rotation = rotation;
// transform.position = position;
//
// }
}
// void RotationCamera () {
// if (targetRotationCamera != null) {
// Quaternion targetRotation = Quaternion.LookRotation(targetRotationCamera - transform.position);
// transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, Time.deltaTime * 4f);
// }
// }
void RotationRoundCamera() {
if(transform.position.y >= tempHmin && transform.position.y <= tempHmax && sum==false ) {
//transform.position = new Vector3(transform.position.x,transform.position.y-2,transform.position.z);
offset = new Vector3 (offset.x,offset.y-HeightChangeRate,offset.z);
if (angleoffset.x - AngleChangeRate >= Anglemin) {
angleoffset = new Quaternion (angleoffset.x-AngleChangeRate,angleoffset.y,angleoffset.z,angleoffset.w);
} else {
angleoffset = new Quaternion (angleoffset.x,angleoffset.y,angleoffset.z,angleoffset.w);
}
} else if(transform.position.y > tempHmax) {
sum = false;
offset = new Vector3 (offset.x,offset.y-HeightChangeRate,offset.z);
if (angleoffset.x - AngleChangeRate >= Anglemin) {
angleoffset = new Quaternion (angleoffset.x-AngleChangeRate,angleoffset.y,angleoffset.z,angleoffset.w);
} else {
angleoffset = new Quaternion (angleoffset.x,angleoffset.y,angleoffset.z,angleoffset.w);
}
//transform.position = new Vector3(transform.position.x,transform.position.y-2,transform.position.z);
} else if (transform.position.y >= tempHmin && transform.position.y <= tempHmax && sum==true ) {
//transform.position = new Vector3(transform.position.x,transform.position.y+2,transform.position.z);
offset = new Vector3 (offset.x,offset.y+HeightChangeRate,offset.z);
if (angleoffset.x + AngleChangeRate <= Anglemax) {
angleoffset = new Quaternion (angleoffset.x+AngleChangeRate,angleoffset.y,angleoffset.z,angleoffset.w);
} else {
angleoffset = new Quaternion (angleoffset.x,angleoffset.y,angleoffset.z,angleoffset.w);
}
} else if (transform.position.y < tempHmin) {
sum = true;
offset = new Vector3 (offset.x,offset.y+HeightChangeRate,offset.z);
if (angleoffset.x + AngleChangeRate <= Anglemax) {
angleoffset = new Quaternion (angleoffset.x+AngleChangeRate,angleoffset.y,angleoffset.z,angleoffset.w);
} else {
angleoffset = new Quaternion (angleoffset.x,angleoffset.y,angleoffset.z,angleoffset.w);
}
//transform.position = new Vector3(transform.position.x,transform.position.y+2,transform.position.z);
}
if (zoombool == true) {
offset.z += zoom/10f;
zoombool = true;
index=index + 0.25f;
if (index==zoomMax){zoombool = false;}
} else if (zoombool == false) {
offset.z -= zoom/10f;
zoombool = false;
index=index - 0.25f;
if (index == -zoomMin){zoombool = true;}
}
offset.z = Mathf.Clamp(offset.z, -Mathf.Abs(zoomMax), -Mathf.Abs(zoomMin));
if(SceneName == "Library") {
X = transform.localEulerAngles.y + 0.1f * sensitivity;
} else {
X = transform.localEulerAngles.y + 0.5f * sensitivity;
}
Y += 0.00000001f * sensitivity;
Y = Mathf.Clamp (Y, -limit, limit);
transform.localEulerAngles = new Vector3(-Y, X, 0);
transform.position = transform.localRotation * offset + target.position;
if (target.position.y == transform.position.y) {
transform.position = new Vector3 (transform.position.x, transform.position.y + target.position.y, transform.position.z);
}
if(angleoffset.w != 0f) {
transform.rotation = transform.rotation * angleoffset;
}
}
void OnCollisionEnter (Collision other) {
tempHmin = Terrain.activeTerrain.SampleHeight (transform.position);
print (other.gameObject.name);
}
}
по сути я хотел повторить путь на рисунке(во время кругового движения): Настройки у скрипта получились не очевидные и не всегда работающие:
За любые улучшения кода буду благодарен.
Айфон мало держит заряд, разбираемся с проблемой вместе с AppLab
Делаю десериализацию массива jsonЕсть следующий код:
В модуле libavi_plugin из состава VLC, присутствует следующий поиск по списку чанков: