Fastest Type Comparison?

前端 未结 4 1972
礼貌的吻别
礼貌的吻别 2021-01-12 11:49

The following event can possibly get called hundreds of times a frame.

public bool OnCollision(Body body1, Body body2)
{
 if(body2.Tag is Dog)
      ((Dog)bo         


        
4条回答
  •  星月不相逢
    2021-01-12 12:34

    How about a generic collision method? Then there is no need for inheritance. Just an interface.

    public bool OnCollision(TA a, TB b)
        where TA : ICollidable
        where TB : ICollidable {
        a.Collision(b);
    }
    

提交回复
热议问题