コード例 #1
0
    public override void OnInspectorGUI()
    {
        OnInspectorObjectGUI(libaryCatch.texture2ds, "texturn2ds");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.renderTextures, "renderTextures");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.movieTextures, "movieTextures");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.sprites, "sprites");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.textAssets, "textAssets");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.materials, "materials");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.prefabs, "prefabs");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.audios, "audios");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.videos, "videos");

        if (GUILayout.Button("Update"))
        {
            UpdateAsset();
        }
        if (GUILayout.Button("Clear"))
        {
            libaryCatch.Clear();
        }

        EditorGUILayout.Space();
        if (GUILayout.Button("Save"))
        {
            EditorUtility.SetDirty(target);
            serializedObject.ApplyModifiedProperties();
            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }
        OnGUIChanged();
    }
コード例 #2
0
    private void UpdateAsset()
    {
        string path = AssetDatabase.GetAssetPath(resourseSetting);
        Dictionary <string, Dictionary <string, ResourceSettingStateObj> > msgDict = resourseSetting.GetSettingMessage();
        //List<string> listRes = new List<string>(assetDict.Keys);
        List <string> ret = new List <string>();

        foreach (var item in assetDict)
        {
            if (item.Value)
            {
                string url = Application.dataPath + item.Key;//Path.Combine(Application.dataPath, item.Key);
                ret.Add(url);
                List <string> list = ResLibaryTool.GetAllSubDirs(url);
                if (list != null)
                {
                    ret.AddRange(list);
                }
            }
        }
        //for (int i = 0; i < listRes.Count; i++)
        //{
        //    List<string> list = ResLibaryTool.GetAllSubDirs(listRes[i]);
        //    if (list != null)
        //        ret.AddRange(list);
        //}
        //ret.AddRange(listRes);
        Debug.Log("ret:" + ret.Count);
        resourseSetting.Clear();
        for (int i = 0; i < ret.Count; i++)
        {
            string resDir = ret[i];
            if (string.IsNullOrEmpty(resDir) || !ResLibaryTool.DirExistResource(resDir))
            {
                continue;
            }
            string[] files = System.IO.Directory.GetFiles(resDir);
            for (int j = 0; j < files.Length; j++)
            {
                string resfile   = files[j];
                string extension = Path.GetExtension(resfile);
                if (!ResLibaryConfig.ResourceExts.Contains(extension))
                {
                    continue;
                }
                resfile = ResLibaryTool.GetAssetRelativePath(resfile);
                int index = resfile.IndexOf("Resources/", StringComparison.CurrentCultureIgnoreCase);
                if (index < 0)
                {
                    continue;
                }
                string filePath = resfile.Substring(index);
                filePath = filePath.Replace("Resources/", "");
                if (Path.HasExtension(filePath))
                {
                    filePath = filePath.Replace(extension, "");
                }
                UnityEngine.Object obj = Resources.Load(filePath);
                if (!ResLibaryConfig.ExistType.ContainsValue(obj.GetType().Name))
                {
                    continue;
                }
                if (obj.GetType().Name == ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D])
                {
                    TextureImporter textureImporter = TextureImporter.GetAtPath(resfile) as TextureImporter;
                    if (textureImporter == null)
                    {
                        continue;
                    }
                    if (textureImporter.textureType == TextureImporterType.Sprite)
                    {
                        Dictionary <string, ResourceSettingStateObj> sDict = null;
                        msgDict.TryGetValue(ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Sprite], out sDict);
                        UnityEngine.Object[] sprs = AssetDatabase.LoadAllAssetsAtPath(resfile);
                        for (int k = 0; k < sprs.Length; k++)
                        {
                            ResourceSettingStateObj settingStateObjs = new ResourceSettingStateObj();
                            settingStateObjs.m_Name = sprs[k].name;
                            settingStateObjs.m_Path = filePath + "/" + sprs[k].name;
                            settingStateObjs.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Sprite];
                            if (sprs[k].GetType().Name == ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Sprite])
                            {
                                if (sDict != null && sDict.ContainsKey(sprs[k].name))
                                {
                                    resourseSetting.AddResToLibary(sDict[sprs[k].name]);
                                    continue;
                                }
                                resourseSetting.AddResToLibary(settingStateObjs);
                            }
                            else
                            {
                                Dictionary <string, ResourceSettingStateObj> sDictT = null;
                                msgDict.TryGetValue(ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D], out sDictT);
                                if (sDictT != null && sDictT.ContainsKey(sprs[k].name))
                                {
                                    resourseSetting.AddResToLibary(sDictT[sprs[k].name]);
                                    continue;
                                }
                                settingStateObjs.m_Path = filePath;
                                settingStateObjs.m_Type = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D];
                                resourseSetting.AddResToLibary(settingStateObjs);
                            }
                        }
                    }
                    else
                    {
                        Dictionary <string, ResourceSettingStateObj> sDict = null;
                        msgDict.TryGetValue(ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D], out sDict);
                        if (sDict != null && sDict.ContainsKey(obj.name))
                        {
                            resourseSetting.AddResToLibary(sDict[obj.name]);
                            continue;
                        }
                        ResourceSettingStateObj settingStateObj = new ResourceSettingStateObj();
                        settingStateObj.m_Name        = obj.name;
                        settingStateObj.m_Path        = filePath;
                        settingStateObj.m_Type        = obj.GetType().Name;
                        settingStateObj.m_ExistStatus = AssetExistStatusEnum.Scene;
                        resourseSetting.AddResToLibary(settingStateObj);
                    }
                }
                else
                {
                    Dictionary <string, ResourceSettingStateObj> sDict = null;
                    msgDict.TryGetValue(obj.GetType().Name, out sDict);
                    if (sDict != null && sDict.ContainsKey(obj.name))
                    {
                        resourseSetting.AddResToLibary(sDict[obj.name]);
                        continue;
                    }
                    ResourceSettingStateObj settingStateObj = new ResourceSettingStateObj();
                    settingStateObj.m_Name        = obj.name;
                    settingStateObj.m_Path        = filePath;
                    settingStateObj.m_Type        = obj.GetType().Name;
                    settingStateObj.m_ExistStatus = AssetExistStatusEnum.Scene;
                    resourseSetting.AddResToLibary(settingStateObj);
                }
            }
        }
        AssetDatabase.ImportAsset(path);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }