Beispiel #1
0
    public override void OnInspectorGUI()
    {
        OnInspectorObjectGUI(libaryCatch.texture2ds, "texturn2ds");
        EditorGUILayout.Space();

        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.textAssets, "textAssets");
        EditorGUILayout.Space();
        OnInspectorObjectGUI(libaryCatch.sprites, "sprites");
        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();
    }
Beispiel #2
0
    private void ResourcesList()
    {
        LibaryStreamingAssetSetting _resourseSetting = Resources.Load <LibaryStreamingAssetSetting>("StreamingAssetLibarySetting");

        if (_resourseSetting == null)
        {
            return;
        }
        string path = AssetDatabase.GetAssetPath(_resourseSetting);
        LibaryStreamingAssetSetting resourseSetting = AssetDatabase.LoadAssetAtPath <LibaryStreamingAssetSetting>(path);
        Dictionary <string, Dictionary <string, ResourceSettingStateObj> > msgDict = resourseSetting.GetSettingMessage();

        resourseSetting.Clear();
        List <string> listRes = ResLibaryTool.GetAllLocalStreamingAssetsDirs(Application.dataPath);
        List <string> ret     = new List <string>();

        for (int i = 0; i < listRes.Count; i++)
        {
            List <string> list = ResLibaryTool.GetAllSubDirs(listRes[i]);
            if (list != null)
            {
                ret.AddRange(list);
            }
        }
        ret.AddRange(listRes);
        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);
                string typeName  = null;
                resfile = resfile.Replace("\\", "/");
                int index = resfile.IndexOf("StreamingAssets/", StringComparison.CurrentCultureIgnoreCase);
                if (index < 0)
                {
                    continue;
                }
                string filePath = resfile.Substring(index);
                filePath = filePath.Replace("StreamingAssets/", "");
                string fileName = Path.GetFileNameWithoutExtension(resfile);
                if (ResLibaryConfig.ResourceImgExts.Contains(extension))
                {
                    typeName = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Texture2D];
                    ResourceSettingStateObj resourceSettingStateObjs = new ResourceSettingStateObj();
                    resourceSettingStateObjs.m_Name        = fileName;
                    resourceSettingStateObjs.m_Path        = filePath;
                    resourceSettingStateObjs.m_Type        = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_Sprite];
                    resourceSettingStateObjs.m_ExistStatus = AssetExistStatusEnum.Quote;
                    resourseSetting.AddResToLibary(resourceSettingStateObjs);
                }
                else if (ResLibaryConfig.ResourceTxtExts.Contains(extension))
                {
                    typeName = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_TextAsset];
                }
                else if (ResLibaryConfig.ResourceAudioExts.Contains(extension))
                {
                    typeName = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_AudioClip];
                }
                else if (ResLibaryConfig.ResourceVideoExts.Contains(extension))
                {
                    typeName = ResLibaryConfig.ExistType[LibaryTypeEnum.LibaryType_VideoClip];
                }
                else
                {
                    continue;
                }


                Dictionary <string, ResourceSettingStateObj> sDict = null;
                msgDict.TryGetValue(typeName, out sDict);
                if (sDict != null && sDict.ContainsKey(fileName))
                {
                    resourseSetting.AddResToLibary(sDict[fileName]);
                    continue;
                }
                ResourceSettingStateObj resourceSettingStateObj = new ResourceSettingStateObj();
                resourceSettingStateObj.m_Name        = fileName;
                resourceSettingStateObj.m_Path        = filePath;
                resourceSettingStateObj.m_Type        = typeName;
                resourceSettingStateObj.m_ExistStatus = AssetExistStatusEnum.Quote;
                resourseSetting.AddResToLibary(resourceSettingStateObj);
            }
        }
        AssetDatabase.ImportAsset(path);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }