예제 #1
0
        internal static void LoadAddonSavedValues(string addonId)
        {
            // Check if values have already been loaded
            if (SavedValues.ContainsKey(addonId))
            {
                return;
            }

            // Create a new entry
            SavedValues.Add(addonId, new Dictionary <string, List <Dictionary <string, object> > >());

            // Verify that the directory exists
            Directory.CreateDirectory(SaveDataDirectoryPath);

            // Get the file path
            var filePath = Path.Combine(SaveDataDirectoryPath, addonId + ".json");

            // Check if save file exists
            if (!File.Exists(filePath))
            {
                return;
            }

            // Deserialize file contents
            var data = JsonConvert.DeserializeObject <Dictionary <string, List <Dictionary <string, object> > > >(File.ReadAllText(filePath));

            // Apply saved data to dictionary
            SavedValues[addonId] = data;
        }
예제 #2
0
 void Start()
 {
     Point = transform.localPosition;
     sv = FindObjectOfType<SavedValues>();
     maxX = 3;
     minX = -3;
     maxY = 3f;
     minY = -0.5f;
 }
예제 #3
0
        internal static void OnSaveTimerElapsed(object sender, ElapsedEventArgs elapsedEventArgs)
        {
            // Verify that the directory exists
            Directory.CreateDirectory(SaveDataDirectoryPath);

            foreach (var entry in MenuInstances)
            {
                // Serialize current data
                var data = new Dictionary <string, List <Dictionary <string, object> > >();
                foreach (var menu in entry.Value)
                {
                    data[menu.UniqueMenuId] = menu.ValueContainer.Serialize();
                }

                // Verify that there is data to save
                if (data.Count > 0)
                {
                    // Merge previous data with current data
                    var dataToSave = SavedValues.ContainsKey(entry.Key) ? SavedValues[entry.Key] : new Dictionary <string, List <Dictionary <string, object> > >();
                    foreach (var entryKeys in data)
                    {
                        dataToSave[entryKeys.Key] = entryKeys.Value;
                    }

                    // Get the file path
                    var filePath       = Path.Combine(SaveDataDirectoryPath, entry.Key + ".json");
                    var fileBackupPath = filePath + ".backup";

                    // Create a backup of the current file
                    if (File.Exists(filePath))
                    {
                        File.Copy(filePath, fileBackupPath, true);
                    }

                    try
                    {
                        // Write content to the file
                        File.WriteAllText(filePath, JsonConvert.SerializeObject(dataToSave));
                    }
                    catch (Exception e)
                    {
                        // Restore the backup
                        if (File.Exists(fileBackupPath))
                        {
                            Logger.Warn("Error during config file writing, restoring backup!");
                            File.Copy(fileBackupPath, filePath, true);
                        }
                    }

                    // Delete the backup file
                    File.Delete(fileBackupPath);
                }
            }
        }
예제 #4
0
 // Use this for initialization
 void Start()
 {
     Text[] ts = GetComponentsInChildren<Text>();
     foreach (var t in ts)
     {
         if (t.name == "Enemies")
             enemies = t;
         if (t.name == "Computers")
             computers = t;
     }
     victory = GameObject.FindGameObjectWithTag("Victory");
     victory.SetActive(false);
     pause = GameObject.FindGameObjectWithTag("Pause");
     pause.SetActive(false);
     sv = GameObject.FindObjectOfType<SavedValues>();
     Cursor.visible = false;
 }
예제 #5
0
    //this method will be called when load process is done
    private void LoadComplete(SavedValues data, SaveResult result, string message)
    {
        //result is success-> load your saved data into variables
        if (result == SaveResult.Success)
        {
            savedValues = data;
        }

        //if for some reason your load failed, create an empty data to work with inside your game or give a message to the user
        if (result == SaveResult.Error || result == SaveResult.EmptyData)
        {
            savedValues = new SavedValues();
        }

        //after load is done refresh the UI
        RefreshUI();
    }
예제 #6
0
 // Use this for initialization
 void Start()
 {
     sv = FindObjectOfType<SavedValues>();
 }
예제 #7
0
 // Use this for initialization
 void Start()
 {
     Time.timeScale = 1f;
     sv = FindObjectOfType<SavedValues>();
 }
예제 #8
0
 void Start()
 {
     sv = GameObject.FindObjectOfType<SavedValues>();
     // Call the Spawn function after a delay of the spawnTime and then continue to call after the same amount of time.
     InvokeRepeating("Spawn", 10f, 10f);
 }
예제 #9
0
파일: AI.cs 프로젝트: Kullax/competence
    IEnumerator Start()
    {
        sv = FindObjectOfType<SavedValues>();
        wayPointArray = sv.getWayPoints();
        nav = GetComponent<NavMeshAgent>();

        _playScare = Camera.main.GetComponent<SoundScript>().PlayAware;

        while (true)
            yield return StartCoroutine(HuntingState());
    }
예제 #10
0
 // Use this for initialization
 void Start()
 {
     sv = FindObjectOfType<SavedValues>();
     this.gameObject.SetActive(false);
 }
예제 #11
0
 // Use this for initialization
 void Start()
 {
     _renderer = GetComponent<Renderer>();
     sv = FindObjectOfType<SavedValues>();
 }