//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 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); } } }