Пример #1
0
		public void Init(Node node){
			if (!initialized) {
				initialized=true;
				root=node.Root;
				FieldInfo[] fields = this.GetType().GetPublicFields();
				for (int k=0; k< fields.Length; k++) {
					if (typeof(FsmVariable).IsAssignableFrom(fields [k].FieldType)) {
						FsmVariable variable = (FsmVariable)fields [k].GetValue (this);
						if (variable != null && variable.IsShared) {
							FsmVariable fsmVariable=node.Root.GetVariable (variable.Name)??GlobalVariables.GetVariable(variable.Name);
							if(fsmVariable != null){
								fields [k].SetValue (this, fsmVariable);
							//	Debug.Log(this.GetType()+" "+variable.Name);
							}
						}
					}		
				}
			}
		}
Пример #2
0
		protected override void OnAddNode (Node node, Type type)
		{
			if (FsmEditor.SelectedTransition == null) {
				EditorUtility.DisplayDialog("Could not add node " + type.Name + "!", "Select a transition before you add a condition.", "Cancel");
				return;			
			}
			Condition condition = (Condition)ScriptableObject.CreateInstance (type);
			condition.hideFlags = HideFlags.HideInHierarchy;
			condition.name = type.GetCategory () + "." + type.Name;

			FsmEditor.SelectedTransition.Conditions = ArrayUtility.Add<Condition> (FsmEditor.SelectedTransition.Conditions, condition);

			if (EditorUtility.IsPersistent (FsmEditor.SelectedTransition)) {
				AssetDatabase.AddObjectToAsset (condition, FsmEditor.SelectedTransition);
				AssetDatabase.SaveAssets ();
			}
			
			if(PreferencesEditor.GetBool(Preference.CloseConditionBrowserOnAdd,false)){
				base.Close();
			}
		}
Пример #3
0
		protected override void OnAddNode (Node node, Type type)
		{
			if(!typeof(State).IsAssignableFrom(node.GetType())){
				EditorUtility.DisplayDialog("Could not add node " + type.Name + "!", "You can only add actions to a state.", "Cancel");
				return;
			}

			State state = node as State;
			StateAction action = (StateAction)ScriptableObject.CreateInstance (type);
			action.hideFlags = HideFlags.HideInHierarchy;
			action.name = type.GetCategory () + "." + type.Name;
			state.Actions = ArrayUtility.Add<StateAction> (state.Actions, action);
			if (EditorUtility.IsPersistent (state)) {
				AssetDatabase.AddObjectToAsset (action, state);
				AssetDatabase.SaveAssets ();
			}

			if(PreferencesEditor.GetBool(Preference.CloseActionBrowserOnAdd,false)){
				base.Close();
			}
		}
Пример #4
0
		private void NodeContextMenu(){
			if (currentEvent.type != EventType.MouseDown || currentEvent.button != 1 || currentEvent.clickCount != 1){
				return;
			}	

			Node node=MouseOverNode();
			if (node == null) {
				return;			
			}
			GenericMenu nodeMenu = new GenericMenu ();
			nodeMenu.AddItem (FsmContent.makeTransition, false, delegate() {
				fromNode=node;
			});


			if(!node.IsStartNode && !(node is AnyState)){
				nodeMenu.AddItem (FsmContent.setAsDefault, false, delegate() {
					FsmEditorUtility.SetDefaultNode(node,FsmEditor.Active);
				});
			}else{
				nodeMenu.AddDisabledItem(FsmContent.setAsDefault);
			}

			if (node.GetType () == typeof(State)) {
				State state = node as State;
				nodeMenu.AddItem (FsmContent.sequence, state.IsSequence, delegate() {
					state.IsSequence=!state.IsSequence;
				});
			}

			if (node.GetType () != typeof(AnyState)) {
				nodeMenu.AddItem (FsmContent.copy, false, delegate() {
					Pasteboard.Copy (node);
				});
				
				nodeMenu.AddItem (FsmContent.delete, false, delegate() {
					if (selection.Contains (node)) {
						foreach (Node mNode in selection) {
							FsmEditorUtility.DeleteNode (mNode);
						}
						selection.Clear ();
						UpdateUnitySelection ();
					} else {
						FsmEditorUtility.DeleteNode (node);
					}
					EditorUtility.SetDirty (FsmEditor.Active);
				});
			} else {
				nodeMenu.AddDisabledItem(FsmContent.copy);
				nodeMenu.AddDisabledItem(FsmContent.delete);
			}
			nodeMenu.ShowAsContext ();
			Event.current.Use ();
		}
Пример #5
0
		private void AddTransition(Node fromNode,Node toNode){
			if (fromNode == null || toNode == null || toNode.GetType () == typeof(AnyState)) {
				return;
			}
			Transition transition= ScriptableObject.CreateInstance<Transition>();
			transition.hideFlags = HideFlags.HideInHierarchy;
			transition.Init(toNode,fromNode);
			if(EditorUtility.IsPersistent(fromNode)){
				AssetDatabase.AddObjectToAsset(transition,fromNode);
				AssetDatabase.SaveAssets();
			}
			fromNode.Transitions=ArrayUtility.Add<Transition>(fromNode.Transitions,transition);
			NodeInspector.Dirty ();	
		}
Пример #6
0
		private void DoTransition(Node node){
			var groups=node.Transitions.GroupBy (c => c.ToNode).ToList ();
			foreach(var group in groups){   
				Node toNode=group.First().ToNode;
				Node fromNode=group.First().FromNode;
				int arrowCount=group.Count() > 1 ? 3:1;
				bool offset=toNode.Transitions.Any(x=>x.ToNode == fromNode);
				Color color=group.Any(x=>x == FsmEditor.SelectedTransition)?Color.cyan:Color.white;
				DrawConnection(fromNode.position.center,toNode.position.center,color,arrowCount,offset); 

			}
		}
Пример #7
0
		private void DoNode(Node node){
			GUIStyle style= FsmEditorStyles.GetNodeStyle(node.color,selection.Contains(node),node.GetType()== typeof(StateMachine));

			GUI.Box (node.position, node.Name,style);

			if(ErrorChecker.HasErrors(node) && Event.current.type != EventType.Layout){
				Rect rect=node.position;
				if(node is StateMachine){
					rect.x+=10;
					rect.y+=6;
				}
				GUI.Label(rect,"","CN EntryError");
			}

			if (node is State && (node as State).IsSequence) {
				Rect rect=node.position;
				rect.x+=25;
				rect.y+=3;
				GUI.Label(rect,EditorGUIUtility.FindTexture( "d_PlayButtonProfile" ));			
			} 

			if(PreferencesEditor.GetBool(Preference.ShowStateDescription)){
				GUILayout.BeginArea(new Rect(node.position.x,node.position.y+node.position.height,node.position.width,500));
				GUILayout.Label(node.comment,FsmEditorStyles.wrappedLabel);
				GUILayout.EndArea();
			}

			if (FsmEditor.Active.Owner != null && FsmEditor.Active.Owner.ActiveNode && (node == FsmEditor.Active.Owner.ActiveNode || node == FsmEditor.Active.Owner.AnyState || node == FsmEditor.Active.Owner.ActiveNode.Parent) && EditorApplication.isPlaying) {
				Rect rect=new Rect(node.position.x+5,node.position.y+20,debugProgress,5);

				if(node == FsmEditor.Active.Owner.ActiveNode.Parent){
					rect.y+=5;
					rect.x+=15;
					rect.width*=0.8f;
				}
				GUI.Box(rect,"", "MeLivePlayBar");
			}	

		}
Пример #8
0
		private void SelectNodes(){
			int controlID = GUIUtility.GetControlID(FocusType.Passive);
			switch (currentEvent.rawType) {
			case EventType.MouseDown:
				GUIUtility.hotControl = controlID;
				selectionStartPosition=mousePosition;
				Node node = MouseOverNode();

				if(node != null){
					if(fromNode != null){
						AddTransition(fromNode,node);
						fromNode=null;
						GUIUtility.hotControl = 0;
						GUIUtility.keyboardControl = 0;
						return;
					}
					if(node.GetType() == typeof(StateMachine) && currentEvent.clickCount == 2){
						SelectStateMachine((StateMachine)node);	
					}else{
						if ( EditorGUI.actionKey || currentEvent.shift) {
							if (!this.selection.Contains (node)) {
								this.selection.Add (node);
							} else {
								this.selection.Remove (node);
							}
						} else if(!this.selection.Contains(node)){
							this.selection.Clear ();
							this.selection.Add (node);
						}
					}
					GUIUtility.hotControl = 0;
					GUIUtility.keyboardControl = 0;
					UpdateUnitySelection();
					return;
				}
				fromNode=null;
				selectionMode = SelectionMode.Pick;
				if (!EditorGUI.actionKey && !currentEvent.shift)
				{
					this.selection.Clear();
					UpdateUnitySelection();
				}
				currentEvent.Use ();
				break;
			case EventType.MouseUp:
				if(GUIUtility.hotControl == controlID){
					selectionMode = SelectionMode.None;
					GUIUtility.hotControl = 0;
					currentEvent.Use ();
				}
				break;
			case EventType.MouseDrag:
				if (GUIUtility.hotControl == controlID && !EditorGUI.actionKey && !currentEvent.shift && (selectionMode == SelectionMode.Pick || selectionMode == SelectionMode.Rect)) {
					selectionMode = SelectionMode.Rect;	
					SelectNodesInRect (FromToRect (selectionStartPosition, mousePosition));
					currentEvent.Use ();
				}
				break;
			case EventType.Repaint:
				if (GUIUtility.hotControl == controlID && selectionMode == SelectionMode.Rect) {
					FsmEditorStyles.selectionRect.Draw(FromToRect(selectionStartPosition, mousePosition), false, false, false, false);		
				}
				break;
			}
		}
Пример #9
0
        public void Init(Node toNode,Node fromNode) {
            this.toNode = toNode;
			this.fromNode = fromNode;
        }
Пример #10
0
		public TransitionEditor(Node node, Editor host)
		{
			this.host = host;
			this.node = node;
		}
Пример #11
0
		public static void Copy(Node node){
			Pasteboard.node = node;
		}
Пример #12
0
		protected virtual void OnAddNode(Node node, Type type){

		}