public float GetPopularity(ScreenshotResolutionAsset preset) { var s = m_Stats.Find(x => x.m_Resolution == preset); if (s != null) { return(s.m_Frequency); } return(-1f); }
public static void ExportPresets(List <ScreenshotResolution> resolutions) { foreach (ScreenshotResolution res in resolutions) { string name = res.m_ResolutionName == "" ? res.m_Width.ToString() + "x" + res.m_Height.ToString() : res.m_ResolutionName; ScreenshotResolutionAsset preset = ScriptableObjectUtils.CreateAsset <ScreenshotResolutionAsset> (name, "Presets/Custom"); preset.m_Resolution = new ScreenshotResolution(res); EditorUtility.SetDirty(preset); } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public static void RemoveTag(ScreenshotResolutionAsset preset, string tag) { if (GetDatabase().m_Database.ContainsKey(tag)) { // Remove tag from list GetDatabase().m_Database[tag].m_Data.Remove(preset); // Remove tag if no preset have it GetDatabase().RemoveEmptyTags(); // Update database EditorUtility.SetDirty(GetDatabase()); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
public static string GetTagString(ScreenshotResolutionAsset preset) { var tags = GetTags(preset); var s = ""; for (int i = 0; i < tags.Count; ++i) { s += tags[i]; if (i != tags.Count - 1) { s += ", "; } } return(s); }
public static void AddTag(ScreenshotResolutionAsset preset, string tag) { // Create empty list for a new tag if (!GetDatabase().m_Database.ContainsKey(tag)) { GetDatabase().m_Database.Add(tag, new TagData()); } // Add tag to list GetDatabase().m_Database[tag].m_Data.Add(preset); // Remove tag if no preset have it GetDatabase().RemoveEmptyTags(); // Update database EditorUtility.SetDirty(GetDatabase()); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
public static string ParseCategory(ScreenshotResolutionAsset asset) { var cat = AssetDatabase.GetAssetPath(asset); int s = cat.LastIndexOf("/"); if (cat.Contains("Resources/")) { int r = cat.LastIndexOf("Resources/"); cat = cat.Substring(r, s - r); } if (cat.Contains("Presets/")) { int p = cat.LastIndexOf("Presets/"); cat = cat.Substring(p, s - p); } cat = cat.Replace("Presets/", ""); cat = cat.Replace("Resources/", ""); return(cat); }
public static void ExportAsCollection(List <ScreenshotResolution> resolutions) { Debug.Log("Creating new custom collection"); var collection = AssetUtils.Create <PresetCollectionAsset>("Custom collection", "Assets/Editor/DevicePresets/"); var presets = AssetUtils.LoadAll <ScreenshotResolutionAsset>(); foreach (var res in resolutions) { ScreenshotResolutionAsset preset = presets.Find(x => (((x.name == res.m_ResolutionName) || (x.name == "Custom " + res.m_ResolutionName)) && x.m_Resolution.m_Width == res.m_Width && x.m_Resolution.m_Height == res.m_Height && x.m_Resolution.m_Scale == res.m_Scale // && x.m_Resolution.m_Orientation == res.m_Orientation && x.m_Resolution.m_SafeAreaPortrait == res.m_SafeAreaPortrait && x.m_Resolution.m_SafeAreaLandscapeLeft == res.m_SafeAreaLandscapeLeft && x.m_Resolution.m_PPI == res.m_PPI && x.m_Resolution.m_ForcedUnityPPI == res.m_ForcedUnityPPI && x.m_Resolution.m_Platform == res.m_Platform && x.m_Resolution.m_DeviceCanvas == res.m_DeviceCanvas)); // If preset does not exist or was changed, create a new custom preset if (preset == null) { Debug.Log("No identical preset found for " + res.m_ResolutionName + ", creating a new custom preset."); preset = AssetUtils.Create <ScreenshotResolutionAsset>(res.m_ResolutionName, "Assets/Editor/DevicePresets/CustomDevices/"); preset.m_Resolution = new ScreenshotResolution(res); preset.m_Resolution.m_Category = "Custom"; EditorUtility.SetDirty(preset); } collection.m_Presets.Add(preset); } EditorUtility.SetDirty(collection); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Selection.activeObject = collection; }
void AddDevice(ScreenshotResolutionAsset preset) { // Create a new instance of the preset resolution m_Config.m_Resolutions.Add(new ScreenshotResolution(preset.m_Resolution)); }
void DrawDeviceItem(ScreenshotResolutionAsset preset) { if (preset == null) { return; } EditorGUILayout.BeginHorizontal(GUILayout.Height(20)); // BUTTONS if (GUILayout.Button("Add", GUILayout.Width(35))) { AddDevice(preset); } if (GUILayout.Button("Select", GUILayout.Width(45))) { Selection.activeObject = preset; } // Bold if already in list var style = EditorStyles.label; if (m_Config.m_Resolutions.Where(x => preset.name == x.m_ResolutionName).ToList().Count > 0) { style = EditorStyles.boldLabel; } // Popularity if popularity selection if (m_SelectedPopularityCollection != null) { float frequency = m_SelectedPopularityCollection.GetPopularity(preset); string fs = ""; if (frequency > 0f) { fs = frequency.ToString() + "%"; } EditorGUILayout.LabelField(fs, style, GUILayout.Width(50)); } // Device name EditorGUILayout.LabelField(preset.name, style, GUILayout.Width(200)); if (m_ShowDetailedDevice) { EditorGUILayout.LabelField(preset.m_Resolution.m_Platform, style, GUILayout.Width(70)); } EditorGUILayout.LabelField("" + preset.m_Resolution.m_Width + "x" + preset.m_Resolution.m_Height, style, GUILayout.Width(75)); if (m_ShowDetailedDevice) { EditorGUILayout.LabelField(preset.m_Resolution.m_PPI > 0 ? preset.m_Resolution.m_PPI.ToString() : "", style, GUILayout.Width(30)); } EditorGUILayout.LabelField(preset.m_Resolution.m_Ratio, style, GUILayout.Width(50)); if (m_ShowDetailedDevice) { EditorGUILayout.LabelField(preset.m_Resolution.m_SafeAreaPortrait == Rect.zero ? " " : "X", EditorStyles.centeredGreyMiniLabel, GUILayout.Width(50)); EditorGUILayout.LabelField(preset.m_Resolution.m_DeviceCanvas == null ? " " : "X", EditorStyles.centeredGreyMiniLabel, GUILayout.Width(35)); } EditorGUILayout.LabelField(TagDatabaseAsset.GetTagString(preset), style, GUILayout.MinWidth(50)); EditorGUILayout.LabelField(preset.m_Resolution.m_Category, style, GUILayout.MinWidth(70)); EditorGUILayout.EndHorizontal(); }
public static List <string> GetTags(ScreenshotResolutionAsset preset) { return(GetDatabase().m_Database.keys.Where(x => GetDatabase().m_Database.ContainsKey(x) && GetDatabase().m_Database[x].m_Data.Contains(preset)).ToList()); }
public bool Contains(ScreenshotResolutionAsset preset) { return(m_Stats.Find(x => x.m_Resolution == preset) != null); }