예제 #1
0
        protected void DrawSharedElements(ActionList _target)
        {
            if (PrefabUtility.GetPrefabType(_target) == PrefabType.Prefab)
            {
                EditorGUILayout.HelpBox("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info);
                return;
            }

            int numActions = 0;

            if (_target.source != ActionListSource.AssetFile)
            {
                numActions = _target.actions.Count;
                if (numActions < 1)
                {
                    numActions = 1;
                    AC.Action newAction = ActionList.GetDefaultAction();
                    _target.actions.Add(newAction);
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();

            if (_target.source == ActionListSource.AssetFile)
            {
                GUI.enabled = false;
            }

            if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(_target, "Expand actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = true;
                }
            }
            if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(_target, "Collapse actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = false;
                }
            }

            GUI.enabled = true;

            if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
            {
                if (_target.source == ActionListSource.AssetFile)
                {
                    if (_target.assetFile != null)
                    {
                        ActionListEditorWindow.Init(_target.assetFile);
                    }
                }
                else
                {
                    ActionListEditorWindow.Init(_target);
                }
            }
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
            {
                _target.Interact();
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (_target.source == ActionListSource.AssetFile)
            {
                return;
            }

            ActionListEditor.ResetList(_target);

            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                return;
            }

            if (!actionsManager.displayActionsInInspector)
            {
                EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info);
                return;
            }

            for (int i = 0; i < _target.actions.Count; i++)
            {
                if (_target.actions[i] == null)
                {
                    ACDebug.LogWarning("An empty Action was found, and was deleted");
                    _target.actions.RemoveAt(i);
                    continue;
                }

                EditorGUILayout.BeginVertical("Button");
                EditorGUILayout.BeginHorizontal();
                int    typeIndex   = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]);
                string actionLabel = " (" + (i).ToString() + ") " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel();
                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f));
                }

                if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                {
                    ActionSideMenu(i);
                }

                _target.actions[i].isAssetFile = false;

                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isBreakPoint)
                {
                    EditorGUILayout.HelpBox("Break point", MessageType.None);
                }

                if (_target.actions[i].isDisplayed)
                {
                    GUI.enabled = _target.actions[i].isEnabled;

                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type has been disabled in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");
                            _target.actions[i] = ActionListEditor.RebuildAction(_target.actions[i], newTypeIndex, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene);
                        }

                        if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0)
                        {
                            _target.actions[i].ShowGUI(_target.parameters);
                        }
                        else
                        {
                            _target.actions[i].ShowGUI(null);
                        }
                    }
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                GUI.enabled = true;

                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new action"))
            {
                Undo.RecordObject(_target, "Create action");
                numActions += 1;
            }

            _target.actions = ActionListEditor.ResizeList(_target.actions, numActions);
        }
        public override void OnInspectorGUI()
        {
            ActionListAsset _target = (ActionListAsset)target;

            ActionListAssetEditor.ShowPropertiesGUI(_target);
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(_target, "Expand actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = true;
                }
            }
            if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(_target, "Collapse actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = false;
                }
            }
            if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
            {
                ActionListEditorWindow.Init(_target);
            }
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
            {
                if (KickStarter.actionListAssetManager != null)
                {
                    if (!_target.canRunMultipleInstances)
                    {
                        int numRemoved = KickStarter.actionListAssetManager.EndAssetList(_target);
                        if (numRemoved > 0)
                        {
                            ACDebug.Log("Removed 1 instance of ActionList asset '" + _target.name + "' because it is set to only run one at a time.", _target);
                        }
                    }

                    AdvGame.RunActionListAsset(_target);
                }
                else
                {
                    ACDebug.LogWarning("An AC PersistentEngine object must be present in the scene for ActionList assets to run.", _target);
                }
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                return;
            }

            if (!actionsManager.displayActionsInInspector)
            {
                EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info);
                return;
            }

            for (int i = 0; i < _target.actions.Count; i++)
            {
                int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]);

                if (_target.actions[i] == null)
                {
                    _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], typeIndex, _target));
                }

                _target.actions[i].isAssetFile = true;

                EditorGUILayout.BeginVertical("Button");

                string actionLabel = " " + (i).ToString() + ": " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel();
                actionLabel = actionLabel.Replace("\r\n", "");
                actionLabel = actionLabel.Replace("\n", "");
                actionLabel = actionLabel.Replace("\r", "");
                if (actionLabel.Length > 40)
                {
                    actionLabel = actionLabel.Substring(0, 40) + "..)";
                }

                EditorGUILayout.BeginHorizontal();
                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.Width(100f));
                }

                if (GUILayout.Button(Resource.CogIcon, GUILayout.Width(20f), GUILayout.Height(15f)))
                {
                    ActionSideMenu(_target.actions[i]);
                }
                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isDisplayed)
                {
                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type has been disabled in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");

                            _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], newTypeIndex, _target, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene));
                        }

                        EditorGUILayout.Space();
                        GUI.enabled = _target.actions[i].isEnabled;

                        if (_target.useParameters)
                        {
                            if (Application.isPlaying)
                            {
                                _target.actions[i].AssignValues(_target.parameters);
                            }

                            _target.actions[i].ShowGUI(_target.parameters);
                        }
                        else
                        {
                            if (Application.isPlaying)
                            {
                                _target.actions[i].AssignValues(null);
                            }
                            _target.actions[i].ShowGUI(null);
                        }
                    }
                    GUI.enabled = true;
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new Action"))
            {
                Undo.RecordObject(_target, "Create action");
                AddAction(actionsManager.GetDefaultAction(), _target.actions.Count, _target);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_target);
            }
        }
예제 #3
0
        protected void DrawSharedElements(ActionList _target)
        {
            if (IsActionListPrefab(_target))
            {
                //EditorGUILayout.HelpBox ("Scene-based Actions can not live in prefabs - use ActionList assets instead.", MessageType.Info);
                //return;
            }

            int numActions = 0;

            if (_target.source != ActionListSource.AssetFile)
            {
                numActions = _target.actions.Count;
                if (numActions < 1)
                {
                    numActions = 1;
                    AddAction(ActionsManager.GetDefaultAction(), -1, _target);
                }
            }

            EditorGUILayout.Space();

            if (_target.source == ActionListSource.InScene)
            {
                ActionListEditor.ResetList(_target);
            }

            actionsManager = AdvGame.GetReferences().actionsManager;
            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                return;
            }

            if (!actionsManager.displayActionsInInspector || _target.source == ActionListSource.AssetFile)
            {
                if (Application.isPlaying)
                {
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("Edit Actions", GUILayout.Height(40f)))
                    {
                        ActionListEditorWindow.OpenForActionList(_target);
                    }

                    bool isRunning = false;
                    if (Application.isPlaying)
                    {
                        if (KickStarter.actionListManager != null)
                        {
                            isRunning = KickStarter.actionListManager.IsListRunning(_target);
                        }
                    }

                    if (isRunning)
                    {
                        if (GUILayout.Button("Stop", GUILayout.Height(40f)))
                        {
                            _target.Kill();
                        }
                    }
                    else
                    {
                        if (GUILayout.Button("Run now", GUILayout.Height(40f)))
                        {
                            _target.Interact();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    if (GUILayout.Button("Edit Actions", GUILayout.Height(40f)))
                    {
                        ActionListEditorWindow.OpenForActionList(_target);
                    }
                }
                return;
            }
            else
            {
                EditorGUILayout.BeginHorizontal();

                GUI.enabled = (_target.source == ActionListSource.InScene);

                if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
                {
                    Undo.RecordObject(_target, "Expand actions");
                    foreach (AC.Action action in _target.actions)
                    {
                        action.isDisplayed = true;
                    }
                }
                if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
                {
                    Undo.RecordObject(_target, "Collapse actions");
                    foreach (AC.Action action in _target.actions)
                    {
                        action.isDisplayed = false;
                    }
                }

                GUI.enabled = true;

                if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
                {
                    ActionListEditorWindow.OpenForActionList(_target);
                }
                GUI.enabled = Application.isPlaying;
                if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
                {
                    _target.Interact();
                }
                GUI.enabled = true;
                EditorGUILayout.EndHorizontal();
                EditorGUILayout.Space();
            }

            for (int i = 0; i < _target.actions.Count; i++)
            {
                if (_target.actions[i] == null)
                {
                    ACDebug.LogWarning("An empty Action was found, and was deleted", _target);
                    _target.actions.RemoveAt(i);
                    numActions--;
                    continue;
                }

                _target.actions[i].AssignParentList(_target);

                CustomGUILayout.BeginVertical();
                EditorGUILayout.BeginHorizontal();
                int typeIndex = actionsManager.GetActionTypeIndex(_target.actions[i]);

                string actionLabel = " (" + i.ToString() + ") " + actionsManager.GetActionTypeLabel(_target.actions[i], true);
                actionLabel = actionLabel.Replace("\r\n", "");
                actionLabel = actionLabel.Replace("\n", "");
                actionLabel = actionLabel.Replace("\r", "");
                if (actionLabel.Length > 40)
                {
                    actionLabel = actionLabel.Substring(0, 40) + "..)";
                }

                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth(100f));
                }

                if (GUILayout.Button("", CustomStyles.IconCog))
                {
                    ActionSideMenu(i);
                }

                _target.actions[i].isAssetFile = false;

                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isBreakPoint)
                {
                    EditorGUILayout.HelpBox("Break point", MessageType.None);
                }

                if (_target.actions[i].isDisplayed)
                {
                    GUI.enabled = _target.actions[i].isEnabled;

                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type is not listed in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");
                            _target.actions[i] = RebuildAction(_target.actions[i], newTypeIndex, _target, -1, _end);
                        }

                        if (_target.NumParameters > 0)
                        {
                            _target.actions[i].ShowGUI(_target.parameters);
                        }
                        else
                        {
                            _target.actions[i].ShowGUI(null);
                        }
                    }
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                GUI.enabled = true;

                CustomGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new action"))
            {
                Undo.RecordObject(_target, "Create action");
                numActions += 1;
            }

            _target = ActionListEditor.ResizeList(_target, numActions);
        }
		protected void DrawSharedElements ()
		{
			ActionList _target = (ActionList) target;
				
			if (_target.source == ActionListSource.AssetFile)
			{
				return;
			}
			
			if (AdvGame.GetReferences () == null)
			{
				Debug.LogError ("A References file is required - please use the Adventure Creator window to create one.");
				EditorGUILayout.LabelField ("No References file found!");
			}
			else
			{
				actionsManager = AdvGame.GetReferences ().actionsManager;
				
				if (actionsManager)
				{
					int numActions = _target.actions.Count;
					if (numActions < 1)
					{
						numActions = 1;
						AC.Action newAction = GetDefaultAction ();
						_target.actions.Add (newAction);
					}

					if (_target.useParameters)
					{
						ShowParametersGUI (_target);
					}

					EditorGUILayout.Space ();
					EditorGUILayout.BeginHorizontal ();
					if (GUILayout.Button ("Expand all", EditorStyles.miniButtonLeft))
					{
						Undo.RecordObject (_target, "Expand actions");
						foreach (AC.Action action in _target.actions)
						{
							action.isDisplayed = true;
						}
					}
					if (GUILayout.Button ("Collapse all", EditorStyles.miniButtonMid))
					{
						Undo.RecordObject (_target, "Collapse actions");
						foreach (AC.Action action in _target.actions)
						{
							action.isDisplayed = false;
						}
					}
					if (GUILayout.Button ("Action List Editor", EditorStyles.miniButtonMid))
					{
						ActionListEditorWindow window = (ActionListEditorWindow) EditorWindow.GetWindow (typeof (ActionListEditorWindow));
						window.Repaint ();
					}
					if (!Application.isPlaying)
					{
						GUI.enabled = false;
					}
					if (GUILayout.Button ("Run now", EditorStyles.miniButtonRight))
					{
						_target.Interact ();
					}
					GUI.enabled = true;
					EditorGUILayout.EndHorizontal ();
					EditorGUILayout.Space ();

					ActionListEditor.ResetList (_target);
					
					for (int i=0; i<_target.actions.Count; i++)
					{
						if (_target.actions[i] == null)
						{
							Debug.LogWarning ("An empty Action was found, and was deleted");
							_target.actions.RemoveAt (i);
						}

						EditorGUILayout.BeginVertical ("Button");
						typeNumber = ActionListEditor.GetTypeNumber (_target.actions[i]);
						categoryNumber = ActionListEditor.GetCategoryNumber (typeNumber);
						subCategoryNumber = ActionListEditor.GetSubCategoryNumber (_target.actions[i].title, categoryNumber);
						
						EditorGUILayout.BeginHorizontal ();
						string actionLabel = " " + (i).ToString() + ": " + _target.actions[i].title + _target.actions[i].SetLabel ();
						_target.actions[i].isDisplayed = EditorGUILayout.Foldout (_target.actions[i].isDisplayed, actionLabel);
						if (!_target.actions[i].isEnabled)
						{
							EditorGUILayout.LabelField ("DISABLED", EditorStyles.boldLabel, GUILayout.MaxWidth (100f));
						}
						Texture2D icon = (Texture2D) AssetDatabase.LoadAssetAtPath ("Assets/AdventureCreator/Graphics/Textures/inspector-use.png", typeof (Texture2D));
						if (GUILayout.Button (icon, GUILayout.Width (20f), GUILayout.Height (15f)))
						{
							ActionSideMenu (i);
						}

						_target.actions[i].isAssetFile = false;
						
						EditorGUILayout.EndHorizontal ();

						if (_target.actions[i].isDisplayed)
						{
							GUI.enabled = _target.actions[i].isEnabled;

							if (!actionsManager.DoesActionExist (_target.actions[i].GetType ().ToString ()))
							{
								EditorGUILayout.HelpBox ("This Action type has been disabled in the Actions Manager", MessageType.Warning);
							}
							else
							{
								EditorGUILayout.BeginHorizontal ();
								EditorGUILayout.LabelField ("Action type:", GUILayout.Width (150));
								categoryNumber = EditorGUILayout.Popup(categoryNumber, actionsManager.GetActionCategories ());
								subCategoryNumber = EditorGUILayout.Popup(subCategoryNumber, actionsManager.GetActionSubCategories (categoryNumber));
								EditorGUILayout.EndVertical ();
								
								typeNumber = actionsManager.GetTypeNumber (categoryNumber, subCategoryNumber);
								
								EditorGUILayout.Space ();

								// Rebuild constructor if Subclass and type string do not match
								if (_target.actions[i].GetType ().ToString () != actionsManager.GetActionName (typeNumber) &&
									_target.actions[i].GetType ().ToString () != ("AC." + actionsManager.GetActionName (typeNumber)))
								{
									ActionEnd _end = new ActionEnd ();
									_end.resultAction = _target.actions[i].endAction;
									_end.skipAction = _target.actions[i].skipAction;
									_end.linkedAsset = _target.actions[i].linkedAsset;
									_end.linkedCutscene = _target.actions[i].linkedCutscene;

									Undo.RecordObject (_target, "Change Action type");

									_target.actions[i] = ActionListEditor.RebuildAction (_target.actions[i], typeNumber, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene);
								}

								if (_target.useParameters && _target.parameters != null && _target.parameters.Count > 0)
								{
									_target.actions[i].ShowGUI (_target.parameters);
								}
								else
								{
									_target.actions[i].ShowGUI (null);
								}
							}
						}

						if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i].numSockets == 2 || _target.actions[i] is ActionCheckMultiple)
						{
							_target.actions[i].SkipActionGUI (_target.actions, _target.actions[i].isDisplayed);
						}

						GUI.enabled = true;
						
						EditorGUILayout.EndVertical();
						EditorGUILayout.Space ();
					}
					
					if (GUILayout.Button("Add new action"))
					{
						Undo.RecordObject (_target, "Create action");
						numActions += 1;
					}
					
					_target.actions = ActionListEditor.ResizeList (_target.actions, numActions);
				}
			}
		}
	public override void OnInspectorGUI ()
	{
		ActionListAsset _target = (ActionListAsset) target;
		actionsManager = AdvGame.GetReferences ().actionsManager;

		EditorGUILayout.BeginVertical ("Button");
		EditorGUILayout.LabelField ("Asset properties", EditorStyles.boldLabel);
		_target.actionListType = (ActionListType) EditorGUILayout.EnumPopup ("When running:", _target.actionListType);
		if (_target.actionListType == ActionListType.PauseGameplay)
		{
			_target.isSkippable = EditorGUILayout.Toggle ("Is skippable?", _target.isSkippable);
			_target.unfreezePauseMenus = EditorGUILayout.Toggle ("Unfreeze 'pause' Menus?", _target.unfreezePauseMenus);
		}
		_target.useParameters = EditorGUILayout.Toggle ("Use parameters?", _target.useParameters);
		EditorGUILayout.EndVertical ();

		if (_target.useParameters)
		{
			ShowParametersGUI (_target);
		}
		EditorGUILayout.Space ();

		EditorGUILayout.BeginHorizontal ();
		if (GUILayout.Button ("Expand all", EditorStyles.miniButtonLeft))
		{
			Undo.RecordObject (_target, "Expand actions");
			foreach (AC.Action action in _target.actions)
			{
				action.isDisplayed = true;
			}
		}
		if (GUILayout.Button ("Collapse all", EditorStyles.miniButtonMid))
		{
			Undo.RecordObject (_target, "Collapse actions");
			foreach (AC.Action action in _target.actions)
			{
				action.isDisplayed = false;
			}
		}
		if (GUILayout.Button ("Action List Editor", EditorStyles.miniButtonMid))
		{
			ActionListEditorWindow window = (ActionListEditorWindow) EditorWindow.GetWindow (typeof (ActionListEditorWindow));
			window.Repaint ();
		}
		if (!Application.isPlaying)
		{
			GUI.enabled = false;
		}
		if (GUILayout.Button ("Run now", EditorStyles.miniButtonRight))
		{
			AdvGame.RunActionListAsset (_target);
		}
		GUI.enabled = true;
		EditorGUILayout.EndHorizontal ();
		EditorGUILayout.Space ();

		for (int i=0; i<_target.actions.Count; i++)
		{
			typeNumber = ActionListEditor.GetTypeNumber (_target.actions[i]);

			if (_target.actions[i] == null)
			{
				_target.actions.Insert (i, ActionListAssetEditor.RebuildAction (_target.actions[i], typeNumber, _target));
			}
			
			categoryNumber = ActionListEditor.GetCategoryNumber (typeNumber);
			subCategoryNumber = ActionListEditor.GetSubCategoryNumber (_target.actions[i].title, categoryNumber);

			_target.actions[i].isAssetFile = true;
			
			EditorGUILayout.BeginVertical("Button");
			
			string actionLabel = " " + (i).ToString() + ": " + _target.actions[i].title + _target.actions[i].SetLabel ();
			
			EditorGUILayout.BeginHorizontal ();
			_target.actions[i].isDisplayed = EditorGUILayout.Foldout (_target.actions[i].isDisplayed, actionLabel);
			if (!_target.actions[i].isEnabled)
			{
				EditorGUILayout.LabelField ("DISABLED", EditorStyles.boldLabel, GUILayout.Width (100f));
			}

			Texture2D icon = (Texture2D) AssetDatabase.LoadAssetAtPath ("Assets/AdventureCreator/Graphics/Textures/inspector-use.png", typeof (Texture2D));
			if (GUILayout.Button (icon, GUILayout.Width (20f), GUILayout.Height (15f)))
			{
				ActionSideMenu (_target.actions[i]);
			}
			EditorGUILayout.EndHorizontal ();
			
			if (_target.actions[i].isDisplayed)
			{
				if (!actionsManager.DoesActionExist (_target.actions[i].GetType ().ToString ()))
				{
					EditorGUILayout.HelpBox ("This Action type has been disabled in the Actions Manager", MessageType.Warning);
				}
				else
				{
					EditorGUILayout.BeginHorizontal ();
					EditorGUILayout.LabelField ("Action type:", GUILayout.Width (150));
					categoryNumber = EditorGUILayout.Popup(categoryNumber, actionsManager.GetActionCategories ());
					subCategoryNumber = EditorGUILayout.Popup(subCategoryNumber, actionsManager.GetActionSubCategories (categoryNumber));
					EditorGUILayout.EndVertical ();

					typeNumber = actionsManager.GetTypeNumber (categoryNumber, subCategoryNumber);

					// Rebuild constructor if Subclass and type string do not match
					if (_target.actions[i].GetType ().ToString () != actionsManager.GetActionName (typeNumber) && _target.actions[i].GetType ().ToString () != ("AC." + actionsManager.GetActionName (typeNumber)))
					{
						ActionEnd _end = new ActionEnd ();
						_end.resultAction = _target.actions[i].endAction;
						_end.skipAction = _target.actions[i].skipAction;
						_end.linkedAsset = _target.actions[i].linkedAsset;
						_end.linkedCutscene = _target.actions[i].linkedCutscene;

						Undo.RecordObject (_target, "Change Action type");

						_target.actions.Insert (i, ActionListAssetEditor.RebuildAction (_target.actions[i], typeNumber, _target, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene));
					}

					EditorGUILayout.Space ();
					GUI.enabled = _target.actions[i].isEnabled;

					if (_target.useParameters)
					{
						_target.actions[i].ShowGUI (_target.parameters);
					}
					else
					{
						_target.actions[i].ShowGUI (null);
					}
				}
				GUI.enabled = true;
			}
			
			if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple)
			{
				_target.actions[i].SkipActionGUI (_target.actions, _target.actions[i].isDisplayed);
			}
			
			EditorGUILayout.EndVertical();
			EditorGUILayout.Space ();
		}
		
		if (GUILayout.Button("Add new Action"))
		{
			AddAction (actionsManager.GetActionName (actionsManager.defaultClass), _target.actions.Count, _target);
		}

		if (GUI.changed)
		{
			EditorUtility.SetDirty (_target);
		}
	}
예제 #6
0
        public override void OnInspectorGUI()
        {
            ActionListAsset _target = (ActionListAsset)target;

            EditorGUILayout.BeginVertical("Button");
            EditorGUILayout.LabelField("Asset properties", EditorStyles.boldLabel);
            _target.actionListType = (ActionListType)EditorGUILayout.EnumPopup("When running:", _target.actionListType);
            if (_target.actionListType == ActionListType.PauseGameplay)
            {
                _target.isSkippable        = EditorGUILayout.Toggle("Is skippable?", _target.isSkippable);
                _target.unfreezePauseMenus = EditorGUILayout.Toggle("Unfreeze 'pause' Menus?", _target.unfreezePauseMenus);
            }
            _target.useParameters = EditorGUILayout.Toggle("Use parameters?", _target.useParameters);
            EditorGUILayout.EndVertical();

            if (_target.useParameters)
            {
                ShowParametersGUI(_target);
            }
            EditorGUILayout.Space();

            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("Expand all", EditorStyles.miniButtonLeft))
            {
                Undo.RecordObject(_target, "Expand actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = true;
                }
            }
            if (GUILayout.Button("Collapse all", EditorStyles.miniButtonMid))
            {
                Undo.RecordObject(_target, "Collapse actions");
                foreach (AC.Action action in _target.actions)
                {
                    action.isDisplayed = false;
                }
            }
            if (GUILayout.Button("Action List Editor", EditorStyles.miniButtonMid))
            {
                ActionListEditorWindow.Init(_target);
            }
            if (!Application.isPlaying)
            {
                GUI.enabled = false;
            }
            if (GUILayout.Button("Run now", EditorStyles.miniButtonRight))
            {
                AdvGame.RunActionListAsset(_target);
            }
            GUI.enabled = true;
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (actionsManager == null)
            {
                EditorGUILayout.HelpBox("An Actions Manager asset file must be assigned in the Game Editor Window", MessageType.Warning);
                OnEnable();
                return;
            }

            if (!actionsManager.displayActionsInInspector)
            {
                EditorGUILayout.HelpBox("As set by the Actions Manager, Actions are only displayed in the ActionList Editor window.", MessageType.Info);
                return;
            }

            for (int i = 0; i < _target.actions.Count; i++)
            {
                int typeIndex = KickStarter.actionsManager.GetActionTypeIndex(_target.actions[i]);

                if (_target.actions[i] == null)
                {
                    _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], typeIndex, _target));
                }

                _target.actions[i].isAssetFile = true;

                EditorGUILayout.BeginVertical("Button");

                string actionLabel = " " + (i).ToString() + ": " + actionsManager.EnabledActions[typeIndex].GetFullTitle() + _target.actions[i].SetLabel();

                EditorGUILayout.BeginHorizontal();
                _target.actions[i].isDisplayed = EditorGUILayout.Foldout(_target.actions[i].isDisplayed, actionLabel);
                if (!_target.actions[i].isEnabled)
                {
                    EditorGUILayout.LabelField("DISABLED", EditorStyles.boldLabel, GUILayout.Width(100f));
                }

                Texture2D icon = (Texture2D)AssetDatabase.LoadAssetAtPath("Assets/AdventureCreator/Graphics/Textures/inspector-use.png", typeof(Texture2D));
                if (GUILayout.Button(icon, GUILayout.Width(20f), GUILayout.Height(15f)))
                {
                    ActionSideMenu(_target.actions[i]);
                }
                EditorGUILayout.EndHorizontal();

                if (_target.actions[i].isDisplayed)
                {
                    if (!actionsManager.DoesActionExist(_target.actions[i].GetType().ToString()))
                    {
                        EditorGUILayout.HelpBox("This Action type has been disabled in the Actions Manager", MessageType.Warning);
                    }
                    else
                    {
                        int newTypeIndex = ActionListEditor.ShowTypePopup(_target.actions[i], typeIndex);
                        if (newTypeIndex >= 0)
                        {
                            // Rebuild constructor if Subclass and type string do not match
                            ActionEnd _end = new ActionEnd();
                            _end.resultAction   = _target.actions[i].endAction;
                            _end.skipAction     = _target.actions[i].skipAction;
                            _end.linkedAsset    = _target.actions[i].linkedAsset;
                            _end.linkedCutscene = _target.actions[i].linkedCutscene;

                            Undo.RecordObject(_target, "Change Action type");

                            _target.actions.Insert(i, ActionListAssetEditor.RebuildAction(_target.actions[i], newTypeIndex, _target, _end.resultAction, _end.skipAction, _end.linkedAsset, _end.linkedCutscene));
                        }

                        EditorGUILayout.Space();
                        GUI.enabled = _target.actions[i].isEnabled;

                        if (_target.useParameters)
                        {
                            _target.actions[i].ShowGUI(_target.parameters);
                        }
                        else
                        {
                            _target.actions[i].ShowGUI(null);
                        }
                    }
                    GUI.enabled = true;
                }

                if (_target.actions[i].endAction == AC.ResultAction.Skip || _target.actions[i] is ActionCheck || _target.actions[i] is ActionCheckMultiple || _target.actions[i] is ActionParallel)
                {
                    _target.actions[i].SkipActionGUI(_target.actions, _target.actions[i].isDisplayed);
                }

                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Add new Action"))
            {
                Undo.RecordObject(_target, "Create action");
                AddAction(actionsManager.GetActionName(actionsManager.defaultClass), _target.actions.Count, _target);
            }

            if (GUI.changed)
            {
                EditorUtility.SetDirty(_target);
            }
        }