示例#1
0
 /// <summary>
 /// Returns paths to all assets that match this filter using AssetDatabase.
 /// </summary>
 public static string[] FindAssets(string filter)
 {
     string[] paths = Relay.FindAssets(filter);
     for (int i = 0; i < paths.Length; i++)
     {
         ref string path = ref paths[i];
         path = path.Replace("Assets/", "");
     }
示例#2
0
        /// <summary>
        /// Loads all assets of this kind using AssetDatabase.
        /// </summary>
        public static List <T> FindAssetsByType <T>() where T : Object
        {
            List <T> assets = new List <T>();

            string[] paths = Relay.FindAssets <T>();
            for (int i = 0; i < paths.Length; i++)
            {
                string path  = paths[i];
                T      asset = Relay.LoadAssetAtPath <T>(path);
                if (asset != null)
                {
                    assets.Add(asset);
                }
            }

            return(assets);
        }
示例#3
0
        internal void EnsureCacheExists(bool forceRecreate = false)
        {
            bool errorFound = false;

            if (pathToItem == null || forceRecreate)
            {
                pathToItem = new Dictionary <string, Reference>();

                //built in
                for (int i = 0; i < assets.Count; i++)
                {
                    if (assets[i] == null)
                    {
                        errorFound = true;
                        continue;
                    }

                    string key = assets[i].Path.Replace('\\', '/');
                    if (!string.IsNullOrEmpty(key))
                    {
                        if (pathToItem.ContainsKey(key))
                        {
                            continue;
                        }

                        pathToItem.Add(key, assets[i]);
                    }
                    else
                    {
                        Debug.LogWarning($"[Referencer] {assets[i]?.Object?.name} has no path, so not adding to reference db");
                    }
                }
            }

            if (nameToItem == null || forceRecreate)
            {
                nameToItem = new Dictionary <string, Reference>();

                //built in
                for (int i = 0; i < assets.Count; i++)
                {
                    if (assets[i] == null)
                    {
                        errorFound = true;
                        continue;
                    }

                    Type type = assets[i].Type;
                    if (type == null)
                    {
                        errorFound = true;
                        continue;
                    }

                    string key = $"{type.FullName}:{Path.GetFileNameWithoutExtension(assets[i].Path)}";
                    if (!string.IsNullOrEmpty(key))
                    {
                        if (nameToItem.ContainsKey(key))
                        {
                            continue;
                        }

                        nameToItem.Add(key, assets[i]);
                    }
                    else
                    {
                        Debug.LogWarning($"[Referencer] {assets[i]?.Object?.name} has no path, so not adding to reference db");
                    }
                }
            }

            if (objectToPath == null || forceRecreate)
            {
                objectToPath = new Dictionary <Object, string>();

                //built in
                for (int i = 0; i < assets.Count; i++)
                {
                    if (assets[i] == null)
                    {
                        errorFound = true;
                        continue;
                    }

                    Object key = assets[i].Object;
                    if (key)
                    {
                        if (objectToPath.ContainsKey(key))
                        {
                            continue;
                        }

                        string value = assets[i].Path.Replace('\\', '/');
                        objectToPath.Add(key, value);
                    }
                }
            }

            //an error in the database was found, gon refresh now then
            if (errorFound)
            {
                Relay.LoadAll();
            }
        }
示例#4
0
 /// <summary>
 /// Loads all assets from this relative path.
 /// <code>
 /// Example: Prefabs/Projectiles
 /// </code>
 /// </summary>
 public static Object[] LoadAllAssetsAtPath(string path) => Relay.LoadAllAssetsAtPath($"Assets/{path}");
示例#5
0
 /// <summary>
 /// Loads the primary asset from this relative path.
 /// <code>
 /// Example: Prefabs/Projectiles/Bullet.prefab
 /// </code>
 /// </summary>
 public static Object LoadAssetAtPath(string path, Type type) => Relay.LoadAssetAtPath($"Assets/{path}", type);