Exemplo n.º 1
0
        public void LoadStoryRecord(int indexOfRecord)
        {
            Dictionary <int, StoryRecord> storyRecordDict = recordManager.StoryRecordDict;
            StoryRecord sr = null;

            if (storyRecordDict.ContainsKey(indexOfRecord))
            {
                sr = storyRecordDict[indexOfRecord];
                Debug.Log("读取故事记录! :" + indexOfRecord);
            }
            else
            {
                Debug.LogWarning("不能读取故事存档 :" + indexOfRecord);
                return;
            }

            stateMachine.LoadStoryRecord(sr.currentStateName, sr.LastStateName, sr.StateBuff);
            musicManager.LoadStoryRecord(sr.bgmIndex, sr.voiceIndex, sr.voiceCharacterName);
            scriptManager.LoadStoryRecord(sr.scriptPointerScriptName, sr.scriptPointerLineNumber,
                                          sr.scriptReplaceKeys, sr.scriptReplaceValues,
                                          sr.pointerScriptNameStack, sr.pointerLineNumberStack);
            markManager.LoadStoryRecord(sr.markStoryList, sr.varStoryNameList, sr.varStoryValueList, sr.chapterName);
            backlogManager.LoadStoryRecord(sr.backlogItemList, sr.head, sr.capacity, sr.count);
            //renderManager.LoadStoryData 负责Choice Backlog Image Text
            renderManager.LoadStoryRecord(sr);
        }
Exemplo n.º 2
0
 public void SaveStoryRecord(int indexOfRecord, StoryRecord newStoryRecord)
 {
     if (newStoryRecord == null)
     {
         throw new System.Exception("PlayerRecordManager SaveStoryRecord");
     }
     if (indexOfRecord >= 0 && indexOfRecord < PachiGrimoire.I.constData.SaveDataMaxCount)
     {
         string      json        = JsonUtility.ToJson(newStoryRecord);
         StoryRecord storyRecord = new StoryRecord();
         JsonUtility.FromJsonOverwrite(json, storyRecord);
         if (StoryRecordDict.ContainsKey(indexOfRecord))
         {
             StoryRecordDict[indexOfRecord] = storyRecord;
         }
         else
         {
             StoryRecordDict.Add(indexOfRecord, storyRecord);
         }
         PachiGrimoire.I.FileManager.SaveStoryRecord(json, indexOfRecord);
     }
     else
     {
         throw new System.Exception("保存storyRecord时,index不得劲!" + indexOfRecord);
     }
 }
Exemplo n.º 3
0
        public bool LoadStoryRecordData(List <FileInfo> fileInfoList)  // 规定保存记录的文件命名格式是固定的
        {
            if (fileInfoList == null || fileInfoList.Count == 0)
            {
                return(false);
            }

            StoryRecordDict.Clear();
            StoryRecordDict = new Dictionary <int, StoryRecord>(PachiGrimoire.I.constData.SaveDataMaxCount);
            string saveDataCommonPrefixName = PachiGrimoire.I.constData.SaveDataCommonPrefixName;

            for (int i = 0; i < fileInfoList.Count; i++)
            {
                FileInfo fileInfo = fileInfoList[i];
                string   fileName = fileInfo.Name;
                if (fileName.Contains(".txt") || fileName.Contains(".TXT"))
                {
                    fileName = fileName.Split('.')[0];
                }
                if (fileName.Contains(saveDataCommonPrefixName))
                {
                    int indexOfSaveData = -1;
                    if (fileName.Contains(PachiGrimoire.I.constData.SaveDataQuickPrefixName))
                    {
                        indexOfSaveData = 0;
                    }
                    else
                    {
                        indexOfSaveData = int.Parse(fileName.Substring(saveDataCommonPrefixName.Length));
                    }
                    if (indexOfSaveData >= 0 && indexOfSaveData < PachiGrimoire.I.constData.SaveDataMaxCount)
                    {
                        string filePath = fileInfo.FullName;
                        string json     = PachiGrimoire.I.FileManager.LoadStoryRecordContext(filePath);

                        // Json可以Overwrite
                        StoryRecord storyRecord = new StoryRecord();
                        JsonUtility.FromJsonOverwrite(json, storyRecord);
                        StoryRecordDict.Add(indexOfSaveData, storyRecord);
                    }
                }
            }
            return(true);
        }
Exemplo n.º 4
0
        public void LoadStoryRecord(StoryRecord sr)
        {
            // Reset Original Data
            #region Reset Original Data
            choice0.SetActive(false);
            choice1.SetActive(false);
            choice2.SetActive(false);
            choice3.SetActive(false);
            if (choiceList != null)
            {
                for (int i = 0; i < choiceList.Count; i++)   // 还原Choice Gameobjects 状态
                {
                    GameObject go = choiceList[i];
                    UIEventListener.Get(go).onPress = null;
                    UIButton button = go.GetComponent <UIButton>();
                    button.hover   = Color.white;
                    button.pressed = Color.white;
                    UITexture texture = go.GetComponent <UITexture>();
                    texture.alpha = 1f;
                    UILabel label = go.GetComponentInChildren <UILabel>();
                    label.text = "";
                    go.SetActive(false);
                }
            }
            sequence?.Pause();
            sequence = CreateSequence();

            #endregion



            // Reset StoryRecord Data
            dialogContextIndex    = sr.dialogContextIndex;
            characterName         = sr.characterName;
            backgroundImageIndex  = sr.backgroundImageIndex;
            smallFigureImageIndex = sr.smallFigureImageIndex;
            List <string> figureImageKeyList     = new List <string>(sr.figureImageKeyList);
            List <string> figureImageFIIndexList = new List <string>(sr.figureImageFIIndexList);
            List <float>  figureImagePosXList    = new List <float>(sr.figureImagePosXList);
            List <float>  figureImagePosYList    = new List <float>(sr.figureImagePosYList);
            List <float>  figureImageScaleXList  = new List <float>(sr.figureImageScaleXList);
            List <float>  figureImageScaleYList  = new List <float>(sr.figureImageScaleYList);
            choiceItemList = new List <ChoiceItem>(sr.choiceItemList);

            if (!string.IsNullOrEmpty(dialogContextIndex))
            {
                string context = resourceManager.Get <string>(dialogContextIndex);
                contextLabel.text = context;
            }
            else
            {
                contextLabel.text = "";
            }

            nameLabel.text = characterName == null ? "" : characterName;

            if (!string.IsNullOrEmpty(backgroundImageIndex))
            {
                Texture2D backgroundTexture2D = resourceManager.Get <Texture2D>(backgroundImageIndex);
                backgroundUITextureTop.mainTexture = backgroundTexture2D;
                backgroundUITextureTop.width       = ConstData.TEXTURE2D_WIDTH;
                backgroundUITextureTop.height      = ConstData.TEXTURE2D_HEIGHT;
                backgroundUITextureTop.alpha       = 1f;
            }
            else
            {
                backgroundUITextureTop.mainTexture = null;
            }
            backgroundUITexture.mainTexture = null;
            backgroundUITexture.width       = ConstData.TEXTURE2D_WIDTH;
            backgroundUITexture.height      = ConstData.TEXTURE2D_HEIGHT;
            backgroundUITexture.alpha       = 1f;

            if (!string.IsNullOrEmpty(smallFigureImageIndex))
            {
                Texture2D smallFigureTexture2D = resourceManager.Get <Texture2D>(smallFigureImageIndex);
                smallFigureImageUITextureTop.mainTexture = smallFigureTexture2D;
                smallFigureImageUITextureTop.width       = ConstData.TEXTURE2D_SMALL_FIGURE_IMAGE_WIDTH;
                smallFigureImageUITextureTop.height      = ConstData.TEXTURE2D_SMALL_FIGURE_IMAGE_HEIGHT;
                smallFigureImageUITextureTop.alpha       = 1f;
            }
            else
            {
                smallFigureImageUITextureTop.mainTexture = null;
            }
            smallFigureImageUITexture.mainTexture = null;
            smallFigureImageUITexture.width       = ConstData.TEXTURE2D_SMALL_FIGURE_IMAGE_WIDTH;
            smallFigureImageUITexture.height      = ConstData.TEXTURE2D_SMALL_FIGURE_IMAGE_HEIGHT;
            smallFigureImageUITexture.alpha       = 1f;

            FigureImageDataClear();
            if (figureImageKeyList.Count != 0)
            {
                for (int i = 0; i < figureImageKeyList.Count; i++)
                {
                    string    uiKey     = figureImageKeyList[i];
                    string    fiIndex   = figureImageFIIndexList[i];
                    float     scale_x   = figureImageScaleXList[i];
                    float     scale_y   = figureImageScaleYList[i];
                    float     pos_x     = figureImagePosXList[i];
                    float     pos_y     = figureImagePosYList[i];
                    Texture2D texture2D = null;
                    if (!string.IsNullOrEmpty(fiIndex))
                    {
                        texture2D = resourceManager.Get <Texture2D>(fiIndex);
                    }
                    float width  = texture2D.width;
                    float height = texture2D.height;

                    GameObject go        = new GameObject(uiKey);
                    UITexture  uiTexture = go.AddComponent <UITexture>();
                    uiTexture.mainTexture = texture2D;
                    uiTexture.width       = (int)(width * scale_x);
                    uiTexture.height      = (int)(height * scale_y);
                    go.transform.position = new Vector3(pos_x, pos_y, 0);
                    go.transform.SetParent(root.transform, false);
                    KeyValuePair <string, UITexture> pair = new KeyValuePair <string, UITexture>(fiIndex, uiTexture);
                    figureImageDict.Add(uiKey, pair);
                }
            }

            if (choiceItemList.Count != 0)
            {
                //ChoiceCreate(choiceItemList);
                PachiGrimoire.I.ScriptManager.KILLERQUEEN();
            }
        }
Exemplo n.º 5
0
        public void SaveStoryRecord(int indexOfRecord)
        {
            BaseState currentState = stateMachine.CurrentState;

            if (currentState != RunWaitState.Instance && currentState != ChoiceWaitState.Instance)   //currentState != SleepState.Instance &&
            {
                throw new System.Exception("StageContextManager SaveStoryRecord " + currentState.StateName);
            }

            Debug.Log("保存故事记录! :" + indexOfRecord);

            StoryRecord storyRecord = new StoryRecord();

            storyRecord.dateTime = System.DateTime.Now.ToString();

            storyRecord.LastStateName    = stateMachine.LastState.StateName;
            storyRecord.currentStateName = stateMachine.CurrentState.StateName;
            storyRecord.StateBuff        = stateMachine.StateBuff;

            storyRecord.bgmIndex           = musicManager.BGMIndex;
            storyRecord.voiceIndex         = musicManager.VoiceIndex;
            storyRecord.voiceCharacterName = musicManager.CharacterName;

            storyRecord.scriptPointerScriptName = scriptManager.ScriptPointerScriptName;
            storyRecord.scriptPointerLineNumber = scriptManager.ScriptPointerLineNumber;
            storyRecord.scriptReplaceKeys       = scriptManager.ScriptReplaceKeys;
            storyRecord.scriptReplaceValues     = scriptManager.ScriptReplaceValues;
            var pointerScriptNameStack = new List <string>(scriptManager.PointerScriptNameStack.ToArray());

            pointerScriptNameStack.Reverse();
            storyRecord.pointerScriptNameStack = pointerScriptNameStack;
            var pointerLineNumberStack = new List <int>(scriptManager.PointerLineNumberStack.ToArray());

            pointerLineNumberStack.Reverse();
            storyRecord.pointerLineNumberStack = pointerLineNumberStack;


            storyRecord.markStoryList     = markManager.MarkStoryList;
            storyRecord.varStoryNameList  = new List <string>(markManager.ValueStoryDict.Keys);
            storyRecord.varStoryValueList = new List <float>(markManager.ValueStoryDict.Values);
            storyRecord.chapterName       = markManager.ChapterName;

            storyRecord.dialogContextIndex   = renderManager.DialogContextIndex;
            storyRecord.characterName        = renderManager.CharacterName;
            storyRecord.backgroundImageIndex = renderManager.BackgroundImageIndex;
            List <string> figureImageKeyList     = new List <string>();
            List <string> figureImageFIIndexList = new List <string>();
            List <float>  figureImagePosXList    = new List <float>();
            List <float>  figureImagePosYList    = new List <float>();
            List <float>  figureImageScaleXList  = new List <float>();
            List <float>  figureImageScaleYList  = new List <float>();
            Dictionary <string, KeyValuePair <string, UITexture> > figureImageDict = renderManager.FigureImageDict;
            var keyArray = figureImageDict.Keys.ToArray();

            for (int i = 0; i < keyArray.Length; i++)
            {
                string key = keyArray[i];
                KeyValuePair <string, UITexture> pair = figureImageDict[key];
                string    fiIndex     = pair.Key;
                Transform uiTextureTF = pair.Value.transform;
                Vector3   pos         = uiTextureTF.localPosition;
                Vector3   scale       = uiTextureTF.localScale;
                figureImageKeyList.Add(key);
                figureImageFIIndexList.Add(fiIndex);
                figureImagePosXList.Add(pos.x);
                figureImagePosYList.Add(pos.y);
                figureImageScaleXList.Add(scale.x);
                figureImageScaleYList.Add(scale.y);
            }
            storyRecord.figureImageKeyList     = figureImageKeyList;
            storyRecord.figureImageFIIndexList = figureImageFIIndexList;
            storyRecord.figureImagePosXList    = figureImagePosXList;
            storyRecord.figureImagePosYList    = figureImagePosYList;
            storyRecord.figureImageScaleXList  = figureImageScaleXList;
            storyRecord.figureImageScaleYList  = figureImageScaleYList;
            storyRecord.smallFigureImageIndex  = renderManager.SmallFigureImageIndex;
            storyRecord.choiceItemList         = renderManager.ChoiceItemList;

            storyRecord.backlogItemList = backlogManager.BacklogItemList;
            storyRecord.capacity        = backlogManager.Capacity;
            storyRecord.count           = backlogManager.Count;
            storyRecord.head            = backlogManager.Head;

            recordManager.SaveStoryRecord(indexOfRecord, storyRecord);
        }