Exemplo n.º 1
0
        private void LoadUIFormSuccessCallback(string uiFormAssetName, object uiFormAsset, float duration, object userData)
        {
            OpenUIFormInfo openUIFormInfo = (OpenUIFormInfo)userData;

            if (openUIFormInfo == null)
            {
                throw new GameFrameworkException("Open UI form info is invalid.");
            }

            m_UIFormsBeingLoaded.Remove(openUIFormInfo.SerialId);
            m_UIFormAssetNamesBeingLoaded.Remove(uiFormAssetName);
            if (m_UIFormsToReleaseOnLoad.Contains(openUIFormInfo.SerialId))
            {
                GameFrameworkLog.Debug("Release UI form '{0}' on loading success.", openUIFormInfo.SerialId.ToString());
                m_UIFormsToReleaseOnLoad.Remove(openUIFormInfo.SerialId);
                m_UIFormHelper.ReleaseUIForm(uiFormAsset, null);
                return;
            }

            UIFormInstanceObject uiFormInstanceObject = new UIFormInstanceObject(uiFormAssetName, uiFormAsset, m_UIFormHelper.InstantiateUIForm(uiFormAsset), m_UIFormHelper);

            m_InstancePool.Register(uiFormInstanceObject, true);

            InternalOpenUIForm(openUIFormInfo.SerialId, uiFormAssetName, openUIFormInfo.UIGroup, uiFormInstanceObject.Target, openUIFormInfo.PauseCoveredUIForm, true, duration, openUIFormInfo.UserData);
        }
            private bool LoadDependencyAsset(string assetName, int priority, LoadResourceTaskBase mainTask, object userData)
            {
                if (mainTask == null)
                {
                    throw new GameFrameworkException("Main task is invalid.");
                }

                ResourceInfo?resourceInfo = null;

                string[] dependencyAssetNames = null;

                if (!CheckAsset(assetName, out resourceInfo, out dependencyAssetNames))
                {
                    GameFrameworkLog.Debug("Can not load asset '{0}'.", assetName);
                    return(false);
                }

                LoadDependencyAssetTask dependencyTask = new LoadDependencyAssetTask(assetName, priority, resourceInfo.Value, dependencyAssetNames, mainTask, userData);

                foreach (string dependencyAssetName in dependencyAssetNames)
                {
                    if (!LoadDependencyAsset(dependencyAssetName, priority, dependencyTask, userData))
                    {
                        GameFrameworkLog.Debug("Can not load dependency asset '{0}' when load dependency asset '{1}'.", dependencyAssetName, assetName);
                        return(false);
                    }
                }

                m_TaskPool.AddTask(dependencyTask);
                return(true);
            }
            /// <summary>
            /// 释放对象池中的可释放对象。
            /// </summary>
            /// <param name="toReleaseCount">尝试释放对象数量。</param>
            /// <param name="releaseObjectFilterCallback">释放对象筛选函数。</param>
            public void Release(int toReleaseCount, ReleaseObjectFilterCallback <T> releaseObjectFilterCallback)
            {
                if (releaseObjectFilterCallback == null)
                {
                    throw new GameFrameworkException("Release object filter callback is invalid.");
                }

                m_AutoReleaseTime = 0f;
                if (toReleaseCount < 0)
                {
                    toReleaseCount = 0;
                }

                DateTime expireTime = DateTime.MinValue;

                if (m_ExpireTime < float.MaxValue)
                {
                    expireTime = DateTime.Now.AddSeconds(-m_ExpireTime);
                }

                GetCanReleaseObjects(m_CachedCanReleaseObjects);
                List <T> toReleaseObjects = releaseObjectFilterCallback(m_CachedCanReleaseObjects, toReleaseCount, expireTime);

                if (toReleaseObjects == null || toReleaseObjects.Count <= 0)
                {
                    return;
                }

                foreach (ObjectBase toReleaseObject in toReleaseObjects)
                {
                    if (toReleaseObject == null)
                    {
                        throw new GameFrameworkException("Can not release null object.");
                    }

                    bool found = false;
                    foreach (Object <T> obj in m_Objects)
                    {
                        if (obj.Peek() != toReleaseObject)
                        {
                            continue;
                        }

                        m_Objects.Remove(obj);
                        obj.Release(false);
                        GameFrameworkLog.Debug("Object pool '{0}' release '{1}'.", Utility.Text.GetFullName <T>(Name), toReleaseObject.Name);
                        found = true;
                        break;
                    }

                    if (!found)
                    {
                        throw new GameFrameworkException("Can not release object which is not found.");
                    }
                }
            }
Exemplo n.º 4
0
    /// <summary>
    /// 请求成功后返回的数据
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void OnWebRequestSuccess(object sender, GameEventArgs e)
    {
        WebRequestSuccessEventArgs ne = (WebRequestSuccessEventArgs)e;
        // 获取回应的数据
        string responseJson = Utility.Converter.GetString(ne.GetWebResponseBytes());

        GameFrameworkLog.Debug("responseJson:" + responseJson);

        EnterMain();
    }
Exemplo n.º 5
0
    protected override void OnEnter(ProcedureOwner procedureOwner)
    {
        base.OnEnter(procedureOwner);

        GameFrameworkLog.Info("开始");
        //跳转场景
        GameEntry.Scene.LoadScene("Assets/Scenes/Loading.unity", this);
        // 切换流程
        ChangeState <ProcedureLoading>(procedureOwner);
    }
            internal override void Update(float elapseSeconds, float realElapseSeconds)
            {
                m_AutoReleaseTime += realElapseSeconds;
                if (m_AutoReleaseTime < m_AutoReleaseInterval)
                {
                    return;
                }

                GameFrameworkLog.Debug("Object pool '{0}' auto release start.", Utility.Text.GetFullName <T>(Name));
                Release();
                GameFrameworkLog.Debug("Object pool '{0}' auto release complete.", Utility.Text.GetFullName <T>(Name));
            }
            /// <summary>
            /// 创建对象。
            /// </summary>
            /// <param name="obj">对象。</param>
            /// <param name="spawned">对象是否已被获取。</param>
            public void Register(T obj, bool spawned)
            {
                if (obj == null)
                {
                    throw new GameFrameworkException("Object is invalid.");
                }

                GameFrameworkLog.Debug(spawned ? "Object pool '{0}' create and spawned '{1}'." : "Object pool '{0}' create '{1}'.", Utility.Text.GetFullName <T>(Name), obj.Name);
                m_Objects.AddLast(new Object <T>(obj, spawned));

                Release();
            }
            internal override void Shutdown()
            {
                LinkedListNode <Object <T> > current = m_Objects.First;

                while (current != null)
                {
                    LinkedListNode <Object <T> > next = current.Next;
                    m_Objects.Remove(current);
                    current.Value.Release(true);
                    GameFrameworkLog.Debug("Object pool '{0}' release '{1}'.", Utility.Text.GetFullName <T>(Name), current.Value.Name);
                    current = next;
                }
            }
Exemplo n.º 9
0
 private void OnLidarHitEvent(GameObject arg1, Vector3 arg2)
 {
     if (arg1 == m_ZiMogu.gameObject)
     {
         m_ZiMogu.sprite  = m_ZiMoguVariant;
         m_IsStepOnZiMogu = true;
         GameFrameworkLog.Debug("<color=lime>变色触发</color>");
     }
     else if (arg1 == m_HongMogu.gameObject)
     {
         m_HongMogu.sprite  = m_HongMoguVariant;
         m_IsStepOnHongMogu = true;
     }
 }
Exemplo n.º 10
0
        protected override void OnUpdate(float elapseSeconds, float realElapseSeconds)
        {
            base.OnUpdate(elapseSeconds, realElapseSeconds);

            if (m_IsStepOnZiMogu && m_ZiMogu.sprite.name.Equals(m_ZiMoguVariant.name))
            {
                m_ZiMogu.sprite  = m_ZiMoguNormal;
                m_IsStepOnZiMogu = false;
                GameFrameworkLog.Debug("<color=cyan>变色触发</color>");
            }
            else if (m_IsStepOnHongMogu && m_HongMogu.sprite.name.Equals(m_HongMoguVariant.name))
            {
                m_HongMogu.sprite  = m_HongMoguNormal;
                m_IsStepOnHongMogu = false;
            }
        }
            /// <summary>
            /// 获取对象。
            /// </summary>
            /// <param name="name">对象名称。</param>
            /// <returns>要获取的对象。</returns>
            public T Spawn(string name)
            {
                foreach (Object <T> obj in m_Objects)
                {
                    if (obj.Name != name)
                    {
                        continue;
                    }

                    if (m_AllowMultiSpawn || !obj.IsInUse)
                    {
                        GameFrameworkLog.Debug("Object pool '{0}' spawn '{1}'.", Utility.Text.GetFullName <T>(Name), obj.Peek().Name);
                        return(obj.Spawn());
                    }
                }

                return(null);
            }
Exemplo n.º 12
0
            /// <summary>
            /// 设置对象是否被加锁。
            /// </summary>
            /// <param name="target">要设置被加锁的对象。</param>
            /// <param name="locked">是否被加锁。</param>
            public void SetLocked(object target, bool locked)
            {
                if (target == null)
                {
                    throw new GameFrameworkException("Target is invalid.");
                }

                Object <T> obj = GetObject(target);

                if (obj != null)
                {
                    GameFrameworkLog.Debug("Object pool '{0}' set locked '{1}' to '{2}.", Utility.Text.GetFullName <T>(Name), obj.Peek().Name, locked.ToString());
                    obj.Locked = locked;
                }
                else
                {
                    throw new GameFrameworkException(Utility.Text.Format("Can not find target in object pool '{0}'.", Utility.Text.GetFullName <T>(Name)));
                }
            }
            /// <summary>
            /// 释放对象池中的所有未使用对象。
            /// </summary>
            public override void ReleaseAllUnused()
            {
                LinkedListNode <Object <T> > current = m_Objects.First;

                while (current != null)
                {
                    if (current.Value.IsInUse || current.Value.Locked || !current.Value.CustomCanReleaseFlag)
                    {
                        current = current.Next;
                        continue;
                    }

                    LinkedListNode <Object <T> > next = current.Next;
                    m_Objects.Remove(current);
                    current.Value.Release(false);
                    GameFrameworkLog.Debug("Object pool '{0}' release '{1}'.", Utility.Text.GetFullName <T>(Name), current.Value.Name);
                    current = next;
                }
            }
            /// <summary>
            /// 设置对象的优先级。
            /// </summary>
            /// <param name="target">要设置优先级的对象。</param>
            /// <param name="priority">优先级。</param>
            public void SetPriority(object target, int priority)
            {
                if (target == null)
                {
                    throw new GameFrameworkException("Target is invalid.");
                }

                foreach (Object <T> obj in m_Objects)
                {
                    if (obj.Peek().Target == target)
                    {
                        GameFrameworkLog.Debug("Object pool '{0}' set priority '{1}' to '{2}.", Utility.Text.GetFullName <T>(Name), obj.Peek().Name, priority.ToString());
                        obj.Priority = priority;
                        return;
                    }
                }

                throw new GameFrameworkException(Utility.Text.Format("Can not find target in object pool '{0}'.", Utility.Text.GetFullName <T>(Name)));
            }
Exemplo n.º 15
0
        private void LoadSoundSuccessCallback(string soundAssetName, object soundAsset, float duration, object userData)
        {
            PlaySoundInfo playSoundInfo = (PlaySoundInfo)userData;

            if (playSoundInfo == null)
            {
                throw new GameFrameworkException("Play sound info is invalid.");
            }

            m_SoundsBeingLoaded.Remove(playSoundInfo.SerialId);
            if (m_SoundsToReleaseOnLoad.Contains(playSoundInfo.SerialId))
            {
                GameFrameworkLog.Debug("Release sound '{0}' on loading success.", playSoundInfo.SerialId.ToString());
                m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId);
                m_SoundHelper.ReleaseSoundAsset(soundAsset);
                return;
            }

            PlaySoundErrorCode?errorCode  = null;
            ISoundAgent        soundAgent = playSoundInfo.SoundGroup.PlaySound(playSoundInfo.SerialId, soundAsset, playSoundInfo.PlaySoundParams, out errorCode);

            if (soundAgent != null)
            {
                if (m_PlaySoundSuccessEventHandler != null)
                {
                    m_PlaySoundSuccessEventHandler(this, new PlaySoundSuccessEventArgs(playSoundInfo.SerialId, soundAssetName, soundAgent, duration, playSoundInfo.UserData));
                }
            }
            else
            {
                m_SoundsToReleaseOnLoad.Remove(playSoundInfo.SerialId);
                m_SoundHelper.ReleaseSoundAsset(soundAsset);
                string errorMessage = Utility.Text.Format("Sound group '{0}' play sound '{1}' failure.", playSoundInfo.SoundGroup.Name, soundAssetName);
                if (m_PlaySoundFailureEventHandler != null)
                {
                    m_PlaySoundFailureEventHandler(this, new PlaySoundFailureEventArgs(playSoundInfo.SerialId, soundAssetName, playSoundInfo.SoundGroup.Name, playSoundInfo.PlaySoundParams, errorCode.Value, errorMessage, playSoundInfo.UserData));
                    return;
                }

                throw new GameFrameworkException(errorMessage);
            }
        }
            /// <summary>
            /// 回收对象。
            /// </summary>
            /// <param name="target">要回收的对象。</param>
            public void Unspawn(object target)
            {
                if (target == null)
                {
                    throw new GameFrameworkException("Target is invalid.");
                }

                foreach (Object <T> obj in m_Objects)
                {
                    if (obj.Peek().Target == target)
                    {
                        GameFrameworkLog.Debug("Object pool '{0}' unspawn '{1}'.", Utility.Text.GetFullName <T>(Name), obj.Peek().Name);
                        obj.Unspawn();
                        Release();
                        return;
                    }
                }

                throw new GameFrameworkException(Utility.Text.Format("Can not find target in object pool '{0}'.", Utility.Text.GetFullName <T>(Name)));
            }
        /// <summary>
        /// GameEventArgs 事件注册
        /// </summary>
        /// <param name="self"></param>
        /// <param name="gameEventArgsType"></param>
        /// <param name="handle"></param>
        /// <exception cref="GameFrameworkException"></exception>
        public static void GameEventSubscribe(this EventComponent self, Type gameEventArgsType, EventHandler <GameEventArgs> handle)
        {
            if (!typeof(GameEventArgs).IsAssignableFrom(gameEventArgsType))
            {
                throw new GameFrameworkException($"gameEventArgsType 不是 {typeof(GameEventArgs)} 类型");
            }

            var args = (GameEventArgs)ReferencePool.Acquire(gameEventArgsType);

            if (!self.Check(args.Id, handle))
            {
                self.Subscribe(args.Id, handle);
            }
            else
            {
                GameFrameworkLog.Error($"事件ID:{args.Id},已存在相同的处理函数,无法继续注册.");
            }

            ReferencePool.Release(args);
        }
Exemplo n.º 18
0
        private void InitLogHelper()
        {
            if (string.IsNullOrEmpty(m_LogHelperTypeName))
            {
                return;
            }

            Type logHelperType = Utility.Assembly.GetType(m_LogHelperTypeName);

            if (logHelperType == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Can not find log helper type '{0}'.", m_LogHelperTypeName));
            }

            GameFrameworkLog.ILogHelper logHelper = (GameFrameworkLog.ILogHelper)Activator.CreateInstance(logHelperType);
            if (logHelper == null)
            {
                throw new GameFrameworkException(Utility.Text.Format("Can not create log helper instance '{0}'.", m_LogHelperTypeName));
            }

            GameFrameworkLog.SetLogHelper(logHelper);
        }
Exemplo n.º 19
0
        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);
        }
Exemplo n.º 20
0
 public static void Debug(string message)
 {
     GameFrameworkLog.Debug(message);
 }
Exemplo n.º 21
0
 public static void Debug(string format, params object[] args)
 {
     GameFrameworkLog.Debug(format, args);
 }
Exemplo n.º 22
0
 public static void Debug(string format, object arg0, object arg1, object arg2)
 {
     GameFrameworkLog.Debug(format, arg0, arg1, arg2);
 }
Exemplo n.º 23
0
 public static void Fatal(string format, params object[] args)
 {
     GameFrameworkLog.Fatal(format, args);
 }
Exemplo n.º 24
0
 public static void Fatal(string format, object arg0, object arg1, object arg2)
 {
     GameFrameworkLog.Fatal(format, arg0, arg1, arg2);
 }
Exemplo n.º 25
0
 public static void Fatal(string message)
 {
     GameFrameworkLog.Fatal(message);
 }
Exemplo n.º 26
0
 public static void Fatal(object message)
 {
     GameFrameworkLog.Fatal(message);
 }
Exemplo n.º 27
0
 public static void Error(string format, params object[] args)
 {
     GameFrameworkLog.Error(format, args);
 }
Exemplo n.º 28
0
 public static void Error(string format, object arg0, object arg1, object arg2)
 {
     GameFrameworkLog.Error(format, arg0, arg1, arg2);
 }
Exemplo n.º 29
0
 public static void Error(string message)
 {
     GameFrameworkLog.Error(message);
 }
Exemplo n.º 30
0
 public static void Error(object message)
 {
     GameFrameworkLog.Error(message);
 }