예제 #1
0
        public PeEntity Create(int entityId, string path, Vector3 pos, Quaternion rot, Vector3 scl, bool isnpc = false)
        {
            if (entityId == IdGenerator.Invalid)
            {
                Debug.LogError("[CreateEntity]Failed to create entity : Invalid entity id " + entityId);
                return(null);
            }

            if (null != EntityMgr.Instance.Get(entityId))
            {
                Debug.LogError("[CreateEntity]Failed to create entity : Existed entity with id:" + entityId);
                return(null);
            }

            PeEntity entity = PeEntity.Create(path, pos, rot, scl);

            if (null == entity)
            {
                Debug.LogError("[CreateEntity]Failed to create entity!");
                return(null);
            }

            bool isPlayer = entity.GetComponent <MainPlayerCmpt>() != null;
            //NpcCmpt npccmpt = entity.GetComponent<NpcCmpt>();

            Transform root;

            if (entity.NpcCmpt == null || isPlayer)
            {
                root = EntityRoot;
            }
            else
            {
                root = npcEntityRoot;
            }

            entity.transform.parent = root;
            InitEntity(entityId, entity.gameObject);
            return(entity);
        }