暂且修了LookAt
This commit is contained in:
@@ -32,13 +32,10 @@ namespace Ichni.RhythmGame
|
||||
look.lookAtObject = lookAtTarget;
|
||||
look.enabling = enabling;
|
||||
look.animationReturnType = FlexibleReturnType.Before;
|
||||
|
||||
|
||||
|
||||
look.targetTransformSubmodule = (animatedObject as IHaveTransformSubmodule).transformSubmodule;
|
||||
|
||||
|
||||
//look.timeDurationSubmodule.SetDuration(-999f, 999f); //TODO: 换为(-delay, songLength)
|
||||
|
||||
look.targetTransformSubmodule.lookAt = look;
|
||||
|
||||
return look;
|
||||
}
|
||||
|
||||
@@ -46,43 +43,19 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
timeDurationSubmodule = new TimeDurationSubmodule(this);
|
||||
}
|
||||
// protected override void Update()
|
||||
// {
|
||||
|
||||
// }
|
||||
// void LateUpdate()
|
||||
// {
|
||||
// if (timeDurationSubmodule.CheckTimeInDuration(EditorManager.instance.songInformation.songTime))
|
||||
// {
|
||||
// UpdateAnimation(EditorManager.instance.songInformation.songTime);
|
||||
// }
|
||||
// }
|
||||
protected override void UpdateAnimation(float songTime)
|
||||
{
|
||||
if (lookAtObject is null) return;
|
||||
|
||||
enabling.UpdateFlexibleBool(songTime);
|
||||
|
||||
targetTransformSubmodule.eulerAnglesOffsetLock = enabling.value;
|
||||
|
||||
if (enabling.value)
|
||||
{
|
||||
animationReturnType = FlexibleReturnType.MiddleExecuting;
|
||||
Vector3 lookingDirection = (lookAtObject.transform.position - animatedObject.transform.position).normalized;
|
||||
|
||||
Vector3 eulerAnglesOffset = Quaternion.LookRotation(lookingDirection).eulerAngles;
|
||||
|
||||
targetTransformSubmodule.eulerAnglesOffset.Add(eulerAnglesOffset);
|
||||
targetTransformSubmodule.eulerAnglesDirtyMark = true;
|
||||
// targetTransformSubmodule.eulerAnglesOffsetLock = true;
|
||||
// targetTransformSubmodule.currentEulerAngles = eulerAnglesOffset;
|
||||
}
|
||||
else if (animationReturnType != FlexibleReturnType.MiddleInterval)
|
||||
{
|
||||
targetTransformSubmodule.eulerAnglesOffset.Add(Vector3.zero);
|
||||
targetTransformSubmodule.eulerAnglesDirtyMark = true;
|
||||
animationReturnType = FlexibleReturnType.MiddleInterval;
|
||||
}
|
||||
|
||||
// targetTransformSubmodule.eulerAnglesOffsetLock = false;
|
||||
|
||||
}
|
||||
|
||||
public override void SaveBM()
|
||||
|
||||
@@ -24,11 +24,12 @@ namespace Ichni.RhythmGame
|
||||
public Vector3 currentPosition;
|
||||
public Vector3 currentEulerAngles;
|
||||
public Vector3 currentScale;
|
||||
|
||||
|
||||
public bool positionDirtyMark;
|
||||
public bool eulerAnglesDirtyMark;
|
||||
public bool scaleDirtyMark;
|
||||
|
||||
public LookAt lookAt;
|
||||
public bool eulerAnglesOffsetLock;
|
||||
|
||||
public TransformSubmodule(GameElement attachedGameElement) : base(attachedGameElement)
|
||||
@@ -157,55 +158,39 @@ namespace Ichni.RhythmGame
|
||||
|
||||
if (transformSubmodule.scaleDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 scaleOffset in transformSubmodule.scaleOffset)
|
||||
{
|
||||
offset += scaleOffset;
|
||||
}
|
||||
|
||||
Vector3 offset = transformSubmodule.scaleOffset.Sum();
|
||||
transformSubmodule.currentScale = transformSubmodule.originalScale + offset;
|
||||
attachedGameElement.transform.localScale = transformSubmodule.currentScale;
|
||||
transformSubmodule.scaleDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.scaleOffset.Clear();
|
||||
}
|
||||
|
||||
if (transformSubmodule.eulerAnglesDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 eulerOffset in transformSubmodule.eulerAnglesOffset)
|
||||
{
|
||||
offset += eulerOffset;
|
||||
}
|
||||
|
||||
Vector3 offset = transformSubmodule.eulerAnglesOffset.Sum();
|
||||
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + offset;
|
||||
attachedGameElement.transform.localEulerAngles = transformSubmodule.currentEulerAngles;
|
||||
transformSubmodule.eulerAnglesDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.eulerAnglesOffset.Clear();
|
||||
}
|
||||
|
||||
if (transformSubmodule.positionDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 posOffset in transformSubmodule.positionOffset)
|
||||
{
|
||||
offset += posOffset;
|
||||
}
|
||||
|
||||
Vector3 offset = transformSubmodule.positionOffset.Sum();
|
||||
transformSubmodule.currentPosition = transformSubmodule.originalPosition + offset;
|
||||
attachedGameElement.transform.localPosition = transformSubmodule.currentPosition;
|
||||
transformSubmodule.positionDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.positionOffset.Clear();
|
||||
}
|
||||
|
||||
if(willRefresh)
|
||||
{
|
||||
attachedGameElement.Refresh();
|
||||
}
|
||||
|
||||
transformSubmodule.scaleOffset.Clear();
|
||||
transformSubmodule.eulerAnglesOffset.Clear();
|
||||
transformSubmodule.positionOffset.Clear();
|
||||
|
||||
|
||||
}).AddTo(attachedGameElement);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ namespace Ichni.RhythmGame
|
||||
Debug.LogError("Null element detected in elementList. Skipping execution.");
|
||||
return;
|
||||
}
|
||||
Debug.Log(element.GetType());
|
||||
//Debug.Log(element.GetType());
|
||||
if (LowPriorityGameElementTypes.Contains(element.GetType()))
|
||||
{
|
||||
return;
|
||||
|
||||
@@ -15,7 +15,8 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
public partial class GameCamera : GameElement, IHaveTransformSubmodule, IHaveTimeDurationSubmodule
|
||||
{
|
||||
[FormerlySerializedAs("camera")] public Camera gameCamera;
|
||||
[FormerlySerializedAs("camera")]
|
||||
public Camera gameCamera;
|
||||
public Transform rotationPoint;
|
||||
public Transform positionPoint;
|
||||
public Transform cameraTransform;
|
||||
@@ -92,22 +93,23 @@ namespace Ichni.RhythmGame
|
||||
|
||||
public partial class GameCamera
|
||||
{
|
||||
private Vector3 GetWorldEulerAngles()
|
||||
private void LateUpdate() // 处理LookAt
|
||||
{
|
||||
Vector3 output = transformSubmodule.originalEulerAngles;
|
||||
GameElement element = this;
|
||||
while (element != null)
|
||||
if (transformSubmodule?.lookAt is not null &&
|
||||
transformSubmodule.eulerAnglesOffsetLock &&
|
||||
transformSubmodule.eulerAnglesDirtyMark)
|
||||
{
|
||||
if (element is IHaveTransformSubmodule)
|
||||
{
|
||||
output += ((TransformSubmodule)element.submoduleList.Where(r => r is TransformSubmodule).First()).currentEulerAngles;
|
||||
}
|
||||
element = element.parentElement;
|
||||
Vector3 offset = transformSubmodule.eulerAnglesOffset.Sum();
|
||||
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + offset;
|
||||
|
||||
transform.LookAt(transformSubmodule.lookAt.lookAtObject.transform);
|
||||
transform.localEulerAngles += transformSubmodule.currentEulerAngles;
|
||||
|
||||
transformSubmodule.eulerAnglesDirtyMark = false;
|
||||
transformSubmodule.eulerAnglesOffset.Clear();
|
||||
}
|
||||
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
public void SetTransformObserver()
|
||||
{
|
||||
Observable.EveryLateUpdate().Subscribe(_ =>
|
||||
@@ -118,47 +120,32 @@ namespace Ichni.RhythmGame
|
||||
}
|
||||
|
||||
bool willRefresh = false;
|
||||
|
||||
if (transformSubmodule.eulerAnglesOffsetLock)
|
||||
|
||||
if (!transformSubmodule.eulerAnglesOffsetLock && transformSubmodule.eulerAnglesDirtyMark)
|
||||
{
|
||||
transform.localEulerAngles = transformSubmodule.originalEulerAngles;
|
||||
}
|
||||
else if (transformSubmodule.eulerAnglesDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 eulerOffset in transformSubmodule.eulerAnglesOffset)
|
||||
{
|
||||
offset += eulerOffset;
|
||||
}
|
||||
|
||||
Vector3 offset = transformSubmodule.eulerAnglesOffset.Sum();
|
||||
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + offset;
|
||||
transform.localEulerAngles = transformSubmodule.currentEulerAngles;
|
||||
transformSubmodule.eulerAnglesDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.eulerAnglesOffset.Clear();
|
||||
}
|
||||
|
||||
if (transformSubmodule.positionDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 posOffset in transformSubmodule.positionOffset)
|
||||
{
|
||||
offset += posOffset;
|
||||
}
|
||||
|
||||
Vector3 offset = transformSubmodule.positionOffset.Sum();
|
||||
transformSubmodule.currentPosition = transformSubmodule.originalPosition + offset;
|
||||
transform.localPosition = transformSubmodule.currentPosition;
|
||||
transformSubmodule.positionDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.positionOffset.Clear();
|
||||
}
|
||||
|
||||
if (willRefresh)
|
||||
{
|
||||
this.Refresh();
|
||||
Refresh();
|
||||
}
|
||||
|
||||
transformSubmodule.eulerAnglesOffset.Clear();
|
||||
transformSubmodule.positionOffset.Clear();
|
||||
|
||||
|
||||
}).AddTo(gameObject);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ namespace Ichni.RhythmGame
|
||||
public string backgroundSpriteName;
|
||||
public Sprite backgroundSprite;
|
||||
|
||||
[FormerlySerializedAs("skyboxController")] public SkyboxSubsetter skyboxSubsetter;
|
||||
public SkyboxSubsetter skyboxSubsetter;
|
||||
|
||||
public static BackgroundSetter GenerateElement(string elementName, Guid id, List<string> tags,
|
||||
bool isFirstGenerated, GameElement parentElement, bool useSkybox, string skyboxThemeBundleName,
|
||||
|
||||
8
Assets/Scripts/Extensions.meta
Normal file
8
Assets/Scripts/Extensions.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b6c5f364054b8346947b90f3115c8e2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,58 +1,58 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 自定义曲线预设
|
||||
/// </summary>
|
||||
public static class CustomCurvePresets
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 瞬间完成
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AnimationCurve Instant()
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[2];
|
||||
keys[0] = new Keyframe(0, 1, 0, 0);
|
||||
keys[1] = new Keyframe(1, 1, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛物线曲线,在中间达到最大值,两端为起始值
|
||||
/// </summary>
|
||||
/// <param name="totalTime">总时间</param>
|
||||
/// <param name="startValue">起始(和结束)值</param>
|
||||
/// <param name="peakValue">中点最大值</param>
|
||||
public static AnimationCurve Parabolic(float totalTime, float startValue, float peakValue)
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[3];
|
||||
keys[0] = new Keyframe(0, startValue, 0, 0);
|
||||
keys[1] = new Keyframe(totalTime / 2, peakValue, 0, 0);
|
||||
keys[2] = new Keyframe(totalTime, startValue, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义峰值点位置的抛物线曲线,在指定时间点达到最大值,两端为起始值
|
||||
/// </summary>
|
||||
/// <param name="totalTime">总时间</param>
|
||||
/// <param name="startValue">起始(和结束)值</param>
|
||||
/// <param name="peakValue">最大值</param>
|
||||
/// <param name="peakTimePercent">最大值的比例点</param>
|
||||
/// <returns></returns>
|
||||
public static AnimationCurve CustomPeakTimeParabolic(float totalTime, float startValue, float peakValue, float peakTimePercent)
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[3];
|
||||
keys[0] = new Keyframe(0, startValue, 0, 0);
|
||||
keys[1] = new Keyframe(totalTime * peakTimePercent, peakValue, 0, 0);
|
||||
keys[2] = new Keyframe(totalTime, startValue, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
}
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 自定义曲线预设
|
||||
/// </summary>
|
||||
public static class CustomCurvePresets
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 瞬间完成
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public static AnimationCurve Instant()
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[2];
|
||||
keys[0] = new Keyframe(0, 1, 0, 0);
|
||||
keys[1] = new Keyframe(1, 1, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 抛物线曲线,在中间达到最大值,两端为起始值
|
||||
/// </summary>
|
||||
/// <param name="totalTime">总时间</param>
|
||||
/// <param name="startValue">起始(和结束)值</param>
|
||||
/// <param name="peakValue">中点最大值</param>
|
||||
public static AnimationCurve Parabolic(float totalTime, float startValue, float peakValue)
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[3];
|
||||
keys[0] = new Keyframe(0, startValue, 0, 0);
|
||||
keys[1] = new Keyframe(totalTime / 2, peakValue, 0, 0);
|
||||
keys[2] = new Keyframe(totalTime, startValue, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 自定义峰值点位置的抛物线曲线,在指定时间点达到最大值,两端为起始值
|
||||
/// </summary>
|
||||
/// <param name="totalTime">总时间</param>
|
||||
/// <param name="startValue">起始(和结束)值</param>
|
||||
/// <param name="peakValue">最大值</param>
|
||||
/// <param name="peakTimePercent">最大值的比例点</param>
|
||||
/// <returns></returns>
|
||||
public static AnimationCurve CustomPeakTimeParabolic(float totalTime, float startValue, float peakValue, float peakTimePercent)
|
||||
{
|
||||
Keyframe[] keys = new Keyframe[3];
|
||||
keys[0] = new Keyframe(0, startValue, 0, 0);
|
||||
keys[1] = new Keyframe(totalTime * peakTimePercent, peakValue, 0, 0);
|
||||
keys[2] = new Keyframe(totalTime, startValue, 0, 0);
|
||||
return new AnimationCurve(keys);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
Assets/Scripts/Extensions/ListExtension.cs
Normal file
12
Assets/Scripts/Extensions/ListExtension.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ListExtension
|
||||
{
|
||||
public static Vector3 Sum(this List<Vector3> list)
|
||||
{
|
||||
return list.Aggregate(Vector3.zero, (current, addition) => current + addition);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Extensions/ListExtension.cs.meta
Normal file
11
Assets/Scripts/Extensions/ListExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 62a89393607258a4c858b3bfede996ce
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
28
Assets/Scripts/Extensions/ShaderExtension.cs
Normal file
28
Assets/Scripts/Extensions/ShaderExtension.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class ShaderExtension
|
||||
{
|
||||
/// <summary>
|
||||
/// 对于从AssetBundle中加载的材质,修改Shader参数可能会出现异常情况。
|
||||
/// 此时需要在生成物体的时候,重新初始化Shader。
|
||||
/// </summary>
|
||||
public static void InitializeShader(this Renderer renderer)
|
||||
{
|
||||
foreach (Material material in renderer.materials)
|
||||
{
|
||||
string shaderName = material.shader.name;
|
||||
Shader shader = Shader.Find(shaderName);
|
||||
|
||||
if (shader != null)
|
||||
{
|
||||
material.shader = shader;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning($"Shader '{shaderName}' not found for material '{material.name}' on renderer '{renderer.name}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Extensions/ShaderExtension.cs.meta
Normal file
11
Assets/Scripts/Extensions/ShaderExtension.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b74e31a7b06bb9743b629a923718f2c2
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -120,6 +120,7 @@ namespace Ichni
|
||||
AssetBundle bundle = AssetBundle.LoadFromFile(uri);
|
||||
Object[] ob = bundle.LoadAllAssets<Object>();
|
||||
loadedThemeBundleList.Add(new ThemeBundle(themeBundleName));
|
||||
|
||||
for (int i = 0; i < ob.Length; i++)
|
||||
{
|
||||
if (ob[i].GetType() == typeof(GameObject))
|
||||
|
||||
Reference in New Issue
Block a user