using DG.Tweening;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Toolset.UI;
///
/// UI管理
///
public class UI_manage : MonoBehaviour
{
#region MyStatement
public static UI_manage inst;
[HideInInspector]
public BaseConf conf_child;//记录当前药材配置文件
bool IsShow_kind;
bool IsFirst = true;
[Tooltip("种类")]
public Button kind;//种类
//public List kind_2;
//public List kind_2_conf;
//[Tooltip("记录当前药材种类")]
//public BaseConf current_kind_conf;//记录当前药材种类
[Tooltip("种类类别")]
public List kinds;//种类类别
[Tooltip("二级菜单父类Grid")]
public RectTransform rt_Grid;//二级菜单父类Grid
[Tooltip("二级菜单实例化模板")]
public GameObject menuitem_obj;//二级菜单实例化模板
[Tooltip("二级菜下当前药材名字")]
///
/// 二级菜下当前药材名字
///
public Text name_current;//二级菜下当前药材名字
//[HideInInspector]
public List menuitem_img;//2级菜单图片列表
[Tooltip("需要克隆的二级菜单【便于滑动】")]
public List menuitem_img_clone;//需要克隆的二级菜单【便于滑动】
[Tooltip("上滑")]
public Button menuitem_UP_bt;
[Tooltip("下滑")]
public Button menuitem_Down_bt;
[Tooltip("3d展示按钮")]
public Button show3D;//3d展示按钮
[Tooltip("0:切片,1:活株,2:模型")]
public int show3D_unm = 2;//切片,活株,模型
[HideInInspector]
public bool IsShow3D;//是否展示3d模型
[Tooltip("展示图片")]
public Image Image_show;//展示图片
Vector3 dir_Image_show_parent=new Vector3(50,0,0);//有无简介中心场景偏移量
Vector3 star_Image_show_parent = new Vector3(0, 20.3f, 0);//初始中心场景坐标
[Tooltip("模型父物体")]
public GameObject FBX_obj;//模型父物体
///
/// 模型的坐标
///
public Vector3 FBX_pos;
[Tooltip("卷轴1")]
public Image JZ_1;//卷轴1
[Tooltip("卷轴中")]
public Image JZ_Z;//卷轴中
[Tooltip("卷轴2")]
public Image JZ_2;//卷轴2
[Tooltip("卷轴2下顶点坐标")]
public Vector3 JZ_2_ps;
Vector3 dir_Vector3 = new Vector3(0, -2.3f, 0);
//[HideInInspector]
public GameObject synopsis_parent;//简介父类
Vector3 synopsis_parent_pos;//简介父类初始坐标
public int IsFirst_synopsis;
[Tooltip("简介文本")]
public Text text_synopsis;//简介文本
[Tooltip("简介标题")]
public Text title_synopsis;//简介标题
[Tooltip("简介按钮")]
public Button synopsis_bt;//简介按钮
[HideInInspector]
public bool IsShow_synopsis;//是否展示简介内容
[Tooltip("关闭按钮")]
public Button exe_off;//关闭按钮
[Tooltip("关闭弹窗父类")]
public GameObject exe_off_img_parent;//关闭弹窗父类
[Tooltip("关闭弹窗图片")]
public Image exe_off_img;//关闭弹窗图片
[Tooltip("是")]
public Button exe_off_yes;//是
[Tooltip("否")]
public Button exe_off_no;//否
///
/// 初始高度基数
///
float hight_rt_Grid;
#endregion
private void Awake()
{
if (inst==null)
{
inst = this;
}
JZ_2_ps = JZ_2.transform.localPosition;
JZ_2.transform.localPosition = JZ_1.transform.localPosition + dir_Vector3;
synopsis_parent = JZ_1.transform.parent.gameObject;
synopsis_parent.SetActive(false);
synopsis_parent_pos = Image_show.transform.parent.localPosition;
Grid = rt_Grid.gameObject;
synopsis_bt.interactable = true;
}
// Start is called before the first frame update
void Start()
{
//for (int i = 0; i < kind_2.Count; i++)
//{
// kind_2[i].onClick.AddListener(menuitem_show(kind_2_conf[i]));
//}
show3D.onClick.AddListener(()=> {
if (show3D_unm == 0)//切到 切片
{
show3D_unm++;
show3D.image.overrideSprite = Resources.Load("切片");
FBX_obj.SetActive(false);
Image_show.overrideSprite = conf_child.go_img[0];
Image_show.SetNativeSize();
Image_show.gameObject.SetActive(true);
}
else if (show3D_unm == 1) //切到 活株
{
show3D_unm++;
show3D.image.overrideSprite = Resources.Load("活株");
FBX_obj.SetActive(false);
Image_show.overrideSprite = conf_child.go_img[1];
Image_show.SetNativeSize();
Image_show.gameObject.SetActive(true);
}
else if (show3D_unm == 2)//切到 3D
{
show3D.image.overrideSprite = Resources.Load("3D");
FBX_obj.SetActive(true);
Image_show.gameObject.SetActive(false);
show3D_unm = 0;
if (kind.transform.Find("Text").GetComponent().text== "矿石类")
{
show3D_unm = 1;
}
}
//if (!IsShow3D)
//{
// FBX_obj.SetActive(true);
// Image_show.gameObject.SetActive(IsShow3D);
// IsShow3D = true;
//}
//else
//{
// FBX_obj.SetActive(false);
// Image_show.gameObject.SetActive(IsShow3D);
// IsShow3D = false;
//}
});
synopsis_bt.onClick.AddListener(Synopsis_bt_onClick);
exe_off.onClick.AddListener(() =>
{
exe_off_img_parent.SetActive(true);
FBX_obj.transform.GetChild(0).gameObject.SetActive(false);
//exe_off_img.gameObject.SetActive(true);
});
exe_off_yes.onClick.AddListener(() =>
{
Application.Quit();
});
exe_off_no.onClick.AddListener(() =>
{
exe_off_img_parent.SetActive(false);
FBX_obj.transform.GetChild(0).gameObject.SetActive(true);
//exe_off_img.gameObject.SetActive(false);
});
float hight_rt_Grid = rt_Grid.gameObject.GetComponent().cellSize.y * Manage.inst.conf.menuitem_num + rt_Grid.gameObject.GetComponent().spacing.y * (Manage.inst.conf.menuitem_num - 1);
rt_Grid.sizeDelta = new Vector2(100, hight_rt_Grid);
kind.transform.Find("Text").GetComponent().text = "种类";
}
///
/// 简介按钮点击函数
///
public void Synopsis_bt_onClick()
{
if (!IsShow_synopsis)//展开
{
AudioSource a = Camera.main.GetComponent();
a.clip = Resources.Load("纸卷轴8");
a.Play();
Transform t = text_synopsis.transform.parent;
t.localPosition = new Vector3(t.localRotation.x, 0, 0);//保持简介内容置顶
synopsis_parent.SetActive(true);
JZ_Z.DOFade(1, 1);
JZ_Z.DOFillAmount(1, 1);
JZ_2.transform.DOLocalMove(JZ_2_ps, 1);
JZ_1.gameObject.SetActive(true);
IsShow_synopsis = !IsShow_synopsis;
}
else//收起
{
JZ_Z.DOFade(0, 1);
JZ_Z.DOFillAmount(0, 1);
JZ_2.transform.DOLocalMove(JZ_1.transform.localPosition + dir_Vector3, 1);
IsShow_synopsis = !IsShow_synopsis;
}
}
public void Synopsis_bt_onClick(bool b)
{
if (!b)//展开
{
if (!IsShow_synopsis)
{
AudioSource a = Camera.main.GetComponent();
a.clip = Resources.Load("纸卷轴8");
a.Play();
}
Transform t = text_synopsis.transform.parent;
t.localPosition = new Vector3(t.localRotation.x, 0, 0);//保持简介内容置顶
synopsis_parent.SetActive(true);
JZ_Z.DOFade(1, 1);
JZ_Z.DOFillAmount(1, 1);
JZ_2.transform.DOLocalMove(JZ_2_ps, 1);
JZ_1.gameObject.SetActive(true);
IsShow_synopsis = true;
}
else
{
JZ_Z.DOFade(0, 1);
JZ_Z.DOFillAmount(0, 1);
JZ_2.transform.DOLocalMove(JZ_1.transform.localPosition + dir_Vector3, 1);
IsShow_synopsis = false;
}
}
///
/// Grid高度倍数因子
///
float rt_Grid_factor = 1;
///
/// 是否增加Grid高度
///
bool IsAdd_rt_Grid;
[HideInInspector]
public GameObject Grid;
Transform t;
void Update()
{
#region 简介内容
if (JZ_Z.fillAmount == 1) //显示简介内容
{
text_synopsis.gameObject.SetActive(true);
title_synopsis.gameObject.SetActive(true);
}
else if (JZ_Z.fillAmount == 0 && !IsShow_synopsis)//隐藏简介父类
{
synopsis_parent.SetActive(false);
}
else if (JZ_Z.fillAmount < 1f)//隐藏简介内容
{
text_synopsis.gameObject.SetActive(false);
title_synopsis.gameObject.SetActive(false);
}
#endregion
#region 中央位置
if (!IsShow_synopsis)
{
//Image_show.transform.parent.localPosition = synopsis_parent_pos + new Vector3(50, 0, 0);//初始无简介中央偏右
if (FBX_obj.transform.GetChild(0) != null)
{
FBX_obj.transform.DOLocalMoveX(-50, 1);
}
Image_show.transform.parent.DOLocalMoveX(50, 1);
}
else
{
//Image_show.transform.parent.localPosition = synopsis_parent_pos;//中央正常
if (FBX_obj.transform.GetChild(0) != null)
{
FBX_obj.transform.DOLocalMoveX(0, 1);
}
Image_show.transform.parent.DOLocalMoveX(0, 1);
}
#endregion
#region 二级菜单实时设置【已注释】
//hight_rt_Grid = Grid.GetComponent().cellSize.y * Manage.inst.conf.menuitem_num + Grid.GetComponent().spacing.y * (Manage.inst.conf.menuitem_num - 1);//初始高度基数
//if (Manage.inst.conf!=null)
//{
// if (Grid.transform.localPosition.y >= (((rt_Grid_factor - 1) * Manage.inst.conf.menuitem_num) + (Manage.inst.conf.menuitem_num - 3)) * (Grid.GetComponent().cellSize.y + Grid.GetComponent().spacing.y)) //减几:总数减一列最多显示几个
// {
// IsAdd_rt_Grid = true;
// }
// if (IsAdd_rt_Grid)
// {
// //hight_rt_Grid = Grid.GetComponent().cellSize.y * Manage.inst.conf.menuitem_num + Grid.GetComponent().spacing.y * (Manage.inst.conf.menuitem_num - 1);//初始高度基数
// rt_Grid_factor++;
// rt_Grid.sizeDelta = new Vector2(100, hight_rt_Grid * rt_Grid_factor+60);
// Debug.Log(rt_Grid_factor + "行了");
// IsAdd_rt_Grid = false;
// }
//}
#endregion
}
#region 种类1级菜单
///
/// 点击种类1级菜单
///
public void Kind_but()
{
if (!IsShow_kind)
{
IsShow_kind = !IsShow_kind;
StartCoroutine(Kind_but_op());
}
else
{
IsShow_kind = !IsShow_kind;
StartCoroutine(Kind_but_cls());
}
}
IEnumerator Kind_but_op()
{
yield return new WaitForSeconds(0.02f);
kinds[0].transform.parent.transform.DOScaleY(1, 0.5f).SetEase(Ease.OutQuad);
kinds[0].transform.parent.GetComponent().DOSizeDelta(new Vector2(161, 42*4), 0.5f, false).SetEase(Ease.OutQuad);
}
IEnumerator Kind_but_cls()
{
yield return new WaitForSeconds(0.02f);
kinds[0].transform.parent.transform.DOScaleY(0, 0.5f).SetEase(Ease.OutQuad);
kinds[0].transform.parent.GetComponent().DOSizeDelta(new Vector2(161, 0), 0.5f, false).SetEase(Ease.OutQuad);
}
#endregion
#region 种类2级菜单设置
///
/// 种类2级菜单设置
///
/// 种类配置文件
public void menuitem_show(BaseConf conf)
{
if (conf.kind== "矿石类")
{
show3D_unm = 2;
show3D.image.overrideSprite = Resources.Load("活株");
}
else
{
show3D_unm = 1;
show3D.image.overrideSprite = Resources.Load("切片");
}
Synopsis_bt_onClick(true);
CarouselMenu carouselMenu = Grid.GetComponent();
carouselMenu.addV = 0;
carouselMenu.vk = 0;
carouselMenu.currentV = 0;
carouselMenu.vTotal = 0;
carouselMenu.vt = 0;
carouselMenu.startPoint = Vector2.zero;
carouselMenu.addVect = Vector2.zero;
carouselMenu.itemList.Clear();
Grid.GetComponent().enabled = true;
Grid.transform.localPosition = new Vector3(-4, -19.6f, 0);
Manage.inst.conf = conf;
kind.transform.Find("Text").GetComponent().text = conf.kind;
text_synopsis.text = conf.Bases[1].synopsis;
Image_show.transform.parent.localPosition = star_Image_show_parent;
if (menuitem_img.Count <= conf.menuitem_num)
{
//清除原图片
for (int i = 0; i < menuitem_img.Count; i++)
{
DestroyImmediate(menuitem_img[i].gameObject);
DestroyImmediate(menuitem_img_clone[i].gameObject);
}
menuitem_img.Clear();
menuitem_img_clone.Clear();
//赋值图片
for (int i = 0; i < conf.menuitem_num; i++)
{
GameObject go = Instantiate(menuitem_obj, Grid.transform);
go.name = (1+i).ToString();
go.GetComponent().conf_child = conf.Bases[i];//赋值配置文件
go.GetComponent().overrideSprite = conf.menuitem_img[i];
go.GetComponent().enabled = true;
go.SetActive(true);
menuitem_img.Add(go.GetComponent());
}
////设置高度
//float hight_rt_Grid = rt_Grid.gameObject.GetComponent().cellSize.y * conf.menuitem_num + rt_Grid.gameObject.GetComponent().spacing.y * (conf.menuitem_num - 1);
//rt_Grid.sizeDelta = new Vector2(100, hight_rt_Grid);
if (/*IsFirst*/true)
{
IsFirst = false;
conf_child = conf.Bases[1];//获取默认药材配置文件
if (FBX_obj.transform.childCount != 0)
{
Destroy(FBX_obj.transform.GetChild(0).gameObject);
}
Instantiate(conf_child.go, FBX_obj.transform).AddComponent();//实例化药材模型
FBX_obj.SetActive(false);
Image_show.gameObject.SetActive(true);
Image_show.overrideSprite = conf.Bases[1].go_img[0];
//Image_show.SetNativeSize();
GameObject CN = Image_show.transform.parent.Find("name_obj/CN").gameObject;
GameObject LT = Image_show.transform.parent.Find("name_obj/LT").gameObject;
CN.GetComponent().text = conf.Bases[1].name_CN;
LT.GetComponent().text = conf.Bases[1].name_LT;
CN.SetActive(true);
LT.SetActive(true);
show3D.gameObject.SetActive(true);
name_current.text = conf.Bases[1].name_CN;
}
}
else if (menuitem_img.Count > conf.menuitem_num)
{
Debug.Log(2);
//清除原图片
for (int i = 0; i < menuitem_img.Count; i++)
{
DestroyImmediate(menuitem_img[i].gameObject);
DestroyImmediate(menuitem_img_clone[i].gameObject);
}
menuitem_img.Clear();
menuitem_img_clone.Clear();
//赋值图片
for (int i = 0; i < conf.menuitem_num; i++)
{
GameObject go = Instantiate(menuitem_obj, Grid.transform);
go.name = (1 + i).ToString();
go.GetComponent().conf_child = conf.Bases[i];//赋值配置文件
go.GetComponent().overrideSprite = conf.menuitem_img[i];
go.GetComponent().enabled = true;
go.SetActive(true);
menuitem_img.Add(go.GetComponent());
}
////设置高度
//float hight_rt_Grid = rt_Grid.gameObject.GetComponent().cellSize.y * conf.menuitem_num + rt_Grid.gameObject.GetComponent().spacing.y * (conf.menuitem_num - 1);
//rt_Grid.sizeDelta = new Vector2(100, hight_rt_Grid);
if (true)
{
IsFirst = false;
Debug.Log(1);
conf_child = conf.Bases[1];//获取默认药材配置文件
if (FBX_obj.transform.childCount != 0)
{
Destroy(FBX_obj.transform.GetChild(0).gameObject);
}
Instantiate(conf_child.go, FBX_obj.transform).AddComponent();//实例化药材模型
FBX_obj.SetActive(false);
Image_show.gameObject.SetActive(true);
Image_show.overrideSprite = conf.Bases[1].go_img[0];
//Image_show.SetNativeSize();
GameObject CN = Image_show.transform.parent.Find("name_obj/CN").gameObject;
GameObject LT = Image_show.transform.parent.Find("name_obj/LT").gameObject;
CN.GetComponent().text = conf.Bases[1].name_CN;
LT.GetComponent().text = conf.Bases[1].name_LT;
CN.SetActive(true);
LT.SetActive(true);
show3D.gameObject.SetActive(true);
name_current.text = conf.Bases[1].name_CN;
}
}
for (int i = 0; i < menuitem_img.Count; i++)
{
GameObject go = Instantiate(menuitem_img[i].gameObject, Grid.transform);
go.GetComponent().conf_child = conf.Bases[i];//赋值配置文件
go.GetComponent().overrideSprite = conf.menuitem_img[i];
go.GetComponent().enabled = true;
go.SetActive(true);
menuitem_img_clone.Add(go);
}
Grid.GetComponent().Refresh();
}
///
/// 关闭一级菜单
///
public void Kind_cls()
{
IsShow_kind = !IsShow_kind;
StartCoroutine(Kind_but_cls());
}
#endregion
}