|
| 1 | +# Localization-Asset文件扩展 以Texture举例 |
| 2 | +``` csharp |
| 3 | +using UnityEngine; |
| 4 | +namespace WooLocalization |
| 5 | +{ |
| 6 | + [CreateAssetMenu(menuName = "WooLocalization/TextureActorAsset")] |
| 7 | + public class TextureActorAsset : ActorAsset<Texture> |
| 8 | + { |
| 9 | + } |
| 10 | +} |
| 11 | + |
| 12 | +using UnityEditor; |
| 13 | +using UnityEngine; |
| 14 | +namespace WooLocalization |
| 15 | +{ |
| 16 | + [CustomEditor(typeof(TextureActorAsset))] |
| 17 | + class TextureActorAssetEditor : ActorAssetEditor<Texture, TextureActorAsset> |
| 18 | + { |
| 19 | + protected override float GetRowHeight() |
| 20 | + { |
| 21 | + return 60; |
| 22 | + } |
| 23 | + |
| 24 | + protected override Texture DrawField(Rect pos, Texture src) |
| 25 | + { |
| 26 | + float min = Mathf.Min(pos.width, pos.height); |
| 27 | + pos.size = Vector2.one * min; |
| 28 | + return EditorGUI.ObjectField(pos, src, typeof(Texture), false) as Texture; |
| 29 | + } |
| 30 | + |
| 31 | + } |
| 32 | +} |
| 33 | +``` |
| 34 | +# 组件扩展 以Texture举例 |
| 35 | +```csharp |
| 36 | +using System.Collections.Generic; |
| 37 | +using UnityEngine; |
| 38 | + |
| 39 | +namespace WooLocalization |
| 40 | +{ |
| 41 | + [DisallowMultipleComponent] |
| 42 | + public class LocalizationTexture : LocalizationBehavior |
| 43 | + { |
| 44 | + public class TextureActor : LocalizationMapActor<LocalizationBehavior, Texture> |
| 45 | + { |
| 46 | + private Texture ins; |
| 47 | + public TextureActor(bool enable) : base(enable) |
| 48 | + { |
| 49 | + } |
| 50 | + public override Texture GetDefault() => default; |
| 51 | + protected override void Execute(string language, LocalizationBehavior component) |
| 52 | + { |
| 53 | +#if UNITY_EDITOR |
| 54 | + if (!Application.isPlaying) return; |
| 55 | + |
| 56 | + if (UnityEditor.SceneManagement.EditorSceneManager.IsPreviewSceneObject(component)) return; |
| 57 | +#endif |
| 58 | + var texture = GetValue(language); |
| 59 | + if (texture != null) |
| 60 | + { |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | + public TextureActor Texture = new TextureActor(true); |
| 65 | + protected override List<ILocalizationActor> GetActors() |
| 66 | + { |
| 67 | + return new List<ILocalizationActor>() { |
| 68 | + Texture |
| 69 | + }; |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | + |
| 75 | +using System; |
| 76 | +using UnityEditor; |
| 77 | +using UnityEngine; |
| 78 | +using static WooLocalization.LocalizationTexture; |
| 79 | + |
| 80 | +namespace WooLocalization |
| 81 | +{ |
| 82 | + |
| 83 | + [CustomEditor(typeof(LocalizationTexture))] |
| 84 | + class LocalizationTextureEditor : LocalizationBehaviorEditor<LocalizationTexture> |
| 85 | + { |
| 86 | + [LocalizationActorEditorAttribute] |
| 87 | + |
| 88 | + class TextureActorEditor : LocalizationMapActorEditor<LocalizationTexture.TextureActor, Texture, LocalizationBehavior> |
| 89 | + { |
| 90 | + protected override Type GetAssetType() => typeof(TextureActorAsset); |
| 91 | + |
| 92 | + protected override bool NeedExecute() => false; |
| 93 | + |
| 94 | + } |
| 95 | + } |
| 96 | +} |
| 97 | +``` |
| 98 | + |
| 99 | +# ActorTest扩展 以Texture举例 |
| 100 | +```csharp |
| 101 | +public class ActorTest : WooLocalization.LocalizationBehavior |
| 102 | +{ |
| 103 | + protected override List<ILocalizationActor> GetActors() |
| 104 | + { |
| 105 | + return new List<ILocalizationActor>() {_texture }; |
| 106 | + } |
| 107 | + public ObjectActor<Texture> _texture = new ObjectActor<Texture>(true); |
| 108 | +} |
| 109 | +``` |
0 commit comments