96 lines
3.7 KiB
C#
96 lines
3.7 KiB
C#
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
[CreateAssetMenu(menuName = "All Scene Prefab Set")]
|
||
|
public class SceneBlocksSet : ScriptableObject
|
||
|
{
|
||
|
public LevelsSet[] levels = new LevelsSet[3];
|
||
|
|
||
|
private GameObject hudObj;
|
||
|
private MessageBoxController messageBoxController;
|
||
|
|
||
|
// initialization
|
||
|
public void InitializeSceneBlocksSet(GameObject hudObj)
|
||
|
{
|
||
|
this.hudObj = hudObj;
|
||
|
messageBoxController = this.hudObj.GetComponent<MessageBoxController>();
|
||
|
for (int i = 0; i < 3; i++)
|
||
|
{
|
||
|
// initialize all level prefab set
|
||
|
levels[i].InitializeLevelsSet();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#region Get Scene,Level,Prefab methods
|
||
|
|
||
|
// get AllLevlePrefabSet by 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<string> { "[ERROR]ScenePrefabSet.GetAllLevlePrefabSet:", " Defence Mode not ready!" },
|
||
|
new List<string> { messageBoxController.errorColor });
|
||
|
return levels[2];
|
||
|
|
||
|
default:
|
||
|
messageBoxController.PushMessage(new List<string> { "[ERROR]ScenePrefabSet.GetAllLevlePrefabSet:", " targetType not found!","tagetType = ",targetType.ToString() },
|
||
|
new List<string> { messageBoxController.errorColor });
|
||
|
return null;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// get SingleLevelPrefabSet by target type and level
|
||
|
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 });
|
||
|
return null;
|
||
|
}
|
||
|
return GetAllLevlePrefabSet(targetType).singleLevelSet[level];
|
||
|
}
|
||
|
|
||
|
// get prefab by target type, level and block type
|
||
|
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 });
|
||
|
return null;
|
||
|
}
|
||
|
return GetSingleLevelPrefabSet(targetType, level).prefabs[blockType];
|
||
|
}
|
||
|
|
||
|
#endregion Get Scene,Level,Prefab methods
|
||
|
|
||
|
#region Get Prefab Property methods
|
||
|
|
||
|
//get level number by target type
|
||
|
public int GetLevelNumber(SceneBlockContainer.Targets targetType)
|
||
|
{
|
||
|
return GetAllLevlePrefabSet(targetType).singleLevelSet.Length;
|
||
|
}
|
||
|
|
||
|
// get block number by target type and level
|
||
|
public int GetBlockNumber(SceneBlockContainer.Targets targetType, int level)
|
||
|
{
|
||
|
return GetSingleLevelPrefabSet(targetType, level).prefabs.Length;
|
||
|
}
|
||
|
|
||
|
// get block size by target type and level and block type
|
||
|
public float GetBlockSize(SceneBlockContainer.Targets targetType, int level, int blockType)
|
||
|
{
|
||
|
return GetPrefab(targetType, level, blockType).GetComponent<SceneBlock>().blockSize;
|
||
|
}
|
||
|
|
||
|
#endregion Get Prefab Property methods
|
||
|
}
|