public void HandleEvent(GameObject a, GameObject b) { if (a == b) { return; } if (_flags.ContainsValue(a) && _flags.ContainsValue(b)) { var pa = PraseFlag(a); var pb = PraseFlag(b); if (pa.index == pb.index && pa.dimension != pb.dimension) { MatrixTransform.Transpose(_cells, _layoutOrder); Step.GetComponent <StepView>().increase(); return; }//转置 else if (pa.position == pb.position && pa.index != pb.index) { MatrixTransform.Swap(_cells, _layoutOrder, pa.dimension, pa.index, pb.index); Step.GetComponent <StepView>().increase(); Result.GetComponent <BaseCellView>().Fraction *= -1; return; }//互换 } if (_cells.ContainsValue(a) && _cells.ContainsValue(b))//互换 { var pa = PraseCell(a); var pb = PraseCell(b); if (pa.col == pb.col && pa.row != pb.row) { MatrixTransform.Swap(_cells, _layoutOrder, Dimension.ROW, pa.row, pb.row); Step.GetComponent <StepView>().increase(); Result.GetComponent <BaseCellView>().Fraction *= -1; return; } else if (pa.col != pb.col && pa.row == pb.row) { MatrixTransform.Swap(_cells, _layoutOrder, Dimension.COL, pa.col, pb.col); Step.GetComponent <StepView>().increase(); Result.GetComponent <BaseCellView>().Fraction *= -1; return; } } else if (_flags.ContainsValue(a) && _cells.ContainsValue(b)) { var pa = PraseFlag(a); var pb = PraseCell(b); int targetIndex = (pa.dimension == Dimension.ROW ? pb.row : pb.col); if (pa.index != targetIndex) { MatrixTransform.AddIn(_cells, _layoutOrder, pa.dimension, pa.index, targetIndex); Step.GetComponent <StepView>().increase(); return; }//叠加 } else if (_nums.Contains(a) && _flags.ContainsValue(b)) { var pb = PraseFlag(b); Result.GetComponent <BaseCellView>().Fraction /= MatrixTransform.Multiply(_cells, _layoutOrder, pb.dimension, pb.index, a);//倍乘 Step.GetComponent <StepView>().increase(); return; } else if (_flags.ContainsValue(a) && _nums.Contains(b)) { var pa = PraseFlag(a); Result.GetComponent <BaseCellView>().Fraction /= MatrixTransform.Multiply(_cells, _layoutOrder, pa.dimension, pa.index, b);//倍乘 Step.GetComponent <StepView>().increase(); return; } else if (_cells.ContainsValue(a) && _flags.ContainsValue(b))//展开? { var pa = PraseCell(a); var pb = PraseFlag(b); //可以行展开 if (pb.dimension == Dimension.ROW) { int index = MatrixTransform.CanRowExpande(_cells, _layoutOrder, pb.index); if (index != -1) { Result.GetComponent <BaseCellView>().Fraction *= MatrixTransform.Cofactor(_cells, _flags, _layoutOrder, pa.row, index); Step.GetComponent <StepView>().increase(); Draw(_layoutOrder - 1, false); return; } } //可以列展开 else if (pb.dimension == Dimension.COL) { int index = MatrixTransform.CanColExpande(_cells, _layoutOrder, pb.index); if (index != -1) { Result.GetComponent <BaseCellView>().Fraction *= MatrixTransform.Cofactor(_cells, _flags, _layoutOrder, index, pa.col); Step.GetComponent <StepView>().increase(); Draw(_layoutOrder - 1, false); return; } } } }