解决在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;
}