コード例 #1
0
    private void StartLoaded()
    {
        state = State.Loaded;

        onLoadedMessage.Execute();

        if (testMode && TestLevelDefined())
        {
            TestLoadLevel();
        }

        if (whenLevelLoaded != WhenLevelLoaded.ShowImmediately)
        {
            for (int i = 0; i < changeDisable.Count; i++)
            {
                var toDisable = changeDisable[i];
                if (toDisable != null)
                {
                    MadGameObject.SetActive(toDisable.gameObject, false);
                }
            }

            for (int i = 0; i < changeEnable.Count; i++)
            {
                var toEnable = changeEnable[i];
                if (toEnable != null)
                {
                    MadGameObject.SetActive(toEnable.gameObject, true);
                }
            }
        }
    }
コード例 #2
0
 void OnDisable()
 {
     if (drawCall != null)
     {
         MadGameObject.SetActive(drawCall.gameObject, false);
     }
 }
コード例 #3
0
    void CleanUp(bool forceDelete)
    {
        int levelCount = configuration.LevelCount(MadLevel.Type.Level);
        var children   = MadTransform.FindChildren <MadLevelIcon>(transform, (icon) => icon.hasLevelConfiguration);

        if (forceDelete)
        {
            foreach (var child in children)
            {
                MadGameObject.SafeDestroy(child.gameObject);
            }
        }
        else
        {
            var sorted = from c in children orderby c.levelIndex ascending select c;

            foreach (MadLevelIcon levelIcon in sorted)
            {
                if (levelIcon.levelIndex >= levelCount)
                {
                    // disable leftovers
                    MadGameObject.SetActive(levelIcon.gameObject, false);
                }
            }
        }
    }
コード例 #4
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;
    }
コード例 #5
0
 void OnDisable()
 {
     for (int i = 0; i < drawCalls.Count; i++)
     {
         var drawCall = drawCalls[i];
         MadGameObject.SetActive(drawCall.gameObject, false);
     }
 }
コード例 #6
0
ファイル: MadLevelGridLayout.cs プロジェクト: kewls74/game1
    static void SlideSetActive(MadSprite icon, bool act)
    {
        bool currentlyActive = MadGameObject.IsActive(icon.gameObject);

        if (currentlyActive != act)
        {
            MadGameObject.SetActive(icon.gameObject, act);
        }
    }
コード例 #7
0
ファイル: MadLevelIcon.cs プロジェクト: MatSe91/Lightbeam
    protected override void Update()
    {
        base.Update();

        if (justEnabled)
        {
            if (Application.isPlaying)
            {
                if (isTemplate)
                {
                    MadGameObject.SetActive(gameObject, false);
                }

                // completed property object is optional
                // if it's not present, check the completed property manually
                if (completedProperty == null)
                {
                    if (level != null)
                    {
                        completed = MadLevelProfile.IsCompleted(level.name);
                    }
                }

                onMouseUp += (sprite) => Activate();
                onTap     += (sprite) => Activate();

                if (!isTemplate)
                {
                    if (!canFocusIfLocked && locked)
                    {
                        var sprite = GetComponent <MadSprite>();
                        sprite.eventFlags = sprite.eventFlags & ~MadSprite.EventFlags.Focus;
                    }
                }
            }

            // init child objects visibility
            if (level != null)
            {
                ChangeState(showWhenLevelLocked, locked);
                ChangeState(showWhenLevelUnlocked, !locked);
                ChangeState(showWhenLevelCompleted, completed);
                ChangeState(showWhenLevelNotCompleted, !completed);

                // if this level is mark as unlocked, make sure that it has a profile entry
                // this is a workaround for situation when level is unlocked, but then level order is changed
                if (!locked && Application.isPlaying)
                {
                    MadLevelProfile.SetLocked(level.name, false);
                }
            }

            justEnabled = false;
        }
    }
コード例 #8
0
    // deactivates all other icons under the draggable than given
    private void DeactivateAllOther(HashSet <MadLevelIcon> activeIcons)
    {
        var allIcons = MadTransform.FindChildren <MadLevelIcon>(draggable.transform);

        foreach (var icon in allIcons)
        {
            if (!activeIcons.Contains(icon))
            {
                MadGameObject.SetActive(icon.gameObject, false);
            }
        }
    }
コード例 #9
0
    public void Destroy()
    {
        MadGameObject.SetActive(gameObject, false);

#if UNITY_EDITOR
        EditorApplication.delayCall += () => {
            DestroyImmediate(gameObject);
        };
#else
        MadGameObject.SafeDestroy(gameObject);
#endif
    }
コード例 #10
0
    static void SlideSetActive(MadSprite icon, bool act)
    {
        if (!MadGameObject.IsActive(icon.gameObject))
        {
            MadGameObject.SetActive(icon.gameObject, true);
        }

        bool currentlyActive = icon.visible;

        if (currentlyActive != act)
        {
            icon.visible = act;
        }
    }
コード例 #11
0
    void InitTemplates(MadRootNode root, out MadLevelIcon icon, out MadSprite slideLeftSprite,
                       out MadSprite slideRightSprite)
    {
        var panel     = MadTransform.FindChild <MadPanel>(root.transform);
        var templates = MadTransform.CreateChild(panel.transform, "Templates");

        GameObject iconPrefab       = (GameObject)AssetDatabase.LoadAssetAtPath(IconPrefab, typeof(GameObject));
        GameObject slideLeftPrefab  = (GameObject)AssetDatabase.LoadAssetAtPath(SlideLeftPrefab, typeof(GameObject));
        GameObject slideRightPrefab = (GameObject)AssetDatabase.LoadAssetAtPath(SlideRightPrefab, typeof(GameObject));

        if (MadGameObject.AnyNull(iconPrefab, slideLeftPrefab, slideRightPrefab))
        {
            Debug.LogWarning("I cannot find all needed prefabs to create example templates. Have you moved Mad Level "
                             + "Manager directory to other than default place?");
        }

        if (iconPrefab != null)
        {
            var obj = MadTransform.CreateChild(templates.transform, "icon", iconPrefab);
            icon = obj.GetComponent <MadLevelIcon>();
        }
        else
        {
            icon = null;
        }

        if (slideLeftPrefab != null)
        {
            var slide = MadTransform.CreateChild(templates.transform, "slide left", slideLeftPrefab);
            slideLeftSprite = slide.GetComponent <MadSprite>();
        }
        else
        {
            slideLeftSprite = null;
        }

        if (slideRightPrefab != null)
        {
            var slide = MadTransform.CreateChild(templates.transform, "slide right", slideRightPrefab);
            slideRightSprite = slide.GetComponent <MadSprite>();
        }
        else
        {
            slideRightSprite = null;
        }

        MadGameObject.SetActive(templates, false);
    }
コード例 #12
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    void OnEnable()
    {
        if (drawCall == null)
        {
            drawCall = MadDrawCall.Create();
            drawCall.gameObject.layer = gameObject.layer;

            MadTransform.SetLocalScale(drawCall.transform, transform.lossyScale);
        }

        panel = GetComponent <MadPanel>();

        if (drawCall != null)
        {
            MadGameObject.SetActive(drawCall.gameObject, true);
        }
    }
コード例 #13
0
    // ===========================================================
    // Methods for/from SuperClass/Interfaces
    // ===========================================================

    // ===========================================================
    // Methods
    // ===========================================================

    void OnEnable()
    {
        panel = GetComponent <MadPanel>();

        // enable existing draw calls
        for (int i = 0; i < drawCalls.Count; i++)
        {
            var drawCall = drawCalls[i];
            if (drawCall == null)
            {
                drawCalls.RemoveAt(i);
                i--;
            }
            else
            {
                MadGameObject.SetActive(drawCall.gameObject, true);
            }
        }
    }
コード例 #14
0
    // ===========================================================
    // Methods
    // ===========================================================

    void FirstUpdate()
    {
        var layout = MadLevelLayout.current;

        if (layout.twoStepActivationType == MadLevelAbstractLayout.TwoStepActivationType.Disabled)
        {
            Debug.LogError("Input controller cannot work when two step activation is disabled! Please enable it!", this);
            MadGameObject.SetActive(gameObject, false);
            return;
        }

        if (layout.twoStepActivationType == MadLevelAbstractLayout.TwoStepActivationType.OnlyOnMobiles && !onlyOnMobiles)
        {
            Debug.LogError("Two step activation is set to work on mobiles, but input controler is not!", this);
            MadGameObject.SetActive(gameObject, false);
            return;
        }

        isMobile = SystemInfo.deviceType == DeviceType.Handheld;

        DoActivateOnStart();
    }
コード例 #15
0
    private MadDrawCall NextDrawCall()
    {
        MadDrawCall drawCall;

        if (nextDrawCall >= drawCalls.Count)
        {
            // create new draw call
            drawCall = MadDrawCall.Create();
            drawCall.gameObject.layer = gameObject.layer;

            MadTransform.SetLocalScale(drawCall.transform, transform.lossyScale);
            drawCalls.Add(drawCall);
            nextDrawCall++;
        }
        else
        {
            drawCall = drawCalls[nextDrawCall++];
            MadGameObject.SetActive(drawCall.gameObject, true);
        }

        return(drawCall);
    }
コード例 #16
0
    private void CleanUp(bool forceDelete)
    {
        int levelCount = currentConfiguration.LevelCount(MadLevel.Type.Level, configurationGroup);
        var children   = MadTransform.FindChildren <MadLevelIcon>(transform, (icon) => icon.hasLevelConfiguration);

        if (forceDelete)
        {
            foreach (var child in children)
            {
                DestroyImmediate(child.gameObject);
            }

            // remove all pages
            var pages = MadTransform.FindChildren <Transform>(transform, (t) => t.name.StartsWith("Page "));
            foreach (var page in pages)
            {
                DestroyImmediate(page.gameObject);
            }
        }
        else
        {
            var sorted = from c in children orderby c.levelIndex ascending select c;

            foreach (MadLevelIcon levelIcon in sorted)
            {
                if (levelIcon.levelIndex >= levelCount)
                {
                    // disable leftovers
                    MadGameObject.SetActive(levelIcon.gameObject, false);
                }
            }
        }

        // remove slides
        ClearSlide("SlideLeftAnchor");
        ClearSlide("SlideRightAnchor");
    }
コード例 #17
0
    private static void Initialize() {
        var guiRootPrefab = AssetDatabase.LoadAssetAtPath(
            AssetDatabase.GUIDToAssetPath(GUIRootGUID), typeof(GameObject)) as GameObject;
        var loadingScriptPrefab = AssetDatabase.LoadAssetAtPath(
            AssetDatabase.GUIDToAssetPath(LoadingScriptGUID), typeof (GameObject)) as GameObject;

        var guiRootInstance = Object.Instantiate(guiRootPrefab) as GameObject;
        var loadingScriptInstance = Object.Instantiate(loadingScriptPrefab) as GameObject;

        guiRootInstance.name = guiRootPrefab.name;
        loadingScriptInstance.name = loadingScriptPrefab.name;

        PrefabUtility.DisconnectPrefabInstance(guiRootInstance);
        PrefabUtility.DisconnectPrefabInstance(loadingScriptInstance);

        var loadingBar = MadTransform.FindChild<MadSprite>(guiRootInstance.transform, sprite => sprite.name == "bar").gameObject;
        var loadingText = MadTransform.FindChild<MadText>(guiRootInstance.transform, text => text.name == "loading text").gameObject;
        var loadedText = MadTransform.FindChild<MadText>(guiRootInstance.transform, text => text.name == "loaded text").gameObject;
        var pressAnywhereText = MadTransform.FindChild<MadText>(guiRootInstance.transform, text => text.name == "press anywhere text").gameObject;

        var loadingScreen = loadingScriptInstance.GetComponent<LoadingScreen>();

        loadingScreen.loadingBar = loadingBar;

        loadingScreen.changeDisable.Clear();
        loadingScreen.changeDisable.Add(loadingText);

        loadingScreen.changeEnable.Clear();
        loadingScreen.changeEnable.Add(loadedText);
        loadingScreen.changeEnable.Add(pressAnywhereText);

        MadGameObject.SetActive(loadedText, false);
        MadGameObject.SetActive(pressAnywhereText, false);

        new GameObject("_mlm_ignore");
    }
コード例 #18
0
    void Build()
    {
        List <MadLevelIcon> allIcons = new List <MadLevelIcon>();

        allIcons.AddRange(MadTransform.FindChildren <MadLevelIcon>(transform));

        int     levelCount    = currentConfiguration.LevelCount(MadLevel.Type.Level, configurationGroup);
        Vector2 currentOffset = Vector2.zero;

        MadLevelIcon previousIcon = null;

        // find out min and max depth
        int min, max;

        iconTemplate.MinMaxDepthRecursively(out min, out max);
        const string name = "level {0:D3}";

        HashSet <MadLevelIcon> activeIcons = new HashSet <MadLevelIcon>();

        for (int levelIndex = 0; levelIndex < levelCount; ++levelIndex)
        {
            MadLevelIcon levelIcon = MadTransform.FindChild <MadLevelIcon>(
                draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
            bool newInstance = levelIcon == null;

            // create new icon instance if it's not exists
            if (newInstance)
            {
                levelIcon = CreateIcon(draggable.transform, string.Format(name, levelIndex + 1), iconTemplate);

                // position & scale
                levelIcon.pivotPoint           = MadSprite.PivotPoint.Center;
                levelIcon.transform.localScale = Vector3.one;

                do
                {
                    levelIcon.transform.localPosition = currentOffset;
                    currentOffset += offset;
                } while (Collides(levelIcon, allIcons));

                allIcons.Add(levelIcon);
            }

            // make it active if deactivated
            if (!MadGameObject.IsActive(levelIcon.gameObject))
            {
                MadGameObject.SetActive(levelIcon.gameObject, true);
            }

            // setup level properties
            levelIcon.levelGroup            = configurationGroup;
            levelIcon.levelIndex            = levelIndex;
            levelIcon.configuration         = currentConfiguration;
            levelIcon.hasLevelConfiguration = true;

            // set level number if exists
            if (levelIcon.levelNumber != null)
            {
                levelIcon.levelNumber.text = GetEnumerationValue(levelIndex);
            }

            // level unlock if set
            if (previousIcon != null)
            {
                if (newInstance)
                {
                    previousIcon.unlockOnComplete.Add(levelIcon);
                }
            }
            else
            {
                levelIcon.locked = false;
            }

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

            previousIcon = levelIcon;

            activeIcons.Add(levelIcon);
        }

        BuildBackgroundTexture();

        DeactivateAllOther(activeIcons);
    }
コード例 #19
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;
        }
    }
コード例 #20
0
    void Build()
    {
        int     levelCount    = configuration.LevelCount(MadLevel.Type.Level);
        Vector2 currentOffset = Vector2.zero;

        MadLevelIcon previousIcon = null;

        // find out min and max depth
        int min, max;

        iconTemplate.MinMaxDepthRecursively(out min, out max);
        int depthDiff = (max - min) + 1;

        const string name = "level {0:D3}";

        for (int levelIndex = 0; levelIndex < levelCount; ++levelIndex)
        {
            MadLevelIcon levelIcon = MadTransform.FindChild <MadLevelIcon>(
                draggable.transform, (ic) => ic.levelIndex == levelIndex, 0);
            bool newInstance = levelIcon == null;

            // create new icon instance if it's not exists
            if (newInstance)
            {
                levelIcon = MadTransform.CreateChild(
                    draggable.transform, string.Format(name, levelIndex + 1), iconTemplate);

                // adjust gui depth for each icon
                levelIcon.guiDepth += levelIndex * depthDiff;
                var sprites = MadTransform.FindChildren <MadSprite>(levelIcon.transform);
                foreach (var sprite in sprites)
                {
                    sprite.guiDepth += levelIndex * depthDiff;
                }

                // position & scale
                levelIcon.pivotPoint = MadSprite.PivotPoint.Center;
                levelIcon.transform.localPosition = currentOffset;
                currentOffset += offset;

                levelIcon.transform.localScale = Vector3.one;
            }

            // make it active if deactivated
            if (!MadGameObject.IsActive(levelIcon.gameObject))
            {
                MadGameObject.SetActive(levelIcon.gameObject, true);
            }

            // setup level properties
            levelIcon.levelIndex            = levelIndex;
            levelIcon.configuration         = configuration;
            levelIcon.hasLevelConfiguration = true;

            // set level number if exists
            if (levelIcon.levelNumber != null)
            {
                levelIcon.levelNumber.text = (levelIndex + 1).ToString();
            }

            // level unlock if set
            if (previousIcon != null)
            {
                if (newInstance)
                {
                    previousIcon.unlockOnComplete.Add(levelIcon);
                }
            }
            else
            {
                levelIcon.locked = false;
            }

            previousIcon = levelIcon;
        }

        BuildBackgroundTexture();
    }
コード例 #21
0
ファイル: MadLevelInitTool.cs プロジェクト: MatSe91/Lightbeam
    void InitTemplates(MadRootNode root, out MadLevelIcon icon, out MadSprite slideLeftSprite,
                       out MadSprite slideRightSprite)
    {
        var panel     = MadTransform.FindChild <MadPanel>(root.transform);
        var templates = MadTransform.CreateChild(panel.transform, "Templates");

        GameObject iconPrefab       = MadAssets.TryLoadGameObject(IconPrefabGUID);
        GameObject slideLeftPrefab  = MadAssets.TryLoadGameObject(SlideLeftPrefabGUID);
        GameObject slideRightPrefab = MadAssets.TryLoadGameObject(SlideRightPrefabGUID);

        if (MadGameObject.AnyNull(iconPrefab, slideLeftPrefab, slideRightPrefab))
        {
            Debug.LogWarning("I cannot find all needed prefabs to create example templates. Have you removed Mad Level "
                             + "Manager example prefabs?");
        }

        if (iconPrefab != null)
        {
            var obj = PrefabUtility.InstantiatePrefab(iconPrefab) as GameObject;
            obj.transform.parent = templates.transform;
            obj.name             = "icon";

            obj.transform.localScale    = Vector3.one;
            obj.transform.localPosition = new Vector2(-400, 150);
            icon = obj.GetComponent <MadLevelIcon>();
        }
        else
        {
            icon = null;
        }

        if (slideLeftPrefab != null)
        {
            var slide = PrefabUtility.InstantiatePrefab(slideLeftPrefab) as GameObject;
            slide.transform.parent = templates.transform;
            slide.name             = "slide left";

            slide.transform.localScale    = Vector3.one;
            slide.transform.localPosition = new Vector2(-400, 0);
            slideLeftSprite = slide.GetComponent <MadSprite>();
        }
        else
        {
            slideLeftSprite = null;
        }

        if (slideRightPrefab != null)
        {
            var slide = PrefabUtility.InstantiatePrefab(slideRightPrefab) as GameObject;
            slide.transform.parent = templates.transform;
            slide.name             = "slide right";

            slide.transform.localScale    = Vector3.one;
            slide.transform.localPosition = new Vector2(-400, -150);
            slideRightSprite = slide.GetComponent <MadSprite>();
        }
        else
        {
            slideRightSprite = null;
        }

        MadGameObject.SetActive(templates, false);
    }
コード例 #22
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
    }
コード例 #23
0
ファイル: MadDrawCall.cs プロジェクト: kewls74/game1
 public void Destroy()
 {
     MadGameObject.SetActive(gameObject, false);
     GameObject.DestroyImmediate(gameObject);
     //MadGameObject.SafeDestroy(gameObject);
 }