-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
… in the project importer inspector was changed. This was fixed by introducing a new config file that gets generated by the project importer (.ldtkc)
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using UnityEditor; | ||
using UnityEditor.AssetImporters; | ||
|
||
namespace LDtkUnity.Editor | ||
{ | ||
[CanEditMultipleObjects] | ||
[CustomEditor(typeof(LDtkConfigImporter))] | ||
internal sealed class LDtkConfigImporterEditor : ScriptedImporterEditor | ||
{ | ||
public override void OnInspectorGUI() | ||
{ | ||
const string msg = "This file is generated by the project importer.\n" + | ||
"It contains the configuration data from the project inspector.\n" + | ||
"It is only used for telling the levels to reimport when this is changed."; | ||
EditorGUILayout.HelpBox(msg, MessageType.Info); | ||
ApplyRevertGUI(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
using UnityEngine; | ||
|
||
#if UNITY_2020_2_OR_NEWER | ||
using UnityEditor.AssetImporters; | ||
#else | ||
using UnityEditor.Experimental.AssetImporters; | ||
#endif | ||
|
||
namespace LDtkUnity.Editor | ||
{ | ||
[ScriptedImporter(LDtkImporterConsts.CONFIG_VERSION, LDtkImporterConsts.CONFIG_EXT, LDtkImporterConsts.CONFIG_ORDER)] | ||
internal sealed class LDtkConfigImporter : ScriptedImporter | ||
{ | ||
public override void OnImportAsset(AssetImportContext ctx) | ||
{ | ||
LDtkConfigData data = LDtkConfigData.ReadJson(assetPath); | ||
|
||
LDtkConfig obj = ScriptableObject.CreateInstance<LDtkConfig>(); | ||
obj._data = data; | ||
|
||
ctx.AddObjectToAsset("main", obj, LDtkIconUtility.LoadListIcon()); | ||
ctx.SetMainObject(obj); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using UnityEngine; | ||
|
||
namespace LDtkUnity.Editor | ||
{ | ||
/// <summary> | ||
/// Purely a class to hold the LDtkConfigData as an import artifact | ||
/// </summary> | ||
internal sealed class LDtkConfig : ScriptableObject | ||
{ | ||
public LDtkConfigData _data; | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using System; | ||
using System.IO; | ||
using System.Text; | ||
using UnityEngine; | ||
|
||
namespace LDtkUnity.Editor | ||
{ | ||
//todo: could be used to spawn levels in runtime potentially | ||
[Serializable] | ||
internal struct LDtkConfigData | ||
{ | ||
public int PixelsPerUnit; | ||
public GameObject CustomLevelPrefab; | ||
public bool IntGridValueColorsVisible; | ||
public bool UseCompositeCollider; | ||
public CompositeCollider2D.GeometryType GeometryType; | ||
public bool CreateBackgroundColor; | ||
public bool CreateLevelBoundsTrigger; | ||
public bool UseParallax; | ||
public LDtkAssetIntGridValue[] IntGridValues; | ||
public LDtkAssetEntity[] Entities; | ||
|
||
internal string WriteJson(string projectAssetPath) | ||
{ | ||
string writePath = GetPath(projectAssetPath); | ||
string json = JsonUtility.ToJson(this, true); | ||
byte[] byteArray = Encoding.UTF8.GetBytes(json); | ||
|
||
LDtkPathUtility.TryCreateDirectoryForFile(writePath); | ||
|
||
File.WriteAllBytes(writePath, byteArray); | ||
return writePath; | ||
} | ||
|
||
internal static LDtkConfigData ReadJson(string assetPath) | ||
{ | ||
if (!File.Exists(assetPath)) | ||
{ | ||
return new LDtkConfigData(); | ||
} | ||
|
||
byte[] bytes = File.ReadAllBytes(assetPath); | ||
string json = Encoding.UTF8.GetString(bytes); | ||
return JsonUtility.FromJson<LDtkConfigData>(json); | ||
} | ||
|
||
internal static string GetPath(string projectAssetPath) | ||
{ | ||
string dir = Path.GetDirectoryName(projectAssetPath); | ||
string importerAssetName = Path.GetFileNameWithoutExtension(projectAssetPath); | ||
return Path.Combine(dir, importerAssetName, $"{importerAssetName}_Config.{LDtkImporterConsts.CONFIG_EXT}"); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"PixelsPerUnit": 16, | ||
"CustomLevelPrefab": { | ||
"instanceID": 0 | ||
}, | ||
"IntGridValueColorsVisible": true, | ||
"UseCompositeCollider": true, | ||
"GeometryType": 0, | ||
"CreateBackgroundColor": true, | ||
"CreateLevelBoundsTrigger": false, | ||
"UseParallax": true, | ||
"IntGridValues": [ | ||
{ | ||
"_key": "IntGrid_1", | ||
"_asset": { | ||
"instanceID": 22226 | ||
} | ||
} | ||
], | ||
"Entities": [] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"PixelsPerUnit": 16, | ||
"CustomLevelPrefab": { | ||
"instanceID": 0 | ||
}, | ||
"IntGridValueColorsVisible": true, | ||
"UseCompositeCollider": true, | ||
"GeometryType": 0, | ||
"CreateBackgroundColor": true, | ||
"CreateLevelBoundsTrigger": false, | ||
"UseParallax": true, | ||
"IntGridValues": [ | ||
{ | ||
"_key": "IntGrid_1", | ||
"_asset": { | ||
"instanceID": 29410 | ||
} | ||
}, | ||
{ | ||
"_key": "IntGrid_2", | ||
"_asset": { | ||
"instanceID": 28118 | ||
} | ||
}, | ||
{ | ||
"_key": "IntGrid_3", | ||
"_asset": { | ||
"instanceID": 24110 | ||
} | ||
} | ||
], | ||
"Entities": [] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.