Beispiel #1
0
        private void DrawActionList()
        {
            Texture2D blackTexture = new Texture2D(1, 1);

            blackTexture.SetPixel(0, 0, Color.black);
            blackTexture.Apply();
            GUI.DrawTexture(new Rect(leftBarWidth, 16, 1f, Screen.height - 16), blackTexture);


            actionListScroll = GUILayout.BeginScrollView(actionListScroll, GUILayout.Width(leftBarWidth), GUILayout.ExpandHeight(true));
            bool delete = false;

            for (int i = 0; i < allAction.Count; i++)
            {
                SpriteAnimationData.ActionData actionData = allAction[i];
                if (actionData == null)
                {
                    continue;
                }
                bool highlight = selection == actionData.name;
                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(actionData.name, "OL TextField", GUILayout.Height(20f)))
                {
                    selection     = actionData.name;
                    CurActionData = actionData;
                    settingView.Draw();
                    timeLineView.Draw();
                }
                if (mDelNames.Contains(actionData.name))
                {
                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("删除", GUILayout.Width(60f)))
                    {
                        delete = true;
                    }
                    GUI.backgroundColor = Color.green;
                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        mDelNames.Remove(actionData.name);
                        delete = false;
                    }
                    GUI.backgroundColor = Color.white;
                }
                else
                {
                    // If we have not yet selected a sprite for deletion, show a small "X" button
                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        mDelNames.Add(actionData.name);
                    }
                }


                GUILayout.EndHorizontal();
            }


            if (delete)
            {
                for (int i = allAction.Count - 1; i >= 0; i--)
                {
                    SpriteAnimationData.ActionData actionData = allAction[i];
                    if (actionData != null && mDelNames.Contains(actionData.name))
                    {
                        allAction.RemoveAt(i);
                        if (CurActionData == actionData)
                        {
                            CurActionData = null;
                            settingView.Draw();
                            timeLineView.Draw();
                        }
                    }
                }
                mDelNames.Clear();
            }


            GUILayout.EndScrollView();

            Rect viewRect = GUILayoutUtility.GetLastRect();

            leftBarWidth = (int)GameEditorUtility.DragableHandle(4819283,
                                                                 viewRect, leftBarWidth,
                                                                 GameEditorUtility.DragDirection.Horizontal);
        }
        private void DrawSpriteList()
        {
            Rect rect = new Rect(0, 0, leftBarWidth, Screen.height);

            if (rect.Contains(Event.current.mousePosition))
            {
                switch (Event.current.type)
                {
                case EventType.DragUpdated:
                    if (IsValidDragPayload())
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    }
                    else
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.None;
                    }
                    break;

                case EventType.DragPerform:
                    var droppedObjectsList = new List <Object>();
                    for (int i = 0; i < DragAndDrop.objectReferences.Length; ++i)
                    {
                        var type = DragAndDrop.objectReferences[i].GetType();
                        if (type == typeof(Texture2D))
                        {
                            droppedObjectsList.Add(DragAndDrop.objectReferences[i]);
                        }
                        else if (type == typeof(Object) && System.IO.Directory.Exists(DragAndDrop.paths[i]))
                        {
                            droppedObjectsList.AddRange(AddTexturesInPath(DragAndDrop.paths[i]));
                        }
                    }
                    deferredDroppedObjects = droppedObjectsList.ToArray();
                    Repaint();
                    break;
                }
            }

            if (Event.current.type == EventType.Layout && deferredDroppedObjects != null)
            {
                HandleDroppedPayload(deferredDroppedObjects);
                deferredDroppedObjects = null;
            }



            if (_spriteAtlasProxy != null)
            {
                if (_spriteAtlasProxy.Empty)
                {
                    GUILayout.BeginVertical(GUILayout.Width(leftBarWidth), GUILayout.ExpandHeight(true));
                    GUILayout.FlexibleSpace();
                    GUILayout.BeginHorizontal();
                    GUILayout.FlexibleSpace();
                    GUILayout.Label("拖动贴图到这里");
                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                    GUILayout.FlexibleSpace();
                    GUILayout.EndVertical();
                    return;
                }
            }
            else
            {
                return;
            }

            //line
            Texture2D blackTexture = new Texture2D(1, 1);

            blackTexture.SetPixel(0, 0, Color.black);
            blackTexture.Apply();
            GUI.DrawTexture(new Rect(leftBarWidth, 16, 1f, Screen.height - 16), blackTexture);
            //Handles.DrawLine(new Vector3(leftBarWidth, 0), new Vector3(leftBarWidth,));

            spriteListScroll = GUILayout.BeginScrollView(spriteListScroll, GUILayout.Width(leftBarWidth), GUILayout.ExpandHeight(true));
            bool delete = false;

            for (int spriteIndex = 0; spriteIndex < _spriteAtlasProxy.spriteDataList.Count; ++spriteIndex)
            {
                var sprite = _spriteAtlasProxy.spriteDataList[spriteIndex];
                var spriteSourceTexture = GetTexture(sprite.name);;
                if (spriteSourceTexture == null && sprite.name.Length == 0)
                {
                    continue;
                }
                bool highlight = selection == sprite.name;
                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(spriteIndex.ToString(), GUILayout.Width(24f));
                if (GUILayout.Button(sprite.name, "OL TextField", GUILayout.Height(20f)))
                {
                    selection = sprite.name;
                    textureView.CurTexture = spriteSourceTexture;
                }
                if (mDelNames.Contains(sprite.name))
                {
                    GUI.backgroundColor = Color.red;

                    if (GUILayout.Button("删除", GUILayout.Width(60f)))
                    {
                        delete = true;
                    }
                    GUI.backgroundColor = Color.green;
                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        mDelNames.Remove(sprite.name);
                        delete = false;
                    }
                    GUI.backgroundColor = Color.white;
                }
                else
                {
                    // If we have not yet selected a sprite for deletion, show a small "X" button
                    if (GUILayout.Button("X", GUILayout.Width(22f)))
                    {
                        mDelNames.Add(sprite.name);
                    }
                }


                GUILayout.EndHorizontal();
            }

            if (delete)
            {
                for (int spriteIndex = _spriteAtlasProxy.spriteDataList.Count - 1; spriteIndex >= 0; spriteIndex--)
                {
                    var sprite = _spriteAtlasProxy.spriteDataList[spriteIndex];
                    var spriteSourceTexture = GetTexture(sprite.name);
                    if (spriteSourceTexture == null && sprite.name.Length == 0)
                    {
                        continue;
                    }
                    if (mDelNames.Contains(sprite.name))
                    {
                        _spriteAtlasProxy.spriteDataList.RemoveAt(spriteIndex);
                        if (textureView.CurTexture == spriteSourceTexture)
                        {
                            textureView.CurTexture = null;
                            textureView.Draw();
                        }
                    }
                }
                mDelNames.Clear();
            }

            GUILayout.EndScrollView();

            Rect viewRect = GUILayoutUtility.GetLastRect();

            leftBarWidth = (int)GameEditorUtility.DragableHandle(4819283,
                                                                 viewRect, leftBarWidth,
                                                                 GameEditorUtility.DragDirection.Horizontal);
        }