147 lines
5.5 KiB
C#
147 lines
5.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using Dreamteck.Splines;
|
|
using Lean.Pool;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
|
|
namespace Ichni.RhythmGame
|
|
{
|
|
public partial class GameCamera : BaseElement
|
|
{
|
|
public Camera camera;
|
|
public Transform rotationPoint;
|
|
public Transform positionPoint;
|
|
public Transform cameraTransform;
|
|
|
|
public CameraViewType cameraViewType;
|
|
public float perspectiveAngle;
|
|
public float orthographicSize;
|
|
|
|
public static GameCamera GenerateElement(string elementName, Guid id,
|
|
List<string> tags, BaseElement parentElement,
|
|
CameraViewType cameraViewType, float perspectiveAngle, float orthographicSize,
|
|
Vector3 initialPosition, Vector3 initialEulerAngles)
|
|
{
|
|
GameCamera gameCamera =
|
|
Instantiate(EditorManager.instance.basePrefabs.gameCamera).GetComponent<GameCamera>();
|
|
|
|
gameCamera.Initialize(elementName, id, tags);
|
|
gameCamera.parentElement = parentElement;
|
|
gameCamera.cameraViewType = cameraViewType;
|
|
gameCamera.camera.orthographic = cameraViewType == CameraViewType.Orthographic;
|
|
gameCamera.perspectiveAngle = perspectiveAngle;
|
|
gameCamera.orthographicSize = orthographicSize;
|
|
gameCamera.transformSubmodule =
|
|
new TransformSubmodule(gameCamera, initialPosition, initialEulerAngles, Vector3.one);
|
|
gameCamera.cameraTransform = gameCamera.transform;
|
|
|
|
gameCamera.SetParent(parentElement);
|
|
|
|
return gameCamera;
|
|
}
|
|
}
|
|
|
|
public partial class GameCamera
|
|
{
|
|
public enum CameraViewType
|
|
{
|
|
None = -1,
|
|
Perspective = 0,
|
|
Orthographic = 1
|
|
}
|
|
}
|
|
|
|
public partial class GameCamera
|
|
{
|
|
public override void SetTransformObserver()
|
|
{
|
|
Observable.EveryUpdate().Subscribe(_ =>
|
|
{
|
|
if (transformSubmodule.eulerAnglesOffsetLock)
|
|
{
|
|
rotationPoint.eulerAngles = transformSubmodule.currentEulerAngles;
|
|
}
|
|
else if (transformSubmodule.eulerAnglesDirtyMark)
|
|
{
|
|
Vector3 offset = Vector3.zero;
|
|
foreach (Vector3 eulerOffset in transformSubmodule.eulerAnglesOffset)
|
|
{
|
|
offset += eulerOffset;
|
|
}
|
|
|
|
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + offset;
|
|
rotationPoint.eulerAngles = transformSubmodule.currentEulerAngles;
|
|
transformSubmodule.eulerAnglesDirtyMark = false;
|
|
}
|
|
|
|
if (transformSubmodule.positionDirtyMark)
|
|
{
|
|
Vector3 offset = Vector3.zero;
|
|
foreach (Vector3 posOffset in transformSubmodule.positionOffset)
|
|
{
|
|
offset += posOffset;
|
|
}
|
|
|
|
transformSubmodule.currentPosition = transformSubmodule.originalPosition + offset;
|
|
positionPoint.localPosition = transformSubmodule.currentPosition;
|
|
transformSubmodule.positionDirtyMark = false;
|
|
}
|
|
}).AddTo(gameObject);
|
|
}
|
|
}
|
|
|
|
public partial class GameCamera
|
|
{
|
|
public override void SaveBM()
|
|
{
|
|
matchedBM = new Beatmap.GameCamera_BM(elementName, elementGuid, tags, parentElement.matchedBM,
|
|
cameraViewType, perspectiveAngle, orthographicSize, transformSubmodule.currentPosition,
|
|
transformSubmodule.currentEulerAngles);
|
|
}
|
|
}
|
|
|
|
namespace Beatmap
|
|
{
|
|
public class GameCamera_BM : BaseElement_BM
|
|
{
|
|
public GameCamera.CameraViewType cameraViewType;
|
|
public float perspectiveAngle;
|
|
public float orthographicSize;
|
|
public Vector3 initialPosition;
|
|
public Vector3 initialEulerAngles;
|
|
|
|
public GameCamera_BM()
|
|
{
|
|
|
|
}
|
|
|
|
public GameCamera_BM(string elementName, Guid elementGuid, List<string> tags,
|
|
BaseElement_BM attachedElement,
|
|
GameCamera.CameraViewType cameraViewType, float perspectiveAngle, float orthographicSize,
|
|
Vector3 initialPosition, Vector3 initialEulerAngles)
|
|
: base(elementName, elementGuid, tags, attachedElement)
|
|
{
|
|
this.cameraViewType = cameraViewType;
|
|
this.perspectiveAngle = perspectiveAngle;
|
|
this.orthographicSize = orthographicSize;
|
|
this.initialPosition = initialPosition;
|
|
this.initialEulerAngles = initialEulerAngles;
|
|
}
|
|
|
|
public override void ExecuteBM()
|
|
{
|
|
GameCamera.GenerateElement(elementName, elementGuid, tags, GetElement(attachedElementGuid),
|
|
cameraViewType, perspectiveAngle, orthographicSize, initialPosition, initialEulerAngles);
|
|
}
|
|
|
|
public override BaseElement DuplicateBM(BaseElement parent)
|
|
{
|
|
return GameCamera.GenerateElement(elementName, elementGuid, tags, parent, cameraViewType,
|
|
perspectiveAngle, orthographicSize, initialPosition, initialEulerAngles);
|
|
}
|
|
}
|
|
}
|
|
} |