private void OnContractRemovedFromBelt(MovableContract contract) { _contractsOnBelt.Remove(contract); _contractsOnBeltCount--; AssignState(); }
private void OnNewContractOnBelt(MovableContract contract) { _contractsOnBelt.Add(contract); _contractsOnBeltCount++; AssignState(); }
private void ContractExitBelt(bool checkForContracts) { _contractInfo.OnContractBeltExit(); if (contractExitBelt != null) { contractExitBelt(this); } if (!checkForContracts) { return; } bool placed = false; int count = 0; while (!placed) { placed = true; Collider2D[] colliders = Physics2D.OverlapPointAll(_collider.bounds.center, documentsLayerMask); foreach (var col in colliders) { MovableContract contract = col.GetComponent <MovableContract>(); if (contract != null && contract != this) { if (Vector2.Distance(contract.transform.position, transform.position) < 0.001f) { Vector2 newPos = contract.transform.position; newPos.y += 0.03125f; transform.position = newPos; placed = false; count++; break; } } } if (count > 400) { Debug.Log("OUCH"); break; } } }
// TODO : Wrapper ça dans container de contrat de grosseur différente public void CreateNewSingleContract() { List <Client> allClients = new List <Client>(); int contractSize = 1; MovableContract movableContract = null; // Contract object if (contractSize == 1) { movableContract = Instantiate(singleContractPrefab).GetComponent <MovableContract>(); } //else if (contractSize == 2) // movableContract = Instantiate(doubleContractPrefab).GetComponent<MovableContract>(); Vector2 spawnPos = Vector2.zero; Vector2 endPos = Vector2.zero; if (_belt == null) { _belt = FindObjectOfType <ConveyorBelt>(); } if (_belt != null) { spawnPos = _belt.contractsStartPos.position; spawnPos.x = _belt.Bounds.center.x; spawnPos.x -= movableContract.ObjSpriteRenderer.bounds.extents.x; endPos.x = spawnPos.x; endPos.y = _belt.contractsEndPos.position.y; endPos.y += movableContract.ObjSpriteRenderer.bounds.size.y; endPos.y += 2 * (1 / 32f); // 2px offset movableContract.SetSortingLayer(_belt.SpriteRenderer.sortingLayerID); movableContract.SetOrderInLayer(_belt.SpriteRenderer.sortingOrder + 1); } movableContract.transform.position = spawnPos; movableContract.InitializeContract(endPos); movableContract.ClientAmount = contractSize; // Client settings // Start planet List <GridTile_Planet> allCandidatePlanets = new List <GridTile_Planet>(PlanetManager.instance.AllPlanetTiles); GridTile_Planet startPlanet = GetStartPlanet(allCandidatePlanets); if (startPlanet == null) { Debug.LogWarning("Could not find target start planet. Check start settings."); int randomIndex = UnityEngine.Random.Range(0, allCandidatePlanets.Count); startPlanet = allCandidatePlanets[randomIndex]; } for (int i = 0; i < contractSize; i++) { int travelDistanceRating = _clientRules[_currentRuleIndex].travelDistanceRating; if (_clientRules[_currentRuleIndex].specialEndCondition == SpecialConditions.ClosestPlanet) { travelDistanceRating = 1; } if (travelDistanceRating == 0) { int randomDistance = UnityEngine.Random.Range(1, 4); travelDistanceRating = randomDistance; } // End planet //List<GridTile_Planet> distanceCandidates = GetPlanetsByDistance(allCandidatePlanets, candidateEndPlanets, startPlanet); GridTile_Planet endPlanet = GetEndPlanet(allCandidatePlanets, startPlanet, travelDistanceRating); allClients.Add(CreateClient(startPlanet, endPlanet, travelDistanceRating)); allCandidatePlanets.Remove(endPlanet); int ruleCount = _clientRules.Count; if (_currentRuleIndex == _clientRules.Count - 1) { _allRulesApplied = true; } if (!_allRulesApplied) { _currentRuleIndex++; } else { _currentRuleIndex = UnityEngine.Random.Range(0, ruleCount); } startPlanet.AddContractHeat(1); } if (contractSize == 1) { Contract_Single contract = movableContract.GetComponent <Contract_Single>(); contract.AssignClients(allClients, _completionTime, _timedContracts); contract.CalculatePointsReward(pointSettings); _allContracts.Add(contract); } //else if (contractSize == 2) //{ // Contract_Double contract = movableContract.GetComponent<Contract_Double>(); // contract.AssignClients(allClients); // contract.CalculatePointsReward(pointSettings); // _allContracts.Add(contract); //} _spawnCount++; if (newContractReceived != null) { newContractReceived(); } }