//交换model private void ExchangeModel(ModelBase m1, ModelBase m2) { //Debug.Log(selectModel.ModelColorComponent.Color+" "+targetModel.ModelColorComponent.Color); if (m1.CanMove() && m2.CanMove()) { models[m1.X, m1.Y] = m2; models[m2.X, m2.Y] = m1; if (step == 0) { if (MatchModels(m2, m1.X, m1.Y) != null || MatchModels(m1, m2.X, m2.Y) != null || m1.Type == ModelType.RainBow || m2.Type == ModelType.RainBow) { int tempX = m1.X; int tempY = m1.Y; m1.ModelMoveComponent.Move(m2.X, m2.Y, fillTime);//交换 m2.ModelMoveComponent.Move(tempX, tempY, fillTime); if (m1.Type == ModelType.RainBow && m1.CanClear() && m2.CanClear()) { ModelColorClearByType mcct = m1.transform.GetComponent <ModelColorClearByType>(); //Debug.Log(mcct == null); if (mcct != null) { mcct.Color = m2.ModelColorComponent.Color; ClearByType(mcct.Color); } m1.ModelClearComponent.Clear(); models[m1.X, m1.Y] = CreatNewModel(m1.X, m1.Y, ModelType.Empty); ClearModel(m1.X, m1.Y); //StartCoroutine(FillAll(fillTime));//将消除后的空位进行填充 } if (m2.Type == ModelType.RainBow && m2.CanClear() && m1.CanClear()) { ModelColorClearByType mcct = m2.transform.GetComponent <ModelColorClearByType>(); //Debug.Log(mcct == null); if (mcct != null) { mcct.Color = m1.ModelColorComponent.Color; ClearByType(mcct.Color); } m2.ModelClearComponent.Clear(); models[m2.X, m2.Y] = CreatNewModel(m2.X, m2.Y, ModelType.Empty); ClearModel(m2.X, m2.Y); //StartCoroutine(FillAll(time));//将消除后的空位进行填充 } ClearAllMatchModels(); //清除所有匹配的model StartCoroutine(FillAll(fillTime)); //将消除后的空位进行填充 selectModel = null; targetModel = null; step = 0; curStep.text = "0"; } else { int tempX = m1.X; int tempY = m1.Y; m1.ModelMoveComponent.Move(m2.X, m2.Y, fillTime);//交换 m2.ModelMoveComponent.Move(tempX, tempY, fillTime); step++; targetModel = null; curStep.text = "1"; } } else { if (MatchModels(m2, m1.X, m1.Y) != null || MatchModels(m1, m2.X, m2.Y) != null || m1.Type == ModelType.RainBow || m2.Type == ModelType.RainBow) { int tempX = m1.X; int tempY = m1.Y; m1.ModelMoveComponent.Move(m2.X, m2.Y, fillTime);//交换 m2.ModelMoveComponent.Move(tempX, tempY, fillTime); if (m1.Type == ModelType.RainBow && m1.CanClear() && m2.CanClear()) { ModelColorClearByType mcct = m1.transform.GetComponent <ModelColorClearByType>(); //Debug.Log(mcct == null); if (mcct != null) { mcct.Color = m2.ModelColorComponent.Color; ClearByType(mcct.Color); } m1.ModelClearComponent.Clear(); models[m1.X, m1.Y] = CreatNewModel(m1.X, m1.Y, ModelType.Empty); ClearModel(m1.X, m1.Y); //StartCoroutine(FillAll(fillTime));//将消除后的空位进行填充 } if (m2.Type == ModelType.RainBow && m2.CanClear() && m1.CanClear()) { ModelColorClearByType mcct = m2.transform.GetComponent <ModelColorClearByType>(); //Debug.Log(mcct == null); if (mcct != null) { mcct.Color = m1.ModelColorComponent.Color; ClearByType(mcct.Color); } m2.ModelClearComponent.Clear(); models[m2.X, m2.Y] = CreatNewModel(m2.X, m2.Y, ModelType.Empty); ClearModel(m2.X, m2.Y); //StartCoroutine(FillAll(time));//将消除后的空位进行填充 } ClearAllMatchModels(); //清除所有匹配的model StartCoroutine(FillAll(fillTime)); //将消除后的空位进行填充 selectModel = null; targetModel = null; step = 0; curStep.text = "0"; } else { //还原基础脚本 models[m1.X, m1.Y] = m1; models[m2.X, m2.Y] = m2; models[m1.X, m1.Y].ModelMoveComponent.Undo(m1, m2, fillTime);//交换位置再还原 step = 1; curStep.text = "1"; } } } //StartCoroutine(FillAll(fillTime));//将消除后的空位进行填充 }