コード例 #1
0
        private static void RefreshSelection()
        {
            VoxNum    = 0;
            QbNum     = 0;
            FolderNum = 0;
            JsonNum   = 0;

            // Fix Selection
            var fixedSelection = new List <KeyValuePair <Object, string> >();

            for (int i = 0; i < Selection.objects.Length; i++)
            {
                fixedSelection.Add(new KeyValuePair <Object, string>(
                                       Selection.objects[i],
                                       AssetDatabase.GetAssetPath(Selection.objects[i]))
                                   );
            }

            for (int i = 0; i < fixedSelection.Count; i++)
            {
                if (!fixedSelection[i].Key)
                {
                    continue;
                }
                var pathI = fixedSelection[i].Value;
                for (int j = 0; j < fixedSelection.Count; j++)
                {
                    if (i == j || !fixedSelection[j].Key)
                    {
                        continue;
                    }
                    var pathJ = fixedSelection[j].Value;
                    if (Util.IsChildPathCompair(pathJ, pathI))
                    {
                        fixedSelection[j] = new KeyValuePair <Object, string>(null, null);
                    }
                }
            }

            // Get Task Map
            TaskMap.Clear();
            for (int i = 0; i < fixedSelection.Count; i++)
            {
                if (!fixedSelection[i].Key)
                {
                    continue;
                }
                var obj  = fixedSelection[i].Key;
                var path = fixedSelection[i].Value;
                path = Util.FixPath(path);
                var ex = Util.GetExtension(path);
                if (AssetDatabase.IsValidFolder(path))
                {
                    FolderNum++;
                    var files = Util.GetFilesIn(path, "*.vox", "*.qb", "*.json");
                    for (int j = 0; j < files.Length; j++)
                    {
                        var filePath = Util.FixedRelativePath(files[j].FullName);
                        var fileEx   = Util.GetExtension(filePath);
                        if (fileEx == ".vox" || fileEx == ".qb" || fileEx == ".json")
                        {
                            var fileObj = AssetDatabase.LoadAssetAtPath <Object>(filePath);
                            if (fileObj && !TaskMap.ContainsKey(fileObj))
                            {
                                TaskMap.Add(fileObj, new PathData()
                                {
                                    Path      = filePath,
                                    Extension = fileEx,
                                    Root      = Util.FixPath(filePath.Substring(
                                                                 path.Length,
                                                                 filePath.Length - path.Length - Util.GetNameWithExtension(filePath).Length
                                                                 )),
                                });

                                if (fileEx == ".vox")
                                {
                                    VoxNum++;
                                    FixVoxIcon(fileObj);
                                }
                                else if (fileEx == ".qb")
                                {
                                    QbNum++;
                                    FixQbIcon(fileObj);
                                }
                                else if (fileEx == ".json")
                                {
                                    JsonNum++;
                                    FixJsonIcon(fileObj);
                                }
                            }
                        }
                    }
                }
                else if (ex == ".vox" || ex == ".qb" || ex == ".json")
                {
                    if (!TaskMap.ContainsKey(obj))
                    {
                        TaskMap.Add(obj, new PathData()
                        {
                            Path      = path,
                            Extension = ex,
                            Root      = "",
                        });
                        if (ex == ".vox")
                        {
                            VoxNum++;
                            FixVoxIcon(obj);
                        }
                        else if (ex == ".qb")
                        {
                            QbNum++;
                            FixQbIcon(obj);
                        }
                        else if (ex == ".json")
                        {
                            JsonNum++;
                            FixJsonIcon(obj);
                        }
                    }
                }
            }

            ObjNum = Selection.objects.Length;
        }