public override void OnInspectorGUI() { Moss myObject = (Moss)target; EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); if (EditorGUI.EndChangeCheck()) { myObject.UpdateMoss(); } }
public void Lauch() { go = true; //canGrow = true; pg = GetComponent <Plant> (); pg.InitializePlant(); growthSpeed = 1f / pg.maxDuration; lastUpdate = Time.time; if (hasMoss) { moss = (Moss)Instantiate(GameManager.gm.pm.mossPrefab, transform); moss.transform.localPosition = Vector3.zero; moss.finalRadius = mossRadius; moss.time = pg.time; moss.UpdateMoss(); } }
/// <summary> /// Create Folder on Google Drive /// </summary> /// <param name="FolderName"></param> /// <param name="parentID"></param> private string CreateFolder(string FolderName, string parentID) { try { string KatalogName = new DirectoryInfo(FolderName).Name.Trim('\\'); IList<Moss> _Files = new List<Moss>(); Moss _filesID = new Moss(); if (parentID == "root") { _Files = GoogleDrive.GetFilesMoss(service, "'root' in parents and name = '" + KatalogName.Replace(@"\", "") + "' and mimeType = 'application/vnd.google-apps.folder' and trashed = false", false, null); if (_Files.Count == 0) { _filesID = (GoogleDrive.createDirectory(service, KatalogName.Replace(@"\", ""), null, parentID)); if (_completeFolderList) googleDriveFolderListMoss.Add(_filesID); else { lock (googleDriveFolderListMoss_Temp) { googleDriveFolderListMoss_Temp.Add(_filesID); } } } else if (_Files.Count > 1) { MessageBox.Show("Fatal error. You have more than one 'Backup in Cloud' folder on your Google Drive"); return null; } else if (_Files.Count == 1) { lb_listProgress("Folder: [" + KatalogName + "] exist"); _filesID = _Files[0]; } return _filesID.Id; } else { _Files = findFolder(KatalogName.Replace(@"\", ""), parentID, null); if (_Files.Count == 0) { _filesID = (GoogleDrive.createDirectory(service, KatalogName.Replace(@"\", ""), null, parentID)); if (_completeFolderList) googleDriveFolderListMoss.Add(_filesID); else lock (googleDriveFolderListMoss_Temp) { googleDriveFolderListMoss_Temp.Add(_filesID); } } else { lb_listProgress("Folder: [" + KatalogName + "] exist"); _filesID = _Files[0]; } return _filesID.Id; } } catch (Exception x) { log.Error("Exception[12]: " + FolderName + " |" + x.Message + " | " + x); return null; } }
/// <summary> /// Upload File. /// </summary> /// <param name="FileToUpload"></param> /// <param name="directoryId"></param> private void UploadToGoogleDriveV3(string FileToUpload, string directoryId) { string nazwaPliku = Path.GetFileName(FileToUpload); long _fileSize = File.GetSize(FileToUpload); IList<Moss> _Files = findFile(nazwaPliku, null, directoryId); if (_Files.Count == 0) { Google.Apis.Drive.v3.Data.File newFile = GoogleDrive.uploadFile(service, FileToUpload, directoryId, ""); if (newFile == null) { Thread.Sleep(3000); log.Error("Error[30]: File " + FileToUpload + " was not sent."); newFile = GoogleDrive.uploadFile(service, FileToUpload, directoryId, ""); } else { Moss _file = new Moss(); if (CompareMD5) { _file.md5Checksum = GetMD5HashFromFile(FileToUpload); } _file.Id = newFile.Id; _file.Name = newFile.Name; _file.size = _fileSize; _file.mimeType = newFile.MimeType; _file.parents = directoryId; if (_completeFileList) googleDriveFileListMoss.Add(_file); else { lock (googleDriveFileListMoss_Temp) { googleDriveFileListMoss_Temp.Add(_file); } } } } else { GoogleDrive.Pause(); if (CompareMD5 == false) { lb_listProgress("Compare Size: " + nazwaPliku); if (_fileSize == _Files[0].size) { log.Info("File already exist on Google Drive " + FileToUpload + " Size: " + _fileSize); lb_listProgress(nazwaPliku + " already exists."); ALLprogressBarUpdate(_fileSize); return; } else { lb_listProgress("File has changed, update needed: " + nazwaPliku); Google.Apis.Drive.v3.Data.File UpdatedFile = GoogleDrive.updateFile(service, FileToUpload, _Files[0].Id); return; } } if (CompareMD5 == true) { string MD5GoogleDriveFile = _Files[0].md5Checksum.ToLower(); lb_listProgress("Calculate MD5: " + nazwaPliku); if (_fileSize > 100000000) Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { pro_curr.IsIndeterminate = true; })); string MD5LocalFile = GetMD5HashFromFile(FileToUpload).ToLower(); if (_fileSize > 100000000) Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { pro_curr.IsIndeterminate = false; })); if (MD5LocalFile == MD5GoogleDriveFile) { log.Info("File already exist on Google Drive " + FileToUpload + " MD5: " + MD5LocalFile); lb_listProgress(nazwaPliku + " already exists."); ALLprogressBarUpdate(_fileSize); } else { lb_listProgress("File has changed, update needed: " + nazwaPliku); Google.Apis.Drive.v3.Data.File UpdatedFile = GoogleDrive.updateFile(service, FileToUpload, _Files[0].Id); } } } }
/// <summary> /// Documentation: https://developers.google.com/drive/v2/reference/files/insert /// </summary> /// <param name="_service"></param> /// <param name="_name"></param> /// <param name="_description"></param> /// <param name="_parent"></param> /// <returns></returns> public static Moss createDirectory(DriveService _service, string _name, string _description, string _parent) { if (_name == null || _parent == null) { log.Error("Exception[2.1]: Folder name or parent are null. " + _name + "| " + _parent); return new Moss(); } Pause(); log.Info("Create catalog: " + _name); File NewDirectory = null; Moss returnValue = new Moss(); Dictionary<string, string> dictionary = new Dictionary<string, string>(); File body = new File(); body.Name = _name; body.Description = _description; body.MimeType = "application/vnd.google-apps.folder"; body.Parents = new List<string> { _parent }; body.Properties = dictionary; var request = _service.Files.Create(body); request.Fields = "id, name, parents, md5Checksum, description, mimeType"; do { try { NewDirectory = request.Execute(); } catch (Exception x) { log.Error("Exception[2]: " + x.Message + " | " + x); Task.Delay(3000).Wait(); continue; } } while (NewDirectory == null); Application.Current.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => { ((MainWindow)Application.Current.MainWindow).lb_currUpload.Content = "Folder: " + @_name + " successful created"; })); if (NewDirectory.Id != null && NewDirectory.MimeType != null && NewDirectory.Name != null && NewDirectory.Parents[0] != null) { returnValue.Id = NewDirectory.Id; returnValue.mimeType = NewDirectory.MimeType; returnValue.Name = NewDirectory.Name; returnValue.parents = NewDirectory.Parents[0]; } return returnValue; }