void Start() { Vector3 midPoint = (streetStart.position - streetEnd.position) * 0.5f + streetEnd.position; Vector3 tangent1Pos = (midPoint - streetStart.position) * 0.1f + streetStart.position; Vector3 tangent2Pos = (midPoint - streetEnd.position) * 0.1f + streetEnd.position; Street s = StreetComponentManager.InitStreetForPreview(streetStart.position); StreetComponentManager.UpdateStreet(s, streetStart.position, streetEnd.position, tangent1Pos, tangent2Pos); StreetComponentManager.CreateStreet(s); Destroy(s.gameObject); }
public override void ToolUpdate() { if (Input.GetKeyUp(KeyCode.C)) //Change to Curve Tool { SetCurveLineTool(false); UIManager.Instance.HighlightButton(UIManager.Instance.CurveButton); } else if (Input.GetKeyUp(KeyCode.L)) //Change to Line Tool { SetCurveLineTool(true); UIManager.Instance.HighlightButton(UIManager.Instance.LineButton); } if (m_validHit) { if (pos1Set == false && pos2Set == false && pos3Set == false) { FindClosestConnection(m_hitPos); //if no Point is set, look for not far away Street possible combinations } if (isCurrendToolLine) { if (pos1Set == true && pos3Set == false && m_previewStreet != null) //Line: First Point Set -> Missing Sec Point { if (Input.GetKey(KeyCode.LeftShift)) //Easy Placement { Vector3 StartEnd = pos1 - m_hitPos; if (Mathf.Abs(StartEnd.x) > Mathf.Abs(StartEnd.z)) { m_hitPos.z = pos1.z; } else { m_hitPos.x = pos1.x; } } Cursor.SetPosition(m_hitPos); Vector3 pos2Tmp = m_previewStreet.m_Spline.GetCentredOrientedPoint().Position; //Get the Midpoint on the Spline Vector3 tangent1 = (pos1 + pos2Tmp) * 0.5f; // 1.Tanget must be between MidPoint and Start Vector3 tangent2 = (pos2Tmp + m_hitPos) * 0.5f; // 2. Tanget must be between MidPoint and End (MousePos) UpdatePreview(tangent1, tangent2, m_hitPos); //Update the Preview (update if Tanget is not locked) CheckForCombine(m_hitPos, false); //If a Combine is possible it Combine (overwrite Tanget Pos) } } else { if (pos1Set == true && pos2Set == false && pos3Set == false && m_previewStreet != null) // Curve: First Point Set -> Wait for Sec Point { Vector3 pos2Tmp = (pos1 + m_hitPos) * 0.5f; //Get the Midpoint between Start and End Vector3 tangent1 = (pos1 + pos2Tmp) * 0.5f; //The 1.Tangent is between the Start and the Mid Vector3 tangent2 = (pos2Tmp + m_hitPos) * 0.5f; //The 2. Tangent is between the End and the Mid UpdatePreview(tangent1, tangent2, m_hitPos); //Update the Preview (update if Tanget is not locked) //The Scecond Point cant Combine to an another Spline } if (pos1Set == true && pos2Set == true && pos3Set == false && m_previewStreet != null) { Vector3 tangent1 = (pos1 + pos2) * 0.5f; //The 1.Tanget is between Start and Sec Point Vector3 tangent2 = (pos2 + m_hitPos) * 0.5f; // The 2.Tanget is between Sec Point and EndPoint (MousePos) UpdatePreview(tangent1, tangent2, m_hitPos); //Update the Preview (update if Tanget is not locked) CheckForCombine(m_hitPos, false); //If a Combine is possible it Combine (overwrite Tanget Pos) } } if (Input.GetMouseButtonDown(1)) { if (m_previewStreet != null) { DecombinePreview(true); DecombinePreview(false); } ResetTool(); return; } if (m_previewStreet != null) { m_currendCost = -m_previewStreet.m_Spline.GetLength() * streetCostMultiplier; UIManager.Instance.SetStreetCost(m_currendCost); if (!CheckForValidForm() || CheckForCollision()) { m_previewStreet.m_IsInvalid = false; return; } else { m_previewStreet.m_IsInvalid = true; } } if (Input.GetMouseButtonDown(0) && !StreetComponentManager.BlockStreetComponentPlacement) { if (pos1Set == false) { pos1 = m_hitPos; pos1Set = true; m_previewStreet = StreetComponentManager.InitStreetForPreview(pos1); //Init a Preview Street (with invalid ID) CheckForCombine(m_hitPos, true); //Check if the Start in the Preview Street can be combined pos1 = Cursor.GetPosition(); //Reset the Position for correct Easy Shift Placement return; } if (!isCurrendToolLine) // In Curve Tool -> Set Sec Pos { if (pos2Set == false) { pos2 = m_hitPos; pos2Set = true; return; } } if (pos3Set == false) { if (Mathf.Abs(m_currendCost) <= Inventory.Instance.m_MoneyAmount) { Inventory.Instance.m_MoneyAmount += m_currendCost; //currend Cost is negative UIManager.Instance.UpdateMoneyUI(); //dont wait for next tick to update UI pos3 = m_hitPos; CheckForCombine(m_hitPos, false); //Check if the End in the Preview Street can be combined Street newStreet = StreetComponentManager.CreateStreet(m_previewStreet); //Create a valid Street from the preview Street ResetTool(); //Reset return; } } } } }