静态函数一个有用的设计模式

public class WardEntity : PositiveEntity
{

    public static WardEntity GetWard(Vec3 aPos, int aTeamID, LFixed aLifeTime)
        {
            WardEntity entity;
            entity = CreateEntity(aTeamID);

            entity.CanSelected = true;
            entity.LogicTrans.position = aPos;
            //entity.InitWardEntity(aPos);

            entity.TeamId = aTeamID;
            entity.ForceUpdateShowLvl = true;
            entity.mMaxLifeTime = aLifeTime;
            entity.LifeTime = aLifeTime;

            //entity.SetUpdate(true);
            entity.Start();
            EntityManager.Instance.Add(entity.EntityId, entity);

            return entity;
        }
}

好处是,在外部可以直接使用WardEntity.
GetWard(pos, id, life)来获取一个对象。直观,好用。
传统引擎的处理是这样的 var ward = EntityManager.GetWard(); ward.Init(pos, id, life),好好对比下这两个点

 

posted @ 2019-03-06 11:47  时空观察者9号  阅读(241)  评论(0编辑  收藏  举报