diff --git a/Gallery/Perlin.png b/Gallery/Perlin.png
new file mode 100644
index 0000000..03e3897
Binary files /dev/null and b/Gallery/Perlin.png differ
diff --git a/Gallery/perlin2.png b/Gallery/perlin2.png
new file mode 100644
index 0000000..056d3ea
Binary files /dev/null and b/Gallery/perlin2.png differ
diff --git a/Readme.md b/Readme.md
index 13096a1..8a65603 100644
--- a/Readme.md
+++ b/Readme.md
@@ -25,3 +25,8 @@ By Defining shapes relative to the canvas, you can rescale the canvas at will to
SpriteMaker isn't meant to make fullscale art assets, but I like to push what I can do with it
![Man](Gallery/Man.png)
+
+SpriteMaker can be used to make Noise maps right in the editor (more noise coming soon). Noise can also be a neat effect for static textures.
+![Perlin](Gallery/perlin2.png)
+![Perlin Two](Gallery/Perlin.png)
+
diff --git a/Roadmap.md b/Roadmap.md
index 608b088..f9ab236 100644
--- a/Roadmap.md
+++ b/Roadmap.md
@@ -9,35 +9,34 @@
5. Add Draw Command Functionality
6. Remove Draw Command Functionality
7. Draw Commands: Fill, Rectangle, Circle, Rounded Rectangle
+8. Rearrange Draw Command
+9. Hide Draw Command
+10. Blend Modes
+11. Collapse Views
+12. Auto previes
+13. Saving, Loading, Serialization of Scriptable Objects (working files)
+14. Undo
+15. Noise Draw Commands: Perlin
-##In Progress
-
-**v 0.2**
-1. Rearrange Draw Command
-2. Hide Draw Command
-3. Blend Modes
-4. Collapse View
-5. Visibility Toggle
-6. Auto preview
-
-##Planned
+##In Progress
-**v 0.3**
+1. Gradient Fill
+2. Voronoi
+3. Fixes to RoundedRect sizing
+4. Other Noise
-1. Save and load DrawCommand Queues
##As Needed
1. N-Gon Draw Command
2. Line Draw Command
3. Star Draw Command
-4. Perlin Noise Draw Command
-5. Gradient Fill Draw Command
+4. Gradient Fill Draw Command
##Research Required
1. Masking
2. Effects (Blur, Glow, Invert)
-3. Undo
\ No newline at end of file
+3. N-Gon visual Editor
\ No newline at end of file
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/BaseDrawCommand.cs b/SpriteMaker/Assets/SpriteMaker/Editor/BaseDrawCommand.cs
index 250beb6..a99cae0 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/BaseDrawCommand.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/BaseDrawCommand.cs
@@ -1,120 +1,170 @@
using UnityEngine;
using UnityEditor;
-namespace SpriteMaker{
-
- ///
- /// Base Draw Command. Subclass this to create custom draw commands
- ///
- public class BaseDrawCommand {
-
- ///
- /// Types of Draw Commands. Need to update when creating a new Draw Command
- ///
- public enum DrawCommandType {
- Fill = 0,
- Circle = 1,
- Rect = 2,
- RoundedRect = 3
- }
-
- ///
- /// Blendmode Enums. Updatewhen adding a blend mode.
- ///
- public enum BlendMode
- {
- Opacity = 0,
- Additive = 1,
- Subtract = 2,
- Multiply = 3
- }
-
- public BlendMode blendMode;
- public string Name;
- public bool Visible = true;
- public bool Hidden = false;
-
- private Color cachedColor;
-
- ///
- /// Override this function to implement the drawing fucntion of a custom Draw Command
- ///
- /// The Canvas after the Draw Command has executed
- /// The Canvas before the Draw COmmand has executed
- /// Width of image in pixels
- /// Height of image in pixels
- public virtual Color[] DrawToColorArray(Color[] _input, int _width, int _height)
- {
- //some draw code here
- //for when we add blend modes
-
- return _input;
-
- }
-
- ///
- /// override this function to draw custom inputs for your draw commands.
- ///
- public virtual void DrawControls()
- {
- blendMode = (BaseDrawCommand.BlendMode)EditorGUILayout.EnumPopup (blendMode);
-
- }
-
- ///
- /// Helper function to appropriately blend a new pixel with the canvas' pixel.
- /// Please use this rather than editing the array directly to support BlendModes
- ///
- /// The blended color value.
- /// Pixel to be blended
- /// Canvas Pixel to blend too
- protected Color BlendPixelToCanvas(Color _pixel, Color _canvas)
- {
- cachedColor = _canvas;
- switch (blendMode){
- case BlendMode.Opacity:
-
- cachedColor.a = _pixel.a + _canvas.a;
-
- cachedColor.r = (_pixel.r * _pixel.a) + ((1 - _pixel.a) * _canvas.r);
- cachedColor.g = (_pixel.g * _pixel.a) + ((1 - _pixel.a) * _canvas.g);
- cachedColor.b = (_pixel.b * _pixel.a) + ((1 - _pixel.a) * _canvas.b);
-
- break;
- case BlendMode.Additive:
+namespace SpriteMaker
+{
+ [System.Serializable]
+ ///
+ /// Base Draw Command. Subclass this to create custom draw commands
+ ///
+ public class BaseDrawCommand
+ {
+
+ ///
+ /// Types of Draw Commands. Need to update when creating a new Draw Command
+ ///
+
+ public enum DrawCommandType
+ {
+ Fill = 0,
+ Circle = 1,
+ Rect = 2,
+ RoundedRect = 3,
+ Perlin = 4
+ }
+
+
+ ///
+ /// Blendmode Enums. Updatewhen adding a blend mode.
+ ///
+ public enum BlendMode
+ {
+ Opacity = 0,
+ Additive = 1,
+ Subtract = 2,
+ Multiply = 3,
+ Replace = 4
+ }
+
+ public BlendMode blendMode;
+ public DrawCommandType myType;
+ public string Name;
+ public bool Visible = true;
+ public bool Hidden = false;
+
+ private Color cachedColor;
+
+ ///
+ /// when we serialize a draw command, it stores its data here so it gets serialized properly.
+ /// Unity doesn't nattively support serializing derived classes, so this class has to hold the data from derived classes
+ /// derived Draw Commands are responsible for storing and retrieving serialized data
+ ///
+ [System.Serializable]
+ public struct SerializedData
+ {
+ public float[] serializedFloats;
+ public Color[] serializedColors;
+ [SerializeField]
+ public Gradient[] serializedGradients;
+ };
+
+ public SerializedData data;
+
+ ///
+ /// Override this function to implement the drawing fucntion of a custom Draw Command
+ ///
+ /// The Canvas after the Draw Command has executed
+ /// The Canvas before the Draw COmmand has executed
+ /// Width of image in pixels
+ /// Height of image in pixels
+ public virtual Color[] DrawToColorArray(Color[] _input, int _width, int _height)
+ {
+ //some draw code here
+ //for when we add blend modes
+
+ return _input;
+
+ }
+
+ ///
+ /// override this function to draw custom inputs for your draw commands.
+ ///
+ public virtual void DrawControls()
+ {
+ blendMode = (BaseDrawCommand.BlendMode)EditorGUILayout.EnumPopup(blendMode);
+
+ }
+
+ ///
+ /// Helper function to appropriately blend a new pixel with the canvas' pixel.
+ /// Please use this rather than editing the array directly to support BlendModes
+ ///
+ /// The blended color value.
+ /// Pixel to be blended
+ /// Canvas Pixel to blend too
+ protected Color BlendPixelToCanvas(Color _pixel, Color _canvas)
+ {
+ cachedColor = _canvas;
+ switch (blendMode)
+ {
+ case BlendMode.Opacity:
+
+ cachedColor.a = _pixel.a + _canvas.a;
+
+ cachedColor.r = (_pixel.r * _pixel.a) + ((1 - _pixel.a) * _canvas.r);
+ cachedColor.g = (_pixel.g * _pixel.a) + ((1 - _pixel.a) * _canvas.g);
+ cachedColor.b = (_pixel.b * _pixel.a) + ((1 - _pixel.a) * _canvas.b);
+
+ break;
+ case BlendMode.Additive:
- cachedColor.a = _pixel.a + _canvas.a;
+ cachedColor.a = _pixel.a + _canvas.a;
+
+ cachedColor.r = Mathf.Min((_pixel.r * _pixel.a) + _canvas.r, 1.0f);
+ cachedColor.g = Mathf.Min((_pixel.g * _pixel.a) + _canvas.g, 1.0f);
+ cachedColor.b = Mathf.Min((_pixel.b * _pixel.a) + _canvas.b, 1.0f);
- cachedColor.r = Mathf.Min((_pixel.r * _pixel.a) + _canvas.r,1.0f);
- cachedColor.g = Mathf.Min((_pixel.g * _pixel.a) + _canvas.g,1.0f);
- cachedColor.b = Mathf.Min((_pixel.b * _pixel.a) + _canvas.b,1.0f);
+ break;
- break;
+ case BlendMode.Subtract:
+ cachedColor.a = _pixel.a + _canvas.a;
- case BlendMode.Subtract:
- cachedColor.a = _pixel.a + _canvas.a;
+ cachedColor.r = Mathf.Max(_canvas.r - (_pixel.r * _pixel.a), 0.0f);
+ cachedColor.g = Mathf.Max(_canvas.g - (_pixel.g * _pixel.a), 0.0f);
+ cachedColor.b = Mathf.Max(_canvas.b - (_pixel.b * _pixel.a), 0.0f);
- cachedColor.r = Mathf.Max(_canvas.r - (_pixel.r * _pixel.a),0.0f);
- cachedColor.g = Mathf.Max(_canvas.g - (_pixel.g * _pixel.a),0.0f);
- cachedColor.b = Mathf.Max(_canvas.b - (_pixel.b * _pixel.a),0.0f);
+ break;
- break;
+ case BlendMode.Multiply:
+ cachedColor.a = Mathf.Min(_pixel.a + _canvas.a, 1.0f);
- case BlendMode.Multiply:
- cachedColor.a = Mathf.Min (_pixel.a + _canvas.a, 1.0f);
+ cachedColor.r = Mathf.Lerp(_canvas.r, _canvas.r * (_pixel.r), _pixel.a);
+ cachedColor.g = Mathf.Lerp(_canvas.g, _canvas.g * (_pixel.g), _pixel.a);
+ cachedColor.b = Mathf.Lerp(_canvas.b, _canvas.b * (_pixel.b), _pixel.a);
- cachedColor.r = Mathf.Lerp (_canvas.r, _canvas.r * (_pixel.r),_pixel.a);
- cachedColor.g = Mathf.Lerp (_canvas.g, _canvas.g * (_pixel.g),_pixel.a);
- cachedColor.b = Mathf.Lerp (_canvas.b, _canvas.b * (_pixel.b),_pixel.a);
+ break;
+ case BlendMode.Replace:
+
+ cachedColor.a = _pixel.a;
- break;
- }
+ cachedColor.r = _pixel.r;
+ cachedColor.g = _pixel.g;
+ cachedColor.b = _pixel.b;
- return cachedColor;
- }
+ break;
+ }
+ return cachedColor;
+ }
+ ///
+ /// Called before serializing this draw call. Derived classes must extend this and populate SerializaedData to be correctly serialized;
+ ///
+ public virtual void OnBeforeSerialize()
+ {
+ }
- }
+ ///
+ /// Called after serializing or anytime a BaseDrawCommand must be cast to a derived type. builds derivedclass from data in SerializedData
+ /// use this to populate properties from serializeddata
+ ///
+ /// Bd.
+ public virtual void PopulateFromBase(BaseDrawCommand bd)
+ {
+
+ blendMode = bd.blendMode;
+ }
+
+ }
}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommandManager.cs b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommandManager.cs
index 3c0a75e..9d8c858 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommandManager.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommandManager.cs
@@ -3,218 +3,262 @@
using System.Collections;
using System.Collections.Generic;
-namespace SpriteMaker{
+namespace SpriteMaker
+{
- public class DrawCommandManager {
+ public class DrawCommandManager
+ {
+ private BaseDrawCommand.DrawCommandType DrawCommandToInsert;
- public List DrawCommands = new List();
+ private int CommandToRemove = -1;
+ private int CommandToRearrange = -1;
+ private int RearrangeAmount = 0;
- private BaseDrawCommand.DrawCommandType DrawCommandToInsert;
+ ///
+ /// Initializes a new instance of the class.
+ ///
+ public DrawCommandManager()
+ {
- private int CommandToRemove = -1;
- private int CommandToRearrange = -1;
- private int RearrangeAmount = 0;
- ///
- /// Initializes a new instance of the class.
- ///
- public DrawCommandManager()
- {
- DrawCommands.Add(new DrawFill());
- }
-
- ///
- /// just a getter for the draw commands
- ///
- /// The draw command queue
- public List GetDrawCommands()
- {
- return DrawCommands;
- }
-
- ///
- /// GUI rendering for the Draw Commands
- ///
- public void DrawControls()
- {
-
-
- for (int i = 0; i < DrawCommands.Count; i++) {
-
- //the big box that holds everything
- EditorGUILayout.BeginVertical ("Box");{
-
-
- //DataGUI is used to draw the top bar of the Draw Command (name,collapse,hide,delete)
- EditorGUILayout.BeginHorizontal ();
- {
- DataGUI (i);
- }
- EditorGUILayout.EndHorizontal ();
-
-
-
- //When we render the actual command, we make sure its not collapsed
- if (!DrawCommands [i].Hidden) {
-
- EditorGUILayout.BeginHorizontal ();
- {
-
- //the actual parameters for each drawcommand are rendered
- EditorGUILayout.BeginVertical ("Box");
- {
- DrawCommands [i].DrawControls ();
- }
- EditorGUILayout.EndVertical ();
-
-
- //and then the selection gui that dictate their position in the list is rendered
- EditorGUILayout.BeginVertical (GUILayout.Width (25));
- {
- SelectionGUI (i);
- }
- EditorGUILayout.EndVertical ();
-
-
- }
- EditorGUILayout.EndHorizontal ();
- }
- }EditorGUILayout.EndVertical ();
- }
-
-
- //at the end we can insert a new Draw Comma
- EditorGUILayout.BeginHorizontal ();{
- InsertionGUI (DrawCommands.Count-1);
- }EditorGUILayout.EndHorizontal ();
-
- //after looping through the commands, we run the code that potentially modifies the list in some way
- RemoveDrawCommand (CommandToRemove);
- RearrangeDrawCommand (CommandToRearrange, RearrangeAmount);
- CommandToRemove = -1;
- CommandToRearrange = -1;
- RearrangeAmount = 0;
-
- }
-
-
- ///
- /// Inserts a new draw command.
- ///
- /// Index.
- public void InsertDrawCommand(int _index)
- {
- BaseDrawCommand bdc;
- switch (DrawCommandToInsert) {
- case BaseDrawCommand.DrawCommandType.Fill:
- bdc = new DrawFill ();
- break;
- case BaseDrawCommand.DrawCommandType.Circle:
- bdc = new DrawCircle ();
- break;
- case BaseDrawCommand.DrawCommandType.Rect:
- default:
- bdc = new DrawRect ();
- break;
- case BaseDrawCommand.DrawCommandType.RoundedRect:
- bdc = new DrawRoundedRect ();
- break;
- }
- DrawCommands.Insert (_index + 1, bdc);
-
- }
-
- ///
- /// Removes a draw command at the provided index.
- ///
- /// Index.
- private void RemoveDrawCommand(int _index)
- {
- if (_index != -1) {
- DrawCommands.RemoveAt (_index);
- }
- }
-
- private void RearrangeDrawCommand(int _currentIndex, int _targetIndex)
- {
- if (_currentIndex != -1 && _currentIndex+_targetIndex >=0 && _currentIndex+_targetIndex newList = new List ();
-
- for (int i = 0; i < DrawCommands.Count; i++) {
- if (i == _currentIndex) {
- newList.Add (DrawCommands [_currentIndex + _targetIndex]);
-
- } else if (i == _currentIndex + _targetIndex) {
- newList.Add (DrawCommands [_currentIndex]);
-
- } else {
- newList.Add (DrawCommands [i]);
- }
- }
- DrawCommands = newList;
- }
- }
-
- ///
- /// This renders the GUI for the selection tools
- ///
- /// Index.
- private void SelectionGUI(int _index)
- {
- Color t = GUI.color;
- GUI.color = Color.cyan;
- if (GUILayout.Button ("^")) {
- CommandToRearrange = _index;
- RearrangeAmount = -1;
- }
- if (GUILayout.Button ("V")) {
- CommandToRearrange = _index;
- RearrangeAmount = 1;
- }
- GUI.color = t;
-
- }
-
- ///
- /// Renders the GUI for the Insertion tool
- ///
- /// Index.
- private void InsertionGUI(int _index)
- {
- if (GUILayout.Button ("Insert New Draw Command")) {
- InsertDrawCommand (_index);
- }
- DrawCommandToInsert = (BaseDrawCommand.DrawCommandType)EditorGUILayout.EnumPopup (DrawCommandToInsert);
- }
-
-
- ///
- /// Renders the GUI for the Data section
- ///
- /// Index.
- private void DataGUI(int _index)
- {
- GUILayout.Label (_index.ToString() + " - " + DrawCommands[_index].Name);
- GUI.color = Color.yellow;
- if (GUILayout.Button (DrawCommands[_index].Hidden?"+":"-", GUILayout.MaxWidth(20))) {
- DrawCommands [_index].Hidden = !DrawCommands [_index].Hidden;
- }
-
- GUI.color = DrawCommands [_index].Visible ? Color.green : Color.red;
- if (GUILayout.Button ("V", GUILayout.MaxWidth(20))) {
- DrawCommands [_index].Visible = !DrawCommands [_index].Visible;
- }
-
- GUI.color = Color.red;
- if (GUILayout.Button ("X",GUILayout.MaxWidth(20))) {
- CommandToRemove = _index;
- }
- GUI.color = Color.white;
- }
-
-
-
-
- }
+ }
+
+ public List BuildNewDrawCommandList()
+ {
+ DrawFill g = new DrawFill();
+ g.blendMode = BaseDrawCommand.BlendMode.Replace;
+ List DrawCommands = new List();
+ DrawCommands.Add(g);
+ return DrawCommands;
+ }
+
+
+
+ public void UseAsset(ref SpriteMakerAsset _asset)
+ {
+
+ if (_asset.DrawCommands == null)
+ {
+ _asset.DrawCommands = BuildNewDrawCommandList();
+ }
+ }
+
+ public void SetupAsset(ref SpriteMakerAsset _asset)
+ {
+ _asset.DrawCommands = BuildNewDrawCommandList();
+ }
+
+ ///
+ /// GUI rendering for the Draw Commands
+ ///
+ public void DrawControls(ref SpriteMakerAsset _asset)
+ {
+
+ if (_asset.DrawCommands != null)
+ {
+ for (int i = 0; i < _asset.DrawCommands.Count; i++)
+ {
+
+ //the big box that holds everything
+ EditorGUILayout.BeginVertical("Box");
+ {
+
+
+ //DataGUI is used to draw the top bar of the Draw Command (name,collapse,hide,delete)
+ EditorGUILayout.BeginHorizontal();
+ {
+ DataGUI(_asset, i);
+ }
+ EditorGUILayout.EndHorizontal();
+
+
+
+ //When we render the actual command, we make sure its not collapsed
+ if (!_asset.DrawCommands[i].Hidden)
+ {
+
+ EditorGUILayout.BeginHorizontal();
+ {
+
+ //the actual parameters for each drawcommand are rendered
+ EditorGUILayout.BeginVertical("Box");
+ {
+ _asset.DrawCommands[i].DrawControls();
+ }
+ EditorGUILayout.EndVertical();
+
+
+ //and then the selection gui that dictate their position in the list is rendered
+ EditorGUILayout.BeginVertical(GUILayout.Width(25));
+ {
+ SelectionGUI(i);
+ }
+ EditorGUILayout.EndVertical();
+
+
+ }
+ EditorGUILayout.EndHorizontal();
+ }
+ }
+ EditorGUILayout.EndVertical();
+ }
+
+
+
+ //at the end we can insert a new Draw Comma
+ EditorGUILayout.BeginHorizontal();
+ {
+ InsertionGUI(ref _asset, _asset.DrawCommands.Count - 1);
+ }
+ EditorGUILayout.EndHorizontal();
+
+ //after looping through the commands, we run the code that potentially modifies the list in some way
+ RemoveDrawCommand(ref _asset, CommandToRemove);
+ RearrangeDrawCommand(ref _asset, CommandToRearrange, RearrangeAmount);
+ CommandToRemove = -1;
+ CommandToRearrange = -1;
+ RearrangeAmount = 0;
+ }
+
+ }
+
+
+ ///
+ /// Inserts a new draw command.
+ ///
+ /// Index.
+ public void InsertDrawCommand(ref SpriteMakerAsset _asset, int _index)
+ {
+ BaseDrawCommand bdc;
+ switch (DrawCommandToInsert)
+ {
+ case BaseDrawCommand.DrawCommandType.Fill:
+ bdc = new DrawFill();
+ break;
+ case BaseDrawCommand.DrawCommandType.Circle:
+ bdc = new DrawCircle();
+ break;
+ case BaseDrawCommand.DrawCommandType.Rect:
+ default:
+ bdc = new DrawRect();
+ break;
+ case BaseDrawCommand.DrawCommandType.RoundedRect:
+ bdc = new DrawRoundedRect();
+ break;
+ case BaseDrawCommand.DrawCommandType.Perlin:
+ bdc = new DrawPerlin();
+ break;
+ }
+ bdc.myType = DrawCommandToInsert;
+ _asset.DrawCommands.Insert(_index + 1, bdc);
+
+ }
+
+ ///
+ /// Removes a draw command at the provided index.
+ ///
+ /// Index.
+ private void RemoveDrawCommand(ref SpriteMakerAsset _asset, int _index)
+ {
+ if (_index != -1)
+ {
+ _asset.DrawCommands.RemoveAt(_index);
+ }
+ }
+
+ private void RearrangeDrawCommand(ref SpriteMakerAsset _asset, int _currentIndex, int _targetIndex)
+ {
+ if (_currentIndex != -1 && _currentIndex + _targetIndex >= 0 && _currentIndex + _targetIndex < _asset.DrawCommands.Count)
+ {
+ List newList = new List();
+
+ for (int i = 0; i < _asset.DrawCommands.Count; i++)
+ {
+ if (i == _currentIndex)
+ {
+ newList.Add(_asset.DrawCommands[_currentIndex + _targetIndex]);
+
+ }
+ else if (i == _currentIndex + _targetIndex)
+ {
+ newList.Add(_asset.DrawCommands[_currentIndex]);
+
+ }
+ else
+ {
+ newList.Add(_asset.DrawCommands[i]);
+ }
+ }
+ _asset.DrawCommands = newList;
+ }
+ }
+
+ ///
+ /// This renders the GUI for the selection tools
+ ///
+ /// Index.
+ private void SelectionGUI(int _index)
+ {
+ Color t = GUI.color;
+ GUI.color = Color.cyan;
+ if (GUILayout.Button("^"))
+ {
+ CommandToRearrange = _index;
+ RearrangeAmount = -1;
+ }
+ if (GUILayout.Button("V"))
+ {
+ CommandToRearrange = _index;
+ RearrangeAmount = 1;
+ }
+ GUI.color = t;
+
+ }
+
+ ///
+ /// Renders the GUI for the Insertion tool
+ ///
+ /// Index.
+ private void InsertionGUI(ref SpriteMakerAsset _asset, int _index)
+ {
+ if (GUILayout.Button("Insert New Draw Command"))
+ {
+ InsertDrawCommand(ref _asset, _index);
+ }
+ DrawCommandToInsert = (BaseDrawCommand.DrawCommandType)EditorGUILayout.EnumPopup(DrawCommandToInsert);
+ }
+
+
+ ///
+ /// Renders the GUI for the Data section
+ ///
+ /// Index.
+ private void DataGUI(SpriteMakerAsset _asset, int _index)
+ {
+ GUILayout.Label(_index.ToString() + " - " + _asset.DrawCommands[_index].Name);
+ GUI.color = Color.yellow;
+ if (GUILayout.Button(_asset.DrawCommands[_index].Hidden ? "+" : "-", GUILayout.MaxWidth(20)))
+ {
+ _asset.DrawCommands[_index].Hidden = !_asset.DrawCommands[_index].Hidden;
+ }
+
+ GUI.color = _asset.DrawCommands[_index].Visible ? Color.green : Color.red;
+ if (GUILayout.Button("V", GUILayout.MaxWidth(20)))
+ {
+ _asset.DrawCommands[_index].Visible = !_asset.DrawCommands[_index].Visible;
+ }
+
+ GUI.color = Color.red;
+ if (GUILayout.Button("X", GUILayout.MaxWidth(20)))
+ {
+ CommandToRemove = _index;
+ }
+ GUI.color = Color.white;
+ }
+
+
+
+
+ }
}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawCircle.cs b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawCircle.cs
index d85e817..ee06bb3 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawCircle.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawCircle.cs
@@ -2,86 +2,127 @@
using UnityEditor;
using System.Collections;
-namespace SpriteMaker{
+namespace SpriteMaker
+{
- ///
- /// used to draw a circle on the canvas.
- ///
- public class DrawCircle : BaseDrawCommand {
+ ///
+ /// used to draw a circle on the canvas.
+ ///
+ public class DrawCircle : BaseDrawCommand
+ {
- public Color color = Color.red;
- public float positionX = 0.5f;
- public float positionY = 0.5f;
- public float radiusFloat = 0.4f;
- public float smoothness = 0.05f;
+ public Color color = Color.red;
+ public float positionX = 0.5f;
+ public float positionY = 0.5f;
+ public float radiusFloat = 0.4f;
+ public float smoothness = 0.05f;
- private int pixelPosX;
- private int pixelPosY;
- private int pixelRadius;
+ private int pixelPosX;
+ private int pixelPosY;
+ private int pixelRadius;
- private Vector2 positionVector;
- private Vector2 tempVector;
+ private Vector2 positionVector;
+ private Vector2 tempVector;
- //TODO: currently uses a distance check to determine a circle. gives better results at lower res than initial circle. investigate.
- public override Color[] DrawToColorArray (Color[] _input, int _width, int _height)
- {
+
+ //TODO: currently uses a distance check to determine a circle. gives better results at lower res than initial circle. investigate.
+
+ public override Color[] DrawToColorArray(Color[] _input, int _width, int _height)
+ {
- //convert our relative values to absolute pixel values
- pixelPosX = Mathf.CeilToInt(positionX * (float)_width);
- pixelPosY = Mathf.CeilToInt(positionY * (float)_height);
- pixelRadius = Mathf.CeilToInt(radiusFloat * ((_width+_height)/2));
-
- positionVector.x = pixelPosX;
- positionVector.y = pixelPosY;
-
- int leftBounds = pixelPosX - pixelRadius;
- int rightBounds = pixelPosX + pixelRadius;
- int upperBounds = pixelPosY + pixelRadius;
- int lowerBounds = pixelPosY - pixelRadius;
-
- //d
-
- for (int x = leftBounds; x <= rightBounds; x++) {
- tempVector.x = x;
- if (x >= 0 && x < _width) {
- for (int y = lowerBounds; y <= upperBounds; y++) {
- if (y >= 0 && y < _height) {
+ //convert our relative values to absolute pixel values
+ pixelPosX = Mathf.CeilToInt(positionX * (float)_width);
+ pixelPosY = Mathf.CeilToInt(positionY * (float)_height);
+ pixelRadius = Mathf.CeilToInt(radiusFloat * ((_width + _height) / 2));
+
+ positionVector.x = pixelPosX;
+ positionVector.y = pixelPosY;
+
+ int leftBounds = pixelPosX - pixelRadius;
+ int rightBounds = pixelPosX + pixelRadius;
+ int upperBounds = pixelPosY + pixelRadius;
+ int lowerBounds = pixelPosY - pixelRadius;
+
+ //d
+
+ for (int x = leftBounds; x <= rightBounds; x++)
+ {
+ tempVector.x = x;
+ if (x >= 0 && x < _width)
+ {
+ for (int y = lowerBounds; y <= upperBounds; y++)
+ {
+ if (y >= 0 && y < _height)
+ {
- tempVector.y = y;
- Color c = color;
-
- c.a = 1.0f - Vector2.Distance (positionVector, tempVector) / pixelRadius;
- if (c.a > smoothness) {
- c.a = 1.0f;
- } else {
- c.a = Mathf.InverseLerp (0, smoothness, c.a);
- }
- c.a *= color.a;
-
-
- _input [y * _width + x] = BlendPixelToCanvas (c, _input [y * _width + x]);
- }
- }
- }
- }
- return base.DrawToColorArray (_input,_width,_height);
- }
-
-
- public override void DrawControls ()
- {
- Name = "Circle"; //TODO: Should I make these editable?
- color = EditorGUILayout.ColorField ("Color", color);
- positionX = float.Parse(EditorGUILayout.TextField ("X Position", positionX.ToString()));
- positionY = float.Parse(EditorGUILayout.TextField ("Y Position", positionY.ToString()));
- radiusFloat = float.Parse(EditorGUILayout.TextField ("Radius", radiusFloat.ToString()));
- smoothness = float.Parse(EditorGUILayout.TextField ("Smoothness", smoothness.ToString()));
-
-
- base.DrawControls ();
- }
- }
+ tempVector.y = y;
+ Color c = color;
+
+ c.a = 1.0f - Vector2.Distance(positionVector, tempVector) / pixelRadius;
+ if (c.a > smoothness)
+ {
+ c.a = 1.0f;
+ }
+ else
+ {
+ c.a = Mathf.InverseLerp(0, smoothness, c.a);
+ }
+ c.a *= color.a;
+
+
+ _input[y * _width + x] = BlendPixelToCanvas(c, _input[y * _width + x]);
+ }
+ }
+ }
+ }
+ return base.DrawToColorArray(_input, _width, _height);
+ }
+
+
+ public override void DrawControls()
+ {
+ Name = "Circle"; //TODO: Should I make these editable?
+ color = EditorGUILayout.ColorField("Color", color);
+ positionX = float.Parse(EditorGUILayout.TextField("X Position", positionX.ToString()));
+ positionY = float.Parse(EditorGUILayout.TextField("Y Position", positionY.ToString()));
+ radiusFloat = float.Parse(EditorGUILayout.TextField("Radius", radiusFloat.ToString()));
+ smoothness = float.Parse(EditorGUILayout.TextField("Smoothness", smoothness.ToString()));
+
+
+ base.DrawControls();
+ }
+
+
+ #region SERIALIZATION
+
+ public override void OnBeforeSerialize()
+ {
+ data = new SerializedData();
+ data.serializedFloats = new float[4];
+ data.serializedColors = new Color[1];
+ data.serializedColors[0] = color;
+ data.serializedFloats[0] = positionX;
+ data.serializedFloats[1] = positionY;
+ data.serializedFloats[2] = radiusFloat;
+ data.serializedFloats[3] = smoothness;
+
+ base.OnBeforeSerialize();
+ }
+
+ public override void PopulateFromBase(BaseDrawCommand bd)
+ {
+ color = bd.data.serializedColors[0];
+ positionX = bd.data.serializedFloats[0];
+ positionY = bd.data.serializedFloats[1];
+ radiusFloat = bd.data.serializedFloats[2];
+ smoothness = bd.data.serializedFloats[3];
+
+ base.PopulateFromBase(bd);
+ }
+
+ #endregion
+ }
}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawFill.cs b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawFill.cs
index 9c76e70..5831817 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawFill.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawFill.cs
@@ -1,33 +1,61 @@
using UnityEngine;
using UnityEditor;
using System.Collections;
-namespace SpriteMaker{
-
- ///
- /// Draw Command to fill the entire canvas with a color
- ///
- public class DrawFill : BaseDrawCommand {
-
- ///
- /// Color to fill canvas with
- ///
- public Color fill;
-
- public override Color[] DrawToColorArray (Color[] _input, int _width, int _height)
- {
- for (int x = 0; x < _input.Length; x++) {
- _input[x] = BlendPixelToCanvas(fill,_input[x]);
- }
-
- return base.DrawToColorArray (_input, _width, _height);
- }
-
- public override void DrawControls ()
- {
- Name = "Fill";
- fill = EditorGUILayout.ColorField ("Fill Color", fill);
- base.DrawControls ();
- }
-
- }
+
+namespace SpriteMaker
+{
+
+ ///
+ /// Draw Command to fill the entire canvas with a color
+ ///
+
+ public class DrawFill : BaseDrawCommand
+ {
+
+ ///
+ /// Color to fill canvas with
+ ///
+ public Color fill;
+
+ public override Color[] DrawToColorArray(Color[] _input, int _width, int _height)
+ {
+ for (int x = 0; x < _input.Length; x++)
+ {
+ _input[x] = BlendPixelToCanvas(fill, _input[x]);
+ }
+
+ return base.DrawToColorArray(_input, _width, _height);
+ }
+
+ public override void DrawControls()
+ {
+ Name = "Fill";
+ fill = EditorGUILayout.ColorField("Fill Color", fill);
+ base.DrawControls();
+ }
+
+ #region SERIALIZATION
+
+ public override void OnBeforeSerialize()
+ {
+ data = new SerializedData();
+
+ data.serializedColors = new Color[1];
+ data.serializedColors[0] = fill;
+
+
+ base.OnBeforeSerialize();
+ }
+
+ public override void PopulateFromBase(BaseDrawCommand bd)
+ {
+ fill = bd.data.serializedColors[0];
+
+
+ base.PopulateFromBase(bd);
+ }
+
+ #endregion
+
+ }
}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawPerlin.cs b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawPerlin.cs
new file mode 100644
index 0000000..eb129b7
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawPerlin.cs
@@ -0,0 +1,125 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEditor;
+
+namespace SpriteMaker
+{
+
+ public class DrawPerlin : BaseDrawCommand
+ {
+ public float HorizontalScale = 6.4f;
+ public float VerticalScale = 6.4f;
+ public float xOffset;
+ public float yOffset;
+ public Gradient gradient = new Gradient();
+
+ private ScriptableGradientAsset gradientObject;
+
+ private float xPosition;
+ private float yPosition;
+
+
+ public override Color[] DrawToColorArray(Color[] _input, int _width, int _height)
+ {
+
+ for (int y = 0; y < _height; y++)
+ {
+ yPosition = (float)y / (float)_height;
+ for (int x = 0; x < _width; x++)
+ {
+ xPosition = (float)x / (float)_width;
+
+ _input[y * _width + x] = BlendPixelToCanvas(
+ gradient.Evaluate(
+ Mathf.PerlinNoise(
+ (xPosition * HorizontalScale) + xOffset,
+ (yPosition * VerticalScale) + yOffset
+ ))
+ , _input[y * _width + x]);
+ }
+ }
+
+
+ return base.DrawToColorArray(_input, _width, _height);
+ }
+
+ public override void DrawControls()
+ {
+ Name = "Perlin Noise";
+ HorizontalScale = float.Parse(EditorGUILayout.TextField("Horizontal Scale", HorizontalScale.ToString()));
+ VerticalScale = float.Parse(EditorGUILayout.TextField("Vertical Scale", VerticalScale.ToString()));
+
+ //TODO: I can't believe this is how this must be done
+ //To get a nice gradient picker, we need to alter the serializedproperty of a serializedobject
+ //since this class isn;t serializable (derives fro something other than monobehaviour or scriptableobject),
+ //we create a SerializedObject that just has a gradient on it, set its gradient to out gradient, and show the field.
+ //if its changed, we apply those settings back to the serialized object and set our gradient from it.
+ if (gradientObject == null)
+ {
+ gradientObject = ScriptableObject.CreateInstance();
+ gradientObject.gradient = gradient;
+ }
+
+ EditorGUI.BeginChangeCheck();
+ {
+ SerializedObject obj = new SerializedObject(gradientObject);
+ SerializedProperty sgrad = obj.FindProperty("gradient");
+ EditorGUILayout.PropertyField(sgrad, true, null);
+ if (EditorGUI.EndChangeCheck())
+ {
+ obj.ApplyModifiedProperties();
+ gradient = gradientObject.gradient;
+ }
+
+
+ }
+
+
+
+ if (GUILayout.Button("Shuffle"))
+ {
+ xOffset = Random.Range(-9999, 9999);
+ yOffset = Random.Range(-9999, 9999);
+ }
+ base.DrawControls();
+ }
+
+ #region SERIALIZATION
+
+ public override void OnBeforeSerialize()
+ {
+ data = new SerializedData();
+
+ data.serializedFloats = new float[4];
+ data.serializedFloats[0] = HorizontalScale;
+ data.serializedFloats[1] = VerticalScale;
+ data.serializedFloats[2] = xOffset;
+ data.serializedFloats[3] = yOffset;
+
+ data.serializedGradients = new Gradient[1];
+ data.serializedGradients[0] = gradient;
+
+ base.OnBeforeSerialize();
+ }
+
+ public override void PopulateFromBase(BaseDrawCommand bd)
+ {
+ HorizontalScale = bd.data.serializedFloats[0];
+ VerticalScale = bd.data.serializedFloats[1];
+ xOffset = bd.data.serializedFloats[2];
+ yOffset = bd.data.serializedFloats[3];
+
+
+ gradient = bd.data.serializedGradients[0];
+
+
+
+
+ base.PopulateFromBase(bd);
+ }
+
+ #endregion
+
+ }
+}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawPerlin.cs.meta b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawPerlin.cs.meta
new file mode 100644
index 0000000..e1cfd38
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawPerlin.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 9ed13316c77e54c279f32bfdf6aa0c8f
+timeCreated: 1490011647
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRect.cs b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRect.cs
index 4f6cc3c..3b12152 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRect.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRect.cs
@@ -2,69 +2,113 @@
using UnityEditor;
using System.Collections;
-namespace SpriteMaker{
+namespace SpriteMaker
+{
- ///
- /// Used to draw a Rect on the canvas.
- ///
- public class DrawRect : BaseDrawCommand {
- public float CenterX, CenterY;
- public float Width;
- public float Height;
- public Color rectColor;
+ ///
+ /// Used to draw a Rect on the canvas.
+ ///
+ public class DrawRect : BaseDrawCommand
+ {
- private int pixelPosX;
- private int pixelPosY;
- private int pixelWidth;
- private int pixelHeight;
+ public float CenterX, CenterY;
+ public float Width;
+ public float Height;
+ public Color rectColor;
- public override Color[] DrawToColorArray (Color[] _input, int _width, int _height)
- {
+ private int pixelPosX;
+ private int pixelPosY;
+ private int pixelWidth;
+ private int pixelHeight;
- pixelPosX = Mathf.CeilToInt(CenterX * (float)_width);
- pixelPosY = Mathf.CeilToInt(CenterY * (float)_height);
- pixelWidth = Mathf.CeilToInt(Width * (_width));
- pixelHeight = Mathf.CeilToInt(Height * (_height));
+ public override Color[] DrawToColorArray(Color[] _input, int _width, int _height)
+ {
+ pixelPosX = Mathf.CeilToInt(CenterX * (float)_width);
+ pixelPosY = Mathf.CeilToInt(CenterY * (float)_height);
+ pixelWidth = Mathf.CeilToInt(Width * (_width));
+ pixelHeight = Mathf.CeilToInt(Height * (_height));
- int leftBounds = pixelPosX - (pixelWidth / 2);
- int rightBounds = pixelPosX + (pixelWidth / 2);
- int lowerBounds = pixelPosY - (pixelHeight / 2);
- int upperBounds = pixelPosY + (pixelHeight / 2);
+ int leftBounds = pixelPosX - (pixelWidth / 2);
+ int rightBounds = pixelPosX + (pixelWidth / 2);
+ int lowerBounds = pixelPosY - (pixelHeight / 2);
+ int upperBounds = pixelPosY + (pixelHeight / 2);
- for (int x = leftBounds; x <= rightBounds; x++) {
- if (x >= 0 && x < _width) {
- for (int y = lowerBounds; y <= upperBounds; y++) {
- if (y >= 0 && y < _height) {
- _input[y*_width+x] = BlendPixelToCanvas(rectColor, _input[y*_width+x]);
+ for (int x = leftBounds; x <= rightBounds; x++)
+ {
+ if (x >= 0 && x < _width)
+ {
+ for (int y = lowerBounds; y <= upperBounds; y++)
+ {
+ if (y >= 0 && y < _height)
+ {
- }
- }
- }
- }
+ _input[y * _width + x] = BlendPixelToCanvas(rectColor, _input[y * _width + x]);
+ }
+ }
+ }
+ }
- return base.DrawToColorArray (_input, _width, _height);
- }
- public override void DrawControls ()
- {
- Name = "Rectangle";
- rectColor = EditorGUILayout.ColorField ("Color", rectColor);
- CenterX = float.Parse(EditorGUILayout.TextField ("X Position", CenterX.ToString()));
- CenterY = float.Parse(EditorGUILayout.TextField ("Y Position", CenterY.ToString()));
- Width = float.Parse(EditorGUILayout.TextField ("Width", Width.ToString()));
- Height = float.Parse(EditorGUILayout.TextField ("Height", Height.ToString()));
+ return base.DrawToColorArray(_input, _width, _height);
+ }
+ public override void DrawControls()
+ {
+ Name = "Rectangle";
+ rectColor = EditorGUILayout.ColorField("Color", rectColor);
+ CenterX = float.Parse(EditorGUILayout.TextField("X Position", CenterX.ToString()));
+ CenterY = float.Parse(EditorGUILayout.TextField("Y Position", CenterY.ToString()));
+ Width = float.Parse(EditorGUILayout.TextField("Width", Width.ToString()));
+ Height = float.Parse(EditorGUILayout.TextField("Height", Height.ToString()));
- base.DrawControls ();
- }
- }
+ base.DrawControls();
+ }
+
+ #region SERIALIZATION
+
+ public override void OnBeforeSerialize()
+ {
+ data = new SerializedData();
+
+ data.serializedFloats = new float[4];
+ data.serializedFloats[0] = CenterX;
+ data.serializedFloats[1] = CenterY;
+ data.serializedFloats[2] = Width;
+ data.serializedFloats[3] = Height;
+
+
+ data.serializedColors = new Color[1];
+ data.serializedColors[0] = rectColor;
+
+
+ base.OnBeforeSerialize();
+ }
+
+ public override void PopulateFromBase(BaseDrawCommand bd)
+ {
+ CenterX = bd.data.serializedFloats[0];
+ CenterY = bd.data.serializedFloats[1];
+ Width = bd.data.serializedFloats[2];
+ Height = bd.data.serializedFloats[3];
+
+
+ rectColor = bd.data.serializedColors[0];
+
+
+ base.PopulateFromBase(bd);
+ }
+
+ #endregion
+
+
+ }
}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRoundedRect.cs b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRoundedRect.cs
index 2388dd0..d9c5378 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRoundedRect.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/DrawCommands/DrawRoundedRect.cs
@@ -2,170 +2,221 @@
using UnityEditor;
using System.Collections;
-namespace SpriteMaker{
-
-
-
- ///
- /// Draws a rounded Rectangle onto the canvas
- ///
- public class DrawRoundedRect : BaseDrawCommand {
-
-
- public float CenterX = 0.5f,CenterY = 0.5f;
- public float Width = 0.8f,Height = 0.8f;
- public float CornerRadius = 0.1f;
- public float Smoothness = 0.0f;
- public Color rectColor = Color.red;
-
- private int pixelPosX;
- private int pixelPosY;
- private int pixelWidth;
- private int pixelHeight;
- private int pixelRadius;
-
- private Vector2 positionVector;
- private Vector2 tempVector;
-
- //TODO: CornerRadius affects the size of the Rectangle for some reason.
- //TODO: Corner Radius can be larger than total rectangle size.
- //TODO: general cleanup.
- //TODO: the way the radius is defined and used here leaves much to be desired for extreme roundedrects
- //TODO: Lazy Implementation - there's no need to loop through the array so much, can be condensed.
- public override Color[] DrawToColorArray (Color[] _input, int _width, int _height)
- {
-
- Color[] tempArray = new Color[_input.Length];
-
- pixelPosX = Mathf.CeilToInt(CenterX * (float)_width);
- pixelPosY = Mathf.CeilToInt(CenterY * (float)_height);
- pixelWidth = Mathf.CeilToInt(Width * (_width));
- pixelHeight = Mathf.CeilToInt(Height * (_height));
- pixelRadius = Mathf.CeilToInt(CornerRadius * ((_width+_height)/2));
-
- //corners
- tempArray = DrawCircle (tempArray, _width, _height, pixelPosX + (pixelWidth / 2) - (pixelRadius / 2), pixelPosY + (pixelHeight / 2) - (pixelRadius / 2));
- tempArray = DrawCircle (tempArray, _width, _height, pixelPosX - (pixelWidth / 2) + (pixelRadius / 2), pixelPosY + (pixelHeight / 2) - (pixelRadius / 2));
- tempArray = DrawCircle (tempArray, _width, _height, pixelPosX + (pixelWidth / 2) - (pixelRadius / 2), pixelPosY - (pixelHeight / 2) + (pixelRadius / 2));
- tempArray = DrawCircle (tempArray, _width, _height, pixelPosX - (pixelWidth / 2) + (pixelRadius / 2), pixelPosY - (pixelHeight / 2) + (pixelRadius / 2));
-
- //body
- tempArray = DrawRect (tempArray,
- _width,
- _height,
- pixelPosX - (pixelWidth / 2) + (pixelRadius / 2),
- pixelPosX + (pixelWidth / 2) - (pixelRadius / 2),
- pixelPosY + (pixelHeight / 2) + (pixelRadius / 2),
- pixelPosY - (pixelHeight /2) - (pixelRadius / 2)
- );
- tempArray = DrawRect (tempArray,
- _width,
- _height,
- pixelPosX - (pixelWidth / 2) - (pixelRadius / 2),
- pixelPosX + (pixelWidth / 2) + (pixelRadius / 2),
- pixelPosY + (pixelHeight / 2) - (pixelRadius / 2),
- pixelPosY - (pixelHeight /2) + (pixelRadius / 2)
- );
+namespace SpriteMaker
+{
+
+
+
+ ///
+ /// Draws a rounded Rectangle onto the canvas
+ ///
+ public class DrawRoundedRect : BaseDrawCommand
+ {
+
+
+ public float CenterX = 0.5f, CenterY = 0.5f;
+ public float Width = 0.8f, Height = 0.8f;
+ public float CornerRadius = 0.1f;
+ public float Smoothness = 0.0f;
+ public Color rectColor = Color.red;
+
+ private int pixelPosX;
+ private int pixelPosY;
+ private int pixelWidth;
+ private int pixelHeight;
+ private int pixelRadius;
+
+ private Vector2 positionVector;
+ private Vector2 tempVector;
+
+ //TODO: CornerRadius affects the size of the Rectangle for some reason.
+ //TODO: Corner Radius can be larger than total rectangle size.
+ //TODO: general cleanup.
+ //TODO: the way the radius is defined and used here leaves much to be desired for extreme roundedrects
+ //TODO: Lazy Implementation - there's no need to loop through the array so much, can be condensed.
+ public override Color[] DrawToColorArray(Color[] _input, int _width, int _height)
+ {
+
+ Color[] tempArray = new Color[_input.Length];
+
+ pixelPosX = Mathf.CeilToInt(CenterX * (float)_width);
+ pixelPosY = Mathf.CeilToInt(CenterY * (float)_height);
+ pixelWidth = Mathf.CeilToInt(Width * (_width));
+ pixelHeight = Mathf.CeilToInt(Height * (_height));
+ pixelRadius = Mathf.CeilToInt(CornerRadius * ((_width + _height) / 2));
+
+ //corners
+ tempArray = DrawCircle(tempArray, _width, _height, pixelPosX + (pixelWidth / 2) - (pixelRadius / 2), pixelPosY + (pixelHeight / 2) - (pixelRadius / 2));
+ tempArray = DrawCircle(tempArray, _width, _height, pixelPosX - (pixelWidth / 2) + (pixelRadius / 2), pixelPosY + (pixelHeight / 2) - (pixelRadius / 2));
+ tempArray = DrawCircle(tempArray, _width, _height, pixelPosX + (pixelWidth / 2) - (pixelRadius / 2), pixelPosY - (pixelHeight / 2) + (pixelRadius / 2));
+ tempArray = DrawCircle(tempArray, _width, _height, pixelPosX - (pixelWidth / 2) + (pixelRadius / 2), pixelPosY - (pixelHeight / 2) + (pixelRadius / 2));
+
+ //body
+ tempArray = DrawRect(tempArray,
+ _width,
+ _height,
+ pixelPosX - (pixelWidth / 2) + (pixelRadius / 2),
+ pixelPosX + (pixelWidth / 2) - (pixelRadius / 2),
+ pixelPosY + (pixelHeight / 2) + (pixelRadius / 2),
+ pixelPosY - (pixelHeight / 2) - (pixelRadius / 2)
+ );
+ tempArray = DrawRect(tempArray,
+ _width,
+ _height,
+ pixelPosX - (pixelWidth / 2) - (pixelRadius / 2),
+ pixelPosX + (pixelWidth / 2) + (pixelRadius / 2),
+ pixelPosY + (pixelHeight / 2) - (pixelRadius / 2),
+ pixelPosY - (pixelHeight / 2) + (pixelRadius / 2)
+ );
- for (int x = 0; x < tempArray.Length; x++) {
+ for (int x = 0; x < tempArray.Length; x++)
+ {
+
+ Color c = tempArray[x];
+ _input[x] = BlendPixelToCanvas(c, _input[x]);
+
+ }
- Color c = tempArray [x];
- _input [x] = BlendPixelToCanvas(c,_input[x]);
+ return base.DrawToColorArray(_input, _width, _height);
+ }
- }
+ private Color[] DrawCircle(Color[] _input, int _width, int _height, int _pixPosX, int _pixPosY)
+ {
- return base.DrawToColorArray (_input, _width, _height);
- }
+ positionVector.x = _pixPosX;
+ positionVector.y = _pixPosY;
- private Color[] DrawCircle (Color[] _input, int _width, int _height, int _pixPosX, int _pixPosY)
- {
+ int leftBounds = _pixPosX - pixelRadius;
+ int rightBounds = _pixPosX + pixelRadius;
+ int upperBounds = _pixPosY + pixelRadius;
+ int lowerBounds = _pixPosY - pixelRadius;
- positionVector.x = _pixPosX;
- positionVector.y = _pixPosY;
+ for (int x = leftBounds; x <= rightBounds; x++)
+ {
+ tempVector.x = x;
+ if (x >= 0 && x < _width)
+ {
+ for (int y = lowerBounds; y <= upperBounds; y++)
+ {
+ if (y >= 0 && y < _height)
+ {
+ tempVector.y = y;
+ Color c = rectColor;
+ c.a = 1.0f - Vector2.Distance(positionVector, tempVector) / pixelRadius;
+ if (c.a > Smoothness)
+ {
+ c.a = 1.0f;
+ }
+ else
+ {
+ c.a = Mathf.InverseLerp(0, Smoothness, c.a);
+ }
+ c.a *= rectColor.a;
- int leftBounds = _pixPosX - pixelRadius;
- int rightBounds = _pixPosX + pixelRadius;
- int upperBounds = _pixPosY + pixelRadius;
- int lowerBounds = _pixPosY - pixelRadius;
- for (int x = leftBounds; x <= rightBounds; x++) {
- tempVector.x = x;
- if (x >= 0 && x < _width) {
- for (int y = lowerBounds; y <= upperBounds; y++) {
- if (y >= 0 && y < _height) {
- tempVector.y = y;
- Color c = rectColor;
- c.a = 1.0f - Vector2.Distance (positionVector, tempVector) / pixelRadius;
- if (c.a > Smoothness) {
- c.a = 1.0f;
- } else {
- c.a = Mathf.InverseLerp (0, Smoothness, c.a);
- }
- c.a *= rectColor.a;
+ if (c.a != 0)
+ {
+ c.r = (c.r * c.a) + ((1 - c.a) * _input[y * _width + x].r);
+ c.g = (c.g * c.a) + ((1 - c.a) * _input[y * _width + x].g);
+ c.b = (c.b * c.a) + ((1 - c.a) * _input[y * _width + x].b);
+ c.a = Mathf.Max(c.a, _input[y * _width + x].a);
- if (c.a != 0) {
- c.r = (c.r * c.a) + ((1 - c.a) * _input [y * _width + x].r);
- c.g = (c.g * c.a) + ((1 - c.a) * _input [y * _width + x].g);
- c.b = (c.b * c.a) + ((1 - c.a) * _input [y * _width + x].b);
+ _input[y * _width + x] = c;
+ }
- c.a = Mathf.Max( c.a, _input [y * _width + x].a);
- _input [y * _width + x] = c;
- }
+ }
+ }
+ }
+ }
+ return _input;
+ }
- }
- }
- }
- }
+ private Color[] DrawRect(Color[] _input, int _width, int _height, int leftBounds, int rightBounds, int upperBounds, int lowerBounds)
+ {
+ for (int x = leftBounds; x <= rightBounds; x++)
+ {
+ if (x >= 0 && x < _width)
+ {
+ for (int y = lowerBounds; y <= upperBounds; y++)
+ {
+ if (y >= 0 && y < _height)
+ {
- return _input;
- }
- private Color[] DrawRect(Color[] _input,int _width, int _height, int leftBounds, int rightBounds, int upperBounds, int lowerBounds)
- {
- for (int x = leftBounds; x <= rightBounds; x++) {
- if (x >= 0 && x < _width) {
- for (int y = lowerBounds; y <= upperBounds; y++) {
- if (y >= 0 && y < _height) {
+ Color c = rectColor;
- Color c = rectColor;
+ c.r = (c.r * c.a) + ((1 - c.a) * _input[y * _width + x].r);
+ c.g = (c.g * c.a) + ((1 - c.a) * _input[y * _width + x].g);
+ c.b = (c.b * c.a) + ((1 - c.a) * _input[y * _width + x].b);
+ c.a = Mathf.Max(c.a, _input[y * _width + x].a);
- c.r = (c.r * c.a) + ((1 - c.a) * _input [y * _width + x].r);
- c.g = (c.g * c.a) + ((1 - c.a) * _input [y * _width + x].g);
- c.b = (c.b * c.a) + ((1 - c.a) * _input [y * _width + x].b);
+ _input[y * _width + x] = c;
- c.a = Mathf.Max(c.a,_input [y * _width + x].a);
+ }
+ }
+ }
+ }
+ return _input;
+ }
- _input [y * _width + x] = c;
+ public override void DrawControls()
+ {
+ Name = "RoundedRect";
+ rectColor = EditorGUILayout.ColorField("Color", rectColor);
+ CenterX = float.Parse(EditorGUILayout.TextField("X Position", CenterX.ToString()));
+ CenterY = float.Parse(EditorGUILayout.TextField("Y Position", CenterY.ToString()));
+ Width = float.Parse(EditorGUILayout.TextField("Width", Width.ToString()));
+ Height = float.Parse(EditorGUILayout.TextField("Height", Height.ToString()));
+ CornerRadius = float.Parse(EditorGUILayout.TextField("Corner Radius", CornerRadius.ToString()));
+ Smoothness = float.Parse(EditorGUILayout.TextField("Smoothness", Smoothness.ToString()));
- }
- }
- }
- }
- return _input;
- }
- public override void DrawControls ()
- {
- Name = "RoundedRect";
- rectColor = EditorGUILayout.ColorField ("Color", rectColor);
- CenterX = float.Parse(EditorGUILayout.TextField ("X Position", CenterX.ToString()));
- CenterY = float.Parse(EditorGUILayout.TextField ("Y Position", CenterY.ToString()));
- Width = float.Parse(EditorGUILayout.TextField ("Width", Width.ToString()));
- Height = float.Parse(EditorGUILayout.TextField ("Height", Height.ToString()));
- CornerRadius = float.Parse (EditorGUILayout.TextField ("Corner Radius", CornerRadius.ToString ()));
- Smoothness = float.Parse (EditorGUILayout.TextField ("Smoothness", Smoothness.ToString ()));
+ base.DrawControls();
+ }
+
+
+ #region SERIALIZATION
+
+ public override void OnBeforeSerialize()
+ {
+ data = new SerializedData();
+
+ data.serializedFloats = new float[6];
+ data.serializedFloats[0] = CenterX;
+ data.serializedFloats[1] = CenterY;
+ data.serializedFloats[2] = Width;
+ data.serializedFloats[3] = Height;
+ data.serializedFloats[4] = CornerRadius;
+ data.serializedFloats[5] = Smoothness;
+
+ data.serializedColors = new Color[1];
+ data.serializedColors[0] = rectColor;
+
+ base.OnBeforeSerialize();
+ }
+
+ public override void PopulateFromBase(BaseDrawCommand bd)
+ {
+ CenterX = bd.data.serializedFloats[0];
+ CenterY = bd.data.serializedFloats[1];
+ Width = bd.data.serializedFloats[2];
+ Height = bd.data.serializedFloats[3];
+ CornerRadius = bd.data.serializedFloats[4];
+ Smoothness = bd.data.serializedFloats[5];
+ rectColor = bd.data.serializedColors[0];
- base.DrawControls ();
- }
+ base.PopulateFromBase(bd);
+ }
+ #endregion
- }
+ }
}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/ScriptableGradientAsset.cs b/SpriteMaker/Assets/SpriteMaker/Editor/ScriptableGradientAsset.cs
new file mode 100644
index 0000000..7a8dbd5
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/ScriptableGradientAsset.cs
@@ -0,0 +1,14 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace SpriteMaker
+{
+ ///
+ /// we need a serializable object witha gradient to show a nice gradient editor. see the comment in DrawPerlin.cs
+ ///
+ public class ScriptableGradientAsset : ScriptableObject
+ {
+ public Gradient gradient;
+ }
+}
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/ScriptableGradientAsset.cs.meta b/SpriteMaker/Assets/SpriteMaker/Editor/ScriptableGradientAsset.cs.meta
new file mode 100644
index 0000000..54bcaac
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/ScriptableGradientAsset.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: 80d3a4a44ac2e46eebfc8b4a22240126
+timeCreated: 1490357695
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerAsset.cs b/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerAsset.cs
new file mode 100644
index 0000000..c86f873
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerAsset.cs
@@ -0,0 +1,72 @@
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+
+namespace SpriteMaker
+{
+
+
+ public class SpriteMakerAsset : ScriptableObject, ISerializationCallbackReceiver
+ {
+ [SerializeField]
+ public string FriendlyName;
+ [SerializeField]
+ public List DrawCommands;
+
+ public void OnBeforeSerialize()
+ {
+ foreach (BaseDrawCommand b in DrawCommands)
+ {
+ b.OnBeforeSerialize();
+ }
+ }
+
+ public void OnAfterDeserialize()
+ {
+ for (int i = 0; i < DrawCommands.Count; i++)
+ {
+
+ switch (DrawCommands[i].myType)
+ {
+ case BaseDrawCommand.DrawCommandType.Circle:
+ DrawCircle tempCircle = new DrawCircle();
+ tempCircle.myType = BaseDrawCommand.DrawCommandType.Circle;
+ tempCircle.PopulateFromBase(DrawCommands[i]);
+ DrawCommands[i] = tempCircle;
+ break;
+ case BaseDrawCommand.DrawCommandType.Fill:
+ DrawFill tempFill = new DrawFill();
+ tempFill.myType = BaseDrawCommand.DrawCommandType.Fill;
+ tempFill.PopulateFromBase(DrawCommands[i]);
+ DrawCommands[i] = tempFill;
+ break;
+ case BaseDrawCommand.DrawCommandType.Perlin:
+ DrawPerlin tempPerlin = new DrawPerlin();
+ tempPerlin.myType = BaseDrawCommand.DrawCommandType.Perlin;
+ tempPerlin.PopulateFromBase(DrawCommands[i]);
+ DrawCommands[i] = tempPerlin;
+ break;
+ case BaseDrawCommand.DrawCommandType.Rect:
+ DrawRect tempRect = new DrawRect();
+ tempRect.myType = BaseDrawCommand.DrawCommandType.Rect;
+ tempRect.PopulateFromBase(DrawCommands[i]);
+ DrawCommands[i] = tempRect;
+ break;
+ case BaseDrawCommand.DrawCommandType.RoundedRect:
+ DrawRoundedRect tempRRect = new DrawRoundedRect();
+ tempRRect.myType = BaseDrawCommand.DrawCommandType.RoundedRect;
+ tempRRect.PopulateFromBase(DrawCommands[i]);
+ DrawCommands[i] = tempRRect;
+ break;
+ default:
+ break;
+
+ }
+ }
+
+
+ }
+
+ }
+}
+
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerAsset.cs.meta b/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerAsset.cs.meta
new file mode 100644
index 0000000..7de3cec
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerAsset.cs.meta
@@ -0,0 +1,12 @@
+fileFormatVersion: 2
+guid: fa344e9c482bd4ff4a0129f4db912e6c
+timeCreated: 1490097553
+licenseType: Free
+MonoImporter:
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerEditor.cs b/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerEditor.cs
index 7499d8c..4cf860a 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerEditor.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/SpriteMakerEditor.cs
@@ -1,170 +1,298 @@
using UnityEngine;
using UnityEditor;
-namespace SpriteMaker{
-
- public class SpriteMakerEditor : EditorWindow {
-
- TextureBuilder texBuilder;
- DrawCommandManager drawCommandManager;
-
- SpritePreviewEditor spritePreview;
-
- private Vector2 ScrollPosition;
-
-
- private bool previewFocus = false;
- private bool updateOnChange = false;
-
- [MenuItem ("Window/SpriteMaker")]
- static void Init () {
- SpriteMakerEditor window = (SpriteMakerEditor)EditorWindow.GetWindow (typeof (SpriteMakerEditor),false,"Sprite Maker");
- window.texBuilder = new TextureBuilder ();
- window.drawCommandManager = new DrawCommandManager ();
- window.Show();
- }
-
- void OnGUI () {
-
- //if the editor window was left open on a new Unity bootup, init doesn't get called.
- if (texBuilder == null) {
- texBuilder = new TextureBuilder ();
- }
- if(drawCommandManager == null){
- drawCommandManager = new DrawCommandManager();
- }
-
- //we draw sprite info first so users can always hit preview
- GUISpriteInfo ();
-
-
-
- //scroll area for the draw commands
- ScrollPosition = EditorGUILayout.BeginScrollView (ScrollPosition);
- {
- EditorGUILayout.BeginVertical ();
- {
- GUIDrawCommands ();
- }
- EditorGUILayout.EndVertical ();
- }
- EditorGUILayout.EndScrollView ();
-
- if (previewFocus) {
- spritePreview.Focus ();
- previewFocus = false;
- }
-
-
- }
-
- ///
- /// Shows the preview Texture.
- ///
- /// The texture to preview
- private void ShowPreview(Texture2D _tex)
- {
- if (spritePreview == null) {
- spritePreview = (SpritePreviewEditor)EditorWindow.GetWindow (typeof(SpritePreviewEditor),false,"Sprite Preview");
- spritePreview.Show ();
- }
- spritePreview.SetTexture (_tex);
- }
-
- ///
- /// Previews the texture.
- ///
- private void PreviewTexture()
- {
- ShowPreview (texBuilder.BuildTexture (drawCommandManager.GetDrawCommands()));
- }
-
-
- ///
- /// Triggers a preview than asks the TextureBuilder to save the texture
- ///
- private void SaveTexture()
- {
- PreviewTexture ();
- texBuilder.SaveTexture ();
- }
+namespace SpriteMaker
+{
+
+ public class SpriteMakerEditor : EditorWindow
+ {
+ TextureBuilder texBuilder;
+ DrawCommandManager drawCommandManager;
- ///
- /// Draws info at the highest level for the sprite (Filename, pixel size, etc)
- ///
- private void GUISpriteInfo()
- {
- GUILayout.Label ("Sprite Info", EditorStyles.boldLabel);
+ SpritePreviewEditor spritePreview;
- EditorGUILayout.BeginVertical ("Box");{
+ private Vector2 ScrollPosition;
- texBuilder.fileName = EditorGUILayout.TextField ("File Name", texBuilder.fileName);
- EditorGUILayout.BeginHorizontal ();
- {
- GUILayout.Label ("Width");
- texBuilder.pixelWidth = GetIntFromTextField (EditorGUILayout.TextField (texBuilder.pixelWidth.ToString ()));
- GUILayout.Label ("Height");
-
- texBuilder.pixelHeight = GetIntFromTextField (EditorGUILayout.TextField (texBuilder.pixelHeight.ToString ()));
- }
- EditorGUILayout.EndHorizontal ();
-
- updateOnChange = GUILayout.Toggle (updateOnChange, "Auto-Preview (Use Low Image Sizes)");
-
- EditorGUILayout.BeginHorizontal ();
- {
- if (GUILayout.Button ("Preview Texture")) {
- PreviewTexture ();
- previewFocus = true;
- }
- if (updateOnChange) {
- PreviewTexture ();
- }
- if (GUILayout.Button ("Save Texture")) {
- SaveTexture ();
- previewFocus = true;
- }
- }EditorGUILayout.EndHorizontal ();
-
- }EditorGUILayout.EndVertical ();
- }
-
- ///
- /// sets up the GUI for drawCommandManager to draw the commands
- ///
- private void GUIDrawCommands()
- {
-
- GUILayout.Label ("Draw Commands", EditorStyles.boldLabel);
-
- EditorGUILayout.BeginVertical ("Box");{
-
-
- drawCommandManager.DrawControls ();
-
-
-
- }EditorGUILayout.EndVertical ();
- }
+ private bool previewFocus = false;
+ private bool updateOnChange = false;
+ private bool saveOnChange = false;
- int temp = 0;
-
- ///
- /// Helper function for textfields using Ints
- ///
- private int GetIntFromTextField(string _text)
- {
- temp = 0;
- if (int.TryParse (_text, out temp)) {
- temp = Mathf.Abs (temp); //No negatives
- } else {
- temp = 0;
- }
- return temp;
- }
-
-
- }
+ private bool showFile = true;
+ private bool showSpriteInfo = true;
+ private bool showDrawCommands = true;
+
+
+ //Files
+ private SpriteMakerAsset activeAsset;
+ private SpriteMakerAsset loadAsset;
+
+
+ [MenuItem("Window/SpriteMaker")]
+ static void Init()
+ {
+ SpriteMakerEditor window = (SpriteMakerEditor)EditorWindow.GetWindow(typeof(SpriteMakerEditor), false, "Sprite Maker");
+ window.texBuilder = new TextureBuilder();
+ window.drawCommandManager = new DrawCommandManager();
+ window.Show();
+ }
+
+ void OnGUI()
+ {
+
+ //if the editor window was left open on a new Unity bootup, init doesn't get called.
+ if (texBuilder == null)
+ {
+ texBuilder = new TextureBuilder();
+ }
+ if (drawCommandManager == null)
+ {
+ drawCommandManager = new DrawCommandManager();
+ }
+
+ //we draw file ops up top
+ GUISpriteMaker();
+
+ //we only show further GUI if there's an asset loaded.
+ if (activeAsset != null)
+ {
+ Undo.RecordObject(activeAsset, "Spritemaker Asset changed");
+
+ //we draw sprite info first so users can always hit preview
+ GUISpriteInfo();
+
+
+
+ EditorGUI.BeginChangeCheck();
+ {
+ //scroll area for the draw commands
+ ScrollPosition = EditorGUILayout.BeginScrollView(ScrollPosition);
+ {
+ EditorGUILayout.BeginVertical();
+ {
+ GUIDrawCommands();
+ }
+ EditorGUILayout.EndVertical();
+ }
+ EditorGUILayout.EndScrollView();
+
+
+ if (EditorGUI.EndChangeCheck())
+ {
+ if (updateOnChange)
+ {
+ PreviewTexture();
+ }
+ if (saveOnChange)
+ {
+ SaveAssetFile(false);
+ }
+ }
+ }
+
+
+
+ }
+
+ if (previewFocus)
+ {
+ spritePreview.Focus();
+ previewFocus = false;
+ }
+
+
+
+ }
+
+ ///
+ /// Shows the preview Texture.
+ ///
+ /// The texture to preview
+ private void ShowPreview(Texture2D _tex)
+ {
+ if (spritePreview == null)
+ {
+ spritePreview = (SpritePreviewEditor)EditorWindow.GetWindow(typeof(SpritePreviewEditor), false, "Sprite Preview");
+ spritePreview.Show();
+ }
+ spritePreview.SetTexture(_tex);
+ }
+
+ ///
+ /// Previews the texture.
+ ///
+ private void PreviewTexture()
+ {
+ ShowPreview(texBuilder.BuildTexture(activeAsset.DrawCommands));
+ }
+
+
+ ///
+ /// Triggers a preview than asks the TextureBuilder to save the texture
+ ///
+ private void SaveTexture()
+ {
+ PreviewTexture();
+ texBuilder.SaveTexture();
+ }
+
+
+ ///
+ /// Saves the asset file toa scriptable object
+ ///
+ /// If set to true, will focus the asset file in the editor
+ private void SaveAssetFile(bool shouldFocus = false)
+ {
+ EditorUtility.SetDirty(activeAsset);
+ AssetDatabase.SaveAssets();
+ AssetDatabase.Refresh();
+ if (shouldFocus)
+ {
+ EditorUtility.FocusProjectWindow();
+ Selection.activeObject = activeAsset;
+ }
+ }
+
+
+
+ private void GUISpriteMaker()
+ {
+ showFile = GUILayout.Toggle(showFile, "File Ops", EditorStyles.boldLabel);
+ if (showFile)
+ {
+ EditorGUILayout.BeginVertical("Box");
+ {
+ if (GUILayout.Button("New Asset File"))
+ {
+ SpriteMakerAsset temp = ScriptableObject.CreateInstance();
+ temp.FriendlyName = texBuilder.fileName;
+ drawCommandManager.SetupAsset(ref temp);
+ string AssetPath = AssetDatabase.GenerateUniqueAssetPath("Assets/" + temp.FriendlyName + ".asset");
+ AssetDatabase.CreateAsset(temp, AssetPath);
+
+ AssetDatabase.SaveAssets();
+ AssetDatabase.Refresh();
+ activeAsset = temp;
+ EditorUtility.FocusProjectWindow();
+ Selection.activeObject = temp;
+
+ }
+ //TODO do we need manual save
+ if (GUILayout.Button("Save Asset File"))
+ {
+
+ SaveAssetFile(true);
+ }
+ saveOnChange = GUILayout.Toggle(saveOnChange, "Auto-Save (Experimental)");
+
+
+ loadAsset = (SpriteMakerAsset)EditorGUILayout.ObjectField(activeAsset, typeof(SpriteMakerAsset), false);
+ if (activeAsset != loadAsset)
+ {
+ activeAsset = loadAsset;
+ drawCommandManager.UseAsset(ref activeAsset);
+ texBuilder.fileName = activeAsset.FriendlyName;
+ }
+ if (activeAsset != null)
+ {
+ EditorGUILayout.LabelField("Currently Editing: " + activeAsset.FriendlyName);
+ }
+
+ }
+ EditorGUILayout.EndVertical();
+ }
+ }
+
+ ///
+ /// Draws info at the highest level for the sprite (Filename, pixel size, etc)
+ ///
+ private void GUISpriteInfo()
+ {
+ showSpriteInfo = GUILayout.Toggle(showSpriteInfo, "Sprite Info", EditorStyles.boldLabel);
+
+ if (showSpriteInfo)
+ {
+ EditorGUILayout.BeginVertical("Box");
+ {
+
+ texBuilder.fileName = activeAsset.FriendlyName = EditorGUILayout.TextField("File Name", texBuilder.fileName);
+ EditorGUILayout.BeginHorizontal();
+ {
+ GUILayout.Label("Width");
+ texBuilder.pixelWidth = GetIntFromTextField(EditorGUILayout.TextField(texBuilder.pixelWidth.ToString()));
+ GUILayout.Label("Height");
+
+ texBuilder.pixelHeight = GetIntFromTextField(EditorGUILayout.TextField(texBuilder.pixelHeight.ToString()));
+ }
+ EditorGUILayout.EndHorizontal();
+
+ updateOnChange = GUILayout.Toggle(updateOnChange, "Auto-Preview (Use Low Image Sizes)");
+
+ EditorGUILayout.BeginHorizontal();
+ {
+ if (GUILayout.Button("Preview Texture"))
+ {
+ PreviewTexture();
+ previewFocus = true;
+ }
+
+
+ if (GUILayout.Button("Save Texture"))
+ {
+ SaveTexture();
+ previewFocus = true;
+ }
+ }
+ EditorGUILayout.EndHorizontal();
+
+ }
+ EditorGUILayout.EndVertical();
+ }
+ }
+
+ ///
+ /// sets up the GUI for drawCommandManager to draw the commands
+ ///
+ private void GUIDrawCommands()
+ {
+ showDrawCommands = GUILayout.Toggle(showDrawCommands, "DrawCommands", EditorStyles.boldLabel);
+
+ if (showDrawCommands)
+ {
+ EditorGUILayout.BeginVertical("Box");
+ {
+
+
+ drawCommandManager.DrawControls(ref activeAsset);
+
+
+
+ }
+ EditorGUILayout.EndVertical();
+ }
+ }
+
+
+ int temp = 0;
+
+ ///
+ /// Helper function for textfields using Ints
+ ///
+ private int GetIntFromTextField(string _text)
+ {
+ temp = 0;
+ if (int.TryParse(_text, out temp))
+ {
+ temp = Mathf.Abs(temp); //No negatives
+ }
+ else
+ {
+ temp = 0;
+ }
+ return temp;
+ }
+
+
+ }
}
\ No newline at end of file
diff --git a/SpriteMaker/Assets/SpriteMaker/Editor/SpritePreviewEditor.cs b/SpriteMaker/Assets/SpriteMaker/Editor/SpritePreviewEditor.cs
index 98eba20..98f8e98 100644
--- a/SpriteMaker/Assets/SpriteMaker/Editor/SpritePreviewEditor.cs
+++ b/SpriteMaker/Assets/SpriteMaker/Editor/SpritePreviewEditor.cs
@@ -1,30 +1,56 @@
using UnityEngine;
using UnityEditor;
-namespace SpriteMaker{
- ///
- /// Handles the SPrite Preview Window
- ///
- public class SpritePreviewEditor : EditorWindow {
+namespace SpriteMaker
+{
- public Texture2D mTex;
- private Texture2D mGray;
+ ///
+ /// Handles the SPrite Preview Window
+ ///
+ public class SpritePreviewEditor : EditorWindow
+ {
+ public Texture2D mTex;
+ private Texture2D mGray;
+ private Material eMaterial;
+ private Material aMaterial;
- void OnGUI()
- {
- if (mTex != null) {
- EditorGUI.DrawPreviewTexture (new Rect(0,0,position.width,position.height),mTex,null,ScaleMode.ScaleToFit,1.0f);
- }
- }
+ private const float scaleFactor = 16.0f;
+ //probably best not to go past 24
- public void SetTexture(Texture2D _tex)
- {
- mTex = _tex;
- mTex.filterMode = FilterMode.Point;
- base.Repaint ();
- }
- }
+ void OnGUI()
+ {
+ if (mGray == null)
+ {
+ mGray = Resources.Load("Checkers");
+ }
+
+
+
+ Rect g = new Rect(0, 0, position.width, position.height);
+ EditorGUI.DrawPreviewTexture(g, mGray, null, ScaleMode.StretchToFill, 1.0f);
+
+
+ if (eMaterial == null)
+ {
+ eMaterial = Resources.Load("EditorMaterial");
+ }
+
+ if (mTex != null)
+ {
+ EditorGUI.DrawPreviewTexture(new Rect(0, 0, position.width, position.height), mTex, eMaterial, ScaleMode.ScaleToFit, 1.0f);
+ }
+ }
+
+ public void SetTexture(Texture2D _tex)
+ {
+
+ mTex = _tex;
+ mTex.filterMode = FilterMode.Point;
+ base.Repaint();
+
+ }
+ }
}
diff --git a/SpriteMaker/Assets/SpriteMaker/Examples.meta b/SpriteMaker/Assets/SpriteMaker/Examples.meta
new file mode 100644
index 0000000..0a3280f
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Examples.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: e4bd9f4684cc54da2afd556e209c7299
+folderAsset: yes
+timeCreated: 1490271791
+licenseType: Free
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Examples/Face.asset b/SpriteMaker/Assets/SpriteMaker/Examples/Face.asset
new file mode 100644
index 0000000..1bd8d20
Binary files /dev/null and b/SpriteMaker/Assets/SpriteMaker/Examples/Face.asset differ
diff --git a/SpriteMaker/Assets/SpriteMaker/Examples/Face.asset.meta b/SpriteMaker/Assets/SpriteMaker/Examples/Face.asset.meta
new file mode 100644
index 0000000..4e289db
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Examples/Face.asset.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 49fe232bfac434c29bdb68482a3d5c24
+timeCreated: 1490271781
+licenseType: Free
+NativeFormatImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Examples/Perlin Blending.asset b/SpriteMaker/Assets/SpriteMaker/Examples/Perlin Blending.asset
new file mode 100644
index 0000000..5618ec7
Binary files /dev/null and b/SpriteMaker/Assets/SpriteMaker/Examples/Perlin Blending.asset differ
diff --git a/SpriteMaker/Assets/SpriteMaker/Examples/Perlin Blending.asset.meta b/SpriteMaker/Assets/SpriteMaker/Examples/Perlin Blending.asset.meta
new file mode 100644
index 0000000..50f5508
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Examples/Perlin Blending.asset.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 8e0b74127bd584aa3a1f1c0392944a11
+timeCreated: 1490391818
+licenseType: Free
+NativeFormatImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Resources.meta b/SpriteMaker/Assets/SpriteMaker/Resources.meta
new file mode 100644
index 0000000..2e4b34a
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Resources.meta
@@ -0,0 +1,9 @@
+fileFormatVersion: 2
+guid: a3c1437f39ecb498d9cb932501a53488
+folderAsset: yes
+timeCreated: 1490045390
+licenseType: Free
+DefaultImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Resources/Checkers.png b/SpriteMaker/Assets/SpriteMaker/Resources/Checkers.png
new file mode 100644
index 0000000..f839f7b
Binary files /dev/null and b/SpriteMaker/Assets/SpriteMaker/Resources/Checkers.png differ
diff --git a/SpriteMaker/Assets/SpriteMaker/Resources/Checkers.png.meta b/SpriteMaker/Assets/SpriteMaker/Resources/Checkers.png.meta
new file mode 100644
index 0000000..693f411
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Resources/Checkers.png.meta
@@ -0,0 +1,100 @@
+fileFormatVersion: 2
+guid: 969aac8e020ef4d29baa586b970740f4
+timeCreated: 1490045346
+licenseType: Free
+TextureImporter:
+ fileIDToRecycleName: {}
+ serializedVersion: 4
+ mipmaps:
+ mipMapMode: 0
+ enableMipMap: 0
+ sRGBTexture: 0
+ linearTexture: 0
+ fadeOut: 0
+ borderMipMap: 0
+ mipMapFadeDistanceStart: 1
+ mipMapFadeDistanceEnd: 3
+ bumpmap:
+ convertToNormalMap: 0
+ externalNormalMap: 0
+ heightScale: 0.25
+ normalMapFilter: 0
+ isReadable: 0
+ grayScaleToAlpha: 0
+ generateCubemap: 6
+ cubemapConvolution: 0
+ seamlessCubemap: 0
+ textureFormat: 1
+ maxTextureSize: 2048
+ textureSettings:
+ filterMode: 0
+ aniso: 1
+ mipBias: -1
+ wrapMode: 0
+ nPOTScale: 0
+ lightmap: 0
+ compressionQuality: 50
+ spriteMode: 1
+ spriteExtrude: 1
+ spriteMeshType: 1
+ alignment: 0
+ spritePivot: {x: 0.5, y: 0.5}
+ spriteBorder: {x: 0, y: 0, z: 0, w: 0}
+ spritePixelsToUnits: 100
+ alphaUsage: 1
+ alphaIsTransparency: 1
+ spriteTessellationDetail: -1
+ textureType: 2
+ textureShape: 1
+ maxTextureSizeSet: 0
+ compressionQualitySet: 0
+ textureFormatSet: 0
+ platformSettings:
+ - buildTarget: DefaultTexturePlatform
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 0
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ - buildTarget: Standalone
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 0
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ - buildTarget: iPhone
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 0
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ - buildTarget: Android
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 0
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ - buildTarget: WebGL
+ maxTextureSize: 2048
+ textureFormat: -1
+ textureCompression: 0
+ compressionQuality: 50
+ crunchedCompression: 0
+ allowsAlphaSplitting: 0
+ overridden: 0
+ spriteSheet:
+ serializedVersion: 2
+ sprites: []
+ outline: []
+ spritePackingTag:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/SpriteMaker/Assets/SpriteMaker/Resources/EditorMaterial.mat b/SpriteMaker/Assets/SpriteMaker/Resources/EditorMaterial.mat
new file mode 100644
index 0000000..5435574
Binary files /dev/null and b/SpriteMaker/Assets/SpriteMaker/Resources/EditorMaterial.mat differ
diff --git a/SpriteMaker/Assets/SpriteMaker/Resources/EditorMaterial.mat.meta b/SpriteMaker/Assets/SpriteMaker/Resources/EditorMaterial.mat.meta
new file mode 100644
index 0000000..417d694
--- /dev/null
+++ b/SpriteMaker/Assets/SpriteMaker/Resources/EditorMaterial.mat.meta
@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 0fde77bbcf0724ae7a6f89f3d2735742
+timeCreated: 1490045601
+licenseType: Free
+NativeFormatImporter:
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Usage.md b/Usage.md
index 0fa42f4..90e1550 100644
--- a/Usage.md
+++ b/Usage.md
@@ -8,7 +8,10 @@ Window -> SpriteMaker
![Editor Window](Gallery/Sprite Maker Editor.png)
-The editor Window currently consists of 2 elements: The Sprite Info Panel, and the Draw Command Queue
+The editor Window currently consists of 3 elements: File Ops, The Sprite Info Panel, and the Draw Command Queue
+
+###File Ops
+File Ops provides an interface for loading, saving and creating SpriteMakerAssets, ScriptableObjects used to save working files.
###Sprite Info
This Panel Allows you to select the name for your finished asset as well as its width and height in pixels. There are buttons at the bottom of this panel for previewing and saving your asset.