Ejemplo n.º 1
0
		public void Initialise (Animator animator, BaseAnimatorAccess animatorAccess) {
			LayerCount = animator.layerCount;
			LayerStatuses = new LayerStatus [LayerCount];
			for (int i = 0; i < LayerCount; i++) {
				LayerStatuses [i] = new LayerStatus (i, 0, 0);
			}
			// callback to overriden method in generated class to initialise state and transition infos
			animatorAccess.InitialiseEventManager ();
		}
Ejemplo n.º 2
0
 public void Initialise(Animator animator, BaseAnimatorAccess animatorAccess)
 {
     LayerCount    = animator.layerCount;
     LayerStatuses = new LayerStatus [LayerCount];
     for (int i = 0; i < LayerCount; i++)
     {
         LayerStatuses [i] = new LayerStatus(i, 0, 0);
     }
     // callback to overriden method in generated class to initialise state and transition infos
     animatorAccess.InitialiseEventManager();
 }
		public string GetFile (BaseAnimatorAccess component) {
			return Get (component).file;
		}
		string GetKey (BaseAnimatorAccess component) {
			if (component != null) {
				return component.GetType ().Name;
			}
			return "";
		}
		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];
		}
		public string RemoveBackup (BaseAnimatorAccess component) {
			string key = GetKey (component);
			if (entries.ContainsKey (key)) {
				string s = entries[key].backupFile;
				entries[key].backupFile = "";
				return s;
			}
			return "";
		}
		public bool HasBackup (BaseAnimatorAccess component) {
			return !string.IsNullOrEmpty (Get (component).backupFile);
		}
		public string GetBackupTimestamp (BaseAnimatorAccess component) {
			string key = GetKey (component);
			if (entries.ContainsKey (key)) {
				return entries[key].timestamp;
			}
			return "";
		}
Ejemplo n.º 9
0
		public string GetBackupTimestamp (BaseAnimatorAccess component) {
			return repository.GetBackupTimestamp (component);
		}
Ejemplo n.º 10
0
		public bool HasBackup (BaseAnimatorAccess component) {
			return repository.HasBackup (component);
		}
Ejemplo n.º 11
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.");
			}
		}
Ejemplo n.º 12
0
        public override void OnInspectorGUI()
        {
            AnimatorAccess.BaseAnimatorAccess myTarget = (AnimatorAccess.BaseAnimatorAccess)target;
            Attribute[] attrs   = Attribute.GetCustomAttributes(myTarget.GetType(), typeof(GeneratedClassAttribute), false);
            string      version = "Version: ";

            if (attrs.Length == 1)
            {
                GeneratedClassAttribute a = (GeneratedClassAttribute)attrs[0];
                version += a.CreationDate;
            }
            else
            {
                version += " not available";
            }
            GUILayout.Label(version);
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Check", EditorStyles.miniButtonLeft))
            {
                CheckForUpdates(true);
            }
            if (GUILayout.Button("Update", (updateCheck != null && updateCheck.Count > 0 ? InspectorStyles.MidMiniButtonHighLighted : EditorStyles.miniButtonMid)))
            {
                Manager.SharedInstance.Update(Selection.activeGameObject);
                updateCheck = null;
                dirty       = true;
            }
            if (GUILayout.Button("Refresh" + (dirty ? "*" : ""), (dirty ? InspectorStyles.RightMiniButtonHighLighted : EditorStyles.miniButtonRight)))
            {
                Manager.SharedInstance.Refresh();
                dirty = false;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Separator();
            if (EditorApplication.isCompiling || EditorApplication.isUpdating)
            {
                EditorGUILayout.BeginVertical();
                EditorGUILayout.LabelField("Loading, please wait ...");
                EditorGUILayout.EndVertical();
            }
            else
            {
                if (updateCheck != null)
                {
                    CheckForUpdates(false);
                    if (updateCheck.Count > 0)
                    {
                        EditorGUILayout.BeginVertical();
                        List <ClassMemberCompareElement> errors = updateCheck.FindAll((element) => element.result == ClassMemberCompareElement.Result.Error);
                        List <ClassMemberCompareElement> infos  = updateCheck.FindAll((element) => element.result > ClassMemberCompareElement.Result.Error);
                        // if there are severe errors, show them first above the foldout GUI element
                        if (errors.Count > 0)
                        {
                            string errorHintTooltip = "If one of the members is marked as obsolete, it will be removed during generation to avoid compiler errrors.\n\n" +
                                                      "If this is not the case, you probably have used the same name for an Animator state and for a parameter too.\n\n" +
                                                      "To use identical names for Animator states and parameters, go to settings and define prefixes for states and/or parameters.";
                            EditorGUILayout.LabelField(new GUIContent(errors.Count + " Naming Conflict(s)", errorHintTooltip), InspectorStyles.LabelRed);
                            foreach (ClassMemberCompareElement error in errors)
                            {
                                string errorTooltip = error.Message;
                                string errorLabel   = string.Format("{0} : {1}", error.Member, errorTooltip);
                                EditorGUILayout.LabelField(new GUIContent(errorLabel, errorTooltip), InspectorStyles.LabelHighLighted);
                            }
                            EditorGUILayout.Separator();
                        }
                        updateCheckFoldOutState = EditorGUILayout.Foldout(updateCheckFoldOutState, updateCheck.Count + " class member(s) to update");
                        if (updateCheckFoldOutState)
                        {
                            // compare elements are sorted already: new, obsolete, removed members
                            foreach (ClassMemberCompareElement c in infos)
                            {
                                string label   = string.Format("{0}", c.Signature);
                                string tooltip = "";
                                switch (c.result)
                                {
                                case ClassMemberCompareElement.Result.New:
                                    tooltip = string.Format("{0} {1} {2} will be added", c.memberType, c.ElementType, c.Signature);
                                    EditorGUILayout.LabelField(new GUIContent(label, iconAdd, tooltip));
                                    break;

                                case ClassMemberCompareElement.Result.Obsolete:
                                    tooltip = string.Format("{0} {1} {2} will be marked as obsolete", c.memberType, c.ElementType, c.Signature);
                                    EditorGUILayout.LabelField(new GUIContent(label, iconObsolete, tooltip));
                                    break;

                                case ClassMemberCompareElement.Result.Remove:
                                    tooltip = string.Format("{0} {1} {2} will be removed", c.memberType, c.ElementType, c.Signature);
                                    EditorGUILayout.LabelField(new GUIContent(label, iconRemove, tooltip));
                                    break;

                                default:
                                    break;
                                }
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }
                    else
                    {
                        EditorGUILayout.BeginVertical();
                        EditorGUILayout.LabelField(myTarget.GetType().Name + " is up to date");
                        EditorGUILayout.EndVertical();
                    }
                }
                else
                {
                    EditorGUILayout.BeginVertical();
                    if (dirty)
                    {
                        EditorGUILayout.LabelField("Press 'Refresh' to load updated component " + myTarget.GetType().Name);
                    }
                    else
                    {
                        EditorGUILayout.LabelField("Press 'Check' to get update information about " + myTarget.GetType().Name);
                    }
                    EditorGUILayout.EndVertical();
                }
            }
            EditorGUILayout.Separator();
            EditorGUILayout.BeginHorizontal();
            if (Manager.SharedInstance.HasBackup(myTarget))
            {
                EditorGUILayout.LabelField("Saved version " + Manager.SharedInstance.GetBackupTimestamp(myTarget));
                if (GUILayout.Button("Undo"))
                {
                    Manager.SharedInstance.Undo(myTarget);
                    updateCheck = null;
                    dirty       = true;
                }
            }
            else
            {
                EditorGUILayout.LabelField("No backup available");
                GUILayout.Button("Undo", InspectorStyles.ButtonDisabled);
            }
            EditorGUILayout.EndHorizontal();
        }