public void BeginFollow(Thread_GridObjectBehavior inputObject, float inputDistance, int inputOriginID, bool instant) { followObject = inputObject; followDistance = inputDistance; packageOriginID = inputOriginID; followObjectPassed = true; this.instant = instant; Appear(); }
void SwapTrails(int thread_b_id) { Debug.Log("Swapping between " + this.component.id + " and " + thread_b_id); Thread_GridObjectBehavior otherTrain = GameManager.Instance.GetGridManager().GetGridObjectByID(thread_b_id) as Thread_GridObjectBehavior; Vector3 fromPosition = transform.position; Vector3 toPosition = otherTrain.transform.position; if (teleportTrail) { GameObject teleportInstance = (GameObject)Instantiate(teleportTrail, fromPosition, Quaternion.identity); iTween.MoveTo(teleportInstance, toPosition, 2f); Destroy(teleportInstance, 2.5f); } otherTrain.ClearCabooses(); ClearCabooses(); }
public override void DoStep(StepData inputStep) { if (behaviorType == BehaviorTypes.component && component != null) { switch (component.type.ToLower()) { case "thread": if (inputStep.eventType == "M") { Vector2 reverseYposition = new Vector2(inputStep.componentPos.x, GameManager.Instance.GetLevelHeight() - inputStep.componentPos.y); float travelTime = 0.5f; if (inputStep.GetNextStep() != -1) { StepData nextStep = GameManager.Instance.GetDataManager().currentLevelData.execution[inputStep.GetNextStep()]; reverseYposition = new Vector2(nextStep.componentPos.x, GameManager.Instance.GetLevelHeight() - nextStep.componentPos.y); //travelTime = inputStep.componentStatus.speed; } iTween.MoveTo(gameObject, iTween.Hash("x", reverseYposition.x, "y", reverseYposition.y, "time", .5f, "easetype", iTween.EaseType.linear)); Vector2 difference = lastSimulationPosition - reverseYposition; Quaternion targetRotation = new Quaternion(); if (difference.x > 0) { targetRotation = Quaternion.Euler(0f, 0f, 180f); } else if (difference.x < 0) { targetRotation = Quaternion.Euler(0f, 0f, 0f); } else if (difference.y > 0) { targetRotation = Quaternion.Euler(0f, 0f, -90f); } else if (difference.y < 0) { targetRotation = Quaternion.Euler(0f, 0f, 90f); } if (difference.x == 0 && difference.y == 0) { } else { iTween.RotateTo(gameObject, targetRotation.eulerAngles, .5f); } lastSimulationPosition = reverseYposition; } else if (inputStep.eventType == "E") { if (inputStep.componentStatus != null) { if (inputStep.componentStatus.passed != 0) { //passed is returned in increments for Thread E steps. What is this for? } else if (inputStep.componentStatus.payload != null) { if (inputStep.componentStatus.payload.Length == 0) { Debug.Log("I am " + component.id + " and For step: " + inputStep.timeStep + " and for object " + inputStep.componentID + " I shall clear mine cabooses."); Debug.Log(JsonUtility.ToJson(inputStep).ToString()); ClearCabooses(); } else { List <int> currentCabooses = new List <int>(); currentCabooses.AddRange(inputStep.componentStatus.payload); List <int> newCabooses = new List <int>(); newCabooses.AddRange(inputStep.componentStatus.payload); List <GameObject> popCabooses = new List <GameObject>(); /* figure out what cabooses to add to current */ foreach (GameObject g in trailObjectList) { int currentId = g.GetComponent <CabooseObject>().packageOriginID; if (newCabooses.Contains(currentId)) { newCabooses.Remove(currentId); } if (!currentCabooses.Contains(currentId)) { popCabooses.Add(g); } } /* figure out what cabooses to remove from current */ for (int p = popCabooses.Count - 1; p >= 0; p--) { CabooseObject caboose = popCabooses[p].GetComponent <CabooseObject>(); caboose.Disconnect(); trailObjectList.Remove(popCabooses[p]); Destroy(popCabooses[p]); } foreach (int payloadId in newCabooses) { GridObjectBehavior payloadObject = GameManager.Instance.GetGridManager().GetGridObjectByID(payloadId); GameObject g = new GameObject(); g.transform.position = payloadObject.transform.position; g.transform.localScale = Vector3.zero; trailObjectList.Add(g); g.name = "payload_" + payloadId; g.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_tint_01"); //payloadObject.GetComponent<SpriteRenderer>().sprite; g.GetComponent <SpriteRenderer>().color = GameManager.Instance.GetGridManager().GetColorByIndex(component.configuration.color); GameObject gChild = new GameObject(); switch (payloadObject.component.configuration.type) { case "Conditional": { gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_03"); } break; case "Unconditional": { gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_02"); } break; case "Limited": { gChild.AddComponent <SpriteRenderer>().sprite = GameManager.Instance.GetGridManager().GetSprite("package_logo_01"); } break; case "Empty": { } break; } gChild.GetComponent <SpriteRenderer>().sortingOrder = Constants.ComponentSortingOrder.basicComponents + 1; gChild.transform.position = g.transform.position; gChild.transform.SetParent(g.transform); gChild.transform.localScale = Vector3.one; if (true /* item is in exchange */) { /* figure out where the exchange point is, spawn it there */ g.AddComponent <CabooseObject>().BeginFollow(transform, (float)trailObjectList.Count, payloadId); } else { g.AddComponent <CabooseObject>().BeginFollow(transform, (float)trailObjectList.Count, payloadId); } } } } } } else if (inputStep.eventType == "D") { if (inputStep.componentStatus.exchange_between_b != 0) { Debug.Log("Moving from " + inputStep.componentStatus.exchange_between_a + " to " + inputStep.componentStatus.exchange_between_b); Thread_GridObjectBehavior otherTrain = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentStatus.exchange_between_b) as Thread_GridObjectBehavior; Vector3 fromPosition = transform.position; Vector3 toPosition = otherTrain.transform.position; if (teleportTrail) { GameObject teleportInstance = (GameObject)Instantiate(teleportTrail, toPosition, Quaternion.identity); iTween.MoveTo(teleportInstance, fromPosition, 2f); Destroy(teleportInstance, 2.5f); } } if (inputStep.componentStatus.delivered_to != 0) { Debug.Log("Should perform delivery for " + inputStep.componentID); if (inputStep.componentStatus.delivered_items.Length > 0) { GridObjectBehavior deliverToObject = GameManager.Instance.GetGridManager().GetGridObjectByID(inputStep.componentStatus.delivered_to); /* Feedback for Cabooses */ foreach (int deliveryId in inputStep.componentStatus.delivered_items) { for (int i = trailObjectList.Count - 1; i >= 0; i--) { CabooseObject caboose = trailObjectList[i].GetComponent <CabooseObject>(); if (caboose.packageOriginID == deliveryId) { Debug.Log("Disconnecting caboose " + caboose.packageOriginID); caboose.Disconnect(); if (inputStep.componentStatus.delivered_to != null && inputStep.componentStatus.delivered_to != 0) { iTween.MoveTo(caboose.gameObject, deliverToObject.transform.position, 1.5f); } iTween.ScaleTo(caboose.gameObject, Vector3.zero, 1.5f); Destroy(caboose.gameObject, 2f); trailObjectList.RemoveAt(i); } } } /* Feedback for Delivery point */ if ( (inputStep.componentStatus.missed != null && inputStep.componentStatus.missed != 0) || (inputStep.componentStatus.missed_items != null && inputStep.componentStatus.missed_items.Length > 0) ) { deliverToObject.ErrorBehavior(Color.black); } else { deliverToObject.SuccessBehavior(GameManager.Instance.GetGridManager().GetColorByIndex(component.configuration.color)); Delivery_GridObjectBehavior deliveryCast = deliverToObject as Delivery_GridObjectBehavior; Debug.Log("INCREMENT " + deliverToObject.component.id + " BY " + inputStep.componentStatus.delivered_items.Length); deliveryCast.deliveryPopup.IncrementNumerator(inputStep.componentStatus.delivered_items.Length); } } } } break; } } }
public void GenerateGrid(List <GridTrack> gridTracks, List <GridComponent> gridComponents) { /* * currentGridWidth = layoutList[0].Length; * currentGridHeight = layoutList.Count; */ Vector3 averagePosition = new Vector3(); //Debug.Log(gridTracks.Count + ", " + gridComponents.Count); foreach (GridTrack track in gridTracks) { Vector2 reversedYposition = track.position; reversedYposition.y = GameManager.Instance.GetLevelHeight() - reversedYposition.y; GameObject gridElementInstance = Instantiate(gridElementPrefab, reversedYposition, Quaternion.identity) as GameObject; SpriteRenderer instanceSpriteRenderer = gridElementInstance.GetComponent <SpriteRenderer>(); GridObjectBehavior behavior = gridElementInstance.GetComponent <GridObjectBehavior>(); gridElementInstance.transform.SetParent(gridContainer); averagePosition += new Vector3(reversedYposition.x, reversedYposition.y, 0); gridElementInstance.name = track.type + "_track"; behavior.behaviorType = GridObjectBehavior.BehaviorTypes.track; behavior.track = track; switch (track.type) { case 'J': // Straight_00 instanceSpriteRenderer.sprite = gridElementDictionary["straight_road"]; gridElementInstance.transform.Rotate(0, 0, 90); break; case 'E': // Straight_01 instanceSpriteRenderer.sprite = gridElementDictionary["straight_road"]; break; case 'N': // ThreeWay_00 instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"]; gridElementInstance.transform.Rotate(0, 0, 90); break; case 'M': // ThreeWay_01 instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"]; gridElementInstance.transform.Rotate(0, 0, 180); break; case 'K': // ThreeWay_02 instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"]; gridElementInstance.transform.Rotate(0, 0, -90); break; case 'G': // ThreeWay_03 instanceSpriteRenderer.sprite = gridElementDictionary["threeway_road"]; break; case 'F': // Turn_00 instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"]; gridElementInstance.transform.Rotate(0, 0, 90); break; case 'C': // Turn_01 instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"]; break; case 'I': // Turn_02 instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"]; gridElementInstance.transform.Rotate(0, 0, 270); break; case 'L': // Turn_03 instanceSpriteRenderer.sprite = gridElementDictionary["corner_road"]; gridElementInstance.transform.Rotate(0, 0, 180); break; case 'O': // FourWay instanceSpriteRenderer.sprite = gridElementDictionary["fourway_road"]; gridElementInstance.transform.Rotate(0, 0, 180); break; /*A - EAST DEAD * B - NORTH DEAD * D - WEST DEAD * H - SOUTH DEAD*/ ///* TODO: Enable Dead ends case 'A': instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"]; gridElementInstance.transform.Rotate(0, 0, 90); break; case 'B': instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"]; //gridElementInstance.transform.Rotate(0,0,180); break; case 'D': instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"]; gridElementInstance.transform.Rotate(0, 0, -90); break; case 'H': instanceSpriteRenderer.sprite = gridElementDictionary["deadEnd_road"]; gridElementInstance.transform.Rotate(0, 0, 180); break; //*/ default: instanceSpriteRenderer.sprite = null; break; } instanceSpriteRenderer.color = new Color(0.2f, 0.2f, 0.2f, 1f); currentLevelObjects.Add(behavior); } averagePosition = averagePosition / gridTracks.Count; worldCamera.transform.position = new Vector3(averagePosition.x, averagePosition.y, -15); float levelheight = GameManager.Instance.GetLevelHeight(); float levelRatio = GameManager.Instance.GetLevelWidth() / GameManager.Instance.GetLevelHeight(); if (levelRatio > 1.78f) // 16:9 { Debug.Log("WIDER LEVEL " + levelRatio); levelheight *= (levelRatio / 1.78f); levelheight /= 0.9f; // To make room for the right banner } else { levelheight += 1; } worldCamera.orthographicSize = (levelheight / 2.0f) / 0.78f; // To make room for the bottom banner foreach (GridComponent gridComponent in gridComponents) { int color = gridComponent.configuration.color; int positionX = gridComponent.posX; int positionY = GameManager.Instance.GetLevelHeight() - gridComponent.posY; string type = gridComponent.type; GameObject gridElementInstance = Instantiate(gridElementPrefab, new Vector3(positionX, positionY), Quaternion.identity) as GameObject; SpriteRenderer instanceSpriteRenderer = gridElementInstance.GetComponent <SpriteRenderer>(); instanceSpriteRenderer.sortingOrder = Constants.ComponentSortingOrder.basicComponents; //instanceSpriteRenderer.color = colorDictionary[color]; GridObjectBehavior behavior = gridElementInstance.GetComponent <GridObjectBehavior>(); if (type == "signal") { Signal_GridObjectBehavior signal_Behavior = gridElementInstance.AddComponent <Signal_GridObjectBehavior>(); signal_Behavior.highlightObject = behavior.highlightObject; signal_Behavior.lineRenderer = gridElementInstance.GetComponentInChildren <LineRenderer>(); signal_Behavior.teleportTrail = behavior.teleportTrail; signal_Behavior.lockObject = behavior.lockObject; Destroy(behavior); behavior = signal_Behavior; } else if (type == "thread") { Thread_GridObjectBehavior thread_Behavior = gridElementInstance.AddComponent <Thread_GridObjectBehavior>(); thread_Behavior.highlightObject = behavior.highlightObject; thread_Behavior.teleportTrail = behavior.teleportTrail; Destroy(behavior); behavior = thread_Behavior; } else if (type == "diverter") { Diverter_GridObjectBehavior diverter_Behavior = gridElementInstance.AddComponent <Diverter_GridObjectBehavior>(); diverter_Behavior.highlightObject = behavior.highlightObject; diverter_Behavior.teleportTrail = behavior.teleportTrail; Destroy(behavior); behavior = diverter_Behavior; gridElementInstance.layer = 8; } else if (type == "delivery") { Delivery_GridObjectBehavior delivery_Behavior = gridElementInstance.AddComponent <Delivery_GridObjectBehavior>(); delivery_Behavior.highlightObject = behavior.highlightObject; delivery_Behavior.teleportTrail = behavior.teleportTrail; Destroy(behavior); behavior = delivery_Behavior; } gridElementInstance.transform.SetParent(gridContainer); gridElementInstance.name = type; behavior.behaviorType = GridObjectBehavior.BehaviorTypes.component; behavior.component = gridComponent; instanceSpriteRenderer.sprite = GetSprite(gridComponent); currentLevelObjects.Add(behavior); gridObjectLevelIDDictionary.Add(gridComponent.id, behavior); gridObjectLevelPositionDictionary.Add(behavior.transform.position, behavior); behavior.InitializeGridComponentBehavior(); } }
public void Disconnect() { followObject = null; followDistance = 0; }