/// <summary> /// Overwrites the current controller with data passed in /// </summary> /// <param name="data"> crowd controller data</param> public void OverWriteData(CrowdData data) { if (Application.isPlaying) { // load the empty placeholders } else { // load the placeholders } }
/// <summary> /// Writes the data about the controller to disk in the streaming assets folder /// </summary> /// <param name="controller">The controller being saved </param> public static void SaveController(CrowdController controller) { if (controller == null) { return; } var _controllerData = new CrowdData(); var _sources = controller.Sources; _controllerData._stateNames = controller.GetCrowdStates(); var _groups = controller.GetGroups(); if (_groups != null) { _controllerData._groups = new GroupData[_groups.Length]; for (int i = 0; i < _groups.Length; i++) { _controllerData._groups[i] = _groups[i].GetData(_sources); } } _controllerData._unassignedGroup = controller.GetUnassignedGroup.GetData(_sources); if (_sources.Count > 0) { _controllerData._parents = new TransformData[_sources.Count]; for (int i = 0; i < _sources.Count; i++) { _controllerData._parents[i] = GetTransformData(_sources[i].transform); } } string _path = Application.streamingAssetsPath + @"/CrowdAIData"; Debug.Log(_path); string _fileName = @"/CrowdData - " + SceneManager.GetActiveScene().name + ".data.json"; Debug.Log(_fileName); Directory.CreateDirectory(_path); var _serializedData = JsonConvert.SerializeObject(_controllerData); File.WriteAllText(_path + _fileName, _serializedData); }