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

171 lines
4.9 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-03-10 16:42:23 +09:00
public class Panel_ToolBar : PanelBase
{
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-03-10 16:42:23 +09:00
private CaptureBase capture;
public Action<ViewMode> onClickCameraView;
2025-03-18 13:57:27 +09:00
public Action onClickDashBoard;
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-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
RecordSetting();
CaptureSetting();
}
private void RecordSetting()
{
var filePath = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));
2025-03-10 16:42:23 +09:00
capture = GameObject.FindObjectOfType<CaptureBase>();
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.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-03-10 16:42:23 +09:00
}
private void OnClickDashBoard()
{
2025-03-18 13:57:27 +09:00
Image_DashboardActive.gameObject.SetActive(true);
onClickDashBoard?.Invoke();
2025-03-10 16:42:23 +09:00
}
2025-03-18 13:57:27 +09:00
public void SetDashboard()
{
Image_DashboardActive.gameObject.SetActive(false);
}
2025-03-10 16:42:23 +09:00
private void OnClickShoulderView()
{
onClickCameraView?.Invoke(ViewMode.FirstPersonView);
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
}
}