public void StopPlayRail() { if (Rail.isPlaying) { Rail.Stop(); } }
Tile FindNextTile() { Tile nextTile = null; Vector2Int inDirection = lastTile.coords - currentTile.coords; Vector2Int[] currentRailDirections = Rail.RailDirections(currentTile.rail.type); Vector2Int outDirection = Vector2Int.zero; if (Math.Parallell(new Vector3(currentRailDirections[0].x, 0, currentRailDirections[0].y), new Vector3(inDirection.x, 0, inDirection.y))) { outDirection = currentRailDirections[1]; } else if (Math.Parallell(new Vector3(currentRailDirections[1].x, 0, currentRailDirections[1].y), new Vector3(inDirection.x, 0, inDirection.y))) { outDirection = currentRailDirections[0]; } else { Debug.LogWarning("!!!! "); } Vector2Int nextTileCoords = currentTile.coords + outDirection; nextTile = grid.tiles[nextTileCoords.x, nextTileCoords.y]; return(nextTile); }
public void StartPlayRail() { if (!Rail.isPlaying) { Rail.Play(); } }
bool InitPlayerPosition() { int index = 0; foreach (var rail in mRails) { if (rail.Index == "0.5") { mActualRail = rail; break; } index++; } if (mActualRail == null) { return(false); } mActualIndexRail = index; mNextRail = mActualRail; if (!Player) { Player = Camera.main.gameObject; } Player.transform.position = mActualRail.Points[0].position; Player.transform.LookAt(mActualRail.Points[1]); mActualIndexPoint = mActualRail.Points[0]; return(true); }
private void BeginRailMotion() { _railIndex = 0; currentRail = rails[_railIndex]; transform.position = currentRail.BakedPoints[0]; //transform.LookAt(currentRail.BakedPoints[1]); }
void CreateNewWagon(Rail rail) { const float wagonCost = 10f; if (Player.score < wagonCost) // check if enough money { ScoreText.color = Color.red; UserInformationText.text = "You do not have enough money to place a train wagon."; return; } if (rail.CurrentNumberOfWagons() >= rail.MaxNrOfWagons()) // also check if rail still has room for more trains // Debug.Log("Too many wagons already on this track, I'm not gonna put any more"); { UserInformationText.text = "Reached the maximum number of wagons on this track."; // have some player information here that its not possible return; } Player.score -= wagonCost; updateScore(); UserInformationText.text = "You placed a train wagon. This cost you " + (int)wagonCost + ".- CHF."; rail.AddWagon(); }
public void SetPathStrokeToRailPath(Rail rail, Path path) { path.Stroke = SetStrokeColorForRail(rail); double thickness = 1.0; if (rail.TopRankedEdgeInfoOfTheRail != null) { thickness = Math.Max(5 - Math.Log(rail.MinPassingEdgeZoomLevel, 2), 1); } path.StrokeThickness = thickness * PathStrokeThickness / 2; // todo : figure out a way to do it nicer than dividing by 2 foreach (var style in Edge.Attr.Styles) { if (style == Drawing.Style.Dotted) { path.StrokeDashArray = new DoubleCollection { 1, 1 }; } else if (style == Drawing.Style.Dashed) { var f = DashSize(); path.StrokeDashArray = new DoubleCollection { f, f }; //CurvePath.StrokeDashOffset = f; } } }
bool RailIsConnected(Rail rail, bool atRailExit) { Tile railTile = rail.GetComponent <Tile>(); // Find the adjacent tile in the specified direction int connectionDirection = atRailExit ? rail.exitDirection : rail.entryDirection; connectionDirection += railTile.direction; connectionDirection %= 4; Vector2Int adjacentTileCoords = railTile.tileCoords + DirectionToVector(connectionDirection); if (!tileManager.IsWithinArray(adjacentTileCoords)) { return(false); } Tile adjacentTile = tileManager.GetTile(adjacentTileCoords); // Check if it has a connecting rail Rail[] adjacentRails = adjacentTile.GetComponents <Rail>(); int adjacentConnectionDirection = (connectionDirection + 2 - adjacentTile.direction + 4) % 4; foreach (Rail adjacentRail in adjacentRails) { if (adjacentRail.entryDirection == adjacentConnectionDirection || adjacentRail.exitDirection == adjacentConnectionDirection) { return(true); } } return(false); }
public void TrackRail(Rail rail) { if (!rails.Contains(rail)) { rails.Add(rail); } }
HitTestResultBehavior NodeOrRailHitTestSelOnlyOneNodeCallback(HitTestResult result) { var frameworkElement = result.VisualHit as FrameworkElement; if (!(frameworkElement is Path)) { return(HitTestResultBehavior.Continue); } object tag = frameworkElement.Tag; if (tag != null) { GraphmapsNode graphmapsNode = tag as GraphmapsNode; if (graphmapsNode != null) { _nodeUnderMouse = graphmapsNode; return(HitTestResultBehavior.Stop); } else { var rail = frameworkElement.Tag as Rail; if (rail != null) { _railUnderMouse = rail; } } } return(HitTestResultBehavior.Continue); }
//When the scene draws void OnSceneGUI() { //Get the rail m_Rail = target as Rail; if (m_Rail == null) { return; } m_Points = m_Rail.points; m_HandleTransform = m_Rail.transform; m_HandleRotation = Tools.pivotRotation == PivotRotation.Local ? m_HandleTransform.rotation : Quaternion.identity; //Draw the points, and allow the editor to move these points if (m_Points.Length > 3) { Vector3 point0 = ShowPoint(0); for (int i = 1; i < m_Points.Length; i += 3) { Vector3 point1 = ShowPoint(i); Vector3 point2 = ShowPoint(i + 1); Vector3 point3 = ShowPoint(i + 2); Handles.DrawBezier(point0, point3, point1, point2, Color.cyan, null, 2f); point0 = point3; } } }
//Add buttons to grow or shrink the rail public override void OnInspectorGUI() { DrawDefaultInspector(); m_Rail = target as Rail; if (m_Rail == null) { return; } m_Points = m_Rail.points; if (GUILayout.Button("Add Curve to Beginning")) { Undo.RecordObject(m_Rail, "Add Curve to Beginning"); AddCurveToBeginning(); EditorUtility.SetDirty(m_Rail); } else if (GUILayout.Button("Add Curve To End")) { Undo.RecordObject(m_Rail, "Add Curve To End"); AddCurveToEnd(); EditorUtility.SetDirty(m_Rail); } else if (GUILayout.Button("Remove Curve From Beginning")) { Undo.RecordObject(m_Rail, "Remove Curve From Beginning"); RemoveCurveFromBeginning(); EditorUtility.SetDirty(m_Rail); } else if (GUILayout.Button("Remove Curve From End")) { Undo.RecordObject(m_Rail, "Remove Curve From End"); RemoveCurveFromEnd(); EditorUtility.SetDirty(m_Rail); } }
private void OnSelectionChange() { var obj = Selection.activeGameObject; if (obj == null) { CleanUp(); return; } if (obj.layer != LayerMask.NameToLayer(Layers.CameraConstraint)) { CleanUp(); return; } _cameraConstraint = obj.GetComponent <Rail>(); if (_cameraConstraint == null) { CleanUp(); return; } _zoomConstraint = obj.GetComponent <CameraZoomConstraint>(); }
private Rail GetFastestRail(int index) { var totalRails = (int)Math.Ceiling(((decimal)this.Count / 5000)); if (rails.Count < totalRails) { rails.Add(new Rail(first, last, count)); } if (lastUsedRail == null) { lastUsedRail = rails[0]; } int minDistance = Math.Abs(lastUsedRail.ClusterStartIndex - index); Rail fastestRail = lastUsedRail; foreach (var rail in rails) { if (minDistance <= Cluster.StorageSize * 2) { break; } int distance = Math.Abs(rail.ClusterStartIndex - index); if (distance < minDistance) { minDistance = distance; fastestRail = rail; } } lastUsedRail = fastestRail; return(fastestRail); }
public virtual void DisconnectFromRail() { AttachedRail.NodesRemoved -= RailRemovedNodes; AttachedRail = null; StartCoroutine(DisableAttachToRail()); //RailSpeed = Mathf.Clamp(RailSpeed, Speed * 0.5f, Speed * 1.5f); }
public static Path CreateEdgeRail(Rail rail, byte edgeTransparency, double pathStrokeThickness) { var railGeometryCurve = rail.Geometry as ICurve; Path edgeRailPath; if (railGeometryCurve is null) { var arrowhead = rail.Geometry as Arrowhead; if (arrowhead != null) { edgeRailPath = CreateEdgeRailArrowhead(rail, arrowhead, rail.CurveAttachmentPoint, edgeTransparency, pathStrokeThickness); } else { throw new InvalidOperationException(); } } else { edgeRailPath = CreateFrameworkElementForRailCurve(rail, railGeometryCurve, edgeTransparency); } edgeRailPath.Tag = rail; return(edgeRailPath); }
private void CreateRails() { FVec3 worldOffset = this._maze.LocalPointToGlobalPoint(new FVec3(this._maze.startPointPlace[0] * Fix64.Half, Fix64.Zero, this._maze.startPointPlace[1] * Fix64.Half)); FVec3 center = this._maze.centerOfStartRange; FVec3[] positions = new FVec3[4]; positions[0] = new FVec3(center.x, center.y, center.z + worldOffset.z); positions[1] = new FVec3(center.x + worldOffset.x, center.y, center.z); positions[2] = new FVec3(center.x, center.y, center.z - worldOffset.z); positions[3] = new FVec3(center.x - worldOffset.x, center.y, center.z); FVec3[] offset = new FVec3[4]; offset[0] = new FVec3(0, 0, 0.5f); offset[1] = new FVec3(0.5f, 0, 0); offset[2] = new FVec3(0, 0, -0.5f); offset[3] = new FVec3(-0.5f, 0, 0); FVec3[] directions = new FVec3[4]; directions[0] = FVec3.backward; directions[1] = FVec3.left; directions[2] = FVec3.forward; directions[3] = FVec3.right; for (int i = 0; i < 4; i++) { EntityParam param = new EntityParam(); param.rid = (i % 2 == 0 ? "_c0@" : "_c0_1@") + i; param.position = positions[i]; param.direction = directions[i]; Rail rail = this._entityManager.Create <Rail>(param); rail.position += offset[i] * rail.bounds.size; } }
void WriteRail(Rail rail, int railId) { WriteStartElement(GeometryToken.Rail); WriteAttribute(GeometryToken.Id, railId); WriteAttribute(GeometryToken.Zoomlevel, rail.ZoomLevel); if (rail.MinPassingEdgeZoomLevel != Double.MaxValue) { WriteAttribute(GeometryToken.MinPassingEdgeZoomLevel, rail.MinPassingEdgeZoomLevel); } Arrowhead ah = rail.Geometry as Arrowhead; if (ah != null) { WriteStartElement(GeometryToken.Arrowhead); WriteAttribute(GeometryToken.ArrowheadPosition, ah.TipPosition); WriteAttribute(GeometryToken.CurveAttachmentPoint, rail.CurveAttachmentPoint); WriteEndElement(); } else { ICurve curve = rail.Geometry as ICurve; if (curve != null) { WriteICurve(curve); } else { throw new InvalidOperationException(); } } WriteEndElement(); }
private void LateUpdate() { if (speed == 0) { return; } _time += Time.deltaTime * speed; if (_time > 1f) { _time = 1f; } Vector3 nextPosition = currentRail.GetPointAtTime(_time); Vector3 nextPoint = _time == 0 ? currentRail.BakedPoints[1] : currentRail.GetPointAtTime(_time + Time.deltaTime * speed); transform.position = Vector3.MoveTowards(transform.position, nextPosition, _time); //Quaternion lookRot = Quaternion.LookRotation(nextPoint, ); //transform.rotation = Quaternion.RotateTowards(transform.rotation, lookRot, Time.deltaTime * 1000f); //transform.LookAt(nextPoint); if (_time >= 1f) { if (_railIndex + 1 < rails.Length) { _railIndex++; _time = 0f; } currentRail = rails[_railIndex]; } }
private void Disconnect(float proposedGravity, float speed) { Gravity = proposedGravity; GravitySpeed = speed; lastRail = AttachedRail; DisconnectFromRail(); }
// Start is called before the first frame update void Start() { music = GetComponent <AudioSource>(); currentRail = FindObjectOfType <LevelSettings>().startRail; // gather all level objects StartCoroutine(startPlaying()); }
private void GetRailGridFromFile(TextAsset level) { string[] lines = SplitOnNewline(level.text); int gridHeight = lines.Length; int gridWidth = lines[0].Length; railGrid = new Rail[gridHeight, gridWidth]; for (int y = 0; y < gridHeight; y++) { string line = lines[y]; for (int x = 0; x < gridWidth; x++) { Vector3 pos = new Vector3(x * cellSize, 0, y * cellSize); char railChar = line[x]; Rail rail = GetRail(railChar, pos); railGrid[y, x] = rail; if (rail != null) { _waypoints.AddRange(rail.GetWaypoints()); } } } WeldRailParts(); }
/// <summary> /// Create framework element for rail. /// </summary> /// <param name="rail">Rail for which to create element.</param> /// <param name="edgeTransparency">Edge transparency.</param> /// <returns>Framework element.</returns> public FrameworkElement CreateFrameworkElementForRail(Rail rail, byte edgeTransparency) { var curve = rail.Geometry as ICurve; Path fe; if (curve != null) { fe = (Path)this.CreateFrameworkElementForRailCurve(rail, curve, edgeTransparency); } else { var arrowhead = rail.Geometry as Arrowhead; if (arrowhead != null) { fe = (Path)this.CreateFrameworkElementForRailArrowhead(rail, arrowhead, rail.CurveAttachmentPoint, edgeTransparency); } else { throw new InvalidOperationException(); } } fe.Tag = rail; return(fe); }
public void FireWeapon(Destroyable target, Weapon weapon) { if (weapon == Weapon.Missile && CanMissileFire) { Missile missile1 = (Missile)MissileScene.Instance(); missile1.Homing = MissileHoming; missile1.Target = target; missile1.GlobalRotation = GlobalRotation; missile1.Position = GlobalPosition; missile1.Position += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90)); missile1.Velocity = Velocity; missile1.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(90)), ProjectileEjectionForce); GetParent().AddChild(missile1); Missile missile2 = (Missile)MissileScene.Instance(); missile2.Homing = MissileHoming; missile2.Target = target; missile2.GlobalRotation = GlobalRotation; missile2.Position = GlobalPosition; missile2.Position += new Vector2(MissileOffset, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90)); missile2.Velocity = Velocity; missile2.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + Mathf.Deg2Rad(-90)), ProjectileEjectionForce); GetParent().AddChild(missile2); CanMissileFire = false; missileCooldownTimer.Start(MissileCooldown); } else if (weapon == Weapon.Laser && CanLaserFire) { if (target is SpaceDamagable damagable) { beam.AddPoint(target.GlobalPosition - GlobalPosition); damagable.Hit(); CanLaserFire = false; laserCooldownTimer.Start(LaserCooldown); } } else if (weapon == Weapon.Railgun && CanRailgunFire) { Rail rail = (Rail)RailScene.Instance(); rail.PartialHoming = RailHoming; rail.Velocity = Velocity; if (target != null) { rail.Target = target; rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition()); rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce); } else { rail.GlobalRotation = GlobalRotation + GetAngleTo(GetGlobalMousePosition()); rail.AddForce(new Vector2(1, 0).Rotated(GlobalRotation + GetAngleTo(GetGlobalMousePosition())), RailEjectionForce); } rail.Position = GlobalPosition; GetParent().AddChild(rail); CanRailgunFire = false; railgunCooldownTimer.Start(RailgunCooldown); } }
public IOHandler() { RaspberryPi.Initialize(); this.I2C = new I2CBusPi(); this.SPI = new SPIBusPi(0); this.PWMGenHighFreq = new PCA9685(this.I2C, 0x4C, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain); this.PWMGenLowFreq = new PCA9685(this.I2C, 0x74, -1, PCA9685.OutputInvert.Inverted, PCA9685.OutputDriverMode.OpenDrain); this.PWMGenHighFreq.SetFrequency(333); this.PWMGenLowFreq.SetFrequency(50); this.RailController = new Rail(this.PWMGenHighFreq.Outputs[0], new DigitalInPi(11), this.SPI, new DigitalOutPi(29), this.I2C, null) { TraceLogging = true }; this.DrillController = new Drill(this.PWMGenHighFreq.Outputs[1], this.PWMGenLowFreq.Outputs[0]); this.SampleController = new Sample(this.PWMGenLowFreq.Outputs[1]); this.LEDController = new LEDs(this.PWMGenLowFreq.Outputs, this.PWMGenHighFreq.Outputs); this.AuxSensors = new AuxSensors(this.SPI, this.I2C) { TraceLogging = false }; this.SysSensors = new SysSensors(); this.Music = new MusicPlayer(); this.InitProcedure = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors, this.Music }; this.EStopProcedure = new ISubsystem[] { this.Music, this.RailController, this.DrillController, this.LEDController, this.AuxSensors, this.SysSensors }; this.UpdateProcedure = new ISubsystem[] { this.RailController, this.DrillController, this.LEDController /*, this.AuxSensors, this.SysSensors*/ }; if (this.EStopProcedure.Length < this.InitProcedure.Length || this.EStopProcedure.Length < this.UpdateProcedure.Length) { throw new Exception("A system is registered for init or updates, but not for emergency stop. For safety reasons, this is not permitted."); } }
private void ChaikinSplit(Rail OldPath, ref Rail NewPath, int Index)//lol { KeyFrame NewNode = NewPath.frames[Index].DeepCopy(); int NewNodeIndex = NewPath.frames.Length; NewPath.InsertFrame(NewNode, NewPath.frames.Length);//Add node at the end to not change the indicies KeyFrame MiddleKeyFrame = OldPath.frames[Index]; KeyFrame FirstKeyframe = OldPath.frames[MiddleKeyFrame.connections[0]]; KeyFrame LastKeyFrame = OldPath.frames[MiddleKeyFrame.connections[1]]; NewPath.frames[Index].x = (short)(0.25 * FirstKeyframe.x + 0.75 * MiddleKeyFrame.x); NewPath.frames[Index].y = (short)(0.25 * FirstKeyframe.y + 0.75 * MiddleKeyFrame.y); NewPath.frames[Index].z = (short)(0.25 * FirstKeyframe.z + 0.75 * MiddleKeyFrame.z); NewPath.frames[NewNodeIndex].x = (short)(0.25 * LastKeyFrame.x + 0.75 * MiddleKeyFrame.x); NewPath.frames[NewNodeIndex].y = (short)(0.25 * LastKeyFrame.y + 0.75 * MiddleKeyFrame.y); NewPath.frames[NewNodeIndex].z = (short)(0.25 * LastKeyFrame.z + 0.75 * MiddleKeyFrame.z); NewPath.frames[Index].connections[1] = (short)NewNodeIndex; NewPath.frames[NewNodeIndex].connections[0] = (short)Index; int ConnectToMiddleIndexOfIndex = -1; for (int i = 0; i < LastKeyFrame.connections.Length; i++) { if (LastKeyFrame.connections[i] == (short)Index) { ConnectToMiddleIndexOfIndex = i; } } if (ConnectToMiddleIndexOfIndex != -1) { NewPath.frames[MiddleKeyFrame.connections[1]].connections[ConnectToMiddleIndexOfIndex] = (short)NewNodeIndex; } }
// This should only be done if RailIsConnected check returns true void TransferToNextRail(bool atRailExit) { Tile railTile = currentRail.GetComponent <Tile>(); // Find the adjacent tile in the specified direction int connectionDirection = atRailExit ? currentRail.exitDirection : currentRail.entryDirection; connectionDirection += railTile.direction; connectionDirection %= 4; Vector2Int adjacentTileCoords = railTile.tileCoords + DirectionToVector(connectionDirection); Tile adjacentTile = tileManager.GetTile(adjacentTileCoords); // Transfer to the connecting rail Rail[] adjacentRails = adjacentTile.GetComponents <Rail>(); int adjacentConnectionDirection = (connectionDirection + 2 - adjacentTile.direction + 4) % 4; foreach (Rail adjacentRail in adjacentRails) { if (adjacentRail.entryDirection == adjacentConnectionDirection || adjacentRail.exitDirection == adjacentConnectionDirection) { bool atAdjacentRailExit = (adjacentConnectionDirection == adjacentRail.exitDirection); float overshoot = atRailExit ? railDistance - currentRail.trackLength : -railDistance; currentRail = adjacentRail; railDistance = atAdjacentRailExit ? adjacentRail.trackLength - overshoot : overshoot; if (atRailExit == atAdjacentRailExit) { alignedWithRail = !alignedWithRail; } } } }
private void ConnectMeToListOfNodes(List <NodeAndDistance> closestNodes) { for (int i = 0; i < closestNodes.Count; i++) { Rail newRail = RailGeneratorManager.GetNewRail(); newRail.initialize(this, closestNodes[i].node); } }
// Start is called before the first frame update void Start() { TryGetComponent <AudioSource>(out pressedSound); TryGetComponent <SpriteRenderer>(out spriteRenderer); thisRail = GetComponentInParent <Rail>(); gmCtrl = FindObjectOfType <GameController>(); gmCtrl.collectibleCount++; }
public Rail GetOneRailInsideRect(RectangleGeometry rect) { _railUnderMouse = null; VisualTreeHelper.HitTest(_graphCanvas, null, RailHitTestSelOneResultCallback, new GeometryHitTestParameters(rect)); return(_railUnderMouse); }
public void InitAsSender(Rail rail) { isMoving = false; startingRail = rail; currentRail = rail; startingPosition = rail.transform.position; minecartAnimator = GetComponent<Animator>(); currentStep = 0; }
// Use this for initialization void Start() { soundIsPlaying = false; railConnector = GetComponent<RailConnection>(); railPoint = GetComponent<Rail>(); //railConnector.ConnectToNext(); //endRailConnector.ConnectToPrev(); }
void Move(float verticalAxis) { // Decide which way rail we are moving towards (Towards Next or Previous rail) Rail railMoveTowards = null; // Hopefully not null afterwards if (currentStep > 0) railMoveTowards = currentRail.next; else if (currentStep < 0) railMoveTowards = currentRail.prev; else if (currentStep == 0 && verticalAxis > 0) railMoveTowards = currentRail.next; else if (currentStep == 0 && verticalAxis < 0) railMoveTowards = currentRail.prev; else Debug.LogError("Movement went terrible wrong, this should not be possible!"); if(railMoveTowards != null) { // Find distance between Current Rail and the Next Rail for Normalize amount of movement float length = Vector3.Distance(currentRail.transform.position, railMoveTowards.transform.position); // Set the currentStep (t) to move towards verticalAxis with normalize distance of the two rails, times acceleration and animationSpeed. currentStep += (1 / length) * verticalAxis * movementSpeed * 0.0075f * (Time.deltaTime * 1000) * (Input.GetKey(KeyCode.R) ? 10f:1f); // Set new position using the currentStep and move that position just a tad up transform.position = Vector3.Lerp(currentRail.transform.position, railMoveTowards.transform.position, Mathf.Abs(currentStep)) + (currentRail.transform.up / 4)*2; transform.rotation = Quaternion.Lerp(currentRail.transform.rotation, railMoveTowards.transform.rotation, Mathf.Abs(currentStep)); // Check if the cart have reached a rail and set that rail to the current rail. if (currentStep >= 1) { currentRail = currentRail.next; currentStep = 0; } else if(currentStep <= -1) { currentRail = currentRail.prev; currentStep = 0; } // Check if the cart have move beyond the starting point (In opposite direction) and save it else if(currentStep <= 0 && currentRail.Equals(startingRail)) { currentStep = 0; } //TODO Might be some issue with last rail point, haven't tested yet! // Set minecart animation speed minecartAnimator.speed = (movementSpeed) * verticalAxis; isMoving = true; } }
public static Block GetBlockById(byte blockId) { Block block = null; if (CustomBlockFactory != null) { block = CustomBlockFactory.GetBlockById(blockId); } if (block != null) return block; if (blockId == 0) block = new Air(); else if (blockId == 1) block = new Stone(); else if (blockId == 2) block = new Grass(); else if (blockId == 3) block = new Dirt(); else if (blockId == 4) block = new Cobblestone(); else if (blockId == 5) block = new Planks(); else if (blockId == 6) block = new Sapling(); else if (blockId == 7) block = new Bedrock(); else if (blockId == 8) block = new FlowingWater(); else if (blockId == 9) block = new StationaryWater(); else if (blockId == 10) block = new FlowingLava(); else if (blockId == 11) block = new StationaryLava(); else if (blockId == 12) block = new Sand(); else if (blockId == 13) block = new Gravel(); else if (blockId == 14) block = new GoldOre(); else if (blockId == 15) block = new IronOre(); else if (blockId == 16) block = new CoalOre(); else if (blockId == 17) block = new Log(); else if (blockId == 18) block = new Leaves(); else if (blockId == 19) block = new Sponge(); else if (blockId == 20) block = new Glass(); else if (blockId == 21) block = new LapisOre(); else if (blockId == 22) block = new LapisBlock(); else if (blockId == 23) block = new Dispenser(); else if (blockId == 24) block = new Sandstone(); else if (blockId == 25) block = new NoteBlock(); else if (blockId == 26) block = new Bed(); else if (blockId == 27) block = new GoldenRail(); else if (blockId == 28) block = new DetectorRail(); else if (blockId == 30) block = new Cobweb(); else if (blockId == 31) block = new TallGrass(); else if (blockId == 32) block = new DeadBush(); else if (blockId == 35) block = new Wool(); else if (blockId == 37) block = new YellowFlower(); else if (blockId == 38) block = new Flower(); else if (blockId == 39) block = new BrownMushroom(); else if (blockId == 40) block = new RedMushroom(); else if (blockId == 41) block = new GoldBlock(); else if (blockId == 42) block = new IronBlock(); else if (blockId == 43) block = new DoubleStoneSlab(); else if (blockId == 44) block = new StoneSlab(); else if (blockId == 45) block = new Bricks(); else if (blockId == 46) block = new Tnt(); else if (blockId == 47) block = new Bookshelf(); else if (blockId == 48) block = new MossStone(); else if (blockId == 49) block = new Obsidian(); else if (blockId == 50) block = new Torch(); else if (blockId == 51) block = new Fire(); else if (blockId == 52) block = new MonsterSpawner(); else if (blockId == 53) block = new OakWoodStairs(); else if (blockId == 54) block = new Chest(); else if (blockId == 55) block = new RedstoneWire(); else if (blockId == 56) block = new DiamondOre(); else if (blockId == 57) block = new DiamondBlock(); else if (blockId == 58) block = new CraftingTable(); else if (blockId == 59) block = new Wheat(); else if (blockId == 60) block = new Farmland(); else if (blockId == 61) block = new Furnace(); else if (blockId == 62) block = new LitFurnace(); else if (blockId == 63) block = new StandingSign(); else if (blockId == 64) block = new WoodenDoor(); else if (blockId == 65) block = new Ladder(); else if (blockId == 66) block = new Rail(); else if (blockId == 67) block = new CobblestoneStairs(); else if (blockId == 68) block = new WallSign(); else if (blockId == 69) block = new Lever(); else if (blockId == 70) block = new StonePressurePlate(); else if (blockId == 71) block = new IronDoor(); else if (blockId == 72) block = new WoodenPressurePlate(); else if (blockId == 73) block = new RedstoneOre(); else if (blockId == 74) block = new LitRedstoneOre(); else if (blockId == 75) block = new UnlitRedstoneTorch(); else if (blockId == 76) block = new RedstoneTorch(); else if (blockId == 77) block = new StoneButton(); else if (blockId == 78) block = new SnowLayer(); else if (blockId == 79) block = new Ice(); else if (blockId == 80) block = new Snow(); else if (blockId == 81) block = new Cactus(); else if (blockId == 82) block = new Clay(); else if (blockId == 83) block = new Reeds(); else if (blockId == 85) block = new Fence(); else if (blockId == 86) block = new Pumpkin(); else if (blockId == 87) block = new Netherrack(); else if (blockId == 88) block = new SoulSand(); else if (blockId == 89) block = new Glowstone(); else if (blockId == 90) block = new Portal(); else if (blockId == 91) block = new LitPumpkin(); else if (blockId == 92) block = new Cake(); else if (blockId == 93) block = new UnpoweredRepeater(); else if (blockId == 94) block = new PoweredRepeater(); else if (blockId == 95) block = new InvisibleBedrock(); else if (blockId == 96) block = new Trapdoor(); else if (blockId == 97) block = new MonsterEgg(); else if (blockId == 98) block = new StoneBrick(); else if (blockId == 99) block = new BrownMushroomBlock(); else if (blockId == 100) block = new RedMushroomBlock(); else if (blockId == 101) block = new IronBars(); else if (blockId == 102) block = new GlassPane(); else if (blockId == 103) block = new Melon(); else if (blockId == 106) block = new Vine(); else if (blockId == 107) block = new FenceGate(); else if (blockId == 108) block = new BrickStairs(); else if (blockId == 109) block = new StoneBrickStairs(); else if (blockId == 110) block = new Mycelium(); else if (blockId == 111) block = new Waterlily(); else if (blockId == 112) block = new NetherBrick(); else if (blockId == 113) block = new NetherBrickFence(); else if (blockId == 114) block = new NetherBrickStairs(); else if (blockId == 115) block = new NetherWart(); else if (blockId == 116) block = new EnchantingTable(); else if (blockId == 117) block = new BrewingStand(); else if (blockId == 120) block = new EndPortalFrame(); else if (blockId == 121) block = new EndStone(); else if (blockId == 122) block = new LitRedstoneLamp(); else if (blockId == 123) block = new RedstoneLamp(); else if (blockId == 126) block = new ActivatorRail(); else if (blockId == 127) block = new Cocoa(); else if (blockId == 128) block = new SandStoneStairs(); else if (blockId == 129) block = new EmeraldOre(); else if (blockId == 131) block = new TripwireHook(); else if (blockId == 132) block = new Tripwire(); else if (blockId == 133) block = new EmeraldBlock(); else if (blockId == 134) block = new SpruceWoodStairs(); else if (blockId == 135) block = new BirchWoodStairs(); else if (blockId == 136) block = new JungleWoodStairs(); else if (blockId == 139) block = new CobblestoneWall(); else if (blockId == 140) block = new FlowerPot(); else if (blockId == 141) block = new Carrots(); else if (blockId == 142) block = new Potatoes(); else if (blockId == 143) block = new WoodenButton(); else if (blockId == 144) block = new Skull(); else if (blockId == 145) block = new Anvil(); else if (blockId == 146) block = new TrappedChest(); else if (blockId == 147) block = new LightWeightedPressurePlate(); else if (blockId == 148) block = new HeavyWeightedPressurePlate(); else if (blockId == 151) block = new DaylightDetector(); else if (blockId == 152) block = new RedstoneBlock(); else if (blockId == 153) block = new QuartzOre(); else if (blockId == 155) block = new QuartzBlock(); else if (blockId == 156) block = new QuartzStairs(); else if (blockId == 157) block = new DoubleWoodSlab(); else if (blockId == 158) block = new WoodSlab(); else if (blockId == 159) block = new StainedHardenedClay(); else if (blockId == 161) block = new AcaciaLeaves(); else if (blockId == 162) block = new AcaciaLog(); else if (blockId == 163) block = new AcaciaStairs(); else if (blockId == 164) block = new DarkOakStairs(); else if (blockId == 167) block = new IronTrapdoor(); else if (blockId == 170) block = new HayBlock(); else if (blockId == 171) block = new Carpet(); else if (blockId == 172) block = new HardenedClay(); else if (blockId == 173) block = new CoalBlock(); else if (blockId == 174) block = new PackedIce(); else if (blockId == 175) block = new Sunflower(); else if (blockId == 178) block = new DaylightDetectorInverted(); else if (blockId == 183) block = new SpruceFenceGate(); else if (blockId == 184) block = new BirchFenceGate(); else if (blockId == 185) block = new JungleFenceGate(); else if (blockId == 186) block = new DarkOakFenceGate(); else if (blockId == 187) block = new AcaciaFenceGate(); else if (blockId == 198) block = new GrassPath(); else if (blockId == 199) block = new ItemFrame(); else if (blockId == 243) block = new Podzol(); else if (blockId == 244) block = new Beetroot(); else if (blockId == 245) block = new Stonecutter(); else if (blockId == 246) block = new GlowingObsidian(); else if (blockId == 247) block = new NetherReactorCore(); else { // Log.DebugFormat(@" // // Add this missing block to the BlockFactory // else if (blockId == {1}) block = new {0}(); // // public class {0} : Block // {{ // internal {0}() : base({1}) // {{ // }} // }} //", "Missing", blockId); block = new Block(blockId); } return block; }
public void ResetPosition() { transform.position = startingPosition; currentRail = startingRail; }
public void SetStartingRail(Rail rail) { startingRail = rail; }
private void CreateRails() { _lanes = lanes; var laneHeight = (UIHelper.MaxY - UIHelper.MinY)/(float) _lanes; _rails = new Rail[_lanes]; for (int r = 0; r < _lanes; r++) { _rails[r] = new Rail {Start = UIHelper.MaxY - (laneHeight*r)}; _rails[r].End = _rails[r].Start - laneHeight; _rails[r].Center = _rails[r].Start - (laneHeight/2); _rails[r].DamageTaken = 0; _rails[r].AllowedDamage = allowedRailDamage; } }
public void Start() { gameObject.layer = transform.position.x < 0 ? LayerMask.NameToLayer("PlatformP1") : LayerMask.NameToLayer("PlatformP2"); LEDRenderers = (from renderer in (transform.GetComponentsInChildren<MeshRenderer>() as MeshRenderer[]) where ((from material in renderer.materials where material.name.Contains( "LED" ) select material).Any<Material>() ) select renderer).ToArray(); GameObject particles = Instantiate(EZGrabber.instance.GetLinkedItem("PARTICLES") as GameObject, transform.position, transform.rotation) as GameObject; particles.transform.parent = transform; foreach( Transform child in particles.transform ) { particleSystems.Add( child ); child.GetChild(0).transform.localPosition *= (collider as BoxCollider).size.x; child.GetChild(1).transform.localPosition *= (collider as BoxCollider).size.x; } platSource = gameObject.AddComponent<AudioSource>(); particleSystems = particleSystems.OrderBy(x => x.name ).ToList(); // foreach( MeshRenderer rend in (transform.GetComponentsInChildren<MeshRenderer>() as MeshRenderer[]) ) // { // for( int i = 0; i < rend.sharedMaterials.Length; i++ ) // { // if( rend.sharedMaterials[i].name.Contains( "LED" ) ) // { // if( LEDMaterial == null ) // { // Material newMaterial = new Material(rend.sharedMaterials[i]); // newMaterial.name = "LED Custom Instance"; // LEDMaterial = newMaterial; // } // // // rend.sharedMaterial = LEDMaterial; // print (LEDMaterial.name); // print (rend.sharedMaterial.name); // } // } // } rail = transform.GetComponentInChildren<Rail>(); if(rail != null){ rail.transform.parent = transform.parent; rail.platform = this; pt = PlatformType.PT_EZLINE; return; } // if(pt == PlatformType.PT_PINNED){ // Transform _pin = GameObject.CreatePrimitive(PrimitiveType.Cylinder).transform; // _pin.transform.position = transform.position + offset; // _pin.localRotation = Quaternion.Euler(90f, 0f, 0f); // _pin.renderer.material = EZGrabber.instance.GetLinkedItem("StaticMaterial") as Material; // _pin.parent = transform; // } if(pt == PlatformType.PT_ORAIL || pt == PlatformType.PT_ORAILPINNED || pt == PlatformType.PT_VRAIL || pt == PlatformType.PT_VRAILPINNED || pt == PlatformType.PT_EVERYTHING){ rail = transform.GetChild(0).GetComponent<Rail>(); rail.transform.parent = transform.parent; } }
internal Rail(Rail previous) { this.Index = previous.Index; this.Status = previous.Status; this.Updated = false; this.StartX = previous.EndX; this.StartY = previous.EndY; this.EndX = previous.EndX; this.EndY = previous.EndY; this.Type = previous.Type; this.WallType = previous.WallType; this.WallSide = previous.WallSide; this.DikeType = previous.DikeType; this.DikeSide = previous.DikeSide; this.Pole = previous.Pole; this.Forms = null; this.FormCount = 0; this.Cracks = null; this.CrackCount = 0; this.FreeObjs = null; this.FreeObjCount = 0; this.Beacons = null; this.BeaconCount = 0; this.Stops = null; this.StopCount = 0; this.Limits = null; this.LimitCount = 0; }
private void UpdateCollisionMesh( Rail rail ) { MeshCollider mc = rail.GetComponent<Collider>() as MeshCollider; List<Vector3> verts = new List<Vector3>(); List<int> tris = new List<int>(); for( int i = 0; i < rail.nodes.Count; i++ ) { Vector3 lookDir; if( i <= 0 ) { lookDir = rail.nodes[1] - rail.nodes[0]; } else if( i > 0 && i < rail.nodes.Count - 1 ) { lookDir = ( rail.nodes[i + 1] - rail.nodes[i] ).normalized + ( rail.nodes[i] - rail.nodes[i - 1] ).normalized / 2f; } else { lookDir = rail.nodes[rail.nodes.Count - 1] - rail.nodes[rail.nodes.Count - 2]; } Quaternion lootRot = Quaternion.LookRotation( lookDir ); //Create vert triangle verts.Add( new Vector3( -0.1f, 0.05f, 0f ) ); verts.Add( new Vector3( 0.1f, 0.05f, 0f ) ); verts.Add( new Vector3( 0f, -0.05f, 0f ) ); //Move vert triangle to node for( int j = verts.Count - 3; j < verts.Count; j++ ) { verts[j] = verts[j] + rail.nodes[i]; } //Point first triangle to next node for( int j = verts.Count - 3; j < verts.Count; j++ ) { Vector3 vertDir = verts[j] - rail.nodes[i]; vertDir = lootRot * vertDir; verts[j] = vertDir + rail.nodes[i]; } } //Build the triangles //Add first node end triangle tris.Add( 0 ); tris.Add( 1 ); tris.Add( 2 ); for( int i = 0; i < rail.nodes.Count - 1; i++ ) { //Top tris.Add( 3 * i + 3 ); tris.Add( 3 * i + 1 ); tris.Add( 3 * i + 0 ); tris.Add( 3 * i + 4 ); tris.Add( 3 * i + 1 ); tris.Add( 3 * i + 3 ); //Right tris.Add( 3 * i + 4 ); tris.Add( 3 * i + 5 ); tris.Add( 3 * i + 1 ); tris.Add( 3 * i + 1 ); tris.Add( 3 * i + 5 ); tris.Add( 3 * i + 2 ); //Left tris.Add( 3 * i + 3 ); tris.Add( 3 * i + 0 ); tris.Add( 3 * i + 5 ); tris.Add( 3 * i + 5 ); tris.Add( 3 * i + 0 ); tris.Add( 3 * i + 2 ); } //Add last node end triangle tris.Add( verts.Count - 1 ); tris.Add( verts.Count - 2 ); tris.Add( verts.Count - 3 ); Mesh mesh = new Mesh(); mesh.vertices = verts.ToArray(); mesh.triangles = tris.ToArray(); mc.sharedMesh = mesh; }