public void SetBlock(int x, int y, JSBlockType blockType) { Map[x, y] = blockType; //Loop through all blocks objects, see if we have to update or add one GameObject foundBlock = null; foreach (var block in GameObject.FindGameObjectsWithTag("Block")) { if (Mathf.Approximately(block.transform.position.x, x) && Mathf.Approximately(block.transform.position.y, y)) { foundBlock = block; break; } } if (foundBlock == null) { foundBlock = (GameObject)Instantiate(BlockPrefab, new Vector3(x, y, 0), Quaternion.identity); } if (blockType.Material == null) { blockType.Material = new Material(BaseBlockMaterial); } //This part is inefficient, should be done with an observer blockType.Material.SetColor("_Color", new Color((float)blockType.Red / 255, (float)blockType.Green / 255, (float)blockType.Blue / 255)); foundBlock.renderer.material = blockType.Material; }
private Color GetColor(JSBlockType jColor) { int red = jColor.Red; int green = jColor.Green; int blue = jColor.Blue; return new Color(red / 255f, green / 255f, blue / 255f); }
public JSBlockType BlockType(string name) { if (context.BlockTypes.ContainsKey(name)) { return context.BlockTypes[name]; } else { JSBlockType blockType = new JSBlockType(Engine, name); context.BlockTypes.Add(name, blockType); return blockType; } }
public BlockChangedEventArgs(int x, int y, JSBlockType blockType) { X = x; Y = y; BlockType = blockType; }
public void Set(int x, int y, JSBlockType blockType) { Map[x,y] = blockType; BlockChanged(this, new BlockChangedEventArgs(x, y, blockType)); }
public JSMap(ScriptEngine engine) : base(engine) { Map = new JSBlockType[128, 128]; this.PopulateFunctions(); }