private string GetBrushDropdownName(GridBrushBase brush) { string result; if (!GridPaletteBrushes.IsLibraryBrush(brush)) { result = brush.name; } else { CustomGridBrushAttribute[] array = brush.GetType().GetCustomAttributes(typeof(CustomGridBrushAttribute), false) as CustomGridBrushAttribute[]; if (array != null && array.Length > 0 && array[0].defaultName.Length > 0) { result = array[0].defaultName; } else if (brush.GetType() == typeof(GridBrush)) { result = "Default Brush"; } else { result = brush.GetType().Name; } } return(result); }
private void RefreshBrushesCache() { if (this.m_Brushes == null) { this.m_Brushes = new List <GridBrushBase>(); } if (this.m_Brushes.Count == 0 || !(this.m_Brushes[0] is GridBrush)) { Type defaultBrushType = GridPaletteBrushes.GetDefaultBrushType(); GridBrushBase item = this.LoadOrCreateLibraryGridBrushAsset(defaultBrushType); this.m_Brushes.Insert(0, item); this.m_Brushes[0].name = this.GetBrushDropdownName(this.m_Brushes[0]); } Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies; Assembly[] array = loadedAssemblies; for (int i = 0; i < array.Length; i++) { Assembly assembly = array[i]; try { IEnumerable <Type> enumerable = from t in assembly.GetTypes() where t != typeof(GridBrushBase) && t != typeof(GridBrush) && typeof(GridBrushBase).IsAssignableFrom(t) select t; foreach (Type current in enumerable) { if (this.IsDefaultInstanceVisibleGridBrushType(current)) { GridBrushBase gridBrushBase = this.LoadOrCreateLibraryGridBrushAsset(current); if (gridBrushBase != null) { this.m_Brushes.Add(gridBrushBase); } } } } catch (Exception ex) { Debug.Log(string.Format("TilePalette failed to get types from {0}. Error: {1}", assembly.FullName, ex.Message)); } } string[] array2 = AssetDatabase.FindAssets("t:GridBrushBase"); string[] array3 = array2; for (int j = 0; j < array3.Length; j++) { string guid = array3[j]; string assetPath = AssetDatabase.GUIDToAssetPath(guid); GridBrushBase gridBrushBase2 = AssetDatabase.LoadAssetAtPath(assetPath, typeof(GridBrushBase)) as GridBrushBase; if (gridBrushBase2 != null && this.IsAssetVisibleGridBrushType(gridBrushBase2.GetType())) { this.m_Brushes.Add(gridBrushBase2); } } this.m_BrushNames = new string[this.m_Brushes.Count]; for (int k = 0; k < this.m_Brushes.Count; k++) { this.m_BrushNames[k] = this.m_Brushes[k].name; } }
private void SaveLibraryGridBrushAsset(GridBrushBase brush) { var gridBrushPath = GenerateGridBrushInstanceLibraryPath(brush.GetType()); string folderPath = Path.GetDirectoryName(gridBrushPath); if (!Directory.Exists(folderPath)) { Directory.CreateDirectory(folderPath); } InternalEditorUtility.SaveToSerializedFileAndForget(new[] { brush }, gridBrushPath, true); }
private string GetBrushDropdownName(GridBrushBase brush) { // Asset Brushes use the asset name if (!IsLibraryBrush(brush)) { return(brush.name); } // Library Brushes CustomGridBrushAttribute[] customBrushes = brush.GetType().GetCustomAttributes(typeof(CustomGridBrushAttribute), false) as CustomGridBrushAttribute[]; if (customBrushes != null && customBrushes.Length > 0 && customBrushes[0].defaultName.Length > 0) { return(customBrushes[0].defaultName); } if (brush.GetType() == typeof(GridBrush)) { return("Default Brush"); } return(brush.GetType().Name); }
private GridBrushBase LoadOrCreateLibraryGridBrushAsset(Type brushType) { var serializedObjects = InternalEditorUtility.LoadSerializedFileAndForget(GenerateGridBrushInstanceLibraryPath(brushType)); if (serializedObjects != null && serializedObjects.Length > 0) { GridBrushBase brush = serializedObjects[0] as GridBrushBase; if (brush != null && brush.GetType() == brushType) { return(brush); } } return(CreateLibraryGridBrushAsset(brushType)); }
private void SaveLibraryGridBrushAsset(GridBrushBase brush) { string path = this.GenerateGridBrushInstanceLibraryPath(brush.GetType()); string directoryName = Path.GetDirectoryName(path); if (!Directory.Exists(directoryName)) { Directory.CreateDirectory(directoryName); } InternalEditorUtility.SaveToSerializedFileAndForget(new GridBrushBase[] { brush }, path, true); }
private GridBrushBase LoadOrCreateLibraryGridBrushAsset(Type brushType) { UnityEngine.Object[] array = InternalEditorUtility.LoadSerializedFileAndForget(this.GenerateGridBrushInstanceLibraryPath(brushType)); GridBrushBase result; if (array != null && array.Length > 0) { GridBrushBase gridBrushBase = array[0] as GridBrushBase; if (gridBrushBase != null && gridBrushBase.GetType() == brushType) { result = gridBrushBase; return(result); } } result = this.CreateLibraryGridBrushAsset(brushType); return(result); }