Beispiel #1
0
        public void LoadData()
        {
            // Build TypeByModuleInfo and ModuleInfoByInput dictionaries
            TypeByModuleInfo.Clear();
            ModuleInfoByInput.Clear();
            TypeByModuleInfo = new SortedDictionary <ModuleInfoAttribute, System.Type>(DTUtility.GetTypesWithAttribute <ModuleInfoAttribute, CGModule>());

            foreach (var kv in TypeByModuleInfo)
            {
                var T      = kv.Value;
                var fields = T.GetFields(BindingFlags.Public | BindingFlags.Instance);
                foreach (var f in fields)
                {
                    if (f.FieldType == typeof(CGModuleInputSlot))
                    {
                        var slotAttrib = f.GetCustomAttributes(typeof(InputSlotInfo), true);
                        if (slotAttrib.Length > 0)
                        {
                            var si = (InputSlotInfo)slotAttrib[0];
                            List <ModuleInfoAttribute> lst;
                            for (int x = 0; x < si.DataTypes.Length; x++)
                            {
                                if (!ModuleInfoByInput.TryGetValue(si.DataTypes[x], out lst))
                                {
                                    lst = new List <ModuleInfoAttribute>();
                                    ModuleInfoByInput.Add(si.DataTypes[x], lst);
                                }

                                lst.Add(kv.Key);
                            }
                        }
                    }
                }
            }
            // load Templates
            TemplatesByMenuName.Clear();
            string[] baseFolders;
            if (AssetDatabase.IsValidFolder("Assets/" + CurvyProject.Instance.CustomizationRootPath + CurvyProject.RELPATH_CGTEMPLATES))
            {
                baseFolders = new string[2] {
                    "Assets/" + CurvyEditorUtility.GetPackagePath("CG Templates"),
                    "Assets/" + CurvyProject.Instance.CustomizationRootPath + CurvyProject.RELPATH_CGTEMPLATES
                }
            }
            ;
            else
            {
                baseFolders = new string[1] {
                    "Assets/" + CurvyEditorUtility.GetPackagePath("CG Templates")
                }
            };

            string[] prefabs = AssetDatabase.FindAssets("t:gameobject", baseFolders);

            foreach (var guid in prefabs)
            {
                var path = AssetDatabase.GUIDToAssetPath(guid);
                // Store under a unique menu name
                string name     = AssetDatabase.LoadAssetAtPath(path, typeof(Transform)).name;
                string menuPath = System.IO.Path.GetDirectoryName(path);
                foreach (var s in baseFolders)
                {
                    menuPath = menuPath.TrimStart(s);
                }
                menuPath = menuPath.TrimStart('/');

                string menuName = string.IsNullOrEmpty(menuPath) ? name : menuPath + "/" + name;
                int    i        = 0;
                while (TemplatesByMenuName.ContainsKey((i == 0) ? menuName :menuName + i.ToString()))
                {
                    i++;
                }
                TemplatesByMenuName.Add((i == 0) ? menuName : menuName + i.ToString(), path);
            }
        }