Example #1
0
	public static void Show(UniRPGArgsEventHandler onAccept, RPGEvent selectedEvent, object[] args)
	{
		// make sure DB is loaded
		if (!UniRPGEditorGlobal.LoadDatabase()) return;

		// create window
		EventSelectWiz window = EditorWindow.GetWindow<EventSelectWiz>(true, "Select Event", true);
		window.inited = false;
		window.selectedEvent = selectedEvent;
		window.args = args;
		window.OnAccept2 = onAccept;

		// show window
		window.ShowUtility();
	}
Example #2
0
	// ================================================================================================================

	public void CopyTo(RPGEvent e)
	{
		e.id = this.id.Copy();

		e.screenName = this.screenName;
		e.description = this.description;
		e.notes = this.notes;
		e.icon = new Texture2D[3] { this.icon[0], this.icon[1], this.icon[2] };
		e.guiHelper = this.guiHelper;

		e.onUseActions = new List<Action>(0);
		GameObject g = e.gameObject;
		foreach (Action act in this.onUseActions)
		{
			Action newAct = (Action)g.AddComponent(act.GetType());
			newAct.hideFlags = HideFlags.HideInInspector;
			act.CopyTo(newAct);
			e.onUseActions.Add(newAct);
		}
	}
Example #3
0
	void OnGUI()
	{
		if (!inited) Init();
		UniRPGEdGui.UseSkin();
		scroll = UniRPGEdGui.BeginScrollView(scroll);
		{
			if (UniRPGEditorGlobal.DB.RPGEvents.Length > 0)
			{
				for (int i = 0; i < UniRPGEditorGlobal.DB.RPGEvents.Length; i++)
				{
					Rect r = EditorGUILayout.BeginHorizontal();
					{
						r.x = 3; r.width = 19; r.height = 19;
						GUI.DrawTexture(r, (UniRPGEditorGlobal.DB.RPGEvents[i].icon[0] != null ? UniRPGEditorGlobal.DB.RPGEvents[i].icon[0] : UniRPGEdGui.Texture_NoPreview));
						GUILayout.Space(21);
						if (UniRPGEdGui.ToggleButton(selectedEvent == UniRPGEditorGlobal.DB.RPGEvents[i], UniRPGEditorGlobal.DB.RPGEvents[i].screenName, UniRPGEdGui.ButtonRightStyle, UniRPGEdGui.ButtonOnColor, GUILayout.Width(150)))
						{
							selectedEvent = UniRPGEditorGlobal.DB.RPGEvents[i];
						}
					}
					EditorGUILayout.EndHorizontal();
				}
			}
			else
			{
				GUILayout.Label("No Events are defined", UniRPGEdGui.WarningLabelStyle);
			}
		}
		UniRPGEdGui.EndScrollView();
		UniRPGEdGui.DrawHorizontalLine(1, UniRPGEdGui.DividerColor, 0, 10);

		EditorGUILayout.BeginHorizontal();
		{
			GUILayout.FlexibleSpace();

			if (selectedEvent == null) GUI.enabled = false;
			if (GUILayout.Button("Accept", UniRPGEdGui.ButtonStyle)) accepted = true;
			GUI.enabled = true;

			if (GUILayout.Button("Cancel", UniRPGEdGui.ButtonStyle)) this.Close();
			GUILayout.FlexibleSpace();
		}
		EditorGUILayout.EndHorizontal();
		GUILayout.Space(10);
	}
Example #4
0
	public void Init(GameObject owningActor)
	{
		this.owningActor = owningActor;
		Bonus = 0f;
		BonusMax = 0f;
		MinValue = data.baseMin;
		MaxValue = data.baseMax;
		_value = data.baseVal;
		if (_value > MaxValue) _value = MaxValue;
		if (_value < MinValue) _value = MinValue;

		if (data.onValChangeEventPrefab)
		{
			GameObject go = (GameObject)Instantiate(data.onValChangeEventPrefab);
			go.transform.parent = owningActor.transform;
			onValChangeEvent = go.GetComponent<RPGEvent>();
		}
		if (data.onMinValueEventPrefab)
		{
			GameObject go = (GameObject)Instantiate(data.onMinValueEventPrefab);
			go.transform.parent = owningActor.transform;
			onMinValueEvent = go.GetComponent<RPGEvent>();
		}
		if (data.onMaxValueEventPrefab)
		{
			GameObject go = (GameObject)Instantiate(data.onMaxValueEventPrefab);
			go.transform.parent = owningActor.transform;
			onMaxValueEvent = go.GetComponent<RPGEvent>();
		}
	}
Example #5
0
	// ================================================================================================================

	private void LeftPanel()
	{
		EditorGUILayout.BeginVertical(GUILayout.Width(DatabaseEditor.LeftPanelWidth));
		GUILayout.Space(5);
		// -------------------------------------------------------------

		// the add button
		EditorGUILayout.Space();
		EditorGUILayout.BeginHorizontal();
		{
			GUILayout.FlexibleSpace();
			if (GUILayout.Button(new GUIContent("Add Event", UniRPGEdGui.Icon_Plus), EditorStyles.miniButtonLeft))
			{
				GUI.FocusControl("");
				TextInputWiz.Show("New RPGEvent", "Enter name for new Event", "", CreateNewEvent);
			}
			if (curr == null) GUI.enabled = false;
			if (GUILayout.Button(new GUIContent(UniRPGEdGui.Icon_Copy, "Copy"), EditorStyles.miniButtonMid))
			{
				GUI.FocusControl("");
				CreateEventCopy();
			}
			GUI.enabled = true;
		}
		EditorGUILayout.EndHorizontal();
		EditorGUILayout.Space();

		scroll[0] = UniRPGEdGui.BeginScrollView(scroll[0], GUILayout.Width(DatabaseEditor.LeftPanelWidth));
		{
			if (ed.db.RPGEvents.Length > 0)
			{
				foreach (RPGEvent rpgEvent in ed.db.RPGEvents)
				{
					if (rpgEvent == null) continue;

					Rect r = EditorGUILayout.BeginHorizontal(GUILayout.Width(DatabaseEditor.LeftPanelWidth - 20), GUILayout.ExpandWidth(false));
					{
						r.x = 3; r.width = 19; r.height = 19;
						GUI.DrawTexture(r, (rpgEvent.icon[0] != null ? rpgEvent.icon[0] : UniRPGEdGui.Texture_NoPreview));
						GUILayout.Space(21);
						if (UniRPGEdGui.ToggleButton(curr == rpgEvent, rpgEvent.screenName, UniRPGEdGui.ButtonMidStyle, GUILayout.Width(140), GUILayout.ExpandWidth(false)))
						{
							curr = rpgEvent;
							GUI.FocusControl("");
						}
						if (GUILayout.Button("X", UniRPGEdGui.ButtonRightStyle, GUILayout.Width(20)))
						{
							del = rpgEvent;
						}
					}
					EditorGUILayout.EndHorizontal();
				}
			}
			else
			{
				GUILayout.Label("No Events are defined", UniRPGEdGui.WarningLabelStyle);
			}
		}
		UniRPGEdGui.EndScrollView();

		// -------------------------------------------------------------
		GUILayout.Space(3);
		EditorGUILayout.EndVertical();

		if (del != null)
		{
			if (curr == del) curr = null;
			ed.db.rpgEventPrefabs.Remove(del.gameObject);
			EditorUtility.SetDirty(ed.db);
			AssetDatabase.SaveAssets();

			string path = AssetDatabase.GetAssetPath(del.gameObject);
			AssetDatabase.DeleteAsset(path);
			AssetDatabase.Refresh();
			del = null;
		}
	}
Example #6
0
	private void CreateEventCopy()
	{
		string name = curr.name;
		if (string.IsNullOrEmpty(name)) name = "Event";

		UniRPGEditorGlobal.CheckDatabasePath(UniRPGEditorGlobal.DB_DATA_PATH, UniRPGEditorGlobal.DB_EVENTS_PATH);
		string fn = UniRPGEditorGlobal.DB_EVENTS_PATH + name + ".prefab";
		if (UniRPGEdUtil.RelativeFileExist(fn)) fn = AssetDatabase.GenerateUniqueAssetPath(fn);

		Object prefab = PrefabUtility.CreateEmptyPrefab(fn);
		GameObject go = new GameObject(name);							// create temp object in scene 
		go.AddComponent<RPGEvent>();
		GameObject toRef = PrefabUtility.ReplacePrefab(go, prefab);		// save prefab
		GameObject.DestroyImmediate(go);								// clear temp object from scene

		RPGEvent e = toRef.GetComponent<RPGEvent>();
		e.screenName = name;
		curr.CopyTo(e);
		e.id = UniRPG.GUID.Create();
		curr = e;

		ed.db.rpgEventPrefabs.Add(toRef);

		EditorUtility.SetDirty(curr);
		EditorUtility.SetDirty(ed.db);
		AssetDatabase.SaveAssets();

		ed.Repaint();
	}
Example #7
0
	private void CreateNewEvent(System.Object sender)
	{
		TextInputWiz wiz = sender as TextInputWiz;
		string name = wiz.text;
		wiz.Close();

		if (string.IsNullOrEmpty(name)) name = "Event";

		UniRPGEditorGlobal.CheckDatabasePath(UniRPGEditorGlobal.DB_DATA_PATH, UniRPGEditorGlobal.DB_EVENTS_PATH);
		string fn = UniRPGEditorGlobal.DB_EVENTS_PATH + name + ".prefab";
		if (UniRPGEdUtil.RelativeFileExist(fn)) fn = AssetDatabase.GenerateUniqueAssetPath(fn);

		Object prefab = PrefabUtility.CreateEmptyPrefab(fn);
		GameObject go = new GameObject(name);							// create temp object in scene 
		go.AddComponent<RPGEvent>();
		GameObject toRef = PrefabUtility.ReplacePrefab(go, prefab);		// save prefab
		GameObject.DestroyImmediate(go);								// clear temp object from scene

		curr = toRef.GetComponent<RPGEvent>();
		curr.screenName = name;
		ed.db.rpgEventPrefabs.Add(toRef);

		EditorUtility.SetDirty(curr);
		EditorUtility.SetDirty(ed.db);
		AssetDatabase.SaveAssets();

		ed.Repaint();
	}