// Use this for initialization void Start() { #region Basic Initialization terrain = gameObject.GetComponent <Terrain>(); maxTraversableSlope *= Mathf.Min(gridXPercentage, gridYPercentage); terrainXGrid = 100f / gridXPercentage; terrainYGrid = 100f / gridYPercentage; gridXSpacing = terrainX / 100f * gridXPercentage; gridYSpacing = terrainY / 100f * gridYPercentage; #endregion #region Algorithm //Create grid of heights grid = new float[(int)terrainXGrid, (int)terrainYGrid]; for (int x = 0; x < terrainXGrid; x++) { for (int y = 0; y < terrainYGrid; y++) { grid[x, y] = terrain.SampleHeight(new Vector3(x * gridXSpacing + gridXSpacing / 2f, 0, y * gridYSpacing + gridYSpacing / 2f)); } } //Create a new analyzer analyzer = new Analyzer(grid, gridXSpacing, gridYSpacing, maxReachableHeight, maxTraversableSlope); //Convert a pruned Voronoi to VoronoiGraph convertToVoronoiGraph(pruneVoronoi(analyzer.getVEdgeList())); //Calculate the radius of each node foreach (VoronoiNode node in workingVoronoi) { node.setRadius(computeRadius(node)); } //Perform culling algorithms cullVeronoi(); #endregion //Set up Analysis Graph analysisGraph = getAnalysisGraph(); //ROB!! /* * Calling addAttribute() lets you put in an interface of type IAttribute. I have given you two examples below. * * ChokeValue's constructor ONLY takes a string because caluations to get choke value can be done without calling unity functions. * * UpHill's constructor takes a string and a HillCalculator. It's annoying, but this is necessary because it requires MonoBehaviour to do it's calculations. * Whenever you're trying to make an attribute that requires extra infomation from the gameworld, you need to make it like UpHill. Basically you need another * MonoBehaviour Object (Like hill Calculator), and you need to attach it to the terrain you'r analyzing. Again this is annoying but it's necessary because * of how unity objects work. Take a look at upHill and you should see how it's working. */ analysisGraph.addAttribute(new ChokeValue("choke")); HillCalculator calc = gameObject.GetComponent <HillCalculator>(); calc.getTerrain(); analysisGraph.addAttribute(new UpHill("hill", calc)); }
public UpHill(string pId, HillCalculator pCalculator) { id = pId; calculator = pCalculator; }