/// <summary> /// 设置状态 /// 返回设置状态后游戏对象的显示是否发生变化 /// </summary> /// <param name="buffState"></param> /// <returns></returns> public bool SetState(BuffState buffState) { if (buffState.statusEffect != statusEffect)//重新设置图标 { statusEffect = buffState.statusEffect; StatusDataInfo statusDataInfo = statusData[buffState.statusEffect]; if (statusDataInfo != null) { statusDataInfo.Load(); stateImage.sprite = statusDataInfo.StatusSprite; explaneText.text = statusDataInfo.StatusExplane + "(" + statusDataInfo[buffState.level].LevelExplane + ")"; } else { stateImage.sprite = null; explaneText.text = ""; } } if (buffState.Time > 0) { int shi = (int)buffState.Time / 3600; int fen = ((int)buffState.Time % 3600) / 60; int miao = ((int)buffState.Time % 3600) % 60; timeText.text = shi > 0 ? (shi + ":" + fen + ":" + miao) : (fen > 0 ? (fen + ":" + miao) : miao.ToString()); } bool lastActive = gameObject.activeSelf; gameObject.SetActive(buffState.Time > 0); return(lastActive == (buffState.Time > 0)); }
public BuffState(EnumStatusEffect statusEffect, int level, object data) { this.statusEffect = statusEffect; Time = 0; this.level = level; tempData = data; multiplying = 1; }
/// <summary> /// 获取指定状态枚举的数组 /// </summary> /// <param name=""></param> /// <returns></returns> public StatusDataInfo this[EnumStatusEffect statusEffect] { get { if (dataDic != null && dataDic.ContainsKey(statusEffect)) { dataDic[statusEffect].EffectType = statusEffect; return(dataDic[statusEffect]); } return(null); } }
/// <summary> /// 清理Debuff /// </summary> public void ClearDebuff(params EnumStatusEffect[] effects) { if (effects == null || effects.Length == 0)//如果空或者零表示清掉全部 { effects = new EnumStatusEffect[] { EnumStatusEffect.bd1, EnumStatusEffect.cd1, EnumStatusEffect.dr1, EnumStatusEffect.dl3, EnumStatusEffect.js4, EnumStatusEffect.mh3, EnumStatusEffect.wl1, EnumStatusEffect.xr2, EnumStatusEffect.zd2, EnumStatusEffect.zz3 } } ; foreach (EnumStatusEffect effect in effects) { switch (effect) { case EnumStatusEffect.bd1: _Bingdong = null; break; case EnumStatusEffect.cd1: _Chidun = null; break; case EnumStatusEffect.dr1: _Dianran = null; break; case EnumStatusEffect.dl3: _Diaoling = null; break; case EnumStatusEffect.js4: _Jiansu = null; break; case EnumStatusEffect.mh3: _Mihuo = null; break; case EnumStatusEffect.wl1: _Wuli = null; break; case EnumStatusEffect.xr2: _Xuruo = null; break; case EnumStatusEffect.zd2: _Zhongdu = null; break; case EnumStatusEffect.zz3: _Zuzhou = null; break; } } } }
private void OnGUI() { if (restart) { EditorGUILayout.LabelField("出现错误请重新打开"); return; } try { EditorGUILayout.BeginHorizontal(); //左侧的选择状态类型与保存面板 EditorGUILayout.BeginVertical(GUILayout.Width(100)); if (GUILayout.Button("保存", GUILayout.Width(95))) { string valueText = SerializeNow(dataDic); File.WriteAllText(dataDirecotryPath + "/Status.txt", valueText, Encoding.UTF8); EditorUtility.DisplayDialog("保存数据", "保存成功!", "确认"); } EditorGUILayout.LabelField("状态类型"); selectEnumStatusEffect = (EnumStatusEffect)EditorGUILayout.EnumPopup(selectEnumStatusEffect, GUILayout.Width(95)); FieldInfo fieldInfo = typeof(EnumStatusEffect).GetField(selectEnumStatusEffect.ToString()); FieldExplanAttribute fieldExplane = fieldInfo.GetCustomAttributes(typeof(FieldExplanAttribute), false).OfType <FieldExplanAttribute>().FirstOrDefault(); if (fieldExplane != null) { EditorGUILayout.LabelField(fieldExplane.GetExplan(), GUILayout.Width(95)); } EditorGUILayout.EndVertical(); //右侧显示详细信息面板 EditorGUILayout.BeginVertical(); rightScroll = EditorGUILayout.BeginScrollView(rightScroll); if (dataDic.ContainsKey(selectEnumStatusEffect)) { StatusDataInfo statusDataInfo = dataDic[selectEnumStatusEffect]; ReflectUnit <StatusDataInfo> statusDataInfoUnit = Entry.On(statusDataInfo); EditorGUILayout.BeginHorizontal(); //说明 EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("状态简要说明"); string statusExplane = EditorGUILayout.TextArea(statusDataInfo.StatusExplane, GUILayout.Width(200), GUILayout.Height(100)); if (!string.Equals(statusExplane, statusDataInfo.StatusExplane)) { statusDataInfoUnit.Field("statusExplane", statusExplane); } EditorGUILayout.EndVertical(); //图片 EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("状态的图标"); statusDataInfo.Load(); Sprite statusSprite = (Sprite)EditorGUILayout.ObjectField(statusDataInfo.StatusSprite, typeof(Sprite), true, GUILayout.Width(100), GUILayout.Height(100)); if (!Sprite.Equals(statusSprite, statusDataInfo.StatusSprite) && statusSprite != null) { string statusSpriteID = SpriteManager.GetName(statusSprite); statusDataInfoUnit.Field("statusSpriteID", statusSpriteID).End(); statusDataInfoUnit.Field("statusSprite", null); } EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); //不同等级的具体状态 Dictionary <int, StatusDataInfo.StatusLevelDataInfo> levelToDataDic = statusDataInfoUnit.Field <Dictionary <int, StatusDataInfo.StatusLevelDataInfo> >("levelToDataDic").Element; //等级 EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("最大等级:" + (levelToDataDic.Count - 1), GUILayout.Width(70)); if (levelToDataDic.Count > 0 && GUILayout.Button("-", GUILayout.Width(20))) { if (EditorUtility.DisplayDialog("警告!", "将会减去最后一个等级的数据!", "确认", "取消")) { levelToDataDic.Remove(levelToDataDic.Count - 1); } } if (GUILayout.Button("+", GUILayout.Width(20))) { levelToDataDic.Add(levelToDataDic.Count, new StatusDataInfo.StatusLevelDataInfo()); } EditorGUILayout.LabelField("当前选择:" + selectLevel, GUILayout.Width(70)); if (selectLevel > 0 && GUILayout.Button("-", GUILayout.Width(20))) { selectLevel--; } if (selectLevel < levelToDataDic.Count - 1 && GUILayout.Button("+", GUILayout.Width(20))) { selectLevel++; } selectLevel = Mathf.Clamp(selectLevel, 0, levelToDataDic.Count - 1); EditorGUILayout.EndHorizontal(); //具体状态 if (selectLevel >= 0 && selectLevel < levelToDataDic.Count) { StatusDataInfo.StatusLevelDataInfo statusLeveDataInfo = levelToDataDic[selectLevel]; EditorGUILayout.LabelField("具体说明"); statusLeveDataInfo.LevelExplane = EditorGUILayout.TextArea(statusLeveDataInfo.LevelExplane, GUILayout.Height(60)); //该等级的耗魔对应基础持续时间曲线 EditorGUILayout.LabelField("持续时间曲线设置:"); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("最小魔力:", GUILayout.Width(75)); statusLeveDataInfo.MinMana = EditorGUILayout.IntField(statusLeveDataInfo.MinMana, GUILayout.Width(75)); statusLeveDataInfo.DurationCuvre = EditorGUILayout.CurveField(statusLeveDataInfo.DurationCuvre, GUILayout.Width(150)); EditorGUILayout.LabelField("最大魔力:", GUILayout.Width(75)); statusLeveDataInfo.MaxMana = EditorGUILayout.IntField(statusLeveDataInfo.MaxMana, GUILayout.Width(75)); EditorGUILayout.EndHorizontal(); //设置具体的数据 EditorGUILayout.LabelField("具体数据设置:"); StatusActionAttribute statusAction = fieldInfo.GetCustomAttributes(typeof(StatusActionAttribute), false).OfType <StatusActionAttribute>().FirstOrDefault(); if (statusAction != null) { EnumStatusAction[] enumStatusActions = statusAction.GetStatusActions(); //如果不存在该项则添加 foreach (EnumStatusAction enumStatusAction in enumStatusActions) { if (!statusLeveDataInfo.StatusActionDataInfoDic.ContainsKey(enumStatusAction)) { Type t = assembly.GetType("StatusActionDataInfo_" + enumStatusAction.ToString()); if (t != null) { StatusActionDataInfo_Base sb = Activator.CreateInstance(t) as StatusActionDataInfo_Base; statusLeveDataInfo.StatusActionDataInfoDic.Add(enumStatusAction, sb); } } } //如果多余则删除 IEnumerable <EnumStatusAction> checkEnumStatusActions = statusLeveDataInfo.StatusActionDataInfoDic.Keys.OfType <EnumStatusAction>(); foreach (EnumStatusAction item in checkEnumStatusActions) { if (!enumStatusActions.Contains(item)) { statusLeveDataInfo.StatusActionDataInfoDic.Remove(item); } } //循环 Type enumStatusActionType = typeof(EnumStatusAction); foreach (KeyValuePair <EnumStatusAction, StatusActionDataInfo_Base> item in statusLeveDataInfo.StatusActionDataInfoDic) { FieldExplanAttribute fieldExplanAttribute = enumStatusActionType.GetField(item.Key.ToString()).GetCustomAttributes(typeof(FieldExplanAttribute), false).OfType <FieldExplanAttribute>().First(); if (fieldExplanAttribute != null) { EditorGUILayout.Space(); EditorGUILayout.LabelField(fieldExplanAttribute.GetExplan()); //显示该状态效果的名字 Type statusActionDataInfoBaseType = item.Value.GetType(); // assembly.GetType("StatusActionDataInfo_" + item.Key.ToString()); if (statusActionDataInfoBaseType != null) { FieldInfo[] statusActionDataInfoBaseInfos = statusActionDataInfoBaseType.GetFields(); //便利该效果对应的数据对象并显示 foreach (FieldInfo statusActionDataInfoBaseInfo in statusActionDataInfoBaseInfos) { object innerValueData = statusActionDataInfoBaseInfo.GetValue(item.Value); FieldExplanAttribute innerAttribute = statusActionDataInfoBaseInfo.GetCustomAttributes(typeof(FieldExplanAttribute), false).OfType <FieldExplanAttribute>().FirstOrDefault(); if (innerAttribute != null) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(innerAttribute.GetExplan()); if (statusActionDataInfoBaseInfo.FieldType.Equals(typeof(int))) { int innerValue = EditorGUILayout.IntField((int)innerValueData); statusActionDataInfoBaseInfo.SetValue(item.Value, innerValue); } else if (statusActionDataInfoBaseInfo.FieldType.Equals(typeof(float))) { float innerValue = EditorGUILayout.FloatField((float)innerValueData); statusActionDataInfoBaseInfo.SetValue(item.Value, innerValue); } else if (statusActionDataInfoBaseInfo.FieldType.Equals(typeof(string))) { string innerValue = EditorGUILayout.TextField((string)innerValueData); statusActionDataInfoBaseInfo.SetValue(item.Value, innerValue); } else if (statusActionDataInfoBaseInfo.FieldType.Equals(typeof(bool))) { bool innerValue = EditorGUILayout.Toggle((bool)innerValueData); statusActionDataInfoBaseInfo.SetValue(item.Value, innerValue); } EditorGUILayout.EndHorizontal(); } } } } } } } } EditorGUILayout.EndScrollView(); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); } catch { restart = false; } }