Big script cleanup. Remove the examples from Ropes' external package

This commit is contained in:
Michal Pikulski
2025-09-06 21:01:54 +02:00
parent 045bd7966e
commit d3c6b838b4
134 changed files with 719 additions and 26298 deletions

View File

@@ -0,0 +1,89 @@
using System;
using UnityEngine;
/// <summary>
/// Handles level switching when interacted with. Applies switch data and triggers scene transitions.
/// </summary>
public class LevelSwitch : MonoBehaviour
{
/// <summary>
/// Data for this level switch (target scene, icon, etc).
/// </summary>
public LevelSwitchData switchData;
/// <summary>
/// Renderer for the switch icon.
/// </summary>
public SpriteRenderer iconRenderer;
private Interactable interactable;
private bool _isActive = true;
/// <summary>
/// Unity Awake callback. Sets up icon, interactable, and event handlers.
/// </summary>
void Awake()
{
_isActive = true;
if (iconRenderer == null)
iconRenderer = GetComponent<SpriteRenderer>();
interactable = GetComponent<Interactable>();
if (interactable != null)
{
interactable.StartedInteraction += OnStartedInteraction;
}
ApplySwitchData();
}
/// <summary>
/// Unity OnDestroy callback. Cleans up event handlers.
/// </summary>
void OnDestroy()
{
if (interactable != null)
{
interactable.StartedInteraction -= OnStartedInteraction;
}
}
#if UNITY_EDITOR
/// <summary>
/// Unity OnValidate callback. Ensures icon and data are up to date in editor.
/// </summary>
void OnValidate()
{
if (iconRenderer == null)
iconRenderer = GetComponent<SpriteRenderer>();
ApplySwitchData();
}
#endif
/// <summary>
/// Applies the switch data to the level switch (icon, name, etc).
/// </summary>
public void ApplySwitchData()
{
if (switchData != null)
{
if (iconRenderer != null)
iconRenderer.sprite = switchData.mapSprite;
gameObject.name = switchData.targetLevelSceneName;
// Optionally update other fields, e.g. description
}
}
/// <summary>
/// Handles the start of an interaction (switches the level if active).
/// </summary>
private async void OnStartedInteraction()
{
Debug.Log($"LevelSwitch.OnInteracted: Switching to level {switchData?.targetLevelSceneName}");
if (switchData != null && !string.IsNullOrEmpty(switchData.targetLevelSceneName) && _isActive)
{
// Optionally: show loading UI here
var progress = new Progress<float>(p => Debug.Log($"Loading progress: {p * 100:F0}%"));
await SceneManagerService.Instance.SwitchSceneAsync(switchData.targetLevelSceneName, progress);
_isActive = false;
// Optionally: hide loading UI here
}
}
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 66cdab2e217c4c8388e2fc66da02f296
timeCreated: 1756733777

View File

@@ -0,0 +1,24 @@
using UnityEngine;
/// <summary>
/// ScriptableObject holding data for a level switch (scene name, description, icon).
/// </summary>
[CreateAssetMenu(fileName = "LevelSwitchData", menuName = "Game/Level Switch Data")]
public class LevelSwitchData : ScriptableObject
{
/// <summary>
/// The name of the target scene to switch to.
/// </summary>
public string targetLevelSceneName;
/// <summary>
/// Description of the level switch.
/// </summary>
[TextArea]
public string description;
/// <summary>
/// Icon to display for this level switch.
/// </summary>
public Sprite mapSprite;
}

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 451d08ffb9ed459db0f0473f2275743b
timeCreated: 1756733909