using BeinLab.Util;
using DG.Tweening;
using SC.XR.Unity.Module_InputSystem;
using SC.XR.Unity.Module_InputSystem.InputDeviceHead;
using SC.XR.Unity.Module_InputSystem.InputDeviceHand;
using ShadowStudio.Tool;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using XRTool.Util;
using XRTool.WorldUI;
using ShadowStudio.Model;
using SC.XR.Unity.Module_InputSystem.InputDeviceGC.BT3Dof;
using SC.XR.Unity.Module_InputSystem.InputDeviceGC.KS;
using Studio.Scripts;
namespace ShadowStudio.UI
{
enum FilePanelType
{
ZiYuanKuDlg=0,
PersonalDlg=1
}
[RequireComponent(typeof(WorldDlg))]
///
/// 控制台窗口
///
public class ConsoleDlg : UnitySingleton
{
private Transform AllMenuToggles;
public List IconDlgList;
public static int PaintBrushDlg = 0;
public static int PiZhuDlg = 1;
public static int ZiYuanKuDlg = 2;
public static int PersonalFiledlg = 3;
public static int FileListDlg = 4;
private Transform IconDlgToggleGroupTran;
private ToggleGroup IconDlgToggleGroup;
public Toggle PiZhuToggle;
private Button shortcutkey;
public Transform AnmationPos;
private Button userInfoBt;
//private Button WenJianBt;
private WorldDlg fileListDlg;
public Camera vufora_camera;
public Transform NotePadPar;
public Transform WorldCanvas;
public GameObject TipPop;
public Text TipPopText;
public static bool IsOne = false;
public Vector3 GetCenterPos()
{
if (shortcutkey)
{
return shortcutkey.transform.position;
}
return Vector3.zero;
}
private void Start()
{
ArtInfoMgr.Instance.InitPackage(HomeProxy.Instance.ArtList);
WorldDlg dlg = GetComponent();
AnmationPos = dlg.GetBreadthChild("AnmationPos");
fileListDlg = dlg.GetBreadthChild("FileListDlg");
fileListDlg.gameObject.SetActive(false);
AllMenuToggles = dlg.GetBreadthChild("AllMenuToggles");
IconDlgToggleGroup = dlg.GetBreadthChild("IconDlgToggleGroup");
IconDlgToggleGroupTran = dlg.GetBreadthChild("IconDlgToggleGroup");
userInfoBt = dlg.GetBreadthChild("userInfoBt");
shortcutkey = dlg.GetBreadthChild("Shortcutkey");
// scanPictureBtn = dlg.GetBreadthChild("ScanPictureBtn");
shortcutkey.onClick.AddListener(ClickOnShortcutkey);
//scanPictureBtn.onClick.AddListener(ClickOnScan);
for (int i = 0; i < IconDlgToggleGroupTran.childCount; i++)
{
Toggle toggle = IconDlgToggleGroupTran.GetChild(i).GetComponent();
toggle.onValueChanged.AddListener((bool isOn) => { OnToggle(isOn, toggle); });
if (i == 1)
{
PiZhuToggle = toggle;
}
}
if (GameSession.Instance)
{
GameSession.Instance.CameraEffect(true);
}
shortcutkey.gameObject.SetActive(false);
InitScan();
//Debug.Log(CommonMethod.roomConfig.Type + "***" + CommonMethod.roomConfig.Room_type + "+++" + CommonMethod.roomConfig.Is_created);
if (CommonMethod.roomConfig.Type == "2")
{
if (CommonMethod.roomConfig.Room_type == "2")
{
Invoke("shortcutkeyShow", 1f);
}
else
{
if (CommonMethod.roomConfig.Is_created == "1")
{
Invoke("shortcutkeyShow", 1f);
}
}
}
else
{
Invoke("shortcutkeyShow", 1f);
}
//TimerMgr.Instance.CreateTimer(() =>
//{
// if (TransferCell.curActiveCell && !TransferCell.curActiveCell.IsLock)
// {
// TransferCell.curActiveCell.DisActiveCell();
// }
//}, 1.2f);
}
private void InitScan()
{
vufora_camera.enabled = false;
Vuforia.VuforiaBehaviour.Instance.enabled = false;
}
public void ClickOnScan()
{
if (vufora_camera.enabled == true)
{
CommonMethod.ShowScanEffect(false);
vufora_camera.enabled = false;
Vuforia.VuforiaBehaviour.Instance.enabled = false;
//if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
//{
// // StudioRtc.Instance.startCamera();
//}
if (ScanPictureBtn.Instance.Bg)
{
ScanPictureBtn.Instance.Bg.gameObject.SetActive(false);
}
//AgoraVideoAudioManager.Instance.OnClickEnableLocalVideo(true);
//if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
//{
// StudioRtc.Instance.stopCamera();
//}
AgoraRTCManager.Instance.JoinChannel();
}
else
{
if(AgoraRTCManager.Instance.isSwitchCamera)
{
AgoraRTCManager.Instance.RtcEngine.SwitchCamera();
AgoraRTCManager.Instance.isSwitchCamera = !AgoraRTCManager.Instance.isSwitchCamera;
}
AgoraRTCManager.Instance.LeaveChannel();
// AgoraVideoAudioManager.Instance.OnClickEnableLocalVideo(false);
//if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
//{
// StudioRtc.Instance.stopCamera();
//}
CommonMethod.ShowScanEffect(true);
vufora_camera.enabled = true;
Vuforia.VuforiaBehaviour.Instance.enabled = true;
if (ScanPictureBtn.Instance.Bg)
{
ScanPictureBtn.Instance.Bg.gameObject.SetActive(true);
}
}
}
public void CloseScan()
{
//if (vufora_camera.enabled == true)
//{
// CommonMethod.ShowScanEffect(false);
// vufora_camera.enabled = false;
// Vuforia.VuforiaBehaviour.Instance.enabled = false;
// //if (StudioRtc.Instance != null && StudioRtc.Instance.me != null)
// //{
// // StudioRtc.Instance.startCamera();
// //}
//}
}
private void shortcutkeyShow()
{
shortcutkey.gameObject.SetActive(true);
}
private void ClickOnShortcutkey()
{
if (isHide)
{
shortcutkey.GetComponent().enabled = false;
isHide = false;
GameEffect.setAlpha(shortcutkey.gameObject, 0, 0.25f, (GameObject obj) =>
{
shortcutkey.gameObject.SetActive(false);
});
GameEffect.setAlpha(AllMenuToggles.gameObject, 1, 0.01f, (GameObject obj) =>
{
});
AllMenuToggles.gameObject.SetActive(true);
ListButtonEffect[] list = AllMenuToggles.GetComponentsInChildren();
for (int i = 0; i < list.Length; i++)
{
list[i].showMove();
}
if (GameSession.Instance)
{
GameSession.Instance.CameraEffect(false);
}
}
}
private void OnToggle(bool isOn, Toggle toggle)
{
if (isOn)
{
switch (toggle.name)
{
case "PaintBrush":
ShowIconDlgs(PaintBrushDlg);
DrawPener.Instance.ActiveDrawPen();
DesAllNotepad();
break;
case "NotePad":
ShowIconDlgs(PiZhuDlg);
DrawPener.Instance.DisActiveDrawPen();
ArtContainer container = NotePadComponent.CreateLocalNotePad();
TimerMgr.Instance.CreateTimer(() => { InitNotePad(container); }, 0f);
break;
case "ZiYuanKu":
ShowIconDlgs(ZiYuanKuDlg);
DrawPener.Instance.DisActiveDrawPen();
DesAllNotepad();
break;
case "PersonalFile":
ShowIconDlgs(PersonalFiledlg);
DrawPener.Instance.DisActiveDrawPen();
DesAllNotepad();
break;
case "SenceMgr":
ShowIconDlgs(FileListDlg);
DrawPener.Instance.DisActiveDrawPen();
DesAllNotepad();
break;
}
}
else
{
if (!IconDlgToggleGroup.AnyTogglesOn())
{
CloseAllDlgs();
DesAllNotepad();
DrawPener.Instance.DisActiveDrawPen();
}
}
}
public void SetClose()
{
IconDlgToggleGroup.SetAllTogglesOff();
}
private void DesAllNotepad()
{
if (NotePadPar && NotePadPar.childCount > 0)
{
for (int i = 0; i < NotePadPar.childCount; i++)
{
Destroy(NotePadPar.GetChild(i).gameObject);
}
}
}
private void InitNotePad(ArtContainer container)
{
Transform NotePadTran = container.GetInstace().transform;
NotePadTran.SetParent(NotePadPar, true);
NotePadTran.localPosition = new Vector3(0f, 0f, 0f);
NotePadTran.localEulerAngles = new Vector3(0f, 0f, 0f);
NotePadTran.localScale = new Vector3(1250f, 1250f, 1250f);
//NotePadTran.position = NotePadPar.position;
//NotePadTran.rotation = NotePadPar.rotation;
NotePadComponent notePadComponent = NotePadTran.GetComponentInChildren();
notePadComponent.Init();
}
private void Update()
{
checkMenu();
}
private bool isHide = true;
private float TimeData;
private List raycastList;
public void checkMenu()
{
if (!IconDlgToggleGroup.AnyTogglesOn() && !isHide)
{
List list = checkFoucs();
bool isLock = false;
for (int i = 0; i < list.Count; i++)
{
if (list[i] != null)
{
isLock = true;
break;
}
}
if (!isLock)
{
TimeData = TimeData + Time.deltaTime;
if (TimeData >= 2f)
{
TimeData = 0;
HeidMenu();
}
}
else
{
TimeData = 0;
}
}
else
{
TimeData = 0;
}
}
private void OnEnable()
{
DispatcherBase.KeyDownDelegateRegister(OnKeyDownAction);
}
private void OnKeyDownAction(InputKeyCode keyCode, InputDevicePartBase part)
{
var obj = part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject;//SDK里判断点击返回的物体
if (!obj && !IconDlgToggleGroup.AnyTogglesOn() && !isHide)
{
HeidMenu();
}
if (!obj)
{
TransferCell.CancelCell();
}
}
private void OnDisable()
{
TransferCell.CancelCell();
DispatcherBase.KeyDownDelegateUnRegister(OnKeyDownAction);
}
public List checkFoucs()
{
if (raycastList == null)
{
raycastList = new List();
}
raycastList.Clear();
InputDeviceBase inputdevice;
inputdevice = Module_InputSystem.instance.GetInputDevice(InputDeviceType.Head);
checkFoucs(raycastList, inputdevice);
inputdevice = Module_InputSystem.instance.GetInputDevice(InputDeviceType.GGT26Dof);
checkFoucs(raycastList, inputdevice);
inputdevice = Module_InputSystem.instance.GetInputDevice(InputDeviceType.GGT26Dof);
checkFoucs(raycastList, inputdevice);
inputdevice = Module_InputSystem.instance.GetInputDevice(InputDeviceType.BT3Dof);
checkFoucs(raycastList, inputdevice);
inputdevice = Module_InputSystem.instance.GetInputDevice(InputDeviceType.KS);
checkFoucs(raycastList, inputdevice);
return raycastList;
}
private void checkFoucs(List raycastList, InputDeviceBase inputdevice)
{
if (inputdevice && inputdevice.inputDevicePartList != null)
{
foreach (var part in inputdevice.inputDevicePartList)
{
if (part && part.inputDataBase != null && part.inputDataBase.isVaild)
{
raycastList.Add(part.inputDataBase.SCPointEventData.pointerCurrentRaycast.gameObject);
}
}
}
}
public void HeidMenu()
{
shortcutkey.GetComponent().enabled = true;
isHide = true;
GameEffect.setAlpha(AllMenuToggles.gameObject, 0, 0.25F, (GameObject obj) => { obj.SetActive(false); });
GameEffect.setAlpha(shortcutkey.gameObject, 1, 0.25F, (GameObject obj) => { obj.SetActive(true); });
ListEffect[] listeffects = AllMenuToggles.GetComponentsInChildren();
for (int i = 0; i < listeffects.Length; i++)
{
listeffects[i].hideEffect();
}
ListButtonEffect[] list = AllMenuToggles.GetComponentsInChildren();
for (int i = 0; i < list.Length; i++)
{
list[i].hideMove();
}
//aboutMeDlg.hideDlg();
//fileListDlg.hideDlg();
if (GameSession.Instance)
{
GameSession.Instance.CameraEffect(true);
}
}
public void CloseAllDlgs()
{
for (int i = 0; i < IconDlgList.Count; i++)
{
if (IconDlgList[i].activeSelf)
{
IconDlgList[i].SetActive(false);
//GameEffect.setAlpha(IconDlgList[i].gameObject, 0, 0.25f, (GameObject obj) =>
//{
// obj.SetActive(false);
//});
}
}
}
public void xiao()
{
// OpenXRCamera.Instance.leftCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent().transform.localPosition.x - 0.001f, OpenXRCamera.Instance.head.GetComponent().transform.localPosition.y, OpenXRCamera.Instance.leftCamera.transform.localPosition.z);
// OpenXRCamera.Instance.rightCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent().transform.localPosition.x + 0.001f, OpenXRCamera.Instance.head.GetComponent().transform.localPosition.y, OpenXRCamera.Instance.rightCamera.transform.localPosition.z);
}
public void da()
{
// OpenXRCamera.Instance.leftCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent().transform.localPosition.x + 0.001f, OpenXRCamera.Instance.head.GetComponent().transform.localPosition.y, OpenXRCamera.Instance.leftCamera.transform.localPosition.z);
// OpenXRCamera.Instance.rightCamera.transform.localPosition = new Vector3(OpenXRCamera.Instance.head.GetComponent().transform.localPosition.x - 0.001f, OpenXRCamera.Instance.head.GetComponent().transform.localPosition.y, OpenXRCamera.Instance.rightCamera.transform.localPosition.z);
}
public void ShowIconDlgs(int index)
{
for (int i = 0; i < IconDlgList.Count; i++)
{
if (index == i)
{
IconDlgList[i].SetActive(true);
}
else
{
if (IconDlgList[i].activeSelf)
{
IconDlgList[i].gameObject.SetActive(false);
}
}
}
}
public void ShowTipPop(string msg)
{
TipPop.SetActive(true);
TipPopText.text = msg;
Invoke("HideTipPop", 3f);
}
private void HideTipPop()
{
TipPop.SetActive(false);
}
}
}