background objects

This commit is contained in:
Rapandrasmus 2024-01-24 21:45:23 +01:00
parent 28d6351f63
commit dd615f8412
3 changed files with 1215 additions and 8 deletions

File diff suppressed because it is too large Load diff

View file

@ -155,7 +155,7 @@ TextureImporter:
width: 800 width: 800
height: 835 height: 835
alignment: 0 alignment: 0
pivot: {x: 0, y: 0} pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0} border: {x: 0, y: 0, z: 0, w: 0}
outline: [] outline: []
physicsShape: [] physicsShape: []
@ -167,6 +167,153 @@ TextureImporter:
indices: indices:
edges: [] edges: []
weights: [] weights: []
- serializedVersion: 2
name: backgroundtotem_0
rect:
serializedVersion: 2
x: 73
y: 1907
width: 76
height: 89
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 4c45eff50c51dd8498fe139c3a350e54
internalID: 592998762
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: trees
rect:
serializedVersion: 2
x: 56
y: 1348
width: 786
height: 462
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 9ffb650b04b53144999bf86d6b4aeea7
internalID: 1370341742
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: kingfisher
rect:
serializedVersion: 2
x: 994
y: 1495
width: 511
height: 311
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: a29ef75a1ecf93741aed0cf44237a322
internalID: -126723542
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: penguin
rect:
serializedVersion: 2
x: 1677
y: 1532
width: 400
height: 245
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 7437f138b4d32c14c9a0196636177b8a
internalID: -1297142145
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: whiteback
rect:
serializedVersion: 2
x: 35
y: 630
width: 475
height: 656
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 0b64cb60b2cbd3f48abb6344b65268ae
internalID: -67062240
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: bluback
rect:
serializedVersion: 2
x: 572
y: 630
width: 475
height: 654
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: c6549a304eda1724bb4ed685c0cdba3a
internalID: -413372245
vertices: []
indices:
edges: []
weights: []
- serializedVersion: 2
name: backgroundtotem_6
rect:
serializedVersion: 2
x: 1112
y: 639
width: 95
height: 88
alignment: 0
pivot: {x: 0.5, y: 0.5}
border: {x: 0, y: 0, z: 0, w: 0}
outline: []
physicsShape: []
tessellationDetail: 0
bones: []
spriteID: 38f1a12849b58a041b2027e520b28c38
internalID: -1889446420
vertices: []
indices:
edges: []
weights: []
outline: [] outline: []
physicsShape: [] physicsShape: []
bones: [] bones: []
@ -178,9 +325,16 @@ TextureImporter:
weights: [] weights: []
secondaryTextures: [] secondaryTextures: []
nameFileIdTable: nameFileIdTable:
backgroundtotem_0: 592998762
backgroundtotem_6: -1889446420
bluback: -413372245
ground: 1150890885 ground: 1150890885
kingfisher: -126723542
penguin: -1297142145
pillar: 589082449 pillar: 589082449
pillartop: 1905395231 pillartop: 1905395231
trees: 1370341742
whiteback: -67062240
spritePackingTag: spritePackingTag:
pSDRemoveMatte: 0 pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0 pSDShowRemoveMatteOption: 0

View file

@ -10,11 +10,15 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
{ {
private const int PILLAR_AMOUNT_X = 12; private const int PILLAR_AMOUNT_X = 12;
private const int PILLAR_AMOUNT_Y = 3; private const int PILLAR_AMOUNT_Y = 3;
private const int BACKGROUND_OBJECT_AMOUNT = 10;
[Header("Components")] [Header("Components")]
[SerializeField] private Transform _pillarFirst; [SerializeField] private Transform _pillarFirst;
[SerializeField] private Transform _pillarSecond; [SerializeField] private Transform _pillarSecond;
[SerializeField] private Transform _pillarUp; [SerializeField] private Transform _pillarUp;
[SerializeField] private Transform _backgroundObjectsParent;
[SerializeField] private List<BackgroundScrollPair> _backgroundObjects;
private List<List<Transform>> _pillars = new(); private List<List<Transform>> _pillars = new();
private Transform _scrollTransform; private Transform _scrollTransform;
@ -31,6 +35,8 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
private float _endDistance = float.MaxValue; private float _endDistance = float.MaxValue;
private bool _hasReachedEnd = false; private bool _hasReachedEnd = false;
private bool _endDistanceSet = false;
private void Awake() private void Awake()
{ {
_scrollTransform = transform.parent; _scrollTransform = transform.parent;
@ -58,7 +64,7 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
_pillarUp.GetChild(0).gameObject.SetActive(true); _pillarUp.GetChild(0).gameObject.SetActive(true);
} }
for (int i = 0; i < PILLAR_AMOUNT_Y; i++) for (int i = 0; i < PILLAR_AMOUNT_Y; i++)
{ {
if (_hasReachedEnd) break; if (_hasReachedEnd) break;
for (int j = 0; j < PILLAR_AMOUNT_X; j++) for (int j = 0; j < PILLAR_AMOUNT_X; j++)
@ -75,9 +81,30 @@ 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() private void Update()
{
PillarUpdate();
if (!_endDistanceSet) return;
foreach (var b in _backgroundObjects)
{
b.ScrollClones(_scrollTransform.localPosition.x);
}
}
private void PillarUpdate()
{ {
float currentScrollX = _scrollTransform.localPosition.x; float currentScrollX = _scrollTransform.localPosition.x;
float currentDistanceX = _pillarStartX + (_pillarDistanceX * _pillarIndexX); float currentDistanceX = _pillarStartX + (_pillarDistanceX * _pillarIndexX);
@ -92,7 +119,7 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
p.localPosition = new Vector3(p.localPosition.x + (_pillarDistanceX * PILLAR_AMOUNT_X), p.localPosition.y); p.localPosition = new Vector3(p.localPosition.x + (_pillarDistanceX * PILLAR_AMOUNT_X), p.localPosition.y);
} }
_pillarIndexX++; _pillarIndexX++;
Update(); PillarUpdate();
} }
if (_hasReachedEnd) return; if (_hasReachedEnd) return;
@ -115,7 +142,7 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
} }
_pillarIndexY++; _pillarIndexY++;
Update(); PillarUpdate();
} }
} }
@ -139,9 +166,57 @@ namespace HeavenStudio.Games.Scripts_TotemClimb
var allPillarEnds = EventCaller.GetAllInGameManagerList("totemClimb", new string[] { "above" }).FindAll(x => x.beat >= startBeat && x.beat < nextGameSwitchBeat); var allPillarEnds = EventCaller.GetAllInGameManagerList("totemClimb", new string[] { "above" }).FindAll(x => x.beat >= startBeat && x.beat < nextGameSwitchBeat);
if (allPillarEnds.Count == 0) return double.MaxValue; if (allPillarEnds.Count == 0) return double.MaxValue;
_endDistanceSet = true;
return allPillarEnds[0].beat - startBeat; return allPillarEnds[0].beat - startBeat;
} }
[System.Serializable]
private class BackgroundScrollPair
{
public Transform first;
public Transform second;
private List<Transform> _objects = new();
private int _index = 0;
private float _startX;
private float _xDistance;
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)
{
float currentDistanceX = _startX + (_xDistance * _index) + (_xDistance * (BACKGROUND_OBJECT_AMOUNT + 2) / 2);
if (currentScrollX >= currentDistanceX)
{
var b = _objects[_index % BACKGROUND_OBJECT_AMOUNT];
b.localPosition += new Vector3(_xDistance * BACKGROUND_OBJECT_AMOUNT, 0);
_index++;
ScrollClones(currentScrollX);
}
}
}
} }
} }