V3.1 控制模式完成
完成控制模式中UI,解决所有逻辑问题。控制模式于Unity中正常运行,可正常判断结束。
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MouseInMap : MonoBehaviour
|
||||
{
|
||||
public Camera playCamera;
|
||||
public GameObject EnvironmentObj;
|
||||
public GameObject selectEffect;
|
||||
public GameObject EnemyContainerObj;
|
||||
public GameObject SceneBlockContainerObj;
|
||||
public GameObject TargetControllerObj;
|
||||
public GameObject HUDObj;
|
||||
|
||||
private Vector3 mouseInMapPosition = Vector3.zero;
|
||||
private Vector3 nowHitPosition = Vector3.zero;
|
||||
private LayerMask groundMask;
|
||||
private int randBlockNum;
|
||||
private GameObject preSet;
|
||||
private TargetController targetCon;
|
||||
private MousePreview mousePreviewCon;
|
||||
private EnemyContainer enemyCon;
|
||||
private SceneBlockContainer sceneBlockCon;
|
||||
private TargetUIController targetUICon;
|
||||
|
||||
public enum MouseMode
|
||||
{
|
||||
Default,
|
||||
AttackSet,
|
||||
GotoSet,
|
||||
EnemySet
|
||||
}
|
||||
public MouseMode mouseMode = MouseMode.Default;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
groundMask = LayerMask.GetMask("Ground");
|
||||
targetCon = TargetControllerObj.GetComponent<TargetController>();
|
||||
mousePreviewCon = this.GetComponent<MousePreview>();
|
||||
enemyCon = EnemyContainerObj.GetComponent<EnemyContainer>();
|
||||
sceneBlockCon = SceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
targetUICon = HUDObj.GetComponent<TargetUIController>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
nowHitPosition = getMouseOnMapPosition();
|
||||
// if mouse position in area, update mouseInMapPosition as nowHitPosition
|
||||
if (nowHitPosition.x < targetCon.maxAgentAreaX && nowHitPosition.x > targetCon.minAgentAreaX && nowHitPosition.z < targetCon.maxEnemyAreaZ && nowHitPosition.z > targetCon.minAgentAreaZ)
|
||||
{
|
||||
mouseInMapPosition = nowHitPosition;
|
||||
mousePreviewCon.updatePreviewPosition(mouseInMapPosition);
|
||||
// Mouse button R pressed
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
switch(mouseMode)
|
||||
{
|
||||
case MouseMode.AttackSet:
|
||||
sceneBlockCon.createNewBlock(SceneBlockContainer.Targets.Attack, randBlockNum, mouseInMapPosition);
|
||||
sceneBlockCon.initializeBlock(EnvironmentObj);
|
||||
targetCon.attackModeChange();
|
||||
changeMouseModeTo(MouseMode.Default);
|
||||
break;
|
||||
case MouseMode.GotoSet:
|
||||
sceneBlockCon.createNewBlock(SceneBlockContainer.Targets.Go, randBlockNum, mouseInMapPosition);
|
||||
sceneBlockCon.initializeBlock(EnvironmentObj);
|
||||
targetCon.gotoModeChange();
|
||||
changeMouseModeTo(MouseMode.Default);
|
||||
break;
|
||||
case MouseMode.EnemySet:
|
||||
enemyCon.initEnemyAtHere(new Vector3(mouseInMapPosition.x,1,mouseInMapPosition.z));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void changeMouseModeTo(MouseMode thisMouseMode)
|
||||
{
|
||||
mouseMode = thisMouseMode;
|
||||
switch (thisMouseMode)
|
||||
{
|
||||
case MouseMode.AttackSet:
|
||||
// random choose attack scene block type and set as preview
|
||||
randBlockNum = Random.Range(0, sceneBlockCon.attackBlockPrefabs.Length);
|
||||
preSet = sceneBlockCon.attackBlockPrefabs[randBlockNum];
|
||||
mousePreviewCon.changePreviewTo(preSet);
|
||||
break;
|
||||
case MouseMode.GotoSet:
|
||||
// random choose Goto scene block type and set as preview
|
||||
randBlockNum = Random.Range(0, sceneBlockCon.goBlockPrefabs.Length);
|
||||
preSet = sceneBlockCon.goBlockPrefabs[randBlockNum];
|
||||
mousePreviewCon.changePreviewTo(preSet);
|
||||
break;
|
||||
case MouseMode.EnemySet:
|
||||
preSet = enemyCon.enemyPrefab;
|
||||
mousePreviewCon.changePreviewTo(preSet);
|
||||
break;
|
||||
default:
|
||||
mousePreviewCon.deleteAllPreviewModele();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// get mouse position on map, return a Vector3
|
||||
public Vector3 getMouseOnMapPosition()
|
||||
{
|
||||
// shoot raycast from mainCamera center to mousepositon
|
||||
RaycastHit thisHit;
|
||||
Color rayColor = Color.red;
|
||||
Vector3 onMapPosition;
|
||||
Ray ray = playCamera.ScreenPointToRay(Input.mousePosition);
|
||||
// if raycast hit gameobject
|
||||
if (Physics.Raycast(ray, out thisHit, Mathf.Infinity, groundMask))
|
||||
{
|
||||
//draw raycast
|
||||
Debug.DrawRay(ray.origin, ray.direction * 100, rayColor);
|
||||
return onMapPosition = thisHit.point;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 586cc33424b6eb941a724f7235d76abe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Xml.Serialization;
|
||||
using UnityEngine;
|
||||
|
||||
public class MousePreview : MonoBehaviour
|
||||
{
|
||||
|
||||
// show mousePreviewObj in mouse position
|
||||
public void changePreviewTo(GameObject mousePreviewObj)
|
||||
{
|
||||
deleteAllPreviewModele();
|
||||
Instantiate(mousePreviewObj, this.transform.position, Quaternion.identity, this.transform);
|
||||
}
|
||||
public void updatePreviewPosition(Vector3 previewPos)
|
||||
{
|
||||
// move this gameobject to previewPos
|
||||
this.transform.position = previewPos;
|
||||
}
|
||||
public void deleteAllPreviewModele()
|
||||
{
|
||||
// delete all child object
|
||||
foreach (Transform childObj in this.transform)
|
||||
{
|
||||
// destroy child
|
||||
Destroy(childObj.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 344fcc32b8a34e44395c603ede216670
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,118 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77518fe48235bbe47bd3adde3630eb02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
@@ -50,20 +50,6 @@ public class PlayerCamera : MonoBehaviour
|
||||
{
|
||||
scrollSp = minHeight - transform.position.y;
|
||||
}
|
||||
/* if((transform.position.y <= maxHeight) && (scrollSp > 0))
|
||||
{
|
||||
scrollSp = 0;
|
||||
}else if((transform.position.y >= minHeight)&& (scrollSp < 0))
|
||||
{
|
||||
scrollSp = 0;
|
||||
}
|
||||
if((transform.position.y + scrollSp) > maxHeight)
|
||||
{
|
||||
scrollSp = maxHeight - transform.position.y;
|
||||
}else if((transform.position.y + scrollSp) < minHeight)
|
||||
{
|
||||
scrollSp = minHeight - transform.position.y;
|
||||
}*/
|
||||
|
||||
Vector3 verticalMove = new Vector3(0,scrollSp,0); // vertical movement
|
||||
Vector3 lateralMove = hsp * transform.right; // lateral movement in global world ignore camera facing
|
||||
@@ -72,11 +58,8 @@ public class PlayerCamera : MonoBehaviour
|
||||
fowardMove = vsp * fowardMove.normalized; // normalize the vector
|
||||
|
||||
Vector3 move = verticalMove + lateralMove + fowardMove; // total movement
|
||||
|
||||
transform.position += move; // move the camera
|
||||
|
||||
cameraRotation();
|
||||
|
||||
}
|
||||
|
||||
void cameraRotation()
|
||||
@@ -99,6 +82,5 @@ public class PlayerCamera : MonoBehaviour
|
||||
|
||||
startMouseP = dragMouseP;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,98 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TargetUIController : MonoBehaviour
|
||||
{
|
||||
// Controller to control the UI of the target,
|
||||
// select target type, select prefeb to set or sth.
|
||||
public GameObject TargetControllerObj;
|
||||
public GameObject MouseSelectorObj;
|
||||
public GameObject EnvironmentUIObj;
|
||||
|
||||
public Button setAttackButton;
|
||||
public Button setGotoButton;
|
||||
public Button setFreeButton;
|
||||
public Button setStayButton;
|
||||
|
||||
private MouseInMap mouseInMapCon;
|
||||
private EnvironmentUIControl envUICon;
|
||||
private TargetController targetCon;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
targetCon = TargetControllerObj.GetComponent<TargetController>();
|
||||
mouseInMapCon = MouseSelectorObj.GetComponent<MouseInMap>();
|
||||
envUICon = EnvironmentUIObj.GetComponent<EnvironmentUIControl>();
|
||||
}
|
||||
|
||||
public void clearGamePressed()
|
||||
{
|
||||
// Clear all enemies and targets. set gamemode to Stay mode
|
||||
targetCon.stayModeChange();
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.Default);
|
||||
// disable setStayButton and enable other buttons
|
||||
setStayButton.interactable = false;
|
||||
setAttackButton.interactable = true;
|
||||
setGotoButton.interactable = true;
|
||||
setFreeButton.interactable = true;
|
||||
targetCon.playInitialize();
|
||||
}
|
||||
public void setEnemyPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.EnemySet);
|
||||
}
|
||||
public void setGotoPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.GotoSet);
|
||||
}
|
||||
public void setAttackPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.AttackSet);
|
||||
}
|
||||
public void setFreePressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.Default);
|
||||
targetCon.freeModeChange();
|
||||
setStayButton.interactable = true;
|
||||
setAttackButton.interactable = true;
|
||||
setGotoButton.interactable = true;
|
||||
setFreeButton.interactable = false;
|
||||
}
|
||||
public void setStayPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.Default);
|
||||
targetCon.stayModeChange();
|
||||
setStayButton.interactable = false;
|
||||
setAttackButton.interactable = true;
|
||||
setGotoButton.interactable = true;
|
||||
setFreeButton.interactable = true;
|
||||
}
|
||||
|
||||
public void UIButtonInteractable(PlayGameModeController.GameMode nowMode = PlayGameModeController.GameMode.Stay)
|
||||
{
|
||||
setStayButton.interactable = true;
|
||||
setAttackButton.interactable = true;
|
||||
setGotoButton.interactable = true;
|
||||
setFreeButton.interactable = true;
|
||||
switch(nowMode)
|
||||
{
|
||||
case PlayGameModeController.GameMode.Attack:
|
||||
setAttackButton.interactable = false;
|
||||
break;
|
||||
case PlayGameModeController.GameMode.Free:
|
||||
setFreeButton.interactable = false;
|
||||
break;
|
||||
case PlayGameModeController.GameMode.Goto:
|
||||
setGotoButton.interactable = false;
|
||||
break;
|
||||
case PlayGameModeController.GameMode.Stay:
|
||||
setStayButton.interactable = false;
|
||||
break;
|
||||
default:
|
||||
Debug.Log("TargetUIController.UIButtonInteractable : Type error");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e5f471594a32c24194088f10d716a89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,16 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class selectEffect : MonoBehaviour
|
||||
{
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
// if this gameobject exist over 5s, destroy it
|
||||
if (Time.time > 5)
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42a602efe0639c144907a166e7e59a79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user