public Quaternion Rotation(float RailZ) { float localway; IRail segment = Way2Segment(RailZ, out localway); return(segment.Rotation(localway)); }
public float Height(float RailZ) { float localway; IRail segment = Way2Segment(RailZ, out localway); return(segment.Height(localway)); }
public StationsController(IRail rail, IGoogle google, IStaticStations staticStations, ILogger <StationsController> logger) { _rail = rail; _google = google; _staticStations = staticStations; _logger = logger; }
public static bool DoRailsAttach(GameObject go1, GameObject go2) { IRail rail1 = go1 as IRail, rail2 = go2 as IRail; if (rail1 == null || rail2 == null) { throw new ArgumentException("Gameobjects must implement IRail interface to be compared"); } foreach (Rotation rail1Rot in RailDirectionToRotation(rail1.RailDirection)) { if (new Rectangle(GetOffsetForRotation(rail1Rot, go1.Location), new Size(1, 1)).IntersectsWith(go2.Rectangle)) { Rotation opposite = OppositeRotation(rail1Rot); foreach (Rotation rail2Rot in RailDirectionToRotation(rail2.RailDirection)) { if (rail2Rot == opposite) { return(true); } } break; } } return(false); }
void Generate() { IRail Rail = railBehaviour as IRail; if (Rail == null) { Rail = RailManager.instance; } Mesh mesh = new Mesh(); Vector3[] originalverts = original.vertices.ToArray(); Vector3[] originalnorms = original.normals.ToArray(); /* * if (InvertYZ) * { * originalverts = originalverts.Select((vec) => { return new Vector3(-vec.x, vec.z, vec.y); }).ToArray(); * originalnorms = originalnorms.Select((vec) => { return new Vector3(-vec.x, vec.z, vec.y); }).ToArray(); * } */ List <Vector3> verts = new List <Vector3>(); List <int> triangles = new List <int>(); List <Vector2> uvs = new List <Vector2>(); List <Vector3> normals = new List <Vector3>(); List <Color> colors = new List <Color>(); for (int i = 0; i < Loop; i++) { verts.AddRange(originalverts.Select((Vector3 vec) => { vec.Scale(Scale); vec += OffSet + Span * i; vec.y += Rail.Height(vec.z); return(Rail.Local2World(vec)); })); triangles.AddRange(original.triangles.Select((int x) => { return(x + originalverts.Length * i); })); uvs.AddRange(original.uv.ToList()); normals.AddRange(originalnorms.Select((norm, index) => { Quaternion qt = Rail.Rotation(originalverts[index].z + OffSet.z + Span.z * i); return(qt * norm); })); colors.AddRange(original.colors.ToList()); } mesh.vertices = verts.ToArray(); mesh.triangles = triangles.ToArray(); mesh.uv = uvs.ToArray(); mesh.normals = normals.ToArray(); mesh.colors = colors.ToArray(); mesh.RecalculateBounds(); MeshFilter filter = GetComponent <MeshFilter>(); filter.sharedMesh = mesh; MeshCollider coll = GetComponent <MeshCollider>(); if (coll != null) { coll.sharedMesh = mesh; } }
public RoutesController(IRail rail, IRailRouteBuilder railRouteBuilder, IStaticStations staticStations, ITime time, ILogger <RoutesController> logger) { _rail = rail; _railRouteBuilder = railRouteBuilder; _staticStations = staticStations; _time = time; _logger = logger; }
public bool IsOnHold(IRail obj) { if (obj.Equals(OnHold)) { return(true); } return(false); }
public Vector3 Local2World(Vector3 LocalPosition) { float localway; IRail segment = Way2Segment(LocalPosition.z, out localway); LocalPosition.z = localway; return(segment.Local2World(LocalPosition)); }
public void RemoveRail(IRail targetrail) { if (!Childs.Contains(targetrail)) { return; } Childs.Remove(targetrail); Length -= targetrail.Length; }
public static TrainNetwork GetNetworkForRail(IRail rail) { foreach (TrainNetwork network in _networks) { if (network.HasRail(rail)) { return(network); } } return(null); }
public void AddRail(IRail rail) { foreach (var r in chainRail.Segments) { if ((r as MarginRail).Rail == rail) { return; } } chainRail.AddRail(new MarginRail(rail)); }
void Awake() { if (railBehaviour == null) { rail = RailManager.instance; } else { rail = railBehaviour; } rigidbody = GetComponent <Rigidbody>(); }
private static void Grid_RailAdded(RailArgs railArgs) { IRail iRail = railArgs.Rail; if (iRail == null) { return; } Rotation[] sides = railArgs.Sides; TrainNetwork network = null; foreach (Rotation rot in sides) { GridObject go = _grid[RailUtils.GetOffsetForRotation(rot, railArgs.RawObject.Location)]; if (go == null || go == iRail) { continue; } IRail rail2 = go as IRail; if (rail2 == null) { continue; } TrainNetwork newNetwork = GetNetworkForRail(rail2); if (network == null) { if (RailUtils.DoRailsAttach(railArgs.RawObject, go)) { network = newNetwork; network.Add(iRail); } } else if (newNetwork != network) { network = CombineNetwork(network, newNetwork); } } if (network == null) { TrainNetwork newNetwork = new TrainNetwork(); //No need to register the object, it does so himself in its constructor newNetwork.Add(iRail); } Rail rail = iRail as Rail; if (rail != null) { rail.RailUpdated += rail_RailUpdated; } }
public void RemoveRail(IRail rail) { IRail target = null; foreach (var r in chainRail.Segments) { if ((r as MarginRail).Rail == rail) { target = r; } } if (target == null) { return; } RemoveRail(target); }
/// <summary> /// Gets the directions for the trains current location in the grid /// </summary> /// <param name="train">The train that you would like to check its directions for</param> /// <returns>An array with Rotation values that indicate where the train can go. Empty array if not successfull</returns> public static Rotation[] GetDirections(Train train) { Point location = train.Location; GridObject go = _grid[location]; if (go == null) { return(new Rotation[0]); } IRail rail = go as IRail; if (rail == null) { return(new Rotation[0]); } return(RailUtils.RailDirectionToRotation(rail.RailDirection, RailUtils.OppositeRotation(train.Direction))); }
private void Move(IRail move) { if (move == null) { Move(); } if (!(move is Dock) && !(move is ShipRail)) { Move(); } if (move is Dock || move is ShipRail) { var temp = this; this._currentRail.ContainsMoveableObject = null; move.ContainsMoveableObject = temp; temp._currentRail = move; if (move is Dock) { Dock d = (Dock)move; d.ContainsShip = this; _currentRail = d; d.SetSideIcons(); } } try { if (move.Below is Dock && move is ShipRail) { var temp = this; this._currentRail.ContainsMoveableObject = null; move.Below.ContainsMoveableObject = temp; temp._currentRail = move.Below; Dock d = (Dock)move.Below; d.ContainsShip = this; _currentRail = d; d.SetSideIcons(); } } catch (Exception e) { Move(); } }
public RailArgs(GameObject raw) { if (raw == null) { throw new ArgumentException("Arguments 'rail' and 'raw' may not be null!"); } IRail rail = raw as IRail; if (rail == null) { throw new ArgumentException("Arguments 'rail' and 'raw' may not be null!"); } this._rail = rail; this._raw = raw; //generate on request _sides = null; }
public StaticStationsRepository(IRail rail) { _rail = rail; GetStationsInforResponse stationsInfo = _rail.GetStationsInfor(Enum.GetValues(typeof(E_Station)).Cast <E_Station>()).Result; IEnumerable <GetStationsInforResponseData> stations = stationsInfo.Data.OrderBy(x => x.Hebrew.StationName); _stations = new List <StationLightData>(); foreach (GetStationsInforResponseData s in stations) { StationLightData lightData = new StationLightData() { Station = (E_Station)int.Parse(s.StationCode), Name = s.Hebrew.StationName, Latitude = s.General.Lat, Longitude = s.General.Long }; _stations.Add(lightData); } }
private void UnregisterObject(GameObject go) { IUpdateable updateable = go as IUpdateable; if (updateable != null && _updateableObjects.Contains(updateable)) { _updateableObjects.Remove(updateable); } IRail rail = go as IRail; if (rail != null && RailRemoved != null) { RailRemoved(new RailArgs(go)); } if (ObjectRemoved != null) { ObjectRemoved(go); } }
public void CreateLinks(char[,] level) { for (int row = 0; row < level.GetLength(0); row++) // for each row { for (int coll = 0; coll < level.GetLength(1); coll++) // for each column of current row { if (level[row, coll].Equals((char)Symbols.SwitchDown) || level[row, coll].Equals((char)Symbols.SwitchUp)) { IRail switchRail = CheckForSwitch(level[row, coll], level[row - 1, coll], level[row + 1, coll]); if (switchRail != null) { LinkLogic(switchRail, row, true); continue; } } LinkLogic(GetObject(level[row, coll]), row, false); } } }
/// <summary> /// Do some general registering for all gameobjects /// </summary> /// <param name="go">The game object that is registered</param> private void RegisterObject(GameObject go) { IUpdateable updateable = go as IUpdateable; if (updateable != null) { if (!_updateableObjects.Contains(updateable)) { _updateableObjects.Add(updateable); } } IRail rail = go as IRail; if (rail != null && RailAdded != null) { RailAdded(new RailArgs(go)); } if (ObjectAdded != null) { ObjectAdded(go); } }
public Direction GetNextDirection(Direction lastMove) { switch (lastMove) { case Direction.Up: _moveTo = _currentRail.Next; return(Direction.Right); case Direction.Right: _moveTo = _currentRail.Below; return(Direction.Down); case Direction.Down: _moveTo = _currentRail.Previous; return(Direction.Left); case Direction.Left: _moveTo = _currentRail.Above; return(Direction.Up); default: return(Direction.Up); } }
static void rail_RailUpdated(RailArgs args) { Rotation[] sides = args.Sides; TrainNetwork network = GetNetworkForRail(args.Rail); foreach (Rotation side in sides) { GameObject go = _grid[RailUtils.GetOffsetForRotation(side, args.RawObject.Location)]; if (go == null) { continue; } IRail rail = go as IRail; if (rail == null) { continue; } TrainNetwork compareNetwork = GetNetworkForRail(rail); if (network != compareNetwork) { CombineNetwork(network, compareNetwork); } } }
public static void RemoveRail(IRail rail) { instance.compositeRail.RemoveRail(rail); }
public static void AddRail(IRail newrail) { instance.compositeRail.AddRail(newrail); }
public MarginRail(IRail original) { Rail = original; }
public bool HasRail(IRail rail) { return(_rails.Contains(rail)); }
public bool IsOnHold(IRail obj) { return(false); }
/// <summary> /// Creates all the links necessary for the functionality of the game /// </summary> public void LinkLogic(IRail obj, int posInRow, bool isSwitch) { // execute logic per instance of the IRail Object if (_mainModel.EndOflevelLink == null) { _mainModel.EndOflevelLink = obj; _prevObj = _mainModel.EndOflevelLink; _firstInCurrentRow = obj; return; } else if (posInRow == 0) { _prevObj.Next = obj; obj.Previous = _prevObj; _prevObj = obj; _prevPos = posInRow; return; } // new row if (_prevPos != posInRow) { // reset first in current and previous _firstInPreviousRow = _firstInCurrentRow; _firstInCurrentRow = obj; // set links to above and below for first and previous _firstInCurrentRow.Above = _firstInPreviousRow; _firstInPreviousRow.Below = _firstInCurrentRow; // set previous row and object _prevObj = _firstInCurrentRow; _prevPos = posInRow; return; } // set previous & next relation obj.Previous = _prevObj; _prevObj.Next = obj; // set above & below relation int counter = 0; var temp = obj; while (temp.Previous != null) { temp = temp.Previous; counter++; } var match = _firstInPreviousRow; for (int x = 0; x < counter; x++) { if (match.Next == null) { break; } match = match.Next; } if (isSwitch) { _mainModel.GetSwitch(_currSwitch).OnHold = match; } obj.Above = match; match.Below = obj; _prevObj = obj; }
public void AddRail(IRail newrail) { Childs.Add(newrail); Length += newrail.Length; }