Пример #1
0
 private void Click()
 {
     if (OnClick != null)
     {
         RuntimeEngine.GetSystem <InvokeSystem>().AddDelayAction(OnClick, 0f);
     }
 }
Пример #2
0
 /// <summary>
 /// 销毁一个游戏物体
 /// </summary>
 public static void Destroy(GameObject gameObject)
 {
     //进行这个设置的时候,就已经关掉了所有组件了.对于系统来说相当于已经被移除
     gameObject.SetActive(false);
     //在最后移除它
     RuntimeEngine.GetSystem <DeleteSystem>().GameObjectsToDelete.Add(gameObject);
 }
Пример #3
0
        public override void Update()
        {
            List <Script> disabledScripts = new List <Script>();

            for (int i = 0; i < StartScriptCollection.Count; i++)
            {
                Script script = StartScriptCollection[i];

                if (script.Enable == false)
                {
                    //添加进未激活列表
                    disabledScripts.Add(script);
                    continue;
                }
                //执行Start方法
                script.Start();
                UpdateSystem updateSystem = RuntimeEngine.GetSystem <UpdateSystem>();
                //添加进Update执行列表
                updateSystem.UpdateScriptCollection.Add(script);
            }

            //清空列表
            StartScriptCollection.Clear();
            //添加未激活列表
            StartScriptCollection.AddRange(disabledScripts);
        }
Пример #4
0
        internal override void Initialize()
        {
            system = RuntimeEngine.GetSystem <EventHandlerSystem>();

            if (system == null)
            {
                Debug.Error("没有事件系统,请检查EventHandlerSystem");
                return;
            }
        }
Пример #5
0
        /// <summary>
        /// 通常的一种搜寻判定,所有物理系统的物体均不可穿过
        /// </summary>
        public static bool CanMoveInPhysics(Vector2 v)
        {
            Dictionary <Vector2, List <Collider> > dic = RuntimeEngine.GetSystem <CollisionSystem>().Colliders;

            if (dic.ContainsKey(v))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        }
Пример #6
0
 /// <summary>
 /// 延迟销毁一个游戏物体
 /// </summary>
 public static void Destroy(GameObject gameObject, float delayTime)
 {
     RuntimeEngine.GetSystem <InvokeSystem>().AddDelayAction(
         () => Destroy(gameObject), delayTime);
 }
Пример #7
0
 internal override void OnRemove()
 {
     RuntimeEngine.GetSystem <CollisionSystem>().RemoveFromSystem(this);
     GameObject.ChangePositionEvent -= OnMove;
 }
Пример #8
0
 private bool OnMove(Vector2 from, Vector2 to)
 {
     RuntimeEngine.GetSystem <CollisionSystem>().MoveInSystem(this, from, to);
     return(true);
 }
Пример #9
0
 internal override void OnAdd()
 {
     RuntimeEngine.GetSystem <CollisionSystem>().AddToSystem(this);
     GameObject.ChangePositionEvent += OnMove;
 }
Пример #10
0
        /// <summary>
        /// Update
        /// </summary>
        public override void Update()
        {
            int x = Input.GetDirectInput(ConsoleKey.A, ConsoleKey.D);
            int y = Input.GetDirectInput(ConsoleKey.S, ConsoleKey.W);

            input = new Vector2Float(x, y);

            if (input == Vector2Float.Zero)
            {
                FPosition = Vector2Float.Zero;
            }
            //启动的时候会送半程的瞬移加速,使反应更灵敏
            //理论上来讲间或的按键可能会比连续按住移动更快...
            else if (input != Vector2Float.Zero && lastInput == Vector2Float.Zero)
            {
                FPosition  = input * 0.5f;
                FPosition += input.Normalized * Speed * Time.DeltaTime;
            }
            else
            {
                FPosition += input.Normalized * Speed * Time.DeltaTime;
                //如果为zero,则朝向依旧保持原本的朝向,如果输入了按键,那么改变朝向
                Direction = (Vector2)input;
            }

            //浮点溢出之后进行移动 相当于原来的Rigid
            int dx = 0, dy = 0;

            if (FPosition.X > 1)
            {
                FPosition.X -= 1;
                dx          += 1;
            }
            else if (FPosition.X < -1)
            {
                FPosition.X += 1;
                dx          -= 1;
            }

            if (FPosition.Y > 1)
            {
                FPosition.Y -= 1;
                dy          += 1;
            }
            else if (FPosition.Y < -1)
            {
                FPosition.Y += 1;
                dy          -= 1;
            }

            Vector2 tomove = new Vector2(dx, dy);

            //如果开启了连续碰撞模式,或者真的产生了位移,才会发送位移请求
            if (tomove != Vector2.Zero)
            {
                if (!CanMoveInCollider)
                {
                    //先去物理系统检测是否可以移动,检测的过程中不会移动物体,但是会产生碰撞回调
                    if (!RuntimeEngine.GetSystem <CollisionSystem>().CanMoveInPos(GetComponent <Collider>(), Position, Position + tomove))
                    {
                        FPosition = Vector2Float.Zero;
                    }
                    //接下来进行移动
                    else
                    {
                        Position += tomove;
                    }
                }
                else
                {
                    Position += tomove;
                }
            }
            lastInput = input;
        }