V3.4.1 整理script位置

This commit is contained in:
2023-10-15 02:16:43 +09:00
parent eabbb656cb
commit 86d6b41ed7
77 changed files with 43272 additions and 302 deletions
@@ -0,0 +1,28 @@
using System;
using UnityEngine;
/// <summary>
/// A ScriptableObject for storing a set of prefabs related to a single level.
/// </summary>
/// <remarks>
/// This class is used to manage a collection of prefabs that are associated with a single level.
/// It includes functionality to initialize and access the prefab set.
/// </remarks>
[CreateAssetMenu(menuName = "Single Level Prefab Set")]
public class BlocksSet : ScriptableObject
{
public GameObject[] prefabs;
[NonSerialized] public int prefabSize = 0;
/// <summary>
/// Initializes the prefab set.
/// </summary>
/// <remarks>
/// This method calculates and stores the size of the prefab set.
/// </remarks>
public void InitializeBlocksSet()
{
// get prefab size
prefabSize = prefabs.Length;
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: db8f30e5213a1754699f4eda49cb3e63
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,194 @@
using System;
using System.Collections.Generic;
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 targetLevels, blocks, and their associated properties.
/// </remarks>
[CreateAssetMenu(menuName = "All Scene Prefab Set")]
public class SceneBlocksSet : ScriptableObject
{
public TargetLevelsSet[] targetLevels = new TargetLevelsSet[3];
public Targets[] targets = new Targets[3];
private GameObject hudObj;
private MessageBoxController messageBoxController;
private bool isHudEnabled = false;
/// <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 = null)
{
if (hudObj != null)
{
isHudEnabled = true;
this.hudObj = hudObj;
messageBoxController = this.hudObj.GetComponent<MessageBoxController>();
}
for (int i = 0; i < targetLevels.Length; i++)
{
// initialize all level prefab set
targetLevels[i].InitializeLevelsSet();
}
}
/// <summary>
/// Gets all level prefab sets.
/// </summary>
/// <param name="targetType">The target type (optional).</param>
/// <param name="index">The index (optional).</param>
/// <returns>The level prefab sets.</returns>
/// <remarks>
/// If the target type (targetType) or index (index) is provided, it returns the corresponding level prefab set.
/// If neither the target type (targetType) nor the index (index) is provided, an exception will be thrown, and an error message will be logged.
/// </remarks>
public TargetLevelsSet GetAllLevlePrefabSet(Targets? targetType = null, int? index = null)
{
if (targetType == null && index == null)
{
PushSceneBlockMessages(new List<string> { "[ERROR]ScenePrefabSet.GetAllLevlePrefabSet:", " targetType or index not found!" },
new List<string> { messageBoxController.errorColor });
throw new ArgumentNullException("Both targetType and index cannot be null.");
}
int levelIndex = 0;
switch (targetType, index)
{
case (Targets type, null):
levelIndex = type.ToIndex();
break;
case (null, int i):
levelIndex = i;
break;
case (Targets type, int i):
levelIndex = type.ToIndex();
break;
default:
PushSceneBlockMessages(new List<string> { "[ERROR]ScenePrefabSet.GetAllLevlePrefabSet:", " targetType or index not found!" },
new List<string> { messageBoxController.errorColor });
break;
}
return targetLevels[levelIndex];
}
/// <summary>
/// Gets the prefab set for a single level.
/// </summary>
/// <param name="level">The level index.</param>
/// <param name="targetType">The target type (optional).</param>
/// <param name="index">The index (optional).</param>
/// <returns>The prefab set for a single level.</returns>
/// <remarks>
/// If the target type (targetType) or index (index) is provided, it returns the prefab set for the corresponding level.
/// If the level index is out of range, an exception will be thrown, and an error message will be logged.
/// </remarks>
public BlocksSet GetSingleLevelPrefabSet(int level, Targets? targetType = null, int? index = null)
{
if (level >= GetAllLevlePrefabSet(targetType, index).singleLevelSet.Length)
{
PushSceneBlockMessages(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, index).singleLevelSet[level];
}
/// <summary>
/// Gets a specific prefab for a given level, block type, target type, and index.
/// </summary>
/// <param name="level">The level index.</param>
/// <param name="blockType">The block type index.</param>
/// <param name="targetType">The target type (optional).</param>
/// <param name="index">The index (optional).</param>
/// <returns>The prefab object.</returns>
/// <remarks>
/// If the target type (targetType) or index (index) is provided, it returns the specific prefab for the given level, block type, target type, and index.
/// If the block type index is out of range, an exception will be thrown, and an error message will be logged.
/// </remarks>
public GameObject GetPrefab(int level, int blockType, Targets? targetType = null, int? index = null)
{
if (blockType >= GetSingleLevelPrefabSet(level, targetType, index).prefabs.Length)
{
PushSceneBlockMessages(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(level, targetType, index).prefabs[blockType];
}
/// <summary>
/// Gets the number of targetLevels for a specific target type and index.
/// </summary>
/// <param name="targetType">The target type (optional).</param>
/// <param name="index">The index (optional).</param>
/// <returns>The number of targetLevels.</returns>
/// <remarks>
/// If the target type (targetType) or index (index) is provided, it returns the number of targetLevels for the corresponding target type and index.
/// </remarks>
public int GetLevelNumber(Targets? targetType = null, int? index = null)
{
return GetAllLevlePrefabSet(targetType, index).singleLevelSet.Length;
}
/// <summary>
/// Gets the number of blocks for a specific level, target type, and index.
/// </summary>
/// <param name="level">The level index.</param>
/// <param name="targetType">The target type (optional).</param>
/// <param name="index">The index (optional).</param>
/// <returns>The number of blocks.</returns>
/// <remarks>
/// If the target type (targetType) or index (index) is provided, it returns the number of blocks for the corresponding level, target type, and index.
/// </remarks>
public int GetBlockNumber(int level, Targets? targetType = null, int? index = null)
{
return GetSingleLevelPrefabSet(level, targetType, index).prefabs.Length;
}
/// <summary>
/// Gets the size of a specific block for a given level, block type, target type, and index.
/// </summary>
/// <param name="level">The level index.</param>
/// <param name="blockType">The block type index.</param>
/// <param name="targetType">The target type (optional).</param>
/// <param name="index">The index (optional).</param>
/// <returns>The block size.</returns>
/// <remarks>
/// If the target type (targetType) or index (index) is provided, it returns the size of the block for the specified level, block type, target type, and index.
/// </remarks>
public float GetBlockSize(int level, int blockType, Targets? targetType = null, int? index = null)
{
return GetPrefab(level, blockType, targetType, index).GetComponent<SceneBlock>().blockSize;
}
/// <summary>
/// Pushes a message to the message box or debug log.推送消息到消息框或调试日志中。
/// </summary>
/// <param name="messageList">The list of messages.</param>
/// <param name="colorList">The list of colors.</param>
/// <remarks>
/// If the message box is enabled (isHudEnabled is true), the message will be pushed to the message box, and the messages will be colored according to the provided color list.
/// If the message box is not enabled (isHudEnabled is false), the messages will be logged as plain text in the debug log.
/// </remarks>
private void PushSceneBlockMessages(List<string> messageList, List<string> colorList)
{
if (isHudEnabled)
{
messageBoxController.PushMessage(messageList, colorList);
}
else
{
Debug.Log(string.Join(" ", messageList));
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: c9ed942e5125e924fad7c8ebd13a79f9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -0,0 +1,32 @@
using System;
using UnityEngine;
/// <summary>
/// ScriptableObject for storing a collection of all level prefab sets.
/// </summary>
/// <remarks>
/// This class is used to organize and initialize multiple level prefab sets.
/// </remarks>
[CreateAssetMenu(menuName = "All Level Prefab Set")]
public class TargetLevelsSet : ScriptableObject
{
public BlocksSet[] singleLevelSet;
[NonSerialized] public int levelSize = 0;
/// <summary>
/// Initialize the level collection.
/// </summary>
/// <remarks>
/// This method retrieves the size of the level collection and initializes each individual level prefab set.
/// </remarks>
public void InitializeLevelsSet()
{
// get level size
levelSize = singleLevelSet.Length;
for(int i = 0; i < levelSize; i++)
{
// initialize all single level prefab set
singleLevelSet[i].InitializeBlocksSet();
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 944a7e8a5086c6646bc0685cbede5ebc
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: