public StateGroup(excel_state_group excel, Character self, int srcUID) { mSelf = self; mStateMgr = mSelf.mStateMgr; mExcel = excel; mSrcUID = srcUID; }
private excel_state_group CheckMutex(excel_state_group excel, int srcUID) { if (excel == null) { return(null); } excel_state_group mutexExcel = null; for (int i = 0; i < mStateList.Count; ++i) { StateGroup s = mStateList[i]; // 如果互斥检查范围是全部,则检查全部状态是否呼出 // 如果互斥检查范围是同一来源,则只检查同一来源的状态是否互斥 if (excel.mutexScope == (int)StateMutexScope.All || (excel.mutexScope == (int)StateMutexScope.SameSrc && srcUID == s.mSrcUID)) { int mutexID = excel.mutexID; // 同ID或同互斥组的状态都算互斥; if ((mutexID > 0 && mutexID == s.mExcel.mutexID) || (mutexID == 0 && excel.id == s.mExcel.id)) { mutexExcel = s.mExcel; break; } } } if (mutexExcel != null) { if (excel.mutexPriority > mutexExcel.mutexPriority) { // 优先级高,直接删除并替换原来的状态; DelState(mutexExcel.id); } else if (excel.mutexPriority == mutexExcel.mutexPriority) { // 同优先级,状态叠加升级一层(如果没有填升级ID则直接替换掉原来的状态) int nextID = mutexExcel.mutexNextID; if (nextID > 0) { excel = excel_state_group.Find(nextID); } DelState(mutexExcel.id); } else if (excel.mutexPriority < mutexExcel.mutexPriority) { // 低优先级,添加失败; excel = null; } } return(excel); }
void StateEffectList(excel_state_group stateExcel) { if (stateExcel == null || stateExcel.stateEffectIDs == null) { return; } for (int i = 0; i < stateExcel.stateEffectIDs.Length; ++i) { int effectID = stateExcel.stateEffectIDs[i]; excel_state_effect effectExcel = excel_state_effect.Find(effectID); if (effectExcel == null) { continue; } bool isExpand = expandStateEffects.Contains(effectExcel.id); bool isSel = mCurStateEffect == effectExcel.id; EditorGUILayout.BeginHorizontal(); Rect rcfold = EditorGUILayout.GetControlRect(GUILayout.Width(12.0f)); Rect rcbtn = EditorGUILayout.GetControlRect(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseDown && Event.current.button == 1) { if (rcbtn.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("删除技能段"), false, StateMenuEvent, "delEffect*" + stateExcel.id + "*" + effectExcel.id); menu.ShowAsContext(); Event.current.Use(); } } GUIStyle skillStyle = EditorStyles.foldout; GUIStyle style = isSel ? mStateStyleSelected : mStateStyleNormal; if (GUI.Button(rcbtn, "● 状态效果{" + effectExcel.id + "}::名称{" + effectExcel.name + "}", style)) { if (!isSel) { mCurStateGroup = 0; mCurStateEffect = effectExcel.id; } else { mCurStateGroup = 0; mCurStateEffect = 0; } } } }
void ShowStateData() { if (mCurStateGroup == 0) { return; } GUIContent c = null; excel_state_group stateExcel = excel_state_group.Find(mCurStateGroup); EditorGUILayout.LabelField("状态ID", string.Format("{0}", stateExcel.id)); stateExcel.name = EditorGUILayout.TextField("状态名称", stateExcel.name); c = new GUIContent("持续时间", "单位毫秒,填-1为永久存在"); stateExcel.duration = EditorGUILayout.IntField(c, stateExcel.duration); int[] values = Enum.GetValues(typeof(StateType)) as int[]; string[] texts = Enum.GetNames(typeof(StateType)); stateExcel.type = EditorGUILayout.IntPopup("状态类型", stateExcel.type, texts, values); c = new GUIContent("状态图标", "目录下的路径"); stateExcel.icon = EditorGUILayout.TextField(c, stateExcel.icon); EditorGUILayout.Separator(); c = new GUIContent("互斥组ID", "同ID的状态为互斥状态,填0则都不进行互斥判断"); stateExcel.mutexID = EditorGUILayout.IntField(c, stateExcel.mutexID); values = Enum.GetValues(typeof(StateMutexScope)) as int[]; GUIContent[] contents = new GUIContent[values.Length]; for (int i = 0; i < values.Length; ++i) { StateMutexScope v = (StateMutexScope)values[i]; contents[i] = new GUIContent(v.ToDescription()); } c = new GUIContent("互斥检测范围", "在该范围内的状态才参与互斥判断"); stateExcel.mutexScope = EditorGUILayout.IntPopup(c, stateExcel.mutexScope, contents, values); c = new GUIContent("互斥优先级", "当该状态与已有状态互斥时,保留优先级高的状态"); stateExcel.mutexPriority = EditorGUILayout.IntField(c, stateExcel.mutexPriority); c = new GUIContent("互斥同级跳转ID", "当该状态与已有状态互斥,并且优先级相同,则可以跳转到其他状态,一般用作状态升级,填0则不跳转只替换"); stateExcel.mutexNextID = EditorGUILayout.IntField(c, stateExcel.mutexNextID); }
public void AddState(int id, int srcUID) { excel_state_group excel = excel_state_group.Find(id); excel = CheckMutex(excel, srcUID); if (excel == null) { return; } StateGroup state = new StateGroup(excel, mOwner, srcUID); mStates[excel.id] = state; mStateList.Add(state); state.Enter(); UpdateDefaultItem(); }
int GetEmptyStateID() { int id = 1; for (int i = 0; i < excel_state_group.Count; ++i) { excel_state_group excel = excel_state_group.GetByIndex(i); if (excel.id < 1 || excel.id > 9999999) { continue; } if (id == excel.id) { ++id; } else { return(id); } } return(id); }
void StateList() { for (int i = 0; i < excel_state_group.Count; ++i) { excel_state_group stateExcel = excel_state_group.GetByIndex(i); bool isExpand = expandStateGroups.Contains(stateExcel.id); bool isSel = mCurStateGroup == stateExcel.id; EditorGUILayout.BeginHorizontal(); Rect rcfold = EditorGUILayout.GetControlRect(GUILayout.Width(12.0f)); Rect rcbtn = EditorGUILayout.GetControlRect(); EditorGUILayout.EndHorizontal(); if (Event.current.type == EventType.MouseDown && Event.current.button == 1) { if (rcbtn.Contains(Event.current.mousePosition)) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("添加状态效果"), false, StateMenuEvent, "addEffect*" + stateExcel.id); menu.AddSeparator(""); menu.AddItem(new GUIContent("删除状态"), false, StateMenuEvent, "delState*" + stateExcel.id); menu.ShowAsContext(); Event.current.Use(); } } GUIStyle skillStyle = EditorStyles.foldout; bool bCurExpand = GUI.Toggle(rcfold, isExpand, "", skillStyle); GUIStyle style = isSel ? mStateStyleSelected : mStateStyleNormal; if (GUI.Button(rcbtn, "状态{" + stateExcel.id + "}::名称{" + stateExcel.name + "}", style)) { if (!isSel) { mCurStateGroup = stateExcel.id; mCurStateEffect = 0; } else { mCurStateGroup = 0; mCurStateEffect = 0; } } if (bCurExpand && !isExpand) { expandStateGroups.Add(stateExcel.id); GUI.FocusControl(""); } else if (!bCurExpand && isExpand) { expandStateGroups.Remove(stateExcel.id); GUI.FocusControl(""); } if (bCurExpand) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.BeginVertical(); StateEffectList(stateExcel); EditorGUILayout.Space(); EditorGUILayout.EndVertical(); GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } } }
void StateMenuEvent(object obj) { string strData = obj as string; if (string.IsNullOrEmpty(strData)) { return; } string[] sdatas = strData.Split('*'); if (sdatas == null || sdatas.Length < 1) { return; } string data0 = sdatas[0]; if (data0 == "addState") { excel_state_group newState = new excel_state_group(); newState.id = GetEmptyStateID(); newState.name = "newState"; excel_state_group.Add(newState); } else if (data0 == "delState") { } else if (data0 == "addEffect") { int stateID = 0; if (!int.TryParse(sdatas[1], out stateID)) { return; } if (!expandStateGroups.Contains(stateID)) { expandStateGroups.Add(stateID); } excel_state_group stateExcel = excel_state_group.Find(stateID); if (stateExcel == null) { return; } excel_state_effect newEffect = new excel_state_effect(); newEffect.id = GetEmptyStateEffectID(); newEffect.name = "newStage"; if (stateExcel.stateEffectIDs == null) { stateExcel.stateEffectIDs = new int[1]; } else { int[] origList = stateExcel.stateEffectIDs.Clone() as int[]; stateExcel.stateEffectIDs = new int[stateExcel.stateEffectIDs.Length + 1]; origList.CopyTo(stateExcel.stateEffectIDs, 0); } stateExcel.stateEffectIDs[stateExcel.stateEffectIDs.Length - 1] = newEffect.id; excel_state_effect.Add(newEffect); } else if (data0 == "delEffect") { } else if (data0 == "save") { } }