Ejemplo n.º 1
0
    void OnGUI()
    {
#if UNITY_EDITOR
        float top = 50f;
#else
        float top = 100f;
#endif

        if (!TransitionManager.Instance.TransitionFinished)
        {
            return;
        }

        if (!_showDebug)
        {
            if (GUI.Button(new Rect(Screen.width - 100, top, 100, 100), "", GUIStyle.none))
            {
                double time = System.DateTime.Now.TimeOfDay.TotalSeconds;

                if (time - _lastTime < 0.35)
                {
                    _lastTime = 0;

                    _showDebug = !_showDebug;
                }
                else
                {
                    _lastTime = time;
                }
            }
        }

        if (_showDebug)
        {
            GUILayout.BeginArea(new Rect(10, top, Screen.width, Screen.height));
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            GUILayout.BeginVertical();

            GUI.enabled = (_userData.Mana < Settings.MaxMana);
            if (GUILayout.Button("Get Mana"))
            {
                NotificationManager.ManaChanged(_userData.Mana + 1);
            }
            GUI.enabled = true;

            GUI.enabled = (_userData.Mana > 0);
            if (GUILayout.Button("Clear Mana"))
            {
                NotificationManager.ManaChanged(0);
            }
            GUI.enabled = true;

#if UNITY_EDITOR
            GUI.enabled = (_userData.Mana < Settings.MaxMana);
            if (GUILayout.Button("Cheat Mana"))
            {
                TimeManager.CheatManaCountdown();
            }
            GUI.enabled = true;
#endif

            if (GUILayout.Button("Get Coin"))
            {
                NotificationManager.CoinChanged(_userData.Coin + 10);
            }

            GUI.enabled = (_userData.Coin > 0);
            if (GUILayout.Button("Clear Coin"))
            {
                NotificationManager.CoinChanged(0);
            }
            GUI.enabled = true;

            int level = _userData.Level;

            GUI.enabled = (level < Settings.MapCount);
            if (GUILayout.Button("Unlock Next Map"))
            {
                ZoneType currentZone = ZoneTypeHelper.GetZoneType(level);

                level++;

                _userData.Level = level;

                map.UnlockMap(level);

                ZoneType newZone = ZoneTypeHelper.GetZoneType(level);

                if (newZone != currentZone)
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
                }
            }

            if (GUILayout.Button("Unlock Zone"))
            {
                for (int zone = 0; zone < 3; zone++)
                {
                    ZoneType zoneType = zone.ToZoneType();
                    int      mapCount = zoneType.MapCount();

                    if (level <= mapCount)
                    {
                        for (int i = level + 1; i <= mapCount; i++)
                        {
                            map.UnlockMap(i);
                        }

                        _userData.Level = mapCount;

                        break;
                    }
                }
            }

            if (GUILayout.Button("Unlock All Maps"))
            {
                ZoneType currentZone = ZoneTypeHelper.GetZoneType(level);

                for (int i = level + 1; i <= Settings.MapCount; i++)
                {
                    map.UnlockMap(i);
                }

                _userData.Level = Settings.MapCount;

                if (currentZone != ZoneType.Volcano)
                {
                    SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
                }
            }
            GUI.enabled = true;

            if (GUILayout.Button("Close"))
            {
                _showDebug = false;
            }

            if (GUILayout.Button("Reset"))
            {
                UserData.Instance.Reset();
            }

            GUILayout.EndVertical();
            GUILayout.Space(20);
            GUILayout.EndHorizontal();
            GUILayout.EndArea();
        }
    }
Ejemplo n.º 2
0
    void Start()
    {
        // Get current level
        int level = UserData.Instance.Level;

        int   mapCount = maps.Length;
        float mapWidth = maps[0].GetWidth();

        int   buttonCount = -1;
        float cloudY      = -1;

        for (int zone = 0; zone < 2; zone++)
        {
            ZoneType zoneType = zone.ToZoneType();

            if (level <= zoneType.MapCount())
            {
                buttonCount = zoneType.MapCount() + 1;
                cloudY      = clouds.GetChild(zone).position.y;
                break;
            }
        }

        Vector3 position = Vector3.zero;

        for (int i = 0; i < mapCount; i++)
        {
            GameObject bg = new GameObject(string.Format("Background {0}", i + 1));
            bg.transform.SetParent(background);
            bg.transform.localPosition = position;

            SpriteRenderer renderer = bg.AddComponent <SpriteRenderer>();
            renderer.sprite       = maps[i];
            renderer.sortingOrder = -3;

            float height = maps[i].GetHeight();

            position.y += height;

            if (cloudY > 0 && position.y >= cloudY)
            {
                break;
            }
        }

        if (cloudY < 0)
        {
            cloudY = position.y;
        }

        // Set cloud position
        cloud.transform.SetPositionY(cloudY);

        // Set number of maps
        _mapCount = points.childCount;

        if (buttonCount < 0)
        {
            buttonCount = _mapCount;
        }

        // Create buttons
        _buttons = new MapButton[buttonCount];

        bool isNewLevel = UserData.Instance.NewLevel;

        for (int i = 0; i < buttonCount; i++)
        {
            position = points.GetChild(i).position;

            int mapID = i + 1;

            GameObject map = buttonPrefab.Create(background, position);
            map.name = string.Format("Map {0}", mapID);

            bool unlocked = mapID < level || (mapID == level && !isNewLevel);

            MapButton mapButton = map.GetComponent <MapButton>();
            mapButton.Construct(spriteLock, zones[ZoneTypeHelper.GetZoneType(mapID).ToInt()].mapIcon, mapID, unlocked);

            _buttons[i] = mapButton;
        }

        // Destroy points
        Destroy(points.gameObject);

        // Destroy clouds
        Destroy(clouds.gameObject);

        // Fixed width
        float scale = Camera.main.GetWidth() / mapWidth;

        background.SetScale(scale);

        float mapHeight = cloudY * scale;

        //
        _squareRadius = ButtonRadius * ButtonRadius * scale * scale;

        // Create vertical scroll
        _verticalScroll = new VerticalScroll();
        _verticalScroll.Construct(-Camera.main.orthographicSize, mapHeight, Camera.main.GetHeight());

        // Set map position
//		transform.SetPositionY(_verticalScroll.Position);

        // Get current map
        int mapIndex = Mathf.Clamp(UserData.Instance.Map - 1, 0, _buttons.Length - 1);

        if (animal != null)
        {
            // Set animal position
            animal.transform.position = _buttons[mapIndex].transform.position;

            // Set skin
            animal.idleDuration = 0;

            ZoneType zoneType = ZoneTypeHelper.GetZoneType(mapIndex + 1);

            if (!zoneType.IsDefault())
            {
                ZoneSetting zone = zones[zoneType.ToInt()];
                animal.SetClothes(zone.clothesLeft, zone.clothesUp, zone.clothesDown);
                animal.SetCap(zone.capLeft, zone.capUp, zone.capDown);
            }
        }

        MoveObjectToCenter(_buttons[mapIndex].gameObject);
    }