Ejemplo n.º 1
0
        public void LoadBrushes()
        {
            // Load the textures;
            var arr    = new List <Brush>();
            var hashes = new List <Hash128>();

            int       idx   = 1;
            Texture2D t     = null;
            Brush     brush = null;

            // Load builtin brushes from editor resources
            do
            {
                brush = (Brush)EditorGUIUtility.Load(EditorResources.brushesPath + "builtin_brush_" + idx + ".brush");
                if (brush != null && brush.m_Mask != null)
                {
                    brush.readOnly = true;
                    arr.Add(brush);
                    hashes.Add(brush.thumbnail.imageContentsHash);
                }

                idx++;
            }while (brush);

            // Load user created brushes from the Assets/Gizmos folder
            idx = 0;
            do
            {
                t = EditorGUIUtility.FindTexture("brush_" + idx + ".png");
                if (t)
                {
                    Brush b = Brush.CreateInstance(t, AnimationCurve.Constant(0, 1, 1), Brush.kMaxRadiusScale, true);
                    arr.Add(b);
                    hashes.Add(b.thumbnail.imageContentsHash);
                }
                idx++;
            }while (t);

            // Load .brush files
            foreach (string assetPath in AssetDatabase.FindAssets($"t:{typeof(Brush).Name}"))
            {
                var b = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(assetPath), typeof(Brush)) as Brush;
                if (b != null && b.texture != null)
                {
                    arr.Add(b);
                    hashes.Add(b.thumbnail.imageContentsHash);
                }
            }

            m_BrushList   = arr.ToArray();
            m_BrushHashes = hashes.ToArray();
        }
Ejemplo n.º 2
0
        internal void CreateBrush()
        {
            ObjectSelector.get.Show(null, typeof(Texture2D), null, false, null,
                                    selection =>
            {
                if (selection == null)
                {
                    return;
                }

                var brushName = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(ProjectWindowUtil.GetActiveFolderPath(), "NewBrush.brush"));
                var newBrush  = Brush.CreateInstance((Texture2D)selection, AnimationCurve.Linear(0, 0, 1, 1), Brush.kMaxRadiusScale, false);
                AssetDatabase.CreateAsset(newBrush, brushName);
                LoadBrushes();
            }, null);
        }
Ejemplo n.º 3
0
        public void LoadBrushes()
        {
            // Load the textures;
            var       arr   = new List <Brush>();
            int       idx   = 1;
            Texture2D t     = null;
            Brush     brush = null;

            // Load builtin brushes from editor resources
            do
            {
                brush = (Brush)EditorGUIUtility.Load(EditorResources.brushesPath + "builtin_brush_" + idx + ".brush");
                if (brush != null && brush.m_Mask != null)
                {
                    brush.readOnly = true;
                    arr.Add(brush);
                }

                idx++;
            }while (brush);

            // Load user created brushes from the Assets/Gizmos folder
            idx = 0;
            do
            {
                t = EditorGUIUtility.FindTexture("brush_" + idx + ".png");
                if (t)
                {
                    arr.Add(Brush.CreateInstance(t, AnimationCurve.Constant(0, 1, 1), Brush.kMaxRadiusScale, true));
                }
                idx++;
            }while (t);

            // Load .brush files
            arr.AddRange(
                AssetDatabase.FindAssets($"t:{typeof(Brush).Name}")
                .Select(p => AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(p), typeof(Brush)) as Brush)
                .Where(b => b != null && b.texture != null)
                );

            m_BrushList = arr.ToArray();
        }