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.EntityId))
            {
                Log.Debug("Release entity '{0}' on loading success.", showEntityInfo.EntityId.ToString());
                m_EntitiesToReleaseOnLoad.Remove(showEntityInfo.EntityId);
                m_EntityHelper.ReleaseEntity(entityAsset, null);
                return;
            }

            EntityGroup entityGroup = (EntityGroup)GetEntityGroup(showEntityInfo.EntityGroupName);

            if (entityGroup == null)
            {
                throw new GameFrameworkException(string.Format("Entity group '{0}' is not exist.", showEntityInfo.EntityGroupName));
            }

            EntityInstanceObject entityInstanceObject = new EntityInstanceObject(entityAssetName, entityAsset, m_EntityHelper.InstantiateEntity(entityAsset), m_EntityHelper);

            entityGroup.RegisterEntityInstanceObject(entityInstanceObject, true);

            InternalShowEntity(showEntityInfo.EntityId, entityAssetName, showEntityInfo.EntityGroupName, entityInstanceObject.Target, true, duration, showEntityInfo.UserData);
        }
Exemple #2
0
        private void LoadAssetSuccessCallback(string entityAssetName, object entityAsset, float duration, object userData)
        {
            ShowEntityInfo showEntityInfo = (ShowEntityInfo)userData;

            if (showEntityInfo == null)
            {
                throw new GameFrameworkException("Show entity info is invalid.");
            }

            if (m_EntitiesToReleaseOnLoad.Contains(showEntityInfo.SerialId))
            {
                m_EntitiesToReleaseOnLoad.Remove(showEntityInfo.SerialId);
                ReferencePool.Release(showEntityInfo);
                m_EntityHelper.ReleaseEntity(entityAsset, null);
                return;
            }

            m_EntitiesBeingLoaded.Remove(showEntityInfo.EntityId);
            EntityInstanceObject entityInstanceObject = EntityInstanceObject.Create(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);
            ReferencePool.Release(showEntityInfo);
        }
Exemple #3
0
        /// <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);
        }
        /// <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, object userData)
        {
            if (m_ResourceManager == null)
            {
                throw new System.Exception("You must set resource manager first.");
            }

            if (m_EntityHelper == null)
            {
                throw new System.Exception("You must set entity helper first.");
            }

            if (string.IsNullOrEmpty(entityAssetName))
            {
                throw new System.Exception("Entity asset name is invalid.");
            }

            if (string.IsNullOrEmpty(entityGroupName))
            {
                throw new System.Exception("Entity group name is invalid.");
            }

            if (m_EntityInfos.ContainsKey(entityId))
            {
                throw new System.Exception(string.Format("Entity id '{0}' is already exist.", entityId.ToString()));
            }

            EntityGroup entityGroup = (EntityGroup)GetEntityGroup(entityGroupName);

            if (entityGroup == null)
            {
                throw new System.Exception(string.Format("Entity group '{0}' is not exist.", entityGroupName));
            }

            EntityInstanceObject entityInstanceObject = entityGroup.SpawnEntityInstanceObject(entityAssetName);

            if (entityInstanceObject == null)
            {
                if (m_EntitiesBeingLoaded.Contains(entityId))
                {
                    throw new System.Exception(string.Format("Entity '{0}' is already being loaded.", entityId.ToString()));
                }

                m_EntitiesBeingLoaded.Add(entityId);
                m_ResourceManager.LoadAsset(entityAssetName, m_LoadAssetCallbacks, new ShowEntityInfo(entityId, entityGroup, userData));
                return;
            }

            InternalShowEntity(entityId, entityAssetName, entityGroup, entityInstanceObject.Target, false, 0f, userData);
        }
            public static EntityInstanceObject Create(string name, object entityAsset, object entityInstance, IEntityHelper entityHelper)
            {
                if (entityAsset == null)
                {
                    throw new GameFrameworkException("Entity asset is invalid.");
                }

                if (entityHelper == null)
                {
                    throw new GameFrameworkException("Entity helper is invalid.");
                }

                EntityInstanceObject entityInstanceObject = ReferencePool.Acquire <EntityInstanceObject>();

                entityInstanceObject.Initialize(name, entityInstance);
                entityInstanceObject.m_EntityAsset  = entityAsset;
                entityInstanceObject.m_EntityHelper = entityHelper;
                return(entityInstanceObject);
            }
Exemple #6
0
        private void LoadEntitySuccessCallback(string entityAssetName, object entityAsset)
        {
            ShowEntityInfo showEntityInfo = (ShowEntityInfo)userData;

            m_EntitiesBeingLoaded.Remove(showEntityInfo.EntityId);
            if (m_EntitiesToReleaseOnLoad.Contains(showEntityInfo.EntityId))
            {
                Log.Debug();
                m_EntitiesToReleaseOnLoad.Remove(showEntityInfo.EntityId);
                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);
        }
Exemple #7
0
        public void ShowEntity(int entityId, string entityAssetName, string entityGroupName, object userData)
        {
            if (m_EntityInfos.ContainsKey(entityId))
            {
                throw;
            }

            EntityGroup          entityGroup          = (EntityGroup)GetAllEntityGroups(entityGroupName);
            EntityInstanceObject entityInstanceObject = entityGroup.SpawnEntityInstanceObject(entityAssetName);

            if (entityInstanceObject == null)
            {
                if (m_EntitiesBeingLoaded.Contains(entityId))
                {
                    throw;
                }

                m_EntitesBeingLoaded.Add(entityId);
                m_ResourceManager.LoadAsset(entityAssetName, m_LoadAssetCallbacks, new ShowEntityInfo(entityId, entityGroup, userData));
                return;
            }

            InternalShowEntity(entityId, entityAssetName, entityGroup, entityInstanceObject.Target);
        }
 public void RegisterEntityInstanceObject(EntityInstanceObject obj, bool spawned)
 {
     m_InstancePool.Register(obj, spawned);
 }