Files
ChunilENG/Assets/WorkSpace/Personal/JYM/Panel_ToolBar.cs

212 lines
6.7 KiB
C#
Raw Normal View History

2025-03-10 16:42:23 +09:00
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using WI;
using RenderHeads.Media.AVProMovieCapture;
using System.IO;
using SFB;
2025-03-26 20:10:27 +09:00
using CHN;
2025-04-09 14:41:40 +09:00
using System.Linq;
2025-03-10 16:42:23 +09:00
public class Panel_ToolBar : PanelBase
{
2025-04-09 14:41:40 +09:00
private Dictionary<ViewMode, Button> viewButtons = new Dictionary<ViewMode, Button>();
2025-03-18 13:57:27 +09:00
public Button Button_TopView;
public Button Button_QuarterView;
public Button Button_SholuderView;
private Button Button_DashBoard;
private Button Button_CustomView;
private Button Button_Minimap;
private Button Button_Record;
private Button Button_Capture;
2025-03-18 13:57:27 +09:00
private Button Button_FloorControl;
2025-03-10 16:42:23 +09:00
2025-03-28 09:50:00 +09:00
private Image Image_DashboardActive;
private Image Image_Record_Play;
private Image Image_MiniMapActive;
private Image Image_FloorControlActive;
2025-04-09 14:41:40 +09:00
private Button currentViewButton;
2025-03-10 16:42:23 +09:00
private CaptureBase capture;
public Action<ViewMode> onClickCameraView;
public Action<bool> onClickDashBoard;
2025-03-18 13:57:27 +09:00
2025-03-26 20:10:27 +09:00
public Action<int> onClickCustomView;
2025-03-18 13:57:27 +09:00
public Action onClickMiniMap;
public Action onClickFloorControl;
2025-04-22 15:29:46 +09:00
public Action<Vector3, string, bool> onAlarm;
2025-03-14 09:21:26 +09:00
2025-03-10 16:42:23 +09:00
public override void AfterAwake()
{
Button_TopView.onClick.AddListener(OnClickTopView);
Button_QuarterView.onClick.AddListener(OnClickQuaterView);
Button_SholuderView.onClick.AddListener(OnClickShoulderView);
Button_DashBoard.onClick.AddListener(OnClickDashBoard);
Button_CustomView.onClick.AddListener(OnClickCustomView);
Button_Minimap.onClick.AddListener(OnClickMinimap);
Button_Record.onClick.AddListener(OnClickRecord);
Button_Capture.onClick.AddListener(OnClickCapture);
2025-03-18 13:57:27 +09:00
Button_FloorControl.onClick.AddListener(OnClickFloorControl);
2025-03-10 16:42:23 +09:00
2025-04-09 14:41:40 +09:00
viewButtons.Add(ViewMode.TopView, Button_TopView);
viewButtons.Add(ViewMode.PerspectiveView, Button_QuarterView);
viewButtons.Add(ViewMode.FirstPersonView, Button_SholuderView);
2025-03-10 16:42:23 +09:00
RecordSetting();
CaptureSetting();
}
private void RecordSetting()
{
var filePath = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));
2025-03-10 16:42:23 +09:00
capture = GameObject.FindFirstObjectByType<CaptureBase>();
2025-03-10 16:42:23 +09:00
capture.CameraRenderResolution = CaptureBase.Resolution.Custom;
capture.CompletedFileWritingAction += OnCompleted;
}
private void CaptureSetting()
{
var filePath = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
2025-03-10 16:42:23 +09:00
}
private void OnCompleted(FileWritingHandler handler)
{
var sourcePath = handler.FinalPath;
var destFilePath = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", "mp4");
if (!string.IsNullOrEmpty(destFilePath))
2025-03-10 16:42:23 +09:00
{
File.Delete(destFilePath);
File.Move(sourcePath, destFilePath);
2025-03-10 16:42:23 +09:00
}
else
{
File.Delete(sourcePath);
2025-03-10 16:42:23 +09:00
}
}
2025-03-18 13:57:27 +09:00
private void OnClickFloorControl()
2025-03-10 16:42:23 +09:00
{
2025-03-28 09:50:00 +09:00
var isActive = Image_FloorControlActive.gameObject.activeSelf ? false : true;
Image_FloorControlActive.gameObject.SetActive(isActive);
2025-03-18 13:57:27 +09:00
onClickFloorControl?.Invoke();
2025-03-10 16:42:23 +09:00
}
private void OnClickCapture()
{
var destFilePath = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", "png");
if (!string.IsNullOrEmpty(destFilePath))
2025-03-10 16:42:23 +09:00
{
ScreenCapture.CaptureScreenshot(destFilePath);
2025-03-10 16:42:23 +09:00
}
}
private bool isRecordClick = false;
private void OnClickRecord()
{
isRecordClick = !isRecordClick;
if (isRecordClick)
{
StartCoroutine(PlayRecord());
capture.CameraRenderCustomResolution = new Vector2(UnityEngine.Screen.width, UnityEngine.Screen.height);
capture.StartCapture();
}
else
{
StopAllCoroutines();
capture.StopCapture();
Image_Record_Play.gameObject.SetActive(false);
2025-03-10 16:42:23 +09:00
}
}
IEnumerator PlayRecord()
{
this.Image_Record_Play.gameObject.SetActive(false);
//Button_Record.image.color = isRecordClick ? ColorUtil.FromHex("#32A3FF") : ColorUtil.FromHex("FFFFFF");
while (isRecordClick)
{
this.Image_Record_Play.gameObject.SetActive(true);
yield return new WaitForSeconds(0.5f);
this.Image_Record_Play.gameObject.SetActive(false);
yield return new WaitForSeconds(0.5f);
}
}
private void OnClickMinimap()
{
2025-03-28 09:50:00 +09:00
var isActive = Image_MiniMapActive.gameObject.activeSelf ? false : true;
Image_MiniMapActive.gameObject.SetActive(isActive);
2025-03-13 09:41:50 +09:00
onClickMiniMap?.Invoke();
2025-03-10 16:42:23 +09:00
}
private void OnClickCustomView()
{
2025-03-26 20:10:27 +09:00
var floorIndex = FindSingle<Building>().currentFloor.floorIndex;
onClickCustomView?.Invoke(floorIndex);
2025-04-22 15:29:46 +09:00
SetToolBarAlarm();
}
private void SetToolBarAlarm()
{
var viewButtonName = currentViewButton.gameObject.name;
var viewMode = viewButtonName.Substring(viewButtonName.IndexOf("_") + 1);
onAlarm?.Invoke(Button_CustomView.transform.position, $"{viewMode} <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><>ġ<EFBFBD><C4A1> <20><><EFBFBD><EFBFBD><EFBFBD>Ͽ<EFBFBD><CFBF><EFBFBD><EFBFBD>ϴ<EFBFBD>.", true);
2025-03-10 16:42:23 +09:00
}
private void OnClickDashBoard()
{
var isActive = Image_DashboardActive.gameObject.activeSelf ? false : true;
Image_DashboardActive.gameObject.SetActive(isActive);
onClickDashBoard?.Invoke(isActive);
2025-03-18 13:57:27 +09:00
}
2025-03-10 16:42:23 +09:00
private void OnClickShoulderView()
{
onClickCameraView?.Invoke(ViewMode.FirstPersonView);
2025-04-22 15:29:46 +09:00
var floorIndex = FindSingle<Building>().currentFloor.floorIndex;
if (floorIndex == 5)
{
onAlarm?.Invoke(Button_SholuderView.transform.position, "<22><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> Shoulder View <20><> <20><>ȯ<EFBFBD><C8AF> <20><> <20><><EFBFBD><EFBFBD><EFBFBD>ϴ<EFBFBD>.", false);
}
2025-03-10 16:42:23 +09:00
}
private void OnClickQuaterView()
{
onClickCameraView?.Invoke(ViewMode.PerspectiveView);
2025-03-10 16:42:23 +09:00
}
private void OnClickTopView()
{
onClickCameraView?.Invoke(ViewMode.TopView);
2025-03-10 16:42:23 +09:00
}
2025-04-09 14:41:40 +09:00
private void SetViewButtonState(Button button)
{
if (currentViewButton != null)
{
var images = currentViewButton.GetComponentsInChildren<Image>(true);
var image = images.Where(a => a != currentViewButton.image).First();
image.gameObject.SetActive(false);
}
currentViewButton = button;
var currentButtonImages = currentViewButton.GetComponentsInChildren<Image>(true);
var currentButtonImage = currentButtonImages.Where(a => a != currentViewButton.image).First();
currentButtonImage.gameObject.SetActive(true);
}
public void SetChangeViewButtonState(ViewMode viewMode)
{
var viewButton = viewButtons[viewMode];
SetViewButtonState(viewButton);
}
2025-03-10 16:42:23 +09:00
}