// Start is called before the first frame update void Start() { var objects = GameObject.FindGameObjectsWithTag("User0"); foreach (var e in objects) { m_points.Add(e.transform.position); } int result = GrahamScan.Run(m_points); for (int i = 0; i < result; ++i) { GameObject obj = GameObject.Instantiate(m_instantiate); obj.transform.position = m_points[i]; } }
/// <summary> /// [CalucrateTerritory] /// Playerのテリトリーを計算する, 基本使わないこと /// 引数1: Player infomation /// </summary> public void CalucrateTerritory(PlayerInfo playerInfo) { //リストクリア playerInfo.allTerritoryPoints.Clear(); playerInfo.borderTerritorys.Clear(); playerInfo.borderTerritoryPoints.Clear(); playerInfo.territorialArea.Clear(); m_grahamResult.Clear(); //ポジション記録, ソート用リスト構築 for (int i = 0, count = playerInfo.allTerritorys.Count; i < count; ++i) { playerInfo.allTerritoryPoints.Add(playerInfo.allTerritorys[i].transform.position); m_grahamResult.Add(new GrahamScan.CustomFormat(playerInfo.allTerritoryPoints[i], i)); } //グラハムソート int result = GrahamScan.Run(m_grahamResult); if (result < m_grahamResult.Count - 1) { m_grahamResult.RemoveRange(result, m_grahamResult.Count - result); } //結果を各リストに構築 for (int i = 0; i < result; ++i) { playerInfo.borderTerritorys.Add(playerInfo.allTerritorys[m_grahamResult[i].userID]); playerInfo.borderTerritoryPoints.Add(playerInfo.allTerritoryPoints[m_grahamResult[i].userID]); } //ボリューム追加した状態でグラハムソート for (int i = 0, count = m_grahamResult.Count; i < count; ++i) { for (int k = 0, length = m_volumePoints.Length; k < length; ++k) { m_grahamResult.Add(new GrahamScan.CustomFormat(m_grahamResult[i].position + (m_volumePoints[k] * m_radiusVolume), -1)); } } result = GrahamScan.Run(m_grahamResult); //結果をリストに構築 for (int i = 0; i < result; ++i) { playerInfo.territorialArea.Add(m_grahamResult[i].position); } }
public void CalculateTerritory() { territoryPoints.Clear(); { int i = 0; foreach (var e in markPoints) { territoryPoints.Add(e.Value.gameObject.transform.position); ++i; } } int result = GrahamScan.Run(territoryPoints); if (result < territoryPoints.Count - 1) { territoryPoints.RemoveRange(result, territoryPoints.Count - result); } TerritoryManager.instance.AddVolumePoints(territoryPoints); result = GrahamScan.Run(territoryPoints); if (result < territoryPoints.Count - 1) { territoryPoints.RemoveRange(result, territoryPoints.Count - result); } Debug.Log(markPoints.Count + "+" + territoryPoints.Count); if (m_lineRenderer != null) { m_lineRenderer.positionCount = territoryPoints.Count; for (int i = 0; i < territoryPoints.Count; ++i) { m_lineRenderer.SetPosition(i, territoryPoints[i]); } } }