Skip to content

Commit

Permalink
Add logic connecting AssetEditors to ExportSettings
Browse files Browse the repository at this point in the history
Also refactor BaseAssetEditor.GetAssetPaths usage to be more generic
  • Loading branch information
burnedram committed May 21, 2019
1 parent c86ceb8 commit 2005ea4
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 49 deletions.
1 change: 1 addition & 0 deletions Disunity/Disunity.Editor/Disunity.Editor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<Compile Include="Editors\BaseSelectionEditor.cs" />
<Compile Include="AsyncEditorTask.cs" />
<Compile Include="Editors\BaseAssetEditor.cs" />
<Compile Include="Editors\BaseSettingsAssetEditor.cs" />
<Compile Include="Fields\BasePickerField.cs" />
<Compile Include="Fields\ClassPickerField.cs" />
<Compile Include="Pickers\BasePicker.cs" />
Expand Down
15 changes: 11 additions & 4 deletions Disunity/Disunity.Editor/Editors/ArtifactEditor.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
using UnityEditor;

using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace Disunity.Editor.Editors {

internal class ArtifactEditor : BaseAssetEditor {
internal class ArtifactEditor : BaseSettingsAssetEditor<Object> {

protected override IEnumerable<Object> Setting {
get => _settings.Artifacts;
set => _settings.Artifacts = value.ToArray();
}

public ArtifactEditor(EditorWindow window, ExportSettings settings) : base(window) { }
public ArtifactEditor(EditorWindow window, ExportSettings settings) : base(window, settings) { }

public override string Label() {
return "Artifacts";
Expand Down
42 changes: 42 additions & 0 deletions Disunity/Disunity.Editor/Editors/BaseSettingsAssetEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Disunity.Editor.Pickers;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine;

namespace Disunity.Editor.Editors {
internal abstract class BaseSettingsAssetEditor<T> : BaseAssetEditor where T : Object {

protected readonly ExportSettings _settings;

protected abstract IEnumerable<T> Setting { get; set; }

public BaseSettingsAssetEditor(EditorWindow window, ExportSettings settings) : base(window) {
_settings = settings;
}

protected override void HandleAddition(AssetEntry addition) {
base.HandleAddition(addition);
if (Setting.All(asmDef => AssetDatabase.GetAssetPath(asmDef) != addition.Value)) {
Setting =
Enumerable.Concat(
Setting,
Enumerable.Repeat(AssetDatabase.LoadAssetAtPath<T>(addition.Value), 1))
.ToArray();
}
}

protected override void HandleSubtraction(AssetEntry subtraction) {
base.HandleSubtraction(subtraction);
Setting = Setting
.Where(asmDef => AssetDatabase.GetAssetPath(asmDef) != subtraction.Value)
.ToArray();
}
public override string[] GetAssetPaths() {
return AssetDatabase
.FindAssets($"t:{typeof(T).Name}")
.Select(AssetDatabase.GUIDToAssetPath)
.ToArray();
}
}
}
21 changes: 10 additions & 11 deletions Disunity/Disunity.Editor/Editors/PrefabEditor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;

using UnityEngine;

namespace Disunity.Editor.Editors {

internal class PrefabEditor : BaseAssetEditor {
internal class PrefabEditor : BaseSettingsAssetEditor<GameObject> {

protected override IEnumerable<GameObject> Setting {
get => _settings.Prefabs;
set => _settings.Prefabs = value.ToArray();
}

public PrefabEditor(EditorWindow window) : base(window) { }
public PrefabEditor(EditorWindow window, ExportSettings settings) : base(window, settings) { }

public override string Label() {
return "Prefabs";
Expand All @@ -31,12 +37,5 @@ ScriptableObjects are non-Scene-objects which can contain data. This is useful
but due to a limitation in how Unity serializes information, only basic types
like strings, ints, floats, and basic arrays will work.";
}

public override string[] GetAssetPaths() {
return AssetDatabase
.FindAssets("t:GameObject t:ScriptableObject")
.Select(AssetDatabase.GUIDToAssetPath)
.ToArray();
}
}
}
22 changes: 11 additions & 11 deletions Disunity/Disunity.Editor/Editors/PreloadAssemblyEditor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;

using UnityEditorInternal;
using UnityEngine;

namespace Disunity.Editor.Editors {

internal class PreloadAssemblyEditor : BaseAssetEditor {
internal class PreloadAssemblyEditor : BaseSettingsAssetEditor<AssemblyDefinitionAsset> {

protected override IEnumerable<AssemblyDefinitionAsset> Setting {
get => _settings.PreloadAssemblies;
set => _settings.PreloadAssemblies = value.ToArray();
}

public PreloadAssemblyEditor(EditorWindow window, ExportSettings settings) : base(window) { }
public PreloadAssemblyEditor(EditorWindow window, ExportSettings settings) : base(window, settings) { }

public override string Label() {
return "Preload";
Expand All @@ -32,12 +39,5 @@ Preload assemblies are defined by a Unity Assembly Definition
<b>Assets -> Create -> Assembly Definition</b> menu.
";
}

public override string[] GetAssetPaths() {
return AssetDatabase
.FindAssets("t:AssemblyDefinitionAsset")
.Select(AssetDatabase.GUIDToAssetPath)
.ToArray();
}
}
}
23 changes: 11 additions & 12 deletions Disunity/Disunity.Editor/Editors/RuntimeAssemblyEditor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;

using UnityEditorInternal;
using UnityEngine;

namespace Disunity.Editor.Editors {

internal class RuntimeAssemblyEditor : BaseAssetEditor {
internal class RuntimeAssemblyEditor : BaseSettingsAssetEditor<AssemblyDefinitionAsset> {

protected override IEnumerable<AssemblyDefinitionAsset> Setting {
get => _settings.RuntimeAssemblies;
set => _settings.RuntimeAssemblies = value.ToArray();
}

public RuntimeAssemblyEditor(EditorWindow window, ExportSettings settings) : base(window) { }
public RuntimeAssemblyEditor(EditorWindow window, ExportSettings settings) : base(window, settings) { }

public override string Label() {
return "Scripts";
Expand All @@ -32,13 +39,5 @@ Runtime assemblies are defined by a Unity Assembly Definition
Asset. These can be created using the
<b>Assets -> Create -> Assembly Definition</b> menu.";
}

public override string[] GetAssetPaths() {
return AssetDatabase
.FindAssets("t:AssemblyDefinitionAsset")
.Select(AssetDatabase.GUIDToAssetPath)
.ToArray();
}

}
}
19 changes: 9 additions & 10 deletions Disunity/Disunity.Editor/Editors/SceneEditor.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
using System.Linq;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;


namespace Disunity.Editor.Editors {

internal class SceneEditor : BaseAssetEditor {
internal class SceneEditor : BaseSettingsAssetEditor<SceneAsset> {

protected override IEnumerable<SceneAsset> Setting {
get => _settings.Scenes;
set => _settings.Scenes = value.ToArray();
}

public SceneEditor(EditorWindow window, ExportSettings settings) : base(window) { }
public SceneEditor(EditorWindow window, ExportSettings settings) : base(window, settings) { }

public override string Label() {
return "Scenes";
Expand All @@ -19,11 +24,5 @@ public override string Title() {
public override string Help() {
return "Scenes can be exported to your mod here.";
}
public override string[] GetAssetPaths() {
return AssetDatabase
.FindAssets("t:Scene")
.Select(AssetDatabase.GUIDToAssetPath)
.ToArray();
}
}
}
2 changes: 1 addition & 1 deletion Disunity/Disunity.Editor/ExporterEditorWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private void OnEnable() {
_runtimeAssemblyEditor = new RuntimeAssemblyEditor(this, _exportSettings.Instance);
_preloadAssemblyEditor = new PreloadAssemblyEditor(this, _exportSettings.Instance);
_artifactEditor = new ArtifactEditor(this, _exportSettings.Instance);
_prefabEditor = new PrefabEditor(this);
_prefabEditor = new PrefabEditor(this, _exportSettings.Instance);
_sceneEditor = new SceneEditor(this, _exportSettings.Instance);
_exportEditor = new ExportEditor(this, _exportSettings.Instance);
_dependencyEditor = new DependencyEditor(this);
Expand Down

0 comments on commit 2005ea4

Please sign in to comment.