Beispiel #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");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Create a new AnimatorAccess component for the specified game object and saves it to targetCodeFile. The
        /// caller is responsible for ensuring that there is not yet a component existing with the same name.
        /// </summary>
        /// <param name="go">Go.</param>
        /// <param name="targetCodeFile">Target code file.</param>
        public void Create(GameObject go, string targetCodeFile)
        {
            ClassElementsBuilder gen    = new ClassElementsBuilder(go, targetCodeFile);
            CodeGeneratorResult  result = gen.PrepareCodeGeneration(false);

            if (result.Error)
            {
                EditorUtility.DisplayDialog(result.ErrorTitle, result.ErrorText, "OK");
                return;
            }
            result = gen.GenerateCode();
            if (result.Success)
            {
                BackupAndSave(gen.Code, targetCodeFile);
                EditorStatusObserver.RegisterForPostProcessing(gen.FullClassName);
            }
        }
Beispiel #3
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.");
     }
 }
Beispiel #4
0
 public void Refresh()
 {
     EditorStatusObserver.Refresh();
 }