Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.4.0 #29

Merged
merged 15 commits into from
Mar 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
384 changes: 218 additions & 166 deletions Assets/Editor.unity

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Assets/Editor/ImageEffects/ColorCorrectionLookupEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,15 @@ class ColorCorrectionLookupEditor : Editor
if (textureImporter.mipmapEnabled == true) {
doImport = true;
}
if (textureImporter.textureFormat != TextureImporterFormat.AutomaticTruecolor) {
if (textureImporter.textureCompression != TextureImporterCompression.Uncompressed) {
doImport = true;
}

if (doImport)
{
textureImporter.isReadable = true;
textureImporter.mipmapEnabled = false;
textureImporter.textureFormat = TextureImporterFormat.AutomaticTruecolor;
textureImporter.textureCompression = TextureImporterCompression.Uncompressed;
AssetDatabase.ImportAsset (path, ImportAssetOptions.ForceUpdate);
//tex = AssetDatabase.LoadMainAssetAtPath(path);
}
Expand Down
111 changes: 111 additions & 0 deletions Assets/Editor/ProfilerUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
using System.IO;
using System.Reflection;
using UnityEditor;
using UnityEditorInternal;

public class ProfilerUtil
{
private const string HtmlOutputPath = "profiler.html";

[MenuItem("Tools/Dump selected profiler frame to HTML")]
public static void DumpProfilerFrame()
{
var property = new ProfilerProperty();
property.SetRoot(GetSelectedFrame(), ProfilerColumn.TotalPercent, ProfilerViewType.Hierarchy);
property.onlyShowGPUSamples = false;

if (File.Exists(HtmlOutputPath))
File.Delete(HtmlOutputPath);
var stream = File.OpenWrite(HtmlOutputPath);
var writer = new StreamWriter(stream);

writer.WriteLine(@"<html>
<head>
<title>Unity Profiler Data</title>
<style type=""text/css"">
html, body {
font-family: Helvetica, Arial, sans-serif;
}
table {
width: 100%;
border-collapse: collapse;
}
th:first-child, td:first-child {
text-align: left;
}
th:not(:first-child), td:not(:first-child) {
text-align: right;
}
tbody tr:nth-child(odd) {
background-color: #EEE;
}
th, td {
margin: 0;
padding: 5px;
}
th {
padding-bottom: 10px;
}
td {
font-size: 12px;
}
</style>
</head>
<body>
<table>
<thead>
<tr><th>Path</th><th>Total</th><th>Self</th><th>Calls</th><th>GC Alloc</th><th>Total ms</th><th>Self ms</th></tr>
</thead>
<tbody>");

while (property.Next(true))
{
writer.Write("<td style=\"padding-left:" + property.depth * 10 + "px\">");
writer.Write(property.GetColumn(ProfilerColumn.FunctionName));
writer.Write("</td>");

writer.Write("<td>");
writer.Write(property.GetColumn(ProfilerColumn.TotalPercent));
writer.Write("</td>");

writer.Write("<td>");
writer.Write(property.GetColumn(ProfilerColumn.SelfPercent));
writer.Write("</td>");

writer.Write("<td>");
writer.Write(property.GetColumn(ProfilerColumn.Calls));
writer.Write("</td>");

writer.Write("<td>");
writer.Write(property.GetColumn(ProfilerColumn.GCMemory));
writer.Write("</td>");

writer.Write("<td>");
writer.Write(property.GetColumn(ProfilerColumn.TotalTime));
writer.Write("</td>");

writer.Write("<td>");
writer.Write(property.GetColumn(ProfilerColumn.SelfTime));
writer.Write("</td>");

writer.WriteLine("</tr>");
}

writer.WriteLine(@"</tbody>
</table>
</body>
</html>");

writer.Close();
}

private static int GetSelectedFrame()
{
var editorAssembly = Assembly.GetAssembly(typeof(EditorApplication));
var profilerWindowType = editorAssembly.GetType("UnityEditor.ProfilerWindow");
var profilerWindowsField = profilerWindowType.GetField("m_ProfilerWindows", BindingFlags.NonPublic | BindingFlags.Static);
var firstProfilerWindow = ((System.Collections.IList)profilerWindowsField.GetValue(null))[0];
var getFrameMethod = profilerWindowType.GetMethod("GetActiveVisibleFrameIndex");
return (int)getFrameMethod.Invoke(firstProfilerWindow, null);
}
}
12 changes: 12 additions & 0 deletions Assets/Editor/ProfilerUtil.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 15 additions & 6 deletions Assets/Scripts/Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,25 @@ protected virtual void Awake()
mr = GetComponent<MeshRenderer>();
}

protected virtual VTileChunk GetChunk()
protected VTileChunk cachedVChunk;

protected VTileChunk GetChunk()
{
return tile.GetTile().GetChunk(layerIndex, animationIndex, frameIndex);
return cachedVChunk;
}

public int GetIndex(int x, int y, int z)
{
return GetChunk().GetPaletteIndexAt(x, y, z);
return cachedVChunk.GetPaletteIndexAt(x, y, z);
}

int colorIndexTemp;

public VColor GetColor(int x, int y, int z)
{
int index = GetIndex(x, y, z);
if (index >= tile.GetTile().GetPalette().GetCount()) return new VColor(255, 0, 255, 255, 0, 0, 255, 0);
return tile.GetTile().GetPalette().GetColor(GetIndex(x, y, z));
colorIndexTemp = cachedVChunk.GetPaletteIndexAt(x, y, z);
if (colorIndexTemp >= tile.GetTile().GetPalette().GetCount()) return new VColor(255, 0, 255, 255, 0, 0, 255, 0);
else return tile.GetTile().GetPalette().GetColor(colorIndexTemp);
}

void LateUpdate()
Expand All @@ -59,6 +63,8 @@ void LateUpdate()

bool active = layerIndex == t.GetLayerIndex() && animationIndex == t.GetAnimationIndex() && frameIndex == t.GetFrameIndex();

cachedVChunk = t.GetChunk(layerIndex, animationIndex, frameIndex);

if (GetChunk().IsDirty() || t.GetPalette().IsDirty() || l.IsDirty() || a.IsDirty()) Refresh();
bool visible = l.GetVisible() && animationIndex == t.GetAnimationIndex() && frameIndex == t.GetFrameIndex();
gameObject.layer = (visible && (active || (!l.GetOutline() && !l.GetTransparent()))) ? 10 : 0;
Expand All @@ -68,6 +74,9 @@ void LateUpdate()

public void Refresh()
{
// The preview chunk uses -1 for all indices, so don't try to grab an actual chunk
if (layerIndex != -1) cachedVChunk = tile.GetTile().GetChunk(layerIndex, animationIndex, frameIndex);

bool layerTrans = (layerIndex >= 0) ? tile.GetTile().GetLayer(layerIndex).GetTransparent() : false;
bool layerLine = (layerIndex >= 0) ? tile.GetTile().GetLayer(layerIndex).GetOutline() : false;

Expand Down
10 changes: 4 additions & 6 deletions Assets/Scripts/Edit.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@ public class Edit : MonoBehaviour
public Binding bindToolPlace;
public Binding bindToolPaint;
public Binding bindToolFill;
public Binding bindToolMove;
public Binding bindToolBox;
public Binding bindToolWand;
public Binding bindToolPicker;

public Binding bindUseTool;
public Binding bindUseToolAlt;
Expand All @@ -58,8 +57,7 @@ public enum Tool
Paint,
Fill,
Box,
Move,
Wand
Picker
}

public enum Brush
Expand All @@ -83,14 +81,14 @@ void Awake()
void Update()
{
tile.SetDirty(false);
PreviewChunk.use.chunk.SetDirty(false);
if (bindUndo.IsPressed() && undos.Count > 0) Do(new UndoAct());
if (bindRedo.IsPressed() && redos.Count > 0) Do(new RedoAct());
if (bindToolPlace.IsPressed()) Do(new ChangeToolAct(Tool.Place));
if (bindToolPaint.IsPressed()) Do(new ChangeToolAct(Tool.Paint));
if (bindToolFill.IsPressed()) Do(new ChangeToolAct(Tool.Fill));
if (bindToolBox.IsPressed()) Do(new ChangeToolAct(Tool.Box));
if (bindToolMove.IsPressed()) Do(new ChangeToolAct(Tool.Move));
if (bindToolWand.IsPressed()) Do(new ChangeToolAct(Tool.Wand));
if (bindToolPicker.IsPressed()) Do(new ChangeToolAct(Tool.Picker));
if (batch.Count > 0 && Time.time > batchTime)
{
DoBatch();
Expand Down