Beispiel #1
0
        public void Draw()
        {
            if (editorDisplayScale <= 1.0f)
            {
                editorDisplayScale = 1.0f;
            }
            GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            TextureGrid.Draw(rect);

            int heightOffset = 50;

            Handles.color = new Color(1, 1, 0, 0.5f);
            Handles.DrawLine(new Vector2(rect.x + 10, rect.center.y + heightOffset), new Vector2(rect.x + rect.width - 10, rect.center.y + heightOffset));
            Handles.DrawLine(new Vector2(rect.center.x, rect.y + 10), new Vector2(rect.center.x, rect.y + rect.height - 10));

            if (CurTexture != null)
            {
                // middle mouse drag and scroll zoom
                if (rect.Contains(Event.current.mousePosition))
                {
                    // 拖动时修改偏移量
                    if (Event.current.type == EventType.MouseDrag)      // && Event.current.button == 2)
                    {
                        //放大后调整偏移值
                        CurFrameData.Offset += Event.current.delta / editorDisplayScale;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        editorDisplayScale -= Event.current.delta.y * 0.03f;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                }

                bool alphaBlend = true;
                textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos,
                                                       new Rect(0, 0, textureBorderPixels * 2 + (CurTexture.width) * editorDisplayScale, textureBorderPixels * 2 + (CurTexture.height) * editorDisplayScale));

                Rect textureRect = new Rect(textureBorderPixels, textureBorderPixels, CurTexture.width * editorDisplayScale, CurTexture.height * editorDisplayScale);

                // 支持放大后调整偏移值
                textureRect.x = rect.width / 2 - textureRect.width / 2 + CurFrameData.Offset.x * editorDisplayScale;
                textureRect.y = rect.height / 2 + heightOffset - textureRect.height + CurFrameData.Offset.y * editorDisplayScale;

                CurTexture.filterMode = FilterMode.Point;
                GUI.DrawTexture(textureRect, CurTexture, ScaleMode.ScaleAndCrop, alphaBlend);

                GUI.EndScrollView();
            }
            GUILayout.EndVertical();
        }
        public void Draw()
        {
            if (editorDisplayScale <= 1.0f)
            {
                editorDisplayScale = 1.0f;
            }
            GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            TextureGrid.Draw(rect);

            if (CurTexture != null)
            {
                // middle mouse drag and scroll zoom
                if (rect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.MouseDrag && Event.current.button == 2)
                    {
                        textureScrollPos -= Event.current.delta * editorDisplayScale;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        editorDisplayScale -= Event.current.delta.y * 0.03f;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                }

                bool alphaBlend = true;
                textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos,
                                                       new Rect(0, 0, textureBorderPixels * 2 + (CurTexture.width) * editorDisplayScale, textureBorderPixels * 2 + (CurTexture.height) * editorDisplayScale));
                Rect textureRect = new Rect(textureBorderPixels, textureBorderPixels, CurTexture.width * editorDisplayScale, CurTexture.height * editorDisplayScale);
                CurTexture.filterMode = FilterMode.Point;
                GUI.DrawTexture(textureRect, CurTexture, ScaleMode.ScaleAndCrop, alphaBlend);
                GameEditorUtility.DrawOutline(textureRect, Color.green);
                GUI.EndScrollView();

                GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));
                GUILayout.Label(string.Format("Name:{0} W: {1} H: {2}", CurTexture.name, CurTexture.width, CurTexture.height));
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }
Beispiel #3
0
        //大图绘制
        public void Draw()
        {
            if (editorDisplayScale <= 1.0f)
            {
                editorDisplayScale = 1.0f;
            }
            GUILayout.BeginVertical(GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            Rect rect = GUILayoutUtility.GetRect(128.0f, 128.0f, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));

            //在给定矩形内裁剪或平铺图像
            TextureGrid.Draw(rect);

            if (CurTexture != null)
            {
                // middle mouse drag and scroll zoom
                if (rect.Contains(Event.current.mousePosition))
                {
                    if (Event.current.type == EventType.MouseDrag && Event.current.button == 2)
                    {
                        textureScrollPos -= Event.current.delta * editorDisplayScale;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                    if (Event.current.type == EventType.ScrollWheel)
                    {
                        editorDisplayScale -= Event.current.delta.y * 0.03f;
                        Event.current.Use();
                        HandleUtility.Repaint();
                    }
                }

                bool    alphaBlend        = true;
                Rect    scrollViewRect    = new Rect(0, 0, textureBorderPixels * 2 + rect.width * editorDisplayScale, textureBorderPixels * 2 + rect.height * editorDisplayScale);
                Vector2 anchorPointInView = new Vector2(scrollViewRect.center.x + _spriteAtlasProxy.anchorPointInEditor.x, scrollViewRect.yMax - _spriteAtlasProxy.anchorPointInEditor.y);
                textureScrollPos = GUI.BeginScrollView(rect, textureScrollPos, scrollViewRect);

                Rect textureRect = new Rect(0, 0, CurTexture.width * editorDisplayScale, CurTexture.height * editorDisplayScale);
                textureRect.x = anchorPointInView.x - (textureRect.width * 0.5f + _spriteAtlasProxy.anchorPointInImage.x);
                textureRect.y = anchorPointInView.y - (textureRect.height - _spriteAtlasProxy.anchorPointInImage.y);

                CurTexture.filterMode = FilterMode.Point;
                GUI.DrawTexture(textureRect, CurTexture, ScaleMode.ScaleAndCrop, alphaBlend);
                GameEditorUtility.DrawOutline(textureRect, Color.green);
                GameEditorUtility.DrawOutline(scrollViewRect, Color.blue);

                // 编辑器中的锚点
                Handles.color = new Color(1, 1, 0, 0.5f);
                Handles.DrawLine(new Vector2(scrollViewRect.x + 10, anchorPointInView.y), new Vector2(scrollViewRect.x + scrollViewRect.width - 10, anchorPointInView.y));
                Handles.DrawLine(new Vector2(anchorPointInView.x, scrollViewRect.yMin + 10), new Vector2(anchorPointInView.x, scrollViewRect.yMax - 10));

                // 图片上的锚点
                Handles.color = new Color(0, 1, 0, 0.5f);
                Handles.DrawLine(new Vector2(textureRect.center.x - 10, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y), new Vector2(textureRect.center.x + 10, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y));
                Handles.DrawLine(new Vector2(textureRect.center.x, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y - 10), new Vector2(textureRect.center.x, textureRect.yMax - _spriteAtlasProxy.anchorPointInImage.y + 10));

                GUI.EndScrollView();

                GUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.ExpandWidth(true));
                GUILayout.Label(string.Format("Name:{0} W: {1} H: {2}", CurTexture.name, CurTexture.width, CurTexture.height));
                GUILayout.EndHorizontal();
            }
            GUILayout.EndVertical();
        }
        private void DrawTextureSettings()
        {
            CurActionData = this.host.CurActionData;
            if (CurActionData == null)
            {
                return;
            }
            GUI.color = Color.white;
            BeginHeader("动作设置");


            string changedName = EditorGUILayout.TextField("动作名", CurActionData.name).Trim();

            if (changedName != CurActionData.name && changedName.Length > 0)
            {
                CurActionData.name = changedName;
                HandleUtility.Repaint();
            }

            float fps = EditorGUILayout.FloatField("帧率", CurActionData.fps);

            if (fps > 0)
            {
                CurActionData.fps = fps;
            }
            float clipTime    = CurActionData.FrameList.Length / fps;
            float newClipTime = EditorGUILayout.FloatField("时长", clipTime);

            if (newClipTime > 0 && newClipTime != clipTime)
            {
                CurActionData.fps = CurActionData.FrameList.Length / newClipTime;
            }



            EndHeader();

            BeginHeader("图集设置");

            if (SpriteAnimationData.SpriteAtlasData != null)
            {
                string atlasName = SpriteAnimationData.SpriteAtlasData.name;
                EditorGUILayout.LabelField("图集名", atlasName);
                int  iwidth  = 256;
                int  iheight = 256;
                Rect rect    = GUILayoutUtility.GetRect(iwidth, iheight, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
                TextureGrid.Draw(rect);
                GameEditorUtility.DrawOutline(rect, Color.gray);

                if (CurTexture != null)
                {
                    iwidth  = (int)rect.width;
                    iheight = (int)rect.height;
                    if (CurTexture.width / CurTexture.height >= iwidth / iheight)
                    {
                        if (CurTexture.width > iwidth)
                        {
                            rect.width  = iwidth;
                            rect.height = (CurTexture.height * iwidth) / CurTexture.width;
                        }
                        else
                        {
                            rect.width  = CurTexture.width;
                            rect.height = CurTexture.height;
                        }
                    }
                    else
                    {
                        if (CurTexture.height > iheight)
                        {
                            rect.height = iheight;
                            rect.width  = (CurTexture.width * iheight) / CurTexture.height;
                        }
                        else
                        {
                            rect.width  = CurTexture.width;
                            rect.height = CurTexture.height;
                        }
                    }
                    rect.x += (iwidth - rect.width) / 2;
                    rect.y += (iheight - rect.height) / 2;
                    GUI.DrawTexture(rect, CurTexture);
                }

                GUILayout.Space(1);

                spriteListScroll = GUILayout.BeginScrollView(spriteListScroll, GUILayout.ExpandWidth(true),
                                                             GUILayout.ExpandHeight(true));
                for (int i = 0; i < SpriteAnimationData.SpriteAtlasData.spriteDataList.Length; i++)
                {
                    SpriteAtlasData.SpriteData spriteData = SpriteAnimationData.SpriteAtlasData.spriteDataList[i];
                    if (spriteData == null)
                    {
                        continue;
                    }
                    bool highlight = selection == spriteData;
                    GUI.backgroundColor = highlight ? Color.green : new Color(0.8f, 0.8f, 0.8f);
                    GUILayout.BeginHorizontal("AS TextArea", GUILayout.MinHeight(20f));
                    GUI.backgroundColor = Color.white;
                    GUILayout.Label(i.ToString(), GUILayout.Width(24f));
                    if (GUILayout.Button(spriteData.name, "OL TextField", GUILayout.Height(20f)))
                    {
                        selection = spriteData;
                    }
                    GUI.backgroundColor = Color.green;
                    if (GUILayout.Button("<+", GUILayout.Width(26f)))
                    {
                        selection = spriteData;
                        host.timeLineView.InsertFrame(selection.name, -1);
                    }
                    if (GUILayout.Button("+>", GUILayout.Width(26f)))
                    {
                        selection = spriteData;
                        host.timeLineView.InsertFrame(selection.name, +1);
                    }

                    if (selection != null)
                    {
                        CurTexture = this.host.GetTexture(selection.name);
                    }
                    else
                    {
                        CurTexture = null;
                    }
                    HandleUtility.Repaint();
                    GUI.backgroundColor = Color.white;
                    GUILayout.EndHorizontal();
                }

                GUILayout.EndScrollView();
            }
            else
            {
                GUILayout.Label("请先创建图集,在创建动画!");
            }
            EndHeader();
        }