Пример #1
0
	public static RPGState CreateInstance(RPGState state, Transform eventParent)
	{
		RPGState s = ScriptableObject.CreateInstance<RPGState>();
		s.id = new GUID();
		s.id.Value = state.id.Value;
		s.slot = state.slot;
		s.effect = state.effect;
		s.timeoutSettings = state.timeoutSettings;
		s.autoRemoveTimeoutSettings = state.autoRemoveTimeoutSettings;
		s.eventPrefab = state.eventPrefab;

		if (s.effect == Effect.RunEventInIntervals && s.eventPrefab)
		{
			GameObject go = (GameObject)GameObject.Instantiate(s.eventPrefab);
			if (go)
			{
				go.transform.parent = eventParent;
				s.eventInstance = go.GetComponent<RPGEvent>();
				s.timeout = s.timeoutSettings;
				s.autoRemoveTimeout = s.autoRemoveTimeoutSettings;
			}
		}

		return s;
	}
Пример #2
0
	void OnGUI()
	{
		if (!inited) Init();
		UniRPGEdGui.UseSkin();
		
		scroll = UniRPGEdGui.BeginScrollView(scroll);
		{
			if (UniRPGEditorGlobal.DB.states.Count > 0)
			{
				foreach (RPGState cl in UniRPGEditorGlobal.DB.states)
				{
					Rect r = EditorGUILayout.BeginHorizontal();
					{
						r.x = 3; r.width = 19; r.height = 19;
						GUI.DrawTexture(r, (cl.icon[0] != null ? cl.icon[0] : UniRPGEdGui.Texture_NoPreview));
						GUILayout.Space(21);
						if (UniRPGEdGui.ToggleButton(selected == cl, cl.screenName, UniRPGEdGui.ButtonRightStyle, UniRPGEdGui.ButtonOnColor, GUILayout.Width(150)))
						{
							selected = cl;
						}
					}
					EditorGUILayout.EndHorizontal();
				}
			}
			else
			{
				GUILayout.Label("No States are defined", UniRPGEdGui.WarningLabelStyle);
			}
		}
		UniRPGEdGui.EndScrollView();
		UniRPGEdGui.DrawHorizontalLine(1, UniRPGEdGui.DividerColor, 0, 10);

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

			if (selected == 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);
	}
Пример #3
0
	// ================================================================================================================

	public void CopyTo(RPGState st)
	{
		st.id = this.id.Copy();

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

		st.maxInstances = this.maxInstances;
		st.effect = this.effect;
		st.slot = this.slot;
		st.timeoutSettings = this.timeoutSettings;
		st.autoRemoveTimeoutSettings = this.autoRemoveTimeoutSettings;
		st.eventPrefab = this.eventPrefab;
	}
Пример #4
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 State", UniRPGEdGui.Icon_Plus), EditorStyles.miniButtonLeft))
			{
				GUI.FocusControl("");
				curr = ScriptableObject.CreateInstance<RPGState>();
				UniRPGEdUtil.AddObjectToAssetFile(curr, UniRPGEditorGlobal.DB_DEF_STATES_FILE);
				curr.screenName = "State";
				ed.db.states.Add(curr);
				EditorUtility.SetDirty(curr);
				EditorUtility.SetDirty(ed.db);
			}
			if (curr == null) GUI.enabled = false;
			if (GUILayout.Button(new GUIContent(UniRPGEdGui.Icon_Copy, "Copy"), EditorStyles.miniButtonMid))
			{
				GUI.FocusControl("");
				RPGState st = ScriptableObject.CreateInstance<RPGState>();
				curr.CopyTo(st);
				st.id = UniRPG.GUID.Create();
				curr = st;
				UniRPGEdUtil.AddObjectToAssetFile(curr, UniRPGEditorGlobal.DB_DEF_STATES_FILE);
				ed.db.states.Add(curr);
				EditorUtility.SetDirty(curr);
				EditorUtility.SetDirty(ed.db);
			}
			GUI.enabled = true;
		}
		EditorGUILayout.EndHorizontal();
		EditorGUILayout.Space();

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

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

		if (del != null)
		{
			if (curr == del) curr = null;
			ed.db.states.Remove(del);
			Object.DestroyImmediate(del, true);
			del = null;
			EditorUtility.SetDirty(ed.db);
			AssetDatabase.SaveAssets();
		}
	}
Пример #5
0
	/// <summary>Removes a State from the Actor. Returns false if there was no such State on the Actor. This removes the 1st State that has the same GUID.</summary>
	public bool RemoveState(RPGState state)
	{
		int idx = -1;
		for (int i = 0; i < this.states.Count; i++)
		{
			if (this.states[i].id == state.id)
			{
				idx = i;
				break;
			}
		}

		if (idx >= 0)
		{
			Destroy(this.states[idx]);
			this.states.RemoveAt(idx);
			return true;
		}

		return false;
	}
Пример #6
0
	// ================================================================================================================
	#region States related

	/// <summary>Add a State to the Actor. Returns false if the State could not be added, for example when the State's maxInstances prevents it.</summary>
	public bool AddState(RPGState state)
	{
		if (state.maxInstances > 0)
		{	// check if not already too many instances of this state active
			int counted = 0;
			for (int i = 0; i < this.states.Count; i++)
			{
				if (this.states[i].id == state.id) counted++;
			}
			if (counted >= state.maxInstances) return false;
		}
		this.states.Add(RPGState.CreateInstance(state, transform));
		return true;
	}