/// <summary>
        /// 对Mission进行重命名
        /// 该方法同时修改MissionObject,即实际文件的名字
        /// 保证Mission的名字与Mision文件的名字同步一致
        /// </summary>
        /// <param name="missionName"></param>
        /// <param name="newName"></param>
        /// <returns></returns>
        public bool RenameMission(string missionName, string newName)
        {
            //string oldPath = GetFullMissionPath(missionName);

            MissionData data = _missionSaveList.Find((m) => m.Name == missionName);

            if (null != data)
            {
                return(data.Rename(newName));
            }
            return(false);
        }
 public bool DeleteMissionData(MissionData mo)
 {
     if (!_missionSaveList.Contains(mo))
     {
         return(false);
     }
     //string path = GetFullMissionPath(mo._name);
     //UnityEditor.AssetDatabase.DeleteAsset(path);
     mo.Delete();
     _missionSaveList.Remove(mo);
     return(true);
 }
        public MissionData[] GetMissionSaveDataByMission(NodeBase[] missions)
        {
            List <MissionData> datas = new List <MissionData>();

            for (int i = 0; i < missions.Length; i++)
            {
                MissionData data = GetMissionSaveDataByName(missions[i]._name);
                if (data != null)
                {
                    datas.Add(data);
                }
            }
            return(datas.ToArray());
        }
        public void Load()
        {
            if (_SaveData.Length > 0)
            {
                using (MemoryStream ms = new MemoryStream(_SaveData))
                {
                    using (BinaryReader r = new BinaryReader(ms))
                    {
                        float ver = r.ReadSingle();
                        if (ver != Story.SaveVersion)
                        {
                            Debug.LogError("Error:Archive data version not same! Curent: " + Story.SaveVersion + " Data: " + ver);
                        }

                        string storyData = r.ReadString();
                        _story = JsonUtility.FromJson <Story>(storyData);
                        _story.LoadOnlyThisNode(r);
                    }
                }
            }

            if (_story == null)
            {
                _story = new Story();
            }

            for (int i = 0; i < _missionSaveList.Count; i++)
            {
                MissionData data = _missionSaveList[i];
                if (!data.MissionObject)
                {
                    Debug.Log("Mission Not Found: " + data.Name);
                    continue;
                }

                data.MissionObject.Load();
                data.MissionObject._mission._name = data.Name;

                NodeModifier.SetContent(data.MissionObject._mission, _story);
            }

            //设置已连接的节点
            for (int i = 0; i < _missionSaveList.Count; i++)
            {
                MissionData data = _missionSaveList[i];
                if (!data.MissionObject)
                {
                    continue;
                }
                if (data.MissionObject._nextMissionNodeList.Count > 0)
                {
                    foreach (var item in data.MissionObject._nextMissionNodeList)
                    {
                        MissionData next = GetMissionSaveDataByName(item.Name);
                        if (next == null)
                        {
                            continue;
                        }
                        if (next.MissionObject == null)
                        {
                            continue;
                        }
                        if (item.IsSingleNode)
                        {
                            data.MissionObject._mission.AddNextNode(next.MissionObject._mission);
                        }
                        else
                        {
                            Mission.SetParent(next.MissionObject._mission, data.MissionObject._mission);
                        }
                    }
                }
            }
        }
        public void Load()
        {
            if (_SaveData.Length > 0)
            {
                using (MemoryStream ms = new MemoryStream(_SaveData))
                {
                    using (BinaryReader r = new BinaryReader(ms))
                    {
                        float ver = r.ReadSingle();
                        if (ver != Story.SaveVersion)
                        {
                            Debug.LogError("Error:Archive data version not same! Curent: " + Story.SaveVersion + " Data: " + ver);
#if UNITY_EDITOR
                            if (!_queryloaded)
                            {
                                _queryloaded = true;
                                if (!UnityEditor.EditorUtility.DisplayDialog("Error!", "Error:Archive data version not the same! Curent Version: " + Story.SaveVersion + " Data Version:" + ver, "Force Load", "Cancel"))
                                {
                                    return;
                                }
                            }
#endif
                        }

                        _queryloaded = false;

                        string storyData = r.ReadString();
                        _story = JsonUtility.FromJson <Story>(storyData);
                        _story.LoadOnlyThisNode(r);
                    }
                }
            }

            if (_story == null)
            {
                _story = new Story();
            }

            _haveNullData = false;
            for (int i = 0; i < _missionSaveList.Count; i++)
            {
                MissionData data = _missionSaveList[i];
                if (!data.MissionObject)
                {
                    Debug.Log("Mission Not Found: " + data.Name);
                    _haveNullData = true;
                    continue;
                }

                data.MissionObject.Load();
                data.MissionObject._mission._name = data.Name;

                NodeModifier.SetContent(data.MissionObject._mission, _story);
            }

            //设置已连接的节点
            for (int i = 0; i < _missionSaveList.Count; i++)
            {
                MissionData data = _missionSaveList[i];
                if (!data.MissionObject)
                {
                    continue;
                }
                if (data.MissionObject._nextMissionNodeList.Count > 0)
                {
                    foreach (var item in data.MissionObject._nextMissionNodeList)
                    {
                        MissionData next = GetMissionSaveDataByName(item.Name);
                        if (next == null)
                        {
                            continue;
                        }
                        if (next.MissionObject == null)
                        {
                            continue;
                        }
                        if (item.IsSingleNode)
                        {
                            data.MissionObject._mission.AddNextNode(next.MissionObject._mission);
                        }
                        else
                        {
                            Mission.SetParent(next.MissionObject._mission, data.MissionObject._mission);
                        }
                    }
                }
            }

            if (_haveNullData)
            {
                UnityEditor.EditorUtility.DisplayDialog("Attention!", "You have some Mission File Lost! ", "OK");
            }
        }
        public void Save()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter w = new BinaryWriter(ms))
                {
                    _saveVersion = Story.SaveVersion;

                    w.Write(Story.SaveVersion);

                    w.Write(JsonUtility.ToJson(_story));

                    _story.SaveOnlyThisNode(w);
                }
                _SaveData = ms.ToArray();
            }


            _haveNullData = false;

            //Upadte Mission Refrence
            NodeModifier[] Nodes = _Story.Nodes;
            for (int i = 0; i < Nodes.Length; i++)
            {
                MissionData data = _missionSaveList.Find((n) => n.Name == Nodes[i]._name);
                if (data != null)
                {
                    if (data.MissionObject != null)
                    {
                        data.MissionObject._mission = Nodes[i] as Mission;
                    }
                }
            }

            List <MissionData> toDelete = new List <MissionData>();

            for (int i = 0; i < _missionSaveList.Count; i++)
            {
                MissionObject mo = _missionSaveList[i].MissionObject;
                if (mo == null)
                {
                    _haveNullData = true;
                    continue;
                }
                //Update Mission Insure Data
                //mo._mission = _Story.GetNode(mo._mission._name) as Mission;
                //Update Name For insure
                //_missionSaveList[i].Name = mo.name;
                //mo._mission = System.Array.Find<NodeModifier>(Nodes, (n) => n._name == mo.name) as Mission;
                //如果标志Mission已经为空,则代表删除
                if (mo._mission == null)
                {
                    toDelete.Add(_missionSaveList[i]);
                    continue;
                }

                _missionSaveList[i].RefreshExtraData();


                //UnityEditor.EditorUtility.SetDirty(mo);
                NodeModifier[] nextMissions = mo._mission.NextNodes;
                MissionData    data         = GetMissionSaveDataByName(mo._mission._name);
                data.ClearNextMissionObject();
                if (nextMissions.Length > 0)
                {
                    data.AddNextMissionObject(GetMissionSaveDataByMission(nextMissions));
                }

                mo.Save();
            }

            //删除
            for (int i = 0; i < toDelete.Count; i++)
            {
                DeleteMissionData(toDelete[i]);
            }

            UnityEditor.EditorUtility.SetDirty(this);

            if (!_haveNullData)
            {
                UnityEditor.EditorUtility.DisplayDialog("Tips", "Save Successfully!", "OK");
            }
            else
            {
                UnityEditor.EditorUtility.DisplayDialog("Tips", "Some Data Save Failed!You should check out it.", "OK");
            }
        }
 public void AddNextMissionObject(MissionData[] os)
 {
     for (int i = 0; i < os.Length; i++)
     {
         MissionObject.AddNextMissionName(os[i]._name, os[i].MissionObject._mission.Parent != MissionObject._mission);
     }
 }
 public bool DeleteMissionData(MissionData mo)
 {
     if (!_missionSaveList.Contains(mo)) return false;
     //string path = GetFullMissionPath(mo._name);
     //UnityEditor.AssetDatabase.DeleteAsset(path);
     mo.Delete();
     _missionSaveList.Remove(mo);
     return true;
 }