private void OnTriggerExit2D(Collider2D collision) { if (collision.gameObject.tag == "ReactionCondition") { rctCondition = ReactionCondition.normal; } }
private void OnTriggerStay2D(Collider2D collision) { if (collision.gameObject.tag == "ReactionCondition") { rctCondition = collision.gameObject.GetComponent <ReactionConditionEntity>().Condition; } }
/// <summary> /// 检测方程式成立接口 /// </summary> /// <param name="input">反应物List</param> /// <param name="condition">反应条件</param> /// <param name="output">接收生成物List</param> /// <param name="index">序号</param> /// <returns>若存在这样的反应,返回true</returns> public bool CheckReaction(List <ChemistyMatter> input, ReactionCondition condition, out List <ChemistyMatter> output, out int index) { output = new List <ChemistyMatter>(); ChemicalEqu equ = new ChemicalEqu(); int i; for (i = 0; i < cmtEqu.Count; i++) { if (InputEqual(cmtEqu[i].input, input) && cmtEqu[i].conditon == condition) { equ = cmtEqu[i]; break; } } index = 0; if (i == cmtEqu.Count) { //Debug.Log("CNM"); return(false); } output = new List <ChemistyMatter>(equ.output); index = i; //Debug.Log("CCCCC"); return(true); }
private bool isAbnormalReacting; //是否正在反应 private void Start() { //初始化,获得各种组件 rctMng = reactionManager.GetComponent <ReactionManager>(); mctMng = createManager.GetComponent <MatterCreateManager>(); nowWaitFrame = waitFrame; //ui = equUI.GetComponent<ReactionEquUI>(); thisMatter = this.GetComponent <MatterName>(); thisCondition_old = thisMatter.rctCondition; //activeEquIndex = null; //includeEqu = null; //includeObj = null; objList = new List <GameObject>(); objMatterList = new List <MatterName>(); objMatterList_old = new List <ReactionCondition>(); cmtEqus = new List <ChemicalEqu>(); abnormalChecked = false; }
private bool abnormalChecked; //非normal状态时是否检查过,提高效率 private void Start() { sprite = gameObject.transform.GetChild(2).gameObject; //初始化,获得各种组件 equUI = GameObject.Find("UI/ReactionEquUI").gameObject; rctMng = reactionManager.GetComponent <ReactionManager>(); mctMng = createManager.GetComponent <MatterCreateManager>(); ui = equUI.GetComponent <ReactionEquUI>(); thisMatter = this.GetComponent <MatterName>(); thisCondition_old = thisMatter.rctCondition; activeEquIndex = null; //includeEqu = null; //includeObj = null; objList = new List <GameObject>(); objMatterList = new List <MatterName>(); objMatterList_old = new List <ReactionCondition>(); cmtEqus = new List <ChemicalEqu>(); abnormalChecked = true; //nowWaitFrame = waitFrame; }
//private void OnTriggerExit2D(Collider2D collision) //{ // if (collision.gameObject.tag == "Matter") // { // //获取OBJ所在的序号 // int objIndex = objList.LastIndexOf(collision.gameObject); // MatterName mn = collision.gameObject.GetComponent<MatterName>(); // //删除列表中的该OBJ要素 // objMatterList_old.RemoveAt(objIndex); // objMatterList.RemoveAt(objIndex); // objList.RemoveAt(objIndex); // //删除所有该OBJ参与的反应 // cmtEqus.RemoveAll(x => x.input.Count >= 2 && x.input[1].name == mn.matterName); // } //} ///// <summary> ///// 材质比较函数 ///// </summary> //private bool MatterEqu(MatterName a, MatterName b) //{ // if (a.matterName == b.matterName && a.matterState == b.matterState && a.rctCondition == b.rctCondition) // return true; // return false; //} private void Update() { //遍历材质,找到变化的材质 for (int i = 0; i < objList.Count; i++) { if (objMatterList[i].rctCondition != objMatterList_old[i]) { //若之前有,删除,重新检查 cmtEqus.RemoveAll(x => x.input.Exists(m => m.name == objMatterList[i].matterName)); MatterCheck(objMatterList[i]); //更新对应oldlist objMatterList_old[i] = objMatterList[i].rctCondition; } } //检查状态是否变化 if (thisCondition_old != thisMatter.rctCondition) { nowWaitFrame = waitFrame; //刷新计时 thisCondition_old = thisMatter.rctCondition; //更新旧的 cmtEqus.RemoveAll(x => x.input.Count == 1); //删除自分解反应 abnormalChecked = false; } //自身状态变化重新检测 if (abnormalChecked == false) { //清空 cmtEqus.Clear(); //重新检查 for (int i = 0; i < objList.Count; i++) { MatterCheck(objMatterList[i]); } } //检查针对自身的分解反应 if (thisMatter.rctCondition != ReactionCondition.normal && abnormalChecked == false) { //activeEquIndex = 0; abnormalChecked = true; List <ChemistyMatter> input = new List <ChemistyMatter> //用于存储自己 { new ChemistyMatter { name = thisMatter.matterName, state = thisMatter.matterState }, }; List <ChemistyMatter> output; //用于接受返回的生成物 //匹配成功,更新反应列表 if (rctMng.CheckReaction(input, thisMatter.rctCondition, out output)) { ChemicalEqu equ = new ChemicalEqu { input = input, conditon = thisMatter.rctCondition, output = output }; //更新 cmtEqus.Add(equ); //ui.AddEqu(equ, this.transform); } } //不为normal状态且有反应可发生,证明应有计时 if (thisMatter.rctCondition != ReactionCondition.normal && cmtEqus.Count > 0) { //时间到,反应 if (nowWaitFrame <= 0) { MakeReaction(); } //计时 else { nowWaitFrame--; } } }
private void Start() { rctCondition = ReactionCondition.normal; //dyeingColor = DyeingColor.Normal; }
//private void OnTriggerEnter2D(Collider2D collision) //{ // //加入碰撞列表,将材质加入列表 // if (collision.gameObject.tag == "Matter") // { // objList.Add(collision.gameObject); // MatterName mn = collision.gameObject.GetComponent<MatterName>(); // objMatterList.Add(mn); // objMatterList_old.Add(mn.rctCondition); // MatterCheck(mn); // } //} //private void OnTriggerExit2D(Collider2D collision) //{ // if (collision.gameObject.tag == "Matter") // { // //获取OBJ所在的序号 // int objIndex = objList.LastIndexOf(collision.gameObject); // Debug.Log(objIndex); // MatterName mn = collision.gameObject.GetComponent<MatterName>(); // //删除列表中的该OBJ要素 // objMatterList_old.RemoveAt(objIndex); // objMatterList.RemoveAt(objIndex); // objList.RemoveAt(objIndex); // //删除所有该OBJ参与的反应 // cmtEqus.RemoveAll(x => x.input.Count >= 2 && x.input[1].name == mn.matterName); // activeEquIndex = 0; // } //} ///// <summary> ///// 材质比较函数 ///// </summary> //private bool MatterEqu(MatterName a, MatterName b) //{ // if (a.matterName == b.matterName && a.matterState == b.matterState && a.rctCondition == b.rctCondition) // return true; // return false; //} private void Update() { //遍历材质,找到变化的材质 for (int i = 0; i < objList.Count; i++) { if (objMatterList[i].rctCondition != objMatterList_old[i]) { //若之前有,删除,重新检查 cmtEqus.RemoveAll(x => x.input.Exists(m => m.name == objMatterList[i].matterName)); MatterCheck(objMatterList[i]); //更新对应oldlist objMatterList_old[i] = objMatterList[i].rctCondition; } } //检查状态是否变化 if (thisCondition_old != thisMatter.rctCondition) { thisCondition_old = thisMatter.rctCondition; cmtEqus.RemoveAll(x => x.input.Count == 1); //nowWaitFrame = waitFrame; abnormalChecked = false; } //自身状态变化重新检测 if (abnormalChecked == false) { //清空 cmtEqus.Clear(); //重新检查 for (int i = 0; i < objList.Count; i++) { MatterCheck(objMatterList[i]); } } //检查针对自身的分解反应 if (thisMatter.rctCondition != ReactionCondition.normal && abnormalChecked == false) { activeEquIndex = 0; //Debug.Log("wtf"); abnormalChecked = true; List <ChemistyMatter> input = new List <ChemistyMatter> //用于存储自己 { new ChemistyMatter { name = thisMatter.matterName, state = thisMatter.matterState }, }; List <ChemistyMatter> output; //用于接受返回的生成物 //匹配成功,更新反应列表 int index; if (rctMng.CheckReaction(input, thisMatter.rctCondition, out output, out index)) { //Debug.Log("OOOOKKKK"); ChemicalEqu equ = new ChemicalEqu { input = input, conditon = thisMatter.rctCondition, output = output }; //更新 cmtEqus.Add(equ); //if (thisMatter.rctCondition == ReactionCondition.condense || // (thisMatter.rctCondition == ReactionCondition.heat && input.Count == 1 && output.Count == 1)) //{ // activeEquIndex = cmtEqus.FindIndex(x => ReactionManager.InputEqual(x.input, equ.input) && x.conditon == equ.conditon); // MakeReaction(0); // return; //} if (thisMatter.rctCondition == ReactionCondition.condense || thisMatter.rctCondition == ReactionCondition.evaporation) { activeEquIndex = cmtEqus.Count - 1; MakeReaction(0); } else { ui.AddEqu(index, this.transform); } } } //切换使用的反应方程式 abnormalChecked = true; if (cmtEqus.Count == 0) { activeEquIndex = null; ui.ClosePrintOutEqu(); } ////切换方程式 //if (Input.GetKeyDown(changeEquKey) && activeEquIndex != null) //{ // activeEquIndex = (activeEquIndex + 1) > (cmtEqus.Count - 1) ? 0 : (activeEquIndex + 1); // ui.AddEqu(cmtEqus[activeEquIndex.Value], this.transform); //} if (activeEquIndex != null) { if (Choose1) { Choose1 = false; ui.ClosePrintOutEqu(); MakeReaction(0); } else if (Choose2) { Choose2 = false; ui.ClosePrintOutEqu(); MakeReaction(1); } else if (Choose3) { Choose3 = false; ui.ClosePrintOutEqu(); MakeReaction(2); } } }