202 lines
5.5 KiB
C#
202 lines
5.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Runtime.InteropServices;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class MyTest : MonoBehaviour
|
|
{
|
|
|
|
public Canvas canvas_122;
|
|
public Camera camera_122;
|
|
public GameObject upPage;
|
|
public GameObject downPage;
|
|
|
|
public GameObject 放大;
|
|
public GameObject 缩小;
|
|
|
|
|
|
public Button downScale;
|
|
public Button upScale;
|
|
public Button backScale;
|
|
|
|
|
|
public Vector3 cameraLocalPos;
|
|
public Vector3 obj1pos;
|
|
public Vector3 obj2pos;
|
|
public Vector3 obj2Scale;
|
|
|
|
public GameObject btn122;
|
|
|
|
private void OnEnable()
|
|
{
|
|
//放大.SetActive(true);
|
|
//缩小.SetActive(true);
|
|
btn122.SetActive(true);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
//放大.SetActive(false);
|
|
//缩小.SetActive(false);
|
|
if (btn122 != null)
|
|
btn122.SetActive(false);
|
|
|
|
}
|
|
public bool isScale;
|
|
void Start()
|
|
{
|
|
|
|
|
|
//obj1pos = canvas_122.transform.GetChild(0).GetComponent<RectTransform>().anchoredPosition;
|
|
obj1pos = new Vector3(117, 89, 0);
|
|
obj2pos = new Vector3(-30, 383, 0);
|
|
obj2Scale = new Vector3(0.6619977f, 0.6619977f, 0.6619977f);
|
|
//obj2pos = upPage.GetComponent<RectTransform>().anchoredPosition;
|
|
//obj2Scale = upPage.GetComponent<RectTransform>().localScale;
|
|
|
|
isScale = false;
|
|
cameraLocalPos = camera_122.transform.localPosition;
|
|
backScale.onClick.AddListener(() => {
|
|
|
|
camera_122.transform.localPosition = cameraLocalPos;
|
|
canvas_122.GetComponent<CanvasScaler>().scaleFactor = 1.55f;
|
|
if (upPage != null)
|
|
{
|
|
|
|
upPage.GetComponent<RectTransform>().anchoredPosition = obj2pos;
|
|
upPage.GetComponent<RectTransform>().localScale = obj2Scale;
|
|
upPage.SetActive(true);
|
|
//downPage.SetActive(true);
|
|
|
|
}
|
|
if (downPage != null)
|
|
{
|
|
|
|
canvas_122.transform.GetChild(0).GetComponent<RectTransform>().anchoredPosition = obj1pos;
|
|
downPage.SetActive(true);
|
|
}
|
|
放大.SetActive(true);
|
|
缩小.SetActive(false);
|
|
isScale = false;
|
|
});
|
|
//-0.001 -0.245 0.608
|
|
//1.93 285.76
|
|
|
|
downScale.onClick.AddListener(() => {
|
|
|
|
//camera_122.transform.localPosition = new Vector3(-0.001f, -0.245f, 0.608f);
|
|
camera_122.transform.localPosition = new Vector3(-0.005f, -0.242f, 0.59f);
|
|
if (downPage != null)
|
|
{
|
|
canvas_122.GetComponent<CanvasScaler>().scaleFactor = 2.9f;
|
|
canvas_122.transform.GetChild(0).GetComponent<RectTransform>().anchoredPosition = new Vector3(111, 270f, 0);
|
|
|
|
downPage.SetActive(true);
|
|
|
|
}
|
|
if(upPage!=null)
|
|
upPage.SetActive(false);
|
|
放大.SetActive(false);
|
|
缩小.SetActive(true);
|
|
isScale = true;
|
|
});
|
|
|
|
upScale.onClick.AddListener(() => {
|
|
|
|
camera_122.transform.localPosition = new Vector3(-0.0059f, 0.103f, 0.59f);
|
|
|
|
if (upPage != null )
|
|
{
|
|
canvas_122.GetComponent<CanvasScaler>().scaleFactor = 2.07f;
|
|
upPage.SetActive(true);
|
|
|
|
upPage.GetComponent<RectTransform>().localScale = Vector3.one;
|
|
upPage.GetComponent<RectTransform>().anchoredPosition = new Vector3(-45, 267f, 0);
|
|
|
|
}
|
|
if(downPage!=null)
|
|
downPage.SetActive(false);
|
|
放大.SetActive(false);
|
|
缩小.SetActive(true);
|
|
isScale = true;
|
|
});
|
|
|
|
|
|
}
|
|
|
|
public void OnInit(int index)
|
|
{
|
|
if (isScale == false)
|
|
{
|
|
if (downPage != null && upPage != null)
|
|
{
|
|
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (index == 0)
|
|
{
|
|
canvas_122.GetComponent<CanvasScaler>().scaleFactor = 2.9f;
|
|
canvas_122.transform.GetChild(0).GetComponent<RectTransform>().anchoredPosition = new Vector3(113, 270f, 0);
|
|
if (upPage != null)
|
|
upPage.SetActive(false);
|
|
downPage.SetActive(true);
|
|
}
|
|
else
|
|
{
|
|
canvas_122.GetComponent<CanvasScaler>().scaleFactor = 2.07f;
|
|
upPage.SetActive(true);
|
|
if (downPage != null)
|
|
downPage.SetActive(false);
|
|
upPage.GetComponent<RectTransform>().localScale = Vector3.one;
|
|
upPage.GetComponent<RectTransform>().anchoredPosition = new Vector3(-33, 267f, 0);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void Update()
|
|
{
|
|
|
|
// 判断是否有按键按下
|
|
//if (Input.anyKeyDown)
|
|
//{
|
|
// // 遍历 KeyCode 枚举,找到按下的键
|
|
// foreach (KeyCode kc in System.Enum.GetValues(typeof(KeyCode)))
|
|
// {
|
|
// if (Input.GetKeyDown(kc))
|
|
// {
|
|
// Debug.Log("按下的键:" + kc.ToString());
|
|
// break;
|
|
// }
|
|
// }
|
|
//}
|
|
|
|
if (Input.GetKeyDown(KeyCode.Space))
|
|
{
|
|
//camera_122.transform.localPosition = new Vector3(-0.001f, 0.103f, 0.599f);
|
|
|
|
}
|
|
|
|
if (Input.GetKeyDown(KeyCode.F11))
|
|
{
|
|
Debug.Log("11");
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public void OnDown()
|
|
{
|
|
|
|
}
|
|
}
|