Exemple #1
0
		private void OnGUI(){
			GUILayout.BeginHorizontal ();
			DoSearch ();
			DoSettings ();
			GUILayout.EndHorizontal ();
			GUILayout.Space (2.0f);
			scroll = GUILayout.BeginScrollView (scroll);
			foreach (KeyValuePair<string,List<Type>> kvp in sortedTypes) {
				bool foldout=EditorPrefs.GetBool(kvp.Key,false);
				if(string.IsNullOrEmpty(searchString)){
					if (GUILayout.Button (kvp.Key,(foldout?(GUIStyle)"TE toolbarbutton" : EditorStyles.toolbarButton))) {
						foldout=!foldout;
						EditorPrefs.SetBool(kvp.Key,foldout);
					}
				}else{
					foldout=true;
				}

				if(foldout){
					foreach(Type actionType in kvp.Value){
						if(!string.IsNullOrEmpty(searchString) && !actionType.Name.ToLower().StartsWith(searchString.ToLower())){
							continue;
						}
						Color color = GUI.contentColor;
						GUI.contentColor = (active != null && actionType==active.GetType() ? EditorStyles.foldout.focused.textColor : color);
						
						if(GUILayout.Button(string.IsNullOrEmpty(searchString)?actionType.Name:actionType.GetCategory()+"."+actionType.Name,"label",GUILayout.ExpandWidth(true))){
							DestroyActive();
							
							ExecutableNode node = (ExecutableNode)ScriptableObject.CreateInstance(actionType);
							node.hideFlags=HideFlags.HideAndDontSave;
							node.name = actionType.Name;
							active=node;

							if ((EditorApplication.timeSinceStartup - clickTime) < doubleClickTime){
								if(FsmEditor.Active != null){
									int selectedStatesCount=FsmEditor.SelectionCount;
									if(selectedStatesCount==0){
										EditorUtility.DisplayDialog("Could not add node "+ active.GetType().Name+"!", "Select a state before adding nodes.", "Cancel");
									}else if(selectedStatesCount==1){
										Node selectedNode=FsmEditor.SelectedNodes[0];
										OnAddNode(selectedNode,active.GetType());
										NodeInspector.Dirty();
									}else{
										EditorUtility.DisplayDialog("Could not add node "+ active.GetType().Name+"!", "Select only one state. Adding nodes to multiple states is not supported.", "Cancel");
									}
								}
							}
							
							clickTime = EditorApplication.timeSinceStartup;
						}
						GUI.contentColor=color;
					}
				}
			}	
			GUILayout.EndScrollView ();
			if (active != null) {
				OnPreviewGUI(active);			
			}
		}
Exemple #2
0
		public FsmError(FsmError.ErrorType type,StateMachine stateMachine,State state,ExecutableNode executableNode,FsmVariable variable ,FieldInfo fieldInfo){
			this.type = type;
			this.variable = variable;
			this.fieldInfo = fieldInfo;
			this.stateMachine = stateMachine;
			this.state = state;
			this.executableNode = executableNode;

		}
Exemple #3
0
		public static void CheckForErrors(UnityEngine.Object targetObject){
			if (targetObject == null) {
				return;
			}
			if (targetObject.GetType ()==typeof(StateMachine)) {
				checkingStateMachine = targetObject as StateMachine;			
			}else if(targetObject.GetType()==typeof(State)){
				checkingState=targetObject as State;
			} else if (targetObject.GetType ().IsSubclassOf (typeof(ExecutableNode))) {
				checkingExecutableNode=targetObject as ExecutableNode;			
			}

			FieldInfo[] fields = targetObject.GetType().GetAllFields (BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
			for (int i=0; i<fields.Length; i++) {
				FieldInfo field=fields[i];
				if(field.HasAttribute(typeof(ReferenceAttribute)) || !field.IsSerialized()){
					continue;
				}
				object value=field.GetValue(targetObject);
				if(field.FieldType.IsSubclassOf(typeof(FsmVariable))){
					if(!field.HasAttribute(typeof(NotRequiredAttribute)) &&(value == null || CheckForVariableError(value as FsmVariable,field))){
						FsmError error=new FsmError(FsmError.ErrorType.RequiredField,checkingStateMachine,checkingState,checkingExecutableNode,value as FsmVariable,field);
						if(!ContainsError(error)){
							errorList.Add(error);
						}
					}
				}else if(field.FieldType.IsSubclassOf(typeof(UnityEngine.Object))){
					CheckForErrors(value as UnityEngine.Object);
				}else if(field.FieldType.IsArray){
					var array = value as Array;
					Type elementType = field.FieldType.GetElementType ();
					if(elementType.IsSubclassOf(typeof(UnityEngine.Object))){
						foreach(UnityEngine.Object element in array){
							CheckForErrors(element);
						}
					}
				}
			}
			checkForErrors = false;
		}
Exemple #4
0
		protected virtual void OnPreviewGUI(ExecutableNode node){
			GUIStyle style = new GUIStyle("IN BigTitle");
			style.padding.top=0;
			GUILayout.BeginVertical(style);
			GUILayout.BeginHorizontal();
			GUILayout.Label(node.name,EditorStyles.boldLabel);
			GUILayout.FlexibleSpace();
			GUIStyle labelStyle= new GUIStyle("label");
			labelStyle.contentOffset= new Vector2(0,5);
			if(!string.IsNullOrEmpty(node.GetHelpUrl()) && GUILayout.Button(FsmEditorStyles.helpIcon,labelStyle,GUILayout.Width(20))){
				Application.OpenURL(node.GetHelpUrl());
			}
			GUILayout.EndHorizontal();
			GUILayout.Space(3f);
			GUILayout.Label(node.GetTooltip(),FsmEditorStyles.wrappedLabel);
			GUILayout.BeginHorizontal();
			GUILayout.FlexibleSpace();

			Node selectedNode =FsmEditor.SelectionCount>0? FsmEditor.SelectedNodes [0]:null;

			if (GUILayout.Button (selectedNode != null? "Add to state" : "Select one state to add") &&  selectedNode != null) {
				OnAddNode(selectedNode, node.GetType());
				NodeInspector.Dirty();
			}

			GUILayout.EndHorizontal();
			GUILayout.EndVertical();
			
			if(PreferencesEditor.GetBool(Preference.ActionBrowserShowPreview,true)){
				EditorGUI.BeginDisabledGroup(true);
				GUIDrawer.OnGUI (node);
				EditorGUI.EndDisabledGroup();
				GUILayout.Space(5);
			}
		}