コード例 #1
0
    public CompositorData(CompositorData otherData)
    {
        red   = otherData.red;
        green = otherData.green;
        blue  = otherData.blue;
        alpha = otherData.alpha;

        textureWidth  = otherData.textureWidth;
        textureHeight = otherData.textureHeight;
        path          = otherData.path;
    }
コード例 #2
0
    void OnWizardCreate()
    {
        string path = EditorUtility.SaveFilePanelInProject("Save Composited Data", "Composited Texture", "png", "Select Where To Save Composited Texture", compositorData.path);

        if (path.Length == 0)
        {
            if (EditorUtility.DisplayDialog("Canceling Composite", "Composite Incomplete. All Changed Settings Will Be Lost. Are You Sure You Wish To Cancel?", "Yes, Exit Without Saving", "No, Go Back"))
            {
                return;
            }
            else
            {
                CreateWizard();
                return;
            }
        }

        //selected a valid path, save the settings before continuing
        compositorData.path = path;
        lastData            = compositorData;

        Texture2D tex = new Texture2D(compositorData.textureWidth, compositorData.textureHeight);

        Color[] pixels = new Color[compositorData.textureWidth * compositorData.textureHeight];

        float uvX, uvY;
        int   pixelIndex;

        //go through the pixel grid, and get the bilinear filtered composited color for each pixel
        for (int x = 0; x < compositorData.textureWidth; x++)
        {
            uvX = x / (compositorData.textureWidth - 1f);
            for (int y = 0; y < compositorData.textureHeight; y++)
            {
                uvY = y / (compositorData.textureHeight - 1f);

                pixelIndex         = x + y * compositorData.textureWidth;
                pixels[pixelIndex] = compositorData.GetColor(uvX, uvY);
            }
        }
        tex.SetPixels(pixels);
        tex.Apply(false);

        byte[] bytes = tex.EncodeToPNG();

        File.WriteAllBytes(path, bytes);

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }