Example #1
0
        /// <summary>
        /// 生成迷宫对象.带碰撞体
        /// </summary>
        /// <param name="height"></param>
        /// <param name="width"></param>
        /// <param name="wallRender">墙壁使用的贴图</param>
        /// <returns></returns>
        public static GameObject GetMaze(int height, int width, RenderPoint wallRender)
        {
            GameObject gameObject = new GameObject("Maze", "Maze");

            gameObject.InitMesh(GetMazeMesh(height, width));
            Debug.Log("迷宫生成完毕,生成墙壁" + gameObject.PosList.Count);

            gameObject.AddComponent <Collider>();
            Renderer renderer = gameObject.AddComponent <Renderer>();

            renderer.Rendering(wallRender);

            return(gameObject);
        }
Example #2
0
        public static void Init(GameObject camera)
        {
            if (!camera || !camera.Active)
            {
                return;
            }

            Camera cameraComponent = camera.GetComponent <Camera>();

            if (!cameraComponent || !cameraComponent.Active)
            {
                return;
            }

            RendererSystem.camera = camera;

            charWidth       = cameraComponent.CharWidth;
            height          = cameraComponent.Height;
            width           = cameraComponent.Width;
            renderers       = new RenderPoint[width, height];
            rendererBuffers = new RenderPoint[width, height];

            Console.CursorVisible = false;
            Console.WindowHeight  = height + 1;
            Console.BufferHeight  = height + 1;
            Console.WindowWidth   = width * charWidth + 2;
            Console.BufferWidth   = width * charWidth + 2;

            //初始化空渲染点的定义
            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < charWidth; i++)
            {
                sb.Append(' ');
            }
            Block = new RenderPoint(sb.ToString(), int.MaxValue);


            //将Buffer复制,Render清空为Block
            for (int i = 0; i < renderers.GetLength(0); i++)
            {
                for (int j = 0; j < renderers.GetLength(1); j++)
                {
                    rendererBuffers[i, j] = Block;
                    renderers[i, j]       = Block;
                }
            }
        }
Example #3
0
        //三项属性相同就视为相等,渲染不需要知道Depth
        public override bool Equals(object obj)
        {
            RenderPoint renderPoint = (RenderPoint)obj;

            return(str == renderPoint.str && foreColor == renderPoint.foreColor && backColor == renderPoint.backColor);
        }
Example #4
0
        internal static void Update(List <GameObject> gameObjects)
        {
            if (!camera || !camera.Active)
            {
                return;
            }

            Vector2Int cameraPos = camera.GetComponent <Transform>().Position;

            //将所有Renderer组件上的渲染信息渲染到屏幕上
            foreach (GameObject gameObject in gameObjects)
            {
                if (!gameObject.Active)
                {
                    continue;
                }

                Renderer renderer = gameObject.GetComponent <Renderer>();
                if (!renderer || !renderer.Active)
                {
                    continue;
                }

                //渲染
                Transform transform = renderer.GetComponent <Transform>();
                foreach (var v in renderer.Pos_RenderPoint)
                {
                    //渲染位置
                    Vector2Int vector = transform.Position + v.Key - cameraPos;
                    //如果这个渲染位置没有越界
                    if (vector.X >= 0 && vector.X < width && height - vector.Y >= 0 && height - vector.Y < height)
                    {
                        //使用特定的加法运算,将点的渲染叠加到原点上面去.
                        //更改了一下算法.. 将Y反转
                        renderers[vector.X, height - vector.Y] += v.Value;

                        //Debug.Log(vector);
                    }
                }
            }

            for (int i = 0; i < renderers.GetLength(0); i++)
            {
                for (int j = 0; j < renderers.GetLength(1); j++)
                {
                    RenderPoint renderer       = renderers[i, j];
                    RenderPoint bufferRenderer = rendererBuffers[i, j];
                    //Diff 如果二者不相等,那么调用DrawCall
                    if (!renderer.Equals(bufferRenderer))
                    {
                        ConsoleOutPutStandard.Draw(
                            new DrawCall()
                        {
                            X         = i * charWidth,
                            Y         = j,
                            ForeColor = renderer.foreColor,
                            BackColor = renderer.backColor,
                            Str       = renderer.str
                        }
                            );
                    }
                }
            }

            //将Buffer复制,Render清空为Block
            for (int i = 0; i < renderers.GetLength(0); i++)
            {
                for (int j = 0; j < renderers.GetLength(1); j++)
                {
                    rendererBuffers[i, j] = renderers[i, j];
                    renderers[i, j]       = Block;
                }
            }
        }