119 lines
3.4 KiB
C#
119 lines
3.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlayGameModeController : MonoBehaviour
|
|
{
|
|
public GameObject ParameterContainerObj;
|
|
public GameObject EnemyContainerObj;
|
|
public GameObject AgentObj;
|
|
public GameObject SceneBlockContainerObj;
|
|
|
|
// area
|
|
public GameObject edgeUp;
|
|
public GameObject edgeDown;
|
|
public GameObject edgeLeft;
|
|
public GameObject edgeRight;
|
|
public GameObject edgeAgent_Enemy;
|
|
|
|
public float minEnemyAreaX;
|
|
public float maxEnemyAreaX;
|
|
public float minEnemyAreaZ;
|
|
public float maxEnemyAreaZ;
|
|
public float minAgentAreaX;
|
|
public float maxAgentAreaX;
|
|
public float minAgentAreaZ;
|
|
public float maxAgentAreaZ;
|
|
|
|
private ParameterContainer paramCon;
|
|
private CharacterController agentCharaCon;
|
|
private EnemyContainer enemyCon;
|
|
private SceneBlockContainer sceneBlockCon;
|
|
|
|
private void Start()
|
|
{
|
|
minEnemyAreaX = edgeLeft.transform.localPosition.x + 1.0f;
|
|
maxEnemyAreaX = edgeRight.transform.localPosition.x - 1.0f;
|
|
minEnemyAreaZ = edgeAgent_Enemy.transform.localPosition.z + 1.0f;
|
|
maxEnemyAreaZ = edgeUp.transform.localPosition.z - 1.0f;
|
|
|
|
minAgentAreaX = edgeLeft.transform.localPosition.x + 1.0f;
|
|
maxAgentAreaX = edgeRight.transform.localPosition.x - 1.0f;
|
|
minAgentAreaZ = edgeDown.transform.localPosition.z + 1.0f;
|
|
maxAgentAreaZ = edgeAgent_Enemy.transform.localPosition.z - 1.0f;
|
|
|
|
paramCon = ParameterContainerObj.GetComponent<ParameterContainer>();
|
|
agentCharaCon = AgentObj.GetComponent<CharacterController>();
|
|
enemyCon = EnemyContainerObj.GetComponent<EnemyContainer>();
|
|
sceneBlockCon = SceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
|
}
|
|
|
|
public enum GameMode
|
|
{
|
|
Stay,
|
|
Free,
|
|
Attack,
|
|
Goto
|
|
}
|
|
public GameMode gameMode = GameMode.Stay;// default stay mode
|
|
|
|
public void startInitialize()
|
|
{
|
|
gameMode = GameMode.Stay;
|
|
moveAgentToSpwanArea();
|
|
enemyCon.destroyAllEnemys();
|
|
sceneBlockCon.destroyBlock();
|
|
}
|
|
|
|
// change to attack mode
|
|
public void attackModeChange()
|
|
{
|
|
|
|
}
|
|
|
|
// change to free mode
|
|
public void freeModeChange()
|
|
{
|
|
gameMode = GameMode.Free;
|
|
}
|
|
|
|
// change to goto mode
|
|
public void gotoModeChange()
|
|
{
|
|
|
|
}
|
|
|
|
// move Agent into Agent Spawn Area
|
|
public void moveAgentToSpwanArea()
|
|
{
|
|
float randX = UnityEngine.Random.Range(minAgentAreaX, maxAgentAreaX); ;
|
|
float randZ = 0f;
|
|
if (paramCon.spawnAgentInAllMap)
|
|
{
|
|
// spawn agent in all around map
|
|
randZ = UnityEngine.Random.Range(minAgentAreaZ, maxEnemyAreaZ);
|
|
}
|
|
else
|
|
{
|
|
// spawn agent in only agent spawn area
|
|
randZ = UnityEngine.Random.Range(minAgentAreaZ, maxAgentAreaZ);
|
|
}
|
|
|
|
int Y = 1;
|
|
Vector3 initAgentLoc = new Vector3(randX, Y, randZ);
|
|
moveAgentTo(initAgentLoc);
|
|
}
|
|
|
|
// move Agent to this position
|
|
public void moveAgentTo(Vector3 thisPosition)
|
|
{
|
|
// while using transform.localPosition to move character
|
|
// u should turn off character Controller or it won't work
|
|
agentCharaCon.enabled = false;
|
|
AgentObj.transform.localPosition = thisPosition;
|
|
agentCharaCon.enabled = true;
|
|
}
|
|
|
|
|
|
}
|