示例#1
0
        /// <summary>
        /// 创建实体
        /// </summary>
        /// <param name="sceneid"></param>
        /// <param name="uid"></param>
        /// <param name="proxyId"></param>
        /// <param name="res">预设体AddressableKey</param>
        /// <param name="bornPos">出生位置</param>
        /// <param name="orientation">方向</param>
        /// <param name="scale">缩放</param>
        /// <param name="entityType">实体类型</param>
        /// <param name="onBodyCreated">实体的组件</param>
        /// <returns></returns>
        public static EntityBehavior CreateEntity(int sceneid, int aoiId, int resId, Vector3 bornPos, float orientation, int entityType, Action <LuaTable> onBodyCreated = null)
        {
            if (entityBehaviors.ContainsKey(aoiId))
            {
                Debug.LogError("CreateEntity error exist uid=" + aoiId);
                return(null);
            }

            EntityBehavior entity = entitiesPool.Alloc();

            if (entity == null)
            {
                Debug.LogError("entity is nil");
            }

            // 设置父物体
            GameObject parent = entity.gameObject;

            if (!parent.activeSelf)
            {
                parent.SetActive(true);
            }
            parent.transform.localScale = Vector3.one;
            parent.transform.SetParent(entityContainer.transform, false);
            parent.transform.position = bornPos;
            parent.transform.rotation = Quaternion.Euler(0, orientation, 0);

            entity.Init(sceneid, aoiId, resId, entityType, onBodyCreated);
            // 把实体放到容器中
            entityBehaviors.Add(aoiId, entity);
            entityBehaviorsQueue.AddFirst(entity);

            return(entity);
        }