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