分离Parameter为Common Parameter和会随着游戏State改变的Parameter。
将不需要public的一些变量改为private。
This commit is contained in:
@@ -5,14 +5,22 @@ using UnityEngine;
|
||||
|
||||
public class AgentController : MonoBehaviour
|
||||
{
|
||||
public GameObject parameterContainerObj;
|
||||
public GameObject environmentObj;
|
||||
public GameObject enemyContainerObj;
|
||||
public GameObject sceneBlockContainerObj;
|
||||
public GameObject environmentUIControlObj;
|
||||
public GameObject targetControllerObj;
|
||||
public GameObject HUDObj;
|
||||
public Camera fpsCam;
|
||||
[SerializeField]
|
||||
private GameObject commonParameterContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject environmentObj;
|
||||
[SerializeField]
|
||||
private GameObject enemyContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject sceneBlockContainerObj;
|
||||
[SerializeField]
|
||||
private GameObject environmentUIControlObj;
|
||||
[SerializeField]
|
||||
private GameObject targetControllerObj;
|
||||
[SerializeField]
|
||||
private GameObject HUDObj;
|
||||
[SerializeField]
|
||||
private Camera fpsCam;
|
||||
|
||||
[Header("GetAxis() Simulate")]
|
||||
public float moveSpeed = 9.0f;
|
||||
@@ -48,25 +56,25 @@ public class AgentController : MonoBehaviour
|
||||
private RaySensors raySensors;
|
||||
|
||||
private CharacterController playerController;
|
||||
private ParameterContainer paramContainer;
|
||||
private CommonParameterContainer commonPramCon;
|
||||
private SceneBlockContainer blockContainer;
|
||||
private TargetController targetCon;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// initialize scripts
|
||||
paramContainer = parameterContainerObj.GetComponent<ParameterContainer>();
|
||||
commonPramCon = commonParameterContainerObj.GetComponent<CommonParameterContainer>();
|
||||
blockContainer = sceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
targetCon = targetControllerObj.GetComponent<TargetController>();
|
||||
raySensors = GetComponent<RaySensors>();
|
||||
playerController = this.transform.GetComponent<CharacterController>();
|
||||
|
||||
// initialize Environment parameters
|
||||
lockMouse = paramContainer.lockMouse;
|
||||
damage = paramContainer.damage;
|
||||
fireRate = paramContainer.fireRate;
|
||||
lockCameraX = paramContainer.lockCameraX;
|
||||
lockCameraY = paramContainer.lockCameraY;
|
||||
lockMouse = commonPramCon.lockMouse;
|
||||
damage = commonPramCon.damage;
|
||||
fireRate = commonPramCon.fireRate;
|
||||
lockCameraX = commonPramCon.lockCameraX;
|
||||
lockCameraY = commonPramCon.lockCameraY;
|
||||
|
||||
// initialize remainTime
|
||||
// this agent's tag
|
||||
@@ -226,24 +234,24 @@ public class AgentController : MonoBehaviour
|
||||
{
|
||||
// im shooting at target but didn't hit enemy
|
||||
// Debug.DrawRay(centerRay.origin, viewPoint-centerRay.origin, Color.blue);
|
||||
return paramContainer.shootTargetAreaReward;
|
||||
return commonPramCon.shootTargetAreaReward;
|
||||
}
|
||||
}
|
||||
}
|
||||
shootState = 0;
|
||||
return paramContainer.shootReward;
|
||||
return commonPramCon.shootReward;
|
||||
}
|
||||
else if (shootState != 0 && gunReadyToggle == false)
|
||||
{
|
||||
// shoot without ready
|
||||
shootState = 0;
|
||||
return paramContainer.shootWithoutReadyReward;
|
||||
return commonPramCon.shootWithoutReadyReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
// do not shoot
|
||||
shootState = 0;
|
||||
return paramContainer.nonReward;
|
||||
return commonPramCon.nonReward;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -294,7 +302,7 @@ public class AgentController : MonoBehaviour
|
||||
// facing to an enemy
|
||||
if (hit.collider.tag != myTag && hit.collider.tag != "Wall")
|
||||
{
|
||||
nowReward = paramContainer.facingReward;
|
||||
nowReward = commonPramCon.facingReward;
|
||||
isFacingtoEnemy = true;
|
||||
}
|
||||
}
|
||||
@@ -318,7 +326,7 @@ public class AgentController : MonoBehaviour
|
||||
if (enemyFacingDistance <= lastEnemyFacingDistance)
|
||||
{
|
||||
// closing to enemy
|
||||
nowReward = 1 / MathF.Sqrt(paramContainer.facingInviewEnemyDisCOEF * enemyFacingDistance + 0.00001f);
|
||||
nowReward = 1 / MathF.Sqrt(commonPramCon.facingInviewEnemyDisCOEF * enemyFacingDistance + 0.00001f);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -326,8 +334,8 @@ public class AgentController : MonoBehaviour
|
||||
}
|
||||
// enemy in view Reward
|
||||
lastEnemyFacingDistance = enemyFacingDistance;
|
||||
if (nowReward >= paramContainer.facingReward) nowReward = paramContainer.facingReward; // limit
|
||||
if (nowReward <= -paramContainer.facingReward) nowReward = -paramContainer.facingReward; // limit
|
||||
if (nowReward >= commonPramCon.facingReward) nowReward = commonPramCon.facingReward; // limit
|
||||
if (nowReward <= -commonPramCon.facingReward) nowReward = -commonPramCon.facingReward; // limit
|
||||
// Debug.Log("ninimum = " + nowReward);
|
||||
}
|
||||
break;
|
||||
@@ -341,12 +349,12 @@ public class AgentController : MonoBehaviour
|
||||
if (camCenterToTarget <= blockContainer.nowBlock.firebasesAreaDiameter / 2)
|
||||
{
|
||||
// Debug.DrawRay(centerRay.origin, viewPoint-centerRay.origin, Color.blue);
|
||||
nowReward = paramContainer.facingReward;
|
||||
nowReward = commonPramCon.facingReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
// while not facing to target
|
||||
nowReward = (lastTargetFacingDistance - camCenterToTarget) * paramContainer.facingTargetReward;
|
||||
nowReward = (lastTargetFacingDistance - camCenterToTarget) * commonPramCon.facingTargetReward;
|
||||
}
|
||||
}
|
||||
// update lastTargetFacingDistance
|
||||
@@ -357,7 +365,7 @@ public class AgentController : MonoBehaviour
|
||||
if (camCenterToTarget <= camCenterToViewEdge)
|
||||
{
|
||||
// fireArea is in view
|
||||
nowReward = paramContainer.facingReward;
|
||||
nowReward = commonPramCon.facingReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -395,23 +403,23 @@ public class AgentController : MonoBehaviour
|
||||
// Penalty
|
||||
// spin penalty
|
||||
spinRecord.Add(mouseX);
|
||||
if (spinRecord.Count >= paramContainer.spinRecordMax)
|
||||
if (spinRecord.Count >= commonPramCon.spinRecordMax)
|
||||
{
|
||||
spinRecord.RemoveAt(0);
|
||||
}
|
||||
float spinPenaltyReward = Math.Abs(spinRecord.ToArray().Sum() * paramContainer.spinPenalty);
|
||||
if (spinPenaltyReward >= paramContainer.spinPenaltyThreshold)
|
||||
float spinPenaltyReward = Math.Abs(spinRecord.ToArray().Sum() * commonPramCon.spinPenalty);
|
||||
if (spinPenaltyReward >= commonPramCon.spinPenaltyThreshold)
|
||||
{
|
||||
epreward -= spinPenaltyReward;
|
||||
}
|
||||
else
|
||||
{
|
||||
epreward -= Math.Abs(mouseX) * paramContainer.mousePenalty;
|
||||
epreward -= Math.Abs(mouseX) * commonPramCon.mousePenalty;
|
||||
}
|
||||
// move penalty
|
||||
if (movement != 0)
|
||||
{
|
||||
epreward -= paramContainer.movePenalty;
|
||||
epreward -= commonPramCon.movePenalty;
|
||||
}
|
||||
return epreward;
|
||||
}
|
||||
|
||||
@@ -2,9 +2,9 @@ using UnityEngine;
|
||||
|
||||
public class EnemyContainer : MonoBehaviour
|
||||
{
|
||||
public GameObject enemyPrefab;
|
||||
public GameObject environmentObj;
|
||||
public GameObject targetControllerObj;
|
||||
[SerializeField] public GameObject enemyPrefab;
|
||||
[SerializeField] private GameObject environmentObj;
|
||||
[SerializeField] private GameObject targetControllerObj;
|
||||
|
||||
private TargetController targetCon;
|
||||
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class States : MonoBehaviour
|
||||
{
|
||||
public bool isDead = false;
|
||||
public float maxHP = 100;
|
||||
private float myHP = 100;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
myHP = maxHP;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
}
|
||||
|
||||
private void DetactDeath()
|
||||
{
|
||||
if (myHP <= 0)
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
isDead = true;
|
||||
}
|
||||
}
|
||||
|
||||
// while got hit
|
||||
public void ReactToHit(float Damage, GameObject damageSource)
|
||||
{
|
||||
myHP -= Damage;
|
||||
Debug.Log("HP:" + myHP);
|
||||
if (myHP <= 0)
|
||||
{
|
||||
if (damageSource.tag == "Player")
|
||||
{
|
||||
damageSource.GetComponent<AgentController>().KillRecord(transform.position);
|
||||
Destroy(this.gameObject);
|
||||
isDead = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
isDead = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// get my hp from other script
|
||||
public float GetnowHP()
|
||||
{
|
||||
return myHP;
|
||||
}
|
||||
|
||||
public void DestroyMe()
|
||||
{
|
||||
Destroy(this.gameObject);
|
||||
isDead = true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b25389b3cd1e7084d81fa752823ef210
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user