private void ErrorDisplay()
        {
            if (error != Texture3DEditorError.None)
            {
                EditorGUILayout.HelpBox(texture3DEditorErrorDescriptions[(uint)error], MessageType.Info);
            }

            // Error has been displayed to user.
            // Clear error to allow user an opportunity to make changes.
            error = Texture3DEditorError.None;
        }
        private static Texture3DEditorError ComputeTexture3DFromTextureSlices(ref Texture3D res, List <Texture2D> textureSlices, List <Color[]> textureSlicesData, Texture3DSettings settings)
        {
            if (textureSlices.Count == 0)
            {
                return(Texture3DEditorError.NoSlicesSpecified);
            }
            for (int i = 0, iLen = textureSlices.Count; i < iLen; ++i)
            {
                if (textureSlices[i] == null)
                {
                    return(Texture3DEditorError.NoTextureAssigned);
                }
            }

            Color[] data = new Color[settings.width * settings.height * settings.depth];
            res = new Texture3D(
                settings.width,
                settings.height,
                settings.depth,
                Texture3DEditor.GetTextureFormat(settings.textureFormatValid),
                settings.isMipmapEnabled
                );
            res.wrapMode   = Texture3DEditor.GetTextureWrapMode(settings.textureWrapModeValid);
            res.filterMode = Texture3DEditor.GetTextureFilterMode(settings.filterModeValid);
            res.anisoLevel = settings.anisoLevel;

            Debug.Assert((int)settings.resampleMode >= 0 && settings.resampleMode < ResampleMode.Count);
            Texture3DEditorError error = Texture3DEditorError.None;

            switch (settings.resampleMode)
            {
            case ResampleMode.Nearest:
                error = ResampleNearest(ref data, textureSlices, textureSlicesData, settings);
                break;

            case ResampleMode.Trilinear:
                error = ResampleTrilinear(ref data, textureSlices, textureSlicesData, settings);
                break;

            default:
                break;
            }
            if (error != Texture3DEditorError.None)
            {
                return(error);
            }
            res.SetPixels(data, 0);
            res.Apply(settings.isMipmapEnabled);
            return(Texture3DEditorError.None);
        }
        private Texture3DEditorError ComputeAndDisplayTextureSlices(ref List <Texture2D> slices, ref List <Color[]> slicesData)
        {
            if (slices == null)
            {
                slices = new List <Texture2D>();
            }
            if (slicesData == null)
            {
                slicesData = new List <Color[]>();
            }

            Texture3DEditorError error = Texture3DEditorError.None;

            isTextureSlicesDisplayed = EditorGUILayout.Foldout(isTextureSlicesDisplayed, GUI_NAME_IS_TEXTURE_SLICES_DISPLAYED);
            if (isTextureSlicesDisplayed)
            {
                EditorGUILayout.BeginVertical();
                ++EditorGUI.indentLevel;

                // Place slice add button outside of scroll view to make it always visible regardless of scroll position.
                if (GUILayout.Button(GUI_NAME_TEXTURE_SLICE_ADD))
                {
                    slices.Add(null);
                    slicesData.Add(null);
                }

                textureSliceScrollPosition = EditorGUILayout.BeginScrollView(textureSliceScrollPosition);
                {
                    int indexRemoval = -1;
                    for (int i = 0, iLen = slices.Count; i < iLen; ++i)
                    {
                        ++EditorGUI.indentLevel;
                        EditorGUILayout.BeginHorizontal();

                        // TODO: Creating garbage with this int to string conversion.
                        // Could create a static readonly string lut given that iLen is <= 64.
                        EditorGUILayout.SelectableLabel(i.ToString());

                        if (GUILayout.Button(GUI_NAME_TEXTURE_SLICE_REMOVE))
                        {
                            indexRemoval = i;
                        }

                        Texture2D slicePrevious = slices[i];
                        slices[i] = (Texture2D)EditorGUILayout.ObjectField((slices[i] != null) ? slices[i].name : GUI_NAME_TEXTURE_SLICE_TEXTURE, slices[i], typeof(Texture2D), true);
                        if (slices[i] != null && slices[i] != slicePrevious)
                        {
                            // Different texture was assigned. Grab the pixel data for use in resampling.
                            slicesData[i] = slices[i].GetPixels(0, 0, slices[i].width, slices[i].height);
                        }

                        // Texture2D slice source must be readable in order to access data via GetPixel functions.
                        // TODO: 18.3 adds Texture2D.isReadable flag which will allow us to report error to user.
                        // if (slices[i] != null && !(slices[i].isReadable))
                        // {
                        //     error = (error != Texture3DEditorError.None) ? Texture3DEditorError.SliceUnreadable : error;
                        // }

                        EditorGUILayout.EndHorizontal();
                        --EditorGUI.indentLevel;
                    }
                    if (indexRemoval >= 0)
                    {
                        slices.RemoveAt(indexRemoval);
                        slicesData.RemoveAt(indexRemoval);
                    }
                }

                EditorGUILayout.EndScrollView();
                --EditorGUI.indentLevel;
                EditorGUILayout.EndVertical();
            }

            return(error);
        }
 private bool ErrorCapture(Texture3DEditorError errorNext)
 {
     error = (error == Texture3DEditorError.None) ? errorNext : error;
     return(!(error == Texture3DEditorError.None));
 }