From 64f6b68ca1e05cde0d46f6032ad5a58fc7d6e5b5 Mon Sep 17 00:00:00 2001 From: Rapandrasmus <78219215+Rapandrasmus@users.noreply.github.com> Date: Thu, 25 Jan 2024 16:55:28 +0100 Subject: [PATCH] background rework --- Assets/Resources/Games/totemClimb.prefab | 65 +++++++++------ .../Games/TotemClimb/TCBackgroundManager.cs | 74 +++++++++++++++++ .../TotemClimb/TCBackgroundManager.cs.meta | 11 +++ .../Games/TotemClimb/TCPillarManager.cs | 79 +------------------ 4 files changed, 125 insertions(+), 104 deletions(-) create mode 100644 Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs create mode 100644 Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs.meta diff --git a/Assets/Resources/Games/totemClimb.prefab b/Assets/Resources/Games/totemClimb.prefab index 83953c44b..e84c48a60 100644 --- a/Assets/Resources/Games/totemClimb.prefab +++ b/Assets/Resources/Games/totemClimb.prefab @@ -6009,7 +6009,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 0 + m_IsActive: 1 --- !u!4 &5916087148675833463 Transform: m_ObjectHideFlags: 0 @@ -6017,9 +6017,9 @@ Transform: m_PrefabInstance: {fileID: 0} m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2819324293506729970} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 0, z: 15} - m_LocalScale: {x: 1, y: 1, z: 1} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -0.1272, y: -0.1899, z: 9} + m_LocalScale: {x: 0.01, y: 0.01, z: 1} m_ConstrainProportionsScale: 0 m_Children: - {fileID: 7088125737275763684} @@ -6032,8 +6032,8 @@ Transform: - {fileID: 7250382413331960117} - {fileID: 2570246928390889843} - {fileID: 6418936641992724766} - m_Father: {fileID: 6499924889799669646} - m_RootOrder: 3 + m_Father: {fileID: 2025892949459409451} + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &3055485254411662678 GameObject: @@ -18060,6 +18060,7 @@ GameObject: m_Component: - component: {fileID: 2025892949459409451} - component: {fileID: 1376725162411129830} + - component: {fileID: 2532346591759855258} m_Layer: 0 m_Name: backgroundbackground m_TagString: Untagged @@ -18075,10 +18076,11 @@ Transform: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 7643611464627975212} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} - m_LocalPosition: {x: 2.8, y: 1.7, z: -3} + m_LocalPosition: {x: 2.8, y: 1.7, z: 0} m_LocalScale: {x: 100, y: 100, z: 1} m_ConstrainProportionsScale: 0 - m_Children: [] + m_Children: + - {fileID: 5916087148675833463} m_Father: {fileID: 4304513864755659316} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -18134,6 +18136,35 @@ SpriteRenderer: m_WasSpriteAssigned: 1 m_MaskInteraction: 0 m_SpriteSortPoint: 0 +--- !u!114 &2532346591759855258 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 7643611464627975212} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 90e9c132b6e784648806d42dd19243a8, type: 3} + m_Name: + m_EditorClassIdentifier: + _objectsParent: {fileID: 5916087148675833463} + _objects: + - first: {fileID: 7088125737275763684} + second: {fileID: 3578614616298500996} + moveSpeed: 6 + - first: {fileID: 4120052851030622860} + second: {fileID: 2375492676405863283} + moveSpeed: 5 + - first: {fileID: 5685927704915689371} + second: {fileID: 7836447183238034407} + moveSpeed: 4 + - first: {fileID: 3212616479633791068} + second: {fileID: 7250382413331960117} + moveSpeed: 3 + - first: {fileID: 2570246928390889843} + second: {fileID: 6418936641992724766} + moveSpeed: 2 --- !u!1 &7783384560661561575 GameObject: m_ObjectHideFlags: 0 @@ -18773,7 +18804,6 @@ Transform: - {fileID: 9098506625303270995} - {fileID: 3318868258064954905} - {fileID: 1586514379553918595} - - {fileID: 5916087148675833463} m_Father: {fileID: 7036195930893080952} m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -18792,23 +18822,6 @@ MonoBehaviour: _pillarFirst: {fileID: 9098506625303270995} _pillarSecond: {fileID: 3318868258064954905} _pillarUp: {fileID: 1586514379553918595} - _backgroundObjectsParent: {fileID: 5916087148675833463} - _backgroundObjects: - - first: {fileID: 7088125737275763684} - second: {fileID: 3578614616298500996} - isCloud: 1 - - first: {fileID: 4120052851030622860} - second: {fileID: 2375492676405863283} - isCloud: 1 - - first: {fileID: 5685927704915689371} - second: {fileID: 7836447183238034407} - isCloud: 0 - - first: {fileID: 3212616479633791068} - second: {fileID: 7250382413331960117} - isCloud: 1 - - first: {fileID: 2570246928390889843} - second: {fileID: 6418936641992724766} - isCloud: 1 --- !u!1 &8860318310391524628 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs b/Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs new file mode 100644 index 000000000..2d142d0a0 --- /dev/null +++ b/Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs @@ -0,0 +1,74 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace HeavenStudio.Games.Scripts_TotemClimb +{ + public class TCBackgroundManager : MonoBehaviour + { + private const int BACKGROUND_OBJECT_AMOUNT = 18; + + [SerializeField] private Transform _objectsParent; + [SerializeField] private List _objects; + + private void Awake() + { + foreach (var o in _objects) + { + o.InitClones(_objectsParent); + } + } + + private void Update() + { + foreach (var o in _objects) + { + o.ScrollClones(); + } + } + + [System.Serializable] + private class BackgroundScrollPair + { + public Transform first; + public Transform second; + public float moveSpeed = 1.0f; + + private List _objects = new(); + private float _xDistance; + + private float GetDistance() + { + return second.localPosition.x - first.localPosition.x; + } + + public void InitClones(Transform parent) + { + _xDistance = GetDistance(); + _objects.Add(first); + _objects.Add(second); + + for (int i = 0; i < BACKGROUND_OBJECT_AMOUNT; i++) + { + Transform spawnedObject = Instantiate(first, parent); + spawnedObject.localPosition = new Vector3(second.localPosition.x + (_xDistance * (i + 1)), first.localPosition.y, first.localPosition.z); + _objects.Add(spawnedObject); + } + } + + public void ScrollClones() + { + foreach (var b in _objects) + { + b.localPosition += new Vector3(-Time.deltaTime * moveSpeed, 0); + + if (b.localPosition.x <= _xDistance * -BACKGROUND_OBJECT_AMOUNT / 2) + { + b.localPosition = new Vector3(_xDistance * BACKGROUND_OBJECT_AMOUNT / 2, b.localPosition.y, b.localPosition.z); + } + } + } + } + } +} + diff --git a/Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs.meta b/Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs.meta new file mode 100644 index 000000000..545d91e86 --- /dev/null +++ b/Assets/Scripts/Games/TotemClimb/TCBackgroundManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 90e9c132b6e784648806d42dd19243a8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Games/TotemClimb/TCPillarManager.cs b/Assets/Scripts/Games/TotemClimb/TCPillarManager.cs index 369b1f5be..0e247e4a6 100644 --- a/Assets/Scripts/Games/TotemClimb/TCPillarManager.cs +++ b/Assets/Scripts/Games/TotemClimb/TCPillarManager.cs @@ -10,15 +10,12 @@ namespace HeavenStudio.Games.Scripts_TotemClimb { private const int PILLAR_AMOUNT_X = 12; private const int PILLAR_AMOUNT_Y = 3; - private const int BACKGROUND_OBJECT_AMOUNT = 10; - private const float CLOUD_MOVE_SPEED = 0.75f; + [Header("Components")] [SerializeField] private Transform _pillarFirst; [SerializeField] private Transform _pillarSecond; [SerializeField] private Transform _pillarUp; - [SerializeField] private Transform _backgroundObjectsParent; - [SerializeField] private List _backgroundObjects; private List> _pillars = new(); @@ -82,27 +79,11 @@ namespace HeavenStudio.Games.Scripts_TotemClimb } } } - - if (_endDistanceSet) - { - _backgroundObjectsParent.gameObject.SetActive(true); - _backgroundObjectsParent.localPosition = new Vector3(0, _endDistance); - - foreach (var b in _backgroundObjects) - { - b.InitClones(_backgroundObjectsParent); - } - } } private void Update() { PillarUpdate(); - if (!_endDistanceSet) return; - foreach (var b in _backgroundObjects) - { - b.ScrollClones(_scrollTransform.localPosition.x); - } } private void PillarUpdate() @@ -170,64 +151,6 @@ namespace HeavenStudio.Games.Scripts_TotemClimb _endDistanceSet = true; return allPillarEnds[0].beat - startBeat; } - - [System.Serializable] - private class BackgroundScrollPair - { - public Transform first; - public Transform second; - public bool isCloud; - - private List _objects = new(); - - private int _index = 0; - - private float _startX; - private float _xDistance; - private float _moveX; - - private float GetDistance() - { - return second.localPosition.x - first.localPosition.x; - } - - public void InitClones(Transform parent) - { - _xDistance = GetDistance(); - _startX = first.localPosition.x; - _objects.Add(first); - _objects.Add(second); - - for (int i = 0; i < BACKGROUND_OBJECT_AMOUNT; i++) - { - Transform spawnedObject = Instantiate(first, parent); - spawnedObject.localPosition = new Vector3(second.localPosition.x + (_xDistance * (i + 1)), first.localPosition.y, first.localPosition.z); - _objects.Add(spawnedObject); - } - } - - public void ScrollClones(float currentScrollX) - { - if (isCloud) - { - foreach (var b in _objects) - { - b.localPosition += new Vector3(-Time.deltaTime * CLOUD_MOVE_SPEED, 0); - } - _moveX -= Time.deltaTime * CLOUD_MOVE_SPEED; - } - float currentDistanceX = _startX + (_xDistance * _index) + (_xDistance * (BACKGROUND_OBJECT_AMOUNT + 2) / 2) + _moveX; - - if (currentScrollX >= currentDistanceX) - { - var b = _objects[_index % BACKGROUND_OBJECT_AMOUNT]; - b.localPosition += new Vector3(_xDistance * BACKGROUND_OBJECT_AMOUNT, 0); - - _index++; - ScrollClones(currentScrollX); - } - } - } } }