Example #1
0
        /// <summary>
        /// Updates the AnimatorAccess component of the specified game object.
        /// </summary>
        /// <param name="go">Go.</param>
        public void Update(GameObject go)
        {
            string file = GetTargetFile(go);

            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            ClassElementsBuilder a = new ClassElementsBuilder(go);
            CodeGeneratorResult  r = a.PrepareCodeGeneration(true);

            if (!r.Error)
            {
                r = a.GenerateCode();
                if (r.Success)
                {
                    BackupAndSave(a.Code, file);
                    EditorStatusObserver.CheckForAutoRefresh();
                }
            }
            else
            {
                Logger.Warning(r);
                EditorUtility.DisplayDialog(r.ErrorTitle, r.ErrorText, "OK");
            }
        }
Example #2
0
 /// <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.");
     }
 }