Files
ChunilENG/Assets/WorkSpace/Personal/JYM/Panel_ToolBar.cs
2025-04-16 13:51:42 +09:00

197 lines
6.1 KiB
C#

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;
using CHN;
using System.Linq;
public class Panel_ToolBar : PanelBase
{
private Dictionary<ViewMode, Button> viewButtons = new Dictionary<ViewMode, Button>();
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;
private Button Button_FloorControl;
private Image Image_DashboardActive;
private Image Image_Record_Play;
private Image Image_MiniMapActive;
private Image Image_FloorControlActive;
private Button currentViewButton;
private CaptureBase capture;
public Action<ViewMode> onClickCameraView;
public Action<bool> onClickDashBoard;
public Action<int> onClickCustomView;
public Action onClickMiniMap;
public Action onClickFloorControl;
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);
Button_FloorControl.onClick.AddListener(OnClickFloorControl);
viewButtons.Add(ViewMode.TopView, Button_TopView);
viewButtons.Add(ViewMode.PerspectiveView, Button_QuarterView);
viewButtons.Add(ViewMode.FirstPersonView, Button_SholuderView);
RecordSetting();
CaptureSetting();
}
private void RecordSetting()
{
var filePath = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.MyVideos));
capture = GameObject.FindFirstObjectByType<CaptureBase>();
capture.CameraRenderResolution = CaptureBase.Resolution.Custom;
capture.CompletedFileWritingAction += OnCompleted;
}
private void CaptureSetting()
{
var filePath = Path.GetFullPath(Environment.GetFolderPath(Environment.SpecialFolder.MyPictures));
}
private void OnCompleted(FileWritingHandler handler)
{
var sourcePath = handler.FinalPath;
var destFilePath = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", "mp4");
if (!string.IsNullOrEmpty(destFilePath))
{
File.Delete(destFilePath);
File.Move(sourcePath, destFilePath);
}
else
{
File.Delete(sourcePath);
}
}
private void OnClickFloorControl()
{
var isActive = Image_FloorControlActive.gameObject.activeSelf ? false : true;
Image_FloorControlActive.gameObject.SetActive(isActive);
onClickFloorControl?.Invoke();
}
private void OnClickCapture()
{
var destFilePath = StandaloneFileBrowser.SaveFilePanel("Save File", "", "", "png");
if (!string.IsNullOrEmpty(destFilePath))
{
ScreenCapture.CaptureScreenshot(destFilePath);
}
}
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);
}
}
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()
{
var isActive = Image_MiniMapActive.gameObject.activeSelf ? false : true;
Image_MiniMapActive.gameObject.SetActive(isActive);
onClickMiniMap?.Invoke();
}
private void OnClickCustomView()
{
var floorIndex = FindSingle<Building>().currentFloor.floorIndex;
onClickCustomView?.Invoke(floorIndex);
}
private void OnClickDashBoard()
{
var isActive = Image_DashboardActive.gameObject.activeSelf ? false : true;
Image_DashboardActive.gameObject.SetActive(isActive);
onClickDashBoard?.Invoke(isActive);
}
private void OnClickShoulderView()
{
onClickCameraView?.Invoke(ViewMode.FirstPersonView);
}
private void OnClickQuaterView()
{
onClickCameraView?.Invoke(ViewMode.PerspectiveView);
}
private void OnClickTopView()
{
onClickCameraView?.Invoke(ViewMode.TopView);
}
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);
}
}