mirror of
https://github.com/RHeavenStudioPlus/HeavenStudioPlus.git
synced 2024-11-14 05:35:08 +00:00
ccfc528d99
* setup * scroll stuff * tons of stuff * totem bop * bopping and new assets * soem more * frog fit * fixed order of operation issue * triple proto * wow i love super curves * TRIPLE JUMP * frog fall * the spinny * dragon initial * functional dragon * fixed un bug * the deets * the deets have been fixed * miss stuff * smol fix * no log * fixed some issues * switch to next state * particle * remove useless logic * zoomed out * sound and line fix * new bg sheet * minor tweaks * pillar tops * background objects * background tweak * triple sound tweak * background rework * frog wings and new jump anim * fix * birds * disable pillars * landing end * fix again * minor fix * fixes and icon * background scroll logic rework * put in fixed sheet * fixed sounds
84 lines
2.6 KiB
C#
84 lines
2.6 KiB
C#
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<BackgroundScrollPair> _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<Transform> _objects = new();
|
|
private List<float> _objectOffsets = new();
|
|
private float _xDistance;
|
|
|
|
private float GetDistance()
|
|
{
|
|
return second.localPosition.x - first.localPosition.x;
|
|
}
|
|
|
|
public void InitClones(Transform parent)
|
|
{
|
|
_xDistance = GetDistance();
|
|
_objects.Add(first);
|
|
_objectOffsets.Add(first.localPosition.x);
|
|
_objects.Add(second);
|
|
_objectOffsets.Add(second.localPosition.x);
|
|
|
|
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);
|
|
_objectOffsets.Add(spawnedObject.localPosition.x);
|
|
}
|
|
}
|
|
|
|
public void ScrollClones()
|
|
{
|
|
for (int i = 0; i < _objects.Count; i++)
|
|
{
|
|
var b = _objects[i];
|
|
var bOffset = _objectOffsets[i];
|
|
float songPos = Conductor.instance.songPosition;
|
|
|
|
b.localPosition = new Vector3(bOffset - (songPos * moveSpeed), b.localPosition.y);
|
|
|
|
float fullDistance = (BACKGROUND_OBJECT_AMOUNT + 2) * _xDistance;
|
|
|
|
if (b.localPosition.x <= -fullDistance / 2)
|
|
{
|
|
_objectOffsets[i] = bOffset + fullDistance;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|