private void Render() { Vector2I vector2I = default(Vector2I); Vector2I vector2I2 = default(Vector2I); if (GameUtil.IsCapturingTimeLapse()) { vector2I = new Vector2I(0, 0); vector2I2 = new Vector2I(Grid.WidthInCells / 16, Grid.HeightInCells / 16); } else { GridArea visibleArea = GridVisibleArea.GetVisibleArea(); Vector2I min = visibleArea.Min; int a = min.x / 16; Vector2I min2 = visibleArea.Min; vector2I = new Vector2I(a, min2.y / 16); Vector2I max = visibleArea.Max; int a2 = (max.x + 16 - 1) / 16; Vector2I max2 = visibleArea.Max; vector2I2 = new Vector2I(a2, (max2.y + 16 - 1) / 16); } foreach (KeyValuePair <KeyValuePair <BuildingDef, RenderInfoLayer>, RenderInfo> item in renderInfo) { RenderInfo value = item.Value; for (int i = vector2I.y; i < vector2I2.y; i++) { for (int j = vector2I.x; j < vector2I2.x; j++) { value.Rebuild(this, j, i, MeshUtil.vertices, MeshUtil.uvs, MeshUtil.indices, MeshUtil.colours); value.Render(j, i); } } } }
public static List <GridArea> OtherAreas(this GridRow row, GridArea currentArea) { return(row.Areas.Except(new List <GridArea>() { currentArea }).ToList()); }
private void TriggerAudio(int old_value) { SpeedControlScreen instance = SpeedControlScreen.Instance; if (old_value != outputValue && (Object)instance != (Object)null && !instance.IsPaused) { GridArea visibleArea = GridVisibleArea.GetVisibleArea(); List <LogicWire> list = new List <LogicWire>(); for (int i = 0; i < wires.Count; i++) { if (visibleArea.Min <= (Vector2)wires[i].transform.GetPosition() && (Vector2)wires[i].transform.GetPosition() <= visibleArea.Max) { list.Add(wires[i]); } } if (list.Count > 0) { int index = Mathf.CeilToInt((float)(list.Count / 2)); if ((Object)list[index] != (Object)null) { Vector3 position = list[index].transform.GetPosition(); EventInstance instance2 = KFMOD.BeginOneShot(GlobalAssets.GetSound("Logic_Circuit_Toggle", false), position); instance2.setParameterValue("wireCount", (float)(wires.Count % 24)); instance2.setParameterValue("enabled", (float)outputValue); KFMOD.EndOneShot(instance2); } } } }
static void Main(string[] args) { Grid a = new Grid(); Grid b = new Grid(); GridArea area = new GridArea(a, b); area.Start.X = 5; area.Start.Y = 5; area.End.X = -1; area.End.Y = -1; GridMatrix <Grid> g = new GridMatrix <Grid>(); g.AddElement(a); g.AddElement(b); bool addDuplicate = g.AddElement(a); g.RemoveElement(a); g.GetArea(); GridArea size = g.GetArea(); bool hasGrid = g.HasElement(new Grid()); System.Console.WriteLine("Press any key to exit"); System.Console.ReadKey(); }
/// <summary> /// Initializes a new instance based on the specified <paramref name="area"/> and <paramref name="controls"/>. /// </summary> /// <param name="area">The area.</param> /// <param name="controls">The controls.</param> public SpaGridArea(GridArea area, IEnumerable <SpaGridControl> controls) { Grid = area.Grid; Styles = area.Styles; Config = area.Config; Controls = controls.ToList(); }
/// <summary> /// Initializes a new instance based on the specified <paramref name="area"/>. /// </summary> /// <param name="area">The area.</param> public SpaGridArea(GridArea area) { Grid = area.Grid; Styles = area.Styles; Config = area.Config; Controls = new List <SpaGridControl>(); }
public static void GeneratePath(GridPath path, GridArea gridArea) { var start = path.Start; var end = path.Finish; var pathResult = new List <GridAreaLocation>(); pathResult.Add(path.StartEntrance); bool isComplete = false; GridAreaLocation previous = path.StartEntrance; GridAreaLocation currentLocation = path.StartEntrance; while (!isComplete) { var cell = gridArea.GetCell(previous); // for (int i = 0; i < 4; i++) // { // var n = cell.Neighbors[i]; // // } var preferredNext = PathAlgorithm.SemiGeneticGetNextLocation(gridArea, currentLocation, path.FinishEntrance, previous); bool added = false; foreach (var i in preferredNext) { var c = gridArea.GetCell(i.Add(currentLocation)); if (c == null) { continue; } if (c.State == CellState.None) { previous = currentLocation; currentLocation = i.Add(currentLocation); if (currentLocation.X < 0 || currentLocation.Y < 0) { return; } c.State = CellState.Path; pathResult.Add(currentLocation); added = true; break; } } if (!added) { path.Path = pathResult; return; } if (pathResult.Last() == path.FinishEntrance) { path.Path = pathResult; return; } } pathResult.Add(path.FinishEntrance); }
private void RenderMesh(float z, int render_layer, float lerp_percent, bool trigger_audio) { GridArea visibleArea = GridVisibleArea.GetVisibleArea(); Vector2I min = visibleArea.Min; int a = Mathf.Max(0, min.x - 1); Vector2I min2 = visibleArea.Min; Vector2I min3 = new Vector2I(a, Mathf.Max(0, min2.y - 1)); int a2 = Grid.WidthInCells - 1; Vector2I max = visibleArea.Max; int a3 = Mathf.Min(a2, max.x + 1); int a4 = Grid.HeightInCells - 1; Vector2I max2 = visibleArea.Max; Vector2I max3 = new Vector2I(a3, Mathf.Min(a4, max2.y + 1)); RenderMeshContext shared_data = new RenderMeshContext(this, lerp_percent, min3, max3); if (shared_data.visible_conduits.Count == 0) { shared_data.Finish(); } else { render_mesh_job.Reset(shared_data); int num = Mathf.Max(1, (int)((float)(shared_data.visible_conduits.Count / CPUBudget.coreCount) / 1.5f)); int num2 = Mathf.Max(1, shared_data.visible_conduits.Count / num); for (int i = 0; i != num2; i++) { int num3 = i * num; int end = (i != num2 - 1) ? (num3 + num) : shared_data.visible_conduits.Count; render_mesh_job.Add(new RenderMeshTask(num3, end)); } GlobalJobManager.Run(render_mesh_job); float z2 = 0f; if (showContents) { z2 = 1f; } int num4 = (int)(animTime / (1.0 / (double)tuning.framesPerSecond)) % (int)tuning.spriteCount; float w = (float)num4 * (1f / tuning.spriteCount); movingBallMesh.Begin(); movingBallMesh.SetTexture("_BackgroundTex", tuning.backgroundTexture); movingBallMesh.SetTexture("_ForegroundTex", tuning.foregroundTexture); movingBallMesh.SetVector("_SpriteSettings", new Vector4(1f / tuning.spriteCount, 1f, z2, w)); movingBallMesh.SetVector("_Highlight", new Vector4((float)(int)highlightColour.r / 255f, (float)(int)highlightColour.g / 255f, (float)(int)highlightColour.b / 255f, 0f)); staticBallMesh.Begin(); staticBallMesh.SetTexture("_BackgroundTex", tuning.backgroundTexture); staticBallMesh.SetTexture("_ForegroundTex", tuning.foregroundTexture); staticBallMesh.SetVector("_SpriteSettings", new Vector4(1f / tuning.spriteCount, 1f, z2, 0f)); staticBallMesh.SetVector("_Highlight", new Vector4((float)(int)highlightColour.r / 255f, (float)(int)highlightColour.g / 255f, (float)(int)highlightColour.b / 255f, 0f)); Vector3 position = CameraController.Instance.transform.GetPosition(); ConduitFlowVisualizer visualizer = (!trigger_audio) ? null : this; for (int j = 0; j != render_mesh_job.Count; j++) { render_mesh_job.GetWorkItem(j).Finish(movingBallMesh, staticBallMesh, position, visualizer); } movingBallMesh.End(z, layer); staticBallMesh.End(z, layer); shared_data.Finish(); } }
public void When_Given_Coordinates_Then_It_Should_Create_Area(int x, int y, int inx, int iny) { var area = new GridArea(x, y); area.Should().NotBe(null); area.Width.Should().Be(inx); area.Height.Should().Be(iny); }
public void AddArea(GridArea area) { if (GetArea(area.id) != null) { //Logger.Out("area (" + area.id + ") is already added"); return; } m_areaList.Add(area); }
public void SetAreaToCell(GridArea area, BaseCell newCell) { var points = area.GetPoints(); foreach (var point in points) { SetCell(point.x, point.y, newCell); } }
public static GridArea Create(Transform parent) { GameObject go = new GameObject(); go.name = "GridArea"; go.transform.parent = parent; GridArea gridarea = go.AddComponent <GridArea>(); return(gridarea); }
static void CreateGridArea() { if (!CheckSelection("zone")) { Debug.LogError("必须先选择zone"); return; } GridArea.Create(Selection.activeTransform); }
/// <inheritdoc /> public virtual GridControl CreateGridControl(JObject json, GridArea area) { // The saved JSON for the editor only contains the alias of the editor as other information may change over // time. As a result of this, we need to inject a new editor object into the JSON. ReplaceEditorObjectFromConfig(json); // Parse the Grid editor (undelrying type may be generic ... or not) GridEditor editor = json.GetObject("editor", CreateGridEditor); // Initialize a new Grid control GridControl control = new GridControl(json, area); // Make sure to set the editor before we parse the control value control.Editor = editor; // Parse the control value control.Value = ParseGridControlValue(control); // Get the type of the editor config (it may not have a config) Type configType = control.Editor.Config?.GetType(); // Determine the value type Type valueType = null; foreach (IGridConverter converter in _converters) { if (converter.GetValueType(control, out valueType)) { break; } } // If no converters specify a value type, we just return the control right away if (valueType == null) { return(control); } // If the editor doesn't have a configuration, we can create a new generic type from just the value type. // If we both have a value type and config type, we create a new generic type from both types if (configType == null) { Type genericType = typeof(GridControl <>).MakeGenericType(valueType); control = (GridControl)Activator.CreateInstance(genericType, control); } else { Type genericType = typeof(GridControl <,>).MakeGenericType(valueType, configType); control = (GridControl)Activator.CreateInstance(genericType, control, editor); } // Return the control return(control); }
/// <summary> /// /// </summary> /// <param name="grid"></param> /// <param name="x"></param> /// <param name="y"></param> /// <returns></returns> public static GridEXRow GetRow(this GridEX grid, int x, int y) { GridArea area = grid.HitTest(x, y); if (area != GridArea.Cell) { return(null); } int position = grid.RowPositionFromPoint(x, y); return(grid.GetRow(position)); }
public void PlaceTowerOnGrid(GameObject tower, GridArea area) { // TODO: check validity of placement var gridPos = mapGrid.WorldToGridPosition(tower.transform.position); towerGrid.SetAreaToCell(area, new GameObjectCell() { Owner = tower }); Rpc_AddTowerToGrid(tower); }
private void BuildMap() { for (int i = 0; i < GridHeight + 1; i++) // + bottom border { GridArea.Add(new List <int>() { }); for (int j = 0; j < GridWidth + 2; j++) // + 2 side borders { GridArea[i].Add(0); } } }
public bool IsAreaValid(GridArea area) { var points = area.GetPoints(); for (int i = 0; i < points.Length; i++) { if (!IsValidGridPosition(points[i].x, points[i].y)) { return(false); } } return(true); }
public IActionResult RunCommand([FromRoute] string command, [FromServices] GridArea grid) { try { var position = grid.Execute(command); return(Ok($"({position.x}, {position.y}, {OrientationString(position.o)})")); } catch (Exception ex) { ModelState.AddModelError("command", ex.Message); _logger.LogError(ex, ex.Message); return(BadRequest()); } }
/// <summary> /// Applied before LateUpdatePos runs. /// </summary> internal static bool Prefix(bool visibleToZoom, NameDisplayScreen __instance) { var inst = CameraController.Instance; if (inst != null) { GridArea area = inst.VisibleArea.CurrentArea; var entries = __instance.entries; var followTarget = inst.followTarget; int n = entries.Count; Vector3 pos; for (int i = 0; i < n; i++) { var entry = entries[i]; var go = entry.world_go; var dg = entry.display_go; var animController = entry.world_go_anim_controller; if (go != null && dg != null) { // Merely fetching the position appears to take almost 1 us? var transform = go.transform; bool active = dg.activeSelf; if (visibleToZoom && area.Contains(pos = transform.position)) { // Visible if (followTarget == transform) { pos = inst.followTargetPos; } else if (animController != null) { pos = animController.GetWorldPivot(); } entry.display_go_rect.anchoredPosition = __instance. worldSpace ? pos : __instance.WorldToScreen(pos); if (!active) { dg.SetActive(true); } } else if (active) { // Invisible dg.SetActive(false); } } } } return(false); }
public void RunOnDifference(GridArea subtract_area, Action <int> action) { for (int i = min.y; i < max.y; i++) { for (int j = min.x; j < max.x; j++) { if (!subtract_area.Contains(j, i)) { int obj = Grid.XYToCell(j, i); action(obj); } } } }
protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); if ((e.Button & MouseButtons.Right) == MouseButtons.Right) { GridArea hitTest = HitTest(e.X, e.Y); if (hitTest == GridArea.Cell) { //this.SelectedItems.Add(RowPositionFromPoint(e.X, e.Y)); RowContextMenu.Show(this, e.Location); } } }
public static GridArea GetVisibleArea() { GridArea result = default(GridArea); if ((UnityEngine.Object)Camera.main != (UnityEngine.Object)null) { Camera main = Camera.main; Vector3 position = Camera.main.transform.GetPosition(); Vector3 vector = main.ViewportToWorldPoint(new Vector3(1f, 1f, position.z)); Camera main2 = Camera.main; Vector3 position2 = Camera.main.transform.GetPosition(); Vector3 vector2 = main2.ViewportToWorldPoint(new Vector3(0f, 0f, position2.z)); result.SetExtents(Math.Max((int)(vector2.x - 0.5f), 0), Math.Max((int)(vector2.y - 0.5f), 0), Math.Min((int)(vector.x + 1.5f), Grid.WidthInCells), Math.Min((int)(vector.y + 1.5f), Grid.HeightInCells)); } return(result); }
// Use this for initialization void Start() { m_area = GridManager.Get.GetArea(1); m_destination = this.transform.position; // 创建寻路器 m_finder = new PathFinder(m_area.map, this.m_transform.position.x, this.m_transform.position.z, true, 0, 1, 10); m_animation = this.GetComponent <Animation>(); this.m_animation["idle"].wrapMode = WrapMode.Loop; this.m_animation["run"].wrapMode = WrapMode.Loop; m_animation.Play("idle"); m_currentAction = Idle; }
private void LateUpdate() { GridArea visibleArea = GridVisibleArea.GetVisibleArea(); Vector2I min = visibleArea.Min; Vector2I max = visibleArea.Max; Vector2I vector2I = min + (max - min) / 2; Camera main = Camera.main; Vector3 position = Camera.main.transform.GetPosition(); Vector3 a = main.ViewportToWorldPoint(new Vector3(1f, 1f, position.z)); Camera main2 = Camera.main; Vector3 position2 = Camera.main.transform.GetPosition(); Vector3 vector = main2.ViewportToWorldPoint(new Vector3(0f, 0f, position2.z)); Vector3 a2 = vector + (a - vector) / 2f; Vector3 a3 = a - vector; if (a3.x > a3.y) { a3.y = a3.x; } else { a3.x = a3.y; } a = a2 + a3 / 2f; vector = a2 - a3 / 2f; Vector3 a4 = a3 / 2f; Vector3 vector2 = a4 / 2f; quadrants[0].Update(new Vector2I(min.x, min.y), new Vector2I(vector2I.x, vector2I.y), new Vector3(vector.x + vector2.x, vector.y + vector2.y, emitterZPosition)); quadrants[1].Update(new Vector2I(vector2I.x, min.y), new Vector2I(max.x, vector2I.y), new Vector3(a2.x + vector2.x, vector.y + vector2.y, emitterZPosition)); quadrants[2].Update(new Vector2I(min.x, vector2I.y), new Vector2I(vector2I.x, max.y), new Vector3(vector.x + vector2.x, a2.y + vector2.y, emitterZPosition)); quadrants[3].Update(new Vector2I(vector2I.x, vector2I.y), new Vector2I(max.x, max.y), new Vector3(a2.x + vector2.x, a2.y + vector2.y, emitterZPosition)); float num = 0f; float num2 = 0f; float num3 = 0f; for (int i = 0; i < quadrants.Length; i++) { num += (float)quadrants[i].spaceLayer.tileCount; num2 += (float)quadrants[i].facilityLayer.tileCount; num3 += (float)quadrants[i].totalTileCount; } AudioMixer.instance.UpdateSpaceVisibleSnapshot(num / num3); AudioMixer.instance.UpdateFacilityVisibleSnapshot(num2 / num3); }
public void UpdateTemperature() { GridArea visibleArea = GridVisibleArea.GetVisibleArea(); for (int i = 0; i < data.Count; i++) { InfraredVisualizerData infraredVisualizerData = data[i]; KAnimControllerBase controller = infraredVisualizerData.controller; if ((Object)controller != (Object)null) { Vector3 position = controller.transform.GetPosition(); if (visibleArea.Min <= (Vector2)position && (Vector2)position <= visibleArea.Max) { data[i].Update(); } } } }
// Update is called once per frame void Update() { if (!testRun) { // IMPORTANT: As currently is, this kernel will be flipped vertically // (due to how this initialization is being done) GridArea area = new GridArea(new byte[5, 5] { { 1, 0, 0, 0, 1 }, { 0, 1, 0, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 0, 1, 0 }, { 1, 0, 0, 0, 1 } }); area.pivot = areaPivot; Grid.ActiveGrid.HighlightTiles(area.GetPlacement(position), GridTile.TileHighlights.AoE); testRun = true; } }
public static GridModel GetEmptyGrid(GridArea gridArea) { var ranList = new List <int>(); for (int i = 0; i < gridArea.TileCount; i++) { ranList.Add(i); } ranList.Shuffle(); foreach (var i in ranList) { var t = gridArea.Grids[i]; if (t.IsEmpty()) { return(t); } } return(null); }
public GridArea GetArea(int id) { GridArea area = m_areaList.Find((x) => x.id == id); return(area); }
public void TestSample1() { // Remove the converter for the Fanoe starter kit GridContext.Current.Converters.Remove <FanoeGridConverter>(); Assert.AreEqual(1, GridContext.Current.Converters.Count); // Load the JSON string json = File.ReadAllText(PathResolver.MapPath("~/Samples/Sample1.json")); // Get the Grid model GridDataModel model = GridDataModel.Deserialize(json); Assert.IsNotNull(model); Assert.AreEqual(1, model.Sections.Length); Assert.AreEqual(7, model.Sections[0].Rows.Length); GridControl[] controls = model.GetAllControls(); Assert.AreEqual(14, controls.Length); Hest(controls[0], "headline", typeof(GridControlTextValue), typeof(GridEditorTextConfig)); Hest(controls[1], "quote", typeof(GridControlTextValue), typeof(GridEditorTextConfig)); Hest(controls[2], "banner_headline"); Hest(controls[3], "banner_tagline"); Hest(controls[4], "rte", typeof(GridControlRichTextValue)); Hest(controls[5], "rte", typeof(GridControlRichTextValue)); Hest(controls[6], "rte", typeof(GridControlRichTextValue)); Hest(controls[7], "rte", typeof(GridControlRichTextValue)); Hest(controls[8], "rte", typeof(GridControlRichTextValue)); Hest(controls[9], "media_wide"); Hest(controls[10], "rte", typeof(GridControlRichTextValue)); Hest(controls[11], "rte", typeof(GridControlRichTextValue)); Hest(controls[12], "rte", typeof(GridControlRichTextValue)); Hest(controls[13], "media", typeof(GridControlMediaValue), typeof(GridEditorMediaConfig)); { Assert.AreEqual(JsonConvert.SerializeObject(model, Formatting.None), model.JObject.ToString(Formatting.None)); Assert.AreEqual(JsonConvert.SerializeObject(model.Sections[0], Formatting.None), model.Sections[0].JObject.ToString(Formatting.None)); GridRow row = model.Sections[0].Rows[6]; Assert.AreEqual("Hest", row.Name); Assert.AreEqual(2, row.Areas.Length); Assert.AreEqual(true, row.HasAreas); Assert.AreEqual(0, row.Styles.Count); Assert.AreEqual(1, row.Config.Count); Assert.AreEqual("dark", row.Config["class"]); Assert.AreEqual(JsonConvert.SerializeObject(row, Formatting.None), row.JObject.ToString(Formatting.None)); GridArea area1 = model.Sections[0].Rows[6].Areas[0]; Assert.AreEqual(4, area1.Grid); Assert.AreEqual(1, area1.Controls.Length); Assert.AreEqual("Hest", area1.Row.Name); Assert.AreEqual(4, area1.Grid); Assert.AreEqual(1, area1.Config.Count); Assert.AreEqual(1, area1.Styles.Count); Assert.AreEqual("yellow", area1.Config["class"]); Assert.AreEqual("150px", area1.Styles["margin-bottom"]); Assert.AreEqual(JsonConvert.SerializeObject(area1, Formatting.None), area1.JObject.ToString(Formatting.None)); GridArea area2 = model.Sections[0].Rows[6].Areas[1]; Assert.AreEqual(8, area2.Grid); Assert.AreEqual(0, area2.Controls.Length); Assert.AreEqual(JsonConvert.SerializeObject(area2, Formatting.None), area2.JObject.ToString(Formatting.None)); } }