public override void LoadData(object obj, Action <object> SaveDataAction) { base.LoadData(obj, SaveDataAction); if (obj != null && obj.GetType().Equals(typeof(bool))) { torchLightState = (bool)obj; } ActionInteractiveDataInfo.OtherDataStruct otherDataStruct = ActionInteractiveDataInfo.OtherValue as ActionInteractiveDataInfo.OtherDataStruct; if (otherDataStruct != null && !string.IsNullOrEmpty(otherDataStruct.Data)) { int index = 0; if (int.TryParse(otherDataStruct.Data.Trim(), out index)) { //每一个代表不同的火炬,通过下标获取相关的对象 switch (index) { case 1: torchIndex = 1; break; case 2: torchIndex = 2; break; case 3: torchIndex = 3; break; case 4: torchIndex = 4; break; } } } if (targetObj) { targetObj.SetActive(torchLightState); } }
private void OnGUI() { if (actionInteractiveDataInfo != null && ActionInteractiveDataEditor.actionInteractiveTypeToNameList != null) { EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); List <EnumActionInteractiveType> actionInteractiveTypeValues = ActionInteractiveDataEditor.actionInteractiveTypeToNameList.Select(temp => temp.Key).ToList(); string[] actionInteractiveTypeExplans = ActionInteractiveDataEditor.actionInteractiveTypeToNameList.Select(temp => temp.Value).ToArray(); int actionInteractiveTypeIndex = actionInteractiveTypeValues.IndexOf(actionInteractiveDataInfo.ActionInteractiveType); EditorGUILayout.Popup(actionInteractiveTypeIndex, actionInteractiveTypeExplans, GUILayout.Width(120)); EditorGUILayout.EndHorizontal(); switch (actionInteractiveDataInfo.ActionInteractiveType) { case EnumActionInteractiveType.TreasureBox: Dictionary <EnumGoodsType, ActionInteractiveDataInfo.TreasureBoxStruct> treasureBoxData = actionInteractiveDataInfo.OtherValue as Dictionary <EnumGoodsType, ActionInteractiveDataInfo.TreasureBoxStruct>; if (treasureBoxData == null) { break; } List <EnumGoodsType> goodsTypeValues = goodsTypeToExplanList.Select(temp => temp.Key).ToList(); string[] goodsTypeExplans = goodsTypeToExplanList.Select(temp => temp.Value).ToArray(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("商品类型", GUILayout.Width(45)); selectGoodsIndex = EditorGUILayout.Popup(selectGoodsIndex, goodsTypeExplans, GUILayout.Width(150)); if (selectGoodsIndex >= 0) { if (!treasureBoxData.ContainsKey(goodsTypeValues[selectGoodsIndex]) && GUILayout.Button("添加", GUILayout.Width(35))) { treasureBoxData.Add(goodsTypeValues[selectGoodsIndex], new ActionInteractiveDataInfo.TreasureBoxStruct()); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); List <EnumQualityType> qualityTypeValues = qualityTypeToExplanList.Select(temp => temp.Key).ToList(); string[] qualityTypeExplans = qualityTypeToExplanList.Select(temp => temp.Value).ToArray(); EnumGoodsType[] showGoodsTypeArray = treasureBoxData.Select(temp => temp.Key).ToArray(); foreach (EnumGoodsType showGoodsType in showGoodsTypeArray) { EditorGUILayout.BeginHorizontal(); int thisIndex = goodsTypeValues.IndexOf(showGoodsType); GUILayout.Button(goodsTypeExplans[thisIndex], GUILayout.Width(50)); EditorGUILayout.LabelField("数量:", GUILayout.Width(35)); treasureBoxData[showGoodsType].Count = EditorGUILayout.IntField(treasureBoxData[showGoodsType].Count, GUILayout.Width(35)); EditorGUILayout.LabelField("最小品质:", GUILayout.Width(50)); int minIndex = qualityTypeValues.IndexOf(treasureBoxData[showGoodsType].MinQualityType); minIndex = EditorGUILayout.Popup(minIndex, qualityTypeExplans, GUILayout.Width(65)); if (minIndex >= 0) { treasureBoxData[showGoodsType].MinQualityType = qualityTypeValues[minIndex]; } EditorGUILayout.LabelField("最大品质:", GUILayout.Width(50)); int maxIndex = qualityTypeValues.IndexOf(treasureBoxData[showGoodsType].MaxQualityType); maxIndex = EditorGUILayout.Popup(maxIndex, qualityTypeExplans, GUILayout.Width(65)); if (maxIndex >= 0) { treasureBoxData[showGoodsType].MaxQualityType = qualityTypeValues[maxIndex]; } if (GUILayout.Button("×", GUILayout.Width(20)) && EditorUtility.DisplayDialog("请再次确认!", "是否从宝箱中移除该道具?", "确认", "取消")) { treasureBoxData.Remove(showGoodsType); } EditorGUILayout.EndHorizontal(); } break; case EnumActionInteractiveType.Other: ActionInteractiveDataInfo.OtherDataStruct otherDataStruct = actionInteractiveDataInfo.OtherValue as ActionInteractiveDataInfo.OtherDataStruct; if (otherDataStruct == null) { break; } string[] otherDataTypeExplans = otherDataTypes.Select(temp => temp.Name).ToArray(); int otherDataTypeIndex = otherDataTypes.IndexOf(otherDataStruct.ActionInterativeClass); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("处理类型:"); otherDataTypeIndex = EditorGUILayout.Popup(otherDataTypeIndex, otherDataTypeExplans); if (otherDataTypeIndex >= 0) { otherDataStruct.ActionInterativeClass = otherDataTypes[otherDataTypeIndex]; } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("数据:"); otherDataStruct.Data = EditorGUILayout.TextField(otherDataStruct.Data); EditorGUILayout.EndHorizontal(); break; } EditorGUILayout.EndHorizontal(); } }