Esempio n. 1
0
    void RemoveGroup(MadLevelConfiguration.Group group)
    {
        if (group == configuration.defaultGroup)
        {
            Debug.LogError("Cannot remove default group");
            return;
        }

        bool removeLevels = false;

        if (group.GetLevels().Count > 0)
        {
            if (EditorUtility.DisplayDialog("Remove Levels As Well?",
                                            "Do you want to remove all levels in this group as well? "
                                            + "If no, all levels will be moved to default group.", "Yes", "No"))
            {
                removeLevels = true;
            }
        }

        MadUndo.RecordObject2(configuration, "Remove Group");

        if (currentGroup == group)
        {
            currentGroup = configuration.defaultGroup;
        }

        if (removeLevels)
        {
            var levels = group.GetLevels();
            configuration.levels.RemoveAll((level) => levels.Contains(level));
        }

        configuration.RemoveGroup(group);
    }
    private void FieldLiveBounds()
    {
        int texWidth  = sprite.currentTextureWidth;
        int texHeight = sprite.currentTextureHeight;

        MadGUI.PropertyField(hasLiveBounds, "Has Border");

        GUI.backgroundColor = Color.yellow;
        MadGUI.Indent(() => {
            MadGUI.LookLikeControls(0, 40);
            FieldLiveBounds(liveLeft, texWidth, "Left", 0, liveRight.floatValue);
            FieldLiveBounds(liveTop, texHeight, "Top", liveBottom.floatValue, 1);
            FieldLiveBounds(liveRight, texWidth, "Right", liveLeft.floatValue, 1);
            FieldLiveBounds(liveBottom, texHeight, "Bottom", 0, liveTop.floatValue);
            MadGUI.LookLikeControls(0);
        });
        GUI.backgroundColor = Color.white;

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        if (MadGUI.Button("Reset"))
        {
            ResetLiveBounds();
        }
        if (MadGUI.Button("Compute"))
        {
            MadUndo.RecordObject2(sprite, "Set Live Bounds");
            ComputeLiveBounds();
        }
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 3
0
    // ===========================================================
    // Static Methods
    // ===========================================================
    
    public static T CreateChild<T>(Transform parent, string name, bool disabled = false) where T : Component {
        GameObject go = null;
    
        go = new GameObject(name);
        if (disabled) {
            MadGameObject.SetActive(go, false);
        }

        go.transform.parent = parent;
        
        go.transform.localRotation = Quaternion.identity;
        go.transform.localScale = Vector3.one;
        go.transform.localPosition = Vector3.zero;
        
        T component = go.GetComponent<T>();
        if (component == null) {
            component = go.AddComponent<T>();
        }

        if (registerUndo) {
            MadUndo.RegisterCreatedObjectUndo(go, "Created " + name);
        }
        
        return component;
    }
    LevelItem AddLevel()
    {
        MadUndo.RecordObject2(configuration, "Add Level");

        var levelItem = new LevelItem(configuration);

        levelItem.level.group = currentGroup;

        LevelItem template = null;

        if (list.selectedItem != null)
        {
            template = list.selectedItem;
        }
        else if (items.Count > 0)
        {
            template = items.Last();
        }

        if (template != null)
        {
            levelItem.level.order = template.level.order + 1;

            levelItem.level.name        = UniqueLevelName(template.level.name);
            levelItem.level.sceneObject = template.level.sceneObject;
            levelItem.level.type        = template.level.type;

            levelItem.level.extension = template.level.extension;
        }
        else
        {
            levelItem.level.order = 0;

            levelItem.level.name = "New Level";
            levelItem.level.type = MadLevel.Type.Level;
        }

        // check if there is a level that is not locked by default
        // if there isn't one, then set this one to be
        bool hasLockedByDefault = items.Find((item) => item.level.type == MadLevel.Type.Level && !item.level.lockedByDefault) != null;

        if (!hasLockedByDefault)
        {
            levelItem.level.lockedByDefault = false;
        }

        items.Add(levelItem);
        configuration.levels.Add(levelItem.level);

        Reorder();

        configuration.SetDirty();

        list.selectedItem = levelItem;
        list.ScrollToItem(levelItem);

        return(levelItem);
    }
Esempio n. 5
0
    public static MadLevelFreeLayout CreateUnderPanel(MadPanel panel)
    {
        MadUndo.LegacyRegisterSceneUndo("Creating Free Layout");
        var child = MadTransform.CreateChild <MadLevelFreeLayout>(panel.transform, "Free Layout");

        Selection.activeObject = child;

        return(child);
    }
    public static MadLevelGridLayout CreateUnderPanel(MadPanel panel)
    {
        MadUndo.LegacyRegisterSceneUndo("Creating Grid Layout");
        var child = MadTransform.CreateChild <MadLevelGridLayout>(panel.transform, "Grid Layout");

        child.setupMethod      = MadLevelGridLayout.SetupMethod.Generate;
        Selection.activeObject = child;

        return(child);
    }
Esempio n. 7
0
 public static GameObject CreateChild(Transform parent, string name, GameObject template) {
     GameObject go = null;
     go = GameObject.Instantiate(template) as GameObject;
     go.transform.parent = parent;
     go.name = name;
     
     MadUndo.RegisterCreatedObjectUndo(go, "Created " + name);
     
     return go;
 }
Esempio n. 8
0
    void RemoveLevel()
    {
        MadUndo.RecordObject2(configuration, "Remove Level");
        configuration.levels.Remove(list.selectedItem.level);
        items.Remove(list.selectedItem);
        Reorder();
        configuration.SetDirty();

        list.selectedItem = null;
    }
    void OnGUI()
    {
        var arrayList = new MadGUI.ArrayList <MadLevelConfiguration.Group>(conf.groups, @group => {
            if (MadGUI.Button(@group.name))
            {
                var builder = new MadInputDialog.Builder("Rename group " + @group.name, "New name for group " + @group.name,
                                                         newName => TryRename(@group, newName));
                builder.BuildAndShow();
            }
            return(@group);
        });

        arrayList.beforeRemove += @group => {
            if (
                !EditorUtility.DisplayDialog("Remove Group",
                                             "Are you sure that you want to remove group " + @group.name + "?", "Yes", "No"))
            {
                return(false);
            }

            if (group.GetLevels().Count > 0)
            {
                MadUndo.RecordObject2(conf, "Remove Group");

                if (EditorUtility.DisplayDialog("Remove Levels As Well?",
                                                "Do you want to remove all levels in this group as well? "
                                                + "If no, all levels will be moved to default group.", "Yes", "No"))
                {
                    var levels = group.GetLevels();
                    conf.levels.RemoveAll((level) => levels.Contains(level));
                }
                else
                {
                    var defaultGroup = conf.defaultGroup;
                    var levels       = group.GetLevels();
                    foreach (var level in levels)
                    {
                        level.groupId = defaultGroup.id;
                    }
                }
            }

            return(true);
        };

        arrayList.beforeAdd = () => MadUndo.RecordObject2(conf, "Add Group");

        arrayList.createFunctionGeneric = CreateGroup;

        if (arrayList.Draw())
        {
            EditorUtility.SetDirty(conf);
        }
    }
    private void ResizeDragAreaToBackground()
    {
        var background = MadTransform.FindChildWithName <MadSprite>(script.transform, "background");

        MadUndo.RecordObject2(script, "Resize Drag Area");

        Rect spriteBounds = background.GetTransformedBounds();

        script.dragBounds = new Bounds(spriteBounds.center, new Vector2(spriteBounds.xMax - spriteBounds.xMin, spriteBounds.yMax - spriteBounds.yMin));

        EditorUtility.SetDirty(script);
    }
Esempio n. 11
0
 public static GameObject CreateChild(Transform parent, string name) {
     GameObject go = new GameObject();
     go.transform.parent = parent;
     
     go.transform.localScale = Vector3.one;
     go.transform.localPosition = Vector3.zero;
     
     go.name = name;
     
     MadUndo.RegisterCreatedObjectUndo(go, "Created " + name);
     
     return go;
 }
Esempio n. 12
0
 public void Cleanup()
 {
     if (sprite != null)
     {
         if (Application.isPlaying)
         {
             Destroy(gameObject);
         }
         else
         {
             MadUndo.DestroyObjectImmediate(gameObject);
         }
     }
 }
    void RemoveLevel()
    {
        MadUndo.RecordObject2(configuration, "Remove Level");

        foreach (var item in list.selectedItems)
        {
            configuration.levels.Remove(item.level);
            items.Remove(item);
        }

        Reorder();
        configuration.SetDirty();

        list.selectedItem = null;
    }
    private void RemoveExtension(int index)
    {
        if (EditorUtility.DisplayDialog(
                "Remove Extension?",
                "Are you sure you want to remove extension \"" + configuration.extensions[index].name + "\"?",
                "Yes", "No"))
        {
            MadUndo.RecordObject2(configuration, "Remove Extension");

            configuration.extensions.RemoveAt(index);
            EditorUtility.SetDirty(configuration);

            Repaint();
        }
    }
Esempio n. 15
0
    public static GameObject CreateChild(Transform parent, string name, GameObject template) {
        GameObject go = null;
        
        instantiating = true;
        try {
        
            go = GameObject.Instantiate(template) as GameObject;
            go.transform.parent = parent;
            go.name = name;
            
            if (registerUndo) {
                MadUndo.RegisterCreatedObjectUndo(go, "Created " + name);
            }
#if !MAD_EBT && (!UNITY_5 || !UNITY_WEBGL) // http://fogbugz.unity3d.com/default.asp?675175_r3deh2mdhmitddpj
        } finally {
#else
} finally {} {
Esempio n. 16
0
    bool AddGroup(string name)
    {
        if (configuration.FindGroupByName(name) != null)
        {
            EditorUtility.DisplayDialog("Group Exists", "Group '" + name + "' already exists.", "OK");
            return(false);
        }

        MadUndo.RecordObject2(configuration, "Add Group");
        var group = configuration.CreateGroup();

        group.name = name;
        configuration.AddGroup(group);
        currentGroup = group;

        return(true);
    }
Esempio n. 17
0
    protected void SectionSprite(DisplayFlag flags)
    {
        serializedObject.Update();
        MadGUI.PropertyField(visible, "Visible");

        if ((flags & DisplayFlag.WithoutMaterial) == 0)
        {
            MadGUI.PropertyField(texture, "Texture", MadGUI.ObjectIsSet);
            MadGUI.Indent(() => {
                MadGUI.PropertyFieldVector2(textureRepeat, "Repeat");
                MadGUI.PropertyFieldVector2(textureOffset, "Offset");
            });
        }

        MadGUI.PropertyField(tint, "Tint");

        if ((flags & DisplayFlag.WithoutSize) == 0)
        {
            if (GUILayout.Button(new GUIContent("Resize To Texture",
                                                "Resizes this sprite to match texture size")))
            {
                var sprite = target as MadSprite;
                MadUndo.RecordObject2(sprite, "Resize To Texture");
                sprite.ResizeToTexture();
                EditorUtility.SetDirty(sprite);
            }
        }

        MadGUI.PropertyField(pivotPoint, "Pivot Point");
        MadGUI.PropertyField(guiDepth, "GUI Depth");

        if ((flags & DisplayFlag.WithoutFill) == 0)
        {
            MadGUI.PropertyField(fillType, "Fill Type");
            EditorGUILayout.Slider(fillValue, 0, 1, "Fill Value");

            if (sprite.fillType == MadSprite.FillType.RadialCCW || sprite.fillType == MadSprite.FillType.RadialCW)
            {
                MadGUI.PropertyFieldSlider(radialFillOffset, -1, 1, "Offset");
                MadGUI.PropertyFieldSlider(radialFillLength, 0, 1, "Length");
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
Esempio n. 18
0
    // ===========================================================
    // Constants
    // ===========================================================

    // ===========================================================
    // Static Methods
    // ===========================================================
    
    public static T CreateChild<T>(Transform parent, string name) where T : Component {
        GameObject go = null;
    
        go = new GameObject(name);
        go.transform.parent = parent;
        
        go.transform.localRotation = Quaternion.identity;
        go.transform.localScale = Vector3.one;
        go.transform.localPosition = Vector3.zero;
        
        T component = go.GetComponent<T>();
        if (component == null) {
            component = go.AddComponent<T>();
        }
        MadUndo.RegisterCreatedObjectUndo(go, "Created " + name);
        
        return component;
    }
Esempio n. 19
0
 public static GameObject CreateChild(Transform parent, string name, GameObject template) {
     GameObject go = null;
     
     instantiating = true;
     try {
     
         go = GameObject.Instantiate(template) as GameObject;
         go.transform.parent = parent;
         go.name = name;
         
         if (registerUndo) {
             MadUndo.RegisterCreatedObjectUndo(go, "Created " + name);
         }
     } finally {
         instantiating = false;
     }
     
     return go;
 }
Esempio n. 20
0
    void AddLevel()
    {
        MadUndo.RecordObject2(configuration, "Add Level");

        var levelItem = new LevelItem(configuration);

        LevelItem template = null;

        if (list.selectedItem != null)
        {
            template = list.selectedItem;
        }
        else if (items.Count > 0)
        {
            template = items.Last();
        }

        if (template != null)
        {
            levelItem.level.order = template.level.order + 1;

            levelItem.level.name        = IncreaseNumber(template.level.name);
            levelItem.level.sceneObject = template.level.sceneObject;
            levelItem.level.type        = template.level.type;
        }
        else
        {
            levelItem.level.order = 0;

            levelItem.level.name = "New Level";
            levelItem.level.type = MadLevel.Type.Level;
        }

        items.Add(levelItem);
        configuration.levels.Add(levelItem.level);

        Reorder();

        configuration.SetDirty();

        list.selectedItem = levelItem;
        list.ScrollToItem(levelItem);
    }
    private MadLevelExtension CreateNewExtension(string name)
    {
        if (ExtensionExists(name))
        {
            EditorUtility.DisplayDialog("Extension exists!", "Extension with name '" + name + "' already exists!", "OK");
            return(null);
        }

        MadUndo.RecordObject2(configuration, "Create New Extension");

        var extension = new MadLevelExtension(name);

        configuration.extensions.Add(extension);
        EditorUtility.SetDirty(configuration);

        Repaint();

        return(extension);
    }
Esempio n. 22
0
    private void FieldLiveBounds()
    {
        int texWidth  = sprite.currentTextureWidth;
        int texHeight = sprite.currentTextureHeight;

        MadGUI.PropertyField(hasLiveBounds, "Has Border");
        MadGUI.PropertyField(renderLiveBoundsOnly, "Cut Texture");
        if (renderLiveBoundsOnly.boolValue &&
            (sprite.fillType == MadSprite.FillType.RadialCCW || sprite.fillType == MadSprite.FillType.RadialCW))
        {
            MadGUI.Error("Cut not supported for radial fill");
        }

        GUI.backgroundColor = Color.yellow;
        MadGUI.Indent(() => {
            MadGUI.LookLikeControls(0, 40);
            FieldLiveBounds(liveLeft, texWidth, "Left", 0, liveRight.floatValue);
            FieldLiveBounds(liveTop, texHeight, "Top", liveBottom.floatValue, 1);
            FieldLiveBounds(liveRight, texWidth, "Right", liveLeft.floatValue, 1);
            FieldLiveBounds(liveBottom, texHeight, "Bottom", 0, liveTop.floatValue);
            MadGUI.LookLikeControls(0);
        });
        GUI.backgroundColor = Color.white;

        EditorGUILayout.Space();

        EditorGUILayout.BeginHorizontal();
        if (MadGUI.Button("Reset"))
        {
            ResetLiveBounds();
        }
        if (MadGUI.Button("Compute"))
        {
            MadUndo.RecordObject2(sprite, "Set Live Bounds");
            ComputeLiveBounds();
        }
        EditorGUILayout.EndHorizontal();
    }
Esempio n. 23
0
    void MoveDown(MadLevelBackgroundLayer layer)
    {
        const string UndoName = "Move Layer Down";

        MadUndo.RecordObject(script, UndoName);
        MadUndo.LegacyRegisterSceneUndo(UndoName);

        int index = script.layers.IndexOf(layer);

        if (index < script.layers.Count - 1)
        {
            var temp = script.layers[index + 1];
            script.layers[index + 1] = layer;
            script.layers[index]     = temp;

            MadUndo.RecordObject(temp.gameObject, UndoName);
            MadUndo.RecordObject(layer.gameObject, UndoName);

            temp.SetDirty();
            layer.SetDirty();
        }

        script.UpdateDepth();
    }
Esempio n. 24
0
    public override void OnInspectorGUI()
    {
        serializedObject.UpdateIfDirtyOrScript();

        MadGUI.PropertyField(draggable, "Draggable", MadGUI.ObjectIsSet);
        MadGUI.PropertyField(startDepth, "Start Depth", "Depth value of first layer added. "
                             + "Every next layer will receive +1 to it's depth value.");
        MadGUI.PropertyField(ignoreXMovement, "Ignore X Movement");
        MadGUI.PropertyField(ignoreYMovement, "Ignore Y Movement");

        serializedObject.ApplyModifiedProperties();

        var arrayList = new MadGUI.ArrayList <MadLevelBackgroundLayer>(script.layers, (layer) => {
            if (layer == null)
            {
                return;
            }

            var so = new SerializedObject(layer);
            so.UpdateIfDirtyOrScript();

            var texture = so.FindProperty("texture");

            EditorGUILayout.BeginHorizontal();

            MadGUI.PropertyField(texture, "");

            MadGUI.ConditionallyEnabled(CanMoveUp(layer), () => {
                if (GUILayout.Button("Up"))
                {
                    MoveUp(layer);
                }
            });

            MadGUI.ConditionallyEnabled(CanMoveDown(layer), () => {
                if (GUILayout.Button("Down"))
                {
                    MoveDown(layer);
                }
            });

            GUI.color = Color.yellow;
            if (GUILayout.Button("Select"))
            {
                Selection.activeGameObject = layer.gameObject;
            }
            GUI.color = Color.white;
            EditorGUILayout.EndHorizontal();

            if (so.ApplyModifiedProperties())
            {
                layer.SetDirty();
            }
        });

        arrayList.createFunctionGeneric = () => {
            var layer = MadTransform.CreateChild <MadLevelBackgroundLayer>(script.transform, "layer (empty)");
            layer.GetComponent <MadSprite>().hideFlags = HideFlags.HideInInspector;
            return(layer);
        };
        arrayList.onRemove = (layer) => layer.Cleanup();

        arrayList.beforeAdd = () => {
            MadUndo.RecordObject(script, "Add Background Layer");
            MadUndo.LegacyRegisterSceneUndo("Add Background Layer");
        };

        arrayList.beforeRemove = (arg) => {
            MadUndo.RecordObject(script, "Remove Background Layer");
            MadUndo.LegacyRegisterSceneUndo("Remove Background Layer");
        };

        if (arrayList.Draw())
        {
            EditorUtility.SetDirty(script);
        }


        EditorGUI.BeginChangeCheck();

        if (EditorGUI.EndChangeCheck())
        {
            // changed
        }
    }
Esempio n. 25
0
    /// <summary>
    /// Will replace all icons in the layout with selected icon. Position, scale and rotation will be preserved.
    /// This method is meant for editor-use only.
    /// </summary>
    /// <param name="newIcon"></param>
    public void ReplaceIcons(GameObject newIcon)
    {
        if (Application.isPlaying)
        {
            Debug.LogError("This method can be called only from the editor");
            return;
        }

        MadUndo.LegacyRegisterSceneUndo("Replaced Icons");

        var icons       = MadTransform.FindChildren <MadLevelIcon>(draggable.transform);
        var activeIcons = from i in icons where MadGameObject.IsActive(i.gameObject) select i;

        // keep track of unlock on complete settings
        Dictionary <int, List <int> > unlockOnCompleteDict = new Dictionary <int, List <int> >();
        List <MadLevelIcon>           createdIcons         = new List <MadLevelIcon>();

        foreach (var icon in activeIcons)
        {
            var position      = icon.transform.position;
            var rotation      = icon.transform.rotation;
            var localScale    = icon.transform.localScale;
            var name          = icon.name;
            var baseDepth     = icon.guiDepth;
            var levelIndex    = icon.levelIndex;
            var configuration = icon.configuration;

            // build unlock on complete dict
            List <int> toUnlockList = new List <int>();
            foreach (var unlock in icon.unlockOnComplete)
            {
                toUnlockList.Add(unlock.levelIndex);
            }
            unlockOnCompleteDict[icon.levelIndex] = toUnlockList;


            MadUndo.DestroyObjectImmediate(icon.gameObject);

            var nIcon = CreateIcon(draggable.transform, name, iconTemplate);
            nIcon.transform.position    = position;
            nIcon.transform.rotation    = rotation;
            nIcon.transform.localScale  = localScale;
            nIcon.guiDepth              = baseDepth;
            nIcon.levelIndex            = levelIndex;
            nIcon.configuration         = configuration;
            nIcon.hasLevelConfiguration = true;

            createdIcons.Add(nIcon);


            var childSprites = MadTransform.FindChildren <MadSprite>(nIcon.transform);
            foreach (var cs in childSprites)
            {
                cs.guiDepth += baseDepth;
            }

            MadUndo.RegisterCreatedObjectUndo(nIcon.gameObject, "Replaced Icons");
        }

        icons = MadTransform.FindChildren <MadLevelIcon>(draggable.transform);

        // apply unlock on complete list
        foreach (var icon in createdIcons)
        {
            List <int> unlockList = unlockOnCompleteDict[icon.levelIndex];
            foreach (var unlockLevelIndex in unlockList)
            {
                var          query        = from i in icons where i.levelIndex == unlockLevelIndex select i;
                MadLevelIcon iconToUnlock = query.First();
                icon.unlockOnComplete.Add(iconToUnlock);
            }
        }
    }
    protected void SectionSprite(DisplayFlag flags)
    {
        serializedObject.Update();
        GUIDepthCheck();

        MadGUI.PropertyField(panel, "Panel", MadGUI.ObjectIsSet);
        EditorGUILayout.Space();

        MadGUI.PropertyField(visible, "Visible");

        if ((flags & DisplayFlag.WithoutMaterial) == 0)
        {
            MadGUI.PropertyFieldEnumPopup(inputType, "Input Type");
            MadGUI.Indent(() => {
                switch (sprite.inputType)
                {
                case MadSprite.InputType.SingleTexture:
                    MadGUI.PropertyField(texture, "Texture", MadGUI.ObjectIsSet);
                    MadGUI.Indent(() => {
                        MadGUI.PropertyFieldVector2(textureRepeat, "Repeat");
                        MadGUI.PropertyFieldVector2(textureOffset, "Offset");
                    });
                    break;

                case MadSprite.InputType.TextureAtlas:
                    MadGUI.PropertyField(textureAtlas, "Texture Atlas", MadGUI.ObjectIsSet);

                    if (sprite.textureAtlas != null)
                    {
                        MadAtlasUtil.AtlasField(textureAtlasSpriteGUID, sprite.textureAtlas, "Sprite", this);
                    }

                    break;

                default:
                    Debug.LogError("Unknown input type: " + sprite.inputType);
                    break;
                }
            });
        }

        MadGUI.PropertyField(hasPremultipliedAlpha, "Has Pre-Alpha");

        MadGUI.PropertyField(tint, "Tint");

        EditorGUILayout.Space();

        if ((flags & DisplayFlag.WithoutSize) == 0)
        {
            EditorGUILayout.Space();
            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button(new GUIContent("Resize To Texture",
                                                "Resizes this sprite to match texture size")))
            {
                MadUndo.RecordObject2(sprite, "Resize To Texture");
                sprite.ResizeToTexture();
                EditorUtility.SetDirty(sprite);
            }
            GUI.backgroundColor = Color.white;
            EditorGUILayout.Space();
        }

        EditorGUILayout.Space();

        MadGUI.PropertyField(pivotPoint, "Pivot Point");
        if (sprite.pivotPoint == MadSprite.PivotPoint.Custom)
        {
            MadGUI.Indent(() => {
                MadGUI.PropertyFieldVector2(customPivotPoint, "Custom Pivot Point");
            });
        }

        MadGUI.PropertyField(guiDepth, "GUI Depth");

        EditorGUILayout.Space();

        if ((flags & DisplayFlag.WithoutFill) == 0)
        {
            MadGUI.PropertyField(fillType, "Fill Type");
            EditorGUILayout.Slider(fillValue, 0, 1, "Fill Value");

            if (sprite.fillType == MadSprite.FillType.RadialCCW || sprite.fillType == MadSprite.FillType.RadialCW)
            {
                MadGUI.PropertyFieldSlider(radialFillOffset, -1, 1, "Offset");
                MadGUI.PropertyFieldSlider(radialFillLength, 0, 1, "Length");
            }
        }

        if (showLiveBounds)
        {
            GUILayout.Label("Sprite Border", "HeaderLabel");
            EditorGUILayout.Space();
            if (sprite.CanDraw())
            {
                FieldLiveBounds();
            }
            else
            {
                MadGUI.Info("More settings will be available when the sprite texture or atlas is set.");
            }
        }

        serializedObject.ApplyModifiedProperties();
    }
 void MoveToTop()
 {
     MadUndo.RecordObject2(configuration, "Move '" + list.selectedItem.level.name + "' To Top");
     list.selectedItem.level.order = int.MinValue;
     Reorder();
 }
 void MoveDown()
 {
     MadUndo.RecordObject2(configuration, "Move '" + list.selectedItem.level.name + "' Down");
     MoveWith(1);
 }
 void MoveUp()
 {
     MadUndo.RecordObject2(configuration, "Move '" + list.selectedItem.level.name + "' Up");
     MoveWith(-1);
 }
    public override void OnInspectorGUI()
    {
        if (MadTrialEditor.isTrialVersion && MadTrialEditor.expired)
        {
            MadTrialEditor.OnEditorGUIExpired("Mad Level Manager");
            return;
        }

        LoadTextures(); // loading textures with delay to prevent editor errors
        CheckAssetLocation();
        ActiveInfo();

        GUIGroupPopup();

        LoadItems();

        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical(GUILayout.Width(1));
        GUILayout.Space(200);
        EditorGUILayout.EndVertical();
        list.Draw();
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = Color.green;
        if (GUILayout.Button("Add"))
        {
            AddLevel();
        }
        GUI.backgroundColor = Color.white;

        GUI.enabled         = list.selectedItem != null;
        GUI.backgroundColor = Color.red;
        if (GUILayout.Button("Remove") || GUI.enabled && Event.current.keyCode == KeyCode.Delete)
        {
            RemoveLevel();
        }
        GUI.backgroundColor = Color.white;

        GUILayout.FlexibleSpace();

        GUILayout.Label("Move");

        if (GUILayout.Button("Down"))
        {
            MoveDown();
            configuration.SetDirty();
        }

        if (GUILayout.Button("Up"))
        {
            MoveUp();
            configuration.SetDirty();
        }

        GUILayout.Space(10);

        if (GUILayout.Button("Bottom"))
        {
            MoveToBottom();
            configuration.SetDirty();
        }

        if (GUILayout.Button("Top"))
        {
            MoveToTop();
            configuration.SetDirty();
        }

        GUI.enabled = true;

        EditorGUILayout.EndHorizontal();

        MadGUI.IndentBox("Level Properties", () => {
            var item  = list.selectedItem;
            var items = list.selectedItems;

            if (item == null)
            {
                item        = new LevelItem(configuration);
                GUI.enabled = false;
            }

            MadUndo.RecordObject(configuration, "Edit '" + item.level.name + "'");
            EditorGUI.BeginChangeCheck();

            EditorGUILayout.BeginHorizontal();

            EditorGUI.BeginChangeCheck();
            UnityEngine.Object sceneValue = null;
            if (!multiSelection)
            {
                MadGUI.Validate(() => item.level.sceneObject != null, () => {
                    sceneValue =
                        EditorGUILayout.ObjectField("Scene", item.level.sceneObject, typeof(UnityEngine.Object), false);
                });
            }
            else
            {
                bool unified = (from i in items select i.level.sceneObject).Distinct().Count() == 1;
                if (unified)
                {
                    sceneValue =
                        EditorGUILayout.ObjectField("Scene", item.level.sceneObject, typeof(UnityEngine.Object), false);
                }
                else
                {
                    sceneValue = EditorGUILayout.ObjectField("Scene", null, typeof(UnityEngine.Object), false);
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                MadUndo.RecordObject2(target, "Changed Level Scene");
                foreach (var levelItem in items)
                {
                    levelItem.level.sceneObject = sceneValue;
                }
            }


            GUI.backgroundColor = Color.yellow;
            if (GUILayout.Button("Set Current", GUILayout.Width(85)))
            {
                MadUndo.RecordObject2(target, "Change Scene");
#if UNITY_5 && !(UNITY_5_0 || UNITY_5_1 || UNITY_5_2)
                Scene activeScene = SceneManager.GetActiveScene();
                var obj           = AssetDatabase.LoadAssetAtPath(activeScene.name, typeof(UnityEngine.Object));
#else
                var obj = AssetDatabase.LoadAssetAtPath(EditorApplication.currentScene, typeof(UnityEngine.Object));
#endif

                if (obj != null)
                {
                    foreach (var levelItem in items)
                    {
                        levelItem.level.sceneObject = obj;
                    }
                }
                else
                {
                    EditorUtility.DisplayDialog("Scene not saved", "Current scene is not saved. Please save it first (CTRL+S).", "OK");
                }
            }
            GUI.backgroundColor = Color.white;

            EditorGUILayout.EndHorizontal();
            if (!CheckAssetIsScene(item.level.sceneObject))
            {
                item.level.sceneObject = null;
            }

            MadGUI.Validate(() => !string.IsNullOrEmpty(item.level.name), () => {
                GUI.SetNextControlName("level name"); // needs names to unfocus
                using (MadGUI.EnabledIf(!multiSelection)) {
                    if (!multiSelection)
                    {
                        EditorGUI.BeginChangeCheck();
                        var value = EditorGUILayout.TextField("Level Name", item.level.name);
                        if (EditorGUI.EndChangeCheck())
                        {
                            MadUndo.RecordObject2(target, "Changed Level Name");
                            item.level.name = value;
                        }
                    }
                    else
                    {
                        EditorGUILayout.TextField("Level Name", "-");
                    }
                }
            });


            // level type
            MadLevel.Type typeValue = default(MadLevel.Type);
            EditorGUI.BeginChangeCheck();
            if (!multiSelection)
            {
                typeValue = (MadLevel.Type)EditorGUILayout.EnumPopup("Type", item.level.type);
            }
            else
            {
                bool unified = (from i in items select i.level.type).Distinct().Count() == 1;
                if (unified)
                {
                    typeValue = (MadLevel.Type)EditorGUILayout.EnumPopup("Type", item.level.type);
                }
                else
                {
                    int val = EditorGUILayout.Popup("Type", -1, Enum.GetNames(typeof(MadLevel.Type)));
                    if (val != -1)
                    {
                        typeValue = (MadLevel.Type)val;
                    }
                }
            }

            if (EditorGUI.EndChangeCheck())
            {
                MadUndo.RecordObject2(target, "Changed Level Type");
                foreach (var levelItem in items)
                {
                    levelItem.level.type = typeValue;
                }
            }


            GUI.SetNextControlName("arguments"); // needs names to unfocus
            if (!multiSelection)
            {
                EditorGUI.BeginChangeCheck();
                var value = EditorGUILayout.TextField("Arguments", item.level.arguments);
                if (EditorGUI.EndChangeCheck())
                {
                    MadUndo.RecordObject2(target, "Changed Level Arguments");
                    item.level.arguments = value;
                }
            }
            else
            {
                bool unified = (from i in items select i.level.arguments).Distinct().Count() == 1;
                EditorGUI.BeginChangeCheck();
                string value = "";
                if (unified)
                {
                    value = EditorGUILayout.TextField("Arguments", item.level.arguments);
                }
                else
                {
                    value = EditorGUILayout.TextField("Arguments", "-");
                }
                if (EditorGUI.EndChangeCheck())
                {
                    MadUndo.RecordObject2(target, "Changed Level Arguments");
                    foreach (var levelItem in items)
                    {
                        levelItem.level.arguments = value;
                    }
                }
            }

            if (MadGUI.Foldout("Locking", false))
            {
                using (MadGUI.Indent()) {
                    bool lockedByDefultState = false;
                    if (multiSelection)
                    {
                        bool unified = (from i in items select i.level.lockedByDefault).Distinct().Count() == 1;
                        if (unified && (item.level.lockedByDefault))
                        {
                            lockedByDefultState = true;
                        }
                    }
                    else
                    {
                        lockedByDefultState = item.level.lockedByDefault;
                    }

                    EditorGUI.BeginChangeCheck();
                    GUI.SetNextControlName("locked by default"); // needs names to unfocus
                    bool lockedByDefaultValue = EditorGUILayout.Toggle("Locked By Default", lockedByDefultState);
                    if (EditorGUI.EndChangeCheck())
                    {
                        MadUndo.RecordObject2(target, "Changed Locked By Default");
                        foreach (var levelItem in items)
                        {
                            levelItem.level.lockedByDefault = lockedByDefaultValue;
                        }
                    }
                }
                EditorGUILayout.Space();
            }

            if (MadGUI.Foldout("Extensions", false))
            {
                using (MadGUI.Indent()) {
                    EditorGUI.BeginChangeCheck();
                    int extensionIndex = -1;

                    if (!multiSelection)
                    {
                        extensionIndex = configuration.extensions.FindIndex((e) => e == item.level.extension) + 1;
                    }
                    else
                    {
                        bool unified = (from i in items select i.level.extension).Distinct().Count() == 1;
                        if (unified)
                        {
                            extensionIndex = configuration.extensions.FindIndex((e) => e == item.level.extension) + 1;
                        }
                    }

                    extensionIndex = MadGUI.DynamicPopup(extensionIndex, "Extension", configuration.extensions.Count + 1,
                                                         (index) => {
                        if (index == 0)
                        {
                            return("(none)");
                        }
                        else
                        {
                            return(configuration.extensions[index - 1].name);
                        }
                    });
                    if (EditorGUI.EndChangeCheck())
                    {
                        MadUndo.RecordObject2(target, "Changed Extension For Level");

                        foreach (var levelItem in items)
                        {
                            if (extensionIndex == 0)
                            {
                                levelItem.level.extension = null;
                            }
                            else
                            {
                                levelItem.level.extension = configuration.extensions[extensionIndex - 1];
                            }
                        }

                        configuration.SetDirty();
                    }

                    bool enabledState = GUI.enabled;
                    GUI.enabled       = true;
                    if (MadGUI.Button("Open Extension Editor", Color.magenta))
                    {
                        MadLevelExtensionEditor.Show(configuration);
                    }
                    GUI.enabled = enabledState;

                    EditorGUILayout.Space();
                }
            }

            EditorGUI.BeginChangeCheck();
            int groupIndex = GroupToIndex(item.level.group);
            groupIndex     = EditorGUILayout.Popup("Move To Group:", groupIndex, GroupNames());
            if (EditorGUI.EndChangeCheck())
            {
                var @group = IndexToGroup(groupIndex);
                MadUndo.RecordObject2(target, "Move Levels To Group " + @group.name);
                foreach (var levelItem in items)
                {
                    levelItem.level.group = @group;
                }
            }


            if (EditorGUI.EndChangeCheck())
            {
                configuration.SetDirty();
            }

            if (inspectorAddons.Count > 0)
            {
                EditorGUILayout.Space();
            }

            foreach (var addon in inspectorAddons)
            {
                addon.OnInspectorGUI(item.level);
            }

            GUI.enabled = true;
        });

        EditorGUILayout.Space();
        EditorGUILayout.BeginHorizontal();
        if (GUILayout.Button("Help"))
        {
            Help.BrowseURL(MadLevelHelp.LevelConfigurationHelp);
        }
        GUILayout.FlexibleSpace();
        EditorGUILayout.EndHorizontal();

        if (!configuration.IsValid())
        {
            MadGUI.Error("Configuration is invalid. Please make sure that:\n"
                         + "- There's no levels with \"!!!\" icon. These levels may have duplicated name or missing scene.\n"
                         + "- All your extensions have no missing scenes (in Extension Editor)"
                         );
        }

        if (configuration.active && !MadLevelConfigurationEditor.CheckBuildSynchronized(configuration))
        {
            if (MadGUI.ErrorFix(
                    "Build configuration is not in synch with level configuration.",
                    "Synchronize Now"))
            {
                MadLevelConfigurationEditor.SynchronizeBuild(configuration);
            }
        }

        ExecuteDelayed();
    }