private void LoadEntitySuccessCallback(string entityAssetName, object entityAsset, float duration, object userData) { Debug.Log(entityAssetName + " " + entityAsset); ShowEntityInfo showEntityInfo = (ShowEntityInfo)userData; if (showEntityInfo == null) { throw new LufyException("Show entity info is invalid."); } if (m_EntitiesToReleaseOnLoad.Contains(showEntityInfo.SerialId)) { m_EntitiesToReleaseOnLoad.Remove(showEntityInfo.SerialId); ReferencePool.Release(showEntityInfo); ReleaseEntity(entityAsset, null); return; } m_EntitiesBeingLoaded.Remove(showEntityInfo.EntityId); EntityInstanceObject entityInstanceObject = EntityInstanceObject.Create(entityAssetName, entityAsset, InstantiateEntity(entityAsset), m_ResourceManager); showEntityInfo.EntityGroup.RegisterEntityInstanceObject(entityInstanceObject, true); InternalShowEntity(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroup, entityInstanceObject.Target, true, duration, showEntityInfo.EntityLogicType, showEntityInfo.UserData); ReferencePool.Release(showEntityInfo); }
public static EntityInstanceObject Create(string name, object entityAsset, object entityInstance, IResManager resManager) { if (entityAsset == null) { throw new LufyException("Entity asset is invalid."); } EntityInstanceObject entityInstanceObject = ReferencePool.Acquire <EntityInstanceObject>(); entityInstanceObject.Initialize(name, entityInstance); entityInstanceObject.m_EntityAsset = entityAsset; entityInstanceObject.m_ResManager = resManager; return(entityInstanceObject); }
/// <summary> /// 显示实体。 /// </summary> /// <param name="entityId">实体编号。</param> /// <param name="entityAssetName">实体资源名称。</param> /// <param name="entityGroupName">实体组名称。</param> /// <param name="userData">用户自定义数据。</param> public void ShowEntity(int entityId, string entityAssetName, string entityGroupName, Type logicType, object userData) { if (m_ResourceManager == null) { throw new LufyException("You must set resource manager first."); } if (string.IsNullOrEmpty(entityAssetName)) { throw new LufyException("Entity asset name is invalid."); } if (string.IsNullOrEmpty(entityGroupName)) { throw new LufyException("Entity group name is invalid."); } if (HasEntity(entityId)) { throw new LufyException(Utility.Text.Format("Entity id '{0}' is already exist.", entityId.ToString())); } if (IsLoadingEntity(entityId)) { throw new LufyException(Utility.Text.Format("Entity '{0}' is already being loaded.", entityId.ToString())); } EntityGroup entityGroup = GetEntityGroup(entityGroupName); if (entityGroup == null) { throw new LufyException(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, m_LoadAssetCallbacks, ShowEntityInfo.Create(serialId, entityId, entityGroup, logicType, userData)); return; } InternalShowEntity(entityId, entityAssetName, entityGroup, entityInstanceObject.Target, false, 0f, logicType, userData); }
public void RegisterEntityInstanceObject(EntityInstanceObject obj, bool spawned) { m_InstancePool.Register(obj, spawned); }