From d454ea31df25ec2123820b5223d95ebd13c3e144 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Wed, 4 Oct 2023 19:37:29 +0200 Subject: [PATCH] Begun doing camera stuff --- Assets/Resources/Games/animalAcrobat.prefab | 37 +++++- .../Games/AnimalAcrobat/Elephant.prefab | 18 +-- .../Games/AnimalAcrobat/AcrobatObstacle.cs | 7 +- .../Games/AnimalAcrobat/AnimalAcrobat.cs | 108 +++++++++++++++++- .../Games/AnimalAcrobat/GiraffeInput.cs | 2 +- 5 files changed, 146 insertions(+), 26 deletions(-) diff --git a/Assets/Resources/Games/animalAcrobat.prefab b/Assets/Resources/Games/animalAcrobat.prefab index 0fa9931d1..1fe04713f 100644 --- a/Assets/Resources/Games/animalAcrobat.prefab +++ b/Assets/Resources/Games/animalAcrobat.prefab @@ -931,7 +931,7 @@ Transform: m_Children: - {fileID: 8794133928851332470} m_Father: {fileID: 5840730152797502065} - m_RootOrder: 3 + m_RootOrder: 4 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!212 &8577280407175396528 SpriteRenderer: @@ -1017,6 +1017,7 @@ Transform: - {fileID: 2661844662320053337} - {fileID: 4037202497222682790} - {fileID: 4618914047223908314} + - {fileID: 6038557817912069913} - {fileID: 4131922717252530528} m_Father: {fileID: 0} m_RootOrder: 0 @@ -1040,3 +1041,37 @@ MonoBehaviour: _giraffe: {fileID: 5248028064811562821, guid: 72e69b6337a6bc04f86ffcf5bcedab92, type: 3} _monkeysLong: {fileID: -3114631264593203074, guid: f52ef60e472be3047bb77f54d5a3229d, type: 3} _monkeysShort: {fileID: 7370747047491091311, guid: 0dfca7cb5fedf0d40aa26ffd9b4595ae, type: 3} + _scroll: {fileID: 6038557817912069913} + _jumpDistance: 8 + _jumpDistanceGiraffe: 32 +--- !u!1 &9154566379104488428 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6038557817912069913} + m_Layer: 0 + m_Name: Scroll + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6038557817912069913 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 9154566379104488428} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 5840730152797502065} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} diff --git a/Assets/Resources/Prefabs/Games/AnimalAcrobat/Elephant.prefab b/Assets/Resources/Prefabs/Games/AnimalAcrobat/Elephant.prefab index c49d442dd..426ae94c3 100644 --- a/Assets/Resources/Prefabs/Games/AnimalAcrobat/Elephant.prefab +++ b/Assets/Resources/Prefabs/Games/AnimalAcrobat/Elephant.prefab @@ -559,23 +559,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 2f9ee457016acdc4eb5dbfdc03be0d6f, type: 3} m_Name: m_EditorClassIdentifier: - _onInit: - m_PersistentCalls: - m_Calls: - - m_Target: {fileID: -4645702950898394595} - m_TargetAssemblyTypeName: HeavenStudio.Games.Scripts_AnimalAcrobat.ObstacleInput, - Assembly-CSharp - m_MethodName: Init - m_Mode: 0 - m_Arguments: - m_ObjectArgument: {fileID: 0} - m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine - m_IntArgument: 0 - m_FloatArgument: 0 - m_StringArgument: - m_BoolArgument: 0 - m_CallState: 2 - _fullRotRange: 120 + _fullRotRange: 160 _spawnOffset: 0 _holdLength: 2 _ease: 4 diff --git a/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs b/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs index 926981845..191bdf7e1 100644 --- a/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs +++ b/Assets/Scripts/Games/AnimalAcrobat/AcrobatObstacle.cs @@ -44,10 +44,15 @@ namespace HeavenStudio.Games.Scripts_AnimalAcrobat public float GetRotationDistance() { - float result = Mathf.Cos((_fullRotRange + 180) * Mathf.Deg2Rad) * _gripPoint.localPosition.y; + float result = Mathf.Cos((_fullRotRange + 180) * Mathf.Deg2Rad) * GetRotationHeight(); return Mathf.Abs(result * 2); } + public float GetRotationHeight() + { + return _gripPoint.localPosition.y; + } + private void Update() { var cond = Conductor.instance; diff --git a/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs b/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs index 2db63007d..0239da481 100644 --- a/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs +++ b/Assets/Scripts/Games/AnimalAcrobat/AnimalAcrobat.cs @@ -51,8 +51,13 @@ namespace HeavenStudio.Games [SerializeField] private AcrobatObstacle _elephant; [SerializeField] private AcrobatObstacle _giraffe, _monkeysLong, _monkeysShort; + [Header("Components")] + [SerializeField] private Transform _scroll; + [Header("Values")] [SerializeField] private float _jumpDistance = 8; + [SerializeField] private float _jumpDistanceGiraffe = 16; + [SerializeField] private float _jumpStartCameraDistance = 4; private List _pooledElephants = new(), _pooledGiraffes = new(), _pooledMonkeysLong = new(), _pooledMonkeysShort = new(); @@ -69,6 +74,20 @@ namespace HeavenStudio.Games public AnimalType type; public double startBeat; public double length; + public float rotationDistance; + public float rotationHeight; + + public double GetHoldLengthFromType() + { + return type switch + { + AnimalType.Elephant => 2, + AnimalType.Giraffe => 4, + AnimalType.MonkeysLong => 3, + AnimalType.MonkeysShort => 1, + _ => throw new System.NotImplementedException(), + }; + } } private List _queuedAnimals = new(); @@ -76,11 +95,18 @@ namespace HeavenStudio.Games private float _animalSummatedDistance = 0; private bool _lastAnimalWasGiraffe = false; + private Util.EasingFunction.Function _funcEaseInOut; + private Util.EasingFunction.Function _funcEaseIn; + private Util.EasingFunction.Function _funcEaseOut; + public static AnimalAcrobat instance; private void Awake() { instance = this; + _funcEaseInOut = Util.EasingFunction.GetEasingFunction(Util.EasingFunction.Ease.EaseInOutQuad); + _funcEaseIn = Util.EasingFunction.GetEasingFunction(Util.EasingFunction.Ease.EaseInQuad); + _funcEaseOut = Util.EasingFunction.GetEasingFunction(Util.EasingFunction.Ease.EaseOutQuad); } private void Update() @@ -88,6 +114,53 @@ namespace HeavenStudio.Games var cond = Conductor.instance; if (!cond.isPlaying) return; AnimalPoolUpdate(cond); + CameraUpdate(cond); + } + + private int _animalCameraIndex = 0; + private float _lastCameraX = 0; + private double _cameraHoldTime = 1; + + private void CameraUpdate(Conductor cond) + { + if (_animalCameraIndex >= _queuedAnimals.Count || cond.songPositionInBeatsAsDouble < _queuedAnimals[0].startBeat - 1) return; + + var currentAnimal = _queuedAnimals[_animalCameraIndex]; + + float distance = (_animalCameraIndex == 0) ? _jumpStartCameraDistance : _jumpDistance; + + float normalizedHold = cond.GetPositionFromBeat(currentAnimal.startBeat, currentAnimal.GetHoldLengthFromType()); + + if (normalizedHold < 0) + { + float normalizedTravel = cond.GetPositionFromBeat(currentAnimal.startBeat - _cameraHoldTime, _cameraHoldTime); + + float newX = Mathf.Lerp(_lastCameraX, _lastCameraX + distance, normalizedTravel); + _scroll.localPosition = new Vector3(-newX, 0, 0); + + return; + } + if (normalizedHold >= 0 && normalizedHold <= 1) + { + float newX = _funcEaseInOut(_lastCameraX + distance, _lastCameraX + distance + currentAnimal.rotationDistance, normalizedHold); + float newY = 0; + if (normalizedHold <= 0.5) + { + float normalizedHoldIn = cond.GetPositionFromBeat(currentAnimal.startBeat, currentAnimal.GetHoldLengthFromType() * 0.5); + newY = _funcEaseIn(0, -currentAnimal.rotationHeight, Mathf.Clamp01(normalizedHoldIn)); + } + else + { + float normalizedHoldOut = cond.GetPositionFromBeat(currentAnimal.startBeat + (currentAnimal.GetHoldLengthFromType() * 0.5), currentAnimal.GetHoldLengthFromType() * 0.5); + newY = _funcEaseOut(-currentAnimal.rotationHeight, 0, Mathf.Clamp01(normalizedHoldOut)); + } + + _scroll.localPosition = new Vector3(-newX, newY, 0); + return; + } + _cameraHoldTime = (currentAnimal.type == AnimalType.Giraffe) ? 4 : 2; + _lastCameraX += distance + currentAnimal.rotationDistance; + _animalCameraIndex++; } private void AnimalPoolUpdate(Conductor cond) @@ -135,7 +208,8 @@ namespace HeavenStudio.Games animal.Init(currentAnimal.startBeat, expBeat, _lastAnimalWasGiraffe); animal.transform.localPosition = new Vector3(_animalSummatedDistance, 0, 0); - _animalSummatedDistance += animal.GetRotationDistance() + _jumpDistance; + + _animalSummatedDistance += animal.GetRotationDistance() + ((currentAnimal.type == AnimalType.Giraffe) ? _jumpDistanceGiraffe : _jumpDistance); _lastAnimalWasGiraffe = currentAnimal.type == AnimalType.Giraffe; _animalPoolIndex++; @@ -155,10 +229,10 @@ namespace HeavenStudio.Games { for (int i = 0; i < POOL_NUMBER; i++) { - _pooledElephants.Add(Instantiate(_elephant, transform)); - _pooledGiraffes.Add(Instantiate(_giraffe, transform)); - _pooledMonkeysLong.Add(Instantiate(_monkeysLong, transform)); - _pooledMonkeysShort.Add(Instantiate(_monkeysShort, transform)); + _pooledElephants.Add(Instantiate(_elephant, _scroll)); + _pooledGiraffes.Add(Instantiate(_giraffe, _scroll)); + _pooledMonkeysLong.Add(Instantiate(_monkeysLong, _scroll)); + _pooledMonkeysShort.Add(Instantiate(_monkeysShort, _scroll)); } var allGameSwitches = EventCaller.GetAllInGameManagerList("gameManager", new string[] { "switchGame" }).FindAll(x => x.beat > beat); @@ -170,6 +244,7 @@ namespace HeavenStudio.Games "elephant", "giraffe", "monkeys", "monkeyLong", "monkeyShort" }).FindAll(x => x.beat >= beat && x.beat < nextGameSwitchBeat); if (allAnimals.Count == 0) return; + allAnimals.Sort((x, y) => x.beat.CompareTo(y.beat)); double goodBeat = allAnimals[0].beat; for (int i = 0; i < allAnimals.Count; i++) @@ -185,12 +260,16 @@ namespace HeavenStudio.Games startBeat = animal.beat, length = 5, type = AnimalType.MonkeysLong, + rotationDistance = _monkeysLong.GetRotationDistance(), + rotationHeight = _monkeysLong.GetRotationHeight() }); _queuedAnimals.Add(new QueuedAnimal() { startBeat = animal.beat + 5, length = 3, type = AnimalType.MonkeysShort, + rotationDistance = _monkeysShort.GetRotationDistance(), + rotationHeight = _monkeysShort.GetRotationHeight() }); continue; } @@ -213,16 +292,33 @@ namespace HeavenStudio.Games "animalAcrobat/monkeyShort" => AnimalType.MonkeysShort, _ => throw new System.NotImplementedException() }, + rotationDistance = animal.datamodel switch + { + "animalAcrobat/elephant" => _elephant.GetRotationDistance(), + "animalAcrobat/giraffe" => _giraffe.GetRotationDistance(), + "animalAcrobat/monkeyLong" => _monkeysLong.GetRotationDistance(), + "animalAcrobat/monkeyShort" => _monkeysShort.GetRotationDistance(), + _ => throw new System.NotImplementedException() + }, + rotationHeight = animal.datamodel switch + { + "animalAcrobat/elephant" => _elephant.GetRotationHeight(), + "animalAcrobat/giraffe" => _giraffe.GetRotationHeight(), + "animalAcrobat/monkeyLong" => _monkeysLong.GetRotationHeight(), + "animalAcrobat/monkeyShort" => _monkeysShort.GetRotationHeight(), + _ => throw new System.NotImplementedException() + } }); } if (_queuedAnimals.Count > 0) { - _queuedAnimals.Sort((x, y) => x.startBeat.CompareTo(y.startBeat)); for (int i = 0; i < POOL_NUMBER; i++) { BakeNextAvailableAnimal(); } + + SoundByte.PlayOneShotGame("animalAcrobat/start", _queuedAnimals[0].startBeat - 1); } } } diff --git a/Assets/Scripts/Games/AnimalAcrobat/GiraffeInput.cs b/Assets/Scripts/Games/AnimalAcrobat/GiraffeInput.cs index 0795359e3..aa653ee6d 100644 --- a/Assets/Scripts/Games/AnimalAcrobat/GiraffeInput.cs +++ b/Assets/Scripts/Games/AnimalAcrobat/GiraffeInput.cs @@ -22,7 +22,7 @@ namespace HeavenStudio.Games.Scripts_AnimalAcrobat private void OnDestroy() { - if (_drumRollSound != null) _drumRollSound.Stop(); + if (_drumRollSound != null) _drumRollSound.KillLoop(0.587); } public void Init(double beat, bool beforeGiraffe)