Skip to content

Instantly share code, notes, and snippets.

@wmiller
wmiller / Events.cs
Last active October 22, 2023 06:39
Unity3D Event System
using System.Collections;
using System.Collections.Generic;
public class GameEvent
{
}
public class Events
{
static Events instanceInternal = null;
@wmiller
wmiller / Build Map Method
Last active January 4, 2016 18:29
XML Database for Unity (Part 1) Build Map Method 1
public void BuildMap(int width, int height)
{
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
// Get a noise value
float noiseX = (float)x / width * 6.0f;
float noiseY = (float)y / height * 6.0f;
float noise = Mathf.PerlinNoise(noiseX, noiseY);
@wmiller
wmiller / gist:8661658
Created January 28, 2014 03:06
XML Database for Unity (Part 1) PlaceTile Method 1
public void PlaceTile(x, y, height)
{
string path;
if (height == 0)
{
path = "Tiles/WaterTile";
}
else if (height == 1)
{
@wmiller
wmiller / MapBuilder.cs
Created February 3, 2014 04:56
XML Database Example1 InitHeights()
private void InitHeights()
{
HeightField = new int[Width * Height];
for (int y = 0; y < Height; ++y)
{
for (int x = 0; x < Width; ++x)
{
// Compute a position in noise space
float noiseX = (float)x / Width * NoiseFrequency;
@wmiller
wmiller / MapBuilder1.cs
Last active August 29, 2015 13:55
XML Database Example1 MapBuilder1
using UnityEngine;
using System.Collections;
public class MapBuilder1 : MapBuilder
{
public int FeatureChance = 30;
public string[] TileLoadStrings;
public string[] FeatureLoadStrings;
protected override void InitMapObjects()
@wmiller
wmiller / Infos.cs
Created February 3, 2014 05:03
XML Database Example2 Infos
using UnityEngine;
using System.Collections;
using System.Xml;
using System.Xml.Serialization;
[XmlRoot]
public sealed class TileInfo : DatabaseEntry
{
[XmlElement]
public int Height { get; private set; }
@wmiller
wmiller / Infos.xml
Last active August 29, 2015 13:55
XML Database Infos XML
<Database>
<!-- Tile Infos -->
<TileInfo ID="TILE_WATER">
<Height>0</Height>
<FeatureChance>0</FeatureChance>
<PrefabPath>Tiles/TileWater</PrefabPath>
</TileInfo>
<TileInfo ID="TILE_GRASS">
<Height>1</Height>
@wmiller
wmiller / MapBuilder2.cs
Created February 3, 2014 05:06
XML Database MapBuilder2
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
public class MapBuilder2 : MapBuilder
{
protected override void InitMapObjects()
{
for (int y = 0; y < Height; ++y)
@wmiller
wmiller / MapBuilder2.cs
Created February 3, 2014 05:07
XML Database Info Loading Example
// Get all tiles in the database that match the height
TileInfo[] tileInfos = Database.Instance.GetEntries<TileInfo>().Where((info) => info.Height == height).ToArray();
@wmiller
wmiller / Database.cs
Last active August 29, 2015 13:55
XML Databse Database.cs
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Xml;
using System.Xml.Serialization;
using System.Runtime;
using System.Runtime.Serialization;
using System.Linq;