using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
using Lovatto.OrbitCamera;
using DG;
using DG.Tweening;
using System.IO;
using UnityEngine.Experimental.GlobalIllumination;
public class main : MonoBehaviour
{
// Start is called before the first frame update
public Text txt1;
public Text txt2;
bool SplitModelBoo = false;
public Animation _Animation;
public AnimationClip[] clips;
public bl_CameraOrbit _bl_CameraOrbit;
bool AutoRoa = true;
public GameObject Leftui;
bool OpenLeftUiBoo = true;
[SerializeField]
Camera UI_Camera;//UI相机
[SerializeField]
Canvas ui_Canvas;
[System.Serializable]
public struct PointInfo
{
public GameObject Point3d;
public string Title;
public string Info;
}
public PointInfo[] _PointInfo = new PointInfo[3];
public RectTransform Circle;
public GameObject Tripmc;
public Text Titletxt;
public Text Infotxt;
public int ShowinfoI;
bool Showinfoboo = false;
public RectTransform Line;
public GameObject[] Uiall;
int UiallIndex = 0;
public GameObject RightModel;
void Start()
{
ShowRightModel(false);
HideInfo();
HideUiall();
}
// Update is called once per frame
void Update()
{
if (Showinfoboo) {
Vector2 mouseDown = Camera.main.WorldToScreenPoint(_PointInfo[ShowinfoI].Point3d.transform.position);
Vector2 mouseUGUIPos = new Vector2();
bool isRect = RectTransformUtility.ScreenPointToLocalPointInRectangle(ui_Canvas.transform as RectTransform, mouseDown, UI_Camera, out mouseUGUIPos);
if (isRect)
{
Circle.anchoredPosition = mouseUGUIPos;
}
//Line.anchoredPosition = mouseUGUIPos;
CreateLine(Line.gameObject, mouseUGUIPos, Tripmc.GetComponent<RectTransform>().anchoredPosition3D);
}
}
public void SplitModel(bool boo)
{if (SplitModelBoo == boo) return;
SplitModelBoo=boo;
if (boo)
{
_Animation.clip = clips[0];
AnimationState state = _Animation["Take 001"];
state.speed = 1;
_Animation.Play();
txt1.text = "组合模型";
}
else
{
_Animation.clip = clips[0];
AnimationState state = _Animation["Take 001"];
state.speed = -1;
_Animation.Play();
txt1.text = "拆分模型";
HideInfo();
}
}
public void SplitModelLoop()
{
SplitModel(!SplitModelBoo);
}
public void SetAutoRoa()
{
if (AutoRoa)
{
_bl_CameraOrbit.AutoRotate = true;
txt2.text = "手动旋转";
}
else
{
_bl_CameraOrbit.AutoRotate = false;
txt2.text = "自动旋转";
}
AutoRoa = !AutoRoa;
}
//public void OpenLeftUiLoop()
//{
// OpenLeftUi(!OpenLeftUiBoo);
//}
public void ShowRightModel(bool boo) {
RightModel.gameObject.SetActive(boo);
if (boo)
{
_bl_CameraOrbit.gameObject.GetComponent<Camera>().orthographic = true;
}
else {
_bl_CameraOrbit.gameObject.GetComponent<Camera>().orthographic = false;
}
}
public void HideUiall()
{
for (int i = 0; i<Uiall.Length; i++) {
Uiall[i].gameObject.SetActive(false);
}
ShowRightModel(false);
}
public void OpenUiall(int j)
{
if (j == 0)
{
ShowRightModel(false);
}
else {
ShowRightModel(true);
}
UiallIndex = j;
for (int i = 0; i < Uiall.Length; i++) {
Uiall[i].gameObject.SetActive(i==j?true:false);
}
SplitModel(false);
}
public void Showinfo(int i) {
Showinfoboo = true;
Circle.gameObject.SetActive(true);
Tripmc.gameObject.SetActive(true);
Line.gameObject.SetActive(true);
Titletxt.text = _PointInfo[i].Title;
Infotxt.text = _PointInfo[i].Info;
ShowinfoI = i;
HideUiall();
}
public void HideInfo() {
Showinfoboo = false;
Circle.gameObject.SetActive(false);
Tripmc.gameObject.SetActive(false);
Line.gameObject.SetActive(false);
}
void CreateLine(GameObject line, Vector2 startPosition, Vector2 endPosition)
{
var heading = endPosition - startPosition;
var distance = heading.magnitude;
var direction = heading / distance;
RectTransform rtLine = line.GetComponent<RectTransform>();
对齐左下角
//rtLine.anchorMin = Vector2.zero;
//rtLine.anchorMax = Vector2.zero;
//计算线条位置
// Vector2 centerPos = new Vector2(startPosition.x + endPosition.x, startPosition.y + endPosition.y) / 2;
rtLine.anchoredPosition = startPosition;
//计算线条角度
float angle = Mathf.Atan2(direction.y, direction.x) * Mathf.Rad2Deg;
line.transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
rtLine.sizeDelta = new Vector2(distance, 5.0f);
}
}