Beispiel #1
0
    public void Init()
    {
        //Init Attributes
        if (uiPathDict == null)
        {
            uiPathDict = new Dictionary <UIPanelType, string>();
        }
        if (PanelDict == null)
        {
            PanelDict = new Dictionary <UIPanelType, BasePanel>();
        }
        if (panelstack == null)
        {
            panelstack = new Stack <BasePanel>();
        }
        canvas     = GameObject.FindObjectOfType <Canvas>().transform;
        maskPrefab = Resources.Load <GameObject>("Prefabs/UI/Img_Mask");
        InitMask();

        //Load Json File using LitJson
        UIPanelPathList pathsList = LoadFromJson();

        //Save Json Loaded text to Dictionary
        foreach (var t in pathsList.panelPathList)
        {
            UIPanelType type = (UIPanelType)System.Enum.Parse(typeof(UIPanelType), t.name);
            uiPathDict.Add(type, t.path);
        }

        //uiPathDict.Add(UIPanelType.StartLoadPanel, "Prefabs/UIPanel/StartLoadPanel");
    }
Beispiel #2
0
    private UIPanelPathList LoadFromJson()
    {
        UIPanelPathList pathList = new UIPanelPathList();
        string          path     = Application.dataPath + "/StreamingAssets/Json/UIPanelTypePath.json";

        if (File.Exists(path))
        {
            StreamReader sr      = new StreamReader(path);
            string       jsonStr = sr.ReadToEnd();
            sr.Close();
            pathList = JsonMapper.ToObject <UIPanelPathList>(jsonStr);
        }
        if (pathList == null)
        {
            Debug.LogWarning("Failed to load Json File, Path: " + path);
        }
        return(pathList);
    }