Пример #1
0
 /// <summary>
 /// 销毁一个游戏物体
 /// </summary>
 public static void Destroy(GameObject gameObject)
 {
     //进行这个设置的时候,就已经关掉了所有组件了.对于系统来说相当于已经被移除
     gameObject.SetActive(false);
     //在最后移除它
     RuntimeEngine.GetSystem <DeleteSystem>().GameObjectsToDelete.Add(gameObject);
 }
Пример #2
0
 private void Click()
 {
     if (OnClick != null)
     {
         RuntimeEngine.GetSystem <InvokeSystem>().AddDelayAction(OnClick, 0f);
     }
 }
Пример #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
        public static void OpenWithEditor(Action action, string FormName = "Destroy")
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            var mainForm = new FormEditor();

            mainForm.Text = FormName;

            #region 关于注册的说明
            //任何引擎入口要搞定的事情就是注册好这几个事件
            //理论上来讲Core现在基本没什么平台依赖的东西了

            //Windows的入口没写,反正估计一阵子之内也用不上了
            //举例,如果是Windows可以这样进行绑定
            //ConsoleIO.WindowsInit();
            //Native.WindowsMouseInit();
            //StandardIO.GetMousePositionInPixelEvent += Native.GetMousePositionPixelWindows;
            //StandardIO.RendererEvent += Native.Print;

            //如果是Winform则可以这么初始化
            //ConsoleIO.Init();
            //StandardIO.RendererEvent += ConsoleIO.Renderer;
            #endregion

            //注册输入事件 输入事件来自于WindowsAPI
            StandardIO.GetKeyEvent         += Windows.Windows.GetInput;
            StandardIO.GetMouseButtonEvent += Windows.Windows.GetInputMouse;
            //将窗体的对应方法绑到核心事件
            StandardIO.DebugLogEvent += EditorSystem.DebugLog;
            StandardIO.GetMousePositionInPixelEvent += EditorSystem.GetMousePositionPixel;
            StandardIO.RendererEvent += EditorSystem.Renderer;



            RuntimeEngine.Init();

            //将窗体的更新作为系统绑定到核心里
            RuntimeEngine.AddSystem <EditorSystem>();

            RuntimeEngine.SetSystemUpdate();
            //留给开发者的初始化接口,由中间层封装控制
            action.Invoke();


            //开启Editor线程
            FormThread = new Thread(() => { Application.Run(mainForm); });
            FormThread.Start();
            //这个解决方法很不优雅,但是必须等这个窗口创建完成了才能开始编辑器生命周期
            Thread.Sleep(10);
            //这个线程负责进行无缝渲染,不和引擎同步
            EditorThread = new Thread(EditorRuntime.Run);
            EditorThread.Start();

            RuntimeEngine.Run();
        }
Пример #5
0
        internal override void Initialize()
        {
            system = RuntimeEngine.GetSystem <EventHandlerSystem>();

            if (system == null)
            {
                Debug.Error("没有事件系统,请检查EventHandlerSystem");
                return;
            }
        }
Пример #6
0
 /// <summary>
 /// 初始化
 /// </summary>
 private void Init()
 {
     Name                = "GameObject";
     Active              = true;
     Tag                 = "None";
     gameObject          = this;
     Components          = new List <Component>();
     transform           = AddComponent <Transform>(); //添加默认组件
     transform.transform = transform;
     RuntimeEngine.Manage(this);                       //进入托管模式
 }
Пример #7
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);
            }
        }
Пример #8
0
        /// <summary>
        /// 运行ILoveDestroy的小游戏
        /// </summary>
        public static void ILoveDestroy()
        {
            string[] lines = new string[]
            {
                @"              ,----------------,              ,---------,",
                @"         ,-----------------------,          ,""        ,""|",
                @"       ,""                      ,""|        ,""        ,""  |",
                @"      +-----------------------+  |      ,""        ,""    |",
                @"      |  .-----------------.  |  |     +---------+      |",
                @"      |  |                 |  |  |     | -==----'|      |",
                @"      |  | I LOVE DESTROY! |  |  |     |         |      |",
                @"      |  | By Charlie      |  |  |/----|`---=    |      |",
                @"      |  | C:\>_           |  |  |   ,/|==== ooo |      ;",
                @"      |  |                 |  |  |  // |(((( [33]|    ,"" ",
                @"      |  `-----------------'  |,"" .;'| |((((     |  ,""   ",
                @"      +-----------------------+  ;;  | |         |,""     ",
                @"         /_)______________(_/  //'   | +---------+       ",
                @"    ___________________________/___  `,                  ",
                @"   /  oooooooooooooooo  .o.  oooo /,   \,""-----------    ",
                @"  / ==ooooooooooooooo==.o.  ooo= //   ,`\--{)B     ,""    ",
                @" /_==__==========__==_ooo__ooo=_/'   /___________,""      ",
                @"                                                         "
            };
            //根据字符串数组初始化宽高
            Resources.GetLinesSize(lines, out int width, out int height);
            //初始化控制台
            Graphics graphics = RuntimeEngine.Construct2(ConsoleType.Default,
                                                         true, false, (short)width, (short)height, CharWidth.Single);
            //变量定义
            GraphicContainer computer  = null;
            Vector2          cursorPos = new Vector2(15, 8);
            char             c         = '\0';
            bool             __        = true;
            float            timer     = 0;
            float            interval  = 0.5f;
            int    limit   = 11;           //最多打印11个英文字符
            int    counter = 0;            //计数器
            string str     = string.Empty; //输入字符
            //键盘
            List <ConsoleKey> keyboard = new List <ConsoleKey>();

            for (int i = 48; i < 91; i++)
            {
                keyboard.Add((ConsoleKey)i);
            }
            keyboard.Add(ConsoleKey.Spacebar);
            keyboard.Add(ConsoleKey.Backspace);
            keyboard.Add(ConsoleKey.Enter);
            //指令集
            Dictionary <string, Action> commands = new Dictionary <string, Action>();

            commands.Add("exit", () => { RuntimeEngine.Exit(); });
            //开始生命周期
            RuntimeEngine.Start(
                () =>
            {
                //Start
                computer = graphics.CreatContainerByLines(lines);
                computer.SetColor(Colour.Black, Colour.White);
            },
                () =>
            {
                //Update
                timer += Time.DeltaTime;
                if (timer >= interval)
                {
                    timer = 0;
                    if (__)
                    {
                        c = '_';
                    }
                    else
                    {
                        c = '\0';
                    }
                    __ = !__;
                }
                foreach (ConsoleKey item in keyboard)
                {
                    //输入指令
                    if (item == ConsoleKey.Enter)
                    {
                        if (Input.GetKeyDown(item))
                        {
                            string lowerCase = str.ToLower();
                            if (commands.ContainsKey(lowerCase))
                            {
                                //执行命令
                                commands[lowerCase]();
                            }
                        }
                    }
                    else if (item == ConsoleKey.Backspace)
                    {
                        if (Input.GetKey(item))
                        {
                            if (counter > 0)
                            {
                                counter--;
                                //删除字符
                                str = str.Substring(0, counter);
                                //删除字符图像
                                GraphicGrid before = computer.GraphicGrids[
                                    cursorPos.Y * width + cursorPos.X];
                                before.Left = new CharInfo('\0', Colour.Black, Colour.White);
                                //光标后退一格
                                cursorPos.X--;
                            }
                        }
                    }
                    else
                    {
                        if (Input.GetKeyDown(item))
                        {
                            if (counter < limit)
                            {
                                counter++;
                                //新增字符
                                str += (char)item;
                                //新增字符图形
                                GraphicGrid before = computer.GraphicGrids[
                                    cursorPos.Y * width + cursorPos.X];
                                before.Left = new CharInfo((char)item, Colour.Black, Colour.White);
                                //光标前进一格
                                cursorPos.X++;
                            }
                        }
                    }
                }
                //设置光标
                GraphicGrid graphicGrid = computer.GraphicGrids[
                    cursorPos.Y * width + cursorPos.X];
                graphicGrid.Left = new CharInfo(c, Colour.Black, Colour.White);
                //执行渲染指令
                graphics.PreRender();
                graphics.Render();
            }
                ,
                () =>
            {
                //Destroy
            }, 30);
        }
Пример #9
0
 /// <summary>
 /// 延迟销毁一个游戏物体
 /// </summary>
 public static void Destroy(GameObject gameObject, float delayTime)
 {
     RuntimeEngine.GetSystem <InvokeSystem>().AddDelayAction(
         () => Destroy(gameObject), delayTime);
 }
Пример #10
0
 internal override void OnRemove()
 {
     RuntimeEngine.GetSystem <CollisionSystem>().RemoveFromSystem(this);
     GameObject.ChangePositionEvent -= OnMove;
 }
Пример #11
0
 private bool OnMove(Vector2 from, Vector2 to)
 {
     RuntimeEngine.GetSystem <CollisionSystem>().MoveInSystem(this, from, to);
     return(true);
 }
Пример #12
0
 internal override void OnAdd()
 {
     RuntimeEngine.GetSystem <CollisionSystem>().AddToSystem(this);
     GameObject.ChangePositionEvent += OnMove;
 }
Пример #13
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;
        }
Пример #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="rigid">当前rigid</param>
        /// <param name="to">要前往的目标点</param>
        /// <param name="dis">要进行的位移</param>
        /// <returns></returns>
        public static bool CanMoveIn(RigidBody rigid, Vector2Int to, Vector2Int dis, float mass)
        {
            //撞到静态碰撞体,强制这个rigid停止移动
            if (staticColliders.ContainsKey(to))
            {
                rigid.Stop();
                return(false);
            }
            //如果撞到了其他的colliders 且这个碰撞体不是自己
            else if (colliders.ContainsKey(to))
            {
                if (colliders[to] == rigid.GetComponent <Collider>())
                {
                    return(true);
                }
                //发生碰撞的另一个碰撞体
                Collider otherCollider = colliders[to];
                //获得自己的质量
                float thisMass = mass;
                //获得对方的质量
                float otherMass;

                RigidBody otherRigid = otherCollider.GetComponent <RigidBody>();
                if (otherRigid != null)
                {
                    otherMass = otherRigid.Mass;

                    //如果自己的质量比对方小,那么自己被阻挡停止
                    if (thisMass <= otherMass)
                    {
                        RuntimeEngine.CallScriptMethod(rigid.gameObject, "OnCollision", false, colliders[to]);
                        rigid.Stop();
                        return(false);
                    }
                    //如果自己质量比对方大,那么将对方推走,并把自己推走
                    else
                    {
                        //递归调用 调用的时候同样会自动检测并移动
                        if (CanMove(otherRigid, dis, mass - otherMass))
                        {
                            //RuntimeEngine.CallScriptMethod(rigid.gameObject, "OnCollision", false, colliders[to]);
                            return(true);
                        }
                        else
                        {
                            RuntimeEngine.CallScriptMethod(rigid.gameObject, "OnCollision", false, colliders[to]);
                            return(false);
                        }
                    }
                }
                //如果没有获取对方的质量,那么强制停止
                else
                {
                    RuntimeEngine.CallScriptMethod(rigid.gameObject, "OnCollision", false, colliders[to]);
                    rigid.Stop();
                    return(false);;
                }
            }
            //没有撞墙,那么移动transform
            else
            {
                return(true);
            }
        }