private void OnChoiceButtonPress(GameObject go, bool isPress) // 不知道怎么编能更好 { if (isPress == false) { return; } if (choosenDLIndex != null) { return; } if (!isWorking) { return; } string name = go.name; int number = int.Parse(name[6].ToString()); ChoiceItem choiceItem = choiceItemList[number]; choosenDLIndex = choiceItem.dlIndex; string mark = choiceItem.mark; string scriptContext = choiceItem.onSelectedScirptContext; PachiGrimoire.I.MarkManager.MarkStorySet(mark); PachiGrimoire.I.MarkManager.MarkPlayerSet(mark); PachiGrimoire.I.ScriptManager.LoadScriptContext(scriptContext); OnChoiceButtonOnPressHelper(); }
protected override void OnUpdateStageContext() //Engine_ChoiceCreate(myFirstMark,*DL_Choice_0*,true,<Engine_ScriptLoadFile(*SC_SomeScriptName*)>,mySecondMark,*DL_Choice_1*,false,<Engine_ScriptLoadFile(*SC_OtherScriptName*)>) { if (paraList.Count == 0 || paraList.Count % 4 != 0) { throw new System.Exception("EngineChoiceCreateNode"); } StateMachineManager stateMachine = PachiGrimoire.I.StateMachine; stateMachine.TransferStateTo(ChoiceWaitState.Instance); StateBuff stateBuff = stateMachine.StateBuff; if (stateBuff == StateBuff.Next) { stateMachine.SetStateBuff(StateBuff.Normal); } List <ChoiceItem> choiceItemList = new List <ChoiceItem>(); string mark; string dlIndex; bool canBeSelected; string onSelectedScirptContext; for (int i = 0; i < paraList.Count; i += 4) { mark = paraList[i]; dlIndex = paraList[i + 1]; canBeSelected = bool.Parse(paraList[i + 2]); onSelectedScirptContext = paraList[i + 3]; ChoiceItem choiceItem = new ChoiceItem(mark, dlIndex, canBeSelected, onSelectedScirptContext); choiceItemList.Add(choiceItem); } StageRenderManager.I.ChoiceCreate(choiceItemList); }
public void ChoiceCreate(List <ChoiceItem> choiceItemList) // 不管是Run Auto Skip 总有渲染效果 { if (choiceItemList == null || choiceItemList.Count == 0) { throw new System.Exception("StageRenderManager ChoiceCreate"); } this.choiceItemList = choiceItemList; choosenDLIndex = null; int count = choiceItemList.Count; // 得到各个选项的文本 // 不能选择的用不能选的图片渲染,能选的检查mark 是否有已经选过的,选过的用别的选项图片渲染 // 给每个选项添加回调函数 要有mark和script信息 choiceList = new List <GameObject>(); choiceList.Add(choice0); choiceList.Add(choice1); if (count >= 3) { choiceList.Add(choice2); if (count >= 4) { choiceList.Add(choice3); if (count > 4) { throw new System.Exception("Only 4 choices!"); } } } for (int i = 0; i < choiceList.Count; i++) { ChoiceItem choiceItem = choiceItemList[i]; string mark = choiceItem.mark; string dlIndex = choiceItem.dlIndex; bool canBeSelected = choiceItem.canBeSelected; string choiceContext = null; if (!string.IsNullOrEmpty(dlIndex)) { choiceContext = resourceManager.Get <string>(dlIndex); } GameObject choice = choiceList[i]; choice.SetActive(true); if (count <= 3) { if (i == 0) { choice.transform.localPosition = new Vector3(constData.ChoicePosX_0of23, constData.ChoicePosY_0of23, 0f); } else if (i == 1) { choice.transform.localPosition = new Vector3(constData.ChoicePosX_1of23, constData.ChoicePosY_1of23, 0f); } else if (i == 2) { choice.transform.localPosition = new Vector3(constData.ChoicePosX_2of23, constData.ChoicePosY_2of23, 0f); } } else if (count == 4) { if (i == 0) { choice.transform.localPosition = new Vector3(constData.ChoicePosX_0of4, constData.ChoicePosY_0of4, 0f); } else if (i == 1) { choice.transform.localPosition = new Vector3(constData.ChoicePosX_1of4, constData.ChoicePosY_1of4, 0f); } else if (i == 2) { choice.transform.localPosition = new Vector3(constData.ChoicePosX_2of4, constData.ChoicePosY_2of4, 0f); } else if (i == 3) { choice.transform.localPosition = new Vector3(constData.ChoicePosX_3of4, constData.ChoicePosY_3of4, 0f); } } UIButton uiButton = choice.GetComponent <UIButton>(); UILabel uiLabel = choice.GetComponentInChildren <UILabel>(); UIEventListener listener = UIEventListener.Get(choice); uiLabel.text = choiceContext; // 文本 if (PachiGrimoire.I.MarkManager.MarkPlayerGet(mark)) { uiLabel.text = "(已选择) " + choiceContext; } if (canBeSelected) // 颜色 和 点击事件 { uiButton.hover = Color.white; uiButton.pressed = Color.white; listener.onPress += OnChoiceButtonPress; } else { uiButton.hover = uiButton.disabledColor; uiButton.pressed = uiButton.disabledColor; } } }