Пример #1
0
    private static void SaveCustomCommands(string path, CustomCommandContainer customCommands)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(CustomCommandContainer));

        FileStream stream = new FileStream(path, FileMode.Create);

        serializer.Serialize(stream, customCommands);

        stream.Close();
    }
Пример #2
0
    private static CustomCommandContainer LoadCustomCommands(string path)
    {
        XmlSerializer serializer = new XmlSerializer(typeof(CustomCommandContainer));

        FileStream stream = new FileStream(path, FileMode.Open);

        CustomCommandContainer customCommands = serializer.Deserialize(stream) as CustomCommandContainer;

        stream.Close();

        return(customCommands);
    }
Пример #3
0
    public static void Save(string path, CustomCommandContainer customCommands)
    {
        ClearCustomCommands();

        //OnBeforeSave() workaround
        CustomCommand[] existingCommands = FindObjectsOfType <CustomCommand>();

        if (existingCommands != null)
        {
            for (int i = 0; i < existingCommands.Length; i++)
            {
                existingCommands[i].StoreData();
                AddCustomCommandData(existingCommands[i].data);
            }
        }

        //OnBeforeSave();
        SaveCustomCommands(path, customCommands);
        ClearCustomCommands();
    }
Пример #4
0
    //public static event SerializeAction OnLoaded;
    //public static event SerializeAction OnBeforeSave;

    public static void Load(string path)
    {
        customCommandContainer = LoadCustomCommands(path);

        foreach (CustomCommandData data in customCommandContainer.customCommands)
        {
            CustomCommandDisplay.CreateCustomCommand(data, new Vector3(data.posX, data.posY, data.posZ), Quaternion.identity);
        }

        //OnLoaded event listener workaround
        CustomCommand[] existingCommands = FindObjectsOfType <CustomCommand>();

        if (existingCommands != null)
        {
            for (int i = 0; i < existingCommands.Length; i++)
            {
                existingCommands[i].LoadData();
            }
        }

        //OnLoaded();
    }