|
@@ -1,4 +1,4 @@
|
|
-using System;
|
|
|
|
|
|
+using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.IO;
|
|
using UnityEngine;
|
|
using UnityEngine;
|
|
@@ -7,12 +7,9 @@ using Object = UnityEngine.Object;
|
|
namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
{
|
|
{
|
|
using Input = InputManager;
|
|
using Input = InputManager;
|
|
- using UInput = Input;
|
|
|
|
public class EnvironmentManager : IManager, ISerializable
|
|
public class EnvironmentManager : IManager, ISerializable
|
|
{
|
|
{
|
|
private static readonly BgMgr bgMgr = GameMain.Instance.BgMgr;
|
|
private static readonly BgMgr bgMgr = GameMain.Instance.BgMgr;
|
|
- private static readonly CameraMain mainCamera = CameraUtility.MainCamera;
|
|
|
|
- private static readonly UltimateOrbitCamera ultimateOrbitCamera = CameraUtility.UOCamera;
|
|
|
|
public const string header = "ENVIRONMENT";
|
|
public const string header = "ENVIRONMENT";
|
|
public const string defaultBg = "Theater";
|
|
public const string defaultBg = "Theater";
|
|
private const string myRoomPrefix = "マイルーム:";
|
|
private const string myRoomPrefix = "マイルーム:";
|
|
@@ -40,12 +37,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
}
|
|
}
|
|
private static event EventHandler CubeActiveChange;
|
|
private static event EventHandler CubeActiveChange;
|
|
private static event EventHandler CubeSmallChange;
|
|
private static event EventHandler CubeSmallChange;
|
|
- private GameObject cameraObject;
|
|
|
|
- private Camera subCamera;
|
|
|
|
- private GameObject bgObject;
|
|
|
|
private Transform bg;
|
|
private Transform bg;
|
|
|
|
+ private GameObject bgObject;
|
|
private DragPointBG bgDragPoint;
|
|
private DragPointBG bgDragPoint;
|
|
- private string currentBGAsset = defaultBg;
|
|
|
|
|
|
+ public string CurrentBgAsset { get; private set; } = defaultBg;
|
|
private bool bgVisible = true;
|
|
private bool bgVisible = true;
|
|
public bool BGVisible
|
|
public bool BGVisible
|
|
{
|
|
{
|
|
@@ -56,35 +51,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
bgObject.SetActive(bgVisible);
|
|
bgObject.SetActive(bgVisible);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- private float defaultCameraMoveSpeed;
|
|
|
|
- private float defaultCameraZoomSpeed;
|
|
|
|
- private const float cameraFastMoveSpeed = 0.1f;
|
|
|
|
- private const float cameraFastZoomSpeed = 3f;
|
|
|
|
- private CameraInfo tempCameraInfo;
|
|
|
|
- private int currentCameraIndex;
|
|
|
|
- private const KeyCode AlphaOne = KeyCode.Alpha1;
|
|
|
|
- public int CameraCount => cameraInfos.Length;
|
|
|
|
- public EventHandler CameraChange;
|
|
|
|
-
|
|
|
|
- public int CurrentCameraIndex
|
|
|
|
- {
|
|
|
|
- get => currentCameraIndex;
|
|
|
|
- set
|
|
|
|
- {
|
|
|
|
- cameraInfos[currentCameraIndex] = mainCamera.GetInfo();
|
|
|
|
- currentCameraIndex = value;
|
|
|
|
- LoadCameraInfo(cameraInfos[currentCameraIndex]);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- private CameraInfo[] cameraInfos;
|
|
|
|
-
|
|
|
|
- static EnvironmentManager()
|
|
|
|
- {
|
|
|
|
- Input.Register(MpsKey.CameraLayer, KeyCode.Q, "Camera control layer");
|
|
|
|
- Input.Register(MpsKey.CameraSave, KeyCode.S, "Save camera transform");
|
|
|
|
- Input.Register(MpsKey.CameraLoad, KeyCode.A, "Load camera transform");
|
|
|
|
- Input.Register(MpsKey.CameraReset, KeyCode.R, "Reset camera transform");
|
|
|
|
- }
|
|
|
|
|
|
|
|
public EnvironmentManager()
|
|
public EnvironmentManager()
|
|
{
|
|
{
|
|
@@ -92,62 +58,7 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
Activate();
|
|
Activate();
|
|
}
|
|
}
|
|
|
|
|
|
- public void Serialize(BinaryWriter binaryWriter) => Serialize(binaryWriter, false);
|
|
|
|
-
|
|
|
|
- public void Serialize(BinaryWriter binaryWriter, bool kankyo)
|
|
|
|
- {
|
|
|
|
- binaryWriter.Write(header);
|
|
|
|
- binaryWriter.Write(currentBGAsset);
|
|
|
|
- binaryWriter.WriteVector3(bg.position);
|
|
|
|
- binaryWriter.WriteQuaternion(bg.rotation);
|
|
|
|
- binaryWriter.WriteVector3(bg.localScale);
|
|
|
|
-
|
|
|
|
- binaryWriter.Write(kankyo);
|
|
|
|
-
|
|
|
|
- binaryWriter.WriteVector3(mainCamera.GetTargetPos());
|
|
|
|
- binaryWriter.Write(mainCamera.GetDistance());
|
|
|
|
- binaryWriter.WriteQuaternion(mainCamera.transform.rotation);
|
|
|
|
-
|
|
|
|
- CameraUtility.StopAll();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void Deserialize(BinaryReader binaryReader)
|
|
|
|
- {
|
|
|
|
- var bgAsset = binaryReader.ReadString();
|
|
|
|
- var isCreative = Utility.IsGuidString(bgAsset);
|
|
|
|
- List<string> bgList = isCreative
|
|
|
|
- ? Constants.MyRoomCustomBGList.ConvertAll(kvp => kvp.Key)
|
|
|
|
- : Constants.BGList;
|
|
|
|
-
|
|
|
|
- var assetIndex = bgList.FindIndex(
|
|
|
|
- asset => asset.Equals(bgAsset, StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
- );
|
|
|
|
- if (assetIndex < 0)
|
|
|
|
- {
|
|
|
|
- Utility.LogWarning($"Could not load BG '{bgAsset}'");
|
|
|
|
- isCreative = false;
|
|
|
|
- bgAsset = defaultBg;
|
|
|
|
- }
|
|
|
|
- else bgAsset = bgList[assetIndex];
|
|
|
|
-
|
|
|
|
- ChangeBackground(bgAsset, isCreative);
|
|
|
|
- bg.position = binaryReader.ReadVector3();
|
|
|
|
- bg.rotation = binaryReader.ReadQuaternion();
|
|
|
|
- bg.localScale = binaryReader.ReadVector3();
|
|
|
|
-
|
|
|
|
- var kankyo = binaryReader.ReadBoolean();
|
|
|
|
-
|
|
|
|
- Vector3 cameraPosition = binaryReader.ReadVector3();
|
|
|
|
- var cameraDistance = binaryReader.ReadSingle();
|
|
|
|
- Quaternion cameraRotation = binaryReader.ReadQuaternion();
|
|
|
|
-
|
|
|
|
- if (kankyo) return;
|
|
|
|
-
|
|
|
|
- mainCamera.SetTargetPos(cameraPosition);
|
|
|
|
- mainCamera.SetDistance(cameraDistance);
|
|
|
|
- mainCamera.transform.rotation = cameraRotation;
|
|
|
|
- CameraUtility.StopAll();
|
|
|
|
- }
|
|
|
|
|
|
+ public void Update() { }
|
|
|
|
|
|
public void Activate()
|
|
public void Activate()
|
|
{
|
|
{
|
|
@@ -156,37 +67,10 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
|
|
|
|
bgObject = bgMgr.Parent;
|
|
bgObject = bgMgr.Parent;
|
|
|
|
|
|
- cameraObject = new GameObject("subCamera");
|
|
|
|
- subCamera = cameraObject.AddComponent<Camera>();
|
|
|
|
- subCamera.CopyFrom(mainCamera.camera);
|
|
|
|
- subCamera.clearFlags = CameraClearFlags.Depth;
|
|
|
|
- subCamera.cullingMask = 256;
|
|
|
|
- subCamera.depth = 1f;
|
|
|
|
- subCamera.transform.parent = mainCamera.transform;
|
|
|
|
-
|
|
|
|
- cameraObject.SetActive(true);
|
|
|
|
-
|
|
|
|
bgObject.SetActive(true);
|
|
bgObject.SetActive(true);
|
|
-
|
|
|
|
- ultimateOrbitCamera.enabled = true;
|
|
|
|
-
|
|
|
|
- defaultCameraMoveSpeed = ultimateOrbitCamera.moveSpeed;
|
|
|
|
- defaultCameraZoomSpeed = ultimateOrbitCamera.zoomSpeed;
|
|
|
|
-
|
|
|
|
- if (!MeidoPhotoStudio.EditMode)
|
|
|
|
- {
|
|
|
|
- ResetCamera();
|
|
|
|
- ChangeBackground(defaultBg);
|
|
|
|
- }
|
|
|
|
- else UpdateBG();
|
|
|
|
-
|
|
|
|
- SaveTempCamera();
|
|
|
|
-
|
|
|
|
- CameraInfo initalInfo = mainCamera.GetInfo();
|
|
|
|
-
|
|
|
|
- cameraInfos = new CameraInfo[5];
|
|
|
|
-
|
|
|
|
- for (var i = 0; i < CameraCount; i++) cameraInfos[i] = initalInfo;
|
|
|
|
|
|
+
|
|
|
|
+ if (MeidoPhotoStudio.EditMode) UpdateBG();
|
|
|
|
+ else ChangeBackground(defaultBg);
|
|
|
|
|
|
CubeSmallChange += OnCubeSmall;
|
|
CubeSmallChange += OnCubeSmall;
|
|
CubeActiveChange += OnCubeActive;
|
|
CubeActiveChange += OnCubeActive;
|
|
@@ -198,26 +82,13 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
BgMgrPatcher.ChangeBgEnd -= OnChangeEnd;
|
|
BgMgrPatcher.ChangeBgEnd -= OnChangeEnd;
|
|
|
|
|
|
DestroyDragPoint();
|
|
DestroyDragPoint();
|
|
- Object.Destroy(cameraObject);
|
|
|
|
- Object.Destroy(subCamera);
|
|
|
|
-
|
|
|
|
BGVisible = true;
|
|
BGVisible = true;
|
|
- mainCamera.camera.backgroundColor = Color.black;
|
|
|
|
-
|
|
|
|
- ultimateOrbitCamera.moveSpeed = defaultCameraMoveSpeed;
|
|
|
|
- ultimateOrbitCamera.zoomSpeed = defaultCameraZoomSpeed;
|
|
|
|
|
|
|
|
if (MeidoPhotoStudio.EditMode) bgMgr.ChangeBg(defaultBg);
|
|
if (MeidoPhotoStudio.EditMode) bgMgr.ChangeBg(defaultBg);
|
|
else
|
|
else
|
|
{
|
|
{
|
|
var isNight = GameMain.Instance.CharacterMgr.status.GetFlag("時間帯") == 3;
|
|
var isNight = GameMain.Instance.CharacterMgr.status.GetFlag("時間帯") == 3;
|
|
-
|
|
|
|
bgMgr.ChangeBg(isNight ? "ShinShitsumu_ChairRot_Night" : "ShinShitsumu_ChairRot");
|
|
bgMgr.ChangeBg(isNight ? "ShinShitsumu_ChairRot_Night" : "ShinShitsumu_ChairRot");
|
|
-
|
|
|
|
- mainCamera.Reset(CameraMain.CameraType.Target, true);
|
|
|
|
- mainCamera.SetTargetPos(new Vector3(0.5609447f, 1.380762f, -1.382336f));
|
|
|
|
- mainCamera.SetDistance(1.6f);
|
|
|
|
- mainCamera.SetAroundAngle(new Vector2(245.5691f, 6.273283f));
|
|
|
|
}
|
|
}
|
|
|
|
|
|
if (bgMgr.BgObject) bgMgr.BgObject.transform.localScale = Vector3.one;
|
|
if (bgMgr.BgObject) bgMgr.BgObject.transform.localScale = Vector3.one;
|
|
@@ -226,23 +97,38 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
CubeActiveChange -= OnCubeActive;
|
|
CubeActiveChange -= OnCubeActive;
|
|
}
|
|
}
|
|
|
|
|
|
- public void Update()
|
|
|
|
|
|
+ public void Serialize(BinaryWriter binaryWriter)
|
|
{
|
|
{
|
|
- if (Input.GetKey(MpsKey.CameraLayer))
|
|
|
|
- {
|
|
|
|
- if (Input.GetKeyDown(MpsKey.CameraSave)) SaveTempCamera();
|
|
|
|
- else if (Input.GetKeyDown(MpsKey.CameraLoad)) LoadCameraInfo(tempCameraInfo);
|
|
|
|
- else if (Input.GetKeyDown(MpsKey.CameraReset)) ResetCamera();
|
|
|
|
|
|
+ binaryWriter.Write(header);
|
|
|
|
+ binaryWriter.Write(CurrentBgAsset);
|
|
|
|
+ binaryWriter.WriteVector3(bg.position);
|
|
|
|
+ binaryWriter.WriteQuaternion(bg.rotation);
|
|
|
|
+ binaryWriter.WriteVector3(bg.localScale);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void Deserialize(BinaryReader binaryReader)
|
|
|
|
+ {
|
|
|
|
+ var bgAsset = binaryReader.ReadString();
|
|
|
|
+ var isCreative = Utility.IsGuidString(bgAsset);
|
|
|
|
+ List<string> bgList = isCreative
|
|
|
|
+ ? Constants.MyRoomCustomBGList.ConvertAll(kvp => kvp.Key)
|
|
|
|
+ : Constants.BGList;
|
|
|
|
|
|
- for (var i = 0; i < CameraCount; i++)
|
|
|
|
- {
|
|
|
|
- if (i != CurrentCameraIndex && UInput.GetKeyDown(AlphaOne + i)) CurrentCameraIndex = i;
|
|
|
|
- }
|
|
|
|
|
|
+ var assetIndex = bgList.FindIndex(
|
|
|
|
+ asset => asset.Equals(bgAsset, StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
+ );
|
|
|
|
+ if (assetIndex < 0)
|
|
|
|
+ {
|
|
|
|
+ Utility.LogWarning($"Could not load BG '{bgAsset}'");
|
|
|
|
+ isCreative = false;
|
|
|
|
+ bgAsset = defaultBg;
|
|
}
|
|
}
|
|
|
|
+ else bgAsset = bgList[assetIndex];
|
|
|
|
|
|
- var shift = Input.Shift;
|
|
|
|
- ultimateOrbitCamera.moveSpeed = shift ? cameraFastMoveSpeed : defaultCameraMoveSpeed;
|
|
|
|
- ultimateOrbitCamera.zoomSpeed = shift ? cameraFastZoomSpeed : defaultCameraZoomSpeed;
|
|
|
|
|
|
+ ChangeBackground(bgAsset, isCreative);
|
|
|
|
+ bg.position = binaryReader.ReadVector3();
|
|
|
|
+ bg.rotation = binaryReader.ReadQuaternion();
|
|
|
|
+ bg.localScale = binaryReader.ReadVector3();
|
|
}
|
|
}
|
|
|
|
|
|
public void ChangeBackground(string assetName, bool creative = false)
|
|
public void ChangeBackground(string assetName, bool creative = false)
|
|
@@ -269,9 +155,9 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
{
|
|
{
|
|
if (!bgMgr.BgObject) return;
|
|
if (!bgMgr.BgObject) return;
|
|
|
|
|
|
- currentBGAsset = bgMgr.GetBGName();
|
|
|
|
- if (currentBGAsset.StartsWith(myRoomPrefix))
|
|
|
|
- currentBGAsset = currentBGAsset.Replace(myRoomPrefix, string.Empty);
|
|
|
|
|
|
+ CurrentBgAsset = bgMgr.GetBGName();
|
|
|
|
+ if (CurrentBgAsset.StartsWith(myRoomPrefix))
|
|
|
|
+ CurrentBgAsset = CurrentBgAsset.Replace(myRoomPrefix, string.Empty);
|
|
bg = bgMgr.BgObject.transform;
|
|
bg = bgMgr.BgObject.transform;
|
|
AttachDragPoint(bg);
|
|
AttachDragPoint(bg);
|
|
}
|
|
}
|
|
@@ -281,22 +167,6 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
if (bgDragPoint) Object.Destroy(bgDragPoint.gameObject);
|
|
if (bgDragPoint) Object.Destroy(bgDragPoint.gameObject);
|
|
}
|
|
}
|
|
|
|
|
|
- private void SaveTempCamera() => tempCameraInfo = mainCamera.GetInfo(true);
|
|
|
|
-
|
|
|
|
- public void LoadCameraInfo(CameraInfo info)
|
|
|
|
- {
|
|
|
|
- mainCamera.ApplyInfo(info, true);
|
|
|
|
- CameraChange?.Invoke(this, EventArgs.Empty);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void ResetCamera()
|
|
|
|
- {
|
|
|
|
- mainCamera.Reset(CameraMain.CameraType.Target, true);
|
|
|
|
- mainCamera.SetTargetPos(new Vector3(0f, 0.9f, 0f));
|
|
|
|
- mainCamera.SetDistance(3f);
|
|
|
|
- CameraChange?.Invoke(this, EventArgs.Empty);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void OnCubeSmall(object sender, EventArgs args)
|
|
private void OnCubeSmall(object sender, EventArgs args)
|
|
{
|
|
{
|
|
bgDragPoint.DragPointScale = CubeSmall ? DragPointGeneral.smallCube : 1f;
|
|
bgDragPoint.DragPointScale = CubeSmall ? DragPointGeneral.smallCube : 1f;
|
|
@@ -307,20 +177,4 @@ namespace COM3D2.MeidoPhotoStudio.Plugin
|
|
bgDragPoint.gameObject.SetActive(CubeActive);
|
|
bgDragPoint.gameObject.SetActive(CubeActive);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
- public readonly struct CameraInfo
|
|
|
|
- {
|
|
|
|
- public Vector3 TargetPos { get; }
|
|
|
|
- public Quaternion Angle { get; }
|
|
|
|
- public float Distance { get; }
|
|
|
|
- public float FOV { get; }
|
|
|
|
-
|
|
|
|
- public CameraInfo(CameraMain camera)
|
|
|
|
- {
|
|
|
|
- TargetPos = camera.GetTargetPos();
|
|
|
|
- Angle = camera.transform.rotation;
|
|
|
|
- Distance = camera.GetDistance();
|
|
|
|
- FOV = camera.camera.fieldOfView;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
}
|
|
}
|