public static void Build()
        {
            PrefabPathAsset         configAsset;
            List <PrefabPathConfig> configs;

            if (File.Exists(PrefabListPath))
            {
                configAsset = AssetDatabase.LoadAssetAtPath <PrefabPathAsset>(PrefabListPath);
                configs     = new List <PrefabPathConfig>(configAsset.Configs);
            }
            else
            {
                configAsset = new PrefabPathAsset();
                configs     = new List <PrefabPathConfig>();
            }

            DirectoryInfo root = new DirectoryInfo(Application.dataPath + "/Art/SceneRes");

            FileInfo[] fileInfos = root.GetFiles("*.prefab", SearchOption.AllDirectories);

            int index = configs.Count == 0 ? 1 : configs[configs.Count - 1].ID + 1;

            for (int i = configs.Count - 1; i >= 0; i--)
            {
                string path = configs[i].Path;
                if (!File.Exists(path))
                {
                    configs.Remove(configs[i]);
                }
            }


            foreach (var item in fileInfos)
            {
                string path = item.FullName.Replace("\\", "/");
                path = path.Replace(Application.dataPath, "Assets");
                if (configs.Find(p => p.Path == path) == null)
                {
                    PrefabPathConfig config = new PrefabPathConfig();
                    config.ID   = index++;
                    config.Path = path;
                    configs.Add(config);
                }
            }
            configAsset.Configs = configs.ToArray();
            if (File.Exists(PrefabListPath))
            {
                EditorUtility.SetDirty(configAsset);
            }
            else
            {
                AssetDatabase.CreateAsset(configAsset, PrefabListPath);
            }
        }
示例#2
0
        public static void Init()
        {
            cmdBuffer = new CommandBuffer();
            m_Cam     = Camera.main;
            m_Cam.AddCommandBuffer(CameraEvent.BeforeForwardAlpha, cmdBuffer);
            Dictionary <int, PrefabPathConfig> map = PrefabPathAsset.GetAll();

            foreach (var item in map)
            {
                Id2Path.Add(item.Key, item.Value.Path);
            }
        }