public void DataBinding_BindToBooleanMember() { ThreadRunner.RunInSTA(delegate { //Create the visual BoolToVisibilityConverterTestVisual testVisual = new BoolToVisibilityConverterTestVisual(); //Create the object that the visual will databind to. BoolToVisibilityConverterBindableBoolClass dataContext = new BoolToVisibilityConverterBindableBoolClass(); dataContext.IsVisible1 = true; dataContext.IsVisible2 = true; testVisual.DataContext = dataContext; //Render the visual RenderUtility.RenderVisual(testVisual); //Check the visibility of the controls Assert.IsTrue(testVisual.nonInvertingVisibilityControl.Visibility == Visibility.Visible); Assert.IsTrue(testVisual.invertingVisibilityControl.Visibility == Visibility.Collapsed); //Negate the visibilities to check that ConvertBack works ok. testVisual.NegateCurrentVisbilities(); RenderUtility.RenderVisual(testVisual); //Check the visibility flags in our datacontext Assert.IsTrue(dataContext.IsVisible1 == false); Assert.IsTrue(dataContext.IsVisible2 == false); }); }
private static string GetText(BocRenderingContext <IBocTextValue> renderingContext) { var textMode = renderingContext.Control.TextBoxStyle.TextMode; if (textMode == BocTextBoxMode.PasswordNoRender || textMode == BocTextBoxMode.PasswordRenderMasked) { return(new string ((char)9679, 5)); } string text; if (textMode == BocTextBoxMode.MultiLine) { var lines = StringUtility.ParseNewLineSeparatedString(renderingContext.Control.Text ?? ""); text = RenderUtility.JoinLinesWithEncoding(lines); } else { text = HttpUtility.HtmlEncode(renderingContext.Control.Text); } if (string.IsNullOrEmpty(text) && renderingContext.Control.IsDesignMode) { text = c_designModeEmptyLabelContents; // Too long, can't resize in designer to less than the content's width // Label.Text = "[ " + this.GetType().Name + " \"" + this.ID + "\" ]"; } return(text); }
protected override Label GetLabel(BocRenderingContext <IBocMultilineTextValue> renderingContext) { Label label = new Label { ClientIDMode = ClientIDMode.Static }; label.ID = renderingContext.Control.GetValueName(); label.EnableViewState = false; string[] lines = renderingContext.Control.Value; string text = RenderUtility.JoinLinesWithEncoding(lines ?? Enumerable.Empty <string>()); if (string.IsNullOrEmpty(text) && renderingContext.Control.IsDesignMode) { text = c_designModeEmptyLabelContents; // Too long, can't resize in designer to less than the content's width // label.Text = "[ " + this.GetType().Name + " \"" + this.ID + "\" ]"; } label.Text = text; label.Width = Unit.Empty; label.Height = Unit.Empty; label.ApplyStyle(renderingContext.Control.CommonStyle); label.ApplyStyle(renderingContext.Control.LabelStyle); return(label); }
protected override void OnStartRunning() { var mapData = _mapQuery.GetSingleton <MapData>(); _console = new SimpleConsole(mapData.width, mapData.height); RenderUtility.AdjustCameraToConsole(_console); }
IEnumerator VerifyCamera() { while (_consoleProxy != null && isActiveAndEnabled && Application.isPlaying) { RenderUtility.AdjustCameraToConsole(_consoleProxy, _camera); yield return(_waitTime); } }
protected override void OnStartRunning() { var mapEntity = GetSingletonEntity <MapTiles>(); var mapData = EntityManager.GetComponentData <MapData>(mapEntity); _console = new SimpleConsole(mapData.width, mapData.height); RenderUtility.AdjustCameraToConsole(_console); }
private void OnDestroy() { RenderUtility.ReleaseRenderTexture(solverTex); RenderUtility.ReleaseRenderTexture(densityTex); RenderUtility.ReleaseRenderTexture(velocityTex); RenderUtility.ReleaseRenderTexture(prevTex); #if UNITY_EDITOR Debug.Log("Buffer Released"); #endif }
void Rebuild() { _console.Resize(_width, _height); // Only needs to be called if we're using "screen" effects in the console shader. //RenderUtility.UpdatePixelEffectData(_console); // Must be called any time the console is resized RenderUtility.AdjustCameraToConsole(_console); }
public void FindChildControl_IndexTooGreat() { ThreadRunner.RunInSTA(delegate { DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual(); RenderUtility.RenderVisual(visual); TextBox tb = visual.FindChildControl <TextBox>(4); Assert.IsNull(tb); }); }
public void FindChildControl_IndexLessThanZero() { ThreadRunner.RunInSTA(delegate { DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual(); RenderUtility.RenderVisual(visual); TextBox tb = visual.FindChildControl <TextBox>(-1); Assert.IsTrue(tb != null && tb.Text == "TextBox 1"); }); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var mapData = GetSingleton <MapData>(); int2 mapSize = new int2(mapData.width, mapData.height); if (mapData.width != _console.Width || mapData.height != _console.Height) { _console.Resize(mapData.width, mapData.height); RenderUtility.AdjustCameraToConsole(_console); return(inputDeps); } _console.ClearScreen(); // Since we're iterating all tiles in the map we can probably benefit from using burst. // We can't use the console in a job since it's a managed object, so copy all tile data var tiles = _console.ReadAllTiles(Allocator.TempJob); Entities .ForEach((ref DynamicBuffer <MapTiles> map) => { for (int i = 0; i < map.Length; ++i) { Tile t = new Tile(); t.bgColor = Color.black; switch ((TileType)map[i]) { case TileType.Floor: t.fgColor = new Color(0.5f, 0.5f, 0.5f); t.glyph = ToCP437('.'); break; case TileType.Wall: t.fgColor = new Color(0, 1, 0); t.glyph = ToCP437('#'); break; } tiles[i] = t; } }).Run(); _console.WriteAllTiles(tiles); tiles.Dispose(); Entities .WithoutBurst() .WithAll <Player>() .ForEach((in Position pos) => { int2 p = math.clamp(pos, 1, mapSize - 1); _console.Set(p.x, p.y, Color.yellow, Color.black, ToCP437('@')); }).Run();
protected override void InitializeComputeShader() { width = Screen.width; height = Screen.height; solverTex = RenderUtility.CreateRenderTexture(width >> lod, height >> lod, 0, RenderTextureFormat.ARGBFloat, TextureWrapMode.Clamp, FilterMode.Point, solverTex); densityTex = RenderUtility.CreateRenderTexture(width >> lod, height >> lod, 0, RenderTextureFormat.RHalf, TextureWrapMode.Clamp, FilterMode.Point, densityTex); velocityTex = RenderUtility.CreateRenderTexture(width >> lod, height >> lod, 0, RenderTextureFormat.RGHalf, TextureWrapMode.Clamp, FilterMode.Point, velocityTex); prevTex = RenderUtility.CreateRenderTexture(width >> lod, height >> lod, 0, RenderTextureFormat.ARGBFloat, TextureWrapMode.Clamp, FilterMode.Point, prevTex); Shader.SetGlobalTexture(solverTexId, solverTex); }
private void LateUpdate() { if (_resized) { _resized = false; _console.Resize(_width, _height); RenderUtility.UpdatePixelEffectData(_console); } RenderUtility.UpdatePixelEffectProperties(_console, Material); _console.Update(); }
public void FindParentControl_ControlNull() { ThreadRunner.RunInSTA(delegate { DependencyObjectExtensionsTestVisual visual = null; RenderUtility.RenderVisual(visual); StackPanel sp = visual.FindParentControl <StackPanel>(); Assert.IsNull(sp); }); }
public void FindParentControl_ParentExists() { ThreadRunner.RunInSTA(delegate { DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual(); RenderUtility.RenderVisual(visual); StackPanel intermediateStackPanel = visual.IntermediatePanel; StackPanel sp = intermediateStackPanel.FindParentControl <StackPanel>(); Assert.IsTrue(sp != null && sp.Name == "RootPanel"); }); }
public void FindParentControl_ParentDoesNotExists() { ThreadRunner.RunInSTA(delegate { DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual(); RenderUtility.RenderVisual(visual); StackPanel intermediateStackPanel = visual.IntermediatePanel; TabControl g = intermediateStackPanel.FindParentControl <TabControl>(); Assert.IsNull(g); }); }
public void FindChildControl_FindFirst() { ThreadRunner.RunInSTA(delegate { DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual(); RenderUtility.RenderVisual(visual); //Assume first element TextBox tb = visual.FindChildControl <TextBox>(); Assert.IsTrue(tb != null && tb.Text == "TextBox 1"); //Explicitly findfirst element tb = visual.FindChildControl <TextBox>(0); Assert.IsTrue(tb != null && tb.Text == "TextBox 1"); }); }
//渲染Mesh网格 public void RenderMesh() { foreach (Mesh mesh in meshs) { int triangles = mesh.indices.GetLength(0); for (int i = 0; i < triangles; ++i) { //应当保证p1 p2 p3是逆时针的顺序 Vertex p1 = new Vertex(mesh.vertices[mesh.indices[i, 0]]); Vertex p2 = new Vertex(mesh.vertices[mesh.indices[i, 1]]); Vertex p3 = new Vertex(mesh.vertices[mesh.indices[i, 2]]); RenderUtility.DrawTriangle(p1, p2, p3); } } }
public void DataBinding_BindToNonBooleanMember() { ThreadRunner.RunInSTA(delegate { //Create the visual BoolToVisibilityConverterTestVisual testVisual = new BoolToVisibilityConverterTestVisual(); //Create the object that the visual will databind to. BoolToVisibilityConverterBindableNonBoolClass dataContext = new BoolToVisibilityConverterBindableNonBoolClass(); dataContext.IsVisible1 = "some string 1"; dataContext.IsVisible2 = "some string 2"; testVisual.DataContext = dataContext; //Render the visual RenderUtility.RenderVisual(testVisual); }); }
public MainWindow() { InitializeComponent(); //当前窗口创建graphics canvas = this.CreateGraphics(); //当前窗口的宽高值 buffer = new Bitmap(this.Width, this.Height); RenderUtility.SetFrameBuffer(buffer); //根据buffer的大小设定zbuffer zbuffer = new float[this.Width, this.Height]; RenderUtility.SetZBuffer(zbuffer); //创建平行光,平行光的位置默认为(0, 20, 0),光照颜色为橘黄色,环境光颜色为白色 light = new Light(new Vector3(0, 20, 0, 1), new Color4(Color.Orange), new Color4(Color.White)); RenderUtility.SetLight(light); //创建摄像机, 摄像机位置默认为(0,0,0),朝向z轴方向(0,0,1),以(0,1,0)为单位up向量,y方向的视角为90度,zn = 1, zf = 500 float aspect = (float)this.Width / (float)this.Height; camera = new Camera(new Vector3(0, 0, 0, 1), new Vector3(0, 0, 1, 0), new Vector3(0, 1, 0, 0), 3.1415926f / 4, aspect, 1.0f, 500.0f); //设定渲染的模式 renderType = RenderType.WireFrame; renderType = RenderType.VertexColor; RenderUtility.SetRenderType(renderType); //加载模型 //meshs,要渲染的网格列表 meshs = new List <Mesh>(); Mesh cube = new Mesh(Cube.positions, Cube.indices, Cube.colors); meshs.Add(cube); //开启计时器 SetupTimer(); }
public void FindChildControl_FindNonExistentControl() { ThreadRunner.RunInSTA(delegate { DependencyObjectExtensionsTestVisual visual = new DependencyObjectExtensionsTestVisual(); RenderUtility.RenderVisual(visual); //Attempt to find first, implicit TabControl tc = visual.FindChildControl <TabControl>(); Assert.IsNull(tc); //Attempt to find first, explicit tc = visual.FindChildControl <TabControl>(0); Assert.IsNull(tc); //Attempt to find other than first tc = visual.FindChildControl <TabControl>(2); Assert.IsNull(tc); }); }
public void JoinLinesWithEncoding_WithMultipleItemsAndRequiringEncoding_ReturnsConcatenatedAndEncodedString() { Assert.That( RenderUtility.JoinLinesWithEncoding(new[] { "Fir<html>st", "Second" }), Is.EqualTo("Fir<html>st<br />Second")); }
public void JoinLinesWithEncoding_WithSingleItemAndRequiringEncoding_ReturnsEncodedString() { Assert.That( RenderUtility.JoinLinesWithEncoding(new[] { "Fir<html>st" }), Is.EqualTo("Fir<html>st")); }
public void JoinLinesWithEncoding_WithMultipleItems_ReturnsConcatenatedString() { Assert.That( RenderUtility.JoinLinesWithEncoding(new[] { "First", "Second" }), Is.EqualTo("First<br />Second")); }
public void JoinLinesWithEncoding_WithSingleItem_ReturnsString() { Assert.That( RenderUtility.JoinLinesWithEncoding(new[] { "First" }), Is.EqualTo("First")); }
public void JoinLinesWithEncoding_WithEmptySequence_ReturnsEmptyString() { Assert.That( RenderUtility.JoinLinesWithEncoding(Enumerable.Empty <string>()), Is.EqualTo("")); }
protected override JobHandle OnUpdate(JobHandle inputDeps) { var mapEntity = _mapQuery.GetSingletonEntity(); var mapData = _mapQuery.GetSingleton <MapData>(); if (mapData.width != _console.Width || mapData.height != _console.Height) { _console.Resize(mapData.width, mapData.height); RenderUtility.AdjustCameraToConsole(_console); return(inputDeps); } var map = EntityManager.GetBuffer <MapTiles>(mapEntity); // The map has been resized but not yet updated if ((mapData.width * mapData.height) != map.Length) { return(inputDeps); } var playerEntity = _playerQuery.GetSingletonEntity(); var view = EntityManager.GetBuffer <TilesInView>(playerEntity); var memory = EntityManager.GetBuffer <TilesInMemory>(playerEntity); _console.ClearScreen(); Job .WithoutBurst() .WithCode(() => { Color fg = default; Color bg = Color.black; char ch = default; for (int x = 0; x < mapData.width; ++x) { for (int y = 0; y < mapData.height; ++y) { int idx = y * mapData.width + x; if (memory[idx]) { var tile = (TileType)map[idx]; if (view[idx]) { switch (tile) { case TileType.Floor: fg = new Color(0, .5f, .5f); ch = '.'; break; case TileType.Wall: fg = new Color(0, 1, 0); ch = '#'; break; } } else { fg = new Color(0.1f, .1f, 0.1f); switch (tile) { case TileType.Floor: ch = '.'; break; case TileType.Wall: ch = '#'; break; } } _console.Set(x, y, fg, bg, ToCP437(ch)); } } } }).Run(); Entities .WithoutBurst() .ForEach((in Renderable render, in Position pos) => { int2 p = math.clamp(pos, 1, mapData.Size - 1); if (view[p.y * mapData.width + p.x]) { _console.Set(p.x, p.y, render.fgColor, render.bgColor, render.glyph); } }).Run();
protected override void OnUpdate() { var mapEntity = _mapQuery.GetSingletonEntity(); var mapData = _mapQuery.GetSingleton <MapData>(); if (mapData.width != _console.Width || mapData.height != _console.Height) { _console.Resize(mapData.width, mapData.height); RenderUtility.AdjustCameraToConsole(_console); return; } RenderUtility.AdjustCameraToConsole(_console); var map = EntityManager.GetBuffer <MapTiles>(mapEntity); // The map has been resized but not yet updated if ((mapData.width * mapData.height) != map.Length) { return; } if (_playerQuery.IsEmptyIgnoreFilter) { return; } // Since we're iterating all tiles in the map we can probably benefit from using burst. // We can't use the console in a job since it's a managed object, so we'll work directly with tiles var tiles = new NativeArray <Tile>(_console.CellCount, Allocator.Temp, NativeArrayOptions.ClearMemory); var playerEntity = _playerQuery.GetSingletonEntity(); bool hasView = EntityManager.HasComponent <TilesInView>(playerEntity); bool hasMemory = EntityManager.HasComponent <TilesInMemory>(playerEntity); _console.ClearScreen(); if (!hasMemory && !hasView) { RenderEverything(map, tiles, mapData.Size); } else { if (hasMemory) { var memory = EntityManager.GetBuffer <TilesInMemory>(playerEntity); RenderMemory(map, memory, tiles, mapData.Size); } if (hasView) { var view = EntityManager.GetBuffer <TilesInView>(playerEntity); RenderView(map, view, tiles, mapData.Size); } } _console.WriteAllTiles(tiles); _console.Update(); _console.Draw(); }
protected override void OnStartRunning() { RenderUtility.AdjustCameraToConsole(_console); }
/// <summary> /// Draw the console to the screen manually. /// </summary> public void Draw() { RenderUtility.DrawConsole(this, Material); }