Пример #1
0
    public void OnClick()
    {
        int          idx   = int.Parse(name.Substring(name.IndexOf("_") + 1));
        ReplayDataV1 param = ReplayQueryDropdown.replayData[idx];

        if (param.Version == 0)
        {
            return;
        }

        ScoreManager scoreManager = ScoreManager.Instance;

        scoreManager.fetchReplay(param);
    }
Пример #2
0
    void Awake()
    {
        if (Instance != null)
        {
            Destroy(gameObject);
            return;
        }

        Instance = this;
        DontDestroyOnLoad(gameObject);

        Formatter <DefaultResolver, UserDataV1> .Register(new UserDataV1Formatter <DefaultResolver>());

        UserDataFilePath = Path.Combine(Application.persistentDataPath, UserDataV1.USER_DATA_FILE_NAME);
        if (File.Exists(UserDataFilePath))
        {
            UserData = ZeroFormatterSerializer.Deserialize <UserDataV1>(File.ReadAllBytes(UserDataFilePath));
        }
        else
        {
            UserData = new UserDataV1();
        }

        Formatter <DefaultResolver, PuzzleDataV1> .Register(new PuzzleDataV1Formatter <DefaultResolver>());

        PuzzleDataFilePath = Path.Combine(Application.persistentDataPath, PuzzleDataV1.PUZZLE_DATA_FILE_NAME);
        if (File.Exists(PuzzleDataFilePath))
        {
            PuzzleData = ZeroFormatterSerializer.Deserialize <PuzzleDataV1>(File.ReadAllBytes(PuzzleDataFilePath));
        }
        else
        {
            PuzzleData = new PuzzleDataV1();
        }

        Formatter <DefaultResolver, ReplayDataV1> .Register(new ReplayDataV1Formatter <DefaultResolver>());

        ReplayDataFilePath = Path.Combine(Application.persistentDataPath, ReplayDataV1.REPLAY_DATA_FILE_NAME);
        if (File.Exists(ReplayDataFilePath))
        {
            ReplayData = ZeroFormatterSerializer.Deserialize <ReplayDataV1>(File.ReadAllBytes(ReplayDataFilePath));
        }
        else
        {
            ReplayData = new ReplayDataV1();
        }
    }
Пример #3
0
    public void OnClick()
    {
        for (int scoreKind = 0; scoreKind < ScoreDataV1.SCORE_KIND_MAX; scoreKind++)
        {
            if (name.Contains(FreeController.scoreKindName[scoreKind]) == false)
            {
                continue;
            }

            int          idx   = int.Parse(name.Substring(name.IndexOf("_") + 1));
            ReplayDataV1 param = FreeHighScoreButton.replayData[scoreKind][idx];

            if (param.Version == 0)
            {
                continue;
            }

            ScoreManager scoreManager = ScoreManager.Instance;
            scoreManager.fetchReplay(param);
        }
    }
Пример #4
0
    //-------------------------------------------------------
    // Private Function
    //-------------------------------------------------------
    private void InitScoreData()
    {
        DataManager dataManager = DataManager.Instance;

        scoreData  = new ScoreDataV1[ScoreDataV1.SCORE_KIND_MAX];
        replayData = new ReplayDataV1[ScoreDataV1.SCORE_KIND_MAX];

        int seed;

        if (replay)
        {
            seed = dataManager.ReplayData.Seed;
        }
        else
        {
            seed = (int)((DateTime.Now.ToBinary() + dataManager.PuzzleData.WriteCount) % int.MaxValue);
        }

        ScoreManager scoreManager = ScoreManager.Instance;

        for (int scoreKind = 0; scoreKind < scoreData.Length; scoreKind++)
        {
            scoreData[scoreKind] = new ScoreDataV1();

            if (replay)
            {
                scoreData[scoreKind].Id                 = dataManager.ReplayData.Id;
                scoreData[scoreKind].Name               = dataManager.ReplayData.Name;
                scoreData[scoreKind].Row                = dataManager.ReplayData.Row;
                scoreData[scoreKind].Col                = dataManager.ReplayData.Col;
                scoreData[scoreKind].Color              = dataManager.ReplayData.Color;
                scoreData[scoreKind].Link               = dataManager.ReplayData.Link;
                scoreData[scoreKind].Direction          = dataManager.ReplayData.Direction;
                scoreData[scoreKind].Time               = dataManager.ReplayData.Time;
                scoreData[scoreKind].Stop               = dataManager.ReplayData.Stop;
                scoreData[scoreKind].CountDisp          = dataManager.ReplayData.CountDisp;
                scoreData[scoreKind].Garbage            = dataManager.ReplayData.Garbage;
                scoreData[scoreKind].Version            = dataManager.ReplayData.Version;
                scoreData[scoreKind].ScoreCategoryValue = dataManager.ReplayData.ScoreCategoryValue;
            }
            else
            {
                scoreData[scoreKind].Id                 = dataManager.UserData.Id;
                scoreData[scoreKind].Name               = dataManager.UserData.Name;
                scoreData[scoreKind].Row                = dataManager.PuzzleData.Row;
                scoreData[scoreKind].Col                = dataManager.PuzzleData.Col;
                scoreData[scoreKind].Color              = dataManager.PuzzleData.Color;
                scoreData[scoreKind].Link               = dataManager.PuzzleData.Link;
                scoreData[scoreKind].Direction          = dataManager.PuzzleData.Direction;
                scoreData[scoreKind].Time               = dataManager.PuzzleData.Time;
                scoreData[scoreKind].Stop               = dataManager.PuzzleData.Stop;
                scoreData[scoreKind].CountDisp          = dataManager.PuzzleData.CountDisp;
                scoreData[scoreKind].Garbage            = dataManager.PuzzleData.Garbage;
                scoreData[scoreKind].Version            = CommonDefine.VERSION;
                scoreData[scoreKind].ScoreCategoryValue = (int)ScoreDataV1.ScoreCategory.Global;
            }

            scoreData[scoreKind].ScoreKindValue = scoreKind;
            scoreManager.getHighScore(scoreData[scoreKind], true);
            scoreManager.getHighScore(scoreData[scoreKind], false);

            if (replay)
            {
                replayData[scoreKind] = dataManager.ReplayData;
                continue;
            }

            replayData[scoreKind]                    = new ReplayDataV1();
            replayData[scoreKind].Version            = CommonDefine.VERSION;
            replayData[scoreKind].Id                 = dataManager.UserData.Id;
            replayData[scoreKind].ScoreKindValue     = scoreKind;
            replayData[scoreKind].Seed               = seed;
            replayData[scoreKind].Row                = dataManager.PuzzleData.Row;
            replayData[scoreKind].Col                = dataManager.PuzzleData.Col;
            replayData[scoreKind].Color              = dataManager.PuzzleData.Color;
            replayData[scoreKind].Link               = dataManager.PuzzleData.Link;
            replayData[scoreKind].Direction          = dataManager.PuzzleData.Direction;
            replayData[scoreKind].Time               = dataManager.PuzzleData.Time;
            replayData[scoreKind].Stop               = dataManager.PuzzleData.Stop;
            replayData[scoreKind].CountDisp          = dataManager.PuzzleData.CountDisp;
            replayData[scoreKind].Garbage            = dataManager.PuzzleData.Garbage;
            replayData[scoreKind].ScoreCategoryValue = (int)ScoreDataV1.ScoreCategory.Global;
        }

        UnityEngine.Random.seed = seed;
        frame      = 0;
        inputFrame = new List <int>();
        inputType  = new List <byte>();
        inputData1 = new List <byte>();
        inputData2 = new List <byte>();
    }
Пример #5
0
    public override ReplayDataV1 Deserialize(ref byte[] bytes, int offset, DirtyTracker tracker, out int byteSize)
    {
        Encoding enc = Encoding.GetEncoding("UTF-8");

        ReplayDataV1 value = new ReplayDataV1();

        value.Version = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset  += 4;
        value.Id = Formatter <TTypeResolver, string> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset            += 4 + enc.GetByteCount(value.Id);
        value.PlayDateTime = Formatter <TTypeResolver, long> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 8;
        value.ScoreKindValue = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset    += 4;
        value.Seed = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.FrameCount = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.InputCount = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.InputFrame = Formatter <TTypeResolver, int[]> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 4;
        if (value.InputFrame != null)
        {
            offset += value.InputFrame.Length * 4;
        }
        value.InputType = Formatter <TTypeResolver, byte[]> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 4;
        if (value.InputType != null)
        {
            offset += value.InputType.Length;
        }
        value.InputData1 = Formatter <TTypeResolver, byte[]> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 4;
        if (value.InputData1 != null)
        {
            offset += value.InputData1.Length;
        }

        value.InputData2 = Formatter <TTypeResolver, byte[]> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 4;
        if (value.InputData2 != null)
        {
            offset += value.InputData2.Length;
        }
        value.Row = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset   += 4;
        value.Col = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset     += 4;
        value.Color = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset    += 4;
        value.Link = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset         += 4;
        value.Direction = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset    += 4;
        value.Time = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset    += 4;
        value.Stop = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset         += 4;
        value.CountDisp = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset       += 4;
        value.Garbage = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 4;

        value.Name = Formatter <TTypeResolver, string> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 4 + enc.GetByteCount(value.Name);
        value.ScoreCategoryValue = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved22 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved23 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved24 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved25 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved26 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved27 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved28 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset          += 4;
        value.Reserved29 = Formatter <TTypeResolver, int> .Default.Deserialize(ref bytes, offset, tracker, out byteSize);

        offset += 4;

        return(value);
    }
Пример #6
0
    public override int Serialize(ref byte[] bytes, int offset, ReplayDataV1 value)
    {
        int startOffset = offset;

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Version);

        offset += Formatter <TTypeResolver, string> .Default.Serialize(ref bytes, offset, value.Id);

        offset += Formatter <TTypeResolver, long> .Default.Serialize(ref bytes, offset, value.PlayDateTime);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.ScoreKindValue);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Seed);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.FrameCount);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.InputCount);

        offset += Formatter <TTypeResolver, int[]> .Default.Serialize(ref bytes, offset, value.InputFrame);

        offset += Formatter <TTypeResolver, byte[]> .Default.Serialize(ref bytes, offset, value.InputType);

        offset += Formatter <TTypeResolver, byte[]> .Default.Serialize(ref bytes, offset, value.InputData1);

        offset += Formatter <TTypeResolver, byte[]> .Default.Serialize(ref bytes, offset, value.InputData2);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Row);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Col);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Color);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Link);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Direction);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Time);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Stop);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.CountDisp);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Garbage);

        offset += Formatter <TTypeResolver, string> .Default.Serialize(ref bytes, offset, value.Name);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.ScoreCategoryValue);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved22);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved23);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved24);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved25);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved26);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved27);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved28);

        offset += Formatter <TTypeResolver, int> .Default.Serialize(ref bytes, offset, value.Reserved29);

        return(offset - startOffset);
    }
Пример #7
0
    // スコア送信処理は非同期でまとめて処理するため、categoryが途中で変わってしまう。
    public void saveReplay(ReplayDataV1 param, int category)
    {
        // データストアの「ReplayData」クラスから、Nameをキーにして検索
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("ReplayDataV1");

        query.WhereEqualTo("Id", param.Id);
        query.WhereEqualTo("ScoreKindValue", param.ScoreKindValue);
        query.WhereEqualTo("Row", param.Row);
        query.WhereEqualTo("Col", param.Col);
        query.WhereEqualTo("Color", param.Color);
        query.WhereEqualTo("Link", param.Link);
        query.WhereEqualTo("Direction", param.Direction);
        query.WhereEqualTo("Time", param.Time);
        query.WhereEqualTo("Stop", param.Stop);
        query.WhereEqualTo("CountDisp", param.CountDisp);
        query.WhereEqualTo("Garbage", param.Garbage);
        query.WhereEqualTo("ScoreCategoryValue", category);

        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            //検索成功したら
            if (e == null)
            {
                // リプレイが未登録だったら
                if (objList.Count == 0)
                {
                    NCMBObject obj        = new NCMBObject("ReplayDataV1");
                    obj["Version"]        = param.Version;
                    obj["Id"]             = param.Id;
                    obj["PlayDateTime"]   = param.PlayDateTime;
                    obj["ScoreKindValue"] = param.ScoreKindValue;
                    obj["Seed"]           = param.Seed;
                    obj["FrameCount"]     = param.FrameCount;
                    obj["InputCount"]     = param.InputCount;
                    obj["InputFrame"]     = param.InputFrame;
                    obj["InputType"]      = param.InputType;
                    obj["InputData1"]     = param.InputData1;
                    obj["InputData2"]     = param.InputData2;

                    obj["Row"]                = param.Row;
                    obj["Col"]                = param.Col;
                    obj["Color"]              = param.Color;
                    obj["Link"]               = param.Link;
                    obj["Direction"]          = param.Direction;
                    obj["Time"]               = param.Time;
                    obj["Stop"]               = param.Stop;
                    obj["CountDisp"]          = param.CountDisp;
                    obj["Garbage"]            = param.Garbage;
                    obj["ScoreCategoryValue"] = category;

                    obj.SaveAsync();
                }
                // リプレイが登録済みだったら
                else
                {
                    objList[0]["PlayDateTime"] = param.PlayDateTime;
                    objList[0]["Seed"]         = param.Seed;
                    objList[0]["Version"]      = param.Version;
                    objList[0]["FrameCount"]   = param.FrameCount;
                    objList[0]["InputCount"]   = param.InputCount;
                    objList[0]["InputFrame"]   = param.InputFrame;
                    objList[0]["InputType"]    = param.InputType;
                    objList[0]["InputData1"]   = param.InputData1;
                    objList[0]["InputData2"]   = param.InputData2;
                    objList[0].SaveAsync();
                }
            }
        });
    }
Пример #8
0
    // ============================================================
    // Replay
    // ============================================================
    public void fetchReplay(ReplayDataV1 param)
    {
        fetchReplayData.flag = false;

        version = param.Version;

        // データストアの「ReplayDataV1」クラスから検索
        NCMBQuery <NCMBObject> query = new NCMBQuery <NCMBObject>("ReplayDataV1");

        query.WhereEqualTo("Version", param.Version);
        query.WhereEqualTo("Id", param.Id);
        query.WhereEqualTo("PlayDateTime", param.PlayDateTime);
        query.WhereEqualTo("ScoreKindValue", param.ScoreKindValue);
        query.WhereEqualTo("Row", param.Row);
        query.WhereEqualTo("Col", param.Col);
        query.WhereEqualTo("Color", param.Color);
        query.WhereEqualTo("Link", param.Link);
        query.WhereEqualTo("Direction", param.Direction);
        query.WhereEqualTo("Time", param.Time);
        query.WhereEqualTo("Stop", param.Stop);
        query.WhereEqualTo("CountDisp", param.CountDisp);
        query.WhereEqualTo("Garbage", param.Garbage);
        query.WhereEqualTo("ScoreCategoryValue", param.ScoreCategoryValue);

        query.Limit = 1;
        query.FindAsync((List <NCMBObject> objList, NCMBException e) =>
        {
            if (e != null)
            {
                //検索失敗時の処理
            }
            else
            {
                //検索成功時の処理

                // 取得したレコードをScoreDataV1クラスとして保存
                foreach (NCMBObject obj in objList)
                {
                    ReplayDataV1 data = new ReplayDataV1();
                    if (version != 0)
                    {
                        data.Version        = System.Convert.ToInt32(obj["Version"]);
                        data.Id             = System.Convert.ToString(obj["Id"]);
                        data.PlayDateTime   = System.Convert.ToInt64(obj["PlayDateTime"]);
                        data.ScoreKindValue = System.Convert.ToInt32(obj["ScoreKindValue"]);

                        data.Row                = System.Convert.ToInt32(obj["Row"]);
                        data.Col                = System.Convert.ToInt32(obj["Col"]);
                        data.Color              = System.Convert.ToInt32(obj["Color"]);
                        data.Link               = System.Convert.ToInt32(obj["Link"]);
                        data.Direction          = System.Convert.ToInt32(obj["Direction"]);
                        data.Time               = System.Convert.ToInt32(obj["Time"]);
                        data.Stop               = System.Convert.ToInt32(obj["Stop"]);
                        data.CountDisp          = System.Convert.ToInt32(obj["CountDisp"]);
                        data.Garbage            = System.Convert.ToInt32(obj["Garbage"]);
                        data.ScoreCategoryValue = System.Convert.ToInt32(obj["ScoreCategoryValue"]);

                        data.Seed       = System.Convert.ToInt32(obj["Seed"]);
                        data.FrameCount = System.Convert.ToInt32(obj["FrameCount"]);
                        data.InputCount = System.Convert.ToInt32(obj["InputCount"]);
                        data.InputFrame = new int[data.InputCount];
                        data.InputType  = new byte[data.InputCount];
                        data.InputData1 = new byte[data.InputCount];
                        data.InputData2 = new byte[data.InputCount];
                        for (int idx = 0; idx < data.InputCount; idx++)
                        {
                            ArrayList listData;
                            listData             = (ArrayList)obj["InputFrame"];
                            data.InputFrame[idx] = System.Convert.ToInt32(listData[idx]);
                            listData             = (ArrayList)obj["InputType"];
                            data.InputType[idx]  = System.Convert.ToByte(listData[idx]);
                            listData             = (ArrayList)obj["InputData1"];
                            data.InputData1[idx] = System.Convert.ToByte(listData[idx]);
                            listData             = (ArrayList)obj["InputData2"];
                            data.InputData2[idx] = System.Convert.ToByte(listData[idx]);
                        }
                    }
                    fetchReplayData.replayData = data;
                }
                fetchReplayData.flag = true;
            }
        });
    }