Exemplo n.º 1
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            var font   = (AlbionSprite) new FixedSizeSpriteLoader().Load(br, streamLength, key, config);
            var frames = new List <AlbionSprite.Frame>();

            // Fix up sub-images for variable size
            foreach (var oldFrame in font.Frames)
            {
                int width = 0;
                for (int j = oldFrame.Y; j < oldFrame.Y + oldFrame.Height; j++)
                {
                    for (int i = oldFrame.X; i < oldFrame.X + oldFrame.Width; i++)
                    {
                        if (i - oldFrame.X > width && font.PixelData[j * font.Width + i] != 0)
                        {
                            width = i - oldFrame.X;
                        }
                    }
                }

                frames.Add(new AlbionSprite.Frame(oldFrame.X, oldFrame.Y, width + 2, oldFrame.Height));
            }

            font.UniformFrames = false;
            font.Frames        = frames;
            return(font);
        }
        /// <summary>
        /// Clear loaded asset.
        /// </summary>
        /// <param name="bundleName">Bundle name without extension.</param>
        /// <param name="assetName">Asset name.</param>
        /// <typeparam name="T">Asset type.</typeparam>
        public static void ClearLoadedAsset <T>(string bundleName, string assetName) where T : Object
        {
            var assetKey = new AssetKey(typeof(T), assetName);

            //Loading
            if (mLoadingAssetDicts.TryGetValue(bundleName, out var loadingAssetDict))
            {
                if (loadingAssetDict.TryGetValue(assetKey, out var loadingAsset))
                {
                    loadingAsset.GetAsset(); //Force sync
                }
            }
            if (!mAssetDicts.TryGetValue(bundleName, out var assetDict))
            {
                return;
            }
            if (!assetDict.TryGetValue(assetKey, out var asset))
            {
                return;
            }
            assetDict.Remove(assetKey);
            if (assetDict.Count == 0)
            {
                mAssetDicts.Remove(bundleName);
            }
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public object Load(Type assetType, string assetName, bool fromEmbeddedResource = false)
        {
            if (assetName == null)
            {
                throw new ArgumentNullException(nameof(assetName));
            }

            if (assetType == null)
            {
                throw new ArgumentNullException(nameof(assetType));
            }

            AssetKey assetKey = new AssetKey(assetType, assetName);

            lock (GetAssetLocker(assetKey, true) !)
            {
                if (_loadedAssets.TryGetValue(assetKey, out object result))
                {
                    return(result);
                }
                result = LoadAssetWithDynamicContentReader(
                    assetType,
                    assetName,
                    fromEmbeddedResource
                        ? ResolveEmbeddedResourceStream(assetType, assetName)
                        : ResolveStream(Path.Combine(_rootDirectory, assetName)));

                lock (_loadedAssets)
                {
                    _loadedAssets.Add(assetKey, result);
                }

                return(result);
            }
        }
Exemplo n.º 4
0
        public IList <ItemData> Serdes(IList <ItemData> items, ISerializer s, AssetKey key, AssetInfo config)
        {
            items ??= new List <ItemData>();
            s.Begin();
            if (s.Mode == SerializerMode.Reading)
            {
                int i = 0;
                while (!s.IsComplete())
                {
                    var item = ItemData.Serdes(i, null, s);
                    items.Add(item);
                    i++;
                }
            }
            else
            {
                foreach (var item in items)
                {
                    ItemData.Serdes((int)item.Id, item, s);
                }
            }

            s.End();
            return(items);
        }
Exemplo n.º 5
0
        string BuildSaveFilename(ushort i)
        {
            var key           = new AssetKey(AssetType.SavedGame, i);
            var generalConfig = Resolve <IAssetManager>().LoadGeneralConfig();

            return(Path.Combine(generalConfig.BasePath, generalConfig.SavePath, $"SAVE.{key.Id:D3}"));
        }
Exemplo n.º 6
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            var results = new Dictionary <int, string>();
            var bytes   = br.ReadBytes((int)streamLength);
            var data    = FormatUtil.BytesTo850String(bytes);
            var lines   = data.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries);

            foreach (var line in lines)
            {
                var m = Regex.Match(line);
                if (!m.Success)
                {
                    continue;
                }

                var id   = int.Parse(m.Groups[1].Value);
                var text = m.Groups[2].Value;
                results[id] = text;
            }

            return(results);

/*
 *          var fullText = FormatUtil.BytesTo850String(br.ReadBytes((int)streamLength));
 *          var lines = fullText.Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
 *          foreach (var line in lines)
 *          {
 *              if (line[0] != '[')
 *                  continue;
 *              var untilColon = line.Substring(1, line.IndexOf(':') - 1);
 *              int id = int.Parse(untilColon);
 *              strings[id] = line.Substring(line.IndexOf(':') + 1).TrimEnd(']');
 *          }
 */
        }
Exemplo n.º 7
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            var initial = br.BaseStream.Position;

            var blockList = new List <Block>();

            while (br.BaseStream.Position < initial + streamLength)
            {
                var block = new Block();
                block.Width    = br.ReadByte();
                block.Height   = br.ReadByte();
                block.Underlay = new int[block.Width * block.Height];
                block.Overlay  = new int[block.Width * block.Height];

                for (int i = 0; i < block.Underlay.Length; i++)
                {
                    byte b1 = br.ReadByte();
                    byte b2 = br.ReadByte();
                    byte b3 = br.ReadByte();

                    int underlay = ((b2 & 0x0F) << 8) + b3;
                    int overlay  = (b1 << 4) + (b2 >> 4);
                    block.Underlay[i] = underlay;
                    block.Overlay[i]  = overlay;
                }
                blockList.Add(block);
            }

            return(blockList);
        }
Exemplo n.º 8
0
        /// <summary>
        /// 实例化资源接口中间回调
        /// </summary>
        /// <param name="assetKey"></param>
        /// <param name="initObject"></param>
        private void OnLoadAssetCallBack(AssetKey assetKey, UnityEngine.Object initObject)
        {
            string assetKeyName = assetKey.ToString();

            if (m_AssetToGameObjectInstantiateData.ContainsKey(assetKeyName))
            {
                Queue <GameObjectInstantiateData> mGameObjectInstantiateQueue = m_AssetToGameObjectInstantiateData[assetKeyName];
                while (mGameObjectInstantiateQueue.Count > 0)
                {
                    GameObjectInstantiateData gameObjectInstantiateData = mGameObjectInstantiateQueue.Dequeue();
                    GameObject gameObject = null;

                    if (initObject is GameObject)
                    {
                        gameObject = GameObject.Instantiate(initObject) as GameObject;
                        if (!gameObjectInstantiateData.BasicData.IsWorldSpace)
                        {
                            if (gameObjectInstantiateData.BasicData.Parent != null)
                            {
                                gameObject.transform.SetParent(gameObjectInstantiateData.BasicData.Parent);
                            }
                        }
                        gameObject.transform.localPosition = gameObjectInstantiateData.BasicData.Position;
                        gameObject.transform.localScale    = Vector3.one;
                    }

                    gameObjectInstantiateData.GameObjectCallback(assetKey, gameObject);
                }
            }
        }
Exemplo n.º 9
0
        private static IEnumerator GetAssetAsyncInternal <T>(AssetBundle assetBundle, string bundleName, string assetName, Action <T> onLoaded) where T : Object
        {
            AssetKey assetKey = new AssetKey(typeof(T), assetName);
            Dictionary <AssetKey, Object> assetDict;

            //Bundle为null,返回null对象
            if (!assetBundle)
            {
                Debug.LogError($"GetAssetAsync {assetName} from {bundleName} error: Null AssetBundle!");
                //添加null对象,下次再加载同样的资源直接返回null
                if (!mAssetDicts.TryGetValue(bundleName, out assetDict))
                {
                    assetDict = new Dictionary <AssetKey, Object>();
                    mAssetDicts.Add(bundleName, assetDict);
                }
                assetDict[assetKey] = null;
                onLoaded?.Invoke(null);
                yield break;
            }

            var assetBundleRequest = assetBundle.LoadAssetAsync <T>(assetName);

            if (assetBundleRequest == null)
            {
                Debug.LogError($"GetAssetAsync {assetName} from {bundleName} error: Null AssetBundleRequest!");
                //添加null对象,下次再加载同样的资源直接返回null
                if (!mAssetDicts.TryGetValue(bundleName, out assetDict))
                {
                    assetDict = new Dictionary <AssetKey, Object>();
                    mAssetDicts.Add(bundleName, assetDict);
                }
                assetDict[assetKey] = null;
                onLoaded?.Invoke(null);
                yield break;
            }
            yield return(assetBundleRequest);

            if (!assetBundleRequest.isDone)
            {
                Debug.LogError($"GetAssetAsync {assetName} from {bundleName} error: AssetBundleRequest is not done!");
            }

            var asset = assetBundleRequest.asset;

            if (!asset)
            {
                Debug.LogError($"GetAssetAsync {assetName} from {bundleName} error: Null Asset!");
            }
            if (!mAssetDicts.TryGetValue(bundleName, out assetDict))
            {
                assetDict = new Dictionary <AssetKey, Object>();
                mAssetDicts.Add(bundleName, assetDict);
            }
            assetDict[assetKey] = asset;
#if UNITY_EDITOR
            ReplaceShader(asset);
#endif
            onLoaded?.Invoke((T)asset);
        }
Exemplo n.º 10
0
        protected void WriteOptions(AssetKey assetGuid, string urhoTextureName, DateTime lastWriteTimeUtc,
                                    TextureOptions options)
        {
            if (options == null)
            {
                return;
            }
            var xmlFileName = ExportUtils.ReplaceExtension(urhoTextureName, ".xml");

            if (xmlFileName == urhoTextureName)
            {
                return;
            }
            using (var writer = _engine.TryCreateXml(assetGuid, xmlFileName, lastWriteTimeUtc))
            {
                if (writer != null)
                {
                    writer.WriteStartElement("texture");
                    writer.WriteWhitespace(Environment.NewLine);
                    switch (options.filterMode)
                    {
                    case FilterMode.Point:
                        writer.WriteElementParameter("filter", "mode", "nearest");
                        break;

                    case FilterMode.Bilinear:
                        writer.WriteElementParameter("filter", "mode", "bilinear");
                        break;

                    case FilterMode.Trilinear:
                        writer.WriteElementParameter("filter", "mode", "trilinear");
                        break;

                    default:
                        writer.WriteElementParameter("filter", "mode", "default");
                        break;
                    }

                    switch (options.wrapMode)
                    {
                    case TextureWrapMode.Repeat:
                        writer.WriteElementParameter("address", "mode", "wrap");
                        break;

                    case TextureWrapMode.Clamp:
                        writer.WriteElementParameter("address", "mode", "clamp");
                        break;

                    case TextureWrapMode.Mirror:
                        writer.WriteElementParameter("address", "mode", "mirror");
                        break;
                    }

                    writer.WriteElementParameter("srgb", "enable", options.sRGBTexture ? "true" : "false");
                    writer.WriteElementParameter("mipmap", "enable", options.mipmapEnabled ? "true" : "false");
                    writer.WriteEndElement();
                }
            }
        }
Exemplo n.º 11
0
        public object Process(ICoreFactory factory, AssetKey key, object asset, Func <AssetKey, object> loaderFunc)
        {
            var bitmap = (InterlacedBitmap)asset;

            return(new TrueColorTexture(
                       key.ToString(), (uint)bitmap.Width, (uint)bitmap.Height,
                       bitmap.Palette, bitmap.ImageData));
        }
Exemplo n.º 12
0
 public CharacterSheet(AssetKey key)
 {
     Key = key;
     if (key.Type == AssetType.PartyMember)
     {
         Inventory = new Inventory((InventoryId)key);
     }
 }
Exemplo n.º 13
0
        /// <summary>
        /// Get asset from AssetBundle asynchronously.
        /// </summary>
        /// <param name="bundleName">Bundle name without extension.</param>
        /// <param name="assetName">Asset name.</param>
        /// <param name="onLoaded">Callback when loaded.</param>
        /// <typeparam name="T">Asset type.</typeparam>
        public static void GetAssetAsync <T>(string bundleName, string assetName, Action <T> onLoaded) where T : Object
        {
#if UNITY_EDITOR
            if (mFastMode)
            {
                var obj = GetAssetFastMode <T>(bundleName, assetName);
                onLoaded?.Invoke(obj);
                return;
            }
#endif
            AssetKey assetKey = new AssetKey(typeof(T), assetName);
            if (!mAssetDicts.TryGetValue(bundleName, out var assetDict))
            {
                assetDict = new Dictionary <AssetKey, Object>();
                mAssetDicts.Add(bundleName, assetDict);
            }

            //Already loaded
            if (assetDict.TryGetValue(assetKey, out var asset))
            {
                onLoaded?.Invoke((T)asset);
                return;
            }

            //Loading
            if (mLoadingAssetDicts.TryGetValue(bundleName, out var loadingAssetDict))
            {
                if (loadingAssetDict.TryGetValue(assetKey, out var loadingAsset))
                {
                    ((LoadingAsset <T>)loadingAsset).Completed += onLoaded;
                    return;
                }
            }

            if (mLoadedAssetBundleDict.TryGetValue(bundleName, out var loadedAssetBundle))
            {
                //Bundle is null
                if (!loadedAssetBundle.AssetBundle)
                {
                    Debug.LogError($"GetAssetAsync {assetName} from {bundleName} error: Null AssetBundle!");
                    //Add null to the dictionary. When the same resource is loaded next time, null is returned directly.
                    assetDict.Add(assetKey, null);
                    onLoaded?.Invoke(null);
                    return;
                }

                GetAssetAsyncInternal(loadedAssetBundle.AssetBundle, bundleName, assetName, onLoaded);
            }
            else
            {
                var param1 = bundleName;
                var param2 = assetName;
                var param3 = onLoaded;
                LoadAssetBundleAsyncInternal(bundleName,
                                             bundle => { GetAssetAsyncInternal(bundle, param1, param2, param3); });
            }
        }
Exemplo n.º 14
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            if (config.Format == FileFormat.Palette)
            {
                return(new AlbionPalette(br, (int)streamLength, key, config.Id));
            }

            return(br.ReadBytes(192)); // Common palette
        }
Exemplo n.º 15
0
        public XmlWriter TryCreateXml(AssetKey assetGuid, string relativePath, DateTime sourceFileTimestampUTC)
        {
            var fileStream = TryCreate(assetGuid, relativePath, sourceFileTimestampUTC);

            if (fileStream == null)
            {
                return(null);
            }
            return(new XmlTextWriter(fileStream, new UTF8Encoding(false)));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Get asset from AssetBundle synchronously.
        /// </summary>
        /// <param name="bundleName">Bundle name without extension.</param>
        /// <param name="assetName">Asset name.</param>
        /// <typeparam name="T">Asset type.</typeparam>
        /// <returns>Asset.</returns>
        public static T GetAsset <T>(string bundleName, string assetName) where T : Object
        {
#if UNITY_EDITOR
            if (mFastMode)
            {
                return(GetAssetFastMode <T>(bundleName, assetName));
            }
#endif
            AssetKey assetKey = new AssetKey(typeof(T), assetName);
            if (!mAssetDicts.TryGetValue(bundleName, out var assetDict))
            {
                assetDict = new Dictionary <AssetKey, Object>();
                mAssetDicts.Add(bundleName, assetDict);
            }

            //Already loaded
            if (assetDict.TryGetValue(assetKey, out var asset))
            {
                return((T)asset);
            }
            //Loading
            if (mLoadingAssetDicts.TryGetValue(bundleName, out var loadingAssetDict))
            {
                if (loadingAssetDict.TryGetValue(assetKey, out var loadingAsset))
                {
                    return((T)loadingAsset.GetAsset()); //Force load sync
                }
            }

            var assetBundle = LoadAssetBundle(bundleName);
            //Bundle is null
            if (!assetBundle)
            {
                Debug.LogError($"GetAsset {assetName} from {bundleName} error: Null AssetBundle!");
                //Add null to the dictionary. When the same resource is loaded next time, null is returned directly.
                assetDict.Add(assetKey, null);
                return(null);
            }

            //Double Check
            if (assetDict.TryGetValue(assetKey, out asset))
            {
                return((T)asset);
            }
            asset = assetBundle.LoadAsset <T>(assetName);
            if (!asset)
            {
                Debug.LogError($"GetAsset {assetName} from {bundleName} error: Null Asset!");
            }
            assetDict.Add(assetKey, asset);
#if UNITY_EDITOR
            ReplaceShader(asset);
#endif
            return((T)asset);
        }
Exemplo n.º 17
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            ApiUtil.Assert(config.Transposed != true);
            long initialPosition = br.BaseStream.Position;
            var  sizes           = ParseSpriteSizes(config.SubSprites);

            AlbionSprite sprite = new AlbionSprite
            {
                Name          = key.ToString(),
                Width         = 0,
                UniformFrames = false,
                Frames        = new List <AlbionSprite.Frame>()
            };

            int currentY   = 0;
            var frameBytes = new List <byte[]>();

            foreach (var(width, height) in sizes)
            {
                if (br.BaseStream.Position >= initialPosition + streamLength)
                {
                    break;
                }

                var bytes = br.ReadBytes(width * height);
                sprite.Frames.Add(new AlbionSprite.Frame(0, currentY, width, height));
                frameBytes.Add(bytes);

                currentY += height;
                if (width > sprite.Width)
                {
                    sprite.Width = width;
                }
            }

            sprite.Height    = currentY;
            sprite.PixelData = new byte[sprite.Frames.Count * sprite.Width * currentY];

            for (int n = 0; n < sprite.Frames.Count; n++)
            {
                var frame = sprite.Frames[n];

                for (int j = 0; j < frame.Height; j++)
                {
                    for (int i = 0; i < frame.Width; i++)
                    {
                        sprite.PixelData[(frame.Y + j) * sprite.Width + frame.X + i] = frameBytes[n][j * frame.Width + i];
                    }
                }
            }

            ApiUtil.Assert(br.BaseStream.Position == initialPosition + streamLength);
            return(sprite);
        }
Exemplo n.º 18
0
    /// <summary>
    /// Searches the dictionary of assets for one matching the provided name and type. Returns null if it can not.
    /// </summary>
    /// <param name="assetName"></param>
    /// <param name="assetType"></param>
    /// <returns></returns>
    public AssetInfo FindAsset(string assetName, AssetType assetType)
    {
        AssetInfo result = null;
        AssetKey  key    = new AssetKey(assetName, assetType);

        if (mDictAssets.ContainsKey(key))
        {
            result = new AssetInfo(key, mDictAssets[key]);
        }

        return(result);
    }
Exemplo n.º 19
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            var sprite = (AlbionSprite) new FixedSizeSpriteLoader().Load(br, streamLength, key, config);

            sprite.Frames = new[]
            {
                sprite.Frames[0],
                new AlbionSprite.Frame(0, sprite.Height - 48, sprite.Width, 48)
            };

            return(sprite);
        }
Exemplo n.º 20
0
 /// <summary>
 ///     Gets asset locker.
 /// </summary>
 /// <param name="assetKey"> The asset key. </param>
 /// <param name="create">   True to create. </param>
 /// <returns>
 ///     The asset locker.
 /// </returns>
 private object?GetAssetLocker(AssetKey assetKey, bool create)
 {
     lock (_assetLockers)
     {
         if (!_assetLockers.TryGetValue(assetKey, out object assetLockerRead) && create)
         {
             assetLockerRead = new object();
             _assetLockers.Add(assetKey, assetLockerRead);
         }
         return(assetLockerRead);
     }
 }
Exemplo n.º 21
0
        /// <summary>
        /// 异步加载资源
        /// </summary>
        /// <param name="assetKey"></param>
        /// <param name="callback"></param>
        public void LoadAssetAsync(AssetKey assetKey, Action <AssetKey, UnityEngine.Object> callback)
        {
            MDebug.Log(LOG_TAG, $"LoadAssetAsync({assetKey})");
            MDebug.Assert(callback != null, LOG_TAG, "callback != null");

            int assetIndex = (int)assetKey;

            AssetHandler assetHandler = m_AssetHandlers[assetIndex];

            if (assetHandler == null)
            {
                assetHandler = m_AssetHandlerPool.Alloc();
                assetHandler.SetAssetKey(assetKey);
                m_AssetHandlers[assetIndex] = assetHandler;
            }

            AssetAction assetAction = assetHandler.AddReference(callback);

            switch (assetAction)
            {
            case AssetAction.RequestLoadBundle:
                int   bundleIndex            = m_AssetInfos[assetIndex].BundleIndex;
                int[] dependencyBundleIndexs = m_BundleInfos[bundleIndex].DependencyBundleIndexs;
                for (int iBundle = 0; iBundle < dependencyBundleIndexs.Length; iBundle++)
                {
                    int iterDependencyBundleIndex = dependencyBundleIndexs[iBundle];
                    LoadBundleForLoadAsset(iterDependencyBundleIndex, assetIndex);
                }
                LoadBundleForLoadAsset(bundleIndex, assetIndex);

                //全部依赖Bundle加载完成?

                if (assetHandler.GetRemainLoadBundleCount() == 0)
                {
                    AddAssetActionRequest(assetIndex, AssetAction.Load);
                }
                break;

            case AssetAction.Load:
            case AssetAction.LoadedCallback:
                AddAssetActionRequest(assetIndex, assetAction);
                break;

            case AssetAction.Null:
                // Nothing To Do
                break;

            default:
                MDebug.Assert(false, LOG_TAG, "Asset Not Support AssetAction: " + assetAction);
                break;
            }
        }
Exemplo n.º 22
0
        private static void GetAssetAsyncInternal <T>(AssetBundle assetBundle, string bundleName, string assetName, Action <T> onLoaded) where T : Object
        {
            AssetKey assetKey = new AssetKey(typeof(T), assetName);
            Dictionary <AssetKey, Object> assetDict;

            //Bundle is null
            if (!assetBundle)
            {
                Debug.LogError($"GetAssetAsync {assetName} from {bundleName} error: Null AssetBundle!");
                //Add null to the dictionary. When the same resource is loaded next time, null is returned directly.
                if (!mAssetDicts.TryGetValue(bundleName, out assetDict))
                {
                    assetDict = new Dictionary <AssetKey, Object>();
                    mAssetDicts.Add(bundleName, assetDict);
                }

                assetDict[assetKey] = null;
                onLoaded?.Invoke(null);
                return;
            }

            if (!mLoadingAssetDicts.TryGetValue(bundleName, out var loadingAssetDict))
            {
                loadingAssetDict = new Dictionary <AssetKey, LoadingAssetBase>();
                mLoadingAssetDicts.Add(bundleName, loadingAssetDict);
            }

            //Not loading
            if (!loadingAssetDict.TryGetValue(assetKey, out var loadingAsset))
            {
                var assetBundleRequest = assetBundle.LoadAssetAsync <T>(assetName);
                if (assetBundleRequest == null)
                {
                    Debug.LogError($"GetAssetAsync {assetName} from {bundleName} error: Null AssetBundleRequest!");
                    //Add null to the dictionary. When the same resource is loaded next time, null is returned directly.
                    if (!mAssetDicts.TryGetValue(bundleName, out assetDict))
                    {
                        assetDict = new Dictionary <AssetKey, Object>();
                        mAssetDicts.Add(bundleName, assetDict);
                    }

                    assetDict[assetKey] = null;
                    onLoaded?.Invoke(null);
                    return;
                }

                //Add to loading
                loadingAsset = new LoadingAsset <T>(bundleName, assetName, assetBundleRequest);
            }

            ((LoadingAsset <T>)loadingAsset).Completed += onLoaded;
        }
Exemplo n.º 23
0
 protected LoadingAssetBase(string bundleName, AssetKey assetKey, AssetBundleRequest assetBundleRequest)
 {
     BundleName                     = bundleName;
     AssetKey                       = assetKey;
     mAssetBundleRequest            = assetBundleRequest;
     mAssetBundleRequest.completed += OnCompleted;
     if (!mLoadingAssetDicts.TryGetValue(BundleName, out var loadingAssetDict))
     {
         loadingAssetDict = new Dictionary <AssetKey, LoadingAssetBase>();
         mLoadingAssetDicts.Add(BundleName, loadingAssetDict);
     }
     loadingAssetDict.Add(AssetKey, this);
 }
Exemplo n.º 24
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            int wordListId = config.Id;
            var wordCount  = streamLength / WordLength;
            var s          = new GenericBinaryReader(br, streamLength, FormatUtil.BytesTo850String, ApiUtil.Assert);
            var words      = new Dictionary <int, string>();

            for (int i = 0; i < wordCount; i++)
            {
                words[wordListId * 100 + i] = s.FixedLengthString("Word", null, WordLength);
            }
            return(words);
        }
Exemplo n.º 25
0
        public void LoadAssetAsync(AssetKey assetKey, Action <AssetKey, UnityEngine.Object> callback)
        {
            MDebug.Assert(callback != null, LOG_TAG, "callback == null");
            MDebug.Log(LOG_TAG, $"LoadAssetAsync({assetKey})");
            int assetIndex = (int)assetKey;

            if (!m_AssetCallBackDic.ContainsKey(assetIndex))
            {
                Action <AssetKey, UnityEngine.Object> m_CallBack = null;
                m_AssetCallBackDic.Add(assetIndex, m_CallBack);
            }
            m_AssetCallBackDic[assetIndex] += callback;
        }
Exemplo n.º 26
0
        public void LoadAsset()
        {
            List <int> tmpKeys = new List <int>(m_AssetCallBackDic.Keys);

            for (int i = 0; i < tmpKeys.Count; i++)
            {
                int                tmpAssetIndex = tmpKeys[i];
                AssetKey           tmpKey        = (AssetKey)tmpAssetIndex;
                UnityEngine.Object assetLoaded   = AssetDatabase.LoadMainAssetAtPath(m_AssetInfos[tmpKeys[i]].AssetPath);
                m_AssetCallBackDic[tmpAssetIndex]?.Invoke(tmpKey, assetLoaded);
                m_AssetCallBackDic[tmpAssetIndex] = null;
            }
        }
Exemplo n.º 27
0
        private object GetAssetLocker(AssetKey assetKey, bool create)
        {
            object assetLockerRead;

            lock (assetLockers)
            {
                if (!assetLockers.TryGetValue(assetKey, out assetLockerRead) && create)
                {
                    assetLockerRead = new object();
                    assetLockers.Add(assetKey, assetLockerRead);
                }
            }
            return(assetLockerRead);
        }
Exemplo n.º 28
0
        public object Load(BinaryReader br, long streamLength, AssetKey key, AssetInfo config)
        {
            if (config.Format == FileFormat.AudioSample)
            {
                return(new AlbionSample(br.ReadBytes((int)streamLength)));
            }

            if (config.Format == FileFormat.SampleLibrary)
            {
                return(WaveLib.Serdes(null, new GenericBinaryReader(br, streamLength, FormatUtil.BytesTo850String, ApiUtil.Assert)));
            }

            throw new InvalidOperationException($"Tried to load asset of invalid type \"{config.Format}\" in SampleLoader");
        }
Exemplo n.º 29
0
 private void SaveJson(string animationControllerName, object json, AssetKey assetGuid, DateTime sourceFileTimestampUtc)
 {
     using (var fileStream = _engine.TryCreate(assetGuid, animationControllerName, sourceFileTimestampUtc))
     {
         if (fileStream == null)
         {
             return;
         }
         using (var streamWriter = new StreamWriter(fileStream, new UTF8Encoding(false)))
         {
             streamWriter.Write(EditorJsonUtility.ToJson(json, true));
         }
     }
 }
        protected override Xbim.CobieLiteUk.System Mapping(IIfcPropertySet pSet, Xbim.CobieLiteUk.System target)
        {
            var helper = ((IfcToCOBieLiteUkExchanger)Exchanger).Helper;

            //Add Assets
            var systemAssignments = helper.GetSystemAssignments(pSet);

            var    ifcObjectDefinitions = systemAssignments as IList <IIfcObjectDefinition> ?? systemAssignments.ToList();
            string name = string.Empty;

            if (ifcObjectDefinitions.Any())
            {
                name = GetSystemName(helper, ifcObjectDefinitions);

                target.Components = new List <AssetKey>();
                foreach (var ifcObjectDefinition in ifcObjectDefinitions)
                {
                    var assetKey = new AssetKey {
                        Name = ifcObjectDefinition.Name
                    };
                    if (!target.Components.Contains(assetKey))
                    {
                        target.Components.Add(assetKey);
                    }
                }
            }
            target.ExternalEntity = helper.ExternalEntityName(pSet);
            target.ExternalId     = helper.ExternalEntityIdentity(pSet);
            target.ExternalSystem = helper.ExternalSystemName(pSet);
            target.Name           = string.IsNullOrEmpty(name) ? "Unknown" : name;
            target.Description    = string.IsNullOrEmpty(pSet.Description) ? name : pSet.Description.ToString();
            target.CreatedBy      = helper.GetCreatedBy(pSet);
            target.CreatedOn      = helper.GetCreatedOn(pSet);
            target.Categories     = helper.GetCategories(pSet);

            //Attributes, no attributes from PSet as Pset is the attributes, assume that component attributes are extracted by each component anyway
            //target.Attributes = helper.GetAttributes(pSet);

            //Documents
            var docsMappings = Exchanger.GetOrCreateMappings <MappingIfcDocumentSelectToDocument>();

            helper.AddDocuments(docsMappings, target, pSet);

            //TODO:
            //System Issues

            return(target);
        }
Exemplo n.º 31
0
		//https://github.com/OpenAssets/open-assets-protocol/blob/master/specification.mediawiki
		public void CanColorizeSpecScenario()
		{
			var repo = new NoSqlColoredTransactionRepository();
			var dust = Money.Parse("0.00005");
			var colored = new ColoredTransaction();
			var a1 = new AssetKey();
			var a2 = new AssetKey();
			var h = new AssetKey();
			var sender = new Key().PubKey.GetAddress(Network.Main);
			var receiver = new Key().PubKey.GetAddress(Network.Main);

			colored.Marker = new ColorMarker(new ulong[] { 0, 10, 6, 0, 7, 3 });
			colored.Inputs.Add(new ColoredEntry(0, new AssetMoney(a1.Id, 3UL)));
			colored.Inputs.Add(new ColoredEntry(1, new AssetMoney(a1.Id, 2UL)));
			colored.Inputs.Add(new ColoredEntry(3, new AssetMoney(a1.Id, 5UL)));
			colored.Inputs.Add(new ColoredEntry(4, new AssetMoney(a1.Id, 3UL)));
			colored.Inputs.Add(new ColoredEntry(5, new AssetMoney(a2.Id, 9UL)));

			colored.Issuances.Add(new ColoredEntry(1, new AssetMoney(h.Id, 10UL)));
			colored.Transfers.Add(new ColoredEntry(3, new AssetMoney(a1.Id, 6UL)));
			colored.Transfers.Add(new ColoredEntry(5, new AssetMoney(a1.Id, 7UL)));
			colored.Transfers.Add(new ColoredEntry(6, new AssetMoney(a2.Id, 3UL)));
			var destroyed = colored.GetDestroyedAssets();
			Assert.True(destroyed.Length == 1);
			Assert.True(destroyed[0].Quantity == 6);
			Assert.True(destroyed[0].Id == a2.Id);
			colored = colored.Clone();
			destroyed = colored.GetDestroyedAssets();
			Assert.True(destroyed.Length == 1);
			Assert.True(destroyed[0].Quantity == 6);
			Assert.True(destroyed[0].Id == a2.Id);

			var prior = new Transaction();
			prior.Outputs.Add(new TxOut(dust, a1.ScriptPubKey));
			prior.Outputs.Add(new TxOut(dust, a2.ScriptPubKey));
			prior.Outputs.Add(new TxOut(dust, h.ScriptPubKey));
			repo.Transactions.Put(prior.GetHash(), prior);

			var issuanceA1 = new Transaction();
			issuanceA1.Inputs.Add(new TxIn(new OutPoint(prior.GetHash(), 0)));
			issuanceA1.Outputs.Add(new TxOut(dust, h.ScriptPubKey));
			issuanceA1.Outputs.Add(new TxOut(dust, sender));
			issuanceA1.Outputs.Add(new TxOut(dust, sender));
			issuanceA1.Outputs.Add(new TxOut(dust, sender));
			issuanceA1.Outputs.Add(new TxOut(dust, new ColorMarker(new ulong[] { 3, 2, 5, 3 }).GetScript()));
			repo.Transactions.Put(issuanceA1.GetHash(), issuanceA1);

			var issuanceA2 = new Transaction();
			issuanceA2.Inputs.Add(new TxIn(new OutPoint(prior.GetHash(), 1)));
			issuanceA2.Outputs.Add(new TxOut(dust, sender));
			issuanceA2.Outputs.Add(new TxOut(dust, new ColorMarker(new ulong[] { 9 }).GetScript()));
			repo.Transactions.Put(issuanceA2.GetHash(), issuanceA2);

			var testedTx = CreateSpecTransaction(repo, dust, receiver, prior, issuanceA1, issuanceA2);
			var actualColored = testedTx.GetColoredTransaction(repo);

			Assert.True(colored.ToBytes().SequenceEqual(actualColored.ToBytes()));


			//Finally, for each transfer output, if the asset units forming that output all have the same asset address, the output gets assigned that asset address. If any output contains units from more than one distinct asset address, the whole transaction is considered invalid, and all outputs are uncolored.

			var testedBadTx = CreateSpecTransaction(repo, dust, receiver, prior, issuanceA1, issuanceA2);
			testedBadTx.Outputs[2] = new TxOut(dust, new ColorMarker(new ulong[] { 0, 10, 6, 0, 6, 4 }).GetScript());
			repo.Transactions.Put(testedBadTx.GetHash(), testedBadTx);
			colored = testedBadTx.GetColoredTransaction(repo);

			destroyed = colored.GetDestroyedAssets();
			Assert.True(destroyed.Length == 2);
			Assert.True(destroyed[0].Id == a1.Id);
			Assert.True(destroyed[0].Quantity == 13);
			Assert.True(destroyed[1].Id == a2.Id);
			Assert.True(destroyed[1].Quantity == 9);


			//If there are more items in the  asset quantity list  than the number of colorable outputs, the transaction is deemed invalid, and all outputs are uncolored.
			testedBadTx = CreateSpecTransaction(repo, dust, receiver, prior, issuanceA1, issuanceA2);
			testedBadTx.Outputs[2] = new TxOut(dust, new ColorMarker(new ulong[] { 0, 10, 6, 0, 7, 4, 10, 10 }).GetScript());
			repo.Transactions.Put(testedBadTx.GetHash(), testedBadTx);

			colored = testedBadTx.GetColoredTransaction(repo);

			destroyed = colored.GetDestroyedAssets();
			Assert.True(destroyed.Length == 2);
			Assert.True(destroyed[0].Id == a1.Id);
			Assert.True(destroyed[0].Quantity == 13);
			Assert.True(destroyed[1].Id == a2.Id);
			Assert.True(destroyed[1].Quantity == 9);
		}