Example #1
0
        private AiStoryInstanceInfo NewAiStoryInstance(string storyId, string _namespace, bool logIfNotFound, params string[] overloadFiles)
        {
            if (!string.IsNullOrEmpty(_namespace))
            {
                storyId = string.Format("{0}:{1}", _namespace, storyId);
            }
            AiStoryInstanceInfo instInfo = GetUnusedAiStoryInstanceInfoFromPool(storyId);

            if (null == instInfo)
            {
                int      ct;
                string[] filePath;
                ct       = overloadFiles.Length;
                filePath = new string[ct];
                for (int i = 0; i < ct; i++)
                {
                    filePath[i] = HomePath.GetAbsolutePath(FilePathDefine_Client.C_DslPath + overloadFiles[i]);
                }
                StoryConfigManager.Instance.LoadStories(0, _namespace, filePath);
                StoryInstance instance = StoryConfigManager.Instance.NewStoryInstance(storyId, 0);
                if (instance == null)
                {
                    if (logIfNotFound)
                    {
                        LogSystem.Error("Can't load story config, story:{0} scene:{1} !", storyId, m_SceneId);
                    }
                    return(null);
                }
                for (int ix = 0; ix < filePath.Length; ++ix)
                {
                    Dictionary <string, StoryInstance> stories = StoryConfigManager.Instance.GetStories(filePath[ix]);
                    if (null != stories)
                    {
                        foreach (KeyValuePair <string, StoryInstance> pair in stories)
                        {
                            if (pair.Key != storyId)
                            {
                                AiStoryInstanceInfo info = new AiStoryInstanceInfo();
                                info.m_StoryInstance = pair.Value.Clone();
                                info.m_IsUsed        = false;
                                AddAiStoryInstanceInfoToPool(pair.Key, info);
                            }
                        }
                    }
                }
                AiStoryInstanceInfo res = new AiStoryInstanceInfo();
                res.m_StoryInstance = instance;
                res.m_IsUsed        = true;

                AddAiStoryInstanceInfoToPool(storyId, res);
                return(res);
            }
            else
            {
                instInfo.m_IsUsed = true;
                return(instInfo);
            }
        }
Example #2
0
        private void AddAiStoryInstanceInfoToPool(string storyId, AiStoryInstanceInfo info)
        {
            List <AiStoryInstanceInfo> infos;

            if (m_AiStoryInstancePool.TryGetValue(storyId, out infos))
            {
                infos.Add(info);
            }
            else
            {
                infos = new List <AiStoryInstanceInfo>();
                infos.Add(info);
                m_AiStoryInstancePool.Add(storyId, infos);
            }
        }
Example #3
0
        public void PreloadAiStory(string _namespace, string file)
        {
            string filePath = HomePath.GetAbsolutePath(FilePathDefine_Client.C_DslPath + file);

            StoryConfigManager.Instance.LoadStories(0, _namespace, filePath);
            Dictionary <string, StoryInstance> stories = StoryConfigManager.Instance.GetStories(filePath);

            if (null != stories)
            {
                foreach (KeyValuePair <string, StoryInstance> pair in stories)
                {
                    AiStoryInstanceInfo info = new AiStoryInstanceInfo();
                    info.m_StoryInstance = pair.Value.Clone();
                    info.m_IsUsed        = false;
                    AddAiStoryInstanceInfoToPool(pair.Key, info);
                }
            }
        }
Example #4
0
        private AiStoryInstanceInfo GetUnusedAiStoryInstanceInfoFromPool(string storyId)
        {
            AiStoryInstanceInfo        info = null;
            List <AiStoryInstanceInfo> infos;

            if (m_AiStoryInstancePool.TryGetValue(storyId, out infos))
            {
                int ct = infos.Count;
                for (int ix = 0; ix < ct; ++ix)
                {
                    if (!infos[ix].m_IsUsed)
                    {
                        info = infos[ix];
                        break;
                    }
                }
            }
            return(info);
        }
Example #5
0
 public void RecycleAiStoryInstance(AiStoryInstanceInfo info)
 {
     info.m_StoryInstance.Reset();
     info.m_IsUsed = false;
 }