Esempio n. 1
0
    bool SaveConstructionData(ConstructionBuilder builder)
    {
        string serialized = ConstructionSerializer.SerializeConstruction(builder.construction.GetAllBricks());

        _numUserConstructions = PlayerPrefs.GetInt("numUserConstructions", 0);
        string constructionId = "construction_" + _numUserConstructions.ToString();
        bool   success        = false;

        try{
            PlayerPrefs.SetString(constructionId, serialized);
            success = true;
        }catch {
            Debug.LogError("Unable to save construction");
        }
        if (success)
        {
            _numUserConstructions++;
            PlayerPrefs.SetInt("numUserConstructions", _numUserConstructions);
        }
        return(success);
    }
Esempio n. 2
0
 public ConstructionBuilder SetUserConstruction(int index, Transform target)
 {
     if (_numUserConstructions > 0)
     {
         if (_numUserConstructions >= index)
         {
             string serialized = PlayerPrefs.GetString("construction_" + index.ToString());
             if (!string.IsNullOrEmpty(serialized))
             {
                 IList <BrickData> bricks = ConstructionSerializer.DeserializeConstruction(serialized);
                 return(SetConstruction(bricks, target));
             }
         }
         else
         {
             UnityEngine.Debug.LogFormat("no user construction for index {0}", index);
         }
     }
     else
     {
         Debug.Log("no user construction");
     }
     return(null);
 }