Exemplo n.º 1
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            // Load the raw file.
            var file = PAFile.Load(ctx.assetPath);

            var texture = new Texture2D(64, 64, TextureFormat.RGBA32, false);

            texture.filterMode = FilterMode.Point;
            texture.name       = "atlas";

            var textures = file.frames.Select(f => file.RenderFrame(f)).ToArray();
            var rects    = texture.PackTextures(textures, 1).Select(r => new Rect(r.xMin * texture.width, r.yMin * texture.height, r.width * texture.width, r.height * texture.height)).ToArray();

            texture.Apply();

            // TODO: look for duplicates by checking imageContentsHash for all textures


            var sprites = new Dictionary <string, Sprite>();

            for (int frameIndex = 0; frameIndex < file.frames.Count; frameIndex++)
            {
                var frame  = file.frames[frameIndex];
                var sprite = Sprite.Create(texture, rects[frameIndex], new Vector2(0.5f, 0.5f));
                sprite.name = $"{frame.animation.name}.{frame.order:D03}";
                ctx.AddObjectToAsset(frame.id, sprite);
                sprites[frame.id] = sprite;
            }

            ctx.AddObjectToAsset("_atlas", texture);

            var pixelArt = PixelArt.Create(
                file.animations.Select(a => new PixelArtAnimation(
                                           a.name,
                                           file.frames.Where(f => f.animation == a).OrderBy(f => f.order).Select(f => new PixelArtAnimationFrame {
                sprite = sprites[f.id]
            }).ToArray()
                                           )).ToArray(),
                defaultAnimationIndex);

            var defaultFrame = file.frames.Where(f => f.animation == file.animations[defaultAnimationIndex]).OrderBy(f => f.order).First();

#if false
            var go = new GameObject();
            var sr = go.AddComponent <SpriteRenderer>();
            sr.sprite = sprites[defaultFrame.id];;
            go.name   = "Prefab";
            var animator = go.AddComponent <PixelArtAnimator>();
            animator.PixelArt = pixelArt;
            animator.layers   = new SpriteRenderer[] { sr };

            ctx.AddObjectToAsset("prefab", go, PAUtils.LoadImage("PixelArtIcon.psd"));
#endif

            pixelArt.name = "PixelArt";
            ctx.AddObjectToAsset("pixelArt", pixelArt, PAUtils.LoadImage("PixelArtIcon.psd"));

            //ctx.AddObjectToAsset("main", pixelArt, file.RenderFrame(file.frames[0]));
            ctx.SetMainObject(pixelArt);
        }
Exemplo n.º 2
0
        public PASelectionTool(PACanvas canvas) : base(canvas)
        {
            // Must move 1 pixel before drawing begins
            DrawThreshold = 1.0f;

            _cursor = PAUtils.LoadCursor("Crosshair.psd");
        }
        public static void AddStyleSheetPath(this VisualElement visualElement, string path)
        {
            var sheet = PAUtils.LoadStyleSheet(path);

            if (sheet != null)
            {
                visualElement.styleSheets.Add(sheet);
            }
        }
Exemplo n.º 4
0
        public PAImageView(PACanvas canvas)
        {
            AddToClassList("canvas");

            pickingMode = PickingMode.Ignore;

            _canvas     = canvas;
            _background = PAUtils.LoadImage("Grid.psd");

            generateVisualContent += OnGenerateVisualContent;
        }
Exemplo n.º 5
0
        private static void CreatePixelArt(int width, int height)
        {
            // Generate a unique filename for the new artwork
            var filename = Path.Combine(
                Application.dataPath,
                AssetDatabase.GenerateUniqueAssetPath($"{PAUtils.GetSelectedPathOrFallback()}/New PixelArt.pixelart").Substring(7));

            // Create an empty file
            var file = new PAFile();

            file.width  = width;
            file.height = height;
            file.AddFrame(file.AddAnimation("New Animation"));
            file.AddLayer();
            file.Save(filename);

            AssetDatabase.Refresh();
        }
Exemplo n.º 6
0
        public PALayerItem(PACanvas canvas, PALayer layer)
        {
            _canvas    = canvas;
            Layer      = layer;
            Layer.Item = this;

            pickingMode = PickingMode.Position;
            focusable   = true;
            AddToClassList("layer");

            Add(PAUtils.CreateIconToggle("LayerVisibilityToggle", "Toggle layer visibility", OnVisibilityChanged));

            _preview = new Image()
            {
                name = "Preview"
            };
            Add(_preview);

            Add(new Label(layer.name));
        }
Exemplo n.º 7
0
 public PAEyeDropperTool(PACanvas canvas) : base(canvas)
 {
     _cursor = PAUtils.LoadCursor("EyeDropper.psd");
 }
Exemplo n.º 8
0
 public PAPencilTool(PACanvas canvas) : base(canvas)
 {
     _cursor = PAUtils.LoadCursor("Pencil.psd");
 }
Exemplo n.º 9
0
 public PAEraserTool(PACanvas canvas) : base(canvas)
 {
     _cursor = PAUtils.LoadCursor("Crosshair.psd");
 }
Exemplo n.º 10
0
 /// <summary>
 /// Set the window title with with the pixel art icon
 /// </summary>
 public void RefreshTitle() =>
 titleContent = new GUIContent(
     Workspace == null ? "PixelArt" : $"{Workspace.Target.name}{(Workspace.IsModified ? "*" : "")}",
     PAUtils.LoadImage("PixelArtEditor.psd"));