/// <summary> /// 显示实体 /// </summary> /// <param name="entityId">实体编号</param> /// <param name="entityAssetName">实体资源名称</param> /// <param name="entityGroup">实体组</param> /// <param name="entityInstance">实体实例</param> /// <param name="isNewInstance">是否是新实例</param> /// <param name="duration">加载持续时间</param> /// <param name="userData">用户自定义数据</param> private void ShowEntity(int entityId, string entityAssetName, EntityGroup entityGroup, object entityInstance, bool isNewInstance, float duration, object userData) { try { //使用辅助器创建实体 Entity entity = m_EntityHelper.CreateEntity(entityInstance, entityGroup, userData); if (entity == null) { throw new Exception("使用辅助器创建实体失败"); } //创建实体信息对象 EntityInfo entityInfo = new EntityInfo(entity); m_EntityInfos.Add(entityId, entityInfo); entityInfo.Status = EntityStatus.WillInit; entity.OnInit(entityId, entityAssetName, entityGroup, isNewInstance, userData); entityInfo.Status = EntityStatus.Inited; entityGroup.AddEntity(entity); entityInfo.Status = EntityStatus.WillShow; entity.OnShow(userData); entityInfo.Status = EntityStatus.Showed; //派发显示实体成功事件 ShowEntitySuccessEventArgs se = new ShowEntitySuccessEventArgs(); m_EventManager.Fire(this, se.Fill(userData, entity, duration)); } catch (Exception exception) { //派发显示实体失败事件 ShowEntityFailureEventArgs fe = new ShowEntityFailureEventArgs(); m_EventManager.Fire(this, fe.Fill(userData, entityId, entityAssetName, entityGroup.Name, exception.Message)); } }
private void LoadEntityFailureCallback(string entityAssetName, LoadResourceStatus status, string errorMessage, object userData) { LoadEntityInfo loadEntityInfo = (LoadEntityInfo)userData; if (loadEntityInfo == null) { Debug.LogError("加载实体的信息为空"); return; } m_EntitiesBeingLoaded.Remove(loadEntityInfo.EntityId); m_EntitiesToReleaseOnLoad.Remove(loadEntityInfo.SerialId); string message = string.Format("加载实体:{0} 失败,错误信息:{1}", entityAssetName, errorMessage); //派发显示实体失败事件 ShowEntityFailureEventArgs e = ReferencePool.Acquire <ShowEntityFailureEventArgs>(); m_EventManager.Fire(this, e.Fill(loadEntityInfo.UserData, loadEntityInfo.EntityId, entityAssetName, loadEntityInfo.EntityGroup.Name, message)); }