public static string GeneratedFile(AssetRef scriptRef,
                                           AssetRef ref1,
                                           AssetRef ref2,
                                           AssetRef ref3)
        {
            return($@"%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!114 &11400000
MonoBehaviour:
  m_ObjectHideFlags: 0
  m_CorrespondingSourceObject: {{fileID: 0}}
  m_PrefabInstance: {{fileID: 0}}
  m_PrefabAsset: {{fileID: 0}}
  m_GameObject: {{fileID: 0}}
  m_Enabled: 1
  m_EditorHideFlags: 0
  m_Script: {{fileID: {scriptRef.fileId}, guid: {scriptRef.guid}, type: 3}}
  m_Name: Testito
  m_EditorClassIdentifier: 
  stuff: {{fileID: {ref1.fileId}, guid: {ref1.guid}, type: 3}}
  stuffjoijoijfiodjfsdojfsdodfjd: {{fileID: {ref2.fileId}, guid: {ref2.guid},
    type: 3}}
  stuffjoijdoijafoidjfsdoaijfdsofjsdofjdsofjdsaofjsdofjosdjfsdojfsadjojojojoofj: {{fileID: {ref3.fileId},
    guid: {ref3.guid}, type: 3}}
");
        }
Exemplo n.º 2
0
        protected override void Import(AssetRef asset, ThreadData data, object oLock)
        {
            //Don't export if the file already exists.
            if (File.Exists(ResourceDir + "/Models/" + Path.GetFileNameWithoutExtension(asset.Name) + ".obj"))
            {
                return;
            }

            //De-serialize
            using (MemoryStream modelMemoryStream = asset.Pack.CreateAssetMemoryStreamByName(asset.Name))
            {
                Model model = null;
                while (model == null)
                {
                    model = ObjectPool.GetPooledObject();
                }

                bool deserializeResult = model.InitializeFromStream(asset.Name, asset.DisplayName, modelMemoryStream);

                if (deserializeResult)
                {
                    ExportModel(model, data.StringBuilder, ref data.TextureBuffer);
                }

                ObjectPool.ReturnObjectToPool(model);
            }
        }
Exemplo n.º 3
0
        private async Task LoadZoneTerrain(Zone zone)
        {
            AssetRef[] assets = assetManager.GetAssetsByType(AssetType.CNK1, Path.GetFileNameWithoutExtension(zone.Name));

            if (assets == null || assets.Length == 0)
            {
                Debug.LogWarningFormat("Could not locate any chunk data associated with zone \"{0}\". Skipping load of terrain.", zone);
                return;
            }

            Task <ForgelightChunk>[] chunkTasks = new Task <ForgelightChunk> [assets.Length];
            for (int i = 0; i < assets.Length; i++)
            {
                AssetRef assetRef = assets[i];
                chunkTasks[i] = terrainFactory.CreateChunk(assetRef, zoneTerrain.transform);
                statusReporter.ReportProgress("Loading Terrain Chunks", i, assets.Length);

                await new WaitForUpdate();
            }

            foreach (Task <ForgelightChunk> task in chunkTasks)
            {
                await task;
            }

            statusReporter.ReportProgress("Loading Terrain Chunks", assets.Length, assets.Length);
            zoneTerrain.transform.localScale = new Vector3(-2, 2, 2);
        }
Exemplo n.º 4
0
 public static async Task <string> GetTextAsync(this AssetRef asset, string?encoding,
                                                IAssetFileStore assetFileStore,
                                                CancellationToken ct = default)
 {
     using (var stream = DefaultPools.MemoryStream.GetStream())
     {
         await assetFileStore.DownloadAsync(asset.AppId, asset.Id, asset.FileVersion, null, stream, default, ct);
Exemplo n.º 5
0
        public AssetRef Load(string path, TYPE type = TYPE.Prefab, string assetBundlePath = null)
        {
            path = Core.Path.instance.Resolve(path, type);
            var name     = System.IO.Path.GetFileNameWithoutExtension(path);
            var assetRef = FindAssetRef(path);

            if (assetRef != null)
            {
                Log.Resource.I("Load {0} in Cache", name);
                return(assetRef.Refrence());
            }

            if (string.IsNullOrEmpty(assetBundlePath))
            {
                assetBundlePath = Core.Path.instance.Resolve(path, TYPE.AssetBundle);
            }
            var assetBundleRef = LoadAssetBundle(assetBundlePath);

            if (assetBundleRef == null)
            {
                return(null);
            }

            var assetBundle = assetBundleRef.Get <AssetBundle>();
            var asset       = assetBundle.LoadAsset(name);

            assetRef = new AssetRef(path, asset, new List <AssetRef>()
            {
                assetBundleRef
            });
            CacheAssetRef(assetRef.Refrence());
            return(assetRef);
        }
Exemplo n.º 6
0
    public void AsyncLoad(string bundlePath, string assetName, LoadDelegate lad)
    {
        StartCoroutine(AsyncLoadBundle(bundlePath, delegate(BundleHolder bh)
        {
            if (bh == null)
            {
                lad?.Invoke(null);
                return;
            }

            StartCoroutine(AsyncLoadAsset(bh.bundle, assetName, delegate(Object obj)
            {
                if (obj == null)
                {
                    lad?.Invoke(null);
                    bh.TryRelease();
                    return;
                }

                AssetRef ar = new AssetRef();
                ar.asset    = obj;
                ar.bh       = bh;
                ar.Retain();
                lad?.Invoke(ar);

                bh.TryRelease();
            }));
        }));
    }
Exemplo n.º 7
0
        public void SetTexture(int i)
        {
            if (textures.IsEmpty())
            {
                return;
            }
            if (Platform.isPlaying)
            {
                GetLoader().Load(textures[i], null);
            }
            else
            {
#if UNITY_EDITOR
                i = MathUtil.Clamp(i, 0, textures.Count);
                if (GetLoader().Target != null)
                {
                    AssetRef r = textures[i];
                    r.LoadAsset <Texture>(t => {
                        GetLoader().Target.mainTexture = t;
                #if UNITY_5_3_OR_NEWER
                        UnityEditor.SceneManagement.EditorSceneManager.MarkAllScenesDirty();
                #else
                        UnityEditor.EditorUtility.SetDirty(GetLoader().gameObject);
                #endif
                    });
                }
#endif
            }
        }
Exemplo n.º 8
0
 public MaterialRef(ComponentRef <Renderer> renderer, int materialIndex)
 {
     _materialRef     = null;
     _materialIndex   = materialIndex;
     _renderer        = renderer;
     _editorCollapsed = false;
     _material        = null;
 }
Exemplo n.º 9
0
 public MaterialRef(AssetRef <Material> materialRef)
 {
     _materialRef     = materialRef;
     _materialIndex   = -1;
     _renderer        = new ComponentRef <Renderer>();
     _editorCollapsed = false;
     _material        = null;
 }
Exemplo n.º 10
0
        public GameObject Instantiate(AssetRef assetRef)
        {
            assetRef.Refrence();
            var clone = UnityEngine.Object.Instantiate(assetRef.Get <GameObject>());

            clone.OnDestroyAsObservable().Subscribe(_ => assetRef.Release());
            return(clone);
        }
Exemplo n.º 11
0
 public void AddRef(AssetRef assetRef)
 {
     if (assetRef == null)
     {
         return;
     }
     assetRefList.AddRef(assetRef);//增加引用
 }
Exemplo n.º 12
0
 public MaterialRef(ComponentRef <Graphic> graphic)
 {
     _materialRef     = null;
     _materialIndex   = kGraphicMaterialIndex;
     _renderer        = new ComponentRef <Renderer>();
     _graphic         = graphic;
     _editorCollapsed = false;
     _material        = null;
 }
Exemplo n.º 13
0
 public void SetData(string icon, string name, int count)
 {
     AssetRef.setImage(mIcon, icon);
     mNum.text = count.ToString();
     if (mName != null)
     {
         mName.text = name.ToString();
     }
 }
Exemplo n.º 14
0
    public static void RefAssetWithGameObject(GameObject go, Object asset)
    {
        AssetRef abRef = GetAssetRef(asset);

        if (abRef != null)
        {
            RefAssetWithGameObject(go, abRef);
        }
    }
Exemplo n.º 15
0
 public StateRef(TextAsset asset, int stateId, StateMachine parentStateMachine = null)
 {
     _file    = new AssetRef <TextAsset>(asset);
     _stateId = stateId;
     _editorExternalLinkPosition = Vector2.zero;
     _parentStateMachine         = parentStateMachine;
     _state           = null;
     _editorCollapsed = false;
     _editorStateName = null;
 }
Exemplo n.º 16
0
 public void CacheAsset(AssetRef assetRef, bool isStrong = false)
 {
     if (!isStrong)
     {
         weakRefs.AddRef(assetRef);
     }
     else
     {
         strongRefs.AddRef(assetRef);
     }
 }
Exemplo n.º 17
0
 public GameObjectRef(eSourceType sourceType)
 {
     _sourceType      = sourceType;
     _objectName      = string.Empty;
     _scene           = new SceneRef();
     _sceneObjectID   = -1;
     _prefab          = new AssetRef <GameObject>();
     _gameObject      = null;
     _sourceObject    = null;
     _editorCollapsed = false;
 }
                private Object LoadMainAsset()
                {
                    if (MainType != null)
                    {
                        if (MainType == typeof(object))
                        {
                            return(null);
                        }
                        AssetRef rMain;
                        if (TypedAssets.TryGetValue(MainType, out rMain))
                        {
                            if (rMain.Asset != null)
                            {
                                var asset = rMain.Asset.GetWeakReference <Object>();
                                if (asset)
                                {
                                    return(asset);
                                }
                            }
                        }
                    }

                    if (ManiItem != null && DepBundles.Count > 0)
                    {
                        var bi = DepBundles[DepBundles.Count - 1];
                        if (bi != null && bi.Bundle != null)
                        {
                            var path = ConcatAssetPath();

                            var asset = bi.Bundle.LoadAsset(path);
                            if (!asset)
                            {
                                MainType = typeof(object);
                                return(null);
                            }
                            if (asset is Texture2D)
                            {
                                var sprite = bi.Bundle.LoadAsset(path, typeof(Sprite));
                                if (sprite)
                                {
                                    asset = sprite;
                                }
                            }

                            MainType = asset.GetType();
                            TypedAssets[MainType] = new AssetRef()
                            {
                                Asset = new WeakReference(asset)
                            };
                            return(asset);
                        }
                    }
                    return(null);
                }
Exemplo n.º 19
0
Arquivo: Skybox.cs Projeto: zhuowp/ge
 public Skybox(
     AssetRef <ImageSharpTexture> front, AssetRef <ImageSharpTexture> back, AssetRef <ImageSharpTexture> left,
     AssetRef <ImageSharpTexture> right, AssetRef <ImageSharpTexture> top, AssetRef <ImageSharpTexture> bottom)
 {
     _front  = front;
     _back   = back;
     _left   = left;
     _right  = right;
     _top    = top;
     _bottom = bottom;
 }
Exemplo n.º 20
0
 public static void CopyTexture(TexSetter s, TexLoader l)
 {
     if (l.Target.mainTexture != null && AssetBundlePath.inst.IsCdnAsset(l.Target.mainTexture))
     {
         AssetRef r = new AssetRef();
         r.cdn = true;
         r.SetPath(l.Target.mainTexture);
         s.textures.Add(r);
         EditorUtil.SetDirty(s);
     }
 }
Exemplo n.º 21
0
    static void TryToAddAsset(string name, Object asset)
    {
        AssetRef assetRef;

        if (!dictOfAssetRefs.TryGetValue(name, out assetRef))
        {
            assetRef       = new AssetRef();
            assetRef.name  = name;
            assetRef.asset = asset;
            dictOfAssetRefs.Add(assetRef.name, assetRef);
        }
    }
Exemplo n.º 22
0
        public override bool Draw(string label, ref AssetRef <T> obj, RenderContext rc)
        {
            object assetName = obj.ID.Value;

            if (DrawerCache.GetDrawer(typeof(string)).Draw(label, ref assetName, rc))
            {
                obj = new AssetRef <T>((string)assetName);
                return(true);
            }

            return(false);
        }
                public override Object Load(Type type)
                {
                    if (MainType == null)
                    {
                        var main = LoadMainAsset();
                        if (MainType == typeof(object) || type == null || type.IsAssignableFrom(MainType))
                        {
                            return(main);
                        }
                    }
                    else if (MainType == typeof(object))
                    {
                        return(null);
                    }
                    else if (type == null || type.IsAssignableFrom(MainType))
                    {
                        return(LoadMainAsset());
                    }

                    AssetRef rAsset;

                    if (TypedAssets.TryGetValue(type, out rAsset))
                    {
                        if (rAsset.Asset != null)
                        {
                            var asset = rAsset.Asset.GetWeakReference <Object>();
                            if (asset)
                            {
                                return(asset);
                            }
                        }
                    }

                    if (ManiItem != null && DepBundles.Count > 0)
                    {
                        var bi = DepBundles[DepBundles.Count - 1];
                        if (bi != null && bi.Bundle != null)
                        {
                            var path = ConcatAssetPath();

                            var asset = bi.Bundle.LoadAsset(path, type);

                            TypedAssets[type] = new AssetRef()
                            {
                                Asset = new WeakReference(asset)
                            };
                            return(asset);
                        }
                    }
                    return(null);
                }
Exemplo n.º 24
0
        public virtual async Task <AssetRef> LoadAsync(string path, TYPE type, LoadingOption option, string assetBundlePath)
        {
            path = Core.Path.instance.Resolve(path, type);
            var name     = System.IO.Path.GetFileNameWithoutExtension(path);
            var assetRef = FindAssetRef(path);

            if (assetRef != null)
            {
                Log.Resource.I("LoadAsync {0} in Cache", name);
                return(assetRef.Refrence());
            }

            if (string.IsNullOrEmpty(assetBundlePath))
            {
                assetBundlePath = Core.Path.instance.Resolve(path, TYPE.AssetBundle);
            }
            var assetBundleRef = await LoadAssetBundleAsync(assetBundlePath, option);

            if (assetBundleRef == null)
            {
                return(null);
            }

            var assetBundle        = assetBundleRef.Get <AssetBundle>();
            var assetBundleRequest = assetBundle.LoadAssetAsync(name);
            var result             = await Loading.instance.Wrap(async() =>
            {
                return(await HookProgress(assetBundleRequest, option.progress, 0.7f));
            }, option);

            if (!result)
            {
                return(null);
            }

            var asset = assetBundleRequest.asset;

            if (asset == null)
            {
                return(null);
            }

            assetRef = new AssetRef(path, asset, new List <AssetRef>()
            {
                assetBundleRef
            });
            CacheAssetRef(assetRef.Refrence());
            return(assetRef);
        }
        private static AssetRef createAssetRef(UANode node)
        {
            //AssetRef
            //  -> Key (multiple)


            AssetRef ass  = new AssetRef();
            var      keys = addSemanticID(node);

            foreach (Key key in keys)
            {
                ass.Keys.Add(key);
            }
            return(ass);
        }
Exemplo n.º 26
0
    public void AddRef(AssetRef assetRef)
    {
        if (assetRef == null)
        {
            return;
        }

        int instId = assetRef.InstId;

        if (!m_assetRefs.ContainsKey(instId))
        {
            m_assetRefs.Add(instId, assetRef);
        }
        assetRef.Ref();
    }
Exemplo n.º 27
0
    public void DelRef(AssetRef assetRef)
    {
        if (assetRef == null)
        {
            return;
        }

        int instId = assetRef.InstId;

        if (m_assetRefs.ContainsKey(instId))
        {
            assetRef.UnRef();
            m_assetRefs.Remove(instId);
        }
    }
Exemplo n.º 28
0
        private LinkData Get(int index)
        {
            if (list.ContainsKey(index))
            {
                return(list[index]);
            }

            var cellPrefabRef = new AssetRef(cellPath, cellPrefab);
            var presenter     = context.presenter as Presenters.Framework.List;
            var data          = presenter.Build(cellPrefabRef, cellPath);

            data.node.transform.SetParent(context.gameObject.transform);
            list.Add(index, data);
            return(data);
        }
Exemplo n.º 29
0
 public void Load(AssetRef asset, Action <Texture> callback)
 {
     if (Target != null && !asset.isEmpty)
     {
         if (asset.cdn)
         {
             Load(asset.path, callback);
         }
         else if (asset.GetReference() != null)
         {
             this.loadedCallback = callback;
             SetTexture(asset.GetReference() as Texture);
         }
     }
 }
Exemplo n.º 30
0
        //生成Manifest配置文件
        public static void BuildManifest()
        {
            //获取manifest文件
            var manifest = GetManifest();

            AssetDatabase.RemoveUnusedAssetBundleNames();
            var bundles = AssetDatabase.GetAllAssetBundleNames();

            List <string>   dirs   = new List <string>();
            List <AssetRef> assets = new List <AssetRef>();

            for (int i = 0; i < bundles.Length; i++)
            {
                var paths = AssetDatabase.GetAssetPathsFromAssetBundle(bundles[i]);
                foreach (var path in paths)
                {
                    var dir = Path.GetDirectoryName(path);
                    dir = dir.Replace("\\", "/");
                    var index = dirs.FindIndex((o) => o.Equals(dir));
                    if (index == -1)
                    {
                        index = dirs.Count;

                        dirs.Add(dir);
                    }

                    var asset = new AssetRef();
                    asset.bundle = i;
                    asset.dir    = index;
                    asset.name   = Path.GetFileName(path);

                    assets.Add(asset);
                }
            }

            manifest.bundles = bundles;
            manifest.dirs    = dirs.ToArray();
            manifest.assets  = assets.ToArray();

            var assetPath  = AssetDatabase.GetAssetPath(manifest);
            var bundleName = Path.GetFileNameWithoutExtension(assetPath).ToLower();

            SetAssetBundleNameAndVariant(assetPath, bundleName, null);

            EditorUtility.SetDirty(manifest);
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
Exemplo n.º 31
0
 static void TryToAddAsset(string name, Object asset)
 {
     AssetRef assetRef;
     if (! dictOfAssetRefs.TryGetValue (name, out assetRef)) {
         assetRef = new AssetRef ();
         assetRef.name = name;
         assetRef.asset = asset;
         dictOfAssetRefs.Add (assetRef.name, assetRef);
     }
 }