示例#1
0
        private static async void CreateBody(EntityBehavior entity)
        {
            entity.bodyLoading = true;
            int         uid    = entity.AoiId;
            ModelConfig config = ModelConfigAsset.Get(entity.ResId);

            if (config == null)
            {
                return;
            }
            var obj = await ResourceManager.LoadPrefabFromePool(config.Resource);

            if (!obj)
            {
                return;
            }
            if (entity == null || uid != entity.AoiId || entity.bodyLoading == false)
            {
                ResourceManager.RecyclePrefab(obj);
                return;
            }

            EntityBehavior p = GetEntity(entity.AoiId);

            if (p != null && p != entity)
            {
                Debug.LogError("这个错误可以无视 保留查看而已 entity create error");
                ResourceManager.RecyclePrefab(obj);
                return;
            }

            GameObject go = obj as GameObject;

            if (p != null)
            {
                go.SetActive(true);
                go.name = "@Body_Entity@";
                p.Body  = go;
                go.transform.SetParent(p.transform, false);
                go.transform.localPosition = Vector3.zero;
                go.transform.localRotation = Quaternion.identity;
                LayerMask defaultLayer = go.layer;

                p.InitComp(true);
                entity.bodyLoading = false;
            }
            else
            {
                ResourceManager.RecyclePrefab(go);                 // 只回收Body
                entity.bodyLoading = false;
            }
        }