V3.3.2 LevelProbabilityPanel初始化完成
LevelProbabilityPanel初始化完成 独立Target enum类
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bb7e12204e0f2e34cbe9674b4927beac
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public static class targetTypeExtensions
|
||||
{
|
||||
public static int ToIndex(this Targets targetType)
|
||||
{
|
||||
switch (targetType)
|
||||
{
|
||||
case Targets.Go:
|
||||
return 0;
|
||||
case Targets.Attack:
|
||||
return 1;
|
||||
case Targets.Defence:
|
||||
return 2;
|
||||
default:
|
||||
Debug.LogError("ToIndex:targetType not found!");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public static Targets ToTargetType(this int index)
|
||||
{
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
return Targets.Go;
|
||||
case 1:
|
||||
return Targets.Attack;
|
||||
case 2:
|
||||
return Targets.Defence;
|
||||
default:
|
||||
Debug.LogError("ToTargetType:index out of range!");
|
||||
return Targets.Go;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb4bd090287d8da47959d417e9234626
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -215,7 +215,7 @@ public class AgentController : MonoBehaviour
|
||||
return targetCon.HitEnemyReward(gotHitObj.transform.position);
|
||||
}
|
||||
}
|
||||
if (targetCon.targetTypeInt == (int)SceneBlockContainer.Targets.Attack)
|
||||
if (targetCon.targetTypeInt == (int)Targets.Attack)
|
||||
{
|
||||
// while if attack mode
|
||||
float targetDis = Vector3.Distance(blockContainer.nowBlock.transform.position, transform.position);
|
||||
@@ -253,7 +253,7 @@ public class AgentController : MonoBehaviour
|
||||
bool isFacingtoEnemy = false;
|
||||
float enemyFacingDistance = 0f;
|
||||
Ray ray = fpsCam.ScreenPointToRay(new Vector3(fpsCam.pixelWidth / 2, fpsCam.pixelHeight / 2, 0));
|
||||
if (targetCon.targetTypeInt == (int)SceneBlockContainer.Targets.Free)
|
||||
if (targetCon.targetTypeInt == (int)Targets.Free)
|
||||
{
|
||||
//free mode
|
||||
RaycastHit hit;
|
||||
@@ -299,7 +299,7 @@ public class AgentController : MonoBehaviour
|
||||
// Debug.Log("ninimum = " + nowReward);
|
||||
}
|
||||
}
|
||||
else if (targetCon.targetTypeInt == (int)SceneBlockContainer.Targets.Attack)
|
||||
else if (targetCon.targetTypeInt == (int)Targets.Attack)
|
||||
{
|
||||
// attack mode
|
||||
// Target to Agent distance
|
||||
|
||||
@@ -135,27 +135,27 @@ public class EnvironmentUIControl : MonoBehaviour
|
||||
{
|
||||
switch (targetInt)
|
||||
{
|
||||
case (int)SceneBlockContainer.Targets.Go:
|
||||
case (int)Targets.Go:
|
||||
targetTypeText.text = "GOTO";
|
||||
targetTypeText.color = Color.blue;
|
||||
break;
|
||||
|
||||
case (int)SceneBlockContainer.Targets.Attack:
|
||||
case (int)Targets.Attack:
|
||||
targetTypeText.text = "Attack!";
|
||||
targetTypeText.color = Color.red;
|
||||
break;
|
||||
|
||||
case (int)SceneBlockContainer.Targets.Defence:
|
||||
case (int)Targets.Defence:
|
||||
targetTypeText.text = "Defence";
|
||||
targetTypeText.color = Color.green;
|
||||
break;
|
||||
|
||||
case (int)SceneBlockContainer.Targets.Free:
|
||||
case (int)Targets.Free:
|
||||
targetTypeText.text = "Free";
|
||||
targetTypeText.color = Color.yellow;
|
||||
break;
|
||||
|
||||
case (int)SceneBlockContainer.Targets.Stay:
|
||||
case (int)Targets.Stay:
|
||||
targetTypeText.text = "Stay";
|
||||
targetTypeText.color = Color.white;
|
||||
break;
|
||||
|
||||
@@ -171,7 +171,7 @@ public class MLAgentsCustomController : Agent
|
||||
// Win or lose Finished
|
||||
Debug.Log("Finish reward = " + nowRoundReward);
|
||||
EP += 1;
|
||||
string targetString = Enum.GetName(typeof(SceneBlockContainer.Targets), targetController.targetTypeInt);
|
||||
string targetString = Enum.GetName(typeof(Targets), targetController.targetTypeInt);
|
||||
switch (finishedState)
|
||||
{
|
||||
case (int)TargetController.EndType.Win:
|
||||
|
||||
@@ -180,7 +180,7 @@ public class ParameterContainer : MonoBehaviour
|
||||
private void Update()
|
||||
{
|
||||
// get target distance and in area
|
||||
if (targetCon.targetTypeInt is (int)SceneBlockContainer.Targets.Go or (int)SceneBlockContainer.Targets.Attack)
|
||||
if (targetCon.targetTypeInt is (int)Targets.Go or (int)Targets.Attack)
|
||||
{
|
||||
(agentDistance, agentInArea) = blockCont.GetAgentTargetDistanceAndInside(agentObj.transform.position);
|
||||
// attack goto or defence target
|
||||
|
||||
@@ -2,12 +2,10 @@
|
||||
|
||||
public class SceneBlockContainer : MonoBehaviour
|
||||
{
|
||||
public enum Targets
|
||||
{ Free, Go, Attack, Defence, Stay, Num };// Num is use for get total target bumber
|
||||
|
||||
public float sceneSize = 10f;
|
||||
public GameObject environmentObj;
|
||||
public GameObject hudObj;
|
||||
|
||||
// public GameObject[] attackBlockPrefabs = new GameObject[1];
|
||||
// public GameObject[] goBlockPrefabs = new GameObject[1];
|
||||
// public GameObject[] defencePrefabs = new GameObject[1];
|
||||
@@ -42,7 +40,7 @@ public class SceneBlockContainer : MonoBehaviour
|
||||
DestroyBlock();
|
||||
}
|
||||
// choose target type
|
||||
nowBlockObj = Instantiate(scenePrefabSet.GetPrefab(targetType, level, blockType), blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
|
||||
nowBlockObj = Instantiate(scenePrefabSet.GetPrefab(level, blockType, targetType), blockPosition + environmentObj.transform.position, Quaternion.identity, transform);
|
||||
nowBlock = nowBlockObj.GetComponent<SceneBlock>();
|
||||
nowBlock.group1Tag = tag1;
|
||||
nowBlock.group2Tag = tag2;
|
||||
|
||||
@@ -104,9 +104,9 @@ public class TargetController : MonoBehaviour
|
||||
maxAgentAreaZ = edgeAgent_Enemy.transform.localPosition.z - 1.0f;
|
||||
|
||||
freeProb = 1 - attackProb - gotoProb - defenceProb;
|
||||
targetNum = (int)SceneBlockContainer.Targets.Num;
|
||||
gotoLevelNum = sceneBlockCon.scenePrefabSet.GetLevelNumber(SceneBlockContainer.Targets.Go);
|
||||
attackLevelNum = sceneBlockCon.scenePrefabSet.GetLevelNumber(SceneBlockContainer.Targets.Attack);
|
||||
targetNum = (int)Targets.Num;
|
||||
gotoLevelNum = sceneBlockCon.scenePrefabSet.GetLevelNumber(Targets.Go);
|
||||
attackLevelNum = sceneBlockCon.scenePrefabSet.GetLevelNumber(Targets.Attack);
|
||||
if (freeProb < 0)
|
||||
{
|
||||
Debug.LogError("TargetController.Start: target percentage wrong");
|
||||
@@ -158,8 +158,8 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
// goto target spawn
|
||||
Debug.Log("GOTO THIS TARGET!");
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Go;
|
||||
RandomSpawnSceneBlock(SceneBlockContainer.Targets.Go);
|
||||
targetTypeInt = (int)Targets.Go;
|
||||
RandomSpawnSceneBlock(Targets.Go);
|
||||
// set startDistance
|
||||
firstRewardFlag = true;
|
||||
}
|
||||
@@ -167,8 +167,8 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
// attack target spawn
|
||||
Debug.Log("ATTACK!");
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Attack;
|
||||
RandomSpawnSceneBlock(SceneBlockContainer.Targets.Attack);
|
||||
targetTypeInt = (int)Targets.Attack;
|
||||
RandomSpawnSceneBlock(Targets.Attack);
|
||||
// set startDistance
|
||||
firstRewardFlag = true;
|
||||
targetEnemySpawnFinish = false;
|
||||
@@ -177,15 +177,15 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
// defence target spawn
|
||||
Debug.Log("DEFENCE!");
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Defence;
|
||||
RandomSpawnSceneBlock(SceneBlockContainer.Targets.Defence);
|
||||
targetTypeInt = (int)Targets.Defence;
|
||||
RandomSpawnSceneBlock(Targets.Defence);
|
||||
// set startDistance
|
||||
firstRewardFlag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log("Free");
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Free;
|
||||
targetTypeInt = (int)Targets.Free;
|
||||
enemyCon.DestroyAllEnemys();
|
||||
enemyCon.RandomInitEnemys(hudCon.enemyNum);
|
||||
MoveAgentToSpwanArea();
|
||||
@@ -254,11 +254,11 @@ public class TargetController : MonoBehaviour
|
||||
/// 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)
|
||||
private void RandomSpawnSceneBlock(Targets targetType)
|
||||
{
|
||||
randLevel = RollRandomLevelIndex(targetType);
|
||||
randBlockType = Random.Range(0, sceneBlockCon.scenePrefabSet.GetBlockNumber(targetType,randLevel));
|
||||
sceneBlockSize = sceneBlockCon.scenePrefabSet.GetBlockSize(targetType, randLevel, randBlockType);
|
||||
randBlockType = Random.Range(0, sceneBlockCon.scenePrefabSet.GetBlockNumber(randLevel,targetType));
|
||||
sceneBlockSize = sceneBlockCon.scenePrefabSet.GetBlockSize(randLevel, randBlockType, targetType);
|
||||
|
||||
float randX = UnityEngine.Random.Range(minEnemyAreaX + sceneBlockSize / 2 + 1f, maxEnemyAreaX - sceneBlockSize / 2 - 1f);
|
||||
float randZ = UnityEngine.Random.Range(minEnemyAreaZ + sceneBlockSize / 2 + 1f, maxEnemyAreaZ - sceneBlockSize / 2 - 1f);
|
||||
@@ -289,7 +289,7 @@ public class TargetController : MonoBehaviour
|
||||
float nowDistance = 0f;
|
||||
switch (targetTypeInt)
|
||||
{
|
||||
case (int)SceneBlockContainer.Targets.Go:
|
||||
case (int)Targets.Go:
|
||||
// goto
|
||||
(nowDistance, inArea) = sceneBlockCon.GetAgentTargetDistanceAndInside(agentObj.transform.position);
|
||||
envUICon.UpdateTargetGauge(sceneBlockCon.nowBlock.firebasesBelong, sceneBlockCon.nowBlock.belongMaxPoint);
|
||||
@@ -320,7 +320,7 @@ public class TargetController : MonoBehaviour
|
||||
}
|
||||
break;
|
||||
|
||||
case (int)SceneBlockContainer.Targets.Attack:
|
||||
case (int)Targets.Attack:
|
||||
// attack
|
||||
(nowDistance, inArea) = sceneBlockCon.GetAgentTargetDistanceAndInside(agentObj.transform.position);
|
||||
envUICon.UpdateTargetGauge(sceneBlockCon.nowBlock.firebasesBelong, sceneBlockCon.nowBlock.belongMaxPoint);
|
||||
@@ -354,7 +354,7 @@ public class TargetController : MonoBehaviour
|
||||
}
|
||||
break;
|
||||
|
||||
case (int)SceneBlockContainer.Targets.Defence:
|
||||
case (int)Targets.Defence:
|
||||
//defence
|
||||
// !!! DIDN't FINISH!!!
|
||||
(nowDistance, inArea) = sceneBlockCon.GetAgentTargetDistanceAndInside(agentObj.transform.position);
|
||||
@@ -382,7 +382,7 @@ public class TargetController : MonoBehaviour
|
||||
}
|
||||
break;
|
||||
|
||||
case (int)SceneBlockContainer.Targets.Stay:
|
||||
case (int)Targets.Stay:
|
||||
// Stay
|
||||
// endless
|
||||
nowReward = 0;
|
||||
@@ -462,7 +462,7 @@ public class TargetController : MonoBehaviour
|
||||
public float KillReward(Vector3 enemyPosition)
|
||||
{
|
||||
float nowKillReward = 0f;
|
||||
if (targetTypeInt == (int)SceneBlockContainer.Targets.Attack)
|
||||
if (targetTypeInt == (int)Targets.Attack)
|
||||
{
|
||||
// attack mode
|
||||
(_, int isInArea) = sceneBlockCon.nowBlock.GetDistInArea(enemyPosition);
|
||||
@@ -476,7 +476,7 @@ public class TargetController : MonoBehaviour
|
||||
nowKillReward = paramCon.killNonTargetReward;
|
||||
}
|
||||
}
|
||||
else if (targetTypeInt == (int)SceneBlockContainer.Targets.Free)
|
||||
else if (targetTypeInt == (int)Targets.Free)
|
||||
{
|
||||
// free mode hit
|
||||
nowKillReward = paramCon.killTargetEnemyReward;
|
||||
@@ -498,7 +498,7 @@ public class TargetController : MonoBehaviour
|
||||
public float HitEnemyReward(Vector3 enemyPosition)
|
||||
{
|
||||
float nowHitReward = 0f;
|
||||
if (targetTypeInt == (int)SceneBlockContainer.Targets.Attack)
|
||||
if (targetTypeInt == (int)Targets.Attack)
|
||||
{
|
||||
// attack mode
|
||||
(_, int isInArea) = sceneBlockCon.nowBlock.GetDistInArea(enemyPosition);
|
||||
@@ -513,7 +513,7 @@ public class TargetController : MonoBehaviour
|
||||
nowHitReward = paramCon.hitNonTargetReward;
|
||||
}
|
||||
}
|
||||
else if (targetTypeInt == (int)SceneBlockContainer.Targets.Free)
|
||||
else if (targetTypeInt == (int)Targets.Free)
|
||||
{
|
||||
// free mode hit
|
||||
nowHitReward = paramCon.hitTargetReward;
|
||||
@@ -544,7 +544,7 @@ public class TargetController : MonoBehaviour
|
||||
/// </remarks>
|
||||
public void PlayInitialize()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Stay;
|
||||
targetTypeInt = (int)Targets.Stay;
|
||||
UpdateTargetStates();
|
||||
envUICon.UpdateTargetType(targetTypeInt);
|
||||
MoveAgentToSpwanArea();
|
||||
@@ -555,7 +555,7 @@ public class TargetController : MonoBehaviour
|
||||
// change to attack mode
|
||||
public void AttackModeChange(Vector3 targetPosition)
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Attack;
|
||||
targetTypeInt = (int)Targets.Attack;
|
||||
UpdateTargetStates(targetPosition);
|
||||
envUICon.UpdateTargetType(targetTypeInt);
|
||||
}
|
||||
@@ -563,7 +563,7 @@ public class TargetController : MonoBehaviour
|
||||
// change to free mode
|
||||
public void FreeModeChange()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Free;
|
||||
targetTypeInt = (int)Targets.Free;
|
||||
UpdateTargetStates();
|
||||
envUICon.UpdateTargetType(targetTypeInt);
|
||||
}
|
||||
@@ -571,7 +571,7 @@ public class TargetController : MonoBehaviour
|
||||
// change to goto mode
|
||||
public void GotoModeChange(Vector3 targetPosition)
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Go;
|
||||
targetTypeInt = (int)Targets.Go;
|
||||
UpdateTargetStates(targetPosition);
|
||||
envUICon.UpdateTargetType(targetTypeInt);
|
||||
}
|
||||
@@ -579,7 +579,7 @@ public class TargetController : MonoBehaviour
|
||||
// change to stay mode
|
||||
public void StayModeChange()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Stay;
|
||||
targetTypeInt = (int)Targets.Stay;
|
||||
UpdateTargetStates();
|
||||
envUICon.UpdateTargetType(targetTypeInt);
|
||||
}
|
||||
@@ -599,7 +599,7 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
this.targetPosition = (Vector3)targetPosition;
|
||||
}
|
||||
if (targetTypeInt == (int)SceneBlockContainer.Targets.Free || targetTypeInt == (int)SceneBlockContainer.Targets.Stay)
|
||||
if (targetTypeInt == (int)Targets.Free || targetTypeInt == (int)Targets.Stay)
|
||||
{
|
||||
for (int i = 1; i < targetState.Length; i++)
|
||||
// set target position state to 0
|
||||
@@ -622,7 +622,7 @@ public class TargetController : MonoBehaviour
|
||||
/// <returns>The in-area state.</returns>
|
||||
public int GetInAreaState()
|
||||
{
|
||||
if (targetTypeInt == (int)SceneBlockContainer.Targets.Go)
|
||||
if (targetTypeInt == (int)Targets.Go)
|
||||
{
|
||||
return inArea;
|
||||
}
|
||||
@@ -638,19 +638,19 @@ public class TargetController : MonoBehaviour
|
||||
/// </summary>
|
||||
/// <param name="target">The target type.</param>
|
||||
/// <returns>A random level index.</returns>
|
||||
public int RollRandomLevelIndex(SceneBlockContainer.Targets target)
|
||||
public int RollRandomLevelIndex(Targets target)
|
||||
{
|
||||
List<float> targetProbs;
|
||||
|
||||
switch (target)
|
||||
{
|
||||
case SceneBlockContainer.Targets.Attack:
|
||||
case Targets.Attack:
|
||||
targetProbs = paramCon.attackLevelProbs;
|
||||
break;
|
||||
case SceneBlockContainer.Targets.Go:
|
||||
case Targets.Go:
|
||||
targetProbs = paramCon.gotoLevelProbs;
|
||||
break;
|
||||
case SceneBlockContainer.Targets.Defence:
|
||||
case Targets.Defence:
|
||||
targetProbs = paramCon.defenceLevelProbs;
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -13,15 +13,15 @@ public class WorldUIController : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
totalGames = new int[(int)SceneBlockContainer.Targets.Num];
|
||||
winGames = new int[(int)SceneBlockContainer.Targets.Num];
|
||||
Array.Clear(totalGames, 0, (int)SceneBlockContainer.Targets.Num);
|
||||
Array.Clear(winGames, 0, (int)SceneBlockContainer.Targets.Num);
|
||||
totalGames = new int[(int)Targets.Num];
|
||||
winGames = new int[(int)Targets.Num];
|
||||
Array.Clear(totalGames, 0, (int)Targets.Num);
|
||||
Array.Clear(winGames, 0, (int)Targets.Num);
|
||||
//WinChart.Init();
|
||||
winChart.RemoveData();
|
||||
for (int i = 0; i < (int)SceneBlockContainer.Targets.Num; i++)
|
||||
for (int i = 0; i < (int)Targets.Num; i++)
|
||||
{
|
||||
string lineName = Enum.GetName(typeof(SceneBlockContainer.Targets), i);
|
||||
string lineName = Enum.GetName(typeof(Targets), i);
|
||||
winChart.AddSerie<Line>(lineName);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,13 @@ public class MessageBoxController : MonoBehaviour
|
||||
[SerializeField]
|
||||
private List<Message> messages = new List<Message>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Pushes a simple message to the message list.
|
||||
/// </summary>
|
||||
/// <param name="text">The message text.</param>
|
||||
/// <remarks>
|
||||
/// This method pushes a simple text message to the message list and handles message overflow to ensure that the message list does not grow indefinitely.
|
||||
/// </remarks>
|
||||
public void PushMessage(string text)
|
||||
{
|
||||
// push simple message to message list
|
||||
@@ -29,7 +35,15 @@ public class MessageBoxController : MonoBehaviour
|
||||
messages.Add(newMessage);
|
||||
}
|
||||
|
||||
// push multi color message to message list
|
||||
/// <summary>
|
||||
/// Pushes multi-color messages to the message list.
|
||||
/// </summary>
|
||||
/// <param name="messageList">The list of message texts.</param>
|
||||
/// <param name="colorList">The list of colors.</param>
|
||||
/// <remarks>
|
||||
/// This method pushes multi-color text messages to the message list and handles message overflow to ensure that the message list does not grow indefinitely.
|
||||
/// If the lengths of the message text list and the color list do not match, it either removes excess colors or adds white color to the extra messages.
|
||||
/// </remarks>
|
||||
public void PushMessage(List<string> messageList,List<string> colorList)
|
||||
{
|
||||
// check messages and colors list length match
|
||||
|
||||
@@ -77,7 +77,7 @@ public class MouseInMap : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// if agent or enemy is not nearby, create new block
|
||||
sceneBlockCon.CreateNewBlock(SceneBlockContainer.Targets.Attack, blockLevel, blockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.CreateNewBlock(Targets.Attack, blockLevel, blockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.InitializeBlock(environmentObj);
|
||||
targetCon.AttackModeChange(nowHitPositionRelative);
|
||||
ChangeMouseMode(MouseMode.Default);
|
||||
@@ -94,7 +94,7 @@ public class MouseInMap : MonoBehaviour
|
||||
else
|
||||
{
|
||||
// if agent or enemy is not nearby, create new block
|
||||
sceneBlockCon.CreateNewBlock(SceneBlockContainer.Targets.Go, blockLevel, blockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.CreateNewBlock(Targets.Go, blockLevel, blockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.InitializeBlock(environmentObj);
|
||||
targetCon.GotoModeChange(nowHitPositionRelative);
|
||||
ChangeMouseMode(MouseMode.Default);
|
||||
@@ -124,7 +124,7 @@ public class MouseInMap : MonoBehaviour
|
||||
public void ChangeMouseMode(MouseMode mouseMode, int level = -1, int blockNum = -1)
|
||||
{
|
||||
this.mouseMode = mouseMode;
|
||||
SceneBlockContainer.Targets nowTargetType;
|
||||
Targets nowTargetType;
|
||||
switch (mouseMode)
|
||||
{
|
||||
case MouseMode.AttackSet:
|
||||
@@ -149,7 +149,7 @@ public class MouseInMap : MonoBehaviour
|
||||
if (blockNum < 0)
|
||||
{
|
||||
// while blockNum is not set, random choose block type
|
||||
this.blockNum = Random.Range(0, sceneBlockCon.scenePrefabSet.GetBlockNumber(nowTargetType, blockLevel));
|
||||
this.blockNum = Random.Range(0, sceneBlockCon.scenePrefabSet.GetBlockNumber(blockLevel, nowTargetType));
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -157,7 +157,7 @@ public class MouseInMap : MonoBehaviour
|
||||
this.blockNum = blockNum;
|
||||
}
|
||||
// set previewModel
|
||||
previewModel = sceneBlockCon.scenePrefabSet.GetPrefab(nowTargetType, blockLevel, this.blockNum);
|
||||
previewModel = sceneBlockCon.scenePrefabSet.GetPrefab(blockLevel, this.blockNum, nowTargetType);
|
||||
mousePreviewCon.ChangePreviewTo(previewModel);
|
||||
break;
|
||||
|
||||
@@ -223,20 +223,20 @@ public class MouseInMap : MonoBehaviour
|
||||
}
|
||||
|
||||
// change to TargetType from MouseMode
|
||||
private SceneBlockContainer.Targets GetTargetTypeByMouseMode(MouseMode mode)
|
||||
private Targets GetTargetTypeByMouseMode(MouseMode mode)
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
case MouseMode.AttackSet:
|
||||
return SceneBlockContainer.Targets.Attack;
|
||||
return Targets.Attack;
|
||||
|
||||
case MouseMode.GotoSet:
|
||||
return SceneBlockContainer.Targets.Go;
|
||||
return Targets.Go;
|
||||
|
||||
default:
|
||||
messageCon.PushMessage(new List<string> { "[Error]MouseInMap:GetTargetTypeByMouseMode:", "Mouse Mode not found!", "mode=", mode.ToString() },
|
||||
new List<string> { messageCon.errorColor });
|
||||
return SceneBlockContainer.Targets.Num;
|
||||
return Targets.Num;
|
||||
}
|
||||
}
|
||||
}
|
||||
+118
-57
@@ -1,5 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.PackageManager;
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
@@ -13,18 +13,24 @@ using UnityEngine;
|
||||
public class SceneBlocksSet : ScriptableObject
|
||||
{
|
||||
public LevelsSet[] levels = new LevelsSet[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)
|
||||
public void InitializeSceneBlocksSet(GameObject hudObj = null)
|
||||
{
|
||||
this.hudObj = hudObj;
|
||||
messageBoxController = this.hudObj.GetComponent<MessageBoxController>();
|
||||
if (hudObj != null)
|
||||
{
|
||||
isHudEnabled = true;
|
||||
this.hudObj = hudObj;
|
||||
messageBoxController = this.hudObj.GetComponent<MessageBoxController>();
|
||||
}
|
||||
for (int i = 0; i < levels.Length; i++)
|
||||
{
|
||||
// initialize all level prefab set
|
||||
@@ -33,101 +39,156 @@ public class SceneBlocksSet : ScriptableObject
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all level prefab sets based on the target type.
|
||||
/// Gets all level prefab sets.
|
||||
/// </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)
|
||||
/// <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 LevelsSet GetAllLevlePrefabSet(Targets? targetType = null, int? index = null)
|
||||
{
|
||||
switch (targetType)
|
||||
if (targetType == null && index == null)
|
||||
{
|
||||
case SceneBlockContainer.Targets.Go:
|
||||
return levels[0];
|
||||
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 SceneBlockContainer.Targets.Attack:
|
||||
return levels[1];
|
||||
case (null, int i):
|
||||
levelIndex = i;
|
||||
break;
|
||||
|
||||
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];
|
||||
case (Targets type, int i):
|
||||
levelIndex = type.ToIndex();
|
||||
break;
|
||||
|
||||
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;
|
||||
PushSceneBlockMessages(new List<string> { "[ERROR]ScenePrefabSet.GetAllLevlePrefabSet:", " targetType or index not found!" },
|
||||
new List<string> { messageBoxController.errorColor });
|
||||
break;
|
||||
}
|
||||
return levels[levelIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a single level prefab set based on the target type and level.
|
||||
/// Gets the prefab set for a single 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)
|
||||
/// <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).singleLevelSet.Length)
|
||||
if (level >= GetAllLevlePrefabSet(targetType, index).singleLevelSet.Length)
|
||||
{
|
||||
messageBoxController.PushMessage(new List<string> { "[ERROR]ScenePrefabSet.GetSingleLevelPrefabSet:", " level out of range!","targetType = ",targetType.ToString(), "level = ",level.ToString()},
|
||||
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).singleLevelSet[level];
|
||||
return GetAllLevlePrefabSet(targetType, index).singleLevelSet[level];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get a prefab based on the target type, level, and block type.
|
||||
/// Gets a specific prefab for a given level, block type, target type, and index.
|
||||
/// </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)
|
||||
/// <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(targetType, level).prefabs.Length)
|
||||
if (blockType >= GetSingleLevelPrefabSet(level, targetType, index).prefabs.Length)
|
||||
{
|
||||
messageBoxController.PushMessage(new List<string> { "[ERROR]ScenePrefabSet.GetPrefab:", " blockType out of range!","targetType = ",targetType.ToString(), "level = ",level.ToString(), "blockType = ",blockType.ToString()},
|
||||
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(targetType, level).prefabs[blockType];
|
||||
return GetSingleLevelPrefabSet(level, targetType, index).prefabs[blockType];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of levels associated with a specific target type.
|
||||
/// Gets the number of levels for a specific target type and index.
|
||||
/// </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)
|
||||
/// <param name="targetType">The target type (optional).</param>
|
||||
/// <param name="index">The index (optional).</param>
|
||||
/// <returns>The number of levels.</returns>
|
||||
/// <remarks>
|
||||
/// If the target type (targetType) or index (index) is provided, it returns the number of levels for the corresponding target type and index.
|
||||
/// </remarks>
|
||||
public int GetLevelNumber(Targets? targetType = null, int? index = null)
|
||||
{
|
||||
return GetAllLevlePrefabSet(targetType).singleLevelSet.Length;
|
||||
return GetAllLevlePrefabSet(targetType, index).singleLevelSet.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the number of blocks associated with a specific target type and level.
|
||||
/// Gets the number of blocks for a specific level, target type, and index.
|
||||
/// </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)
|
||||
/// <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(targetType, level).prefabs.Length;
|
||||
return GetSingleLevelPrefabSet(level, targetType, index).prefabs.Length;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the size of a block associated with a specific target type, level, and block type.
|
||||
/// Gets the size of a specific block for a given level, block type, target type, and index.
|
||||
/// </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)
|
||||
/// <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(targetType, level, blockType).GetComponent<SceneBlock>().blockSize;
|
||||
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,70 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SingleLevelProbabilityPanel : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI levelNameText;
|
||||
public TextMeshProUGUI probabilityText;
|
||||
|
||||
public Slider probabilitySlider;
|
||||
public float probabilityValue = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the level probability panel, setting the level name and probability value.
|
||||
/// </summary>
|
||||
/// <param name="levelName">The level name.</param>
|
||||
/// <param name="probability">The probability value.</param>
|
||||
public void InitializeLevelProbabilityPanel(string levelName, float probability)
|
||||
{
|
||||
SetLevelName(levelName);
|
||||
SetProbability(probability);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize the level probability panel, setting the level number and probability value.
|
||||
/// </summary>
|
||||
/// <param name="levelName">The level number.</param>
|
||||
/// <param name="probability">The probability value.</param>
|
||||
public void InitializeLevelProbabilityPanel(int levelName, float probability)
|
||||
{
|
||||
SetLevelName(levelName);
|
||||
SetProbability(probability);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the level name.
|
||||
/// </summary>
|
||||
/// <param name="levelName">The level name.</param>
|
||||
public void SetLevelName(string levelName)
|
||||
{
|
||||
levelNameText.text = levelName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the level name.
|
||||
/// </summary>
|
||||
/// <param name="levelName">The level number.</param>
|
||||
public void SetLevelName(int levelName)
|
||||
{
|
||||
levelNameText.text = "Level" + levelName.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Set the probability value.
|
||||
/// </summary>
|
||||
/// <param name="prob">The probability value.</param>
|
||||
public void SetProbability(float prob)
|
||||
{
|
||||
probabilitySlider.value = prob;
|
||||
UpdateProbabilityText();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update the probability text display.
|
||||
/// </summary>
|
||||
public void UpdateProbabilityText()
|
||||
{
|
||||
probabilityText.text = (probabilitySlider.value * 100).ToString("0.00") + "%";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 650649b0f68385646ba7f21566945d1a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,4 @@
|
||||
public enum Targets
|
||||
{
|
||||
Free, Go, Attack, Defence, Stay, Num
|
||||
}// Num is use for get total target bumber
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17d9008070d061944815e4ee376ddb46
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user