コード例 #1
0
 private void OnDestroy()
 {
     if (ResultHandle != null)
     {
         if (tempNPCDataInfo.NPCObj != null)
         {
             TalkShowPosition talkShowPosition = tempNPCDataInfo.NPCObj.GetComponent <TalkShowPosition>();
             if (talkShowPosition != null)
             {
                 GameObject.DestroyImmediate(talkShowPosition);
             }
         }
         if (nowIDList.Contains(tempNPCDataInfo.NPCID) ||
             string.IsNullOrEmpty(tempNPCDataInfo.npcPrefabName) ||
             !isCreate)
         {
             if (tempNPCDataInfo != null && tempNPCDataInfo.NPCObj)
             {
                 GameObject.DestroyImmediate(tempNPCDataInfo.NPCObj);
             }
             tempNPCDataInfo = null;
         }
         //如果对象是商人,则将心有的数据序列化进去
         if (tempNPCDataInfo != null && tempNPCDataInfo.NPCType == EnumNPCType.Businessman)
         {
             tempNPCDataInfo.OtherValue = BusinessmanDataInfo.SerializeNow(businessmanDataInfo);
         }
         ResultHandle(tempNPCDataInfo);
     }
 }
コード例 #2
0
    private void OnGUI()
    {
        if (npcDataDic == null)
        {
            return;
        }
        if (tempNPCDataInfo == null)
        {
            tempNPCDataInfo = new NPCDataInfo();
            if (nowIDList.Count > 0)
            {
                tempNPCDataInfo.NPCID = nowIDList.Max() + 1;
            }
            else
            {
                tempNPCDataInfo.NPCID = 0;
            }
            tempNPCDataInfo.NPCName       = "Name";
            tempNPCDataInfo.npcPrefabName = "";
            tempNPCDataInfo.NPCType       = EnumNPCType.Normal;
        }
        EditorGUILayout.BeginVertical();

        scroll = EditorGUILayout.BeginScrollView(scroll);

        List <string> names = npcDataDic.Keys.OfType <string>().ToList();
        int           index = names.IndexOf(tempNPCDataInfo.npcPrefabName);

        if (tempNPCDataInfo.NPCObj)
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField(tempNPCDataInfo.npcPrefabName);
            if (GUILayout.Button("×", GUILayout.Width(25)))
            {
                if (EditorUtility.DisplayDialog("警告!", "是否重新选择预设提?", "是", "否"))
                {
                    tempNPCDataInfo.npcPrefabName = "";
                    tempNPCDataInfo.InitNPCObjPrefab();
                    GameObject.DestroyImmediate(tempNPCDataInfo.NPCObj);
                    tempNPCDataInfo.NPCObj = null;
                    index    = -1;
                    isCreate = false;
                }
            }
            EditorGUILayout.EndHorizontal();
        }
        else
        {
            index = EditorGUILayout.Popup(index, names.ToArray());
            if (index >= 0)
            {
                tempNPCDataInfo.npcPrefabName = names[index];
            }
        }

        if (index >= 0)
        {
            EditorGUILayout.ObjectField(npcDataDic[tempNPCDataInfo.npcPrefabName], typeof(GameObject), true);
        }
        int id = EditorGUILayout.IntField("NPC ID:", tempNPCDataInfo.NPCID);

        if (!nowIDList.Contains(id))
        {
            tempNPCDataInfo.NPCID = id;
        }
        tempNPCDataInfo.NPCName = EditorGUILayout.TextField("NPC Name:", tempNPCDataInfo.NPCName);
        if (npcTypeToExplanList == null)
        {
            npcTypeToExplanList = new List <KeyValuePair <EnumNPCType, string> >();
            FieldExplanAttribute.SetEnumExplanDic(npcTypeToExplanList);
        }
        List <EnumNPCType> npcTypeValues = npcTypeToExplanList.Select(temp => temp.Key).ToList();

        string[] npcTypeExplans = npcTypeToExplanList.Select(temp => temp.Value).ToArray();
        int      npcTypeIndex   = npcTypeValues.IndexOf(tempNPCDataInfo.NPCType);

        npcTypeIndex = EditorGUILayout.Popup("NPC Type:", npcTypeIndex, npcTypeExplans);
        if (npcTypeIndex >= 0)
        {
            tempNPCDataInfo.NPCType = npcTypeValues[npcTypeIndex];
        }
        tempNPCDataInfo.OtherValue = EditorGUILayout.TextField("Other Data:", tempNPCDataInfo.OtherValue);
        if (isCreate)
        {
            EditorGUILayout.ObjectField("NPC Object:", tempNPCDataInfo.NPCObj, typeof(GameObject), true);
        }
        if (((!isCreate && index >= 0) || (tempNPCDataInfo.NPCObj == null && index >= 0)) &&
            GUILayout.Button("Create NPC GameObject"))
        {
            GameObject createObj = GameObject.Instantiate <GameObject>(npcDataDic[tempNPCDataInfo.npcPrefabName]);
            tempNPCDataInfo.NPCObj = createObj;
            isCreate = true;
        }
        if (tempNPCDataInfo.NPCObj != null)
        {
            Selection.activeGameObject = tempNPCDataInfo.NPCObj;
            if (tempNPCDataInfo.NPCObj.GetComponent <TalkShowPosition>() == null)
            {
                tempNPCDataInfo.NPCObj.AddComponent <TalkShowPosition>();
            }
            tempNPCDataInfo.NPCObj.GetComponent <TalkShowPosition>().tempNPCDataInfo = tempNPCDataInfo;
            tempNPCDataInfo.TalkShowOffset = EditorGUILayout.Vector3Field("Talk Show Offset:", tempNPCDataInfo.TalkShowOffset);
            Vector3 talkShowWorldVec = tempNPCDataInfo.TalkShowOffset + tempNPCDataInfo.NPCObj.transform.position;
        }
        Sprite tempSprite = (Sprite)EditorGUILayout.ObjectField("NPC Sprite:", tempNPCDataInfo.NPCSprite, typeof(Sprite), false);

        if (tempSprite != tempNPCDataInfo.NPCSprite && tempSprite != null)
        {
            tempNPCDataInfo.npcSpriteID = SpriteManager.GetName(tempSprite);
            tempNPCDataInfo.NPCSprite   = tempSprite;
        }
        EditorGUILayout.LabelField("------------------显示条件------------------");
        if (tempNPCDataInfo.NPCShowCondition == null && GUILayout.Button("创建显示条件"))
        {
            tempNPCDataInfo.NPCShowCondition = new NPCShowCondition();
        }
        if (tempNPCDataInfo.NPCShowCondition != null)
        {
            if (GUILayout.Button("删除显示条件"))
            {
                if (EditorUtility.DisplayDialog("请再次确认!", "是否要删除显示条件?", "删除", "取消"))
                {
                    tempNPCDataInfo.NPCShowCondition = null;
                }
            }
        }
        if (tempNPCDataInfo.NPCShowCondition != null)
        {
            if (taskStateTypeToExplanList == null)
            {
                taskStateTypeToExplanList = new List <KeyValuePair <TaskMap.Enums.EnumTaskProgress, string> >();
                FieldExplanAttribute.SetEnumExplanDic(taskStateTypeToExplanList);
            }
            List <TaskMap.Enums.EnumTaskProgress> taskProgressValueList = taskStateTypeToExplanList.Select(temp => temp.Key).ToList();
            string[] taskProgressExplanArray = taskStateTypeToExplanList.Select(temp => temp.Value).ToArray();
            //显示与任务条件相关的函数
            Func <NPCShowCondition.TaskCondition[], NPCShowCondition.TaskCondition[]> ShowAbourtTaskConditionFunc = (source) =>
            {
                if (source == null)
                {
                    source = new NPCShowCondition.TaskCondition[0];
                }
                if (GUILayout.Button("添加", GUILayout.Width(50)))
                {
                    NPCShowCondition.TaskCondition[] tempSource = new NPCShowCondition.TaskCondition[source.Length + 1];
                    Array.Copy(source, tempSource, source.Length);
                    tempSource[source.Length] = new NPCShowCondition.TaskCondition();
                    source = tempSource;
                }
                List <NPCShowCondition.TaskCondition> removeList = new List <NPCShowCondition.TaskCondition>();//需要移除的列表
                foreach (NPCShowCondition.TaskCondition taskCondition in source)
                {
                    if (taskCondition == null)
                    {
                        continue;
                    }
                    EditorGUILayout.BeginHorizontal();
                    if (GUILayout.Button("×", GUILayout.Width(20)))//删除
                    {
                        if (EditorUtility.DisplayDialog("请再次确认!", "是否删除该条数据?", "删除", "取消"))
                        {
                            removeList.Add(taskCondition);
                        }
                    }
                    EditorGUILayout.LabelField("任务ID:", GUILayout.Width(50));
                    taskCondition.TaskID = EditorGUILayout.IntField(taskCondition.TaskID, GUILayout.Width(20));

                    EditorGUILayout.LabelField("任务状态:", GUILayout.Width(60));
                    int taskStateIndex = taskProgressValueList.IndexOf(taskCondition.TaskState);
                    taskStateIndex = EditorGUILayout.Popup(taskStateIndex, taskProgressExplanArray, GUILayout.Width(100));
                    if (taskStateIndex > -1)
                    {
                        TaskMap.Enums.EnumTaskProgress tskProgress = taskProgressValueList[taskStateIndex];
                        taskCondition.TaskState = tskProgress;
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (removeList.Count > 0)
                {
                    List <NPCShowCondition.TaskCondition> tempSource = new List <NPCShowCondition.TaskCondition>(source);
                    foreach (NPCShowCondition.TaskCondition taskCondition in removeList)
                    {
                        tempSource.Remove(taskCondition);
                    }
                    source = tempSource.ToArray();
                }
                return(source);
            };
            tempNPCDataInfo.NPCShowCondition.TimeRange = EditorGUILayout.Vector2Field("在该时间范围内显示(都为0表示不受该项影响)", tempNPCDataInfo.NPCShowCondition.TimeRange);
            EditorGUILayout.LabelField("NPC的隐藏条件(满足任何一条则必须隐藏):");
            tempNPCDataInfo.NPCShowCondition.TaskConditionsHide = ShowAbourtTaskConditionFunc(tempNPCDataInfo.NPCShowCondition.TaskConditionsHide);
            EditorGUILayout.LabelField("NPC的显示条件(满足任何一条则允许显示):");
            tempNPCDataInfo.NPCShowCondition.TaskConditionShow = ShowAbourtTaskConditionFunc(tempNPCDataInfo.NPCShowCondition.TaskConditionShow);
        }
        EditorGUILayout.LabelField("------------------其他数据------------------");
        switch (tempNPCDataInfo.NPCType)
        {
        case EnumNPCType.Businessman:    //如果是商人,则otherValue的数据是BusinessmanDataInfo类型的数据
            if (businessmanDataInfo == null)
            {
                businessmanDataInfo = BusinessmanDataInfo.DeSerializeNow <BusinessmanDataInfo>(tempNPCDataInfo.OtherValue);
                if (businessmanDataInfo == null)
                {
                    businessmanDataInfo = new BusinessmanDataInfo();
                }
            }
            if (goodsMetaInfoMations == null)
            {
                goodsMetaInfoMations = new GoodsMetaInfoMations();
                goodsMetaInfoMations.Load();
            }
            if (goodsTypeToExplanList == null)
            {
                goodsTypeToExplanList = new List <KeyValuePair <EnumGoodsType, string> >();
                FieldExplanAttribute.SetEnumExplanDic(goodsTypeToExplanList, 0, temp => ((int)temp) % 1000 != 0);
            }
            if (goodsQualityTypeToExplanList == null)
            {
                goodsQualityTypeToExplanList = new List <KeyValuePair <EnumQualityType, string> >();
                FieldExplanAttribute.SetEnumExplanDic(goodsQualityTypeToExplanList, 0);
            }
            //显示商人应该显示的列表
            businessmanScroll = EditorGUILayout.BeginScrollView(businessmanScroll);
            {
                List <EnumGoodsType> enumGoodsTypes   = goodsTypeToExplanList.Select(temp => temp.Key).ToList();
                string[]             enumGoodsExplans = goodsTypeToExplanList.Select(temp => temp.Value).ToArray();
                EditorGUILayout.BeginHorizontal();
                goodsTypeIndex = EditorGUILayout.Popup(goodsTypeIndex, enumGoodsExplans);
                if (GUILayout.Button("添加该物品"))
                {
                    if (goodsTypeIndex > -1 &&
                        goodsTypeIndex < enumGoodsExplans.Length &&
                        !businessmanDataInfo.GoodsDic.ContainsKey(enumGoodsTypes[goodsTypeIndex]))
                    {
                        businessmanDataInfo.GoodsDic.Add(enumGoodsTypes[goodsTypeIndex], new BusinessmanDataInfo.GoodsDataInfoInner());
                    }
                    else
                    {
                        EditorUtility.DisplayDialog("提示!", "添加失败!", "确定");
                    }
                }
                EditorGUILayout.EndHorizontal();
                List <EnumQualityType> qualityTypes   = goodsQualityTypeToExplanList.Select(temp => temp.Key).ToList();
                string[]             qualityExplans   = goodsQualityTypeToExplanList.Select(temp => temp.Value).ToArray();
                List <EnumGoodsType> removeGoodsTypes = new List <EnumGoodsType>();
                foreach (KeyValuePair <EnumGoodsType, BusinessmanDataInfo.GoodsDataInfoInner> item in businessmanDataInfo.GoodsDic)
                {
                    EditorGUILayout.BeginHorizontal();
                    int goodsTypeIndex = enumGoodsTypes.IndexOf(item.Key);
                    if (goodsTypeIndex > -1)
                    {
                        EditorGUILayout.LabelField(enumGoodsExplans[goodsTypeIndex], GUILayout.Width(150));
                        int _qualityIndex_min = qualityTypes.IndexOf(item.Value.MinQualityType);
                        int qualityIndex_min  = EditorGUILayout.Popup(_qualityIndex_min, qualityExplans, GUILayout.Width(150));
                        if (_qualityIndex_min != qualityIndex_min && qualityIndex_min > -1)
                        {
                            item.Value.MinQualityType = qualityTypes[qualityIndex_min];
                        }
                        int _qualityIndex_Max = qualityTypes.IndexOf(item.Value.MaxQualityType);
                        int qualityIndex_max  = EditorGUILayout.Popup(_qualityIndex_Max, qualityExplans, GUILayout.Width(150));
                        if (_qualityIndex_Max != qualityIndex_max && qualityIndex_max > -1)
                        {
                            item.Value.MaxQualityType = qualityTypes[qualityIndex_max];
                        }
                        if (GUILayout.Button("×", GUILayout.Width(25)))
                        {
                            if (EditorUtility.DisplayDialog("请再次确认!", "是否删除?", "确定", "取消"))
                            {
                                removeGoodsTypes.Add(item.Key);
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                removeGoodsTypes.ForEach(temp => businessmanDataInfo.GoodsDic.Remove(temp));
            }
            EditorGUILayout.EndScrollView();
            break;
        }

        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();
    }
コード例 #3
0
    /// <summary>
    /// 更新商人的道具
    /// </summary>
    protected void UpdateBusinessman()
    {
        //获取当前商人
        businessman = businessmanStates.BusinessmanList.FirstOrDefault(temp => temp.BusinessmanID == iInteractiveState.ClickInteractiveNPCID && string.Equals(iGameState.SceneName, temp.BusinessmanScene));
        NPCDataInfo npcDataInfo = npcData.GetNPCDataInfo(iGameState.SceneName, iInteractiveState.ClickInteractiveNPCID);

        if (businessman == null && npcDataInfo != null)
        {
            businessman = new Businessman();
            businessman.BusinessManDataInfo = BusinessmanDataInfo.DeSerializeNow <BusinessmanDataInfo>(npcDataInfo.OtherValue);
            businessman.BusinessmanID       = iInteractiveState.ClickInteractiveNPCID;
            businessman.BusinessmanScene    = iGameState.SceneName;
            businessmanStates.BusinessmanList.Add(businessman);
        }
        if (businessman != null)
        {
            #region 刷新商品
            //如果商人的基础道具不足则刷新
            EnumGoodsType[] baseGoodsTypes = businessman.BusinessManDataInfo.GoodsDic.Select(temp => temp.Key).ToArray();//商人基础的物品
            foreach (EnumGoodsType baseGoodsType in baseGoodsTypes)
            {
                //如果不存在该物品则添加
                if (businessman.BaseList.FirstOrDefault(temp => temp.GoodsInfo.EnumGoodsType == baseGoodsType) == null)
                {
                    Goods addGoods = goodsMetaInfoMations[baseGoodsType].Clone(true);//获取需要添加物品的原始属性
                    BusinessmanDataInfo.GoodsDataInfoInner mustAddDataInfoInner = businessman.BusinessManDataInfo.GoodsDic[baseGoodsType];
                    EnumQualityType qualityTypeMin = mustAddDataInfoInner.MinQualityType;
                    EnumQualityType qualityTypeMax = mustAddDataInfoInner.MaxQualityType;
                    int             count          = mustAddDataInfoInner.Count;
                    //如果是道具或炼金物品则可以叠加,但是没有品质
                    if (baseGoodsType > EnumGoodsType.Item && baseGoodsType < EnumGoodsType.SpecialItem)
                    {
                        //尝试从玩家道具中获取id,如果没有则新建一个(这个id并没有什么卵用)
                        int addGoodsID = playerState.PlayerAllGoods.Where(temp => temp.GoodsInfo.EnumGoodsType == baseGoodsType).Select(temp => temp.ID).FirstOrDefault();
                        if (addGoodsID == 0)
                        {
                            addGoodsID = NowTimeToID.GetNowID(DataCenter.Instance.GetEntity <GameRunnedState>());
                        }
                        PlayGoods playGoods = new PlayGoods(addGoodsID, addGoods, GoodsLocation.None);
                        playGoods.QualityType = EnumQualityType.White;
                        playGoods.Count       = count;
                        businessman.BaseList.Add(playGoods);
                    }
                    //如果不是道具和炼金物品则不可以叠加,但是存在品质
                    else
                    {
                        int             addGoodsID  = NowTimeToID.GetNowID(DataCenter.Instance.GetEntity <GameRunnedState>());
                        EnumQualityType qualityType = (EnumQualityType)UnityEngine.Random.Range((int)qualityTypeMin, (int)qualityTypeMax + 1);
                        // 根据品质设置属性
                        if (qualityType != EnumQualityType.Red)//如果是唯一的则不用改变属性
                        {
                            float minRate = ((int)qualityType) * 0.2f + 0.8f;
                            float maxRate = minRate + 0.2f;
                            //将所有属性随机
                            addGoods.goodsAbilities.ForEach(temp =>
                            {
                                float min  = temp.Value * minRate;
                                float max  = temp.Value * maxRate;
                                temp.Value = (int)UnityEngine.Random.Range(min, max);
                            });
                            //取出用于分割固定属性以及随机属性的条目
                            GoodsAbility goodsAbility_nothing = addGoods.goodsAbilities.FirstOrDefault(temp => temp.AbilibityKind == EnumGoodsAbility.Nothing);
                            int          index = -1;
                            if (goodsAbility_nothing != null)
                            {
                                index = addGoods.goodsAbilities.IndexOf(goodsAbility_nothing);
                            }
                            //存在分割属性
                            if (index > -1 && index + 1 < addGoods.goodsAbilities.Count)
                            {
                                //取出分割项后的可变项
                                List <EnumGoodsAbility> randomAbilitys = Enumerable.Range(index + 1, addGoods.goodsAbilities.Count - index - 1).
                                                                         Select(temp => addGoods.goodsAbilities[temp]).Select(temp => temp.AbilibityKind).ToList();
                                int saveAbilityCount = (int)qualityType;//可保留的属性
                                while (randomAbilitys.Count > saveAbilityCount)
                                {
                                    int removeIndex = UnityEngine.Random.Range(0, randomAbilitys.Count);
                                    EnumGoodsAbility removeGoodsAbility = randomAbilitys[removeIndex];
                                    addGoods.goodsAbilities.RemoveAll(temp => temp.AbilibityKind == removeGoodsAbility);
                                    randomAbilitys.RemoveAt(removeIndex);
                                }
                            }
                        }
                        addGoods.goodsAbilities.RemoveAll(temp => temp.AbilibityKind == EnumGoodsAbility.Nothing);
                        //--------------------
                        PlayGoods playGoods = new PlayGoods(addGoodsID, addGoods, GoodsLocation.None);
                        playGoods.QualityType = qualityType;
                        playGoods.Count       = 1;
                        businessman.BaseList.Add(playGoods);
                    }
                }
            }
            #endregion
        }
    }