Esempio n. 1
0
        public override TextAndEncoding TranslateTextAsset(string calculatedModificationPath, TextAsset asset,
                                                           IAssetOrResourceLoadedContext context)
        {
            if (TextAssetMessagePackHelper.CanHandleAsset(asset, context, out var handler))
            {
                //return new TextAndEncoding(asset.bytes, null);
                var defaultTranslationFile = Path.Combine(calculatedModificationPath, "translation.txt");
                var redirectedResources    = RedirectedDirectory.GetFilesInDirectory(calculatedModificationPath, ".txt");
                var streams = redirectedResources.Select(x => x.OpenStream());
                var cache   = new SimpleTextTranslationCache(
                    defaultTranslationFile,
                    streams,
                    false,
                    true);

                if (cache.IsEmpty)
                {
                    Logger.LogDebug($"{GetType()} unable to handle {calculatedModificationPath} (no cache)");
                    return(null);
                }

                var obj = handler.Load(asset);

                if (obj != null && handler.Translate(ref obj, cache, calculatedModificationPath))
                {
                    Logger.LogDebug($"{GetType()} handled {calculatedModificationPath}");
                    return(handler.Store(obj));
                }
            }

            return(null);
        }
Esempio n. 2
0
        protected override bool ShouldHandleAsset(TextAsset asset, IAssetOrResourceLoadedContext context)
        {
            var result = Enabled && TextAssetMessagePackHelper.CanHandleAsset(asset, context) &&
                         !context.HasReferenceBeenRedirectedBefore(asset);

            Logger.LogDebug($"{GetType()}.ShouldHandleAsset({asset.name}[{asset.GetType()}]) => {result}");
            return(result);
        }