2025-01-26 21:10:16 -05:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Linq;
|
2025-02-08 02:31:39 -05:00
|
|
|
|
using Ichni.RhythmGame.Beatmap;
|
2025-01-26 21:10:16 -05:00
|
|
|
|
using UniRx;
|
|
|
|
|
|
using Unity.Mathematics;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.Events;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Ichni.RhythmGame
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TransformSubmodule : SubmoduleBase
|
|
|
|
|
|
{
|
|
|
|
|
|
public Vector3 originalPosition;
|
|
|
|
|
|
public Vector3 originalEulerAngles;
|
|
|
|
|
|
public Vector3 originalScale;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
public List<Vector3> positionOffset;
|
|
|
|
|
|
public List<Vector3> eulerAnglesOffset;
|
|
|
|
|
|
public List<Vector3> scaleOffset;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
public Vector3 currentPosition;
|
|
|
|
|
|
public Vector3 currentEulerAngles;
|
|
|
|
|
|
public Vector3 currentScale;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
public bool positionDirtyMark;
|
|
|
|
|
|
public bool eulerAnglesDirtyMark;
|
|
|
|
|
|
public bool scaleDirtyMark;
|
2025-01-29 23:49:18 -05:00
|
|
|
|
|
|
|
|
|
|
public bool eulerAnglesOffsetLock;
|
2025-01-26 21:10:16 -05:00
|
|
|
|
|
2025-02-08 02:31:39 -05:00
|
|
|
|
|
|
|
|
|
|
public TransformSubmodule(GameElement attachedGameElement) : base(attachedGameElement)
|
2025-01-29 23:49:18 -05:00
|
|
|
|
{
|
|
|
|
|
|
this.originalPosition = Vector3.zero;
|
|
|
|
|
|
this.originalEulerAngles = Vector3.zero;
|
|
|
|
|
|
this.originalScale = Vector3.one;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
positionOffset = new List<Vector3>();
|
|
|
|
|
|
eulerAnglesOffset = new List<Vector3>();
|
|
|
|
|
|
scaleOffset = new List<Vector3>();
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
currentPosition = Vector3.zero;
|
|
|
|
|
|
currentEulerAngles = Vector3.zero;
|
|
|
|
|
|
currentScale = Vector3.one;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
positionDirtyMark = false;
|
|
|
|
|
|
eulerAnglesDirtyMark = false;
|
|
|
|
|
|
scaleDirtyMark = false;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
eulerAnglesOffsetLock = false;
|
2025-02-08 02:31:39 -05:00
|
|
|
|
|
|
|
|
|
|
// (attachedGameElement as IHaveTransformSubmodule).SetTransformObserver();
|
2025-01-29 23:49:18 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-08 02:31:39 -05:00
|
|
|
|
public TransformSubmodule(GameElement attachedGameElement,
|
|
|
|
|
|
Vector3 originalPosition, Vector3 originalEulerAngles, Vector3 originalScale) : base(attachedGameElement)
|
2025-01-26 21:10:16 -05:00
|
|
|
|
{
|
|
|
|
|
|
this.originalPosition = originalPosition;
|
|
|
|
|
|
this.originalEulerAngles = originalEulerAngles;
|
|
|
|
|
|
this.originalScale = originalScale;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
positionOffset = new List<Vector3>();
|
|
|
|
|
|
eulerAnglesOffset = new List<Vector3>();
|
|
|
|
|
|
scaleOffset = new List<Vector3>();
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
currentPosition = originalPosition;
|
|
|
|
|
|
currentEulerAngles = originalEulerAngles;
|
|
|
|
|
|
currentScale = originalScale;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-26 21:10:16 -05:00
|
|
|
|
positionDirtyMark = false;
|
|
|
|
|
|
eulerAnglesDirtyMark = false;
|
|
|
|
|
|
scaleDirtyMark = false;
|
2025-01-30 22:45:33 -05:00
|
|
|
|
|
2025-01-29 23:49:18 -05:00
|
|
|
|
eulerAnglesOffsetLock = false;
|
2025-02-08 02:31:39 -05:00
|
|
|
|
|
|
|
|
|
|
// (attachedGameElement as IHaveTransformSubmodule).SetTransformObserver();
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|
2025-02-06 23:01:44 -05:00
|
|
|
|
|
|
|
|
|
|
public override void SaveBM()
|
|
|
|
|
|
{
|
2025-02-08 02:31:39 -05:00
|
|
|
|
matchedBM = new TransformSubmodule_BM(attachedGameElement);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public interface IHaveTransformSubmodule
|
|
|
|
|
|
{
|
|
|
|
|
|
TransformSubmodule transformSubmodule { get; set; }
|
|
|
|
|
|
|
2025-02-08 23:09:50 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 设置物体Transform的监听,顺序为Scale -> EulerAngles -> Position
|
|
|
|
|
|
/// 如果有一些特殊的物体(例如Camera,ElementFolder),需要自定义监听,可以重写这个方法
|
|
|
|
|
|
/// </summary>
|
2025-02-08 02:31:39 -05:00
|
|
|
|
public void SetTransformObserver()
|
|
|
|
|
|
{
|
|
|
|
|
|
GameElement attachedGameElement = transformSubmodule.attachedGameElement;
|
|
|
|
|
|
|
|
|
|
|
|
Observable.EveryUpdate().Subscribe(_ =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (transformSubmodule == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (transformSubmodule.scaleDirtyMark)
|
|
|
|
|
|
{
|
|
|
|
|
|
Vector3 offset = Vector3.zero;
|
|
|
|
|
|
foreach (Vector3 scaleOffset in transformSubmodule.scaleOffset)
|
|
|
|
|
|
{
|
|
|
|
|
|
offset += scaleOffset;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
transformSubmodule.currentScale = transformSubmodule.originalScale + offset;
|
|
|
|
|
|
attachedGameElement.transform.localScale = transformSubmodule.currentScale;
|
|
|
|
|
|
transformSubmodule.scaleDirtyMark = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
transformSubmodule.scaleOffset.Clear();
|
|
|
|
|
|
transformSubmodule.eulerAnglesOffset.Clear();
|
|
|
|
|
|
transformSubmodule.positionOffset.Clear();
|
|
|
|
|
|
}).AddTo(attachedGameElement);
|
2025-02-06 23:01:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
namespace Beatmap
|
|
|
|
|
|
{
|
|
|
|
|
|
public class TransformSubmodule_BM : Submodule_BM
|
|
|
|
|
|
{
|
|
|
|
|
|
public Vector3 originalPosition;
|
|
|
|
|
|
public Vector3 originalEulerAngles;
|
|
|
|
|
|
public Vector3 originalScale;
|
2025-02-08 02:31:39 -05:00
|
|
|
|
|
2025-02-06 23:01:44 -05:00
|
|
|
|
public TransformSubmodule_BM()
|
|
|
|
|
|
{
|
2025-02-08 02:31:39 -05:00
|
|
|
|
|
2025-02-06 23:01:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-08 02:31:39 -05:00
|
|
|
|
public TransformSubmodule_BM(GameElement attachedElement) : base(attachedElement)
|
2025-02-06 23:01:44 -05:00
|
|
|
|
{
|
2025-02-08 02:31:39 -05:00
|
|
|
|
TransformSubmodule transformSubmodule = (attachedElement as IHaveTransformSubmodule).transformSubmodule;
|
|
|
|
|
|
this.originalPosition = transformSubmodule.originalPosition;
|
|
|
|
|
|
this.originalEulerAngles = transformSubmodule.originalEulerAngles;
|
|
|
|
|
|
this.originalScale = transformSubmodule.originalScale;
|
2025-02-06 23:01:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void ExecuteBM()
|
|
|
|
|
|
{
|
2025-02-08 02:31:39 -05:00
|
|
|
|
attachedElement = GameElement_BM.GetElement(attachedElementGuid);
|
2025-02-08 23:09:50 -05:00
|
|
|
|
(attachedElement as IHaveTransformSubmodule).transformSubmodule = new TransformSubmodule(attachedElement, originalPosition, originalEulerAngles, originalScale);
|
|
|
|
|
|
attachedElement.submoduleList.Add((attachedElement as IHaveTransformSubmodule).transformSubmodule);
|
2025-02-06 23:01:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-08 02:31:39 -05:00
|
|
|
|
public override void DuplicateBM(GameElement attached)
|
2025-02-06 23:01:44 -05:00
|
|
|
|
{
|
2025-02-08 23:09:50 -05:00
|
|
|
|
(attached as IHaveTransformSubmodule).transformSubmodule = new TransformSubmodule(attached, originalPosition, originalEulerAngles, originalScale);
|
|
|
|
|
|
attached.submoduleList.Add((attached as IHaveTransformSubmodule).transformSubmodule);
|
2025-02-06 23:01:44 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-26 21:10:16 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|