Exemplo n.º 1
0
    void BuildDragging(MadDragStopDraggable dragHandler, int dragStops)
    {
        var pages = MadTransform.FindChildren <Transform>(dragHandler.transform, (t) => t.name.StartsWith("Page"), 0);

        pages.Sort((a, b) => { return(a.localPosition.x.CompareTo(b.localPosition.x)); });

        for (int i = 0; i < pages.Count; ++i)
        {
            int dragStopIndex = dragHandler.AddDragStop(pages[i].localPosition.x, 0);
            var page          = new Page(dragStopIndex);
            this.pages.Add(page);
        }
    }
Exemplo n.º 2
0
    // builds level icons that are absent now
    void Build()
    {
        // create or get a draggable
        draggable = MadTransform.GetOrCreateChild <MadDragStopDraggable>(transform, "Draggable");

        draggable.dragStopCallback = (index) => {
            pageCurrentIndex = index;
        };

        float startX = -pixelsWidth / 2;
        float startY = pixelsHeight / 2;

        float dx = pixelsWidth / (gridWidth + 1);
        float dy = -pixelsHeight / (gridHeight + 1);

        int levelNumber = 1;

        MadLevelIcon previousIcon = null;

        int levelCount = configuration.LevelCount(MadLevel.Type.Level);
        int levelIndex = 0;

        int pageIndex = 0;

        while (levelIndex < levelCount)
        {
            Transform page = MadTransform.FindChild <Transform>(draggable.transform, (t) => t.name == "Page " + (pageIndex + 1));
            bool      createPageInstance = page == null;

            if (createPageInstance)
            {
                page = MadTransform.CreateChild <Transform>(draggable.transform, "Page " + (pageIndex + 1));
            }

            if (createPageInstance || generate)
            {
                page.localPosition = new Vector3(pagesXOffset * pageIndex, 0, 0);
            }


            for (int y = 1; y <= gridHeight && levelIndex < levelCount; ++y)
            {
                for (int x = 1; x <= gridWidth && levelIndex < levelCount; ++x, levelIndex++)
                {
                    // update info: in previous versions page was nested directly under draggable
                    // now they should be placed inside "Page X" transforms
                    MadLevelIcon levelIcon;

                    // look directly under Draggable
                    levelIcon = MadTransform.FindChild <MadLevelIcon>(
                        draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
                    if (levelIcon != null)
                    {
                        // move to page
                        levelIcon.transform.parent = page;
                    }
                    else
                    {
                        // find under the page
                        levelIcon = MadTransform.FindChild <MadLevelIcon>(
                            page.transform, (ic) => ic.levelIndex == levelIndex, 0);
                    }

                    bool createNewInstance = levelIcon == null;
                    var  level             = configuration.GetLevel(MadLevel.Type.Level, levelIndex);

                    if (createNewInstance)
                    {
                        levelIcon = MadTransform.CreateChild(
                            page.transform, level.name, iconTemplate);
                    }
                    else
                    {
                        levelIcon.name = level.name;
                    }

                    levelIcon.gameObject.hideFlags = generate ? HideFlags.HideInHierarchy : 0;

                    if (!MadGameObject.IsActive(levelIcon.gameObject))
                    {
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }

                    levelIcon.levelIndex            = levelIndex;
                    levelIcon.configuration         = configuration;
                    levelIcon.hasLevelConfiguration = true;

                    if (generate || createNewInstance)
                    {
                        levelIcon.pivotPoint = MadSprite.PivotPoint.Center;

                        levelIcon.transform.localPosition =
                            new Vector3(startX + dx * x + iconOffset.x, startY + dy * y + iconOffset.y, 0);

                        levelIcon.transform.localScale = new Vector3(iconScale.x, iconScale.y, 1);

                        if (levelIcon.levelNumber != null)
                        {
                            levelIcon.levelNumber.text = levelNumber.ToString();
                        }
                    }

                    if (previousIcon != null)
                    {
                        if (createNewInstance)
                        {
                            previousIcon.unlockOnComplete.Add(levelIcon);
                        }
                    }
                    else
                    {
                        if (generate)
                        {
                            levelIcon.locked = false;
                        }
                    }

                    previousIcon = levelIcon;
                    levelNumber++;
                }
            }

            pageIndex++;
        }

        BuildSlideIcons();
        BuildDragging(draggable, (int)Mathf.Ceil((float)levelCount / (gridWidth * gridHeight)));

        // enable/disable selection based on hide settings
        var sprites = GetComponentsInChildren <MadSprite>();

        foreach (var sprite in sprites)
        {
            sprite.editorSelectable = !generate;
        }
    }
Exemplo n.º 3
0
    // builds level icons that are absent now
    private void Build(bool forceDelete)
    {
        // create or get a draggable
        draggable = MadTransform.GetOrCreateChild <MadDragStopDraggable>(transform, "Draggable");

        draggable.dragStopCallback = OnDragStopCallback;

        float startX = -pixelsWidth / 2;
        float startY = pixelsHeight / 2;

        float dx = pixelsWidth / (gridWidth + 1);
        float dy = -pixelsHeight / (gridHeight + 1);

        MadLevelIcon previousIcon = null;

        int levelCount = currentConfiguration.LevelCount(MadLevel.Type.Level, configurationGroup);
        int levelIndex = 0;

        int pageIndex = 0;

        while (levelIndex < levelCount)
        {
            Transform page = MadTransform.FindChild <Transform>(draggable.transform,
                                                                (t) => t.name == "Page " + (pageIndex + 1));
            bool createPageInstance = page == null;

            if (createPageInstance)
            {
                page           = MadTransform.CreateChild <Transform>(draggable.transform, "Page " + (pageIndex + 1));
                page.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;
            }

            Transform pageAnchor = MadTransform.FindChild <Transform>(draggable.transform,
                                                                      (t) => t.name == "Anchor " + (pageIndex + 1));
            if (pageAnchor == null)
            {
                pageAnchor = MadTransform.CreateChild <Transform>(draggable.transform, "Anchor " + (pageIndex + 1));
                pageAnchor.gameObject.AddComponent <MadFollow>();
            }

            var followPage = pageAnchor.GetComponent <MadFollow>();
            followPage.followTransform = page;

            if (createPageInstance || generate)
            {
                switch (pagingMethod)
                {
                case PagingMethod.HorizontalSimple:
                    page.localPosition = ComputePageOffsetHoriz(pageIndex);
                    break;

                case PagingMethod.VerticalSimple:
                    page.localPosition = ComputePageOffsetVert(pageIndex);
                    break;

                case PagingMethod.HorizontalZoom:
                    page.localPosition = ComputePageOffsetHoriz(pageIndex);
                    break;

                case PagingMethod.VerticalZoom:
                    page.localPosition = ComputePageOffsetVert(pageIndex);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            int  levelPageIndex = 0;
            bool stop           = false;
            for (int y = 1; y <= gridHeight && levelIndex < levelCount; ++y)
            {
                if (stop)
                {
                    break;
                }

                for (int x = 1; x <= gridWidth && levelIndex < levelCount; ++x, levelIndex++, levelPageIndex++)
                {
                    if (limitLevelsPerPage && generate && levelPageIndex == levelsPerPage)
                    {
                        stop = true;
                        break;
                    }

                    // update info: in previous versions page was nested directly under draggable
                    // now they should be placed inside "Page X" transforms
                    MadLevelIcon levelIcon = null;

                    if (!forceDelete)
                    {
                        // look directly under Draggable
                        levelIcon = MadTransform.FindChild <MadLevelIcon>(
                            draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        if (levelIcon != null)
                        {
                            // move to page
                            levelIcon.transform.parent = page;
                        }
                        else
                        {
                            // find under the page
                            levelIcon = MadTransform.FindChild <MadLevelIcon>(
                                page.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        }
                    }

                    var  level             = currentConfiguration.GetLevel(MadLevel.Type.Level, configurationGroup, levelIndex);
                    bool createNewInstance = levelIcon == null;

                    if (createNewInstance)
                    {
                        levelIcon = CreateIcon(
                            page.transform, level.name, iconTemplate);
                    }
                    else
                    {
                        levelIcon.name = level.name;
                    }

                    levelIcon.gameObject.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;

                    levelIcon.levelGroup            = configurationGroup;
                    levelIcon.levelIndex            = levelIndex;
                    levelIcon.configuration         = currentConfiguration;
                    levelIcon.hasLevelConfiguration = true;

                    if (!MadGameObject.IsActive(levelIcon.gameObject))
                    {
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }
                    else
                    {
                        // re-enable icon to reload its properties
                        MadGameObject.SetActive(levelIcon.gameObject, false);
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }

                    if (generate || createNewInstance)
                    {
                        levelIcon.pivotPoint = MadSprite.PivotPoint.Center;

                        if (!generate)
                        {
                            levelIcon.transform.localPosition =
                                new Vector3(startX + dx * x + iconOffset.x, startY + dy * y + iconOffset.y, 0);
                        }
                        else
                        {
                            levelIcon.transform.localPosition = IconGeneratedPosition(levelIndex, levelCount, x - 1,
                                                                                      y - 1);
                        }

                        levelIcon.transform.localScale = new Vector3(iconScale.x, iconScale.y, 1);

                        if (levelIcon.levelNumber != null)
                        {
                            levelIcon.levelNumber.text = GetEnumerationValue(levelIndex);
                        }
                    }

                    if (previousIcon != null)
                    {
                        if (createNewInstance)
                        {
                            previousIcon.unlockOnComplete.Add(levelIcon);
                        }
                    }

                    if (!Application.isPlaying || !MadLevelProfile.IsLockedSet(level.name))
                    {
                        levelIcon.locked = levelIcon.level.lockedByDefault;
                    }

                    previousIcon = levelIcon;
                }
            }

            pageIndex++;
        }

        BuildSlideIcons();
        BuildDragging();

        // enable/disable selection based on hide settings
        var sprites = GetComponentsInChildren <MadSprite>();

        foreach (var sprite in sprites)
        {
            sprite.editorSelectable = !generate;
        }

#if UNITY_EDITOR
        EditorApplication.delayCall += () => EditorUtility.SetDirty(this);
#endif
    }
Exemplo n.º 4
0
    // builds level icons that are absent now
    private void Build(bool forceDelete) {
        // create or get a draggable
        draggable = MadTransform.GetOrCreateChild<MadDragStopDraggable>(transform, "Draggable");

        draggable.dragStopCallback = OnDragStopCallback;

        float startX = -pixelsWidth / 2;
        float startY = pixelsHeight / 2;

        float dx = pixelsWidth / (gridWidth + 1);
        float dy = -pixelsHeight / (gridHeight + 1);

        MadLevelIcon previousIcon = null;

        int levelCount = currentConfiguration.LevelCount(MadLevel.Type.Level, configurationGroup);
        int levelIndex = 0;

        int pageIndex = 0;

        while (levelIndex < levelCount) {
            Transform page = MadTransform.FindChild<Transform>(draggable.transform,
                (t) => t.name == "Page " + (pageIndex + 1));
            bool createPageInstance = page == null;

            if (createPageInstance) {
                page = MadTransform.CreateChild<Transform>(draggable.transform, "Page " + (pageIndex + 1));
                page.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;
            }

            Transform pageAnchor = MadTransform.FindChild<Transform>(draggable.transform,
                (t) => t.name == "Anchor " + (pageIndex + 1));
            if (pageAnchor == null) {
                pageAnchor = MadTransform.CreateChild<Transform>(draggable.transform, "Anchor " + (pageIndex + 1));
                pageAnchor.gameObject.AddComponent<MadFollow>();
            }

            var followPage = pageAnchor.GetComponent<MadFollow>();
            followPage.followTransform = page;

            if (createPageInstance || generate) {
                switch (pagingMethod) {
                    case PagingMethod.HorizontalSimple:
                        page.localPosition = ComputePageOffsetHoriz(pageIndex);
                        break;
                    case PagingMethod.VerticalSimple:
                        page.localPosition = ComputePageOffsetVert(pageIndex);
                        break;
                    case PagingMethod.HorizontalZoom:
                        page.localPosition = ComputePageOffsetHoriz(pageIndex);
                        break;
                    case PagingMethod.VerticalZoom:
                        page.localPosition = ComputePageOffsetVert(pageIndex);
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
                
            }

            int levelPageIndex = 0;
            bool stop = false;
            for (int y = 1; y <= gridHeight && levelIndex < levelCount; ++y) {
                if (stop) {
                    break;
                }

                for (int x = 1; x <= gridWidth && levelIndex < levelCount; ++x, levelIndex++, levelPageIndex++) {
                    if (limitLevelsPerPage && generate && levelPageIndex == levelsPerPage) {
                        stop = true;
                        break;
                    }

                    // update info: in previous versions page was nested directly under draggable
                    // now they should be placed inside "Page X" transforms
                    MadLevelIcon levelIcon = null;

                    if (!forceDelete) {
                        // look directly under Draggable
                        levelIcon = MadTransform.FindChild<MadLevelIcon>(
                            draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        if (levelIcon != null) {
                            // move to page
                            levelIcon.transform.parent = page;
                        } else {
                            // find under the page
                            levelIcon = MadTransform.FindChild<MadLevelIcon>(
                                page.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        }
                    }

                    var level = currentConfiguration.GetLevel(MadLevel.Type.Level, configurationGroup, levelIndex);
                    bool createNewInstance = levelIcon == null;

                    if (createNewInstance) {
                        levelIcon = CreateIcon(
                            page.transform, level.name, iconTemplate);
                    } else {
                        levelIcon.name = level.name;
                    }

                    levelIcon.gameObject.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;

                    levelIcon.levelGroup = configurationGroup;
                    levelIcon.levelIndex = levelIndex;
                    levelIcon.configuration = currentConfiguration;
                    levelIcon.hasLevelConfiguration = true;

                    if (!MadGameObject.IsActive(levelIcon.gameObject)) {
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    } else {
                        // re-enable icon to reload its properties
                        MadGameObject.SetActive(levelIcon.gameObject, false);
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }

                    if (generate || createNewInstance) {
                        levelIcon.pivotPoint = MadSprite.PivotPoint.Center;

                        if (!generate) {
                            levelIcon.transform.localPosition =
                                new Vector3(startX + dx * x + iconOffset.x, startY + dy * y + iconOffset.y, 0);
                        } else {
                            levelIcon.transform.localPosition = IconGeneratedPosition(levelIndex, levelCount, x - 1,
                                y - 1);
                        }

                        levelIcon.transform.localScale = new Vector3(iconScale.x, iconScale.y, 1);

                        if (levelIcon.levelNumber != null) {
                            levelIcon.levelNumber.text = GetEnumerationValue(levelIndex);
                        }
                    }

                    if (previousIcon != null) {
                        if (createNewInstance) {
                            previousIcon.unlockOnComplete.Add(levelIcon);
                        }
                    }

                    if (!Application.isPlaying || !MadLevelProfile.IsLockedSet(level.name)) {
                        levelIcon.locked = levelIcon.level.lockedByDefault;
                    }

                    previousIcon = levelIcon;
                }
            }

            pageIndex++;
        }

        BuildSlideIcons();
        BuildDragging();

        // enable/disable selection based on hide settings
        var sprites = GetComponentsInChildren<MadSprite>();
        foreach (var sprite in sprites) {
            sprite.editorSelectable = !generate;
        }

#if UNITY_EDITOR
        EditorApplication.delayCall += () => EditorUtility.SetDirty(this);
#endif
    }
Exemplo n.º 5
0
    private void BuildDragging(MadDragStopDraggable dragHandler, int dragStops) {
        var pages = MadTransform.FindChildren<Transform>(dragHandler.transform, (t) => t.name.StartsWith("Page"), 0);
        pages.Sort((a, b) => { return a.localPosition.x.CompareTo(b.localPosition.x); });

        dragHandler.ClearDragStops();

        for (int i = 0; i < pages.Count; ++i) {
            int dragStopIndex = dragHandler.AddDragStop(pages[i].localPosition.x, 0);
            var page = new Page(dragStopIndex);
            this.pages.Add(page);
        }
    }
Exemplo n.º 6
0
    // builds level icons that are absent now
    private void Build(bool forceDelete) {
        // create or get a draggable
        draggable = MadTransform.GetOrCreateChild<MadDragStopDraggable>(transform, "Draggable");

        draggable.dragStopCallback = (index) => {
            pageCurrentIndex = index;
        };

        float startX = -pixelsWidth / 2;
        float startY = pixelsHeight / 2;

        float dx = pixelsWidth / (gridWidth + 1);
        float dy = -pixelsHeight / (gridHeight + 1);

        MadLevelIcon previousIcon = null;

        int levelCount = configuration.LevelCount(MadLevel.Type.Level, configurationGroup);
        int levelIndex = 0;

        int pageIndex = 0;

        while (levelIndex < levelCount) {
            Transform page = MadTransform.FindChild<Transform>(draggable.transform,
                (t) => t.name == "Page " + (pageIndex + 1));
            bool createPageInstance = page == null;

            if (createPageInstance) {
                page = MadTransform.CreateChild<Transform>(draggable.transform, "Page " + (pageIndex + 1));
                page.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;
            }

            if (createPageInstance || generate) {
                page.localPosition = new Vector3(pagesXOffset * pageIndex, 0, 0);
            }


            for (int y = 1; y <= gridHeight && levelIndex < levelCount; ++y) {
                for (int x = 1; x <= gridWidth && levelIndex < levelCount; ++x, levelIndex++) {

                    // update info: in previous versions page was nested directly under draggable
                    // now they should be placed inside "Page X" transforms
                    MadLevelIcon levelIcon = null;

                    if (!forceDelete) {
                        // look directly under Draggable
                        levelIcon = MadTransform.FindChild<MadLevelIcon>(
                            draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        if (levelIcon != null) {
                            // move to page
                            levelIcon.transform.parent = page;
                        } else {
                            // find under the page
                            levelIcon = MadTransform.FindChild<MadLevelIcon>(
                                page.transform, (ic) => ic.levelIndex == levelIndex, 0);
                        }
                    }

                    var level = configuration.GetLevel(MadLevel.Type.Level, configurationGroup, levelIndex);
                    bool createNewInstance = levelIcon == null;

                    if (createNewInstance) {
                        levelIcon = CreateIcon(
                            page.transform, level.name, iconTemplate);
                    } else {
                        levelIcon.name = level.name;
                    }

                    levelIcon.gameObject.hideFlags = generate && hideManagedObjects ? HideFlags.HideInHierarchy : 0;

                    levelIcon.levelGroup = configurationGroup;
                    levelIcon.levelIndex = levelIndex;
                    levelIcon.configuration = configuration;
                    levelIcon.hasLevelConfiguration = true;

                    if (!MadGameObject.IsActive(levelIcon.gameObject)) {
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    } else {
                        // re-enable icon to reload its properties
                        MadGameObject.SetActive(levelIcon.gameObject, false);
                        MadGameObject.SetActive(levelIcon.gameObject, true);
                    }

                    if (generate || createNewInstance) {
                        levelIcon.pivotPoint = MadSprite.PivotPoint.Center;

                        if (!generate) {
                            levelIcon.transform.localPosition =
                                new Vector3(startX + dx * x + iconOffset.x, startY + dy * y + iconOffset.y, 0);
                        } else {
                            levelIcon.transform.localPosition = IconGeneratedPosition(levelIndex, levelCount, x - 1,
                                y - 1);
                        }

                        levelIcon.transform.localScale = new Vector3(iconScale.x, iconScale.y, 1);

                        if (levelIcon.levelNumber != null) {
                            levelIcon.levelNumber.text = GetEnumerationValue(levelIndex);
                        }
                    }

                    if (previousIcon != null) {
                        if (createNewInstance) {
                            previousIcon.unlockOnComplete.Add(levelIcon);
                        }
                    }

                    if (!Application.isPlaying || !MadLevelProfile.IsLockedSet(level.name)) {
                        levelIcon.locked = levelIcon.level.lockedByDefault;
                    }

                    previousIcon = levelIcon;
                }
            }

            pageIndex++;
        }

        BuildSlideIcons();
        BuildDragging(draggable, (int) Mathf.Ceil((float) levelCount / (gridWidth * gridHeight)));

        // enable/disable selection based on hide settings
        var sprites = GetComponentsInChildren<MadSprite>();
        foreach (var sprite in sprites) {
            sprite.editorSelectable = !generate;
        }
    }