319 lines
10 KiB
C#
319 lines
10 KiB
C#
/// <summary>
|
||
///********************************************************
|
||
/// 作者: DDG
|
||
/// 日期: 2024/10/21 09:16:34
|
||
/// 功能: Main场景UI
|
||
///********************************************************
|
||
/// <summary>
|
||
|
||
using System;
|
||
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using ZXKFramework;
|
||
using RenderHeads.Media.AVProMovieCapture;
|
||
|
||
public class MainWnd : UIBase
|
||
{
|
||
GameModel gameModel;
|
||
|
||
/// <summary>
|
||
/// 模型是否炸开
|
||
/// </summary>
|
||
bool isBomb;
|
||
|
||
/// <summary>
|
||
/// 控制模型炸开与合并按钮
|
||
/// </summary>
|
||
Button boomIO_Btn;
|
||
Button lzIO_Btn;
|
||
bool isLu;
|
||
CaptureFromScreen cap;
|
||
|
||
/// <summary>
|
||
/// 返回首页按钮
|
||
/// </summary>
|
||
Button home_Btn;
|
||
|
||
/// <summary>
|
||
/// 退出客户端按钮
|
||
/// </summary>
|
||
Button exit_Btn;
|
||
|
||
Button tip_But;
|
||
|
||
Text ShowJieGouText;
|
||
Image ShowJieGouPic;
|
||
private Dictionary<string, ShowJieGou> jiegouList = new();
|
||
|
||
GameManager gameManager;
|
||
|
||
/// <summary>
|
||
/// 控制透明滑动条
|
||
/// </summary>
|
||
Slider touMingSlider;
|
||
|
||
List<BTInPos> zhuTi = new List<BTInPos>();
|
||
|
||
/// <summary>
|
||
/// 需要透视的材质球
|
||
/// </summary>
|
||
//Material touShiMat;
|
||
public override string GroupName => "MainWnd";
|
||
|
||
public override string Name => "MainWnd";
|
||
|
||
private void Start()
|
||
{
|
||
isLu = false;
|
||
gameManager = GameManager.Instance;
|
||
}
|
||
|
||
void ChangeCamera() {
|
||
Camera a = GameObject.Find("Camera").GetComponent<Camera>();
|
||
GetComponentInParent<Canvas>().worldCamera = a;
|
||
cap = GameObject.Find("LuShiPin").GetComponent<CaptureFromScreen>();
|
||
}
|
||
|
||
public override void Init(IUIManager uictrl)
|
||
{
|
||
base.Init(uictrl);
|
||
|
||
Invoke("ChangeCamera", 0.2f);
|
||
|
||
gameModel = MVC.GetModel<GameModel>();
|
||
isBomb = false;
|
||
//touShiMat = GameManager.Instance.transform.FindFirst<Renderer>("石材").material;
|
||
|
||
touMingSlider = transform.FindFirst<Slider>("touMingSlider");
|
||
|
||
touMingSlider.onValueChanged.AddListener((c) =>
|
||
{
|
||
|
||
foreach (GameObject it in GameManager.Instance.allAlphaGame)
|
||
{
|
||
Renderer renderer = it.GetComponent<Renderer>();
|
||
for (int i = 0; i < renderer.materials.Length; i++)
|
||
{
|
||
Material touShiMat = renderer.materials[i];
|
||
Color col = touShiMat.GetColor("_BaseColor");
|
||
col.a = c;
|
||
touShiMat.SetColor("_BaseColor", col);
|
||
//渲染模式
|
||
//BlendMode.Cutout:打开_ALPHATEST_ON,其他两个关闭。BlendMode.Fade:打开_ALPHABLEND_ON,其他两个关闭。BlendMode.Transparent:打开_ALPHAPREMULTIPLY_ON,其他两个关闭。//
|
||
if (c == 1) {
|
||
if (touShiMat.GetFloat("_Surface") != 1.0f) continue;
|
||
touShiMat.SetFloat("_Surface", 0.0f);
|
||
touShiMat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||
touShiMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.Zero);
|
||
touShiMat.SetInt("_ZWrite", 1);
|
||
touShiMat.DisableKeyword("_ALPHATEST_ON");
|
||
touShiMat.DisableKeyword("_ALPHABLEND_ON");
|
||
touShiMat.DisableKeyword("_ALPHAPREMULTIPLY_ON");
|
||
touShiMat.renderQueue = -1;
|
||
}
|
||
else
|
||
{
|
||
if (touShiMat.GetFloat("_Surface") != 0.0f) continue;
|
||
touShiMat.SetFloat("_Surface", 1.0f);
|
||
touShiMat.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.One);
|
||
touShiMat.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
|
||
touShiMat.SetInt("_ZWrite", 0);
|
||
touShiMat.DisableKeyword("_ALPHATEST_ON");
|
||
touShiMat.DisableKeyword("_ALPHABLEND_ON");
|
||
touShiMat.EnableKeyword("_ALPHAPREMULTIPLY_ON");
|
||
touShiMat.renderQueue = 3000;
|
||
}
|
||
|
||
}
|
||
}
|
||
});
|
||
|
||
boomIO_Btn = transform.FindFirst<Button>("boomIO_Btn");
|
||
lzIO_Btn = transform.FindFirst<Button>("lzIO_Btn");
|
||
tip_But = transform.FindFirst<Button>("Tip_Btn");
|
||
|
||
tip_But.onClick.AddListener(() =>
|
||
{
|
||
if (!isBomb) return;
|
||
OrderDragData data = gameModel.excelData.GetOrderDragDataorderID(OrderDragManager.Instance.GetorderID());
|
||
if (data == null) return;
|
||
GameManager.Instance.outLineManager.OpenHightLightAndCloseOther(data.dragGameName);
|
||
});
|
||
|
||
lzIO_Btn.onClick.AddListener(() =>
|
||
{
|
||
if (!isLu)
|
||
{
|
||
cap.StartCapture();
|
||
lzIO_Btn.GetComponent<Image>().sprite = Resources.Load<Sprite>("UI/True");
|
||
lzIO_Btn.gameObject.FindFirst<Text>("Label").text = new String("录制中");
|
||
}
|
||
else
|
||
{
|
||
cap.StopCapture();
|
||
lzIO_Btn.GetComponent<Image>().sprite = Resources.Load<Sprite>("UI/False");
|
||
lzIO_Btn.gameObject.FindFirst<Text>("Label").text = new String("录制");
|
||
}
|
||
isLu = !isLu;
|
||
});
|
||
|
||
boomIO_Btn.onClick.AddListener(() =>
|
||
{
|
||
if (gameManager == null)
|
||
{
|
||
gameManager = GameManager.Instance;
|
||
}
|
||
///如果当前为未炸开状态
|
||
if (!isBomb)
|
||
{
|
||
uiManager.ShowUI<LeftVer>();
|
||
|
||
boomIO_Btn.GetComponent<Image>().sprite = Resources.Load<Sprite>("UI/True");
|
||
boomIO_Btn.gameObject.FindFirst<Text>("Label").text = new String("一键合并");
|
||
|
||
//当前模型炸开
|
||
gameManager.bomb.Move();
|
||
for (int i = 0; i < gameManager.allMouseMove.Count; i++)
|
||
{
|
||
gameManager.allMouseMove[i].enabled = true;
|
||
gameManager.allMouseMove[i].GetComponent<Collider>().enabled = true;
|
||
}
|
||
for (int i = 0; i < gameManager.allOutLine.Count; i++)
|
||
{
|
||
gameManager.allOutLine[i].enabled = true;
|
||
}
|
||
|
||
foreach (BTInPos it in zhuTi)
|
||
{
|
||
it.pos.transform.parent.gameObject.SetActive(false);
|
||
it.gameObject.SetActive(false);
|
||
}
|
||
|
||
OrderDragManager.Instance.InitDragOrder();
|
||
MVC.GetView<LeftVer>().changeState(1);
|
||
}
|
||
else//如果当前为炸开状态
|
||
{
|
||
uiManager.CloseUI<LeftVer>();
|
||
|
||
boomIO_Btn.GetComponent<Image>().sprite = Resources.Load<Sprite>("UI/False");
|
||
boomIO_Btn.gameObject.FindFirst<Text>("Label").text = new String("一键拆解");
|
||
|
||
//当前模型合并
|
||
gameManager.bomb.Back();
|
||
for (int i = 0; i < gameManager.allMouseMove.Count; i++)
|
||
{
|
||
gameManager.allMouseMove[i].enabled = false;
|
||
gameManager.allMouseMove[i].GetComponent<Collider>().enabled = false;
|
||
}
|
||
for (int i = 0; i < gameManager.allOutLine.Count; i++)
|
||
{
|
||
gameManager.allOutLine[i].enabled = true;
|
||
}
|
||
|
||
foreach (BTInPos it in zhuTi)
|
||
{
|
||
it.pos.transform.parent.gameObject.SetActive(true);
|
||
it.gameObject.SetActive(true);
|
||
}
|
||
|
||
//OrderDragManager.Instance.InitDragOrder();
|
||
}
|
||
isBomb = !isBomb;
|
||
});
|
||
|
||
home_Btn = transform.FindFirst<Button>("home_Btn");
|
||
home_Btn.onClick.AddListener(() =>
|
||
{
|
||
Game.Instance.sceneManager.LoadLevel("Start", (yes, num) =>
|
||
{
|
||
if (yes)
|
||
{
|
||
uiManager.CloseUI<MainWnd>();
|
||
uiManager.ShowUI<StartWnd>();
|
||
}
|
||
});
|
||
});
|
||
|
||
exit_Btn = transform.FindFirst<Button>("exit_Btn");
|
||
exit_Btn.onClick.AddListener(() =>
|
||
{
|
||
Application.Quit();
|
||
});
|
||
|
||
ShowJieGouText = transform.FindFirst<Text>("jieGou_Txt");
|
||
ShowJieGouPic = transform.FindFirst<Image>("jieGouPic");
|
||
|
||
foreach (var item in gameModel.excelData.allShowJieGou)
|
||
{
|
||
if (!jiegouList.ContainsKey(item.Name))
|
||
{
|
||
jiegouList.Add(item.Name, item);
|
||
}
|
||
}
|
||
}
|
||
|
||
Coroutine cor;
|
||
|
||
public override void Show()
|
||
{
|
||
base.Show();
|
||
|
||
Game.Instance.objectPool.Unspawn("jiegouBT");
|
||
cor = Game.Instance.IEnumeratorManager.Run(.05f, () =>
|
||
{
|
||
foreach (var item in jiegouList)
|
||
{
|
||
if (item.Value.Show == "") continue;
|
||
Game.Instance.objectPool.Spawn("jiegouBT", transform, m =>
|
||
{
|
||
m.transform.localScale = Vector3.one;
|
||
m.FindFirst<Text>("Text").text = item.Key;
|
||
Button loBtn = m.GetComponent<Button>();
|
||
loBtn.onClick.RemoveAllListeners();
|
||
loBtn.onClick.AddListener(delegate
|
||
{
|
||
ShowJieGouText.text = item.Value.Show;
|
||
string name = string.Format("UI/{0}", item.Value.Name);
|
||
ShowJieGouPic.sprite = Resources.Load<Sprite>(name);
|
||
Color col = new Color(ShowJieGouPic.color.r, ShowJieGouPic.color.g, ShowJieGouPic.color.b, 1);
|
||
ShowJieGouPic.color = col;
|
||
});
|
||
BTInPos bt = m.GetComponent<BTInPos>();
|
||
|
||
zhuTi.Add(bt);
|
||
|
||
bt.cam = Camera.main;
|
||
bt.pos = GameManager.Instance.transform.FindFirst(item.Value.Name).FindFirst("btpos");
|
||
});
|
||
}
|
||
});
|
||
}
|
||
|
||
IEnumerator YanShi(float time, Action callBack)
|
||
{
|
||
yield return new WaitForSeconds(time);
|
||
callBack?.Invoke();
|
||
}
|
||
|
||
public void ChangeIsBomb(bool isBom)
|
||
{
|
||
isBomb = isBom;
|
||
}
|
||
|
||
public override void Hide()
|
||
{
|
||
base.Hide();
|
||
if (ShowJieGouPic == null) return;
|
||
Color col = new Color(ShowJieGouPic.color.r, ShowJieGouPic.color.g, ShowJieGouPic.color.b, 0);
|
||
ShowJieGouPic.color = col;
|
||
}
|
||
|
||
private void OnDisable()
|
||
{
|
||
Game.Instance.IEnumeratorManager.Stop(cor);
|
||
}
|
||
}
|