保存scrollrect或rect变换的最后位置

时间:2017-05-28 23:09:51

标签: unity3d scrollbar scrollrect

我有Level scrollrect但是我喜欢当我选择一个级别时我喜欢向我显示总是最后一级(如果我完成13级解锁我14级并且当我去菜单场景时显示我在14级中心后这个如果我完成14级,当我再次在菜单场景中显示我在中心的15级时)可以做到这一点并保存最后一级的最后位置。 当我打开菜单时,它会显示我从botton看到 - Picture 1但我喜欢当我打开菜单场景从这个位置打开时看到 - Picture 2

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;


public class LevelData
{
    public LevelData(string levelName)
    {
        string data = PlayerPrefs.GetString(levelName);
        if (data == "")
            return;

        string[] allData = data.Split('&');
        BestTime = float.Parse(allData[0]);
        SilverTime = float.Parse(allData[1]);
        GoldTime = float.Parse(allData[2]);
    }

    public float BestTime { set; get; }
    public float GoldTime { set; get; }
    public float SilverTime { set; get; }
    public float BronzeTime { set; get; }
}

public class Menu : MonoBehaviour
{
    private static Menu instance;
    public static Menu Instance { get { return instance; } }
    private int idLevel;
    public Text timeText;
    public Text txtselectLevel;
    public string[] Level;
    public ScrollRect scrol;

    public GameObject PlayPanel;
    public GameObject star1;
    public GameObject star2;
    public GameObject star3;

    void Start()
    {
        instance = this;
        PlayPanel.SetActive(false);
        GameManager.Instance.Load();
        idLevel = 0;
        txtselectLevel.text = Level[idLevel];
        PlayerPrefs.GetString(idLevel.ToString());

        star1.SetActive(false);
        star2.SetActive(false);
        star3.SetActive(false);

    }

    public void Scenes()
    {
        SceneManager.LoadScene("L" + idLevel.ToString());
    }

    public void SelectLevel(int i)
    {
        idLevel = i;

        PlayerPrefs.SetInt("idLevel", idLevel);
        txtselectLevel.text = Level[idLevel];

        LevelData level = new LevelData(i.ToString());

        string minutes = ((int)level.BestTime / 60).ToString("00");
        string seconds = (level.BestTime % 60).ToString("00.00");

        timeText.text = (level.BestTime != 0.0f) 
            ? "Best Time: " + minutes + ":" + seconds 
            : "";

        if (level.BestTime < level.GoldTime)
        {
            star1.SetActive(true);
            star2.SetActive(true);
            star3.SetActive(true);
        }
        else if (level.BestTime < level.SilverTime)
        {
            star1.SetActive(true);
            star2.SetActive(true);
            star3.SetActive(false);
        }
        else if(level.BestTime < level.BronzeTime)
        {
            star1.SetActive(true);
            star2.SetActive(false);
            star3.SetActive(false);
        }
        else
        {
            star1.SetActive(false);
            star2.SetActive(false);
            star3.SetActive(false);
        }

        PlayPanel.SetActive(true);
    }

    public void ExitPanel()
    {
        PlayPanel.SetActive(false);
    }
}

0 个答案:

没有答案