/// <summary> /// 计算并存储所有被照亮的边缘 /// </summary> public void CalcLightedEdges(List<GameObject> wallTiles, Vector2 lightPos) { Init(wallTiles); //1.基于edge中点与光源的距离与所在tile与光源的距离,筛出朝向光源的edge for (int i = 0; i < _listEdges.Count; i++) { if (_listEdges[i].CalcLightDistance(lightPos)) { _listLightedEdges.Add(_listEdges[i]); } } //2.移除两个块之间夹着的edge CleanInsideEdges(); //3.按照edge之间的相连关系,设置他们的prev和next for (int i = 0; i < _listLightedEdges.Count; i++) { Edge edge = _listLightedEdges[i]; for (int j = 0; j < _listLightedEdges.Count; j++) { Edge another = _listLightedEdges[j]; if (edge.PointEnd.Equals(another.PointStart)) { edge.Next = another; another.Prev = edge; break; } } } //4.按distance由近及远排序 _listLightedEdges.Sort((x, y) => { if (x.Distance < y.Distance) return -1; if (x.Distance > y.Distance) return 1; return 0; }); //5.进行射线切割 SliceEdges(lightPos); //6.清理无头无尾的edge CleanIsolatedEdges(); if (action != null) { DataShadow data = new DataShadow { LightedEdges = _listLightedEdges.ToArray() }; action(data); } }
public void OnReceiveShadowData(DataShadow data) { _data = data; UpdateLineParams(); }
/// <summary> /// 计算并存储所有被照亮的边缘 /// </summary> public void CalcLightedEdges(List <GameObject> wallTiles, Vector2 lightPos) { Init(wallTiles); //1.基于edge中点与光源的距离与所在tile与光源的距离,筛出朝向光源的edge for (int i = 0; i < _listEdges.Count; i++) { if (_listEdges[i].CalcLightDistance(lightPos)) { _listLightedEdges.Add(_listEdges[i]); } } //2.移除两个块之间夹着的edge CleanInsideEdges(); //3.按照edge之间的相连关系,设置他们的prev和next for (int i = 0; i < _listLightedEdges.Count; i++) { Edge edge = _listLightedEdges[i]; for (int j = 0; j < _listLightedEdges.Count; j++) { Edge another = _listLightedEdges[j]; if (edge.PointEnd.Equals(another.PointStart)) { edge.Next = another; another.Prev = edge; break; } } } //4.按distance由近及远排序 _listLightedEdges.Sort((x, y) => { if (x.Distance < y.Distance) { return(-1); } if (x.Distance > y.Distance) { return(1); } return(0); }); //5.进行射线切割 SliceEdges(lightPos); //6.清理无头无尾的edge CleanIsolatedEdges(); if (action != null) { DataShadow data = new DataShadow { LightedEdges = _listLightedEdges.ToArray() }; action(data); } }
public void OnReceiveShadowData(DataShadow data) { _data = data; UpdateLineParams(); }