V3.1 控制模式完成
完成控制模式中UI,解决所有逻辑问题。控制模式于Unity中正常运行,可正常判断结束。
This commit is contained in:
@@ -81,7 +81,7 @@ public class AgentWithGun : Agent
|
||||
|
||||
[System.NonSerialized] public int finishedState;
|
||||
|
||||
// start scene datas
|
||||
// start scene datas 0=train 1=play
|
||||
private int gamemode;
|
||||
|
||||
private void Start()
|
||||
@@ -96,7 +96,7 @@ public class AgentWithGun : Agent
|
||||
catch
|
||||
{
|
||||
Debug.LogError("Run WithOut StartScreen");
|
||||
gamemode = 0;
|
||||
gamemode = 1;
|
||||
}
|
||||
|
||||
// initialize scripts
|
||||
@@ -452,9 +452,19 @@ public class AgentWithGun : Agent
|
||||
{
|
||||
Cursor.lockState = CursorLockMode.Locked; // hide and lock the mouse
|
||||
}
|
||||
//thisAgentObj.name = thisAgentObj.GetInstanceID().ToString();
|
||||
targetCon.rollNewScene();
|
||||
paramContainer.resetTimeBonusReward();
|
||||
//thisAgentObj.name = thisAgentObj.GetInstanceID().ToString();
|
||||
if (gamemode == 0)
|
||||
{
|
||||
// train mode
|
||||
targetCon.rollNewScene();
|
||||
}
|
||||
else
|
||||
{
|
||||
// play mode
|
||||
targetCon.playInitialize();
|
||||
}
|
||||
|
||||
// give default Reward to Reward value will be used.
|
||||
if (hudController.chartOn)
|
||||
{
|
||||
|
||||
@@ -43,8 +43,8 @@ public class EnvironmentUIControl : MonoBehaviour
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
int remainTime = Convert.ToInt32(targetController.startTime + paramContainer.timeLimit - Time.time);
|
||||
remainTimeText.text = "RemainTime:" + remainTime.ToString();
|
||||
// int remainTime = Convert.ToInt32(targetController.startTime + paramContainer.timeLimit - Time.time);
|
||||
remainTimeText.text = "RemainTime:" + Convert.ToInt32(targetController.leftTime).ToString();
|
||||
if (resultActive && Time.time - overTime >= resultTimeout)
|
||||
{
|
||||
// while result is active and show time over timeOut
|
||||
@@ -150,6 +150,10 @@ public class EnvironmentUIControl : MonoBehaviour
|
||||
targetTypeText.text = "Free";
|
||||
targetTypeText.color = Color.yellow;
|
||||
break;
|
||||
case (int)SceneBlockContainer.Targets.Stay:
|
||||
targetTypeText.text = "Stay";
|
||||
targetTypeText.color = Color.white;
|
||||
break;
|
||||
default:
|
||||
targetTypeText.text = "TYPE ERROR";
|
||||
targetTypeText.color = Color.red;
|
||||
|
||||
@@ -119,7 +119,8 @@ public class ParameterContainer : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (targetCon.targetTypeInt != (int)SceneBlockContainer.Targets.Free)
|
||||
// get target distance and in area
|
||||
if (targetCon.targetTypeInt is (int)SceneBlockContainer.Targets.Go or (int)SceneBlockContainer.Targets.Attack)
|
||||
{
|
||||
(agentDistance, agentInArea) = blockCont.getAgentTargetDistanceAndInside(agentObj.transform.position);
|
||||
// attack goto or defence target
|
||||
|
||||
@@ -49,6 +49,7 @@ public class SceneBlock : MonoBehaviour
|
||||
{
|
||||
if (Time.time - intervalStart >= addPointInterval)
|
||||
{
|
||||
// update belong ratio every addPointInterval scecond
|
||||
group1InareaNum = getInAreaNumber(group1Tag);
|
||||
group2InareaNum = getInAreaNumber(group2Tag);
|
||||
belongRatio = group1InareaNum - group2InareaNum;
|
||||
@@ -74,7 +75,7 @@ public class SceneBlock : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
//Initialize thi scene block should be excuted after enemy created
|
||||
//Initialize this scene block should be excuted after enemy created
|
||||
public void initBlock(GameObject envObj)
|
||||
{
|
||||
//Buffer all Player or enemy obj int this environment to list
|
||||
|
||||
@@ -5,7 +5,7 @@ using UnityEngine;
|
||||
|
||||
public class SceneBlockContainer : MonoBehaviour
|
||||
{
|
||||
public enum Targets { Free, Go, Attack, Defence, Num };// Num is use for get total target bumber
|
||||
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[] attackBlockPrefabs = new GameObject[1];
|
||||
@@ -74,5 +74,8 @@ public class SceneBlockContainer : MonoBehaviour
|
||||
return thisBlock.getDist_inArea(agentPosition);
|
||||
}
|
||||
|
||||
|
||||
public void initializeBlock(GameObject envObj)
|
||||
{
|
||||
thisBlock.initBlock(envObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,6 +63,9 @@ public class TargetController : MonoBehaviour
|
||||
private WorldUIController worldUICon;
|
||||
private HUDController hudCon;
|
||||
private RaySensors raySensors;
|
||||
private StartSeneData startSceneData;
|
||||
// start scene datas 0=train 1=play
|
||||
private int gamemode;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
@@ -91,6 +94,19 @@ public class TargetController : MonoBehaviour
|
||||
{
|
||||
Debug.LogError("target percentage wrong");
|
||||
}
|
||||
// initialize startSceneData & datas
|
||||
// while GameObject StartSceneDataTransfer is exist
|
||||
try
|
||||
{
|
||||
startSceneData = GameObject.Find("StartSceneDataTransfer").GetComponent<StartSeneData>();
|
||||
gamemode = startSceneData.gamemode;
|
||||
}
|
||||
// while GameObject StartSceneDataTransfer is not exist
|
||||
catch
|
||||
{
|
||||
Debug.LogError("Run WithOut StartScreen");
|
||||
gamemode = 1;
|
||||
}
|
||||
|
||||
// initialize a simple fake onehot encoder.
|
||||
for (int i = 0; i < targetNum; i++)
|
||||
@@ -107,7 +123,17 @@ public class TargetController : MonoBehaviour
|
||||
|
||||
private void Update()
|
||||
{
|
||||
leftTime = paramCon.timeLimit - Time.time + startTime;
|
||||
// if gamemode is play, then time will keep paramCon.timeLimit
|
||||
if (gamemode == 1)
|
||||
{
|
||||
leftTime = paramCon.timeLimit;
|
||||
// print out time
|
||||
Debug.Log("Playing Time: " + leftTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
leftTime = paramCon.timeLimit - Time.time + startTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void rollNewScene()
|
||||
@@ -250,7 +276,6 @@ public class TargetController : MonoBehaviour
|
||||
agentCharaCon.enabled = true;
|
||||
}
|
||||
|
||||
|
||||
// check over and get rewards
|
||||
// 1 = success,2 = overtime,0 = notover
|
||||
public (int, float,float) checkOverAndRewards()
|
||||
@@ -297,12 +322,14 @@ public class TargetController : MonoBehaviour
|
||||
envUICon.updateTargetGauge(blockCont.thisBlock.firebasesBelong, blockCont.thisBlock.belongMaxPoint);
|
||||
if (blockCont.thisBlock.getInAreaNumber(group2Tag) <= 0 && targetEnemySpawnFinish)
|
||||
{
|
||||
Debug.Log(blockCont.thisBlock.getInAreaNumber(group2Tag));
|
||||
// win
|
||||
// let the area belongs to me and kill every enmy in this area.
|
||||
thisReward = 0;
|
||||
endReward = paramCon.attackWinReward;
|
||||
//thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
endTypeInt = (int)EndType.Win;
|
||||
targetEnemySpawnFinish = false;
|
||||
}
|
||||
else if (leftTime <= 0 && targetEnemySpawnFinish)
|
||||
{
|
||||
@@ -311,6 +338,7 @@ public class TargetController : MonoBehaviour
|
||||
endReward = paramCon.loseReward;
|
||||
//thisReward = (paramCon.inAreaReward * inArea) + getSceneReward(nowDistance);
|
||||
endTypeInt = (int)EndType.Lose;
|
||||
targetEnemySpawnFinish = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -349,17 +377,24 @@ public class TargetController : MonoBehaviour
|
||||
endTypeInt = (int)EndType.Running;
|
||||
}
|
||||
break;
|
||||
case (int)SceneBlockContainer.Targets.Stay:
|
||||
// Stay
|
||||
// endless
|
||||
thisReward = 0;
|
||||
endReward = 0;
|
||||
endTypeInt = (int)EndType.Running;
|
||||
break;
|
||||
default:
|
||||
//free kill
|
||||
if (EnemyContainerObj.transform.childCount <= 0)
|
||||
{
|
||||
// win
|
||||
//thisReward = paramCon.winReward + (paramCon.timeBonusPerSecReward * leftTime);
|
||||
// thisReward = paramCon.winReward + (paramCon.timeBonusPerSecReward * leftTime);
|
||||
thisReward = 0;
|
||||
endReward = paramCon.freeWinReward;
|
||||
endTypeInt = (int)EndType.Win;
|
||||
}
|
||||
else if (Time.time - startTime >= paramCon.timeLimit)
|
||||
else if (leftTime <= 0)
|
||||
{
|
||||
// lose
|
||||
//thisReward = paramCon.loseReward;
|
||||
@@ -481,4 +516,44 @@ public class TargetController : MonoBehaviour
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// Play Mode method
|
||||
// Initialize Play mode
|
||||
public void playInitialize()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Stay;
|
||||
envUICon.updateTargetType(targetTypeInt);
|
||||
moveAgentToSpwanArea();
|
||||
enemyCont.destroyAllEnemys();
|
||||
blockCont.destroyBlock();
|
||||
}
|
||||
|
||||
// change to attack mode
|
||||
public void attackModeChange()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Attack;
|
||||
envUICon.updateTargetType(targetTypeInt);
|
||||
}
|
||||
|
||||
// change to free mode
|
||||
public void freeModeChange()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Free;
|
||||
envUICon.updateTargetType(targetTypeInt);
|
||||
}
|
||||
|
||||
// change to goto mode
|
||||
public void gotoModeChange()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Go;
|
||||
envUICon.updateTargetType(targetTypeInt);
|
||||
}
|
||||
|
||||
// change to stay mode
|
||||
public void stayModeChange()
|
||||
{
|
||||
targetTypeInt = (int)SceneBlockContainer.Targets.Stay;
|
||||
envUICon.updateTargetType(targetTypeInt);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -27,11 +27,6 @@ public class WorldUIController : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
public void updateChart(int targetType, int endType)
|
||||
{
|
||||
float winRatio = 0f;
|
||||
|
||||
Reference in New Issue
Block a user