예제 #1
0
        private Vector4 GetInputs(TextureInput texInput)
        {
            Vector4 states = Vector4.zero;

            for (int i = 0; i < 4; ++i)
            {
                var state = texInput.GetChannelInput((TextureChannel)i).enabled;
                states[i] = state ? 1f : 0f;
            }

            return(states);
        }
예제 #2
0
        private Matrix4x4 GetOutputs(TextureInput texInput)
        {
            Matrix4x4 m = Matrix4x4.zero;

            for (int i = 0; i < 4; ++i)
            {
                Vector4 inChannel = Vector4.zero;
                var     output    = texInput.GetChannelInput((TextureChannel)i).output;
                inChannel[(int)output] = 1f;
                m.SetRow(i, inChannel);
            }

            return(m);
        }
예제 #3
0
        private void OnGUI()
        {
            if (_preview == null)
            {
                return;
            }

            _windowScrollPos = EditorGUILayout.BeginScrollView(_windowScrollPos, false, false);

            RefreshItems();

            GUILayout.Label(_windowTitle, TexturePackerStyles.Heading);
            GUILayout.BeginVertical(TexturePackerStyles.Section);

            GUILayout.Label("Inputs", TexturePackerStyles.Heading);
            foreach (TextureItem item in _items)
            {
                item.Draw();
            }

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("+"))
            {
                TextureInput entry = new TextureInput();
                _texturePacker.Add(entry);
                _items.Add(new TextureItem(entry));
            }
            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            int prevRes = _texturePacker.resolution;

            _texturePacker.resolution = 128;

            _preview.Draw(_texturePacker);

            _texturePacker.resolution = prevRes;

            GUILayout.Label("Options", TexturePackerStyles.Heading);
            GUILayout.BeginVertical(TexturePackerStyles.Section);
            textureFormat             = (TextureFormat)EditorGUILayout.EnumPopup("> Format:", textureFormat);
            _texturePacker.resolution = EditorGUILayout.IntPopup("> Resolution:", _texturePacker.resolution, _textureResolutionsNames.ToArray(), _textureResolutions.ToArray());
            GUILayout.EndVertical();

            if (GUILayout.Button("Generate Texture", TexturePackerStyles.Button))
            {
                string savePath = EditorUtility.SaveFilePanel("Save", Application.dataPath, "texture.png", textureFormat.ToString());
                if (savePath != string.Empty)
                {
                    Texture2D output = _texturePacker.Create();

                    if (textureFormat == TextureFormat.JPG)
                    {
                        File.WriteAllBytes(savePath, output.EncodeToJPG());
                    }
                    else if (textureFormat == TextureFormat.PNG)
                    {
                        File.WriteAllBytes(savePath, output.EncodeToPNG());
                    }
                    else if (textureFormat == TextureFormat.TGA)
                    {
                        File.WriteAllBytes(savePath, output.EncodeToTGA());
                    }
                    else
                    {
                        File.WriteAllBytes(savePath, output.EncodeToEXR());
                    }

                    AssetDatabase.Refresh();
                }
            }

            GUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }
 public TextureItem(TextureInput input)
 {
     this.input = input;
 }
예제 #5
0
 public void Remove(TextureInput input)
 {
     _texInputs.Remove(input);
 }
예제 #6
0
 public void Add(TextureInput entry)
 {
     _texInputs.Add(entry);
 }
 public void Add(TextureInput entry) => TexInputs.Add(entry);