private List <Dictionary <string, string> > m_fullDic = new List <Dictionary <string, string> >(); // every item info from DB public NPCActionChoiceFactory() { m_choiceWithParentList = new List <NPCActionChoiceWithParentID>(); m_actionChoiceList = new List <NPCActionChoice>(); m_choiceStList = new List <NPCActionChoiceNameSt>(); ReadNameDataFromXML(); for (int i = 0; i < m_fullDic.Count; i++) { m_choiceStList.Add(new NPCActionChoiceNameSt(m_fullDic[i])); } // NameTable XML에서 가져와서 저장 m_fullDic.Clear(); // 재활용하기 위해서 비워주기 ReadDataFromXml(); // 데이터 읽어오기 int numOfChoice = System.Enum.GetNames(typeof(NPCActionChoiceName)).Length; for (int i = 0; i < numOfChoice; i++) { string name = "NPCActionChoice" + i.ToString(); object obj = Activator.CreateInstance(Type.GetType(name)); NPCActionChoice choice = (NPCActionChoice)obj; m_actionChoiceList.Add(choice); } for (int i = 0; i < m_fullDic.Count; i++) { Dictionary <string, string> data = m_fullDic[i]; int id = int.Parse(data["ID"]); int givenID = -1; for (int k = 0; k < m_choiceStList.Count; k++) { if (m_choiceStList[k].GetGivenID(id) == -1) { continue; } givenID = m_choiceStList[k].m_givenID; break; } NPCActionChoice choice = m_actionChoiceList[givenID]; choice.Init(data); choice.m_npcActionChoiceName = (NPCActionChoiceName)givenID; int parentNPCActionID = int.Parse(data["ParentActionName"]); NPCActionChoiceWithParentID choiceWithParent = new NPCActionChoiceWithParentID(choice, parentNPCActionID); m_choiceWithParentList.Add(choiceWithParent); } // 데이터 저장 및 다음 Factory에게 부모가 누군지 알려주기 위해서 리스트 따로 만듬. for (int i = 0; i < m_actionChoiceList.Count; i++) { NPCActionChoice choice = m_actionChoiceList[i]; for (int j = 0; j < m_choiceStList.Count; j++) { if (m_choiceStList[j].GetGivenID(choice.m_id) != -1) { choice.m_npcActionChoiceName = (NPCActionChoiceName)m_choiceStList[j].m_givenID; break; } } } // 자기 자신에 대해서 초기화 m_fullDic = null; }
private List <Dictionary <string, string> > m_fullDic = new List <Dictionary <string, string> >(); // every item info from DB public NPCActionFactory(NPCActionChoiceFactory _choiceFactory) { m_actionList = new List <NPCAction>(); m_actionStList = new List <NPCActionNameSt>(); m_actionWithParentList = new List <NPCActionWithParentID>(); ReadNameDataFromXml(); // Name Table 읽어오기 for (int i = 0; i < m_fullDic.Count; i++) { m_actionStList.Add(new NPCActionNameSt(m_fullDic[i])); } // Name Table 저장 for (int i = 0; i < _choiceFactory.m_choiceWithParentList.Count; i++) { NPCActionChoiceWithParentID parentWithID = _choiceFactory.m_choiceWithParentList[i]; NPCActionChoice choice = parentWithID.m_npcActionChoice; int parentID = parentWithID.m_parentActionID; // parentID = DB에서 프라이머리 키, 자동할당 따라서 내 임의대로 안됨. 그래서 따로 바꿔줘야 함 for (int k = 0; k < m_actionStList.Count; k++) { NPCActionNameSt nameST = m_actionStList[k]; int givenID = -1; if (nameST.GetGivenID(parentID) == -1) { continue; } givenID = nameST.m_givenID; choice.m_parentNPCActionName = (NPCActionName)givenID; break; } } // 이전 단계에서 Parent에 대해서 ID와 GivenID 알 수 없었기 때문에 여기에서 초기화 해준다. m_fullDic.Clear(); // 재활용을 위해서 ReadDataFromXml(); // 정보 읽어오기 int numOfAction = Enum.GetNames(typeof(NPCActionName)).Length; for (int i = 0; i < numOfAction; i++) { string name = "NPCAction" + i.ToString(); object obj = Activator.CreateInstance(Type.GetType(name)); NPCAction action = (NPCAction)obj; m_actionList.Add(action); } // 스크립트가 다 따로 있기 때문에 현재 이런 방식으로 하고 있음. // 스크립트 이름이 다르기 때문에 만들었음. // 순서는 givenID를 Enum Casting한 것과 똑같다. for (int i = 0; i < m_fullDic.Count; i++) { Dictionary <string, string> data = m_fullDic[i]; int id = int.Parse(data["NPCActionName"]); int givenID = -1; for (int k = 0; k < m_actionStList.Count; k++) { if (m_actionStList[k].GetGivenID(id) == -1) { continue; } givenID = m_actionStList[k].m_givenID; break; } NPCAction properAction = m_actionList[givenID]; properAction.Init(data); // 몇 개의 데이터만 초기화 된다. F12들어가서 보면 확인가능 properAction.m_npcActionName = (NPCActionName)givenID; // ID는 GivenID로 형변환 해야한다. int parentNPCID = int.Parse(data["ParentNPC"]); NPCActionWithParentID actionWithParent = new NPCActionWithParentID(properAction, parentNPCID); m_actionWithParentList.Add(actionWithParent); } for (int i = 0; i < _choiceFactory.m_actionChoiceList.Count; i++) { NPCActionChoice choice = _choiceFactory.m_actionChoiceList[i]; for (int k = 0; k < m_actionList.Count; k++) { NPCAction action = m_actionList[k]; if (action.m_npcActionName != choice.m_parentNPCActionName || action.m_npcActionName == NPCActionName.None) { continue; } action.AddChoice(choice); break; } } m_fullDic = null; }