using UnityEngine;
|
|
using System.Collections;
|
|
public class MapArea : MonoBehaviour
|
{
|
public enum E_Type
|
{
|
RebornSafe = 1,// 重生安全区域
|
Safe = 2,// 安全区域
|
Union = 4,// 帮会区域
|
Normal = 8,// 普通区域
|
Neutral = 16,// 中立区域(自由PK) 主动切换为强制
|
Alliance = 32,// 同盟区域
|
Dazuo = 64,// 打坐区域
|
Boss = 128,
|
}
|
|
public Vector3 startPosition;
|
public Vector3 endPosition;
|
|
int _type;
|
|
int m_MapID;
|
int m_AreaID;
|
|
bool m_IsHeroInside;
|
|
public static MapArea CreateMapArea(mapAreaConfig config)
|
{
|
GameObject _go = new GameObject();
|
BoxCollider _collider = _go.AddComponent<BoxCollider>();
|
_go.layer = LayerUtility.MapTrigger;
|
#if UNITY_EDITOR
|
_go.name = "MapArea_" + config.AreaID;
|
#endif
|
MapArea _area = _go.AddMissingComponent<MapArea>();
|
|
_area.startPosition = new Vector3((config.StartPosX - GA_Hero.MapOffset.x) * .5f,
|
0,
|
(config.StartPosY - GA_Hero.MapOffset.z) * .5f);
|
_area.endPosition = new Vector3((config.EndPosX - GA_Hero.MapOffset.x) * .5f,
|
0,
|
(config.EndPosY - GA_Hero.MapOffset.z) * .5f);
|
|
int _width;
|
int _height;
|
|
if (config.StartPosX > config.EndPosX)
|
{
|
_width = (int)((config.StartPosX - config.EndPosX) * .5f);
|
}
|
else
|
{
|
_width = (int)((config.EndPosX - config.StartPosX) * .5f);
|
}
|
|
if (config.StartPosY > config.EndPosY)
|
{
|
_height = (int)((config.StartPosY - config.EndPosY) * .5f);
|
}
|
else
|
{
|
_height = (int)((config.EndPosY - config.StartPosY) * .5f);
|
}
|
|
_collider.transform.localScale = new Vector3(_width + 1, 50, _height + 1);
|
_collider.isTrigger = true;
|
|
Vector3 _position = (_area.endPosition + _area.startPosition) * .5f;
|
float _groundHeight;
|
if (CollisionUtility.TryGetGroundHeight(_position, out _groundHeight))
|
{
|
_position.y = _groundHeight;
|
}
|
_go.transform.position = _position;
|
_area._type = config.AreaName;
|
_area.m_MapID = config.MapID;
|
_area.m_AreaID = config.AreaID;
|
|
return _area;
|
}
|
|
private void OnTriggerEnter(Collider other)
|
{
|
if (GA_Hero.s_MapSwitching)
|
{
|
return;
|
}
|
|
if (_type >= 3000)
|
{
|
SnxxzGame.Instance.MovingCamera(false, _type);
|
SnxxzGame.Instance.ResetCamera(false);
|
SnxxzGame.Instance.MovingCamera(true, _type);
|
}
|
|
if (PlayerDatas.Instance.hero != null)
|
{
|
if (_type >= 3000)
|
{
|
PlayerDatas.Instance.hero.EnterArea((int)E_Type.Boss);
|
PlayerDatas.Instance.hero.currentBossArea = this;
|
//SoundPlayer.Instance.PlayBackGroundMusic(GeneralDefine.BossSound);
|
}
|
else
|
{
|
PlayerDatas.Instance.hero.EnterArea(_type);
|
}
|
}
|
}
|
|
private void OnTriggerExit(Collider other)
|
{
|
// if (GA_Hero.s_MapSwitching)
|
// {
|
// return;
|
// }
|
|
if (_type >= 3000)
|
{
|
SnxxzGame.Instance.MovingCamera(false, _type);
|
SnxxzGame.Instance.ResetCamera(true);
|
}
|
|
if (PlayerDatas.Instance.hero != null)
|
{
|
if (_type >= 3000)
|
{
|
PlayerDatas.Instance.hero.ExitArea((int)E_Type.Boss);
|
PlayerDatas.Instance.hero.currentBossArea = null;
|
//MapConfig _mapConfig = MapConfig.Get(PlayerDatas.Instance.baseData.MapID);
|
//SoundPlayer.Instance.PlayBackGroundMusic(_mapConfig.Music);
|
}
|
else
|
{
|
PlayerDatas.Instance.hero.ExitArea(_type);
|
}
|
}
|
}
|
|
|
#if UNITY_EDITOR
|
private void OnDrawGizmos()
|
{
|
switch ((E_Type)_type)
|
{
|
case E_Type.Normal:
|
Gizmos.color = Color.white;
|
break;
|
case E_Type.RebornSafe:
|
Gizmos.color = new Color(.6f, 1, .6f);
|
break;
|
case E_Type.Safe:
|
Gizmos.color = Color.green;
|
break;
|
case E_Type.Union:
|
Gizmos.color = Color.blue;
|
break;
|
case E_Type.Neutral:
|
Gizmos.color = Color.red;
|
break;
|
case E_Type.Alliance:
|
Gizmos.color = new Color(.4f, .2f, 1);
|
break;
|
case E_Type.Dazuo:
|
Gizmos.color = Color.yellow;
|
break;
|
default:
|
if (_type >= 3000)
|
{
|
Gizmos.color = Color.black;
|
}
|
break;
|
}
|
|
|
if (m_IsHeroInside)
|
{
|
Gizmos.DrawWireCube(transform.position, new Vector3(endPosition.x - startPosition.x, 10, endPosition.z - startPosition.z));
|
}
|
else
|
{
|
Gizmos.DrawWireCube(transform.position, new Vector3(endPosition.x - startPosition.x, 1, endPosition.z - startPosition.z));
|
}
|
|
}
|
#endif
|
|
public static bool IsInMapArea(int types, E_Type type)
|
{
|
return (types & (byte)type) != 0;
|
}
|
|
public static bool IsOutMapArea(int types, E_Type type)
|
{
|
return !IsInMapArea(types, type);
|
}
|
|
public bool IsPosIn(Vector3 pos)
|
{
|
return pos.x > startPosition.x
|
&& pos.x < endPosition.x
|
&& pos.z > startPosition.z
|
&& pos.z < endPosition.z;
|
}
|
|
public bool IsPosOut(Vector3 pos)
|
{
|
return pos.x < startPosition.x
|
|| pos.x > endPosition.x
|
|| pos.z < startPosition.z
|
|| pos.z > endPosition.z;
|
}
|
}
|