예제 #1
0
        public static List <BundleInfo> BuildAllName()
        {
            Stack <string> searchStack = new Stack <string>()
            {
            };

            searchStack.Push(RootPath);
            Debug.Log(RootPath);

            List <BundleInfo> list = new List <BundleInfo>();

            while (searchStack.Count > 0)
            {
                string headPath = searchStack.Pop();

                string relativelyPath =
                    headPath.Length == RootPath.Length ? "" : headPath.Substring(RootPath.Length + 1);

                Debug.Log(relativelyPath);
                foreach (var VARIABLE in Directory.GetFiles(headPath))
                {
                    if (VARIABLE.EndsWith(".meta"))
                    {
                        string path = VARIABLE.Substring(0, VARIABLE.Length - 5);

                        if (Directory.Exists(path))
                        {
                            searchStack.Push(path);
                        }
                        else
                        {
                            BundleInfo info = new BundleInfo();
                            info.Path = relativelyPath;
                            string fileName = Path.GetFileName(path);
//                            Debug.Log("fileName:"+fileName);

                            string[] prefabBundleName = fileName.Split('.');
                            //资源的bundleName
                            string bundleName = relativelyPath + "/" + prefabBundleName[0];

                            string variant = prefabBundleName[1];
                            info.Variant = variant;
                            info.Name    = bundleName;
                            list.Add(info);
                        }
                    }
                }
            }


            for (int i = 0; i < list.Count; i += 1)
            {
                Debug.Log(list[i]);
            }

            Debug.Log(Directory.Exists(RootPath));

            return(list);
        }
예제 #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var indexProp = property.FindPropertyRelative("selectedIndex");
            var nowPath   = property.FindPropertyRelative("Path");
            var paths     = new List <string>();

            var resPath = Application.dataPath + "/Resources";

            if (!Directory.Exists(resPath))
            {
                Directory.CreateDirectory(resPath);
                AssetDatabase.Refresh();
            }

            Search(resPath, paths);
            if (paths.Count == 0)
            {
                EditorGUI.HelpBox(position, "现在Resources目录为空", MessageType.Error);
                return;
            }
            else if (indexProp.intValue >= paths.Count)
            {
                Debug.LogError("路径索引越界,路径已经重置,请重新选择路径" + property.serializedObject.targetObject.name);
                indexProp.intValue = 0;
            }
            EditorGUI.BeginChangeCheck();

            indexProp.intValue = EditorGUI.Popup(position, property.displayName, indexProp.intValue, paths.ToArray());

            var changed = EditorGUI.EndChangeCheck();

            if (string.IsNullOrEmpty(nowPath.stringValue))
            {
                nowPath.stringValue = paths[indexProp.intValue];
            }
            else
            {
                if (nowPath.stringValue != paths[indexProp.intValue])
                {
                    if (changed)
                    {
                        //主动修改
                        nowPath.stringValue = paths[indexProp.intValue];
                    }
                    else
                    {
                        //如果原先路径和当前路径不同
                        var currentName = nowPath.stringValue;
                        if (currentName.Contains("/"))
                        {
                            var select = currentName.LastIndexOf('/') + 1;
                            currentName = currentName.Substring(select, currentName.Length - select);
                        }

                        var index = 0;
                        foreach (var VARIABLE in paths)
                        {
                            //找到新路径
                            if (VARIABLE.EndsWith(currentName))
                            {
                                indexProp.intValue  = index;
                                nowPath.stringValue = VARIABLE;
                                Debug.Log("重新找到!");
                                return;
                            }

                            index++;
                        }
                        Debug.LogError("路径丢失,没有找到!错误路径:" + nowPath.stringValue);
                    }
                }
            }
        }
예제 #3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var indexProp = property.FindPropertyRelative("selectedIndex");
            var goProp    = property.FindPropertyRelative("go");
            var obj       = goProp.objectReferenceValue as GameObject;
            var nowPath   = property.FindPropertyRelative("path");
            var paths     = new List <string>();

            EditorGUI.LabelField(position.GetLeft(TransformPathChooser.LabelWidth), property.displayName);
            goProp.objectReferenceValue = EditorGUI.ObjectField(
                position.GetLeft(TransformPathChooser.LabelWidth + TransformPathChooser.ObjectFidldWidth,
                                 TransformPathChooser.LabelWidth + 0.015f), goProp.objectReferenceValue, typeof(GameObject), false);
            var enumWidth = 1 - TransformPathChooser.LabelWidth - TransformPathChooser.ObjectFidldWidth;

            if (obj == null)
            {
                EditorGUI.HelpBox(position.GetRight(enumWidth), "请选择预制体", MessageType.Error);
                return;
            }

            Search(obj.transform, paths, "");


            if (paths.Count == 0)
            {
                EditorGUI.HelpBox(position.GetRight(enumWidth), "此物体没有子物体", MessageType.Error);
                return;
            }


            if (indexProp.intValue >= paths.Count)
            {
                Debug.LogError("路径索引越界,路径已经重置,请重新选择路径" + property.serializedObject.targetObject.name);
                indexProp.intValue = 0;
            }

            EditorGUI.BeginChangeCheck();

            indexProp.intValue = EditorGUI.Popup(position.GetRight(enumWidth), indexProp.intValue, paths.ToArray());

            var changed = EditorGUI.EndChangeCheck();

            if (string.IsNullOrEmpty(nowPath.stringValue))
            {
                nowPath.stringValue = paths[indexProp.intValue];
            }
            else
            {
                if (nowPath.stringValue != paths[indexProp.intValue])
                {
                    if (changed)
                    {
                        //主动修改
                        nowPath.stringValue = paths[indexProp.intValue];
                    }
                    else
                    {
                        //如果原先路径和当前路径不同
                        var currentName = nowPath.stringValue;
                        if (currentName.Contains("/"))
                        {
                            var select = currentName.LastIndexOf('/') + 1;
                            currentName = currentName.Substring(select, currentName.Length - select);
                        }

                        var index = 0;
                        foreach (var VARIABLE in paths)
                        {
                            //找到新路径
                            if (VARIABLE.EndsWith(currentName))
                            {
                                indexProp.intValue  = index;
                                nowPath.stringValue = VARIABLE;
                                Debug.Log("重新找到!");
                                return;
                            }

                            index++;
                        }

                        Debug.LogError("路径丢失,没有找到!错误路径:" + nowPath.stringValue);
                    }
                }
            }
        }