Skip to content

Commit

Permalink
1.3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
V0odo0 committed Oct 24, 2024
1 parent 866b0a6 commit fe91ae5
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 64 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.3.2 (2024-10-25)

* KnotTextKeyReference & KnotAssetReference ToString impl

## 1.3.0 (2024-09-27)

* [breaking change] Asset Store - Moving common parts of code to Knot.Core assembly. Please, delete asset folder before updating
Expand Down
9 changes: 1 addition & 8 deletions Editor/Scripts/Core/EditorUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,7 @@ internal static class EditorUtils
public const string ToolsRootPath = "Tools/" + KnotLocalization.CoreName + "/";

const string EditorStylesResourcesPath = "UI/KnotEditorStyles";


public static bool IsUpmPackage => UpmPackageInfo != null;

public static PackageInfo UpmPackageInfo =>
_upmPackageInfo ?? (_upmPackageInfo = PackageInfo.FindForAssembly(Assembly.GetAssembly(typeof(KnotLocalization))));
private static PackageInfo _upmPackageInfo;


public static IReadOnlyDictionary<KnotMetadataInfoAttribute.MetadataScope, EditorExtensions.TypeInfo[]> MetadataTypes
{
get
Expand Down
3 changes: 3 additions & 0 deletions Runtime/Scripts/Key References/KnotAssetKeyReference.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using Knot.Localization.Data;
using UnityEngine;
using Object = UnityEngine.Object;

namespace Knot.Localization
Expand All @@ -26,5 +27,7 @@ protected override void UnRegisterValueUpdatedCallback(string key, Action<Object
{
KnotLocalization.UnRegisterAssetUpdatedCallback(Key, valueUpdated);
}

public override string ToString() => Application.isPlaying && Value != null ? Value.ToString() : Key;
}
}
2 changes: 2 additions & 0 deletions Runtime/Scripts/Key References/KnotTextKeyReference.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ protected override void UnRegisterValueUpdatedCallback(string key, Action<string
{
KnotLocalization.UnRegisterTextUpdatedCallback(key, valueUpdated);
}

public override string ToString() => Application.isPlaying? Value : Key;
}
}
54 changes: 3 additions & 51 deletions Runtime/Scripts/KnotLocalization.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
using System;
using System.Linq;
using Knot.Core;
using Knot.Localization.Data;
using UnityEngine;
using Object = UnityEngine.Object;

#if UNITY_EDITOR
using UnityEditor;
#endif

namespace Knot.Localization
{
/// <summary>
Expand All @@ -18,9 +13,9 @@ public static class KnotLocalization
{
internal const string CoreName = "KNOT Localization";
internal const string CorePath = Utils.EditorRootPath + "Localization/";
public static KnotProjectSettings ProjectSettings =>
_projectSettings ?? (_projectSettings = LoadProjectSettings());

internal static KnotProjectSettings ProjectSettings =>
_projectSettings == null ? _projectSettings = Utils.GetProjectSettings<KnotProjectSettings>() : _projectSettings;
private static KnotProjectSettings _projectSettings;

public static IKnotManager Manager => _manager ?? (_manager = ProjectSettings.Manager ?? new KnotManager());
Expand All @@ -34,49 +29,6 @@ static void Init()
Manager.SetDatabase(ProjectSettings.DefaultDatabase, true);
}


static KnotProjectSettings LoadProjectSettings()
{
KnotProjectSettings settings;

#if UNITY_EDITOR
var allSettings =
AssetDatabase.FindAssets($"t:{nameof(KnotProjectSettings)}").
Select(AssetDatabase.GUIDToAssetPath).
Select(AssetDatabase.LoadAssetAtPath<KnotProjectSettings>).ToArray();

if (allSettings.Length == 0)
{
string path = $"Assets/{nameof(KnotProjectSettings)}.asset";
settings = AssetDatabase.LoadAssetAtPath<KnotProjectSettings>(path);

if (settings == null)
settings = PlayerSettings.GetPreloadedAssets().OfType<KnotProjectSettings>().FirstOrDefault();

if (settings == null)
{
var instance = ScriptableObject.CreateInstance<KnotProjectSettings>();
AssetDatabase.CreateAsset(instance, path);
AssetDatabase.SaveAssets();
settings = instance;

var preloadedAssets = PlayerSettings.GetPreloadedAssets();
PlayerSettings.SetPreloadedAssets(preloadedAssets.Append(settings).ToArray());
}
}
else settings = allSettings.First();
#else
settings = Resources.FindObjectsOfTypeAll<KnotProjectSettings>().FirstOrDefault();
#endif

if (settings == null)
{
settings = KnotProjectSettings.Empty;
Log("Unable to load or create Project Settings. Empty Project Settings will be assigned.", LogType.Warning);
}
return settings;
}


internal static void Log(object message, LogType type, Object context = null)
{
Expand Down
21 changes: 19 additions & 2 deletions Samples~/Demo/Localization Assets/KnotTextKeyCollection_demo.asset
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ MonoBehaviour:
_editor: []
- _key: Pages.1.0
_metadata:
_runtime: []
_runtime:
- rid: 7349065975784275987
- rid: 7349065975784275988
- rid: 7349065975784275989
_editor: []
- _key: Pages.1.title
_metadata:
Expand Down Expand Up @@ -102,4 +105,18 @@ MonoBehaviour:
_runtime: []
_editor: []
references:
version: 1
version: 2
RefIds:
- rid: 7349065975784275987
type: {class: KnotCultureSpecificDayPostfixMetadata, ns: Knot.Localization.Demo,
asm: Knot.Localization}
data:
_serializationPlaceholder: 0
- rid: 7349065975784275988
type: {class: KnotCustomFontMetadata, ns: Knot.Localization.Data, asm: Knot.Localization}
data:
_font: {fileID: 0}
- rid: 7349065975784275989
type: {class: KnotPrefixMetadata, ns: Knot.Localization.Data, asm: Knot.Localization}
data:
_prefix: 123
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "com.knot.localization",
"version": "1.3.1",
"version": "1.3.2",
"author": "V0odo0",
"displayName": "KNOT Localization",
"unity": "2021.3",
"description": "Lightweight, scalable and extensible texts & assets localization system for Unity. \n\nWiki: https://github.com/V0odo0/KNOT-Localization/wiki \n\nGitHub: https://github.com/V0odo0/KNOT-Localization \n\nAsset Store: https://assetstore.unity.com/packages/tools/localization/knot-localization-187603 \n\nUnity Forum Thread: https://forum.unity.com/threads/knot-localization.1042891/",
"description": "Lightweight, scalable and extensible texts & assets localization system for Unity. \n\nWiki: https://github.com/V0odo0/KNOT-Localization/wiki \nGitHub: https://github.com/V0odo0/KNOT-Localization \nAsset Store: https://assetstore.unity.com/packages/tools/localization/knot-localization-187603 \nUnity Forum Thread: https://forum.unity.com/threads/knot-localization.1042891/",
"dependencies": {
"com.knot.core": "1.0.1"
"com.knot.core": "1.0.4"
},
"keywords": [
"localization",
Expand Down

0 comments on commit fe91ae5

Please sign in to comment.