/// <summary> /// Load all assets /// </summary> public void LoadAll() { soundHitBrick.Load("Demos/BrickBust/Sounds/hit"); soundHitWall.Load("Demos/BrickBust/Sounds/hit2"); soundExplode.Load("Demos/BrickBust/Sounds/explode"); soundDeath.Load("Demos/BrickBust/Sounds/death"); soundStart.Load("Demos/BrickBust/Sounds/start"); soundPowerUp.Load("Demos/BrickBust/Sounds/powerup"); soundLaserShot.Load("Demos/BrickBust/Sounds/lasershot"); soundLaserHit.Load("Demos/BrickBust/Sounds/laserhit"); musicMenu.Load("Demos/BrickBust/Music/BossFight"); musicLevel.Load("Demos/BrickBust/Music/Stage2"); // You can load a spritesheet here spriteSheet.Load("Demos/BrickBust/Sprites"); spriteSheet.grid = new SpriteGrid(new Vector2i(10, 10)); RB.SpriteSheetSet(spriteSheet); shaderShadow.Load("Demos/BrickBust/DrawShaderShadow"); shaderShadow.SpriteSheetTextureSet("_SpritesTexture", spriteSheet); }
private void DrawTMX(int x, int y) { var demo = (DemoReel)RB.Game; if (mMap != null) { RB.Offscreen(spriteSheet3); RB.DrawRectFill(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height), DemoUtil.IndexToRGB(22)); RB.DrawMapLayer(0); RB.DrawMapLayer(1); RB.Offscreen(spriteSheet4); RB.Clear(new Color32(0, 0, 0, 0)); RB.SpriteSheetSet(spriteSheet2); RB.DrawSprite(0, new Vector2i((int)mBouncePos.x, (int)mBouncePos.y), mVelocity.x > 0 ? RB.FLIP_H : 0); RB.Onscreen(); RB.ShaderSet(shader1); shader1.SpriteSheetTextureSet("Mask", spriteSheet4); shader1.FloatSet("Wave", RB.Ticks / 10.0f); shader1.SpriteSheetFilterSet(spriteSheet4, RB.Filter.Linear); RB.SpriteSheetSet(spriteSheet3); RB.DrawCopy(new Rect2i(0, 0, RB.DisplaySize.width, RB.DisplaySize.height), Vector2i.zero); RB.ShaderReset(); RB.SpriteSheetSet(spriteSheet1); } else { RB.Print(new Vector2i(x, y + 250), DemoUtil.IndexToRGB(14), "Failed to load TMX map.\nPlease try re-importing the map Demos/DemoReel/Tilemap.tmx in Unity"); } string shaderName = "WavyMaskShader"; mFormatStr.Set("@C// Custom shaders can be used for many things, like masking!\n"); mFormatStr.Append("@NmyShader.Load(@S\"Demos/DemoReel/").Append(shaderName).Append("\"@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Draw a tilemap to one offscreen surface\n"); mFormatStr.Append("@[email protected](myOffscreenSurface1);\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N,\n"); mFormatStr.Append(" @[email protected], @[email protected]),\n"); mFormatStr.Append(" @I22@N);\n"); mFormatStr.Append("@[email protected](@L0@N);\n"); mFormatStr.Append("@[email protected](@L1@N);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Draw a mask to the other offscreen surface\n"); mFormatStr.Append("@[email protected](myOffscreenSurface2);\n"); mFormatStr.Append("@[email protected](@Knew @MColor32@N(@L0@N, @L0@N, @L0@N, @L0@N));\n"); mFormatStr.Append("@[email protected](@NmyGhostMaskSpriteSheet);\n"); mFormatStr.Append("@[email protected](@L0@N, @Knew @MVector2i@N(@L").Append((int)mBouncePos.x).Append("@N, @L").Append((int)mBouncePos.y).Append("@N)").Append(mVelocity.x > 0 ? ", RB.FLIP_H" : string.Empty).Append(");\n"); mFormatStr.Append("\n"); mFormatStr.Append("@C// Use a custom shader to combine the two!\n"); mFormatStr.Append("@[email protected]();\n"); mFormatStr.Append("@[email protected](@NmyShader);\n"); mFormatStr.Append("@NmyShader.SpriteSheetTextureSet(@S\"Mask\"@N, myOffscreenSurface2);\n"); mFormatStr.Append("@NmyShader.FloatSet(@S\"Wave\"@N, @L").Append(RB.Ticks / 10.0f, 2).Append("f@N);\n"); mFormatStr.Append("@NmyShader.SpriteSheetFilterSet(myOffscreenSurface2, @MRB@N.@[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected](@NmyOffscreenSurface1);\n"); mFormatStr.Append("@[email protected](@Knew @MRect2i@N(@L0@N, @L0@N,\n @[email protected], @[email protected]),\n @[email protected]);\n"); mFormatStr.Append("\n"); mFormatStr.Append("@[email protected]();\n"); DemoUtil.HighlightCode(mFormatStr, mCodeStr); mFormatStr.Set("@C// This shader multiplies in a mask and applies a wavy effect!\n"); mFormatStr.Append("@KShader@N \"Unlit/").Append(shaderName).Append("\" {\n"); mFormatStr.Append(" @KSubShader@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @KPass@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @C/*** Insert custom shader variables here ***/\n"); mFormatStr.Append(" @Ksampler2D@N Mask;\n"); mFormatStr.Append(" @Kfloat@N Wave;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Nfrag_in vert(vert_in v, @Kout float4@N screen_pos : @MSV_POSITION@N) {\n"); mFormatStr.Append(" @C...@N\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @Kfloat4@N frag(frag_in i, @MUNITY_VPOS_TYPE@N screen_pos : @MVPOS@N) : @MSV_Target@N {\n"); mFormatStr.Append(" @C...\n"); mFormatStr.Append(" @C/*** Insert custom fragment shader code here ***/@N\n"); mFormatStr.Append(" @C// Sample the mask texture@N\n"); mFormatStr.Append(" i.uv.x += sin(Wave + i.uv.y * @L8@N) * @L0.025@N;\n"); mFormatStr.Append(" i.uv.y += cos(Wave - i.uv.x * @L8@N) * @L0.015@N;\n"); mFormatStr.Append(" @Kfloat4@N mask_color = @Mtex2D@N(Mask, i.uv).rgba;\n"); mFormatStr.Append("\n"); mFormatStr.Append(" @C// Multiply the sprite pixel by mask color@N\n"); mFormatStr.Append(" @Kreturn@N sprite_pixel_color * mask_color;\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append(" }\n"); mFormatStr.Append("}\n"); DemoUtil.HighlightCode(mFormatStr, mShaderStr); RB.Print(new Vector2i(x, y), DemoUtil.IndexToRGB(5), mCodeStr); RB.Print(new Vector2i(x + 300, y), DemoUtil.IndexToRGB(5), mShaderStr); }