Aimbot-ParallelEnv/Assets/Script/SceneBlocksSet.cs

133 lines
6.2 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using UnityEditor.PackageManager;
using UnityEngine;
/// <summary>
/// A ScriptableObject for storing and managing various sets of scene blocks.
/// </summary>
/// <remarks>
/// This class is responsible for organizing and initializing different sets of scene blocks,
/// which include levels, blocks, and their associated properties.
/// </remarks>
[CreateAssetMenu(menuName = "All Scene Prefab Set")]
public class SceneBlocksSet : ScriptableObject
{
public LevelsSet[] levels = new LevelsSet[3];
private GameObject hudObj;
private MessageBoxController messageBoxController;
/// <summary>
/// Initialize the scene block set.
/// </summary>
/// <param name="hudObj">The HUD object used to access the message box controller.</param>
public void InitializeSceneBlocksSet(GameObject hudObj)
{
this.hudObj = hudObj;
messageBoxController = this.hudObj.GetComponent<MessageBoxController>();
for (int i = 0; i < levels.Length; i++)
{
// initialize all level prefab set
levels[i].InitializeLevelsSet();
}
}
/// <summary>
/// Get all level prefab sets based on the target type.
/// </summary>
/// <param name="targetType">The target type to retrieve all level prefab sets for.</param>
/// <returns>All level prefab sets for the specified target type.</returns>
public LevelsSet GetAllLevlePrefabSet(SceneBlockContainer.Targets targetType)
{
switch (targetType)
{
case SceneBlockContainer.Targets.Go:
return levels[0];
case SceneBlockContainer.Targets.Attack:
return levels[1];
case SceneBlockContainer.Targets.Defence:
messageBoxController.PushMessage(new List<string> { "[ERROR]ScenePrefabSet.GetAllLevlePrefabSet:", " Defence Mode not ready!" },
new List<string> { messageBoxController.errorColor });
Debug.LogError("ScenePrefabSet.GetAllLevlePrefabSet:Defence Mode not ready!");
return levels[2];
default:
messageBoxController.PushMessage(new List<string> { "[ERROR]ScenePrefabSet.GetAllLevlePrefabSet:", " targetType not found!","tagetType = ",targetType.ToString() },
new List<string> { messageBoxController.errorColor });
Debug.LogError("ScenePrefabSet.GetAllLevlePrefabSet:targetType not found!");
return null;
}
}
/// <summary>
/// Get a single level prefab set based on the target type and level.
/// </summary>
/// <param name="targetType">The target type to retrieve the level prefab set for.</param>
/// <param name="level">The level to retrieve the level prefab set for.</param>
/// <returns>The single level prefab set for the specified target type and level.</returns>
public BlocksSet GetSingleLevelPrefabSet(SceneBlockContainer.Targets targetType, int level)
{
if(level >= GetAllLevlePrefabSet(targetType).singleLevelSet.Length)
{
messageBoxController.PushMessage(new List<string> { "[ERROR]ScenePrefabSet.GetSingleLevelPrefabSet:", " level out of range!","targetType = ",targetType.ToString(), "level = ",level.ToString()},
new List<string> { messageBoxController.errorColor });
Debug.LogError("ScenePrefabSet.GetSingleLevelPrefabSet:level out of range!");
return null;
}
return GetAllLevlePrefabSet(targetType).singleLevelSet[level];
}
/// <summary>
/// Get a prefab based on the target type, level, and block type.
/// </summary>
/// <param name="targetType">The target type to retrieve the prefab for.</param>
/// <param name="level">The level to retrieve the prefab for.</param>
/// <param name="blockType">The block type to retrieve the size information for.</param>
/// <returns>The prefab for the specified block.</returns>
public GameObject GetPrefab(SceneBlockContainer.Targets targetType, int level, int blockType)
{
if(blockType >= GetSingleLevelPrefabSet(targetType, level).prefabs.Length)
{
messageBoxController.PushMessage(new List<string> { "[ERROR]ScenePrefabSet.GetPrefab:", " blockType out of range!","targetType = ",targetType.ToString(), "level = ",level.ToString(), "blockType = ",blockType.ToString()},
new List<string> { messageBoxController.errorColor });
Debug.LogError("ScenePrefabSet.GetPrefab:blockType out of range!");
return null;
}
return GetSingleLevelPrefabSet(targetType, level).prefabs[blockType];
}
/// <summary>
/// Get the number of levels associated with a specific target type.
/// </summary>
/// <param name="targetType">The target type to retrieve level information for.</param>
/// <returns>The number of levels for the specified target type.</returns>
public int GetLevelNumber(SceneBlockContainer.Targets targetType)
{
return GetAllLevlePrefabSet(targetType).singleLevelSet.Length;
}
/// <summary>
/// Get the number of blocks associated with a specific target type and level.
/// </summary>
/// <param name="targetType">The target type to retrieve block information for.</param>
/// <param name="level">The level to retrieve block information for.</param>
/// <returns>The number of blocks for the specified target type and level.</returns>
public int GetBlockNumber(SceneBlockContainer.Targets targetType, int level)
{
return GetSingleLevelPrefabSet(targetType, level).prefabs.Length;
}
/// <summary>
/// Get the size of a block associated with a specific target type, level, and block type.
/// </summary>
/// <param name="targetType">The target type to retrieve block size information for.</param>
/// <param name="level">The level to retrieve block size information for.</param>
/// <param name="blockType">The type of block to retrieve size information for.</param>
/// <returns>The size of the specified block.</returns>
public float GetBlockSize(SceneBlockContainer.Targets targetType, int level, int blockType)
{
return GetPrefab(targetType, level, blockType).GetComponent<SceneBlock>().blockSize;
}
}