perf
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
using UniRx;
|
||||
using UniRx.Triggers;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Ichni.RhythmGame
|
||||
@@ -20,6 +24,8 @@ namespace Ichni.RhythmGame
|
||||
|
||||
public bool baseColorDirtyMark;
|
||||
public bool emissionColorDirtyMark;
|
||||
|
||||
public IDisposable observer;
|
||||
|
||||
public Color GetCurrentEmissionColor()
|
||||
{
|
||||
@@ -50,27 +56,6 @@ namespace Ichni.RhythmGame
|
||||
}
|
||||
}
|
||||
|
||||
public ColorSubmodule(GameElement attachedGameElement, Color originalBaseColor) : base(attachedGameElement)
|
||||
{
|
||||
this.originalBaseColor = originalBaseColor;
|
||||
this.emissionEnabled = false;
|
||||
this.originalEmissionColor = Color.black;
|
||||
this.originalEmissionIntensity = 0;
|
||||
|
||||
this.currentBaseColor = originalBaseColor;
|
||||
this.currentEmissionColor = Color.black;
|
||||
this.currentEmissionIntensity = 0;
|
||||
|
||||
this.baseColorDirtyMark = false;
|
||||
this.emissionColorDirtyMark = false;
|
||||
|
||||
if (!HaveSameSubmodule)
|
||||
{
|
||||
(attachedGameElement as IHaveColorSubmodule).colorSubmodule = this;
|
||||
(attachedGameElement as IHaveColorSubmodule).SetColorObserver();
|
||||
}
|
||||
}
|
||||
|
||||
public ColorSubmodule(GameElement attachedGameElement, Color originalBaseColor, bool emissionEnabled,
|
||||
Color originalEmissionColor, float originalEmissionIntensity) : base(attachedGameElement)
|
||||
{
|
||||
@@ -106,6 +91,17 @@ namespace Ichni.RhythmGame
|
||||
baseColorDirtyMark = true;
|
||||
emissionColorDirtyMark = true;
|
||||
}
|
||||
|
||||
private bool HaveAnimation() => attachedGameElement.childElementList
|
||||
.Any(element => element is BaseColorChange or EmissionColorChange);
|
||||
|
||||
public override void CheckAndRemoveObservers()
|
||||
{
|
||||
if (!HaveAnimation())
|
||||
{
|
||||
observer?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IHaveColorSubmodule
|
||||
@@ -115,36 +111,38 @@ namespace Ichni.RhythmGame
|
||||
|
||||
public void SetColorObserver()
|
||||
{
|
||||
GameElement attachedGameElement = colorSubmodule.attachedGameElement;
|
||||
colorSubmodule.observer = Observable.EveryUpdate()
|
||||
.Subscribe(_ => UpdateColor())
|
||||
.AddTo(colorSubmodule.attachedGameElement);
|
||||
}
|
||||
|
||||
Observable.EveryUpdate().Subscribe(_ =>
|
||||
public void UpdateColor()
|
||||
{
|
||||
if (!GameManager.instance.audioManager.isUpdating)
|
||||
{
|
||||
if (!GameManager.instance.audioManager.isUpdating || colorSubmodule == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
bool willRefresh = false;
|
||||
bool willRefresh = false;
|
||||
|
||||
if (colorSubmodule.baseColorDirtyMark)
|
||||
{
|
||||
//在动画物体中改变currentColor
|
||||
colorSubmodule.baseColorDirtyMark = false;
|
||||
willRefresh = true;
|
||||
}
|
||||
if (colorSubmodule.baseColorDirtyMark)
|
||||
{
|
||||
//在动画物体中改变currentColor
|
||||
colorSubmodule.baseColorDirtyMark = false;
|
||||
willRefresh = true;
|
||||
}
|
||||
|
||||
if (colorSubmodule.emissionColorDirtyMark)
|
||||
{
|
||||
//在动画物体中改变currentColor
|
||||
colorSubmodule.emissionColorDirtyMark = false;
|
||||
willRefresh = true;
|
||||
}
|
||||
if (colorSubmodule.emissionColorDirtyMark)
|
||||
{
|
||||
//在动画物体中改变currentColor
|
||||
colorSubmodule.emissionColorDirtyMark = false;
|
||||
willRefresh = true;
|
||||
}
|
||||
|
||||
if (willRefresh)
|
||||
{
|
||||
attachedGameElement.Refresh();
|
||||
}
|
||||
}).AddTo(attachedGameElement);
|
||||
if (willRefresh)
|
||||
{
|
||||
colorSubmodule.attachedGameElement.Refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
effectCollection.Add("Generate", new List<EffectBase>());
|
||||
effectCollection.Add("GeneralJudge", new List<EffectBase>());
|
||||
effectCollection.Add("StartHold", new List<EffectBase>()); //仅用于Hold
|
||||
effectCollection.Add("Holding", new List<EffectBase>()); //仅用于Hold
|
||||
effectCollection.Add("Perfect", new List<EffectBase>());
|
||||
effectCollection.Add("Good", new List<EffectBase>());
|
||||
|
||||
@@ -50,6 +50,11 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public virtual void CheckAndRemoveObservers()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace Beatmap
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Ichni.RhythmGame.Beatmap;
|
||||
using UniRx;
|
||||
using UniRx.Triggers;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
namespace Ichni.RhythmGame
|
||||
{
|
||||
@@ -13,19 +17,21 @@ namespace Ichni.RhythmGame
|
||||
public Vector3 originalEulerAngles;
|
||||
public Vector3 originalScale;
|
||||
|
||||
public List<Vector3> positionOffset;
|
||||
public List<Vector3> eulerAnglesOffset;
|
||||
public List<Vector3> scaleOffset;
|
||||
public Vector3 positionOffset;
|
||||
public Vector3 eulerAnglesOffset;
|
||||
public Vector3 scaleOffset;
|
||||
|
||||
public Vector3 currentPosition;
|
||||
public Vector3 currentEulerAngles;
|
||||
public Vector3 currentScale;
|
||||
|
||||
|
||||
public bool positionDirtyMark;
|
||||
public bool eulerAnglesDirtyMark;
|
||||
public bool scaleDirtyMark;
|
||||
|
||||
public bool eulerAnglesOffsetLock;
|
||||
|
||||
public IDisposable observer;
|
||||
|
||||
public TransformSubmodule(GameElement attachedGameElement) : base(attachedGameElement)
|
||||
{
|
||||
@@ -33,14 +39,14 @@ namespace Ichni.RhythmGame
|
||||
this.originalEulerAngles = Vector3.zero;
|
||||
this.originalScale = Vector3.one;
|
||||
|
||||
positionOffset = new List<Vector3>();
|
||||
eulerAnglesOffset = new List<Vector3>();
|
||||
scaleOffset = new List<Vector3>();
|
||||
positionOffset = Vector3.zero;
|
||||
eulerAnglesOffset = Vector3.zero;
|
||||
scaleOffset = Vector3.zero;
|
||||
|
||||
currentPosition = Vector3.zero;
|
||||
currentEulerAngles = Vector3.zero;
|
||||
currentScale = Vector3.one;
|
||||
|
||||
|
||||
positionDirtyMark = true;
|
||||
eulerAnglesDirtyMark = true;
|
||||
scaleDirtyMark = true;
|
||||
@@ -61,14 +67,14 @@ namespace Ichni.RhythmGame
|
||||
this.originalEulerAngles = originalEulerAngles;
|
||||
this.originalScale = originalScale;
|
||||
|
||||
positionOffset = new List<Vector3>();
|
||||
eulerAnglesOffset = new List<Vector3>();
|
||||
scaleOffset = new List<Vector3>();
|
||||
positionOffset = Vector3.zero;
|
||||
eulerAnglesOffset = Vector3.zero;
|
||||
scaleOffset = Vector3.zero;
|
||||
|
||||
currentPosition = originalPosition;
|
||||
currentEulerAngles = originalEulerAngles;
|
||||
currentScale = originalScale;
|
||||
|
||||
|
||||
positionDirtyMark = true;
|
||||
eulerAnglesDirtyMark = true;
|
||||
scaleDirtyMark = true;
|
||||
@@ -97,6 +103,17 @@ namespace Ichni.RhythmGame
|
||||
eulerAnglesDirtyMark = true;
|
||||
scaleDirtyMark = true;
|
||||
}
|
||||
|
||||
private bool HaveAnimation() => attachedGameElement.childElementList
|
||||
.Any(element => element is Displacement or Swirl or Scale or LookAt);
|
||||
|
||||
public override void CheckAndRemoveObservers()
|
||||
{
|
||||
if (!HaveAnimation())
|
||||
{
|
||||
observer?.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface IHaveTransformSubmodule
|
||||
@@ -109,69 +126,74 @@ namespace Ichni.RhythmGame
|
||||
/// </summary>
|
||||
public void SetTransformObserver()
|
||||
{
|
||||
GameElement attachedGameElement = transformSubmodule.attachedGameElement;
|
||||
transformSubmodule.observer = Observable.EveryUpdate()
|
||||
.Subscribe(_ => UpdateTransform())
|
||||
.AddTo(transformSubmodule.attachedGameElement);
|
||||
}
|
||||
|
||||
Observable.EveryUpdate().Subscribe(_ =>
|
||||
public void UpdateTransform()
|
||||
{
|
||||
if (!GameManager.instance.audioManager.isUpdating)
|
||||
{
|
||||
if (!GameManager.instance.audioManager.isUpdating || transformSubmodule == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
GameElement attachedGameElement = transformSubmodule.attachedGameElement;
|
||||
bool willRefresh = false;
|
||||
|
||||
if (transformSubmodule.scaleDirtyMark)
|
||||
{
|
||||
transformSubmodule.currentScale = transformSubmodule.originalScale + transformSubmodule.scaleOffset;
|
||||
attachedGameElement.transform.localScale = transformSubmodule.currentScale;
|
||||
transformSubmodule.scaleDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.scaleOffset = Vector3.zero;
|
||||
}
|
||||
|
||||
if (!transformSubmodule.eulerAnglesOffsetLock && transformSubmodule.eulerAnglesDirtyMark)
|
||||
{
|
||||
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + transformSubmodule.eulerAnglesOffset;
|
||||
attachedGameElement.transform.localEulerAngles = transformSubmodule.currentEulerAngles;
|
||||
transformSubmodule.eulerAnglesDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.eulerAnglesOffset = Vector3.zero;
|
||||
}
|
||||
|
||||
if (transformSubmodule.positionDirtyMark)
|
||||
{
|
||||
transformSubmodule.currentPosition = transformSubmodule.originalPosition + transformSubmodule.positionOffset;
|
||||
attachedGameElement.transform.localPosition = transformSubmodule.currentPosition;
|
||||
transformSubmodule.positionDirtyMark = false;
|
||||
willRefresh = true;
|
||||
transformSubmodule.positionOffset = Vector3.zero;
|
||||
}
|
||||
|
||||
bool willRefresh = false;
|
||||
if(willRefresh)
|
||||
{
|
||||
attachedGameElement.Refresh();
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdateLookAt(LookAt lookAt) // 处理LookAt
|
||||
{
|
||||
Transform target = lookAt.lookAtObject.transform;
|
||||
Transform self = transformSubmodule.attachedGameElement.transform;
|
||||
|
||||
if (transformSubmodule.eulerAnglesOffsetLock && transformSubmodule.eulerAnglesDirtyMark)
|
||||
{
|
||||
Vector3 lookingDirection = (target.position - self.position).normalized;
|
||||
|
||||
if (transformSubmodule.scaleDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 scaleOffset in transformSubmodule.scaleOffset)
|
||||
{
|
||||
offset += scaleOffset;
|
||||
}
|
||||
Vector3 eulerAnglesOffset = Quaternion.LookRotation(lookingDirection).eulerAngles;
|
||||
|
||||
transformSubmodule.currentScale = transformSubmodule.originalScale + offset;
|
||||
attachedGameElement.transform.localScale = transformSubmodule.currentScale;
|
||||
transformSubmodule.scaleDirtyMark = false;
|
||||
willRefresh = true;
|
||||
}
|
||||
|
||||
if (transformSubmodule.eulerAnglesDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 eulerOffset in transformSubmodule.eulerAnglesOffset)
|
||||
{
|
||||
offset += eulerOffset;
|
||||
}
|
||||
|
||||
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + offset;
|
||||
attachedGameElement.transform.localEulerAngles = transformSubmodule.currentEulerAngles;
|
||||
transformSubmodule.eulerAnglesDirtyMark = false;
|
||||
willRefresh = true;
|
||||
}
|
||||
|
||||
if (transformSubmodule.positionDirtyMark)
|
||||
{
|
||||
Vector3 offset = Vector3.zero;
|
||||
foreach (Vector3 posOffset in transformSubmodule.positionOffset)
|
||||
{
|
||||
offset += posOffset;
|
||||
}
|
||||
|
||||
transformSubmodule.currentPosition = transformSubmodule.originalPosition + offset;
|
||||
attachedGameElement.transform.localPosition = transformSubmodule.currentPosition;
|
||||
transformSubmodule.positionDirtyMark = false;
|
||||
willRefresh = true;
|
||||
}
|
||||
transformSubmodule.eulerAnglesOffset += eulerAnglesOffset;
|
||||
transformSubmodule.currentEulerAngles = transformSubmodule.originalEulerAngles + transformSubmodule.eulerAnglesOffset;
|
||||
|
||||
if(willRefresh)
|
||||
{
|
||||
attachedGameElement.Refresh();
|
||||
}
|
||||
self.localEulerAngles = transformSubmodule.currentEulerAngles;
|
||||
|
||||
transformSubmodule.scaleOffset.Clear();
|
||||
transformSubmodule.eulerAnglesOffset.Clear();
|
||||
transformSubmodule.positionOffset.Clear();
|
||||
|
||||
}).AddTo(attachedGameElement);
|
||||
transformSubmodule.eulerAnglesDirtyMark = false;
|
||||
transformSubmodule.eulerAnglesOffsetLock = false;
|
||||
transformSubmodule.eulerAnglesOffset = Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +222,7 @@ namespace Ichni.RhythmGame
|
||||
{
|
||||
attachedElement = GameElement_BM.GetElement(attachedElementGuid);
|
||||
|
||||
if(attachedElement == null)Debug.Log(attachedElementGuid);
|
||||
//if(attachedElement == null)Debug.Log(attachedElementGuid);
|
||||
|
||||
(attachedElement as IHaveTransformSubmodule).transformSubmodule = new TransformSubmodule(attachedElement, originalPosition, originalEulerAngles, originalScale);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user