V3.1.1 优化代码
优化可读性与规范化命名方式
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class MouseInMap : MonoBehaviour
|
||||
{
|
||||
public Camera playCamera;
|
||||
public GameObject EnvironmentObj;
|
||||
public GameObject environmentObj;
|
||||
public GameObject selectEffect;
|
||||
public GameObject EnemyContainerObj;
|
||||
public GameObject SceneBlockContainerObj;
|
||||
public GameObject TargetControllerObj;
|
||||
public GameObject enemyContainerObj;
|
||||
public GameObject sceneBlockContainerObj;
|
||||
public GameObject targetControllerObj;
|
||||
public GameObject HUDObj;
|
||||
|
||||
private Vector3 mouseInMapPosition = Vector3.zero;
|
||||
@@ -31,46 +28,50 @@ public class MouseInMap : MonoBehaviour
|
||||
GotoSet,
|
||||
EnemySet
|
||||
}
|
||||
|
||||
public MouseMode mouseMode = MouseMode.Default;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
groundMask = LayerMask.GetMask("Ground");
|
||||
targetCon = TargetControllerObj.GetComponent<TargetController>();
|
||||
targetCon = targetControllerObj.GetComponent<TargetController>();
|
||||
mousePreviewCon = this.GetComponent<MousePreview>();
|
||||
enemyCon = EnemyContainerObj.GetComponent<EnemyContainer>();
|
||||
sceneBlockCon = SceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
enemyCon = enemyContainerObj.GetComponent<EnemyContainer>();
|
||||
sceneBlockCon = sceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
targetUICon = HUDObj.GetComponent<TargetUIController>();
|
||||
}
|
||||
|
||||
void Update()
|
||||
private void Update()
|
||||
{
|
||||
nowHitPosition = getMouseOnMapPosition();
|
||||
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);
|
||||
mousePreviewCon.UpdatePreviewPosition(mouseInMapPosition);
|
||||
// Mouse button R pressed
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
switch(mouseMode)
|
||||
switch (mouseMode)
|
||||
{
|
||||
case MouseMode.AttackSet:
|
||||
sceneBlockCon.createNewBlock(SceneBlockContainer.Targets.Attack, randBlockNum, mouseInMapPosition);
|
||||
sceneBlockCon.initializeBlock(EnvironmentObj);
|
||||
targetCon.attackModeChange();
|
||||
changeMouseModeTo(MouseMode.Default);
|
||||
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);
|
||||
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));
|
||||
enemyCon.InitEnemyAtHere(new Vector3(mouseInMapPosition.x, 1, mouseInMapPosition.z));
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
@@ -78,7 +79,7 @@ public class MouseInMap : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public void changeMouseModeTo(MouseMode thisMouseMode)
|
||||
public void ChangeMouseModeTo(MouseMode thisMouseMode)
|
||||
{
|
||||
mouseMode = thisMouseMode;
|
||||
switch (thisMouseMode)
|
||||
@@ -87,26 +88,29 @@ public class MouseInMap : MonoBehaviour
|
||||
// random choose attack scene block type and set as preview
|
||||
randBlockNum = Random.Range(0, sceneBlockCon.attackBlockPrefabs.Length);
|
||||
preSet = sceneBlockCon.attackBlockPrefabs[randBlockNum];
|
||||
mousePreviewCon.changePreviewTo(preSet);
|
||||
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);
|
||||
mousePreviewCon.ChangePreviewTo(preSet);
|
||||
break;
|
||||
|
||||
case MouseMode.EnemySet:
|
||||
preSet = enemyCon.enemyPrefab;
|
||||
mousePreviewCon.changePreviewTo(preSet);
|
||||
mousePreviewCon.ChangePreviewTo(preSet);
|
||||
break;
|
||||
|
||||
default:
|
||||
mousePreviewCon.deleteAllPreviewModele();
|
||||
mousePreviewCon.DeleteAllPreviewModele();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// get mouse position on map, return a Vector3
|
||||
public Vector3 getMouseOnMapPosition()
|
||||
public Vector3 GetMouseOnMapPosition()
|
||||
{
|
||||
// shoot raycast from mainCamera center to mousepositon
|
||||
RaycastHit thisHit;
|
||||
@@ -125,4 +129,4 @@ public class MouseInMap : MonoBehaviour
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,17 +7,17 @@ public class MousePreview : MonoBehaviour
|
||||
{
|
||||
|
||||
// show mousePreviewObj in mouse position
|
||||
public void changePreviewTo(GameObject mousePreviewObj)
|
||||
public void ChangePreviewTo(GameObject mousePreviewObj)
|
||||
{
|
||||
deleteAllPreviewModele();
|
||||
DeleteAllPreviewModele();
|
||||
Instantiate(mousePreviewObj, this.transform.position, Quaternion.identity, this.transform);
|
||||
}
|
||||
public void updatePreviewPosition(Vector3 previewPos)
|
||||
public void UpdatePreviewPosition(Vector3 previewPos)
|
||||
{
|
||||
// move this gameobject to previewPos
|
||||
this.transform.position = previewPos;
|
||||
}
|
||||
public void deleteAllPreviewModele()
|
||||
public void DeleteAllPreviewModele()
|
||||
{
|
||||
// delete all child object
|
||||
foreach (Transform childObj in this.transform)
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class MouseSelector : MonoBehaviour
|
||||
{
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(1))
|
||||
{
|
||||
// shoot raycast from mainCamera center to mousepositon
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3460b8ea83509ed41b69b84ba0c86b87
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,118 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77518fe48235bbe47bd3adde3630eb02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -4,7 +4,7 @@ using UnityEngine;
|
||||
|
||||
public class PlayerCamera : MonoBehaviour
|
||||
{
|
||||
public float normalSpeed = 0.035f;
|
||||
public float normalSpeed = 0.0035f;
|
||||
public float shiftSpeed = 0.06f;
|
||||
public float zoomSpeed = -10.0f;
|
||||
public float rotateSpeed = 0.1f;
|
||||
@@ -59,10 +59,10 @@ public class PlayerCamera : MonoBehaviour
|
||||
|
||||
Vector3 move = verticalMove + lateralMove + fowardMove; // total movement
|
||||
transform.position += move; // move the camera
|
||||
cameraRotation();
|
||||
CameraRotation();
|
||||
}
|
||||
|
||||
void cameraRotation()
|
||||
void CameraRotation()
|
||||
{
|
||||
// camera rotation while press middle mousebutton
|
||||
if(Input.GetMouseButtonDown(2))
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
@@ -7,9 +5,10 @@ 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 GameObject targetControllerObj;
|
||||
|
||||
public GameObject mouseSelectorObj;
|
||||
public GameObject environmentUIObj;
|
||||
|
||||
public Button setAttackButton;
|
||||
public Button setGotoButton;
|
||||
@@ -22,77 +21,56 @@ public class TargetUIController : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
targetCon = TargetControllerObj.GetComponent<TargetController>();
|
||||
mouseInMapCon = MouseSelectorObj.GetComponent<MouseInMap>();
|
||||
envUICon = EnvironmentUIObj.GetComponent<EnvironmentUIControl>();
|
||||
targetCon = targetControllerObj.GetComponent<TargetController>();
|
||||
mouseInMapCon = mouseSelectorObj.GetComponent<MouseInMap>();
|
||||
envUICon = environmentUIObj.GetComponent<EnvironmentUIControl>();
|
||||
}
|
||||
|
||||
public void clearGamePressed()
|
||||
public void ClearGamePressed()
|
||||
{
|
||||
// Clear all enemies and targets. set gamemode to Stay mode
|
||||
targetCon.stayModeChange();
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.Default);
|
||||
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();
|
||||
targetCon.PlayInitialize();
|
||||
}
|
||||
public void setEnemyPressed()
|
||||
|
||||
public void SetEnemyPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.EnemySet);
|
||||
mouseInMapCon.ChangeMouseModeTo(MouseInMap.MouseMode.EnemySet);
|
||||
}
|
||||
public void setGotoPressed()
|
||||
|
||||
public void SetGotoPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.GotoSet);
|
||||
mouseInMapCon.ChangeMouseModeTo(MouseInMap.MouseMode.GotoSet);
|
||||
}
|
||||
public void setAttackPressed()
|
||||
|
||||
public void SetAttackPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.AttackSet);
|
||||
mouseInMapCon.ChangeMouseModeTo(MouseInMap.MouseMode.AttackSet);
|
||||
}
|
||||
public void setFreePressed()
|
||||
|
||||
public void SetFreePressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.Default);
|
||||
targetCon.freeModeChange();
|
||||
mouseInMapCon.ChangeMouseModeTo(MouseInMap.MouseMode.Default);
|
||||
targetCon.FreeModeChange();
|
||||
setStayButton.interactable = true;
|
||||
setAttackButton.interactable = true;
|
||||
setGotoButton.interactable = true;
|
||||
setFreeButton.interactable = false;
|
||||
}
|
||||
public void setStayPressed()
|
||||
|
||||
public void SetStayPressed()
|
||||
{
|
||||
mouseInMapCon.changeMouseModeTo(MouseInMap.MouseMode.Default);
|
||||
targetCon.stayModeChange();
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 42a602efe0639c144907a166e7e59a79
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user