//ViewChanged脚本需绑定在主相机上
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.EventSystems;
public class ViewChanged : MonoBehaviour, IPointerClickHandler
{
public Button SubBtn;//减少视角按钮
public Button AddBtn;//增大视角按钮
public Text ShowTxt;
public GameObject _3DGameParent;
public int no = 1;
void Start()
{
ShowTxt.text = "1";
SubBtn.GetComponent<Button>().onClick.AddListener(delegate
{
this.OnClick1(SubBtn.GetComponent<Button>());
});
AddBtn.GetComponent<Button>().onClick.AddListener(delegate
{
this.OnClick2(AddBtn.GetComponent<Button>());
});
}
void OnClick1(Button btn)
{
if (no > 1)
{
int j;
j = int.Parse(ShowTxt.text) - 1;
ShowTxt.text = j.ToString();
no--;
}
ViewNumChoose(no);
}
void OnClick2(Button btn)
{
if (no < 6)
{
int i;
i = int.Parse(ShowTxt.text) + 1;
ShowTxt.text = i.ToString();
no++;
}
ViewNumChoose(no);
}
#region 根据切换的视角,旋转物体
private void ViewNumChoose(int num)
{
_3DGameParent.transform.position = Vector3.zero;
switch (num)
{
case 1:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 0, 0);
// _3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.right);
break;
case 2:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 90, 0);
// _3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.back);
break;
case 3:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 180, 0);
//_3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.left);
break;
case 4:
_3DGameParent.transform.localRotation = Quaternion.Euler(0, 270, 0);
// _3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.forward);
break;
case 5:
_3DGameParent.transform.localRotation = Quaternion.Euler(90, 0, 0);
//_3DGameParent.transform.LookAt(_3DGameParent.transform.position + Vector3.up);
break;
case 6:
_3DGameParent.transform.localRotation = Quaternion.Euler(270, 0, 0);
//_3DGameParent.transform.LookAt(-_3DGameParent.transform.position + Vector3.down);
break;
default:
break;
}
}
#endregion
void Update ()
{
}
public void OnPointerClick(PointerEventData eventData)
{
throw new System.NotImplementedException();
}
}