Fastest Type Comparison?

前端 未结 4 1967
礼貌的吻别
礼貌的吻别 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:46

    Would an approach like this be feasible or useful?

    public interface ICollidable
    {
        void OnCollision();
    }
    
    public abstract class Body : ICollidable
    {
        public abstract void OnCollision();
    }
    
    public class Dog : Body
    {
        public override void OnCollision();
        {
            Bark();
        }
    }
    
    public Boolean OnCollision(ICollidable a, ICollidable b)
    {
        b.OnCollision();
    }
    

提交回复
热议问题