Skip to content

Commit 80bb153

Browse files
author
Brian MacIntosh
committed
parse errors in Unity objects are caught and displayed on the object
1 parent ccb8642 commit 80bb153

12 files changed

+154
-52
lines changed
Loading

UnityProjectBrowser/MainForm.Designer.cs

+36-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityProjectBrowser/MainForm.cs

+36-2
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,15 @@ private void OnAllObjectsTreeViewSelectionChanged(object sender, TreeViewEventAr
378378
selectedObjectFileIdTextBox.Text = unityObjectKey.FileId.ToString();
379379
selectedObjectFilePathTextBox.Text = selectedObject.GetFilePath();
380380
projectObjectTypeTextBox.Text = selectedObject.GetType().Name;
381+
if (selectedObject.ParseError != null)
382+
{
383+
viewErrorButton.Visible = true;
384+
toolTip.SetToolTip(viewErrorButton, selectedObject.ParseError.ToString());
385+
}
386+
else
387+
{
388+
viewErrorButton.Visible = false;
389+
}
381390
}
382391
else
383392
{
@@ -564,7 +573,7 @@ private void openInExplorerToolStripMenuItem_Click(object sender, EventArgs e)
564573
}
565574

566575
/// <summary>
567-
/// Opens the selected ojbect in the allObjects view in the default editor.
576+
/// Opens the selected object in the allObjects view in the default editor.
568577
/// </summary>
569578
private void editToolStripMenuItem_Click(object sender, EventArgs e)
570579
{
@@ -575,11 +584,36 @@ private void editToolStripMenuItem_Click(object sender, EventArgs e)
575584
string objectPath = projectObject.GetFilePath();
576585
if (!string.IsNullOrEmpty(objectPath))
577586
{
578-
Process.Start(objectPath);
587+
try
588+
{
589+
Process.Start(objectPath);
590+
}
591+
catch (System.ComponentModel.Win32Exception except)
592+
{
593+
MessageBox.Show(except.Message, "Error", MessageBoxButtons.OK);
594+
}
579595
}
580596
}
581597
}
582598

599+
/// <summary>
600+
/// Copies the full path of the selected object in the allObjects view to the clipboard.
601+
/// </summary>
602+
private void copyPathToolStripMenuItem_Click(object sender, EventArgs e)
603+
{
604+
ProjectObject projectObject;
605+
if (allObjectsTreeView.SelectedNode != null
606+
&& ObjectDatabase.TryGetObject(allObjectsTreeView.SelectedNode.Name, out projectObject))
607+
{
608+
string objectPath = projectObject.GetFilePath();
609+
Clipboard.SetText(objectPath);
610+
}
611+
else
612+
{
613+
Clipboard.SetText(allObjectsTreeView.SelectedNode.Name);
614+
}
615+
}
616+
583617
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
584618
{
585619
Close();

UnityProjectBrowser/Properties/Resources.Designer.cs

+14-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

UnityProjectBrowser/Properties/Resources.resx

+9-6
Original file line numberDiff line numberDiff line change
@@ -388,22 +388,25 @@
388388
<data name="Close_16xLG" type="System.Resources.ResXFileRef, System.Windows.Forms">
389389
<value>..\assets\uiicons\close_16xlg.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
390390
</data>
391-
<data name="FlatView" type="System.Resources.ResXFileRef, System.Windows.Forms">
392-
<value>..\assets\appicons\flatview.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
393-
</data>
394391
<data name="FolderOpen_16x16_72" type="System.Resources.ResXFileRef, System.Windows.Forms">
395392
<value>..\assets\uiicons\folderopen_16x16_72.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
396393
</data>
397394
<data name="Open_6529" type="System.Resources.ResXFileRef, System.Windows.Forms">
398395
<value>..\assets\uiicons\open_6529.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
399396
</data>
400-
<data name="TreeView_713" type="System.Resources.ResXFileRef, System.Windows.Forms">
401-
<value>..\assets\appicons\treeview_713.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
402-
</data>
403397
<data name="DialogGroup_5846_16x" type="System.Resources.ResXFileRef, System.Windows.Forms">
404398
<value>..\assets\uiicons\dialoggroup_5846_16x.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
405399
</data>
406400
<data name="Find_VS" type="System.Resources.ResXFileRef, System.Windows.Forms">
407401
<value>..\assets\uiicons\find_vs.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
408402
</data>
403+
<data name="Error_red_16x16" type="System.Resources.ResXFileRef, System.Windows.Forms">
404+
<value>..\assets\uiicons\error_red_16x16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
405+
</data>
406+
<data name="FlatView1" type="System.Resources.ResXFileRef, System.Windows.Forms">
407+
<value>..\assets\uiicons\flatview.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
408+
</data>
409+
<data name="TreeView_7131" type="System.Resources.ResXFileRef, System.Windows.Forms">
410+
<value>..\assets\uiicons\treeview_713.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
411+
</data>
409412
</root>

UnityProjectBrowser/Structure/ProjectObject.cs

+6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright(c) 2018 Brian MacIntosh
22
// MIT License
33

4+
using System;
45
using System.Collections.Generic;
56
using System.Collections.ObjectModel;
67

@@ -23,6 +24,11 @@ public virtual bool HideFromHierarchy
2324
{
2425
get { return false; }
2526
}
27+
28+
/// <summary>
29+
/// If there was an error while parsing the object, the error.
30+
/// </summary>
31+
public Exception ParseError;
2632

2733
public ProjectObject(string uniqueId)
2834
{

UnityProjectBrowser/Structure/Unity/UnityComponent.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,28 @@ public class UnityComponent : UnityObject
1313
/// <summary>
1414
/// The type name of this object.
1515
/// </summary>
16-
public readonly string TypeName;
16+
public string TypeName
17+
{
18+
get; private set;
19+
}
1720

18-
private readonly UnityObjectKey m_scriptKey;
21+
private UnityObjectKey m_scriptKey;
1922

20-
private readonly UnityObjectKey m_gameObjectKey;
23+
private UnityObjectKey m_gameObjectKey;
2124

2225
/// <summary>
2326
/// Reads a <see cref="UnityComponent"/> from the specified Yaml node.
2427
/// </summary>
2528
public UnityComponent(string documentId, YamlDocument yaml, UnityObjectKey key)
2629
: base(documentId, yaml, key)
2730
{
31+
32+
}
33+
34+
protected override void Parse(YamlDocument yaml, UnityObjectKey key)
35+
{
36+
base.Parse(yaml, key);
37+
2838
YamlMappingNode rootNode = (YamlMappingNode)yaml.RootNode;
2939
KeyValuePair<YamlNode, YamlNode> firstNode = rootNode.Children.First();
3040
YamlMappingNode objectNode = (YamlMappingNode)firstNode.Value;

0 commit comments

Comments
 (0)