示例#1
0
    public void FinishPainting()
    {
        playerCharTransition.MakeTransition();
        DoneButton.SetActive(false);
        CameraController.camera.GetComponent <Es.InkPainter.Sample.MousePainter>().enabled = false;
        ReplayButton.SetActive(true);

        Texture texture = PaintWall.GetComponent <MeshRenderer>().materials[0].GetTexture("_BaseMap");

        RenderTexture.active = texture as RenderTexture;
        Texture2D tx = new Texture2D(texture.width, texture.height);

        tx.ReadPixels(new Rect(0, 0, tx.width, tx.height), 0, 0);
        tx.Apply();
        //Texture2D tx = texture as Texture2D;  // Texture2D.CreateExternalTexture(texture.width, texture.height, TextureFormat.RGBA32, true, false, texture.GetNativeTexturePtr());

        int redCount = 0;

        for (int x = 0; x < tx.width; x++)
        {
            for (int y = 0; y < tx.height; y++)
            {
                if (tx.GetPixel(x, y) == Color.red)
                {
                    redCount++;
                }
            }
        }
        float percent = redCount * 100 / (texture.width * texture.height);

        messager.ShowMessage("You've drawn " + percent + "% of the canvas", 10f);
        Debug.Log("You've drawn " + percent + "% of the canvas");
    }
        //Called after the window and OpenGL are initialized. Called exactly once, before the main loop.
        protected override void init()
        {
            g_fzNear = 10.0f;
            g_fzFar = 1000.0f;
            frontWall = new PaintWall();
            backWall = new PaintWall();
            topWall = new PaintWall();
            bottomWall = new PaintWall();
            leftWall = new PaintWall();
            rightWall = new PaintWall();
            InitializeProgram();

            ball = new Ball(ballRadius);
            ball.SetLimits(ballLimitLow, ballLimitHigh);
            ballSpeed = new Vector3(
                ballSpeedFactor + ballSpeedFactor * (float)random.NextDouble(),
                ballSpeedFactor + ballSpeedFactor * (float)random.NextDouble(),
                ballSpeedFactor + ballSpeedFactor * (float)random.NextDouble());
            ball.SetSpeed(ballSpeed);
            //ball.SetProgram(ballProgram);

            try
            {
                g_unitSphereMesh = new Mesh("unitsphere12.xml");

            } catch (Exception ex) {
                throw new Exception("Error " + ex.ToString());
            }

            SetupDepthAndCull();
            Textures.EnableTextures();

            Camera.Move(0f, 0f, 0f);
            Camera.MoveTarget(0f, 0f, 0.0f);
            reshape();
            current_mesh = g_unitSphereMesh;
            frontWall.Move(0f, 0f, 1f);
            frontWall.Scale(50f);

            backWall.Move(0f, 0f, -1f);
            backWall.Scale(50f);

            leftWall.Move(-1f, 0f, 0f);
            leftWall.Scale(50f);
            leftWall.RotateShape(Vector3.UnitY, 90f);
            rightWall.Move(1f, 0f, 0f);
            rightWall.Scale(50f);
            rightWall.RotateShape(Vector3.UnitY, -90f);

            topWall.Move(0f, 1f, 0f);
            topWall.Scale(50f);
            topWall.RotateShape(Vector3.UnitX, 90f);
            bottomWall.Move(0f, -1f, 0f);
            bottomWall.Scale(50f);
            bottomWall.RotateShape(Vector3.UnitX, -90f);
        }