//using CCS.App;
using DG.Tweening;
using SC.XR.Unity;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Timers;
using TMPro;
using UnityEngine;
public class Scenes_YiLiao : MonoBehaviour
{
// Start is called before the first frame update
public string SeverString;
public GameObject bodyRol;
public GameObject muscle;
///
/// 初始效果出现隐藏变量
///
public MeshRenderer startRentiRenderer;
private float initStartRentiRendererFloat;
private float maxStartRentiRendererFloat;
private float minStartRentiRendererFloat;
private bool _isStartShow;
public GameObject[] topTextsList;
public GameObject[] topSlidesList;
private float initTopTxtsTxtColorA;
private float maxTopTxtsTxtColorA;
private float minTopTxtsTxtColorA;
private float inittopSlidesColorRGB;
private float maxtopSlidesColorRGB;
private float mintopSlidesColorRGB;
///
/// 头部变量
///
public MeshRenderer babyTopRenderer;
public SCSlider3D babyTopSlider;
//头部滑块变量
public MeshRenderer babyTopSaoMaoFXRenderer;
private Color initBabyTopSaoMaoFXRendererColor;
private Animator anim_babyTopSaoMaoFX;
private bool isbabyTopSaoMaoFXShowOrHeid;
private bool IsOneOpenBabyTopSaoMaoFXShowOrHeid;
///
/// 身体躯干变量
///
public MeshRenderer babyTrunkRenderer;
public SCSlider3D babyTrunkSlider;
//头部ct变量
public MeshRenderer ct1Renderer;
private float initBabyTrunRongjie;
private float MaxBabyTrunRongjie;
private float minBabyTrunRongjie;
private bool isUserDownBabyTrunkSlider;
public GameObject[] babyTrunkGamesUIList;
//private FunctionInfo _headFunction;
//private FunctionInfo _bodyFunction;
private float _waitTime = 3;
public bool IsStartShow
{
set
{
_isStartShow = value;
StartCoroutine(Ro3Show(_isStartShow));
if (value)
{
}
else
{
//// ShowOrHeidBbabyTrunkUI(-1, babyTrunkGamesUIList, "r1");
//babyTopSlider.value = _headFunction == null ? 0 : _headFunction.defaultValue / 1.0f;
//babyTrunkSlider.value = _bodyFunction == null ? 0 : _bodyFunction.defaultValue / 1.0f;
//scannerSlider.value=
babyTopRenderer.material.SetFloat("_Ani", 0);
}
}
}
#region 新的整体滑动条逻辑
///
/// 新的整体滑动条
///
public SCSlider3D scannerSlider;
public GameObject hintHandGo; //小手
public GameObject hintHandFX;//扫描特效
public float fixedpoint_startvalue;//固定的头和身体的中间值开始变量
public float fixedpoint_endvalue;//固定的头和身体的中间值结束变量
private float now_value; //当前value
private float top_value; //滑到头部时value
private float baby_value;//滑到身体时的value
public GameObject RayLiget;
///
/// 扫描仪拖动事件
///
public void ScannerSliderValueChaged()
{
now_value = scannerSlider.value;
if (now_value <= fixedpoint_startvalue)
{
isTop = true;
babyTrunkGamesUIList[0].SetActive(false);
babyTrunkRenderer.material.SetFloat("_rongjie", 1);
top_value = now_value / fixedpoint_startvalue;
babyTopRenderer.material.SetFloat("_Ani", top_value);
}
else if (now_value >= fixedpoint_endvalue)
{
isTop = false;
babyTrunkGamesUIList[0].SetActive(true);
baby_value = (now_value - fixedpoint_endvalue) / (1 - fixedpoint_endvalue);
if (baby_value >= 1)
{
baby_value = 1;
}
babyTrunkRenderer.material.SetFloat("_rongjie", 0);
babyTrunkRenderer.material.SetFloat("_Ani", baby_value);
if (baby_value <= 0.1f)
{
ShowOrHeidBbabyTrunkUI(0, babyTrunkGamesUIList, "r4");
}
else if (baby_value >= 0.1f && baby_value < 0.3f)
{
ShowOrHeidBbabyTrunkUI(1, babyTrunkGamesUIList, "r3");
}
else if (baby_value >= 0.3f && baby_value < 0.5f)
{
ShowOrHeidBbabyTrunkUI(2, babyTrunkGamesUIList, "r2");
}
else if (baby_value >= 0.5f && baby_value < 1f)
{
ShowOrHeidBbabyTrunkUI(3, babyTrunkGamesUIList, "r1");
}
}
hintHandFX.SetActive(true);
}
public bool isTop = true; //是否扫描的头部
///
/// 进入或者滑出滑动条进行的操作
///
///
public void Show_ScannerSliderFX(string str)
{
if (str == "Down")
{
RayLiget.SetActive(true);
if (isTop)
{
babyTopSaoMaoFXRenderer.gameObject.SetActive(true);
anim_babyTopSaoMaoFX.Play("startSaoMiao");
//SendTopFenctionInfo2S(top_value);
}
else
{
isUserDownBabyTrunkSlider = true;
//SendBabyFenctionInfo2S(baby_value);
}
muscle.SetActive(true);
}
if (str == "Up")
{
RayLiget.SetActive(false);
if (isTop)
{
anim_babyTopSaoMaoFX.Play("retrunSaoMiao");
//SendTopFenctionInfo2S(top_value);
}
else
{
isUserDownBabyTrunkSlider = false;
//SendBabyFenctionInfo2S(baby_value);
}
}
ShowOrHeidTextsColorA("ChangeTextMeshPro", topTextsList, initTopTxtsTxtColorA, true);
}
///
/// 焦点进入事件
///
public void PointEnterEvent()
{
Debug.Log("PointEnterEvent");
hintHandGo.SetActive(true);
// hintHandFX.SetActive(true);
}
///
/// 焦点移出事件
///
public void PointExitEvent()
{
Debug.Log("PointExitEvent");
hintHandFX.SetActive(false);
hintHandGo.SetActive(false);
}
///
/// 发送头当前数据给中控
///
/// 当前value
//private void SendTopFenctionInfo2S(float value)
//{
// _headFunction.functionValues[0].value = (int)(value * 100);
// //GameManager.Instance.SendFunctionInfo2S(_headFunction);
//}
///
/// 发送身体当前数据给中控
///
/// 当前value
//private void SendBabyFenctionInfo2S(float value)
//{
// _bodyFunction.functionValues[0].value = (int)(value * 100);
// //GameManager.Instance.SendFunctionInfo2S(_bodyFunction);
//}
/////
/// 获取头或者身体当前滑动条的值
///
/// 中控发送的值
/// 0 为头部, 1为身体
/// 换算后的滑动条值
private float ConvertsTheurrentSliderPosition(float value, int type)
{
if (type == 0)//扫描的头部
{
return (value * fixedpoint_startvalue);
}
else if (type == 1) //扫描的身体
{
return (value * (1 - fixedpoint_endvalue) + fixedpoint_endvalue);
}
return 0;
}
#endregion
private void Awake()
{
//GameManager.Instance.functionChangleAction += MedicalFunctionChangleHandler;
//_headFunction = AppManager.Instance.functionInfos.FirstOrDefault(f => f.moduleID == 2 && f.functionID == 3);
//_bodyFunction = AppManager.Instance.functionInfos.FirstOrDefault(f => f.moduleID == 2 && f.functionID == 4);
}
private void OnDestroy()
{
//GameManager.Instance.functionChangleAction -= MedicalFunctionChangleHandler;
}
/*
private void MedicalFunctionChangleHandler(int moduleID, int functionID, FunctionType functionType, List functionValues)
{
//当前是医疗
if (moduleID == 2 && functionID == 1 && functionType == FunctionType.Switch)
{
switch ((FunctionState)functionValues[0].value)
{
case FunctionState.None:
break;
case FunctionState.Open:
StartOrOpenRenTiObj(true);
break;
case FunctionState.Close:
StartOrOpenRenTiObj(false);
break;
case FunctionState.Wait:
break;
default:
break;
}
}
else if (moduleID == 2 && functionID == 3 && functionType == FunctionType.RangeValue)
{
babyTopSlider.value = functionValues[0].value / 100.0f;
//metoo
; scannerSlider.value = ConvertsTheurrentSliderPosition(functionValues[0].value / 100.0f,0);
}
else if (moduleID == 2 && functionID == 4 && functionType == FunctionType.RangeValue)
{
if (!muscle.activeSelf)
{
muscle.SetActive(true);
isUserDownBabyTrunkSlider = true;
}
babyTrunkSlider.value = functionValues[0].value / 100.0f;
//metoo
scannerSlider.value = ConvertsTheurrentSliderPosition(functionValues[0].value / 100.0f, 1);
ScannerSliderValueChaged();
BabyTrunkSliderValueChaged();
_waitTime = 0;
}
}
*/
void Start()
{
Init();
StartOrOpenRenTiObj(true);
StartCoroutine(DeleEffectsTrue());
}
IEnumerator DeleEffectsTrue()
{
yield return new WaitForSeconds(0.1f);
//GameManager.Instance.LoadingGameObj(false);
}
WaitForEndOfFrame wfs = new WaitForEndOfFrame();
IEnumerator Ro3Show(bool isShow)
{
startRentiRenderer.gameObject.SetActive(true);
if (isShow)
{
bodyRol.SetActive(true);
}
startRentiRenderer.material.SetFloat("_Float1", isShow ? maxStartRentiRendererFloat : minStartRentiRendererFloat);
bool isStart = true;
while (isStart)
{
yield return wfs;
if (isShow)
{
if (initStartRentiRendererFloat < minStartRentiRendererFloat)
{
isStart = false;
}
}
else
{
if (initStartRentiRendererFloat > maxStartRentiRendererFloat)
{
isStart = false;
bodyRol.SetActive(false);
}
}
}
startRentiRenderer.gameObject.SetActive(false);
}
private void Init()
{
InitStartBabyAll();
InitBabyTop();
InitBabyTrunk();
}
///
/// 整体效果初始化
///
private void InitStartBabyAll()
{
muscle.SetActive(false);
initStartRentiRendererFloat = 1.2f;
maxStartRentiRendererFloat = initStartRentiRendererFloat;
minStartRentiRendererFloat = 0;
startRentiRenderer.material.SetFloat("_Float1", initStartRentiRendererFloat);
IsStartShow = false;
initTopTxtsTxtColorA = 0;
maxTopTxtsTxtColorA = 1;
minTopTxtsTxtColorA = initTopTxtsTxtColorA;
inittopSlidesColorRGB = 0;
maxtopSlidesColorRGB = 1;
mintopSlidesColorRGB = inittopSlidesColorRGB;
}
///
/// 脑部初始
///
private void InitBabyTop()
{
babyTopRenderer.material.SetFloat("_Ani", 0);
ct1Renderer.material.SetFloat("_Ani", 0);
anim_babyTopSaoMaoFX = babyTopSaoMaoFXRenderer.gameObject.GetComponent();
initBabyTopSaoMaoFXRendererColor = new Color(0, 0, 0);
babyTopSaoMaoFXRenderer.material.SetColor("_yanse", initBabyTopSaoMaoFXRendererColor);
babyTopSaoMaoFXRenderer.material.SetColor("_node_2070", initBabyTopSaoMaoFXRendererColor);
babyTopSaoMaoFXRenderer.material.SetColor("_node_3228", initBabyTopSaoMaoFXRendererColor);
babyTopSaoMaoFXRenderer.gameObject.SetActive(false);
IsOneOpenBabyTopSaoMaoFXShowOrHeid = true;
}
private void InitBabyTrunk()
{
babyTrunkRenderer.material.SetFloat("_Ani", 0);
initBabyTrunRongjie = 1;
MaxBabyTrunRongjie = 1;
minBabyTrunRongjie = 0;
babyTrunkRenderer.material.SetFloat("_rongjie", 1);
isUserDownBabyTrunkSlider = false;
}
///
/// 滑动头部滑块
///
public void BabyTopSliderValueChaged()
{
babyTopRenderer.material.SetFloat("_Ani", babyTopSlider.value);
ct1Renderer.material.SetFloat("_Ani", babyTopSlider.value);
}
///
/// 滑动身体滑块
///
public void BabyTrunkSliderValueChaged()
{
babyTrunkRenderer.material.SetFloat("_Ani", babyTrunkSlider.value);
// Debug.Log(babyTrunkSlider.value + "=>babyTrunkSlider.value");
if (babyTrunkSlider.value <= 0.1f)
{
ShowOrHeidBbabyTrunkUI(0, babyTrunkGamesUIList, "r4");
}
else if (babyTrunkSlider.value >= 0.1f && babyTrunkSlider.value < 0.3f)
{
ShowOrHeidBbabyTrunkUI(1, babyTrunkGamesUIList, "r3");
}
else if (babyTrunkSlider.value >= 0.3f && babyTrunkSlider.value < 0.5f)
{
ShowOrHeidBbabyTrunkUI(2, babyTrunkGamesUIList, "r2");
}
else if (babyTrunkSlider.value >= 0.5f && babyTrunkSlider.value < 1f)
{
ShowOrHeidBbabyTrunkUI(3, babyTrunkGamesUIList, "r1");
}
}
// Update is called once per frame
void Update()
{
if (_waitTime <= 2)
{
_waitTime += Time.deltaTime;
if (_waitTime > 2)
{
isUserDownBabyTrunkSlider = false;
}
}
//根据bool 显示或关闭 整体模型
if (_isStartShow)
{
// Debug.Log("++++++++++++++++++++++++++++++++++");
if (initStartRentiRendererFloat >= minStartRentiRendererFloat)
{
initStartRentiRendererFloat -= Time.deltaTime * 0.3f;
startRentiRenderer.material.SetFloat("_Float1", initStartRentiRendererFloat);
}
//if (initTopTxtsTxtColorA <= maxTopTxtsTxtColorA)
//{
// Debug.Log("22222222222222222222222222");
// initTopTxtsTxtColorA += Time.deltaTime * 0.3f;
// ShowOrHeidTextsColorA("ChangeTextMeshPro", topTextsList, initTopTxtsTxtColorA, false);
//}
//if (inittopSlidesColorRGB <= maxtopSlidesColorRGB)
//{
// Debug.Log("111111111111111111111111111111111");
// inittopSlidesColorRGB += Time.deltaTime * 0.3f;
// ShowOrHeidTextsColorA("ChangeMeshRenderer", topSlidesList, inittopSlidesColorRGB, true);
//}
if (isUserDownBabyTrunkSlider)
{
if (initBabyTrunRongjie >= minBabyTrunRongjie)
{
initBabyTrunRongjie -= Time.deltaTime * 1f;
babyTrunkRenderer.material.SetFloat("_rongjie", initBabyTrunRongjie);
}
}
//else
//{
// if (initBabyTrunRongjie <= MaxBabyTrunRongjie)
// {
// Debug.Log("444444444444444444444444");
// initBabyTrunRongjie += Time.deltaTime * 0.04f;
// babyTrunkRenderer.material.SetFloat("_rongjie", initBabyTrunRongjie);
// }
// else
// {
// muscle.SetActive(false);
// }
//}
}
//else
//{
// // Debug.Log("-----------------------------------");
// if (initStartRentiRendererFloat <= maxStartRentiRendererFloat)
// {
// initStartRentiRendererFloat += Time.deltaTime * 0.3f;
// startRentiRenderer.material.SetFloat("_Float1", initStartRentiRendererFloat);
// }
// if (initTopTxtsTxtColorA >= minTopTxtsTxtColorA)
// {
// initTopTxtsTxtColorA -= Time.deltaTime * 0.3f;
// ShowOrHeidTextsColorA("ChangeTextMeshPro", topTextsList, initTopTxtsTxtColorA, false);
// }
// if (inittopSlidesColorRGB >= mintopSlidesColorRGB)
// {
// inittopSlidesColorRGB -= Time.deltaTime * 0.3f;
// ShowOrHeidTextsColorA("ChangeMeshRenderer", topSlidesList, inittopSlidesColorRGB, false);
// }
// if (initBabyTrunRongjie <= MaxBabyTrunRongjie)
// {
// initBabyTrunRongjie += Time.deltaTime * 0.3f;
// babyTrunkRenderer.material.SetFloat("_rongjie", initBabyTrunRongjie);
// }
//}
#if UNITY_EDITOR
if (Input.GetKey(KeyCode.J))
{
StartOrOpenRenTiObj(true);
}
else if (Input.GetKey(KeyCode.K))
{
StartOrOpenRenTiObj(false);
}
#endif
}
public void ShowOrHeidTextsColorA(string str, GameObject[] games, float colorA, bool isOpenBoxCollider)
{
if (str == "ChangeTextMeshPro")
{
if (isOpenBoxCollider)//这里用关闭 “手势捏住下方滑块滑动条”
{
games[1].GetComponent().color = new Color(1, 1, 1, 0);
}
else
{
for (int i = 0; i < games.Length; i++)
{
games[i].GetComponent().color = new Color(1, 1, 1, colorA);
}
}
}
else if (str == "ChangeMeshRenderer")
{
for (int i = 0; i < games.Length; i++)
{
games[i].GetComponent().enabled = isOpenBoxCollider;
games[i].GetComponent().material.color = new Color(colorA, colorA, colorA);
}
}
}
///
/// 开启或关闭人体
///
///
public void StartOrOpenRenTiObj(bool isOpen)
{
IsStartShow = isOpen;
}
///
/// 关闭或显示人体脑部特效
///
///
public void Show_BabyTopSaoMaoFX(string str)
{
if (str == "ShowBobyTopSaoMiaoFX")
{
babyTopSaoMaoFXRenderer.gameObject.SetActive(true);
anim_babyTopSaoMaoFX.Play("startSaoMiao");
}
else if (str == "HeidBobyTopSaoMiaoFX")
{
anim_babyTopSaoMaoFX.Play("retrunSaoMiao");
}
//_headFunction.functionValues[0].value = (int)(babyTopSlider.value * 100);
//GameManager.Instance.SendFunctionInfo2S(_headFunction);
ShowOrHeidTextsColorA("ChangeTextMeshPro", topTextsList, initTopTxtsTxtColorA, true);
}
///
/// 关闭或现实人体躯干特效
///
///
public void Show_BabyTrunkFX(string str)
{
if (str == "ShowBobyTrunkFX")
{
muscle.SetActive(true);
isUserDownBabyTrunkSlider = true;
}
else if (str == "HeidBobyTrunkFX")
{
isUserDownBabyTrunkSlider = false;
}
//_bodyFunction.functionValues[0].value = (int)(babyTrunkSlider.value * 100);
//GameManager.Instance.SendFunctionInfo2S(_bodyFunction);
// Debug.LogError(str + "=>str");
ShowOrHeidTextsColorA("ChangeTextMeshPro", topTextsList, initTopTxtsTxtColorA, true);
}
// int lastgamesNum=-1;
private void ShowOrHeidBbabyTrunkUI(int index, GameObject[] games, string animName)
{
if (index == -1)
{
return;
}
// Debug.Log(index + "=>index");
for (int i = 0; i < games.Length; i++)
{
if (i != index)
{
// games[i].SetActive(true);
// Debug.Log(i + "=>+++++back");
games[i].gameObject.GetComponent().SetBool("Open", true);
games[i].gameObject.transform.localPosition = new Vector3(999f, 999f, 999f);
}
else
{
switch (index)
{
case 0:
games[i].GetComponent().SetBool("Open", false);
games[0].gameObject.transform.localPosition = new Vector3(-0.0353f, 0.131f, 0.0618f);
break;
case 1:
games[i].GetComponent().SetBool("Open", false);
// games[1].gameObject.GetComponent().Play(animName);
games[1].gameObject.transform.localPosition = new Vector3(-0.0077f, 0.1765f, 0.06325f);
break;
case 2:
games[i].GetComponent().SetBool("Open", false);
// games[2].gameObject.GetComponent().Play(animName);
games[2].gameObject.transform.localPosition = new Vector3(-0.0124f, 0.2897f, 0.0449f);
break;
case 3:
games[i].GetComponent().SetBool("Open", false);
// games[3].gameObject.GetComponent().Play(animName);
games[3].gameObject.transform.localPosition = new Vector3(-0.0206f, 0.3177f, 0.063f);
break;
}
}
}
}
private IEnumerator waitOfAnimEndHeidGameObj(float timer, GameObject obj, bool isB)
{
yield return new WaitForSeconds(timer);
obj.SetActive(isB);
}
private IEnumerator waitOfInit(float timer)
{
yield return new WaitForSeconds(timer);
Init();
}
}