136 lines
4.5 KiB
C#
136 lines
4.5 KiB
C#
|
using Thousandto.Code.Logic;
|
|||
|
using Thousandto.Core.Asset;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Thousandto.Code.Center
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 场景遮挡剔除
|
|||
|
/// </summary>
|
|||
|
public class SceneOcSystem
|
|||
|
{
|
|||
|
#region//私有变量
|
|||
|
//是否初始化完成
|
|||
|
private bool _isLoadFinish = false;
|
|||
|
private int _colRow = 0;
|
|||
|
//当前玩家所处的视口id
|
|||
|
private int _curProtalId = 0;
|
|||
|
private List<int> _idList = new List<int>();
|
|||
|
private Dictionary<int, List<string>> _dicOcData = new Dictionary<int, List<string>>();
|
|||
|
private Dictionary<string, Transform> _dicTrans = new Dictionary<string, Transform>();
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//属性
|
|||
|
public bool IsLoadFinish
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _isLoadFinish;
|
|||
|
}
|
|||
|
}
|
|||
|
public Dictionary<int, List<string>> DicOcData
|
|||
|
{
|
|||
|
get
|
|||
|
{
|
|||
|
return _dicOcData;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//公共函数
|
|||
|
//加载数据
|
|||
|
public void LoadParam()
|
|||
|
{
|
|||
|
LoadScriptAsset();
|
|||
|
}
|
|||
|
//检查物件是否被遮挡剔除
|
|||
|
public bool CheckOc( Transform trans )
|
|||
|
{
|
|||
|
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|||
|
if (lp == null)
|
|||
|
return true;
|
|||
|
//UnityEngine.Debug.LogError(string.Format("玩家在视口: {0} 处", _curProtalId));
|
|||
|
if (_dicOcData.ContainsKey(_curProtalId))
|
|||
|
{
|
|||
|
string path = string.Empty;
|
|||
|
path = GetTransPath(trans, path);
|
|||
|
List<string> listPath = _dicOcData[_curProtalId];
|
|||
|
if (listPath != null)
|
|||
|
{
|
|||
|
if (listPath.Contains(path))
|
|||
|
return true;
|
|||
|
}
|
|||
|
else
|
|||
|
return false;
|
|||
|
}
|
|||
|
else
|
|||
|
return false;
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
public void Update()
|
|||
|
{
|
|||
|
//判断玩家视口是否改变了
|
|||
|
LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer();
|
|||
|
if (lp != null)
|
|||
|
{
|
|||
|
int protalId = GetPortalId(lp);
|
|||
|
if (_curProtalId != protalId)
|
|||
|
{
|
|||
|
_curProtalId = protalId;
|
|||
|
//玩家所在视口发生了变化 更新物件的遮挡剔除
|
|||
|
//GameCenter.SceneRestoreSystem.Update();
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
#region//私有函数
|
|||
|
private void LoadScriptAsset()
|
|||
|
{
|
|||
|
string name = GameCenter.GameSceneSystem.GetActivedScene().Cfg.LevelName;
|
|||
|
string path = string.Format("Scene/OcclusionCulling/{0}_OcMapScript", name);
|
|||
|
ResourcesEx.LoadAsync(path, AssetTypeCode.None, (o, b, err) =>
|
|||
|
{
|
|||
|
if (o is ScriptableObject)
|
|||
|
{
|
|||
|
var asset = o as ScriptableObject;
|
|||
|
Type type = o.GetType();
|
|||
|
OcMapDataProxy proxy = new OcMapDataProxy(type, asset);
|
|||
|
proxy.SetOcMapData(_dicOcData, _idList);
|
|||
|
if (_idList != null && _idList.Count > 0)
|
|||
|
_colRow = _idList[0];
|
|||
|
_isLoadFinish = true;
|
|||
|
}
|
|||
|
}, AsyncActionType.LoadObject);
|
|||
|
}
|
|||
|
|
|||
|
private int GetPortalId(LocalPlayer lp)
|
|||
|
{
|
|||
|
//int row = (int)Math.Floor((lp.Position.z - GameCenter.SceneRestoreSystem.Min.y) / (GameCenter.SceneRestoreSystem.Max.y - GameCenter.SceneRestoreSystem.Min.y) * _colRow);
|
|||
|
//int col = (int)Math.Floor((lp.Position.x - GameCenter.SceneRestoreSystem.Min.x) / (GameCenter.SceneRestoreSystem.Max.x - GameCenter.SceneRestoreSystem.Min.x) * _colRow);
|
|||
|
//int cel = row * _colRow + col;
|
|||
|
//return cel;
|
|||
|
return 0;
|
|||
|
}
|
|||
|
|
|||
|
private string GetTransPath(Transform trans, string path)
|
|||
|
{
|
|||
|
if (trans == null)
|
|||
|
return path;
|
|||
|
if (string.IsNullOrEmpty(path))
|
|||
|
path = string.Format("{0}", trans.name);
|
|||
|
else
|
|||
|
path = string.Format("{0}/{1}", trans.name, path);
|
|||
|
if (string.Equals(trans.name, "SceneRoot"))
|
|||
|
return path;
|
|||
|
return GetTransPath(trans.parent, path);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
|