public Transmutable Lookup(Point p) { Transmutable r = null; entries.TryGetValue(p, out r); return(r); }
protected void UpdateFiring() { if (Input.GetMouseButtonDown(0)) { var hit = Raycast(); if (hit.HasValue) { var transmutable = hit.Value.collider.GetComponentInParent <Transmutable>(); if (transmutable != null) { transmutable.Apply(selected); } } } if (Input.GetMouseButtonDown(1)) { var hit = Raycast(); if (hit.HasValue) { if (selected == Element.Fire) { Transmutable.Spawn <Fire>(VoxelStorage.Vector.OfVector3(hit.Value.point)); } else if (selected == Element.Water) { Transmutable.Spawn <Water>(VoxelStorage.Vector.OfVector3(hit.Value.point)); } } } }
public static T Spawn <T>(VoxelStorage.Point point) where T : Transmutable { GameObject gameObject; { Transmutable prev = VoxelStorage.instance.Lookup(point); if (prev != null) { gameObject = prev.gameObject; Destroy(prev); } else { gameObject = Instantiate(Resources.Load <GameObject>("Transmutable"), point.ToVector3(), Quaternion.identity); } } var spawned = gameObject.AddComponent <T>(); spawned.point = point; VoxelStorage.instance.AddOrReplace(point, spawned); UpdateNeighbors(point, spawned.GetElement()); return(spawned); }
public void AddOrReplace(Point p, Transmutable entry) { entries[p] = entry; }
public void Enqueue(Transmutable t, Element e) { updatesThisFrame.Add(new Entry { t = t, e = e }); }