private void LoadEntitySuccessCallback(string entityAssetName, object entityAsset, float duration, object userData) { ShowEntityInfo showEntityInfo = (ShowEntityInfo)userData; if (showEntityInfo == null) { throw new GameFrameworkException("Show entity info is invalid."); } m_EntitiesBeingLoaded.Remove(showEntityInfo.EntityId); if (m_EntitiesToReleaseOnLoad.Contains(showEntityInfo.SerialId)) { GameFrameworkLog.Debug("Release entity '{0}' (serial id '{1}') on loading success.", showEntityInfo.EntityId.ToString(), showEntityInfo.SerialId.ToString()); m_EntitiesToReleaseOnLoad.Remove(showEntityInfo.SerialId); m_EntityHelper.ReleaseEntity(entityAsset, null); return; } EntityInstanceObject entityInstanceObject = new EntityInstanceObject(entityAssetName, entityAsset, m_EntityHelper.InstantiateEntity(entityAsset), m_EntityHelper); showEntityInfo.EntityGroup.RegisterEntityInstanceObject(entityInstanceObject, true); InternalShowEntity(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroup, entityInstanceObject.Target, true, duration, showEntityInfo.UserData); }
/// <summary> /// Show entities. /// </summary> /// <param name="entityId"> entity number. </param> /// <param name="entityAssetName"> entity resource name. </param> /// <param name="entityGroupName"> entity group name. </param> /// <param name="priority"> The priority of the loaded entity resource. </param> /// <param name="userData"> User-defined data. </param> public void ShowEntity(int entityId, string entityAssetName, string entityGroupName, int priority, object userData) { if (m_ResourceManager == null) { throw new GameFrameworkException("You must set resource manager first."); } if (m_EntityHelper == null) { throw new GameFrameworkException("You must set entity helper first."); } if (string.IsNullOrEmpty(entityAssetName)) { throw new GameFrameworkException("Entity asset name is invalid."); } if (string.IsNullOrEmpty(entityGroupName)) { throw new GameFrameworkException("Entity group name is invalid."); } if (HasEntity(entityId)) { throw new GameFrameworkException(Utility.Text.Format("Entity id '{0}' is already exist.", entityId.ToString())); } if (IsLoadingEntity(entityId)) { throw new GameFrameworkException(Utility.Text.Format("Entity '{0}' is already being loaded.", entityId.ToString())); } EntityGroup entityGroup = (EntityGroup)GetEntityGroup(entityGroupName); if (entityGroup == null) { throw new GameFrameworkException(Utility.Text.Format("Entity group '{0}' is not exist.", entityGroupName)); } EntityInstanceObject entityInstanceObject = entityGroup.SpawnEntityInstanceObject(entityAssetName); if (entityInstanceObject == null) { int serialId = ++m_Serial; m_EntitiesBeingLoaded.Add(entityId, serialId); m_ResourceManager.LoadAsset(entityAssetName, priority, m_LoadAssetCallbacks, ShowEntityInfo.Create(serialId, entityId, entityGroup, userData)); return; } InternalShowEntity(entityId, entityAssetName, entityGroup, entityInstanceObject.Target, false, 0f, userData); }