代码只有一个:
public class CameraSurround : MonoBehaviour {
public GameObject look_objects;
private int shape_count = 0;
private int shape_index = 0;
public Light gameobject_light;
private bool is_self_rotate = true;
public Text target_text;
public Text color_text;
private void Start()
{
look_objects = GameObject.Find("ReferShapes");
shape_count = look_objects.transform.childCount;
shape_index = 0;
}
void Update () {
if(Input.GetKey(KeyCode.LeftArrow))
{
Vector3 rotate = new Vector3(0f, 1f, 0f);
if(is_self_rotate)
{
transform.RotateAround(look_objects.transform.GetChild(shape_index).transform.position, rotate, 5f);
}
else
{
look_objects.transform.GetChild(shape_index).transform.Rotate(rotate);
}
}
else if(Input.GetKey(KeyCode.RightArrow))
{
Vector3 rotate = new Vector3(0f, -1f, 0f);
if (is_self_rotate)
{
transform.RotateAround(look_objects.transform.GetChild(shape_index).transform.position, rotate, 5f);
}
else
{
look_objects.transform.GetChild(shape_index).transform.Rotate(rotate);
}
}
else if (Input.GetKey(KeyCode.UpArrow))
{
Vector3 rotate = new Vector3(1f, 0f, 0f);
if (is_self_rotate)
{
transform.RotateAround(look_objects.transform.GetChild(shape_index).transform.position, rotate, 5f);
}
else
{
look_objects.transform.GetChild(shape_index).transform.Rotate(rotate);
}
}
else if (Input.GetKey(KeyCode.DownArrow))
{
Vector3 rotate = new Vector3(-1f, 0f, 0f);
if (is_self_rotate)
{
transform.RotateAround(look_objects.transform.GetChild(shape_index).transform.position, rotate, 5f);
}
else
{
look_objects.transform.GetChild(shape_index).transform.Rotate(rotate);
}
}
else if (Input.GetKeyDown(KeyCode.R))
{
if(is_self_rotate)
{
transform.position = new Vector3(0, 0, 0);
transform.rotation = new Quaternion(0f, 0f, 0f, 0f);
}
else
{
look_objects.transform.GetChild(shape_index).transform.rotation = new Quaternion(0f, 0f, 0f, 0f);
}
}
else if(Input.GetKeyDown(KeyCode.N))
{
look_objects.transform.GetChild(shape_index).gameObject.SetActive(false);
shape_index = shape_index < (shape_count - 1) ? (shape_index + 1) : 0;
look_objects.transform.GetChild(shape_index).gameObject.SetActive(true);
}
else if(Input.GetKeyDown(KeyCode.M))
{
is_self_rotate = !is_self_rotate;
target_text.text = is_self_rotate == true ? "目前旋转者为:摄像机" : "目前旋转者为:物体";
}
else if (Input.GetKeyDown(KeyCode.H))
{
float h, s, v;
Color.RGBToHSV(gameobject_light.color, out h, out s, out v);
h = h < 1f ? h + 0.05f : 0f;
gameobject_light.color = Color.HSVToRGB(h,s,v);
color_text.text = string.Format("当前颜色值为:H{0:P},S{1:P},V{2:P}", h, s, v);
}
else if (Input.GetKeyDown(KeyCode.S))
{
float h, s, v;
Color.RGBToHSV(gameobject_light.color, out h, out s, out v);
s = s < 1f ? s + 0.05f : 0f;
gameobject_light.color = Color.HSVToRGB(h, s, v);
color_text.text = string.Format("当前颜色值为:H{0:P},S{1:P},V{2:P}", h, s, v);
}
else if (Input.GetKeyDown(KeyCode.V))
{
float h, s, v;
Color.RGBToHSV(gameobject_light.color, out h, out s, out v);
v = v < 1f ? v + 0.05f : 0f;
gameobject_light.color = Color.HSVToRGB(h, s, v);
color_text.text = string.Format("当前颜色值为:H{0:P},S{1:P},V{2:P}", h, s, v);
}
if (Input.GetKeyDown(KeyCode.Escape) || Input.GetKeyDown(KeyCode.Home))
{
Application.Quit();
}
}
}