Example #1
0
    private static void selectTextureAtlas(string title, Action <dfAtlas> callback)
    {
        var savedColor = GUI.color;

        try
        {
            dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item)
            {
                var newAtlas = (item == null) ? null : item.GetComponent <dfAtlas>();
                if (newAtlas != null)
                {
                    callback(newAtlas);
                }
            };

            dfEditorUtil.DelayedInvoke((System.Action)(() =>
            {
                var dialog         = dfPrefabSelectionDialog.Show(title, typeof(dfAtlas), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null);
                dialog.previewSize = 200;
            }));
        }
        finally
        {
            GUI.enabled = true;
            GUI.color   = savedColor;
        }
    }
Example #2
0
    private void EditAtlasReplacement(dfAtlas atlas)
    {
        var value = atlas.Replacement;

        dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item)
        {
            var newAtlas = (item == null) ? null : item.GetComponent <dfAtlas>();
            dfEditorUtil.MarkUndo(atlas, "Assign replacement Atlas");
            atlas.Replacement = newAtlas;
        };

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.LabelField("Replacement", "", GUILayout.Width(dfEditorUtil.LabelWidth - 6));

            GUILayout.Space(2);

            var displayText = value == null ? "[none]" : value.name;
            GUILayout.Label(displayText, "TextField");

            var evt = Event.current;
            if (evt != null)
            {
                Rect textRect = GUILayoutUtility.GetLastRect();
                if (evt.type == EventType.mouseDown && evt.clickCount == 2)
                {
                    if (textRect.Contains(evt.mousePosition))
                    {
                        if (GUI.enabled && value != null)
                        {
                            Selection.activeObject = value;
                            EditorGUIUtility.PingObject(value);
                        }
                    }
                }
                else if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform)
                {
                    if (textRect.Contains(evt.mousePosition))
                    {
                        var draggedObject = DragAndDrop.objectReferences.First() as GameObject;
                        var draggedAtlas  = draggedObject != null?draggedObject.GetComponent <dfAtlas>() : null;

                        DragAndDrop.visualMode = (draggedAtlas != null) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                        if (evt.type == EventType.DragPerform)
                        {
                            selectionCallback(draggedObject);
                        }
                        evt.Use();
                    }
                }
            }

            if (GUI.enabled && GUILayout.Button(new GUIContent(" ", "Edit Atlas"), "IN ObjectField", GUILayout.Width(14)))
            {
                dfEditorUtil.DelayedInvoke((System.Action)(() =>
                {
                    var dialog         = dfPrefabSelectionDialog.Show("Select Texture Atlas", typeof(dfAtlas), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null);
                    dialog.previewSize = 200;
                }));
            }
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(2);
    }
Example #3
0
    protected internal static void SelectTextureAtlas(string label, dfFont view, string propertyName, bool readOnly, bool colorizeIfMissing, int labelWidth)
    {
        var savedColor = GUI.color;
        var showDialog = false;

        try
        {
            var atlas = getValue(view, propertyName) as dfAtlas;

            GUI.enabled = !readOnly;

            if (atlas == null && colorizeIfMissing)
            {
                GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red;
            }

            dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item)
            {
                var newAtlas = (item == null) ? null : item.GetComponent <dfAtlas>();
                dfEditorUtil.MarkUndo(view, "Change Atlas");
                setValue(view, propertyName, newAtlas);
            };

            var value = (dfAtlas)getValue(view, propertyName);

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(label, "", GUILayout.Width(labelWidth));

                var displayText = value == null ? "[none]" : value.name;
                GUILayout.Label(displayText, "TextField");

                var evt = Event.current;
                if (evt != null)
                {
                    Rect textRect = GUILayoutUtility.GetLastRect();
                    if (evt.type == EventType.MouseDown && evt.clickCount == 2)
                    {
                        if (textRect.Contains(evt.mousePosition))
                        {
                            if (GUI.enabled && value != null)
                            {
                                Selection.activeObject = value;
                                EditorGUIUtility.PingObject(value);
                            }
                        }
                    }
                    else if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform)
                    {
                        if (textRect.Contains(evt.mousePosition))
                        {
                            var draggedObject = DragAndDrop.objectReferences.First() as GameObject;
                            var draggedFont   = draggedObject != null?draggedObject.GetComponent <dfAtlas>() : null;

                            DragAndDrop.visualMode = (draggedFont != null) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                            if (evt.type == EventType.DragPerform)
                            {
                                selectionCallback(draggedObject);
                            }
                            evt.Use();
                        }
                    }
                }

                if (GUI.enabled && GUILayout.Button(new GUIContent(" ", "Edit Atlas"), "IN ObjectField", GUILayout.Width(14)))
                {
                    showDialog = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(2);

            if (showDialog)
            {
                var dialog = dfPrefabSelectionDialog.Show("Select Texture Atlas", typeof(dfAtlas), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null);
                dialog.previewSize = 200;
            }
        }
        finally
        {
            GUI.enabled = true;
            GUI.color   = savedColor;
        }
    }
Example #4
0
    private static void inspectFont(dfRichTextLabel control)
    {
        dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item)
        {
            var font = (item == null) ? null : item.GetComponent <dfDynamicFont>();
            dfEditorUtil.MarkUndo(control, "Assign Dynamic Font");
            control.Font = font;
        };

        var value = control.Font;

        EditorGUILayout.BeginHorizontal();
        {
            EditorGUILayout.LabelField("Default Font", "", GUILayout.Width(dfEditorUtil.LabelWidth));

            var displayText = value == null ? "[none]" : value.name;
            GUILayout.Label(displayText, "TextField");

            var evt = Event.current;
            if (evt != null)
            {
                Rect textRect = GUILayoutUtility.GetLastRect();
                if (evt.type == EventType.mouseDown && evt.clickCount == 2)
                {
                    if (textRect.Contains(evt.mousePosition))
                    {
                        if (GUI.enabled && value != null)
                        {
                            Selection.activeObject = value;
                            EditorGUIUtility.PingObject(value);
                        }
                    }
                }
                else if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform)
                {
                    if (textRect.Contains(evt.mousePosition))
                    {
                        var draggedObject = DragAndDrop.objectReferences.First() as GameObject;
                        var draggedFont   = draggedObject != null?draggedObject.GetComponent <dfDynamicFont>() : null;

                        DragAndDrop.visualMode = (draggedFont != null) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                        if (evt.type == EventType.DragPerform)
                        {
                            selectionCallback(draggedObject);
                        }
                        evt.Use();
                    }
                }
            }

            if (GUI.enabled && GUILayout.Button(new GUIContent(" ", "Select Font"), "IN ObjectField", GUILayout.Width(14)))
            {
                dfEditorUtil.DelayedInvoke((System.Action)(() =>
                {
                    var dialog         = dfPrefabSelectionDialog.Show("Select Dynamic Font", typeof(dfDynamicFont), selectionCallback, dfFontDefinitionInspector.DrawFontPreview, null);
                    dialog.previewSize = 200;
                }));
            }
        }
        EditorGUILayout.EndHorizontal();

        GUILayout.Space(2);
    }
    public static void CreateAnimationClip()
    {
        dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item)
        {
            var atlas = (item == null) ? null : item.GetComponent <dfAtlas>();
            if (atlas == null)
            {
                return;
            }

            var    defaultPath = Path.GetDirectoryName(AssetDatabase.GetAssetPath(item));
            string prefabPath  = EditorUtility.SaveFilePanel("Create Animation Clip", defaultPath, "AnimationClip", "prefab");
            if (string.IsNullOrEmpty(prefabPath))
            {
                return;
            }

            prefabPath = prefabPath.MakeRelativePath();

            var go = new GameObject()
            {
                name = Path.GetFileNameWithoutExtension(prefabPath)
            };
            var clip = go.AddComponent <dfAnimationClip>();
            clip.Atlas = atlas;

            var prefab = PrefabUtility.CreateEmptyPrefab(prefabPath);
            if (prefab == null)
            {
                EditorUtility.DisplayDialog("Create Animation Clip", "Failed to create the Animation Clip prefab", "OK");
                return;
            }

            prefab.name = clip.name;
            PrefabUtility.ReplacePrefab(go, prefab);

            DestroyImmediate(go);
            AssetDatabase.Refresh();

            #region Delay execution of object baseFont to work around a Unity issue

            // Declared with null value to eliminate "uninitialized variable"
            // compiler error in lambda below.
            EditorApplication.CallbackFunction callback = null;

            callback = () =>
            {
                EditorUtility.FocusProjectWindow();
                go = AssetDatabase.LoadMainAssetAtPath(prefabPath) as GameObject;
                Selection.objects = new Object[] { go };
                EditorGUIUtility.PingObject(go);
                Debug.Log("Animation clip created at " + prefabPath, prefab);
                EditorApplication.delayCall -= callback;
            };

            EditorApplication.delayCall += callback;

            #endregion
        };

        var dialog = dfPrefabSelectionDialog.Show("Select Texture Atlas", typeof(dfAtlas), selectionCallback, dfTextureAtlasInspector.DrawAtlasPreview, null);
        dialog.previewSize = 200;
    }
Example #6
0
    protected internal static void SelectAnimationClip(string label, dfSpriteAnimation animation)
    {
        var savedColor = GUI.color;
        var showDialog = false;

        try
        {
            var clip = animation.Clip;
            if (clip == null)
            {
                GUI.color = EditorGUIUtility.isProSkin ? Color.yellow : Color.red;
            }

            dfPrefabSelectionDialog.SelectionCallback selectionCallback = delegate(GameObject item)
            {
                var newClip = (item == null) ? null : item.GetComponent <dfAnimationClip>();
                dfEditorUtil.MarkUndo(animation, "Change Atlas");
                animation.Clip = newClip;
            };

            var value = clip;

            EditorGUILayout.BeginHorizontal();
            {
                EditorGUILayout.LabelField(label, "", GUILayout.Width(dfEditorUtil.LabelWidth - 6));

                GUILayout.Space(2);

                var displayText = value == null ? "[none]" : value.name;
                GUILayout.Label(displayText, "TextField");

                var evt = Event.current;
                if (evt != null)
                {
                    Rect textRect = GUILayoutUtility.GetLastRect();
                    if (evt.type == EventType.mouseDown && evt.clickCount == 2)
                    {
                        if (textRect.Contains(evt.mousePosition))
                        {
                            if (GUI.enabled && value != null)
                            {
                                Selection.activeObject = value;
                                EditorGUIUtility.PingObject(value);
                            }
                        }
                    }
                    else if (evt.type == EventType.DragUpdated || evt.type == EventType.DragPerform)
                    {
                        if (textRect.Contains(evt.mousePosition))
                        {
                            var draggedObject = DragAndDrop.objectReferences.First() as GameObject;
                            var draggedFont   = draggedObject != null?draggedObject.GetComponent <dfAtlas>() : null;

                            DragAndDrop.visualMode = (draggedFont != null) ? DragAndDropVisualMode.Copy : DragAndDropVisualMode.None;
                            if (evt.type == EventType.DragPerform)
                            {
                                selectionCallback(draggedObject);
                            }
                            evt.Use();
                        }
                    }
                }

                if (GUI.enabled && GUILayout.Button(new GUIContent(" ", "Edit Clip"), "IN ObjectField", GUILayout.Width(14)))
                {
                    showDialog = true;
                }
            }
            EditorGUILayout.EndHorizontal();

            GUILayout.Space(2);

            if (showDialog)
            {
                var dialog = dfPrefabSelectionDialog.Show("Select Animation Clip", typeof(dfAnimationClip), selectionCallback, dfAnimationClipInspector.RenderPreview, null);
                dialog.previewSize = 200;
            }
        }
        finally
        {
            GUI.color = savedColor;
        }
    }