/// <summary> /// 播放声音。 /// </summary> /// <param name="soundAssetName">声音资源名称。</param> /// <param name="playSoundParams">播放声音参数。</param> /// <returns>声音的序列编号。</returns> public int PlaySound(string soundAssetName, PlaySoundParams playSoundParams, bool isShort) { if (m_ResManager == null) { throw new LufyException("ResManager is invalid."); } if (playSoundParams != null) { if (isShort) { m_SoundSoundParams = playSoundParams; } else { m_MusicSoundParams = playSoundParams; } } AudioClip clip = null; m_AudioClips.TryGetValue(soundAssetName, out clip); if (clip == null) { m_ResManager.LoadAsset(soundAssetName, m_LoadAssetCallbacks, PlaySoundInfo.Create(playSoundParams, isShort)); } else { internalPlaySound(soundAssetName, clip, playSoundParams, isShort); } return(0); }
/// <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); }
/// <summary> /// 打开界面。 /// </summary> /// <param name="uiFormAssetName">界面资源名称。</param> /// <param name="userData">用户自定义数据。</param> /// <returns>界面的序列编号。</returns> public void OpenUIForm(string uiFormAssetName, object userData) { if (string.IsNullOrEmpty(uiFormAssetName)) { throw new LufyException("UI form asset name is invalid."); } if (m_ResManager == null) { throw new LufyException("ResManager is invalid."); } if (m_PoolManager == null) { throw new LufyException("ObjectPoolManager is invalid."); } UIFormLogic uiFormInstanceObject = null; m_cachedForms.TryGetValue(uiFormAssetName, out uiFormInstanceObject); if (uiFormInstanceObject == null) { UIFormObject obj = m_InstancePool.Spawn(uiFormAssetName); uiFormInstanceObject = obj?.Target as UIFormLogic; if (uiFormInstanceObject == null) { m_ResManager.LoadAsset(uiFormAssetName, m_LoadAssetCallbacks, userData); } else { m_cachedForms.Add(uiFormAssetName, uiFormInstanceObject); InternalOpenUIForm(uiFormAssetName, uiFormInstanceObject, 0, userData); } } else { m_formList.Remove(uiFormInstanceObject); InternalOpenUIForm(uiFormAssetName, uiFormInstanceObject, 0, userData); } }