Esempio n. 1
0
 /** Loads item from store, or creates a new default instance if not found. */
 private T loadFromStoreDefault <T>(string key) where T : DataObject, new()
 {
     if (StateStorage.HasData(key))
     {
         return(StateStorage.LoadData <T>(key));
     }
     else
     {
         return(new T());
     }
 }
Esempio n. 2
0
 /** Loads item from store, throws error if not found. */
 private T loadFromStore <T>(string key) where T : DataObject
 {
     if (StateStorage.HasData(key))
     {
         return(StateStorage.LoadData <T>(key));
     }
     else
     {
         throw new Exception(String.Format("Error reading from save file, expecting file {0} but it wasn't found.", key));
     }
 }
Esempio n. 3
0
    void OnClickStart(long videoId, byte index)
    {
        CustomAudio.GetInstance().PlayCustomAudio(1002);
        string             key  = videoId + ":" + index;
        List <VideoAction> list = StateStorage.LoadData <List <VideoAction> >(key);

        if (list == null || list.Count == 0)
        {
            UMessage msg = new UMessage((uint)GameCity.EMSG_ENUM.CCVideoMsg_ApplyGetStepInfo);
            msg.Add(videoId);
            msg.Add(index);
            HallMain.videotcpclient.SendMsg(msg);
        }
        else
        {
            m_ActionsList = new List <VideoAction>(list);
            StartPlay(index);
        }
    }
Esempio n. 4
0
        /** Writes out each object in library, reads it back in, and makes sure they are the same */
        private bool Validate <T>(DataLibrary <T> library) where T : NamedDataObject
        {
            List <string> differences = new List <string>();

            foreach (NamedDataObject item in library)
            {
                StateStorage.SaveData("validationtest", item);
                object loadedItem = StateStorage.LoadData <T>("validationtest");
                if (!Util.CompareProperites(item, loadedItem, ref differences))
                {
                    Trace.LogWarning("Validation failed on " + typeof(T) + ": " + String.Join(",", differences.ToArray()) + "]");
                    return(false);
                }
            }

            Trace.Log("Validation passed for " + typeof(T));

            return(true);
        }
Esempio n. 5
0
File: CoM.cs Progetto: bsimser/CoM
    /**
     * Loads a file from storage and returns it.
     * Provides validiation and logging.
     * If the type is a library the library will be set as the global library for that type.
     * If min version is set an exception will be thrown if data doesn't meet minimum version.
     */
    private static T LoadData <T>(string source, float minVersion = 0.0f, bool silent = false) where T : DataObject
    {
        if (!StateStorage.HasData(source))
        {
            throw new Exception("Source not found [" + source + "]");
        }

        T result = StateStorage.LoadData <T>(source);

        if (result.Version < minVersion)
        {
            throw new Exception(String.Format("File {0} has an old version, expecting {1} but found {2}", source, minVersion, result.Version));
        }

        if (!silent)
        {
            Trace.Log(" - Loaded [" + source + "] (v" + result.Version.ToString("0.0") + ")");
        }

        return(result);
    }
Esempio n. 6
0
    /// <summary>
    /// 加载游戏排行榜数据
    /// </summary>
    public void LoadContestRankingData(List <long> ContestIDList)
    {
        if (ContestIDList.Count == 0)
        {
            return;
        }

        SerializableDictionary <long, SerializableDictionary <int, CPlayerRankingInfo> > ContestRankingDictionary = StateStorage.LoadData <SerializableDictionary <long, SerializableDictionary <int, CPlayerRankingInfo> > >(Key);

        if (ContestRankingDictionary != null)
        {
            ContestRankingDataDictionary = ContestRankingDictionary;
        }
        List <long> RemoveIDList = new List <long>();

        foreach (var value in ContestRankingDataDictionary.Keys)
        {
            if (ContestIDList.FindIndex(id => { return(value == id); }) == -1)
            {
                RemoveIDList.Add(value);
            }
        }
        foreach (var keyId in RemoveIDList)
        {
            ContestRankingDataDictionary.Remove(keyId);
        }
    }
Esempio n. 7
0
    void AddPage(AssetBundle bundle, string name, PageType pt, object param = null,
                 bool pageOn = false, UnityAction <Toggle, GameObject> fun = null, bool bReadState = true)
    {
        if (bundle == null)
        {
            return;
        }

        GameObject obj = (GameObject)bundle.LoadAsset("Lobby_News_Toggle");

        obj = (GameObject)GameMain.instantiate(obj);
        ToggleGroup tg = transform.Find("PanelDown/Lobby_News_Left/Content").GetComponent <ToggleGroup>();

        obj.transform.SetParent(tg.transform, false);
        obj.transform.Find("Label").GetComponent <Text>().text = name;

        if (PageLiftToggleGroupDictionary.ContainsKey(pt))
        {
            if (PageLiftToggleGroupDictionary[pt] != null)
            {
                for (int index = 0; index < tg.transform.childCount; ++index)
                {
                    if (PageLiftToggleGroupDictionary[pt] == tg.transform.GetChild(index).gameObject)
                    {
                        if (pt == PageType.ePT_Chess)
                        {
                            long oldContestID = 0, newContestID = (long)param;
                            long.TryParse(PageLiftToggleGroupDictionary[pt].name, out oldContestID);
                            if (oldContestID > newContestID)
                            {
                                obj.transform.SetSiblingIndex(index + 1);
                                break;
                            }
                        }
                        obj.transform.SetSiblingIndex(index);
                        break;
                    }
                }
            }
            PageLiftToggleGroupDictionary[pt] = obj;
        }
        GameObject assetObj = null;
        GameObject objR     = null;
        bool       clicked  = bReadState;

        switch (pt)
        {
        case PageType.ePT_Signin:
        {
            assetObj = (GameObject)bundle.LoadAsset("Lobby_News_signin");
            clicked  = (GameMain.hall_.GetPlayerData().NeedSign == 0);
        }
        break;

        case PageType.ePT_Mail:
        {
            if (Email.GetEmailInstance().root_ == null)
            {
                Email.GetEmailInstance().LoadNewsResource();
            }
            objR         = Email.GetEmailInstance().root_;
            clicked      = (GameMain.hall_.GetPlayerData().mailNumber <= 0);
            m_MailToggle = obj;
        }
        break;

        case PageType.ePT_Chess:
        {
            objR = CGameContestRankingTifings.GetChessRankingInstance().GetMainTransform().gameObject;
        }
        break;

        default:
        {
            assetObj = (GameObject)bundle.LoadAsset("Lobby_News_Activity");
            clicked  = StateStorage.LoadData <bool>(pt + ":" + name);
        }
        break;
        }

        if (assetObj != null)
        {
            objR = (GameObject)GameMain.instantiate(assetObj);
        }

        if (objR != null)
        {
            objR.transform.SetParent(transform.Find("PanelDown/Lobby_News_Right"), false);

            bool ActiveState = pageOn;
            if (pt == PageType.ePT_Activity)
            {
                GameMain.SC(LoadActivityImage(objR, (string)param));
                m_Announcement[obj] = objR;
            }
            else if (pt == PageType.ePT_Chess)
            {
                ActiveState = objR.activeSelf;
            }

            objR.SetActive(ActiveState);
        }

        Toggle t = obj.GetComponent <Toggle>();

        t.group = tg;
        t.isOn  = pageOn;
        t.onValueChanged.AddListener((isOn) => OnToggleChanged(t, name, pt, isOn, objR));

        obj.transform.Find("ImageSpot").gameObject.SetActive(!clicked);

        if (!clicked)
        {
            NeedClick++;
        }

        if (fun != null)
        {
            fun.Invoke(t, objR);
        }
    }
Esempio n. 8
0
 public static UserProfile LoadProfile()
 {
     return(StateStorage.LoadData <UserProfile>("Profile"));
 }