private void Awake() { if (this.Renderer == null) { this.Renderer = this.GetComponent <Renderer>(); } if (this.Renderer == null) { Debug.LogWarning("BitsyComponent requires a Renderer to render to."); this.enabled = false; return; } _surface = TextureRenderSurface.Create(this.Margin); }
public static Texture2D DrawFontToTexture(IFont font) { var text = TextureRenderSurface.CreateCustomSize(BitsyUnityUtils.TEXTUREFONT_DIM, BitsyUnityUtils.TEXTUREFONT_DIM); text.FillSurface(BitsyGame.Color.Black); for (int i = 0; i < 256; i++) { var gfx = font.GetCharGfx((char)i); int x = (i % BitsyUnityUtils.TEXTUREFONT_FONTTILE_EDGE_CNT) * BitsyUnityUtils.TEXTUREFONT_FONTTILE_DIM; int y = (i / BitsyUnityUtils.TEXTUREFONT_FONTTILE_EDGE_CNT) * BitsyUnityUtils.TEXTUREFONT_FONTTILE_DIM; gfx.Draw(0, x + 1, y, BitsyGame.Color.White, text); } return(text.Texture); }
public void RestartGame() { if (this.GameData == null || this.Renderer == null || _surface == null) { this.enabled = false; return; } //parse game var parser = new BitsyGameParser(); Environment environment; using (var reader = new System.IO.StringReader(this.GameData.text)) { environment = parser.Parse(reader, this.HanldeBitsyInput, BitsyUnityUtils.LoadTextureFont(this.FontTexture)); } if (this.UseExtensionFunctions) { environment.ScriptInterpreter.ScriptExtension = BitsyExtensionFunctions.CreateTable(); } environment.OnMessage += this.OnBitsyMessageCallback; //prepare renderer if (this.Margin != _surface.Margin) { Object.Destroy(_surface.Texture); _surface = TextureRenderSurface.Create(this.Margin); } this.Renderer.material.mainTexture = _surface.Texture; //get input _input = this.GetComponent <IBitsyInput>(); //begin game _game.Begin(environment, _surface, this.ShowTitleText); }