예제 #1
0
    public override void Initialize()
    {
        // camera 3D init
        camera = new FpsCamera(Core.screen.size);
        camera.SetPosition(new Vector3f(-20, 10, 20));
        camera.SetRotation(-Math.Pi / 10f, 3f / 4f * Math.Pi);

        // core init
        Core.mainCamera = camera;         // See "UnityBootstrap.Update()" method
        Core.graphics.ClearAuto(true, new Color32(71));

        // camera 2D init
        hudCamera = new Camera2D(Core.screen.size);
        hudCamera.SetZoom(2f);

        // materials init
        shapesMaterial  = Core.resource.CreateMaterial("Lines/Colored Blended");
        spritesMaterial = Core.resource.CreateMaterial("Unlit/Transparent");

        // grid init
        gridMesh = Models.CreateGrid(100);

        // model test init
        testtransform = new Transform3D();
        testtransform.Rotate(new Vector3f(-90f * Math.Deg2Rad, 0f, 0f));
        testmesh     = Core.resource.LoadMesh("Models/Test");
        testtexture  = Core.resource.LoadTexture("Models/lightmap");
        testmaterial = Core.resource.CreateMaterial("Unlit/Texture");
        testmaterial.Set("_MainTex", testtexture);

        // billboard init
        testtransformbillboard = new Transform3D();
        testtransformbillboard.SetPosition(new Vector3f(0, 0, 10));
        testtransformbillboard.SetLocalScale(Vector3f.one * 0.01f);
        billboard = Core.resource.LoadTexture("Sprites/tree_billboard");

        // procedural texture init
        {
            proceduralTexture = Core.resource.CreateTexture(256, 256);

            for (int x = 0; x < proceduralTexture.GetWidth(); ++x)
            {
                for (int y = 0; y < proceduralTexture.GetHeight(); ++y)
                {
                    var baseColor    = new Color((float)x / proceduralTexture.GetWidth(), 0.5f, (float)y / proceduralTexture.GetHeight());
                    var checkerColor = (new Color(1f, 1f, 1f, 0f)) * (y % 32 > 15 ? (x % 32 > 15 ? 0 : 0.2f) : (x % 32 <= 15 ? 0 : 0.2f));

                    proceduralTexture.SetPixel(x, y, baseColor - checkerColor);
                }
            }

            proceduralTexture.Apply();
        }
    }