LocalizedAsset<> property inspector rendering and serialization fails.

Issue #895 new
Jorrit de Vries created an issue
  1. The property drawer for LocalizedAsset<> is not working correctly, and this seems related to the fixed https://bitbucket.org/sirenix/odin-inspector/issues/806/serialized-localizedstring-type
  2. Create empty project

  3. Before Odin import

After Odin import

4. Odin Inspector & Serializer, 3.1.8.0 from Asset Store
5. Unity 2020.3.42f1, 2021.3.14f1
6. Editor Mode enabled
7. Windows 10 Pro 64

Comments (2)

  1. Jorrit de Vries reporter

    In the mean time I created a fix, at least for assets. I’m using com.unity.localization 1.3.2, I believe in 1.4.2 there is the LocalizedMesh asset.

    Runtime:

    using Sirenix.Serialization;
    using UnityEngine.Localization;
    
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedAudioClipFormatter))]
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedFontFormatter))]
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedGameObjectFormatter))]
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedMaterialFormatter))]
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedObjectFormatter))]
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedSpriteFormatter))]
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedTextureFormatter))]
    [assembly: RegisterFormatter(typeof(Sirenix.OdinInspector.Modules.Localization.LocalizedTmpFontFormatter))]
    
    namespace Sirenix.OdinInspector.Modules.Localization
    {
        public class LocalizedAudioClipFormatter : LocalizedAssetFormatter<LocalizedAudioClip> { }
        public class LocalizedFontFormatter : LocalizedAssetFormatter<LocalizedFont> { }
        public class LocalizedGameObjectFormatter : LocalizedAssetFormatter<LocalizedGameObject> { }
        public class LocalizedMaterialFormatter : LocalizedAssetFormatter<LocalizedMaterial> { }
        public class LocalizedObjectFormatter : LocalizedAssetFormatter<LocalizedObject> { }
        public class LocalizedSpriteFormatter : LocalizedAssetFormatter<LocalizedSprite> { }
        public class LocalizedTextureFormatter : LocalizedAssetFormatter<LocalizedTexture> { }
        public class LocalizedTmpFontFormatter : LocalizedAssetFormatter<LocalizedTmpFont> { }
    
        public abstract class LocalizedAssetFormatter<T> : ReflectionOrEmittedBaseFormatter<T> where T : LocalizedReference, new()
        {
            protected override T GetUninitializedObject()
            {
                return new T();
            }
        }
    }
    

    Editor:

    namespace Sirenix.OdinInspector.Modules.Localization.Editor
    {
        using System;
        using System.Collections.Generic;
        using System.Reflection;
        using Sirenix.OdinInspector;
        using Sirenix.OdinInspector.Editor;
        using Sirenix.Utilities.Editor;
        using UnityEngine.Localization;
    
        public class LocalizedReferenceProcessor : OdinAttributeProcessor<LocalizedReference>
        {
            public override bool CanProcessChildMemberAttributes(InspectorProperty parentProperty, MemberInfo member)
            {
                return false;
            }
    
            public override void ProcessSelfAttributes(InspectorProperty property, List<Attribute> attributes)
            {
                attributes.Add(new DrawWithUnityAttribute());
            }
        }
    
        public class LocalizedReferenceResolver : OdinPropertyResolver<LocalizedReference>
        {
            public override int ChildNameToIndex(string name)
            {
                throw new NotSupportedException();
            }
    
            public override int ChildNameToIndex(ref StringSlice name)
            {
                throw new NotSupportedException();
            }
    
            public override InspectorPropertyInfo GetChildInfo(int childIndex)
            {
                throw new NotSupportedException();
            }
    
            protected override int GetChildCount(LocalizedReference value)
            {
                return 0;
            }
        }
    }
    

    I’m not very well familair with Odin’s internals, so not sure this is the best implementation, but it seems to do the trick. It is similar to what’s present in the localization module. It looks like LocalizedStringProcessor can be replaced with LocalizedReferenceProcessor, and the same yields for the resolver.

  2. Log in to comment