示例#1
0
    public Transmutable Lookup(Point p)
    {
        Transmutable r = null;

        entries.TryGetValue(p, out r);
        return(r);
    }
示例#2
0
 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));
             }
         }
     }
 }
示例#3
0
    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);
    }
示例#4
0
 public void AddOrReplace(Point p, Transmutable entry)
 {
     entries[p] = entry;
 }
示例#5
0
 public void Enqueue(Transmutable t, Element e)
 {
     updatesThisFrame.Add(new Entry {
         t = t, e = e
     });
 }