Exemplo n.º 1
0
    private void Start()
    {
        saveData = transform.root.gameObject.GetComponent <StorageReferenceShootingCube>().data;

        if (saveData.Death)
        {
            Destroy(transform.root.gameObject);
        }

        currentHealth = saveData.CurrentHealth;

        healthBar.SetMaxHealth(maxHealth);
        healthBar.SetHealth(currentHealth);

        if (gmObjArmorPaint != null)
        {
            float minusColorG = 250f / 255f - armor / 5f;
            gmObjArmorPaint.GetComponent <Renderer>().material.color = new Color(255f / 255f, minusColorG, 50f / 255f, 1);
        }
    }
Exemplo n.º 2
0
    public static void SaveGame(List <GameObject> listGmObj)
    {
        //Для сериализации
        BinaryFormatter bf = new BinaryFormatter();
        //Создаём поток
        FileStream fs = new FileStream(filePath, FileMode.Create);

        foreach (GameObject saveGmObj in listGmObj)
        {
            saveGmObj.GetComponent <Motion>().SavePosition();
            DataStorageShootingCube saveDate = saveGmObj.GetComponent <StorageReferenceShootingCube>().data;
            //превращем объект в string закодированный Json
            string jsonData = JsonUtility.ToJson(saveDate, true);

            //сериализуем и сохраняем
            bf.Serialize(fs, jsonData);
        }

        //Закрываем поток
        fs.Close();
    }
Exemplo n.º 3
0
    public static void LoadGame(List <GameObject> listGmObj)
    {
        if (!File.Exists(filePath))
        {
            return;
        }

        BinaryFormatter bf = new BinaryFormatter();
        FileStream      fs = new FileStream(filePath, FileMode.Open);

        foreach (GameObject loadGmObj in listGmObj)
        {
            DataStorageShootingCube loadData = loadGmObj.GetComponent <StorageReferenceShootingCube>().data;
            JsonUtility.FromJsonOverwrite((string)bf.Deserialize(fs), loadData);

            loadGmObj.GetComponent <Motion>().LoadPosition();
        }

        fs.Close();

        //SceneManager.LoadScene(SceneManager.GetActiveScene().name);
    }