Search Unity

Save a List of colors

Discussion in 'Scripting' started by shardnzl, Jan 19, 2019.

  1. shardnzl

    shardnzl

    Joined:
    Jan 2, 2015
    Posts:
    8
    Hi all - any help greatly appreciated on why this doesn't work.
    I have a game with 11 additive scenes - each scene has a List of GameObjects that they pass to a static controller on loading and when the user clicks save i need to iterate through that list and find out the gameobjects material color and save it to disk (android). Save function .....

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.Runtime.Serialization.Formatters.Binary;
    5. using System.IO;
    6.  
    7. [System.Serializable]
    8. public static class SaveLoad {
    9.     public static List<Color> coloursUsed = new List<Color>();
    10.     public static Color thisColour;
    11.  
    12.     public static void Save(int page) {
    13.         SaveLoad.coloursUsed.Clear();
    14.         foreach(GameObject go in globals.colourables){
    15.                     SaveLoad.thisColour = go.GetComponent<Renderer>().material.color;
    16.                     SaveLoad.coloursUsed.Add(SaveLoad.thisColour);
    17.         }
    18.         BinaryFormatter bf = new BinaryFormatter();
    19.         FileStream file = File.Create(Application.persistentDataPath + "/page_" + page + ".gd");
    20.         bf.Serialize(file, SaveLoad.coloursUsed);
    21.         file.Close();
    22.     }
    This is the final piece of the development before launch :)