public bool Init(ScriptableData.ScriptableDataInfo config) { bool ret = false; ScriptableData.FunctionData skill = config.First; if (null != skill && (skill.GetId() == "skill" || skill.GetId() == "script")) { ret = true; ScriptableData.CallData callData = skill.Call; if (null != callData && callData.HaveParam()) { m_Id = int.Parse(callData.GetParamId(0)); } for (int i = 0; i < skill.Statements.Count; i++) { if (skill.Statements[i].GetId() == "local") { ScriptableData.FunctionData sectionData = skill.Statements[i] as ScriptableData.FunctionData; if (null != sectionData) { for (int j = 0; j < sectionData.Statements.Count; j++) { ScriptableData.CallData defData = sectionData.Statements[j] as ScriptableData.CallData; if (null != defData && defData.HaveId() && defData.HaveParam()) { string id = defData.GetId(); if (id.StartsWith("@") && !id.StartsWith("@@")) { SkillValue val = new SkillValue(); val.InitFromDsl(defData.GetParam(0)); if (!m_PreInitedLocalVariables.ContainsKey(id)) { m_PreInitedLocalVariables.Add(id, val.Value); } else { m_PreInitedLocalVariables[id] = val.Value; } } } } } else { LogUtil.Error("Story {0} DSL, local must be a function !", m_Id); } } else if (skill.Statements[i].GetId() == "onmessage") { ScriptableData.FunctionData sectionData = skill.Statements[i] as ScriptableData.FunctionData; if (null != sectionData) { MessageHandler handler = new MessageHandler(); handler.Load(sectionData); string msgId = handler.MessageId; if (!m_MessageQueues.ContainsKey(msgId)) { m_MessageHandlers.Add(handler); m_MessageQueues.Add(msgId, new Queue<MessageInfo>()); } else { LogUtil.Error("Story {0} DSL, onmessage {1} duplicate, discard it !", m_Id, msgId); } } else { LogUtil.Error("Story {0} DSL, onmessage must be a function !", m_Id); } } else { LogUtil.Error("Instance::Init, unknown part {0}", skill.Statements[i].GetId()); } } } else { LogUtil.Error("Instance::Init, isn't story DSL"); } //LogSystem.Debug("Instance.Init message handler num:{0} {1}", m_MessageHandlers.Count, ret); return ret; }
public bool Init(ScriptableData.ScriptableDataInfo config) { bool ret = false; ScriptableData.FunctionData story = config.First; if (story != null && (story.GetId() == "story" || story.GetId() == "script")) { ret = true; //参数 ScriptableData.CallData callData = story.Call; if (callData != null && callData.HaveParam()) { //第一个参数是剧情的id m_iStoryId = int.Parse(callData.GetParamId(0)); } foreach (var info in story.Statements) { if (info.GetId() == "local") { ScriptableData.FunctionData sectionData = info as ScriptableData.FunctionData; if (null != sectionData) { foreach (ScriptableData.ISyntaxComponent def in sectionData.Statements) { ScriptableData.CallData defData = def as ScriptableData.CallData; if (null != defData && defData.HaveId() && defData.HaveParam()) { string id = defData.GetId(); if (id.StartsWith("@") && !id.StartsWith("@@")) { StoryValue val = new StoryValue(); val.InitFromDsl(defData.GetParam(0)); if (!m_dicLocalVariables.ContainsKey(id)) { m_dicLocalVariables.Add(id, val.Value); } else { m_dicLocalVariables[id] = val.Value; } } } } } else { Debug.LogError("剧情" + m_iStoryId + "DSL语法,必须是个函数"); } } else if (info.GetId() == "onmessage") { ScriptableData.FunctionData sectionData = info as ScriptableData.FunctionData; if (null != sectionData) { StoryMessageHandler handler = new StoryMessageHandler(); handler.Load(sectionData); m_listMessageHandlers.Add(handler); } else { Debug.LogError("剧情" + m_iStoryId + "DSL语法,必须是个函数"); } } else { Debug.LogError("StoryInstance::Init,不知道DSL语法部分:" + info.GetId()); } } } else { Debug.LogError("StoryInstance::Init,不是一个DSL语法"); } return ret; }
public bool Init(ScriptableData.ScriptableDataInfo config) { bool ret = false; ScriptableData.FunctionData skill = config.First; if (null != skill && skill.GetId() == "skill") { ret = true; ScriptableData.CallData callData = skill.Call; if (null != callData && callData.HaveParam()) { m_SkillId = int.Parse(callData.GetParamId(0)); } for (int i = 0; i < skill.Statements.Count; i++) { if (skill.Statements[i].GetId() == "section") { ScriptableData.FunctionData sectionData = skill.Statements[i] as ScriptableData.FunctionData; if (null != sectionData) { SkillSection section = new SkillSection(); section.Load(sectionData, m_SkillId); m_Sections.Add(section); } else { LogSystem.Error("Skill {0} DSL, section must be a function !", m_SkillId); } } else if (skill.Statements[i].GetId() == "onmessage") { ScriptableData.FunctionData sectionData = skill.Statements[i] as ScriptableData.FunctionData; if (null != sectionData) { SkillMessageHandler handler = new SkillMessageHandler(); handler.Load(sectionData, m_SkillId); m_MessageHandlers.Add(handler); } else { LogSystem.Error("Skill {0} DSL, onmessage must be a function !", m_SkillId); } } else if (skill.Statements[i].GetId() == "onstop") { ScriptableData.FunctionData sectionData = skill.Statements[i] as ScriptableData.FunctionData; if (null != sectionData) { m_StopSection = new SkillMessageHandler(); m_StopSection.Load(sectionData, m_SkillId); } else { LogSystem.Error("Skill {0} DSL, onstop must be a function !", m_SkillId); } } else if (skill.Statements[i].GetId() == "oninterrupt") { ScriptableData.FunctionData sectionData = skill.Statements[i] as ScriptableData.FunctionData; if (null != sectionData) { m_InterruptSection = new SkillMessageHandler(); m_InterruptSection.Load(sectionData, m_SkillId); } else { LogSystem.Error("Skill {0} DSL, oninterrupt must be a function !", m_SkillId); } } else { LogSystem.Error("SkillInstance::Init, unknown part {0}", skill.Statements[i].GetId()); } } /* * foreach (ScriptableData.ISyntaxComponent info in skill.Statements) { * if (info.GetId() == "section") { * ScriptableData.FunctionData sectionData = info as ScriptableData.FunctionData; * if (null != sectionData) { * SkillSection section = new SkillSection(); * section.Load(sectionData, m_SkillId); * m_Sections.Add(section); * } else { * LogSystem.Error("Skill {0} DSL, section must be a function !", m_SkillId); * } * } else if (info.GetId() == "onmessage") { * ScriptableData.FunctionData sectionData = info as ScriptableData.FunctionData; * if (null != sectionData) { * SkillMessageHandler handler = new SkillMessageHandler(); * handler.Load(sectionData, m_SkillId); * m_MessageHandlers.Add(handler); * } else { * LogSystem.Error("Skill {0} DSL, onmessage must be a function !", m_SkillId); * } * } else if (info.GetId() == "onstop") { * ScriptableData.FunctionData sectionData = info as ScriptableData.FunctionData; * if (null != sectionData) { * m_StopSection = new SkillMessageHandler(); * m_StopSection.Load(sectionData, m_SkillId); * } else { * LogSystem.Error("Skill {0} DSL, onstop must be a function !", m_SkillId); * } * } else if (info.GetId() == "oninterrupt") { * ScriptableData.FunctionData sectionData = info as ScriptableData.FunctionData; * if (null != sectionData) { * m_InterruptSection = new SkillMessageHandler(); * m_InterruptSection.Load(sectionData, m_SkillId); * } else { * LogSystem.Error("Skill {0} DSL, oninterrupt must be a function !", m_SkillId); * } * } else { * LogSystem.Error("SkillInstance::Init, unknown part {0}", info.GetId()); * } * }*/ } else { LogSystem.Error("SkillInstance::Init, isn't skill DSL"); } //LogSystem.Debug("SkillInstance.Init section num:{0} {1}", m_Sections.Count, ret); return(ret); }