コード例 #1
0
ファイル: MadLevelInitTool.cs プロジェクト: tng2903/game1
    void CreateFree(MadRootNode root, MadLevelIcon icon) {
        var panel = MadTransform.FindChild<MadPanel>(root.transform);
        var freeLayout = MadLevelFreeTool.CreateUnderPanel(panel);

        freeLayout.iconTemplate = icon;
        freeLayout.dirty = true;
    }
コード例 #2
0
ファイル: MadLevelInitTool.cs プロジェクト: tng2903/game1
    // ===========================================================
    // Methods
    // ===========================================================

    void CreateGrid(MadRootNode root, MadLevelIcon icon, MadSprite slideLeft, MadSprite slideRight) {
        var panel = MadTransform.FindChild<MadPanel>(root.transform);
        var gridLayout = MadLevelGridTool.CreateUnderPanel(panel);

        gridLayout.iconTemplate = icon;
        gridLayout.leftSlideSprite = slideLeft;
        gridLayout.rightSlideSprite = slideRight;
        gridLayout.dirty = true;
    }
コード例 #3
0
    void Start() {
        sprite = GetComponent<MadSprite>();
        if (sprite == null) {
            Debug.LogError("Condition needs a MadSprite to be attached to this game object.", this);
            return;
        }

        icon = MadTransform.FindParent<MadLevelIcon>(transform);
        if (icon == null) {
            Debug.LogError("Condition need to be set under MadLevelIcon.", this);
            return;
        }

        Apply();
    }
コード例 #4
0
 public override MadLevelIcon TopIcon(MadLevelIcon current) {
     return FindBest(current, Vector3.up, 45);
 }
コード例 #5
0
 public override MadLevelIcon RightIcon(MadLevelIcon current) {
     var layout = MadLevelLayout.current;
     return layout.GetNextIcon(current);
 }
コード例 #6
0
 public override MadLevelIcon LeftIcon(MadLevelIcon current) {
     return FindBest(current, Vector3.left, 45);
 }
コード例 #7
0
 /// <summary>
 /// Looks at given icon;
 /// </summary>
 /// <param name="icon">Icon.</param>
 public abstract void LookAtIcon(MadLevelIcon icon);
コード例 #8
0
    // second tier of icon activation. Will go through loadLevel condition
    private IEnumerator Activate2nd(MadLevelIcon icon) {
        switch (loadLevel) {
            case LoadLevel.Immediately:
                icon.LoadLevel();
                break;

            case LoadLevel.WithDelay:
                yield return new WaitForSeconds(loadLevelLoadLevelDelay);
                icon.LoadLevel();
                break;

            case LoadLevel.SendMessage:
                if (loadLevelMessageReceiver == null) {
                    Debug.LogError("No send message receiver", this);
                    break;
                }

                if (string.IsNullOrEmpty(loadLevelMessageName)) {
                    Debug.LogError("No sent message name", this);
                    break;
                }

                if (loadLevelMessageIncludeChildren) {
                    loadLevelMessageReceiver.BroadcastMessage(loadLevelMessageName, icon);
                } else {
                    loadLevelMessageReceiver.SendMessage(loadLevelMessageName, icon);
                }
                break;

            default:
                Debug.LogError("Unknown LoadLevel option: " + loadLevel);
                break;
        }
    }
コード例 #9
0
 public abstract MadLevelIcon LeftIcon(MadLevelIcon current);
コード例 #10
0
ファイル: MadLevelFreeLayout.cs プロジェクト: tng2903/game1
    private bool Collides(MadLevelIcon icon, List<MadLevelIcon> iconList) {
        var b1 = icon.GetTransformedBounds();
        foreach (var i in iconList) {
            var b2 = i.GetTransformedBounds();
            if (MadMath.Overlaps(b1, b2)) {
                return true;
            }
        }

        return false;
    }
コード例 #11
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 template = iconTemplateQuantity == IconTemplateQuantity.Single
                            ? iconTemplate
                            : iconTemplates[levelIndex];

            if (template == null)
            {
                template = iconTemplate;
            }

            var nIcon = CreateIcon(draggable.transform, name, template);
            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);
            }
        }

        Build();
    }
コード例 #12
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)
            {
                var template = iconTemplateQuantity == IconTemplateQuantity.Single
                            ? iconTemplate
                            : iconTemplates[levelIndex];

                if (template == null)
                {
                    template = iconTemplate;
                }

                levelIcon = CreateIcon(draggable.transform, string.Format(name, levelIndex + 1), template);

                // 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);
    }
コード例 #13
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();
    }
コード例 #14
0
ファイル: MadLevelFreeLayout.cs プロジェクト: kewls74/game1
 public override void LookAtIcon(MadLevelIcon icon)
 {
     LookAtIcon(icon, default(MadiTween.EaseType), 0);
 }
コード例 #15
0
 /// <summary>
 /// Looks at given icon;
 /// </summary>
 /// <param name="icon">Icon.</param>
 /// <param name="animate">Set to true to animate switching. Using an animation from the Draggable object.</param>
 public abstract void LookAtIcon(MadLevelIcon icon, bool animate = false);
コード例 #16
0
 public override MadLevelIcon BottomIcon(MadLevelIcon current)
 {
     return(FindBest(current, Vector3.down, 45));
 }
コード例 #17
0
 public override MadLevelIcon TopIcon(MadLevelIcon current)
 {
     return(FindBest(current, Vector3.up, 45));
 }
コード例 #18
0
 public override MadLevelIcon RightIcon(MadLevelIcon current)
 {
     return(FindBest(current, Vector3.right, 45));
 }
コード例 #19
0
 public override void LookAtIcon(MadLevelIcon icon, bool animate = false)
 {
     LookAtIcon(icon, default(MadiTween.EaseType), animate ? 1 : 0);
 }
コード例 #20
0
 /// <summary>
 /// Looks at given icon;
 /// </summary>
 /// <param name="icon">Icon.</param>
 public abstract void LookAtIcon(MadLevelIcon icon);
コード例 #21
0
    // ===========================================================
    // Methods
    // ===========================================================

    #region Public API

    public void LookAtIcon(MadLevelIcon icon, MadiTween.EaseType easeType, float time)
    {
        draggable.MoveToLocal(icon.transform.localPosition, easeType, time);
    }
コード例 #22
0
 public abstract MadLevelIcon RightIcon(MadLevelIcon current);
コード例 #23
0
ファイル: MadLevelGridLayout.cs プロジェクト: kewls74/game1
    public override void LookAtIcon(MadLevelIcon icon)
    {
        int pageIndex = PageIndexForLevel(icon.level.name);

        SwitchPage(pageIndex, true);
    }
コード例 #24
0
ファイル: MadLevelFreeLayout.cs プロジェクト: tng2903/game1
 // ===========================================================
 // Methods
 // ===========================================================
 
 #region Public API
 
 public void LookAtIcon(MadLevelIcon icon, MadiTween.EaseType easeType, float time) {
     draggable.MoveToLocal(icon.transform.localPosition, easeType, time);
 }
コード例 #25
0
ファイル: MadLevelGridLayout.cs プロジェクト: kewls74/game1
    // 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;
        }
    }
コード例 #26
0
    private void Activate1st(MadLevelIcon icon) {
        if (icon.locked && !icon.canFocusIfLocked) {
            return;
        }

        if (!icon.hasFocus) {
            icon.hasFocus = true;
            if (onIconActivate != null) {
                onIconActivate(icon, icon.level.name);
            }

            activeIcon = icon;

        } else if (!icon.locked) {
            StartCoroutine(Activate2nd(icon));
        }
    }
コード例 #27
0
 public override MadLevelIcon BottomIcon(MadLevelIcon current)
 {
     throw new System.NotImplementedException();
 }
コード例 #28
0
        public override MadLevelIcon RightIcon(MadLevelIcon current)
        {
            var layout = MadLevelLayout.current;

            return(layout.GetNextIcon(current));
        }
コード例 #29
0
        public MadLevelIcon FindBest(MadLevelIcon origin, Vector2 direction, float toleranceAngle) {
            List<MadLevelIcon> found = FindAll(origin, direction, toleranceAngle);
            if (found.Count == 0) {
                return null;
            } else if (found.Count == 1) {
                return found[0];
            } else {
                // find the best candidate based on distance and angle
                float weight = float.MaxValue;
                MadLevelIcon bestIcon = null;

                var layout = MadLevelLayout.current;

                for (int i = 0; i < found.Count; ++i) {
                    var icon = found[i];

                    if (!layout.CanActivate(icon)) {
                        continue;
                    }

                    var originToIconVec = icon.transform.position - origin.transform.position;
                    float angle = Vector2.Angle(direction, originToIconVec);
                    float distance = originToIconVec.magnitude;

                    float currentWeight = distance + (distance * (angle / toleranceAngle) * 2);
                    if (currentWeight < weight) {
                        bestIcon = icon;
                        weight = currentWeight;
                    }
                }

                return bestIcon;
            }
        }
コード例 #30
0
 public override MadLevelIcon BottomIcon(MadLevelIcon current) {
     throw new System.NotImplementedException();
 }
コード例 #31
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);
    }
コード例 #32
0
 public override MadLevelIcon RightIcon(MadLevelIcon current) {
     return FindBest(current, Vector3.right, 45);
 }
コード例 #33
0
    public bool CanActivate(MadLevelIcon icon) {
        if (icon.locked && !icon.canFocusIfLocked) {
            return false;
        }

        return true;
    }
コード例 #34
0
 public override MadLevelIcon BottomIcon(MadLevelIcon current) {
     return FindBest(current, Vector3.down, 45);
 }
コード例 #35
0
 public override MadLevelIcon LeftIcon(MadLevelIcon current)
 {
     return(FindBest(current, Vector3.left, 45));
 }
コード例 #36
0
        public List<MadLevelIcon> FindAll(MadLevelIcon origin, Vector2 direction, float toleranceAngle) {
            List<MadLevelIcon> output = new List<MadLevelIcon>();
            
            var layout = MadLevelLayout.current;
            var allIcons = layout.GetAllIcons();

            for (int i = 0; i < allIcons.Length; ++i) {
                var icon = allIcons[i];
                if (icon == origin) {
                    continue;
                }

                Vector2 vec = icon.transform.position - origin.transform.position;
                if (Vector2.Angle(direction, vec) <= toleranceAngle) {
                    output.Add(icon);
                }
            }

            return output;
        }
コード例 #37
0
    public override void LookAtIcon(MadLevelIcon icon, bool animate = false)
    {
        int pageIndex = PageIndexForLevel(icon.level.name);

        SwitchPage(pageIndex, !animate);
    }
コード例 #38
0
 public MadLevelIcon GetNextIcon(MadLevelIcon icon) {
     var nextLevel = currentConfiguration.FindNextLevel(icon.level.name);
     if (nextLevel == null) {
         return null;
     }
     
     return GetIcon(nextLevel.name);
 }
コード例 #39
0
    // TODO: make this a abstract method
    public void LookAtIconAnimate(MadLevelIcon icon)
    {
        int pageIndex = PageIndexForLevel(icon.level.name);

        SwitchPage(pageIndex, false);
    }
コード例 #40
0
    private void Activate1st(MadLevelIcon icon) {
        if (!CanActivate(icon)) {
            Debug.Log("Icon " + icon + " cannot be activated because of layout settings.", icon);
            return;
        }

        if (!icon.hasFocus) {
            icon.hasFocus = true;
            if (onIconActivate != null) {
                onIconActivate(icon, icon.level.name);
            }

            activeIcon = icon;

        } else if (!icon.locked) {
            StartCoroutine(Activate2nd(icon));
        }
    }
コード例 #41
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
    }
コード例 #42
0
    void Update()
    {
        if (onlyOnMobiles && !isMobile)
        {
            return;
        }

        MadLevelIcon newIcon    = null;
        var          activeIcon = ActiveIcon();

        if ((isLeft || isRight || isUp || isDown) && activeIcon == null)
        {
            var layout    = MadLevelLayout.current;
            var firstIcon = layout.GetFirstIcon();

            Activate(firstIcon);
        }
        else
        {
            if (isLeft && traverseRule.canGoLeft)
            {
                if (CanExecuteAction())
                {
                    newIcon        = traverseRule.LeftIcon(activeIcon);
                    keyDown        = true;
                    lastActionTime = Time.time;
                }
            }
            else if (isRight && traverseRule.canGoRight)
            {
                if (CanExecuteAction())
                {
                    newIcon        = traverseRule.RightIcon(activeIcon);
                    keyDown        = true;
                    lastActionTime = Time.time;
                }
            }
            else if (isUp && traverseRule.canGoUp)
            {
                if (CanExecuteAction())
                {
                    newIcon        = traverseRule.TopIcon(activeIcon);
                    keyDown        = true;
                    lastActionTime = Time.time;
                }
            }
            else if (isDown && traverseRule.canGoDown)
            {
                if (CanExecuteAction())
                {
                    newIcon        = traverseRule.BottomIcon(activeIcon);
                    keyDown        = true;
                    lastActionTime = Time.time;
                }
            }
            else if (isEnter)
            {
                Activate(activeIcon);
            }
            else
            {
                keyDown = false;
            }

            if (newIcon != null)
            {
                Activate(newIcon);
            }
        }
    }
コード例 #43
0
 public bool ContainsIcon(MadLevelIcon icon)
 {
     return(Array.IndexOf(icons, icon) != -1);
 }
コード例 #44
0
 public abstract MadLevelIcon TopIcon(MadLevelIcon current);
コード例 #45
0
    void Activate(MadLevelIcon icon) {
        if (icon == null) {
            return;
        }

        var layout = MadLevelLayout.current;
        if (layout.CanActivate(icon)) {
            layout.Activate(icon);
            if (layout is MadLevelFreeLayout) {
                var free = layout as MadLevelFreeLayout;
                free.LookAtIcon(icon, MadiTween.EaseType.easeOutCubic, 1);
            } else if (layout is MadLevelGridLayout) {
                var grid = layout as MadLevelGridLayout;
                grid.LookAtIconAnimate(icon);
            }
        }
    }
コード例 #46
0
 public abstract MadLevelIcon BottomIcon(MadLevelIcon current);
コード例 #47
0
 public abstract MadLevelIcon LeftIcon(MadLevelIcon current);
コード例 #48
0
ファイル: MadLevelFreeLayout.cs プロジェクト: tng2903/game1
 public override void LookAtIcon(MadLevelIcon icon) {
     LookAtIcon(icon, default(MadiTween.EaseType), 0);
 }
コード例 #49
0
 public abstract MadLevelIcon TopIcon(MadLevelIcon current);
コード例 #50
0
 public MadLevelIcon GetPreviousIcon(MadLevelIcon icon) {
     var nextLevel = configuration.FindPreviousLevel(icon.level.name);
     if (nextLevel == null) {
         return null;
     }
     
     return GetIcon(nextLevel.name);
 }
コード例 #51
0
 public abstract MadLevelIcon RightIcon(MadLevelIcon current);
コード例 #52
0
    public void Activate(MadLevelIcon icon) {
        if (activeIcon != null && icon != activeIcon) {
            DeactivateActiveIcon();
        }

        switch (twoStepActivationType) {
            case TwoStepActivationType.Disabled:
                if (!icon.locked) {
                    StartCoroutine(Activate2nd(icon));
                }
                break;
                
            case TwoStepActivationType.OnlyOnMobiles:
                if (SystemInfo.deviceType == DeviceType.Handheld) {
                    Activate1st(icon);
                } else if (!icon.locked) {
                    StartCoroutine(Activate2nd(icon));
                }
                break;
                
            case TwoStepActivationType.Always:
                Activate1st(icon);
                break;
                
            default:
                Debug.LogError("Uknown option: " + twoStepActivationType);
                break;
        }
    }
コード例 #53
0
 public abstract MadLevelIcon BottomIcon(MadLevelIcon current);
コード例 #54
0
 void DeactivateActiveIcon() {
     var icon = activeIcon;
     activeIcon = null;
     
     if (onIconDeactivate != null) {
         onIconDeactivate(icon, icon.level.name);
     }
 }
コード例 #55
0
 public override MadLevelIcon LeftIcon(MadLevelIcon current) {
     var layout = MadLevelLayout.current;
     return layout.GetPreviousIcon(current);
 }
コード例 #56
0
    protected MadLevelIcon CreateIcon(Transform parent, string name, MadLevelIcon template) {
        GameObject go = null;
        
#if UNITY_EDITOR
        go = PrefabUtility.InstantiatePrefab(template.gameObject) as GameObject;
#endif
        if (go != null) {
            go.name = name;
            go.transform.parent = parent;
            
        } else {
            go = MadTransform.CreateChild(parent, name, template.gameObject);
        }

        return go.GetComponent<MadLevelIcon>();
    }
コード例 #57
0
        public override MadLevelIcon LeftIcon(MadLevelIcon current)
        {
            var layout = MadLevelLayout.current;

            return(layout.GetPreviousIcon(current));
        }