void OnGUI() { if (!inited) Init(); UniRPGEdGui.UseSkin(); scroll = UniRPGEdGui.BeginScrollView(scroll); { if (UniRPGEditorGlobal.DB.attributes.Count > 0) { foreach (RPGAttribute cl in UniRPGEditorGlobal.DB.attributes) { 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(selectedAttrib == cl, cl.screenName, UniRPGEdGui.ButtonRightStyle, UniRPGEdGui.ButtonOnColor, GUILayout.Width(150))) { selectedAttrib = cl; } } EditorGUILayout.EndHorizontal(); } } else { GUILayout.Label("No Attributes are defined", UniRPGEdGui.WarningLabelStyle); } } UniRPGEdGui.EndScrollView(); UniRPGEdGui.DrawHorizontalLine(1, UniRPGEdGui.DividerColor, 0, 10); EditorGUILayout.BeginHorizontal(); { GUILayout.FlexibleSpace(); if (selectedAttrib == 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); }
public void Init(GameObject owningActor, int startXP) { // init the attributes Attributes = new List<RPGAttribute>(attribDataFabs.Count); for (int i = 0; i < attribDataFabs.Count; i++) { RPGAttribute attribFab = RPGAttribute.GetAttribByGuid(UniRPGGlobal.DB.attributes, attribDataFabs[i].attribId); if (attribFab) { RPGAttribute a = (RPGAttribute)ScriptableObject.Instantiate(attribFab); a.data = attribDataFabs[i]; Attributes.Add(a); if (a.data.canRegen) _RegenAttribs.Add(a); if (a.id == xpAttribId) a.Init(owningActor, startXP); // this attrib is the one used for XP, so init it with the starting XP else a.Init(owningActor); // else, typical attribute } else { Debug.LogError("The Attribute definition could not be found. You might have removed it from the Database and not updated the ActorClass definition."); } } // init the XP attribute Level = 1; xpAttrib = GetAttribute(xpAttribId); if (xpAttrib != null) { xpAttrib.onValueChange += OnXPValueChange; OnXPValueChange(xpAttrib); } }
private void OnXPValueChange(RPGAttribute att) { if (xpAttrib != null) { Level = (int)levelCurve.Evaluate(xpAttrib.Value); } if (Level > maxLevel) Level = maxLevel; if (Level < 1) Level = 1; if (!loadingState) { // check if any attributes must be updated when the level changes for (int i = 0; i < Attributes.Count; i++) { if (Attributes[i].data.levelAffectMax) { Attributes[i].MaxValue = Attributes[i].data.maxAffectCurve.Evaluate(Level); if (Attributes[i].Value > Attributes[i].MaxValue) Attributes[i].Value = Attributes[i].MaxValue; } if (Attributes[i].data.levelAffectVal) { Attributes[i].Value = Attributes[i].data.valAffectCurve.Evaluate(Level); } } } }
// ============================================================================================================ public void WasHit(RPGAttribute att) { // Force it to chase player even if not in detection radius OnPlayerEnterTrigger(); }
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 Attribute", UniRPGEdGui.Icon_Plus), EditorStyles.miniButtonLeft)) { GUI.FocusControl(""); curr = ScriptableObject.CreateInstance<RPGAttribute>(); curr.id = UniRPG.GUID.Create(); ed.db.attributes.Add(curr); UniRPGEdUtil.AddObjectToAssetFile(curr, UniRPGEditorGlobal.DB_DEF_ATTRIBS_FILE); curr.screenName = "Attribute"; 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(""); RPGAttribute att = ScriptableObject.CreateInstance<RPGAttribute>(); curr.CopyTo(att, 1); att.id = UniRPG.GUID.Create(); curr = att; ed.db.attributes.Add(curr); UniRPGEdUtil.AddObjectToAssetFile(curr, UniRPGEditorGlobal.DB_DEF_ATTRIBS_FILE); 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.attributes.Count > 0) { foreach (RPGAttribute attrib in ed.db.attributes) { Rect r = EditorGUILayout.BeginHorizontal(GUILayout.Width(DatabaseEditor.LeftPanelWidth - 20), GUILayout.ExpandWidth(false)); { r.x = 3; r.width = 19; r.height = 19; GUI.DrawTexture(r, (attrib.icon[0] != null ? attrib.icon[0] : UniRPGEdGui.Texture_NoPreview)); GUILayout.Space(21); if (UniRPGEdGui.ToggleButton(curr == attrib, attrib.screenName, UniRPGEdGui.ButtonMidStyle, GUILayout.Width(140), GUILayout.ExpandWidth(false))) { curr = attrib; GUI.FocusControl(""); } if (GUILayout.Button("X", UniRPGEdGui.ButtonRightStyle, GUILayout.Width(20))) { del = attrib; } } EditorGUILayout.EndHorizontal(); } } else { GUILayout.Label("No Attributes are defined", UniRPGEdGui.WarningLabelStyle); } } UniRPGEdGui.EndScrollView(); // 0 // ------------------------------------------------------------- GUILayout.Space(3); EditorGUILayout.EndVertical(); if (del != null) { if (curr == del) curr = null; ed.db.attributes.Remove(del); Object.DestroyImmediate(del, true); del = null; EditorUtility.SetDirty(ed.db); AssetDatabase.SaveAssets(); } }
private void OnDeathAttribValueChange(RPGAttribute att) { if (att.Value <= 0) { // was a death since value is now <= (0) // Stop any skill that might be running _actor.StopAndClearAllSkill(); // Run death event UniRPGGameController.ExecuteActions(onDeath, gameObject, null, null, null, null, false); } }
private void OnHitAttribValueChange(RPGAttribute att) { if (att.Value < hitAttPrevVal) { // was a hit since value is now less hitAttPrevVal = att.Value; UniRPGGameController.ExecuteActions(onGetHit, gameObject, null, null, null, null, false); } }
// ================================================================================================================ public void CopyTo(RPGAttribute att, float maxLevel) { att.id = this.id.Copy(); att.screenName = this.screenName; att.shortName = this.shortName; att.description = this.description; att.notes = this.notes; att.icon = new Texture2D[3] { this.icon[0], this.icon[1], this.icon[2] }; att.guiHelper = this.guiHelper; if (this.data != null) att.data = this.data.Copy(maxLevel); else att.data = null; }