string GetKey(BaseAnimatorAccess component) { if (component != null) { return(component.GetType().Name); } return(""); }
public static BaseAnimatorAccess GetActiveAnimatorAccessComponent() { BaseAnimatorAccess a = null; if (Selection.activeGameObject != null) { a = Selection.activeGameObject.GetComponent <BaseAnimatorAccess> (); } return(a); }
public string GetBackupTimestamp(BaseAnimatorAccess component) { string key = GetKey(component); if (entries.ContainsKey(key)) { return(entries[key].timestamp); } return(""); }
public string RemoveBackup(BaseAnimatorAccess component) { string key = GetKey(component); if (entries.ContainsKey(key)) { string s = entries[key].backupFile; entries[key].backupFile = ""; return(s); } return(""); }
/// <summary> /// Udpate contructor. /// </summary> /// <param name="go">GameObject to generate an AnimatorAccess class for.</param> public ClassElementsBuilder(GameObject go) { BaseAnimatorAccess animatorAccess = go.GetComponent <BaseAnimatorAccess> (); if (animatorAccess != null) { existingClassBuilder = new ReflectionCodeElementsBuilder(animatorAccess); className = existingClassBuilder.ClassName; config = ConfigFactory.Get(className); templateEngine = new SmartFormatTemplateEngine(); builder = new AnimatorCodeElementsBuilder(go, className, config); existingAllTransitionsHash = animatorAccess.AllTransitionsHash; } else { Logger.Error("Cannot access component BaseAnimatorAccess from object " + go.name); } }
MetaInfo Get(BaseAnimatorAccess component) { var key = GetKey(component); if (!entries.ContainsKey(key)) { string fileName = key + ".cs"; string backupFileName = key + ".txt"; string file = CodeGenerationUtils.GetPathToFile(fileName); string backupFile = CodeGenerationUtils.GetPathToFile(backupFileName, backupDir); string timestamp = ""; if (!string.IsNullOrEmpty(backupFile)) { timestamp += File.GetCreationTime(backupFile); } entries [key] = new MetaInfo(file, backupFile, timestamp); } return(entries [key]); }
/// <summary> /// Show the File save dialog to determine the file name to write to. /// </summary> /// <returns>The target file or "" if user has cancelled the file chooser.</returns> /// <param name="go">Game object to build reasonable preset file name.</param> string GetTargetFile(GameObject go) { BaseAnimatorAccess a = go.GetComponent <BaseAnimatorAccess> (); string targetCodeFile = a.GetType().Name + ".cs"; string[] files = Directory.GetFiles(Application.dataPath, targetCodeFile, SearchOption.AllDirectories); if (files.Length > 1 || files.Length == 0) { targetCodeFile = EditorUtility.SaveFilePanel(files.Length + " target file(s) found. Please select", ResourcesDir, targetCodeFile, "cs"); if (targetCodeFile == null || targetCodeFile == "") { return(""); } } else { targetCodeFile = files [0]; } return(targetCodeFile); }
/// <summary> /// Restore the current AnimatorAcces component, if there is a backup available. /// </summary> /// <param name="component">Component.</param> public void Undo(BaseAnimatorAccess component) { if (HasBackup(component)) { string backupFile = repository.RemoveBackup(component); string file = repository.GetFile(component); try { FileInfo sourceInfo = new FileInfo(backupFile); System.DateTime t = sourceInfo.CreationTime; File.Copy(backupFile, file, true); File.SetCreationTime(file, t); File.SetLastWriteTime(file, t); File.Delete(backupFile); Logger.Debug("Undo: " + file + " replaced by backup " + backupFile + " from " + t); EditorStatusObserver.CheckForAutoRefresh(); } catch (System.Exception ex) { Logger.Warning(ex.Message); } } else { Logger.Warning("No target file for undo found."); } }
public bool HasBackup(BaseAnimatorAccess component) { return(!string.IsNullOrEmpty(Get(component).backupFile)); }
public string GetFile(BaseAnimatorAccess component) { return(Get(component).file); }
public string GetBackupTimestamp(BaseAnimatorAccess component) { return(repository.GetBackupTimestamp(component)); }
public bool HasBackup(BaseAnimatorAccess component) { return(repository.HasBackup(component)); }