コード例 #1
0
    bool sendData(JengaData data)
    {
        if (udp == null)
        {
            return(false);
        }

        try {
            BinaryFormatter bf = new BinaryFormatter();
            using (MemoryStream ms = new MemoryStream()) {
                bf.Serialize(ms, data);
                byte[] bytes = ms.ToArray();
                int    res   = udp.Send(bytes, bytes.Length, ep);
                if (res != bytes.Length)
                {
                    return(false);
                }

                return(true);
            }
        } catch (System.Exception e) {
            Debug.LogError(e.Message);
            return(false);
        }
    }
コード例 #2
0
ファイル: Config.cs プロジェクト: Ioennir/NotJenga
    /// <summary>
    /// Tries to get the config if there is some. If you wanna load config call LoadJengaConfig.
    ///
    /// For bug prevention, LoadConfig sets to null the configuration so you have to explicitly load a config again.
    ///
    /// </summary>
    /// <returns>If there is no config, it will return null.</returns>
    public static JengaData GetJengaConfig()
    {
        JengaData data = _data;

        _data = null;
        return(data);
    }
コード例 #3
0
    void sendBlocks()
    {
        JengaData data = new JengaData();

        fillBlocks(ref data);
        sendData(data);
    }
コード例 #4
0
ファイル: Config.cs プロジェクト: Ioennir/NotJenga
 /// <summary>
 /// Will start saving the jenga game in another thread.
 /// </summary>
 /// <returns></returns>
 public static bool SaveJengaGame(GameObject[] pieces)
 {
     if (_instance._loadingData || _instance._loadingSavedGamesData != null)
     {
         Debug.Log("CAN'T SAVE");
         return(false);
     }
     _instance._loadingData = true;
     if (_data == null)
     {
         _data = new JengaData {
             id = UnityEngine.Random.Range(-100000, 100000)
         };
     }
     _data.jengas = new JengaPieceData[pieces.Length];
     _data.date   = DateTime.Now.Ticks;
     for (int i = 0; i < pieces.Length; ++i)
     {
         _data.jengas[i] = new JengaPieceData
         {
             position = pieces[i].transform.localPosition,
             rotation = pieces[i].transform.localRotation.eulerAngles,
             scale    = pieces[i].transform.localScale
         };
     }
     // We will keep with more login in KeepSavingJengaGame when this is finished loading
     _instance._loadingSavedGamesData = SaveSystem.LoadOnAnotherThread <SavedGamesData>("game_data.json");
     return(true);
 }
コード例 #5
0
    public void sendLost()
    {
        JengaData data = new JengaData();

        fillBlocks(ref data);
        data.lost = true;
        sendData(data);
    }
コード例 #6
0
    public void sendEndTurn()
    {
        lastData = Time.time;
        JengaData data = new JengaData();

        fillBlocks(ref data);
        data.endTurn = true;
        sendData(data);
    }
コード例 #7
0
ファイル: TowerGenerator.cs プロジェクト: Ioennir/NotJenga
 public void ResetWithLoad(JengaData data)
 {
     _towerData.towerAlreadyBuilt = false;
     _piecePool.DeactivateAll();
     _dataLoaded = data;
     Config.LoadJengaConfig(data);
     StartCoroutine(SpawnLoad());
     FindObjectOfType <PlayerInGame>().Reset(false);
 }
コード例 #8
0
    void fillBlocks(ref JengaData data)
    {
        List <JengaBlockData> lblocks = new List <JengaBlockData>();

        foreach (KeyValuePair <int, JengaBlock> b in dblocks)
        {
            if (b.Value != null)
            {
                lblocks.Add(new JengaBlockData(b.Value));
            }
        }
        data.blocks = lblocks.ToArray();
    }
コード例 #9
0
ファイル: TowerGenerator.cs プロジェクト: Ioennir/NotJenga
 private void Start()
 {
     _tower = new GameObject("Tower");
     _tower.transform.parent = transform;
     _piecePool  = GetComponent <Pool>();
     _dataLoaded = Config.GetJengaConfig();
     if (_dataLoaded == null)
     {
         StartCoroutine("BuildTower", buildInterval);
         return;
     }
     // Inject configuration again because
     // When you get jenga config it deletes
     // it because safety measures
     Config.LoadJengaConfig(_dataLoaded);
     StartCoroutine(SpawnLoad());
 }
コード例 #10
0
ファイル: Config.cs プロジェクト: Ioennir/NotJenga
 /// <summary>
 /// Loads jenga data so when we are in the gameplay scene
 /// we can have custom setups. if there is no config loaded it will spawn a standard tower.
 /// </summary>
 /// <param name="data"></param>
 public static void LoadJengaConfig(JengaData data)
 {
     _data = data;
 }