GetSimpleCenterPoint() public method

Gets the simple center point.
Ignores height
public GetSimpleCenterPoint ( ) : Vector3
return Vector3
示例#1
0
	/// <summary>
	/// Computes the center point based on the bounds of the tile positions.
	/// </summary>
	/// <returns>
	/// The center point.
	/// </returns>
	public IEnumerator ComputeCenterPoint()
	{
		HTTP.Request request = new HTTP.Request( "Get", WebRequests.GetURLToResourceTile(this.ids[0]) );
		request.AddParameters( WebRequests.authenticatedGodModeParameters );
		request.Send();
		while( !request.isDone ) {
			yield return 0;
		}
		
		if( request.ProducedError ) {
			Debug.LogError( "Unable to compute center point of harvest: " + request.Error );
			yield break;
		};
		ResourceTile tile = new ResourceTile();
		try {
			tile = JSONDecoder.Decode<IndividualResourceTile>(request.response.Text).resource_tile;
		}
		catch (JsonException) {
			Debug.LogError("Error parsing json data:\n"+request.response.Text);
		}
		Bounds bounds = new Bounds(tile.GetSimpleCenterPoint(), new Vector3(1f,0f,1f));
		foreach (int id in this.ids) {
			request = new HTTP.Request( "Get", WebRequests.GetURLToResourceTile(id) );
			request.AddParameters( WebRequests.authenticatedGodModeParameters );
			request.Send();
			
			while( !request.isDone ) {
				yield return 0;
			}
			
			if( request.ProducedError ) {
				Debug.LogError( "Unable to compute center point of harvest: " + request.Error );
				yield break;
			}
			try {
				tile = JSONDecoder.Decode<IndividualResourceTile>(request.response.Text).resource_tile;
				bounds.Encapsulate(tile.GetSimpleCenterPoint());
			}
			catch (JsonException) {
				Debug.LogError("Error parsing json data:\n"+request.response.Text);
			}
		}
		// set the center point from the bounding box
		this.centerPoint = bounds.center;
	}