using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Move
{
public Camera cachedCam;
public Camera orthCam;
public InputField inputfield1;
public InputField inputfield2;
public Button btn;
public void Onmove(Camera cachedCam,float x,float y, float angle)
{
Vector3 temp = new Vector3();
temp = cachedCam.transform.position;
Vector3 dir = new Vector3();
dir.x = x;
dir.y = 0;
dir.z = y;
cachedCam.transform.position = Vector3.Lerp(temp,dir,0.5f);
Vector3 temprotation = cachedCam.transform.rotation.eulerAngles;
temprotation.y = angle;
}
void Rotating(float hor, float ver)
{
//获取方向
Vector3 dir = new Vector3(hor, 0, ver);
//将方向转换为四元数
Quaternion quaDir = Quaternion.LookRotation(dir, Vector3.up);
//缓慢转动到目标点
// transform.rotation = Quaternion.Lerp(transform.rotation, quaDir, Time.deltaTime * 100f);
}
void OnCameraMove( Vector3 pos, Vector3 dir)
{
if (cachedCam )
{
dir.y = 0;
// Vector3 oldDirXZ = transform.forward;
// oldDirXZ.y = 0;
// oldDirXZ.Normalize();
// Quaternion rot = Quaternion.FromToRotation(oldDirXZ, dir);
//Vector3 newpos = new Vector3(pos.x, transform.position.y, pos.z);
Vector3 newpos = new Vector3(pos.x, 0, pos.z);
if (orthCam)
{
float w = 2 * orthCam.orthographicSize * 16.0f / 9.0f;
float h = 2 * orthCam.orthographicSize;
Vector3 org = orthCam.transform.position;
Vector3 right = orthCam.transform.right;
Vector3 up = -orthCam.transform.up;
newpos = org + w * right * (newpos.x - 0.5f) + h * up * (newpos.z - 0.5f);
}
// Vector3 v = transform.rotation.eulerAngles;
// v.y += rot.eulerAngles.y;
// transform.rotation = Quaternion.Euler(v);
// transform.position = new Vector3(newpos.x, transform.position.y, newpos.z);
//transform.rotation = rot * transform.rotation;
}
}
Vector3 GetDir(string name)
{
string temp;
Vector3 dir = new Vector3();
temp = name.Replace("(", "").Replace(")", "");
string[] tmp = temp.Split(',');
dir.x = float.Parse(tmp[0]);
dir.y = 0;
dir.z = float.Parse(tmp[1]);
//(0,1)
return dir;
}
public void Onclick()
{
OnCameraMove(GetDir(inputfield1.text), GetDir(inputfield2.text));
}
}