public FileStateObj(ResourceSettingStateObj stateObj) { this.m_Name = stateObj.m_Name; this.m_Path = stateObj.m_Path; this.m_Type = stateObj.m_Type; this.m_ExistStatus = stateObj.m_ExistStatus; }
public override void DelResToLibary(ResourceSettingStateObj resourceSetting) { LibaryTypeEnum libaryStatusEnum; if (!ResLibaryConfig.ExistTypeNameToEnum.TryGetValue(resourceSetting.m_Type, out libaryStatusEnum)) { return; } switch (libaryStatusEnum) { case LibaryTypeEnum.LibaryType_RenderTexture: if (renderTextures == null) { renderTextures = new List <ResourceSettingStateObj>(); } if (renderTextures.Contains(resourceSetting)) { renderTextures.Remove(resourceSetting); } break; case LibaryTypeEnum.LibaryType_MovieTexture: if (movieTextures == null) { movieTextures = new List <ResourceSettingStateObj>(); } if (movieTextures.Contains(resourceSetting)) { movieTextures.Remove(resourceSetting); } break; case LibaryTypeEnum.LibaryType_Material: if (materials == null) { materials = new List <ResourceSettingStateObj>(); } if (materials.Contains(resourceSetting)) { materials.Remove(resourceSetting); } break; case LibaryTypeEnum.LibaryType_GameObject: if (prefabs == null) { prefabs = new List <ResourceSettingStateObj>(); } if (prefabs.Contains(resourceSetting)) { prefabs.Remove(resourceSetting); } break; default: base.DelResToLibary(resourceSetting); break; } }
private void OnInspectorObjectGUI(List <ResourceSettingStateObj> list, string label) { if (!showDict.ContainsKey(label)) { showDict[label] = 0; } float wid = EditorGUIUtility.currentViewWidth; EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(label, GUILayout.MaxWidth(wid / 3)); string CountInfor = "0"; if (list != null) { CountInfor = list.Count.ToString(); } EditorGUILayout.LabelField("Count:" + CountInfor, GUILayout.MaxWidth(wid / 3)); int isShow = showDict[label]; isShow = EditorGUILayout.Popup(isShow, showPopup, GUILayout.MaxWidth(wid / 3)); showDict[label] = isShow; EditorGUILayout.EndHorizontal(); if (isShow == 0) { return; } if (list == null) { return; } for (int i = 0; i < list.Count; i++) { ResourceSettingStateObj settingStateObj = list[i]; EditorGUILayout.BeginHorizontal(); //float wid = EditorGUIUtility.currentViewWidth; EditorGUILayout.LabelField(settingStateObj.m_Name, GUILayout.Width(wid / 3)); EditorGUILayout.LabelField(settingStateObj.m_Path, GUILayout.Width(wid / 3)); settingStateObj.m_ExistStatus = (AssetExistStatusEnum)EditorGUILayout.EnumPopup(settingStateObj.m_ExistStatus, GUILayout.Width(wid / 3)); EditorGUILayout.EndHorizontal(); } }
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(); }
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(); }
public virtual void AddResToLibary(ResourceSettingStateObj resourceSetting) { LibaryTypeEnum libaryStatusEnum; if (!ResLibaryConfig.ExistTypeNameToEnum.TryGetValue(resourceSetting.m_Type, out libaryStatusEnum)) { return; } switch (libaryStatusEnum) { case LibaryTypeEnum.LibaryType_Texture2D: if (texture2ds == null) { texture2ds = new List <ResourceSettingStateObj>(); } if (!texture2ds.Contains(resourceSetting)) { texture2ds.Add(resourceSetting); } break; case LibaryTypeEnum.LibaryType_TextAsset: if (textAssets == null) { textAssets = new List <ResourceSettingStateObj>(); } if (!textAssets.Contains(resourceSetting)) { textAssets.Add(resourceSetting); } break; case LibaryTypeEnum.LibaryType_Sprite: if (sprites == null) { sprites = new List <ResourceSettingStateObj>(); } if (!sprites.Contains(resourceSetting)) { sprites.Add(resourceSetting); } break; case LibaryTypeEnum.LibaryType_AudioClip: if (audios == null) { audios = new List <ResourceSettingStateObj>(); } if (!audios.Contains(resourceSetting)) { audios.Add(resourceSetting); } break; case LibaryTypeEnum.LibaryType_VideoClip: if (videos == null) { videos = new List <ResourceSettingStateObj>(); } if (!videos.Contains(resourceSetting)) { videos.Add(resourceSetting); } break; } }
public ResourceStateObj(ResourceSettingStateObj stateObj) { this.m_Name = stateObj.m_Name; this.m_Path = stateObj.m_Path; this.m_Type = stateObj.m_Type; }