-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from bdovaz/feature/format
Format code
- Loading branch information
Showing
32 changed files
with
1,141 additions
and
1,207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[*.cs] | ||
charset = utf-8 | ||
end_of_line = lf | ||
indent_style = space | ||
indent_size = 4 | ||
trim_trailing_whitespace = true |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// Original from http://wiki.unity3d.com/index.php/EditorGraphWindow | ||
|
||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Mumble.Editor | ||
{ | ||
public class GraphChannel | ||
{ | ||
public int numPoints = 0; | ||
public float[] _data = new float[Graph.MAX_HISTORY]; | ||
public Color _color = Color.white; | ||
public bool isActive = false; | ||
|
||
private float yMin, yMax; | ||
|
||
public GraphChannel(Color _C) | ||
{ | ||
_color = _C; | ||
} | ||
|
||
public void Feed(float val) | ||
{ | ||
if (val > yMax) | ||
{ | ||
yMax = val; | ||
Graph.UpdateMax(yMin, yMax); | ||
} | ||
if (val < yMin) | ||
{ | ||
yMin = val; | ||
Graph.UpdateMax(yMin, yMax); | ||
} | ||
|
||
// Shift all values over | ||
for (int i = Graph.MAX_HISTORY - 1; i >= 1; i--) | ||
_data[i] = _data[i - 1]; | ||
|
||
_data[0] = val; | ||
|
||
numPoints = Mathf.Min(numPoints + 1, Graph.MAX_HISTORY); | ||
isActive = true; | ||
} | ||
} | ||
|
||
public class Graph | ||
{ | ||
public static float YMin, YMax; | ||
|
||
public const int MAX_HISTORY = 1024; | ||
public const int MAX_CHANNELS = 3; | ||
|
||
public static GraphChannel[] channel = new GraphChannel[MAX_CHANNELS]; | ||
|
||
static Graph() | ||
{ | ||
channel[0] = new GraphChannel(Color.gray); | ||
channel[1] = new GraphChannel(Color.blue); | ||
channel[2] = new GraphChannel(Color.red); | ||
} | ||
|
||
public static void UpdateMax(float newMin, float newMax) | ||
{ | ||
YMin = Mathf.Min(YMin, newMin); | ||
YMax = Mathf.Max(YMax, newMax); | ||
} | ||
} | ||
|
||
public class EditorGraph : EditorWindow | ||
{ | ||
[MenuItem("Window/Graph")] | ||
static void ShowGraph() | ||
{ | ||
GetWindow<EditorGraph>(); | ||
} | ||
|
||
Material lineMaterial; | ||
|
||
void OnEnable() | ||
{ | ||
EditorApplication.update += OnEditorUpdate; | ||
} | ||
|
||
void OnDisable() | ||
{ | ||
EditorApplication.update -= OnEditorUpdate; | ||
} | ||
|
||
void OnEditorUpdate() | ||
{ | ||
Repaint(); | ||
} | ||
|
||
void CreateLineMaterial() | ||
{ | ||
if (!lineMaterial) | ||
{ | ||
lineMaterial = new Material(Shader.Find("Unlit/GraphShader")) | ||
{ | ||
hideFlags = HideFlags.HideAndDontSave | ||
}; | ||
lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave; | ||
} | ||
} | ||
|
||
void OnGUI() | ||
{ | ||
if (Event.current.type != EventType.Repaint) | ||
return; | ||
|
||
if (Graph.channel[0] == null) | ||
return; | ||
|
||
int W = (int)position.width; | ||
int H = (int)position.height; | ||
|
||
CreateLineMaterial(); | ||
lineMaterial.SetPass(0); | ||
|
||
GL.PushMatrix(); | ||
GL.LoadPixelMatrix(); | ||
|
||
GL.Begin(GL.LINES); | ||
|
||
for (int chan = 0; chan < Graph.MAX_CHANNELS; chan++) | ||
{ | ||
GraphChannel C = Graph.channel[chan]; | ||
|
||
if (!C.isActive) | ||
continue; | ||
|
||
GL.Color(C._color); | ||
|
||
for (int h = 0; h < Graph.MAX_HISTORY; h++) | ||
{ | ||
int xPix = (W - 1) - h; | ||
|
||
if (xPix >= 0) | ||
{ | ||
float y = C._data[h]; | ||
|
||
float y_01 = Mathf.InverseLerp(Graph.YMin, Graph.YMax, y); | ||
|
||
int yPix = (int)(y_01 * H); | ||
|
||
Plot(xPix, yPix); | ||
} | ||
} | ||
} | ||
|
||
GL.End(); | ||
|
||
GL.PopMatrix(); | ||
} | ||
|
||
// Plot an X | ||
void Plot(float x, float y) | ||
{ | ||
// First line of X | ||
GL.Vertex3(x - 1, y - 1, 0); | ||
GL.Vertex3(x + 1, y + 1, 0); | ||
|
||
// Second | ||
GL.Vertex3(x - 1, y + 1, 0); | ||
GL.Vertex3(x + 1, y - 1, 0); | ||
} | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "Mumble.Editor", | ||
"rootNamespace": "", | ||
"references": [], | ||
"includePlatforms": [ | ||
"Editor" | ||
], | ||
"excludePlatforms": [], | ||
"allowUnsafeCode": false, | ||
"overrideReferences": false, | ||
"precompiledReferences": [], | ||
"autoReferenced": true, | ||
"defineConstraints": [], | ||
"versionDefines": [], | ||
"noEngineReferences": false | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.