Пример #1
0
		/// <summary>
		/// Start a Dialogue Graph of the specified name. This will use the first graph that has the name. It will start 
		/// walking the graph and pass back a *DiaQConversation* object when a Dialogue node is reached, or null on error 
		/// or when the graph has reached its end.
		/// </summary>
		public bool Load(string assetPath)
		{
			if (!assetPath.EndsWith("/") && !assetPath.EndsWith("\\")) assetPath += "/";
			assetPath += "DiaQ.asset";
			asset = (DiaQAsset)Instantiate(Resources.Load(assetPath, typeof(DiaQAsset)));
			if (asset == null)
			{
				Debug.LogError("Error: DiaQ failed to load (" + assetPath + ")");
				return false;
			}
			return true;
		}
Пример #2
0
		public static void ShowWiz(OnAcceptEvent onAccept, DiaQAsset asset, object[] args)
		{
			if (asset == null) return;
			DiaQGraphSelectWiz window = EditorWindow.GetWindow<DiaQGraphSelectWiz>(true);
#if UNITY_4_5 || UNITY_4_6
			window.title = "Select Graph";
#else
			window.titleContent = new GUIContent("Select Graph");
#endif
			window.minSize = new Vector2(300, 350);
			window.maxSize = new Vector2(300, 350);
			window.OnAccept = onAccept;
			window.asset = asset;
			window.args = args;
			window.ShowUtility();
		}
Пример #3
0
		// ============================================================================================================
		#region loading

		/// <summary>
		/// Call this to load the DiaQ assets and get it ready for use. You must specify the path to the asset, as set in 
		/// the DiaQ editor settings, excluding the specific asset file. For example assetPath = *Assets/DiaQ/Sample/Resources/*. 
		/// Will return false if it failed to load.
		/// </summary>
		public bool Load()
		{
			Object res = Resources.Load("DiaQ", typeof(DiaQAsset));
			if (res == null)
			{
				// silently fail in UniRPG
				Debug.LogError("Error: DiaQ failed to locate and load (DiaQ.asset)");
				return false;
			}

			asset = (DiaQAsset)Instantiate(res);
			if (asset == null)
			{
				Debug.LogError("Error: DiaQ failed to locate and load (DiaQ.asset)");
				return false;
			}
			return true;
		}
Пример #4
0
		// ============================================================================================================

		private static void ShowVariableField(EditorWindow ed, DiaQDecisionTest t, DiaQAsset asset, float w)
		{
			GUILayout.BeginVertical();
			{
				// show main variable choise
				t.varType = (DiaQDecisionTest.VarType)EditorGUILayout.EnumPopup(t.varType, EditorStyles.miniButtonMid, GUILayout.Width(w));

				// show additional field for quest related var
				if (t.varType == DiaQDecisionTest.VarType.HasSeenPlayer)
				{
					if (t.valType != DiaQDecisionTest.ValType.True && t.valType != DiaQDecisionTest.ValType.False) t.valType = DiaQDecisionTest.ValType.True;
				}

				else if (t.varType == DiaQDecisionTest.VarType.AcceptedQuest || t.varType == DiaQDecisionTest.VarType.CompletedQuest || t.varType == DiaQDecisionTest.VarType.HandedInQuest)
				{
					if (t.valType != DiaQDecisionTest.ValType.True && t.valType != DiaQDecisionTest.ValType.False) t.valType = DiaQDecisionTest.ValType.True;
					if (t.s_opt1.Length < 2) t.s_opt1 = new string[] { "", "-" };
					if (GUILayout.Button(t.s_opt1[1], EditorStyles.miniButton, GUILayout.Width(w - 16))) DiaQuestSelectWiz.ShowWiz(_OnSelectedQuest, asset, new object[] { t, ed, asset });
				}

				else if (t.varType == DiaQDecisionTest.VarType.DiaQVariable)
				{
					if (t.valType < DiaQDecisionTest.ValType.Empty || t.valType > DiaQDecisionTest.ValType.DiaQVar) t.valType = DiaQDecisionTest.ValType.Empty;
					if (t.s_opt1.Length < 1) t.s_opt1 = new string[] { "" };
					GUILayout.BeginHorizontal();
					t.s_opt1[0] = EditorGUILayout.TextField(t.s_opt1[0], GUILayout.Width(w - 46));
					if (GUILayout.Button("<>", EditorStyles.miniButton, GUILayout.Width(30))) DiaQVarSelectWiz.ShowWiz(_OnSelectedVar, (s) => { t.s_opt1[0] = s; }, asset, new object[] { ed, asset });
					GUILayout.EndHorizontal();
				}

			}
			GUILayout.EndVertical();

			// --------------------------------------------------------------------------------------------------------
			// show test types that can be performed on this type of variable
			if (t.varType >= DiaQDecisionTest.VarType.HasSeenPlayer && t.varType <= DiaQDecisionTest.VarType.DiaQVariable)
			{
				t.testType = (DiaQDecisionTest.TestType)EditorGUILayout.Popup((int)t.testType, TestTypeNames1, EditorStyles.miniButtonMid, GUILayout.Width(30));
			}

		}
Пример #5
0
		//private static readonly string[] TestTypeNames2 = { "==", "!=", ">", "<", ">=", "<=" };

		public static void OnGUI(EditorWindow ed, DiaQDecision d, DiaQAsset asset, float areaWidth)
		{
			float w = (areaWidth - 104) * 0.5f;

			GUILayout.BeginHorizontal();
			{
				GUILayout.Label("Evaluation");
				if (GUILayout.Button("+", EditorStyles.miniButton, GUILayout.Width(30))) d.tests.Add(new DiaQDecisionTest());
				GUILayout.FlexibleSpace();
			}
			GUILayout.EndHorizontal();
			EditorGUILayout.Space();

			DiaQDecisionTest del = null;
			bool first = true;
			foreach (DiaQDecisionTest t in d.tests)
			{
				GUILayout.BeginHorizontal();
				{
					// delete button
					if (GUILayout.Button("x", EditorStyles.miniButtonLeft, GUILayout.Width(20))) del = t;
					
					// how to combine with previous test
					if (!first) t.combineWithPrev = EditorGUILayout.Popup(t.combineWithPrev, ComBineOptions, EditorStyles.miniButtonMid, GUILayout.Width(30));
					else GUILayout.Button(" ", EditorStyles.miniButtonMid, GUILayout.Width(30));
					first = false;
					
					ShowVariableField(ed, t, asset, w);
					ShowValueField(ed, t, asset, w);

					GUILayout.FlexibleSpace();
				}
				GUILayout.EndHorizontal();
				GUILayout.Space(5);
			}
			if (del != null) d.tests.Remove(del);
		}
Пример #6
0
		private static void LoadAsset(bool forceReload)
		{
			if (asset != null && !forceReload) return;

			assetsLocation = EditorPrefs.GetString(GetProjectName() + "_DiaQ_assetLocation", assetsLocation);
			assetsLocation = DiaQEdUtil.CheckRelativePathExist(assetsLocation, "Resources");
			EditorPrefs.SetString(GetProjectName() + "_DiaQ_assetLocation", assetsLocation);

			// load the graphs
#if UNITY_4_5 || UNITY_4_6
			asset = (DiaQAsset)Resources.LoadAssetAtPath(assetsLocation + assetFile, typeof(DiaQAsset));
#else
			asset = (DiaQAsset)AssetDatabase.LoadAssetAtPath(assetsLocation + assetFile, typeof(DiaQAsset));
#endif
			if (asset == null)
			{
				asset = ScriptableObject.CreateInstance<DiaQAsset>();
				AssetDatabase.CreateAsset(asset, assetsLocation + assetFile);
				AssetDatabase.Refresh();
			}
		}
Пример #7
0
		// ============================================================================================================

		private static void ShowValueField(EditorWindow ed, DiaQDecisionTest t, DiaQAsset asset, float w)
		{
			GUILayout.BeginVertical();
			{
				if (t.varType >= DiaQDecisionTest.VarType.HasSeenPlayer && t.varType <= DiaQDecisionTest.VarType.HandedInQuest)
				{
					t.valType = (DiaQDecisionTest.ValType)EditorGUILayout.Popup((int)t.valType, ValTypeNames1, EditorStyles.miniButtonRight, GUILayout.Width(w));
				}

				else if (t.varType == DiaQDecisionTest.VarType.DiaQVariable)
				{
					int sel = ((int)t.valType) - 2;
					if (sel < 0) sel = 0;
					EditorGUI.BeginChangeCheck();
					sel = EditorGUILayout.Popup(sel, ValTypeNames2, EditorStyles.miniButtonRight, GUILayout.Width(w));
					if (EditorGUI.EndChangeCheck())
					{
						t.valType = (DiaQDecisionTest.ValType)(sel + 2);
						t.s_opt2 = (t.valType == DiaQDecisionTest.ValType.Empty ? null : new string[] { "" });
					}

					if (t.valType == DiaQDecisionTest.ValType.String)
					{
						t.s_opt2[0] = EditorGUILayout.TextField(t.s_opt2[0], GUILayout.Width(w - 16));
					}
					else if (t.valType == DiaQDecisionTest.ValType.DiaQVar)
					{
						GUILayout.BeginHorizontal();
						t.s_opt2[0] = EditorGUILayout.TextField(t.s_opt2[0], GUILayout.Width(w-46)); 
						if (GUILayout.Button("<>", EditorStyles.miniButton, GUILayout.Width(30))) DiaQVarSelectWiz.ShowWiz(_OnSelectedVar, (s) => { t.s_opt2[0] = s; }, asset, new object[] { ed, asset });
						GUILayout.EndHorizontal();
					}

				}

			}
			GUILayout.EndVertical();
		}