V3.3.1 添加一些summary

添加一些summary
This commit is contained in:
2023-09-08 22:05:43 +09:00
parent 203407693c
commit 6dffd4185d
9 changed files with 261 additions and 128 deletions
+13 -1
View File
@@ -1,13 +1,25 @@
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;
// initialization
/// <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
+11 -2
View File
@@ -1,4 +1,4 @@
using UnityEngine;
using UnityEngine;
public class SceneBlockContainer : MonoBehaviour
{
@@ -22,7 +22,16 @@ public class SceneBlockContainer : MonoBehaviour
scenePrefabSet.InitializeSceneBlocksSet(hudObj);
}
// create appointed block at appointed position
/// <summary>
/// Creates a specified block at a specified position.
/// 在指定位置创建指定类型的场景块。
/// </summary>
/// <param name="targetType">The target type.</param>
/// <param name="level">The level.</param>
/// <param name="blockType">The block type.</param>
/// <param name="blockPosition">The block position.</param>
/// <param name="tag1">Tag 1 (optional, default is "Player").</param>
/// <param name="tag2">Tag 2 (optional, default is "Enemy").</param>
public void CreateNewBlock(Targets targetType, int level, int blockType, Vector3 blockPosition, string tag1 = "Player", string tag2 = "Enemy")
{
// check if nowBlock is deleted
+86 -17
View File
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;
@@ -140,8 +140,15 @@ public class TargetController : MonoBehaviour
}
}
#region Train Mode Initialization Functions
/// <summary>
/// Generates a new scene configuration by selecting a random target type and spawning related scene blocks.
/// </summary>
/// <remarks>
/// This method is responsible for creating a new scene configuration, which involves selecting a target type
/// (Go, Attack, Defence, or Free) based on predefined probabilities. Depending on the chosen target type,
/// the method spawns the associated scene blocks, updates various flags, and informs the user interface about
/// the selected target type.
/// </remarks>
public void RollNewScene()
{
startTime = Time.time;// Reset StartTime as now time
@@ -188,11 +195,12 @@ public class TargetController : MonoBehaviour
envUICon.UpdateTargetType(targetTypeInt);
}
#endregion Train Mode Initialization Functions
#region Agent Move Method
// move Agent into Agent Spawn Area
/// <summary>
/// Move the agent to the spawn area.
/// 将Agent移动到生成区域。
/// </summary>
private void MoveAgentToSpwanArea()
{
float randX = UnityEngine.Random.Range(minAgentAreaX, maxAgentAreaX); ;
@@ -213,7 +221,17 @@ public class TargetController : MonoBehaviour
MoveAgentTo(initAgentLoc);
}
// move Agent to this position
/// <summary>
/// Move the agent to the specified position.
/// 将代理移动到指定位置。
/// </summary>
/// <param name="position">要移动到的位置。</param>
/// <remarks>
/// When moving the character using transform.localPosition,
/// must disable the character controller, or it won't work properly.
/// 使用 transform.localPosition 移动角色时,
/// 必须禁用角色控制器,否则它将无法正常工作。
/// </remarks>
public void MoveAgentTo(Vector3 position)
{
// while using transform.localPosition to move character
@@ -227,7 +245,15 @@ public class TargetController : MonoBehaviour
#region Random SceneBlock Spawn Method
// initialize scene block by target type
/// <summary>
/// Randomly spawns a scene block based on the target type.
/// 根据目标类型随机生成场景块。
/// </summary>
/// <param name="targetType">要生成的场景块的目标类型。The target type of the scene block to be generated.</param>
/// <remarks>
/// This method generates a random scene block based on the target type and spawns enemies at the specified location.
/// 此方法根据目标类型生成一个随机场景块,并在指定位置生成敌人。
/// </remarks>
private void RandomSpawnSceneBlock(SceneBlockContainer.Targets targetType)
{
randLevel = GetRandomLevelIndex(targetType);
@@ -250,8 +276,11 @@ public class TargetController : MonoBehaviour
#region Reward function
// check over and get rewards
// 1 = success,2 = overtime,0 = notover
/// <summary>
/// Checks the game's end state and retrieves rewards.
/// </summary>
/// <returns>A tuple containing the game's end type, current reward, and final reward.
/// 1 = success,2 = overtime,0 = notover</returns>
public (int, float, float) CheckOverAndRewards()
{
int endTypeInt = 0;
@@ -393,7 +422,13 @@ public class TargetController : MonoBehaviour
return (endTypeInt, nowReward, endReward);
}
// caulculate sceneReward if close to target then get great reward
/// <summary>
/// Calculates scene reward based on distance, granting higher rewards for being closer to the target.
/// 根据距离计算场景奖励,靠近目标则获得更高奖励。
/// </summary>
/// <param name="nowDistance">The current distance.</param>
/// <param name="inarea">Whether inside an area.</param>
/// <returns>The reward value calculated based on distance.</returns>
private float GetDistanceReward(float nowDistance, int inarea)
{
if (firstRewardFlag)
@@ -418,7 +453,12 @@ public class TargetController : MonoBehaviour
return nowSeneReward;
}
// calculate kill reward base on killed enemy's position
/// <summary>
/// Calculates kill reward based on the position of the killed enemy.
/// 根据击杀的敌人位置计算击杀奖励。
/// </summary>
/// <param name="enemyPosition">The position of the killed enemy.</param>
/// <returns>The reward value calculated based on the kill position.</returns>
public float KillReward(Vector3 enemyPosition)
{
float nowKillReward = 0f;
@@ -449,7 +489,12 @@ public class TargetController : MonoBehaviour
return nowKillReward;
}
// calculate hit reward base on killed enemy's position and now mode
/// <summary>
/// Calculates hit reward based on the position of the hit enemy and the current mode.
/// 根据击中的敌人位置和当前模式计算击中Reward。
/// </summary>
/// <param name="enemyPosition">The position of the hit enemy.</param>
/// <returns>The reward value calculated based on the hit position and mode.</returns>
public float HitEnemyReward(Vector3 enemyPosition)
{
float nowHitReward = 0f;
@@ -485,7 +530,18 @@ public class TargetController : MonoBehaviour
#region Play Mode Method
// Initialize Play mode
/// <summary>
/// Initializes the game in play mode.
/// 初始化游戏playMode。
/// </summary>
/// <remarks>
/// This method is used to initialize the game in play mode,
/// including setting the target type, updating target states,
/// updating UI display, moving the agent to the spawn area,
/// destroying all enemies, and scene blocks.
/// 该方法用于初始化游戏播放模式,包括设置目标类型、更新目标状态、更新UI显示、
/// 将代理移动到生成区域、销毁所有敌人和场景块。
/// </remarks>
public void PlayInitialize()
{
targetTypeInt = (int)SceneBlockContainer.Targets.Stay;
@@ -530,7 +586,11 @@ public class TargetController : MonoBehaviour
#endregion Play Mode Method
// get target observation states
/// <summary>
/// Gets the target observation states.
/// 获取目标观测状态。
/// </summary>
/// <param name="targetPosition">The target position (optional).</param>
private void UpdateTargetStates(Vector3? targetPosition = null)
{
// targettype, x,y,z, firebasesAreaDiameter
@@ -555,7 +615,11 @@ public class TargetController : MonoBehaviour
}
}
// get in area state
/// <summary>
/// Gets the in-area state.
/// 获取是否在区域内的State
/// </summary>
/// <returns>The in-area state.</returns>
public int GetInAreaState()
{
if (targetTypeInt == (int)SceneBlockContainer.Targets.Go)
@@ -568,7 +632,12 @@ public class TargetController : MonoBehaviour
}
}
// get random Level by target type
/// <summary>
/// Gets a random level index based on the target type.
/// 根据目标类型获取随机关卡索引。
/// </summary>
/// <param name="target">The target type.</param>
/// <returns>A random level index.</returns>
public int GetRandomLevelIndex(SceneBlockContainer.Targets target)
{
List<float> targetProbs;
+12 -1
View File
@@ -1,13 +1,24 @@
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 LevelsSet : ScriptableObject
{
public BlocksSet[] singleLevelSet;
[NonSerialized] public int levelSize = 0;
// initialization
/// <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
+47 -15
View File
@@ -2,6 +2,13 @@ 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
{
@@ -10,7 +17,10 @@ public class SceneBlocksSet : ScriptableObject
private GameObject hudObj;
private MessageBoxController messageBoxController;
// initialization
/// <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;
@@ -22,9 +32,11 @@ public class SceneBlocksSet : ScriptableObject
}
}
#region Get Scene,Level,Prefab methods
// get AllLevlePrefabSet by target type
/// <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)
@@ -49,7 +61,12 @@ public class SceneBlocksSet : ScriptableObject
}
}
// get SingleLevelPrefabSet by target type and level
/// <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)
@@ -62,7 +79,13 @@ public class SceneBlocksSet : ScriptableObject
return GetAllLevlePrefabSet(targetType).singleLevelSet[level];
}
// get prefab by target type, level and block type
/// <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)
@@ -75,27 +98,36 @@ public class SceneBlocksSet : ScriptableObject
return GetSingleLevelPrefabSet(targetType, level).prefabs[blockType];
}
#endregion Get Scene,Level,Prefab methods
#region Get Prefab Property methods
//get level number by target type
/// <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;
}
// get block number by target type and level
/// <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;
}
// get block size by target type and level and block type
/// <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;
}
#endregion Get Prefab Property methods
}