🤔
This commit is contained in:
@@ -0,0 +1,209 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using DG.Tweening.Core.Easing;
|
||||
using UnityEngine;
|
||||
using Ichni.Editor;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
|
||||
namespace Ichni.RhythmGame
|
||||
{
|
||||
public class CameraAngleOffset : AnimationBase
|
||||
{
|
||||
public List<Hold> holds => Hold.holdingHoldList;
|
||||
public TransformSubmodule camtransformSubmodule;
|
||||
public FlexibleBool enabling;
|
||||
public float MaxxOffset;
|
||||
public float MaxyOffset;
|
||||
public float MaxzOffset;
|
||||
public float TimeToMax;
|
||||
public AnimationCurveType animationCurveType;
|
||||
public float xCurrentValue;
|
||||
public float yCurrentValue;
|
||||
public float zCurrentValue;
|
||||
|
||||
bool xOffseting;
|
||||
bool yOffseting;
|
||||
bool zOffseting;
|
||||
float xOffsetStartTime = 0f;
|
||||
float yOffsetStartTime = 0f;
|
||||
float zOffsetStartTime = 0f;
|
||||
|
||||
protected override void UpdateAnimation(float songTime)
|
||||
{
|
||||
if (enabling == null)
|
||||
return;
|
||||
enabling.UpdateFlexibleBool(songTime);
|
||||
if (enabling.value && Hold.holdingHoldList.Count != 0)
|
||||
{
|
||||
|
||||
animationReturnType = FlexibleReturnType.MiddleExecuting;
|
||||
|
||||
float xValue = 0;
|
||||
float yValue = 0;
|
||||
float zValue = 0;
|
||||
if (Hold.holdingHoldList != null)
|
||||
{
|
||||
foreach (Hold i in Hold.holdingHoldList)
|
||||
{
|
||||
xValue += i.noteScreenPosition.x - (Screen.width / 2);
|
||||
yValue += i.noteScreenPosition.y - (Screen.width / 2);
|
||||
}
|
||||
}
|
||||
zValue = xValue;
|
||||
JudgeState(ref xCurrentValue, xValue, ref xOffseting, ref xOffsetStartTime, songTime);
|
||||
JudgeState(ref yCurrentValue, yValue, ref yOffseting, ref yOffsetStartTime, songTime);
|
||||
JudgeState(ref zCurrentValue, zValue, ref zOffseting, ref zOffsetStartTime, songTime);
|
||||
|
||||
// 平滑过渡到目标值
|
||||
if (xOffseting)
|
||||
{
|
||||
xCurrentValue = UpdateOffset(xOffsetStartTime, ref xOffseting, songTime, MaxxOffset);
|
||||
}
|
||||
if (yOffseting)
|
||||
{
|
||||
yCurrentValue = UpdateOffset(yOffsetStartTime, ref yOffseting, songTime, MaxyOffset);
|
||||
}
|
||||
if (zOffseting)
|
||||
{
|
||||
zCurrentValue = UpdateOffset(zOffsetStartTime, ref zOffseting, songTime, MaxzOffset);
|
||||
}
|
||||
if (camtransformSubmodule != null && camtransformSubmodule.eulerAnglesOffset != null)
|
||||
{
|
||||
Vector3 currentEulerAngles = new(xCurrentValue, yCurrentValue, zCurrentValue);
|
||||
camtransformSubmodule.eulerAnglesOffset.Add(currentEulerAngles);
|
||||
camtransformSubmodule.eulerAnglesDirtyMark = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
animationReturnType = FlexibleReturnType.MiddleInterval;
|
||||
|
||||
}
|
||||
}
|
||||
public override void SetDefaultSubmodules()
|
||||
{
|
||||
timeDurationSubmodule = new TimeDurationSubmodule(this);
|
||||
|
||||
}
|
||||
private void JudgeState(ref float CurrentValue, float Value, ref bool Offseting, ref float OffsetStartTime, float songtime)
|
||||
{
|
||||
if (Mathf.Abs(Value - CurrentValue) >= 1)
|
||||
{
|
||||
Offseting = true;
|
||||
OffsetStartTime = songtime;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
CurrentValue = Value;
|
||||
}
|
||||
}
|
||||
private float UpdateOffset(float OffsetStartTime, ref bool Offseting, float songTime, float MaxOffset)
|
||||
{
|
||||
if (OffsetStartTime + TimeToMax < songTime)
|
||||
{
|
||||
Offseting = false;
|
||||
return MaxOffset;
|
||||
}
|
||||
float denominator = songTime + TimeToMax - OffsetStartTime;
|
||||
if (Mathf.Approximately(denominator, 0f))
|
||||
return 0f;
|
||||
float Value = AnimationCurveEvaluator.Evaluate(animationCurveType, (songTime - OffsetStartTime) / denominator);
|
||||
return Value * MaxOffset;
|
||||
}
|
||||
|
||||
|
||||
public static CameraAngleOffset GenerateElement(
|
||||
string elementName, Guid id, List<string> tags, bool isFirstGenerated, GameElement animatedObject,
|
||||
FlexibleBool enabling, float maxX, float maxY, float maxZ, float timeToMax, AnimationCurveType curveType)
|
||||
{
|
||||
CameraAngleOffset offset = Instantiate(EditorManager.instance.basePrefabs.emptyObject)
|
||||
.AddComponent<CameraAngleOffset>();
|
||||
offset.Initialize(elementName, id, tags, isFirstGenerated, animatedObject);
|
||||
offset.animatedObject = animatedObject;
|
||||
var submoduleHolder = animatedObject as IHaveTransformSubmodule;
|
||||
if (submoduleHolder != null)
|
||||
offset.camtransformSubmodule = EditorManager.instance.cameraManager.gameCamera.transformSubmodule;
|
||||
offset.enabling = enabling;
|
||||
offset.MaxxOffset = maxX;
|
||||
offset.MaxyOffset = maxY;
|
||||
offset.MaxzOffset = maxZ;
|
||||
offset.TimeToMax = timeToMax;
|
||||
offset.animationCurveType = curveType;
|
||||
offset.animationReturnType = FlexibleReturnType.Before;
|
||||
return offset;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public override void SaveBM()
|
||||
{
|
||||
matchedBM = new CameraAngleOffset_BM(
|
||||
elementName, elementGuid, tags, parentElement.matchedBM as GameElement_BM,
|
||||
enabling.ConvertToBM(), MaxxOffset, MaxyOffset, MaxzOffset, TimeToMax, animationCurveType
|
||||
);
|
||||
}
|
||||
|
||||
public override void SetUpInspector()
|
||||
{
|
||||
base.SetUpInspector();
|
||||
IHaveInspection inspector = EditorManager.instance.uiManager.inspector;
|
||||
var container = inspector.GenerateContainer("CameraAngleOffset");
|
||||
var subcontainer = container.GenerateSubcontainer(5);
|
||||
|
||||
inspector.GenerateButton(this, subcontainer, "Enabling", () =>
|
||||
{
|
||||
inspector.GenerateCompositeParameterWindow(this, "Enabling", nameof(enabling)).SetAsFlexibleBool();
|
||||
});
|
||||
|
||||
inspector.GenerateInputField(this, subcontainer, "Max X Offset", nameof(MaxxOffset));
|
||||
inspector.GenerateInputField(this, subcontainer, "Max Y Offset", nameof(MaxyOffset));
|
||||
inspector.GenerateInputField(this, subcontainer, "Max Z Offset", nameof(MaxzOffset));
|
||||
inspector.GenerateInputField(this, subcontainer, "Time To Max", nameof(TimeToMax));
|
||||
inspector.GenerateDropdown(this, subcontainer, "Offset Ease", typeof(AnimationCurveType), nameof(animationCurveType));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// BM类
|
||||
namespace Beatmap
|
||||
{
|
||||
public class CameraAngleOffset_BM : AnimationBase_BM
|
||||
{
|
||||
public FlexibleBool_BM enabling;
|
||||
public float maxX, maxY, maxZ, timeToMax;
|
||||
public AnimationCurveType animationCurveType;
|
||||
|
||||
public CameraAngleOffset_BM() { }
|
||||
|
||||
public CameraAngleOffset_BM(string elementName, Guid elementGuid, List<string> tags, GameElement_BM attachedElement,
|
||||
FlexibleBool_BM enabling, float maxX, float maxY, float maxZ, float timeToMax, AnimationCurveType curveType)
|
||||
: base(elementName, elementGuid, tags, attachedElement)
|
||||
{
|
||||
this.enabling = enabling;
|
||||
this.maxX = maxX;
|
||||
this.maxY = maxY;
|
||||
this.maxZ = maxZ;
|
||||
this.timeToMax = timeToMax;
|
||||
this.animationCurveType = curveType;
|
||||
}
|
||||
|
||||
public override void ExecuteBM()
|
||||
{
|
||||
matchedElement = CameraAngleOffset.GenerateElement(
|
||||
elementName, elementGuid, tags, false, GetElement(attachedElementGuid),
|
||||
enabling.ConvertToGameType(), maxX, maxY, maxZ, timeToMax, animationCurveType
|
||||
);
|
||||
}
|
||||
|
||||
public override GameElement DuplicateBM(GameElement parent)
|
||||
{
|
||||
return CameraAngleOffset.GenerateElement(
|
||||
elementName, Guid.NewGuid(), tags, false, parent,
|
||||
enabling.ConvertToGameType(), maxX, maxY, maxZ, timeToMax, animationCurveType
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1ec2771618afafe489a6cd3de5b20bc1
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -44,7 +44,7 @@ namespace Ichni.RhythmGame
|
||||
eulerAngleY.UpdateFlexibleFloat(songTime);
|
||||
eulerAngleZ.UpdateFlexibleFloat(songTime);
|
||||
|
||||
if ((eulerAngleX.returnType is FlexibleReturnType.MiddleExecuting || eulerAngleX.isSwitchingReturnType) ||
|
||||
if (eulerAngleX.returnType is FlexibleReturnType.MiddleExecuting || eulerAngleX.isSwitchingReturnType ||
|
||||
(eulerAngleY.returnType is FlexibleReturnType.MiddleExecuting || eulerAngleY.isSwitchingReturnType) ||
|
||||
(eulerAngleZ.returnType is FlexibleReturnType.MiddleExecuting || eulerAngleZ.isSwitchingReturnType))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user