解决在commit 03267d2 中添加goto模式的facing reward未对play mode适配的问题。

This commit is contained in:
2023-10-25 04:05:50 +09:00
parent 9087a8c552
commit 779897c874
12 changed files with 240 additions and 210 deletions
@@ -55,7 +55,7 @@ public class MLAgentsCustomController : Agent
envUIController = environmentUIObj.GetComponent<EnvironmentUIControl>();
hudController = hudObj.GetComponent<HUDController>();
targetUIController = hudObj.GetComponent<TargetUIController>();
messageBoxController = worldUIControllerObj.GetComponent<MessageBoxController>();
messageBoxController = hudObj.GetComponent<MessageBoxController>();
sideChannelController = sideChannelObj.GetComponent<AimBotSideChannelController>();
rewardFunction = gameObject.GetComponent<RewardFunction>();
worldUICon = worldUIControllerObj.GetComponent<WorldUIController>();
@@ -163,13 +163,13 @@ public class MLAgentsCustomController : Agent
{
envUIController.RemoveChart();
}
worldUICon.UpdateChart(targetController.targetTypeInt, endTypeInt);
worldUICon.UpdateChart(targetController.targetType, endTypeInt);
//Debug.Log("reward = " + nowReward);
if (endTypeInt != (int)TargetController.EndType.Running)
{
// Win or lose Finished
Debug.Log("Finish reward = " + nowReward);
string targetString = Enum.GetName(typeof(Targets), targetController.targetTypeInt);
string targetString = Enum.GetName(typeof(Targets), targetController.targetType);
switch (endTypeInt)
{
case (int)TargetController.EndType.Win:
@@ -93,7 +93,7 @@ public class ParameterContainer : MonoBehaviour
private void Update()
{
// get target distance and in area
if (targetCon.targetTypeInt is (int)Targets.Go or (int)Targets.Attack)
if (targetCon.targetType is Targets.Go or Targets.Attack)
{
(agentDistance, agentInArea) = blockCont.GetAgentTargetDistanceAndInside(agentObj.transform.position);
// attack goto or defence target
+19 -19
View File
@@ -36,7 +36,7 @@ public class TargetController : MonoBehaviour
[SerializeField, Range(0f, 1f)] public float gotoProb = 0.2f;
[SerializeField, Range(0f, 1f)] public float defenceProb = 0.2f;
[System.NonSerialized] public int targetTypeInt;
[System.NonSerialized] public Targets targetType;
[System.NonSerialized] public int gotoLevelNum;
[System.NonSerialized] public int attackLevelNum;
public float[] targetState = new float[6];
@@ -150,7 +150,7 @@ public class TargetController : MonoBehaviour
{
// goto target spawn
Debug.Log("GOTO THIS TARGET!");
targetTypeInt = (int)Targets.Go;
targetType = Targets.Go;
RandomSpawnSceneBlock(Targets.Go);
// set startDistance
firstRewardFlag = true;
@@ -159,7 +159,7 @@ public class TargetController : MonoBehaviour
{
// attack target spawn
Debug.Log("ATTACK Mode Start");
targetTypeInt = (int)Targets.Attack;
targetType = Targets.Attack;
RandomSpawnSceneBlock(Targets.Attack);
// set startDistance
firstRewardFlag = true;
@@ -169,7 +169,7 @@ public class TargetController : MonoBehaviour
{
// defence target spawn
Debug.Log("DEFENCE Mode Start");
targetTypeInt = (int)Targets.Defence;
targetType = Targets.Defence;
RandomSpawnSceneBlock(Targets.Defence);
// set startDistance
firstRewardFlag = true;
@@ -177,14 +177,14 @@ public class TargetController : MonoBehaviour
else
{
Debug.Log("Free Mode Start");
targetTypeInt = (int)Targets.Free;
targetType = Targets.Free;
enemyCon.DestroyAllEnemys();
enemyCon.RandomInitEnemys(hudCon.enemyNum);
MoveAgentToSpwanArea();
sceneBlockCon.DestroyBlock();
}
UpdateTargetStates();
envUICon.UpdateTargetType(targetTypeInt);
envUICon.UpdateTargetType(targetType);
}
#region Agent Move Method
@@ -282,9 +282,9 @@ public class TargetController : MonoBehaviour
/// </remarks>
public void PlayInitialize()
{
targetTypeInt = (int)Targets.Stay;
targetType = Targets.Stay;
UpdateTargetStates();
envUICon.UpdateTargetType(targetTypeInt);
envUICon.UpdateTargetType(targetType);
MoveAgentToSpwanArea();
enemyCon.DestroyAllEnemys();
sceneBlockCon.DestroyBlock();
@@ -293,33 +293,33 @@ public class TargetController : MonoBehaviour
// change to attack mode
public void AttackModeChange(Vector3 targetPosition)
{
targetTypeInt = (int)Targets.Attack;
targetType = Targets.Attack;
UpdateTargetStates(targetPosition);
envUICon.UpdateTargetType(targetTypeInt);
envUICon.UpdateTargetType(targetType);
}
// change to free mode
public void FreeModeChange()
{
targetTypeInt = (int)Targets.Free;
targetType = (int)Targets.Free;
UpdateTargetStates();
envUICon.UpdateTargetType(targetTypeInt);
envUICon.UpdateTargetType(targetType);
}
// change to goto mode
public void GotoModeChange(Vector3 targetPosition)
{
targetTypeInt = (int)Targets.Go;
targetType = Targets.Go;
UpdateTargetStates(targetPosition);
envUICon.UpdateTargetType(targetTypeInt);
envUICon.UpdateTargetType(targetType);
}
// change to stay mode
public void StayModeChange()
{
targetTypeInt = (int)Targets.Stay;
targetType = Targets.Stay;
UpdateTargetStates();
envUICon.UpdateTargetType(targetTypeInt);
envUICon.UpdateTargetType(targetType);
}
#endregion Play Mode Method
@@ -332,12 +332,12 @@ public class TargetController : MonoBehaviour
private void UpdateTargetStates(Vector3? targetPosition = null)
{
// targettype, x,y,z, firebasesAreaDiameter
targetState[0] = targetTypeInt;
targetState[0] = (int)targetType;
if (targetPosition != null)
{
this.targetPosition = (Vector3)targetPosition;
}
if (targetTypeInt == (int)Targets.Free || targetTypeInt == (int)Targets.Stay)
if (targetType == (int)Targets.Free || targetType == Targets.Stay)
{
for (int i = 1; i < targetState.Length; i++)
// set target position state to 0
@@ -360,7 +360,7 @@ public class TargetController : MonoBehaviour
/// <returns>The in-area state.</returns>
public int GetInAreaState()
{
if (targetTypeInt == (int)Targets.Go)
if (targetType == Targets.Go)
{
return inArea;
}
+2 -2
View File
@@ -21,7 +21,7 @@ public class MouseInMap : MonoBehaviour
[SerializeField]
private GameObject targetControllerObj;
[SerializeField]
private GameObject parameterContainerObj;
private GameObject commonParameterContainerObj;
[SerializeField]
private GameObject HUDObj;
@@ -56,7 +56,7 @@ public class MouseInMap : MonoBehaviour
private void Start()
{
commonParamCon = parameterContainerObj.GetComponent<CommonParameterContainer>();
commonParamCon = commonParameterContainerObj.GetComponent<CommonParameterContainer>();
groundMask = LayerMask.GetMask("Ground");
targetCon = targetControllerObj.GetComponent<TargetController>();
mousePreviewCon = mousePreviewObj.GetComponent<MousePreview>();
+7 -7
View File
@@ -131,31 +131,31 @@ public class EnvironmentUIControl : MonoBehaviour
}
// update targetType text
public void UpdateTargetType(int targetInt)
public void UpdateTargetType(Targets targetInt)
{
switch (targetInt)
{
case (int)Targets.Go:
case Targets.Go:
targetTypeText.text = "GOTO";
targetTypeText.color = Color.blue;
break;
case (int)Targets.Attack:
case Targets.Attack:
targetTypeText.text = "Attack!";
targetTypeText.color = Color.red;
break;
case (int)Targets.Defence:
case Targets.Defence:
targetTypeText.text = "Defence";
targetTypeText.color = Color.green;
break;
case (int)Targets.Free:
case Targets.Free:
targetTypeText.text = "Free";
targetTypeText.color = Color.yellow;
break;
case (int)Targets.Stay:
case Targets.Stay:
targetTypeText.text = "Stay";
targetTypeText.color = Color.white;
break;
@@ -169,7 +169,7 @@ public class EnvironmentUIControl : MonoBehaviour
// update state text
// public TextMeshProUGUI stateText;
// targetState[0] = targetTypeInt;
// targetState[0] = targetType;
// targetState[1] = targetEndPosition.x / raySensors.viewDistance; // normalization
// targetState[2] = targetEndPosition.y / raySensors.viewDistance;
// targetState[3] = targetEndPosition.z / raySensors.viewDistance;
+13 -12
View File
@@ -26,32 +26,33 @@ public class WorldUIController : MonoBehaviour
}
}
public void UpdateChart(int targetType, int endType)
public void UpdateChart(Targets targetType, int endType)
{
float winRatio = 0f;
int targetTypeInt = (int)targetType;
switch (endType)
{
case (int)TargetController.EndType.Win:
//Win
totalGames[targetType] += 1;
winGames[targetType] += 1;
winRatio = (float)winGames[targetType] / totalGames[targetType];
winChart.AddData(targetType, winRatio);
if (totalGames[targetType] > maxXAxis)
totalGames[targetTypeInt] += 1;
winGames[targetTypeInt] += 1;
winRatio = (float)winGames[targetTypeInt] / totalGames[targetTypeInt];
winChart.AddData(targetTypeInt, winRatio);
if (totalGames[targetTypeInt] > maxXAxis)
{
maxXAxis = totalGames[targetType];
maxXAxis = totalGames[targetTypeInt];
winChart.AddXAxisData(Convert.ToString(maxXAxis));
}
break;
case (int)TargetController.EndType.Lose:
//lose
totalGames[targetType] += 1;
winRatio = (float)winGames[targetType] / totalGames[targetType];
winChart.AddData(targetType, winRatio);
if (totalGames[targetType] > maxXAxis)
totalGames[targetTypeInt] += 1;
winRatio = (float)winGames[targetTypeInt] / totalGames[targetTypeInt];
winChart.AddData(targetTypeInt, winRatio);
if (totalGames[targetTypeInt] > maxXAxis)
{
maxXAxis = totalGames[targetType];
maxXAxis = totalGames[targetTypeInt];
winChart.AddXAxisData(Convert.ToString(maxXAxis));
}
break;