-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_ex0.html
63 lines (63 loc) · 6.85 KB
/
_ex0.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.14"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>HexMapLibrary: Example 0: Hello hex world</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">HexMapLibrary
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.14 -->
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',false,false,'search.php','Search');
});
/* @license-end */</script>
<div id="main-nav"></div>
<div id="nav-path" class="navpath">
<ul>
<li class="navelem"><a class="el" href="index.html">HexMap Library Documentation</a></li> </ul>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Example 0: Hello hex world </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The first step of almost every project will be to create the map or board of the game. To do that we first need to import our library into unity (Menubar -> Assets -> Import Package -> Custom Package -> Select the HexMapLibrary.unitypackage file). For now we recommend importing the example folder as they include a hexagon mesh and some other sample prefabs which we use in the following tutorials.</p>
<p>The next step is creating a new script file and reference the needed namespaces of our library: </p><div class="fragment"><div class="line"><span class="keyword">using</span> <a class="code" href="namespace_system.html">System</a>.Collections;</div><div class="line"><span class="keyword">using</span> <a class="code" href="namespace_system.html">System</a>.Collections.Generic;</div><div class="line"><span class="keyword">using</span> <a class="code" href="namespace_unity_engine.html">UnityEngine</a>;</div><div class="line"><span class="keyword">using</span> <a class="code" href="namespace_wunderwunsch.html">Wunderwunsch</a>.<a class="code" href="namespace_wunderwunsch_1_1_hex_map_library.html">HexMapLibrary</a>;</div><div class="line"><span class="keyword">using</span> <a class="code" href="namespace_wunderwunsch.html">Wunderwunsch</a>.<a class="code" href="namespace_wunderwunsch_1_1_hex_map_library.html">HexMapLibrary</a>.<a class="code" href="namespace_wunderwunsch_1_1_hex_map_library_1_1_generic.html">Generic</a>;</div></div><!-- fragment --><p>Now we create some variables which we can set in the inspector: the map size and the gameObject we use to represent each tile. [TODO :Explanation of the gameObject and it's material/shader] </p><div class="fragment"><div class="line">[SerializeField] <span class="keyword">private</span> Vector2Int mapSize = <span class="keyword">new</span> Vector2Int(11, 11); <span class="comment">// the mapSize, can be set in inspector </span></div><div class="line">[SerializeField] <span class="keyword">private</span> GameObject tilePrefab = null; <span class="comment">// the prefab we use for each Tile -> use TilePrefab.prefab [TODO check if that is the correct name]</span></div><div class="line"><span class="keyword">private</span> HexMap<int> hexMap; <span class="comment">// our map. For this example we create a map where an integer represents the data of each tile</span></div></div><!-- fragment --><p>Then we can create our map. For this simple example we want each tile to represent an integer and we want the map to be rectangular and do not want it be wrapping around. <br />
</p><div class="fragment"><div class="line"><span class="keywordtype">void</span> Start ()</div><div class="line">{</div><div class="line"> HexMap = <span class="keyword">new</span> HexMap<int>(HexMapBuilder.CreateRectangularShapedMap(mapSize), null); <span class="comment">//creates a HexMap using one of the pre-defined shapes in the static MapBuilder Class </span></div><div class="line"> </div><div class="line"> <span class="keywordflow">foreach</span> (var tile <span class="keywordflow">in</span> hexMap.Tiles) <span class="comment">//loops through all the tiles, assigns them a random value and instantiates and positions a gameObject for each of them.</span></div><div class="line"> {</div><div class="line"> GameObject instance = GameObject.Instantiate(tilePrefab);</div><div class="line"> instance.transform.position = tile.CartesianPosition;</div><div class="line"> }</div><div class="line">}</div></div><!-- fragment --><p>Now let's set change the settings of our camera so we can see the whole map and center it: </p><div class="fragment"><div class="line"><span class="comment">//put the following at the end of the start method (or in its own method called after map creation)</span></div><div class="line">Camera.main.transform.position = <span class="keyword">new</span> Vector3(hexMap.MapSizeData.center.x, 4, hexMap.MapSizeData.center.z); <span class="comment">// centers the camera and moves it 5 units above the XZ-plane</span></div><div class="line">Camera.main.orthographic = <span class="keyword">true</span>; <span class="comment">//for this example we use an orthographic camera.</span></div><div class="line">Camera.main.transform.rotation = Quaternion.Euler(90, 0, 0); <span class="comment">//rotates the camera to it looks at the XZ-plane</span></div><div class="line">Camera.main.orthographicSize = hexMap.MapSizeData.extents.z * 2 * 0.8f; <span class="comment">// sets orthographic size of the camera.]</span></div><div class="line"><span class="comment">//this does not account for aspect ratio but for our purposes it works good enough.</span></div></div><!-- fragment --><p> You should end up with something looking like this: </p><div class="image">
<img src="Ex0.png" alt="Ex0.png"/>
</div>
<p> This concludes this example, now let's continue with the next [ADD LINK] </p>
</div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by  <a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.14
</small></address>
</body>
</html>