V3.2.0 添加InGameMessageBox 修改Playmode中小错误
添加InGameMessageBox,可以在游戏中显示某些消息 修正可以在Enemy或者Agent身上生成Target或者Enemy的错误
This commit is contained in:
@@ -2,7 +2,11 @@ using UnityEngine;
|
||||
|
||||
public class MouseInMap : MonoBehaviour
|
||||
{
|
||||
public float targetDistanceThreshold = 6f;
|
||||
public float enemyDistanceThreshold = 1f;
|
||||
|
||||
public Camera playCamera;
|
||||
public GameObject AgentObj;
|
||||
public GameObject environmentObj;
|
||||
public GameObject mousePreviewObj;
|
||||
public GameObject enemyContainerObj;
|
||||
@@ -19,6 +23,7 @@ public class MouseInMap : MonoBehaviour
|
||||
private MousePreview mousePreviewCon;
|
||||
private EnemyContainer enemyCon;
|
||||
private SceneBlockContainer sceneBlockCon;
|
||||
private MessageBoxController messageCon;
|
||||
private TargetUIController targetUICon;
|
||||
|
||||
public enum MouseMode
|
||||
@@ -39,6 +44,7 @@ public class MouseInMap : MonoBehaviour
|
||||
enemyCon = enemyContainerObj.GetComponent<EnemyContainer>();
|
||||
sceneBlockCon = sceneBlockContainerObj.GetComponent<SceneBlockContainer>();
|
||||
targetUICon = HUDObj.GetComponent<TargetUIController>();
|
||||
messageCon = HUDObj.GetComponent<MessageBoxController>();
|
||||
}
|
||||
|
||||
private void Update()
|
||||
@@ -55,21 +61,46 @@ public class MouseInMap : MonoBehaviour
|
||||
switch (mouseMode)
|
||||
{
|
||||
case MouseMode.AttackSet:
|
||||
sceneBlockCon.CreateNewBlock(SceneBlockContainer.Targets.Attack, randBlockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.InitializeBlock(environmentObj);
|
||||
targetCon.AttackModeChange(nowHitPositionRelative);
|
||||
ChangeMouseModeTo(MouseMode.Default);
|
||||
if (IsAgentorEnemyWithinDistance(targetDistanceThreshold))
|
||||
{
|
||||
// if agent or enemy is nearby, do not create new block
|
||||
messageCon.PushMessage("Agent or Enemy is too close!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if agent or enemy is not nearby, create new block
|
||||
sceneBlockCon.CreateNewBlock(SceneBlockContainer.Targets.Attack, randBlockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.InitializeBlock(environmentObj);
|
||||
targetCon.AttackModeChange(nowHitPositionRelative);
|
||||
ChangeMouseModeTo(MouseMode.Default);
|
||||
}
|
||||
break;
|
||||
|
||||
case MouseMode.GotoSet:
|
||||
sceneBlockCon.CreateNewBlock(SceneBlockContainer.Targets.Go, randBlockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.InitializeBlock(environmentObj);
|
||||
targetCon.GotoModeChange(nowHitPositionRelative);
|
||||
ChangeMouseModeTo(MouseMode.Default);
|
||||
if (IsAgentorEnemyWithinDistance(targetDistanceThreshold))
|
||||
{
|
||||
// if agent or enemy is nearby, do not create new block
|
||||
messageCon.PushMessage("Agent or Enemy is too close!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// if agent or enemy is not nearby, create new block
|
||||
sceneBlockCon.CreateNewBlock(SceneBlockContainer.Targets.Go, randBlockNum, nowHitPositionRelative);
|
||||
sceneBlockCon.InitializeBlock(environmentObj);
|
||||
targetCon.GotoModeChange(nowHitPositionRelative);
|
||||
ChangeMouseModeTo(MouseMode.Default);
|
||||
}
|
||||
break;
|
||||
|
||||
case MouseMode.EnemySet:
|
||||
enemyCon.InitEnemyAtHere(new Vector3(nowHitPositionRelative.x, 1, nowHitPositionRelative.z));
|
||||
if (IsAgentorEnemyWithinDistance(enemyDistanceThreshold))
|
||||
{
|
||||
messageCon.PushMessage("Agent or Enemy is too close!");
|
||||
}
|
||||
else
|
||||
{
|
||||
enemyCon.InitEnemyAtHere(new Vector3(nowHitPositionRelative.x, 1, nowHitPositionRelative.z));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -100,7 +131,7 @@ public class MouseInMap : MonoBehaviour
|
||||
|
||||
case MouseMode.EnemySet:
|
||||
preSet = enemyCon.enemyPrefab;
|
||||
mousePreviewCon.ChangePreviewTo(preSet);
|
||||
mousePreviewCon.ChangePreviewTo(preSet,true);
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -127,4 +158,32 @@ public class MouseInMap : MonoBehaviour
|
||||
return Vector3.zero;
|
||||
}
|
||||
}
|
||||
|
||||
private bool IsAgentorEnemyWithinDistance(float distance)
|
||||
{
|
||||
// check all child object in enemyContainerObj
|
||||
// if any child object is near by nowHitPosition in 10, return true
|
||||
Vector3 playerPosition = Vector3.zero;
|
||||
for (int i = 0; i < enemyContainerObj.transform.childCount; i++)
|
||||
{
|
||||
//set enemy Position's y as 0
|
||||
playerPosition = enemyContainerObj.transform.GetChild(i).position;
|
||||
playerPosition.y = 0;
|
||||
// check if enemy near by nowHitPositionRelative in distance, return true
|
||||
if (Vector3.Distance(playerPosition, nowHitPosition) < distance)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// set agentObj position's y as 0
|
||||
playerPosition = AgentObj.transform.position;
|
||||
playerPosition.y = 0;
|
||||
// check if agentObj near by nowHitPositionRelative in distance, return true
|
||||
if (Vector3.Distance(playerPosition, nowHitPosition) < distance)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
// if no enemy or agent near by, return false
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,20 @@ using UnityEngine;
|
||||
|
||||
public class MousePreview : MonoBehaviour
|
||||
{
|
||||
private GameObject nowMousePreviewObj;
|
||||
// show mousePreviewObj in mouse position
|
||||
public void ChangePreviewTo(GameObject mousePreviewObj)
|
||||
public void ChangePreviewTo(GameObject mousePreviewObj, bool disableCollider = false)
|
||||
{
|
||||
// change mouse preview object to mousePreviewObj
|
||||
// delete all child object
|
||||
DeleteAllPreviewModele();
|
||||
Instantiate(mousePreviewObj, transform.position, Quaternion.identity, this.transform);
|
||||
// create new mouse preview object
|
||||
nowMousePreviewObj = Instantiate(mousePreviewObj, transform.position, Quaternion.identity, this.transform);
|
||||
if (disableCollider)
|
||||
{
|
||||
// disable mousePreviewObj collider
|
||||
nowMousePreviewObj.GetComponent<Collider>().enabled = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePreviewPosition(Vector3 previewPos)
|
||||
|
||||
Reference in New Issue
Block a user