V3.1.2 追加Train Button选择
引入DOTween Plugin 追加Train Button选择和其动画 优化代码
This commit is contained in:
@@ -85,24 +85,10 @@ public class AgentWithGun : Agent
|
||||
[System.NonSerialized] public int finishedState;
|
||||
|
||||
// start scene datas 0=train 1=play
|
||||
private int gamemode;
|
||||
private int gameMode;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// 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 scripts
|
||||
paramContainer = parameterContainerObj.GetComponent<ParameterContainer>();
|
||||
eneContainer = enemyContainerObj.GetComponent<EnemyContainer>();
|
||||
@@ -113,6 +99,9 @@ public class AgentWithGun : Agent
|
||||
raySensors = GetComponent<RaySensors>();
|
||||
playerController = this.transform.GetComponent<CharacterController>();
|
||||
|
||||
// initialize gamemode from PrameterContainer
|
||||
gameMode = paramContainer.gameMode;
|
||||
|
||||
// initialize Environment parameters
|
||||
lockMouse = paramContainer.lockMouse;
|
||||
damage = paramContainer.damage;
|
||||
@@ -456,7 +445,7 @@ public class AgentWithGun : Agent
|
||||
}
|
||||
paramContainer.ResetTimeBonusReward();
|
||||
//thisAgentObj.name = thisAgentObj.GetInstanceID().ToString();
|
||||
if (gamemode == 0)
|
||||
if (gameMode == 0)
|
||||
{
|
||||
// train mode
|
||||
targetCon.RollNewScene();
|
||||
|
||||
@@ -7,6 +7,7 @@ public class ParameterContainer : MonoBehaviour
|
||||
public GameObject agentObj;
|
||||
private TargetController targetCon;
|
||||
private SceneBlockContainer blockCont;
|
||||
private StartSeneData startSceneData;
|
||||
private float agentDistance;
|
||||
private int agentInArea;
|
||||
|
||||
@@ -132,6 +133,11 @@ public class ParameterContainer : MonoBehaviour
|
||||
private float targetInAreaTime = 0f;
|
||||
private float lastFrameTime = 0f;
|
||||
|
||||
[System.NonSerialized] public int gameMode;
|
||||
[System.NonSerialized] public float attackProb = 0f;
|
||||
[System.NonSerialized] public float gotoProb = 0f;
|
||||
[System.NonSerialized] public float defenceProb = 0f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
targetCon = targetConObj.GetComponent<TargetController>();
|
||||
@@ -139,6 +145,19 @@ public class ParameterContainer : MonoBehaviour
|
||||
areaTimeBonus = areaTimeBonusPerSec * timeLimit;
|
||||
freeTimeBonus = freeTimeBonusPerSec * timeLimit;
|
||||
targetTimeBonus = targetTimeBonusPerSec * timeLimit;
|
||||
try
|
||||
{
|
||||
startSceneData = GameObject.Find("StartSceneDataTransfer").GetComponent<StartSeneData>();
|
||||
gameMode = startSceneData.gamemode;
|
||||
attackProb = startSceneData.attackProb;
|
||||
gotoProb = startSceneData.gotoProb;
|
||||
defenceProb = startSceneData.defenceProb;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Debug.LogError("PrameterContainer:Run WithOut StartScreen!");
|
||||
gameMode = 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
@@ -4,7 +4,7 @@ MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
executionOrder: -1100
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
|
||||
@@ -16,7 +16,6 @@ public class TargetController : MonoBehaviour
|
||||
|
||||
// area
|
||||
public GameObject edgeUp;
|
||||
|
||||
public GameObject edgeDown;
|
||||
public GameObject edgeLeft;
|
||||
public GameObject edgeRight;
|
||||
@@ -24,7 +23,6 @@ public class TargetController : MonoBehaviour
|
||||
|
||||
//group
|
||||
public string group1Tag = "Player";
|
||||
|
||||
public string group2Tag = "Enemy";
|
||||
|
||||
public float minEnemyAreaX;
|
||||
@@ -67,7 +65,6 @@ 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;
|
||||
@@ -75,6 +72,22 @@ public class TargetController : MonoBehaviour
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
blockCont = sceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
envUICon = environmentUIObj.GetComponent<EnvironmentUIControl>();
|
||||
enemyCont = enemyContainerObj.GetComponent<EnemyContainer>();
|
||||
agentCharaCon = agentObj.GetComponent<CharacterController>();
|
||||
paramCon = parameterContainerObj.GetComponent<ParameterContainer>();
|
||||
worldUICon = worldUIObj.GetComponent<WorldUIController>();
|
||||
hudCon = HUDObj.GetComponent<HUDController>();
|
||||
raySensors = agentObj.GetComponent<RaySensors>();
|
||||
|
||||
// get parameter from ParameterContainer
|
||||
gamemode = paramCon.gameMode;
|
||||
attackProb = paramCon.attackProb;
|
||||
gotoProb = paramCon.gotoProb;
|
||||
defenceProb = paramCon.defenceProb;
|
||||
|
||||
// initialize spawn area
|
||||
minEnemyAreaX = edgeLeft.transform.localPosition.x + 1.0f;
|
||||
maxEnemyAreaX = edgeRight.transform.localPosition.x - 1.0f;
|
||||
minEnemyAreaZ = edgeAgent_Enemy.transform.localPosition.z + 1.0f;
|
||||
@@ -85,33 +98,12 @@ public class TargetController : MonoBehaviour
|
||||
minAgentAreaZ = edgeDown.transform.localPosition.z + 1.0f;
|
||||
maxAgentAreaZ = edgeAgent_Enemy.transform.localPosition.z - 1.0f;
|
||||
|
||||
blockCont = sceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
envUICon = environmentUIObj.GetComponent<EnvironmentUIControl>();
|
||||
enemyCont = enemyContainerObj.GetComponent<EnemyContainer>();
|
||||
agentCharaCon = agentObj.GetComponent<CharacterController>();
|
||||
paramCon = parameterContainerObj.GetComponent<ParameterContainer>();
|
||||
worldUICon = worldUIObj.GetComponent<WorldUIController>();
|
||||
hudCon = HUDObj.GetComponent<HUDController>();
|
||||
raySensors = agentObj.GetComponent<RaySensors>();
|
||||
freeProb = 1 - attackProb - gotoProb - defenceProb;
|
||||
targetNum = (int)SceneBlockContainer.Targets.Num;
|
||||
if (freeProb < 0)
|
||||
{
|
||||
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++)
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
using DG.Tweening;
|
||||
using UnityEngine;
|
||||
|
||||
public class StartMenuAnimations : MonoBehaviour
|
||||
{
|
||||
public GameObject maskObj;
|
||||
public GameObject mixButton;
|
||||
public GameObject attackButton;
|
||||
public GameObject gotoButton;
|
||||
public GameObject freeButton;
|
||||
|
||||
public float animeDuration = 0.2f;
|
||||
|
||||
public Vector3 mixDestination = new Vector3(-85, 29, 0);
|
||||
public Vector3 attackDestination = new Vector3(-100, 0, 0);
|
||||
public Vector3 gotoDestination = new Vector3(-115, -29, 0);
|
||||
public Vector3 freeDestination = new Vector3(-130, -58, 0);
|
||||
|
||||
public float maskScaleX = 1;
|
||||
public float maskScaleY = 0.4f;
|
||||
|
||||
private Vector3 mixOriginDestination;
|
||||
private Vector3 attackOriginDestination;
|
||||
private Vector3 gotoOriginDestination;
|
||||
private Vector3 freeOriginDestination;
|
||||
|
||||
private PolygonCollider2D parallelogramPolygon;
|
||||
private bool isMouseOverMask = false;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
// get start position
|
||||
mixOriginDestination = mixButton.transform.position;
|
||||
attackOriginDestination = attackButton.transform.position;
|
||||
gotoOriginDestination = gotoButton.transform.position;
|
||||
freeOriginDestination = freeButton.transform.position;
|
||||
|
||||
// transform local vector3 to world vector3 by parent
|
||||
mixDestination += mixButton.transform.parent.position;
|
||||
attackDestination += attackButton.transform.parent.position;
|
||||
gotoDestination += gotoButton.transform.parent.position;
|
||||
freeDestination += freeButton.transform.parent.position;
|
||||
|
||||
//get polygon from maskOBJ
|
||||
parallelogramPolygon = maskObj.GetComponent<PolygonCollider2D>();
|
||||
|
||||
// minimize mask object
|
||||
MinimizeMaskObj();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
// check if mouse is in parallelogram
|
||||
if (!isMouseOverMask && parallelogramPolygon.OverlapPoint(Input.mousePosition))
|
||||
{
|
||||
isMouseOverMask = true;
|
||||
OnMaskPointerEnter();
|
||||
}
|
||||
else if (isMouseOverMask && !parallelogramPolygon.OverlapPoint(Input.mousePosition))
|
||||
{
|
||||
isMouseOverMask = false;
|
||||
OnMaskPointerExit();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMaskPointerEnter()
|
||||
{
|
||||
// dotween move button
|
||||
mixButton.transform.DOMove(mixDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
attackButton.transform.DOMove(attackDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
gotoButton.transform.DOMove(gotoDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
freeButton.transform.DOMove(freeDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
MaximizeMaskObj();
|
||||
}
|
||||
|
||||
private void OnMaskPointerExit()
|
||||
{
|
||||
// dotween move button batck to original position
|
||||
mixButton.transform.DOMove(mixOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
attackButton.transform.DOMove(attackOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
gotoButton.transform.DOMove(gotoOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
freeButton.transform.DOMove(freeOriginDestination, animeDuration, true).SetEase(Ease.OutCirc).Play();
|
||||
MinimizeMaskObj();
|
||||
}
|
||||
|
||||
private void MinimizeMaskObj()
|
||||
{
|
||||
// minimize mask object use dotween doscale
|
||||
maskObj.transform.DOScaleX(maskScaleX, animeDuration).SetEase(Ease.OutCirc).Play();
|
||||
maskObj.transform.DOScaleY(maskScaleY, animeDuration).SetEase(Ease.OutCirc).Play();
|
||||
}
|
||||
|
||||
private void MaximizeMaskObj()
|
||||
{
|
||||
// maximize mask object use dotween doscale
|
||||
maskObj.transform.DOScaleX(1, animeDuration).SetEase(Ease.OutCirc).Play();
|
||||
maskObj.transform.DOScaleY(1, animeDuration).SetEase(Ease.OutCirc).Play();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ee00299c7bed34148860da6e69fca27a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,6 +4,10 @@ public class StartSeneData : MonoBehaviour
|
||||
{
|
||||
[Header("Game mode")]
|
||||
public int gamemode = 0;// default trainning mode
|
||||
[Header("Targets Prob")]
|
||||
public float attackProb = 0f;
|
||||
public float gotoProb = 0f;
|
||||
public float defenceProb = 0f;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
|
||||
@@ -31,16 +31,8 @@ public class StartUIManager : MonoBehaviour
|
||||
// if time limit is over, load Train Scene
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Train);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// while Train-StartButton Pressed
|
||||
public void OnTrainStartButtonPressed()
|
||||
{
|
||||
startSceneData.gamemode = 0;
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Train);
|
||||
messageTextObj.text = "Loading Train Scene...";
|
||||
}
|
||||
// while StartButton-Play Pressed
|
||||
public void OnPlayButtonPressed()
|
||||
{
|
||||
@@ -48,5 +40,38 @@ public class StartUIManager : MonoBehaviour
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Play);
|
||||
messageTextObj.text = "Loading Play Scene...";
|
||||
}
|
||||
|
||||
public void OnAttackTrainButtonPressed()
|
||||
{
|
||||
// while Train-Attack-Button Pressed
|
||||
startSceneData.attackProb = 1f;
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnGotoTrainButtonPressed()
|
||||
{
|
||||
// while Train-Goto-Button Pressed
|
||||
startSceneData.gotoProb = 1f;
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnFreeTrainButtonPressed()
|
||||
{
|
||||
// while Train-Free-Button Pressed
|
||||
LoadTrainScene();
|
||||
}
|
||||
public void OnMixTrainButtonPressed()
|
||||
{
|
||||
// while Train-Mix-Button Pressed
|
||||
startSceneData.attackProb = 0.333f;
|
||||
startSceneData.gotoProb = 0.333f;
|
||||
LoadTrainScene();
|
||||
}
|
||||
private void LoadTrainScene()
|
||||
{
|
||||
// load Train Scene
|
||||
sceneLoader.LoadGameScene(SceneLoader.SceneType.Train);
|
||||
messageTextObj.text = "Loading Train Scene...";
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user