public void OnInputAction(InputActionData action_data) { if (action_data.m_Action == InputsManager.InputAction.LMB || action_data.m_Action == InputsManager.InputAction.Button_X) { int i = 0; while (i < this.m_Masks.Count) { if (this.m_Masks[i].gameObject.activeSelf) { ConstructionController component = Player.Get().GetComponent <ConstructionController>(); if (!component.IsActive()) { string itemID = this.m_Masks[i].gameObject.transform.parent.GetComponent <NotepadConstructionData>().m_ItemID; ItemID id = (ItemID)Enum.Parse(typeof(ItemID), itemID); ItemInfo info = ItemsManager.Get().GetInfo(id); component.SetupPrefab(info); Player.Get().StartController(PlayerControllerType.Construction); return; } break; } else { i++; } } } }
public void InvalidBuildingConstruction() { ConstructionController constructionController = CreateConstructionController(CreatePlayerData()); Assert.AreEqual(constructionController.CheckBuildingValidity((int)Random.Range(1, 10)), false); GameObject.DestroyImmediate(constructionController); }
public void NotEnoughRessourceToBuild() { int ressources = Random.Range(0, 4); ConstructionController constructionController = CreateConstructionController(CreatePlayerData(0, ressources)); Assert.AreEqual(constructionController.CheckRessourcesAvailability(Random.Range(0, 1)), false); GameObject.DestroyImmediate(constructionController); }
public void Start() { this.myButton = this.GetComponent <Button>(); myButton.interactable = false; this.constructionController = GameObject.FindWithTag(GameSetup.CONSTRUCTION_CONTROLLER_TAG).GetComponent <ConstructionController>(); myButton.onClick.AddListener(delegate { myClick(); }); }
public void OnSlotPress(int slot_index) { MenuConstructionSlot menuConstructionSlot = this.m_Slots[slot_index]; ConstructionController component = Player.Get().GetComponent <ConstructionController>(); component.SetupPrefab(menuConstructionSlot.info); Player.Get().StartController(PlayerControllerType.Construction); this.m_MenuInGameManager.HideMenu(); }
protected override bool ShouldShow() { if (!ConstructionController.Get().IsActive()) { return(false); } ConstructionGhost ghost = ConstructionController.Get().GetGhost(); return(ghost != null && ghost.GetState() == ConstructionGhost.GhostState.Dragging); }
public void load() { List <PurchaseRequest> reqs = PurchaseRequestController.getInstance().getAll(); List <Idea> ideas = IdeaController.getInstance().getAll(); List <FundRequest> funds = FundRequestController.getInstance().getAll(); List <Construction> cons = ConstructionController.getInstance().getAll(); List <PersonalRequest> pers_reqs = PersonalRequestController.getInstance().getAll(); var pers_status = pers_reqs.Where(p => p.EmployeeID == employee.Id && (p.Status == "Accepted" || p.Status == "Rejected")); var cons_status = cons.Where(c => c.Status == "In progress of constructing" || c.Status == "Finish constructing"); var funds_status = funds.Where(p => (p.Status == "Accepted" || p.Status == "Rejected") && p.DepartmentId == employee.DepartmentID); var idea_status = ideas.Where(i => i.Status == "Accepted" || i.Status == "Rejected"); var req_status = reqs.Where(p => (p.Status == "Accepted" || p.Status == "Rejected") && p.DepartmentId == employee.DepartmentID); var req_filtered = req_status.Select(p => new { p.Id, p.Information, p.Note, p.Status, p.Date }); var cons_filtered = cons_status.Select(c => new { c.Id, title = c.Idea.Tittle, information = c.Idea.Information, c.Status }); var pers_filterd = pers_status.Select(p => new { p.Id, p.Title, p.Description, p.Date, p.Note, p.Status, p.Type }); viewFund.ItemsSource = funds_status; viewPurchase.ItemsSource = req_filtered; viewIdeas.ItemsSource = idea_status; viewCons.ItemsSource = cons_filtered; viewRA.ItemsSource = AttractionRideController.getInstance().getAll(); viewPers.ItemsSource = pers_filterd; }
public void ConstructionControllerIsSuccesfullyCreated() { ConstructionController constructionController = CreateConstructionController(CreatePlayerData()); Assert.AreNotEqual(constructionController, null); GameObject.DestroyImmediate(constructionController); constructionController = CreateConstructionController(CreatePlayerData(1, 1)); Assert.AreNotEqual(constructionController, null); GameObject.DestroyImmediate(constructionController); }
private void SetupText(bool can_create) { if (can_create) { if (!this.m_Create.activeSelf) { this.m_Create.SetActive(true); } if (this.m_Find.gameObject.activeSelf) { this.m_Find.gameObject.SetActive(false); } } else if (ConstructionController.Get() && ConstructionController.Get().GetGhost()) { if (this.m_Create.activeSelf) { this.m_Create.SetActive(false); } if (!this.m_Find.gameObject.activeSelf) { this.m_Find.gameObject.SetActive(true); } if (ConstructionController.Get().GetGhost().GetProhibitionType() == ConstructionGhost.ProhibitionType.Hard) { ConstructionGhost.GhostPlacingCondition placingCondition = ConstructionController.Get().GetGhost().m_PlacingCondition; if (placingCondition == ConstructionGhost.GhostPlacingCondition.NeedFirecamp) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindFire"); } else if (placingCondition == ConstructionGhost.GhostPlacingCondition.MustBeInWater) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindWater"); } else { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindPlace"); } } else if (ConstructionController.Get().GetGhost().GetProhibitionType() == ConstructionGhost.ProhibitionType.Soft) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HIDConstruction_CutPlants"); } else { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindPlace"); } } }
public void GoWork(GameObject getTarget) { ConstructionController targetController = getTarget.GetComponent <ConstructionController>(); if (!targetController.hasBuilder) { agent.SetDestination(targetController.BoundingBox.min); movementTarget = getTarget; Building = getTarget; //I have used two different variables to prevent "foreach loop" issues constructionSite = GameObject.CreatePrimitive(PrimitiveType.Cube); constructionSite.GetComponent <Collider>().enabled = false; constructionSite.transform.localScale = targetController.BoundingBox.size; constructionSite.transform.position = targetController.BoundingBox.center; targetController.hasBuilder = true; } }
public int send(int id) { var idea = IdeaRepository.find(id); if (idea.Status == "Accepted") { if (ConstructionController.getInstance().add(id)) { IdeaRepository.remove(id); return(1); } return(0); } return(-1); }
private void GenerateUI() { constructionController = FindObjectOfType <ConstructionController>(); menuRows = transform.Find("MenuRows"); menuBar = transform.Find("MenuBar"); menuBarImage = menuBar.GetComponent <Image>(); menuRowImage = menuRows.GetComponent <Image>(); float size = menuBar.GetComponent <RectTransform>().position.y * 2 - 30; GenerateMenuBar(buildMenuData.buildMenu.rows, size); rows = new List <GameObject>(); foreach (var row in buildMenuData.buildMenu.rows) { rows.Add(GenerateRow(row, menuRows, size)); } menuRows.gameObject.SetActive(false); }
private dynamic getConsList() { List <Construction> constructions = ConstructionController.getInstance().getAll(); var cons_status = constructions.Where(c => c.Status == "Waiting for constructing" || c.Status == "In progress of constructing"); var filtered = cons_status.Select(c => new { c.Id, title = c.Idea.Tittle, information = c.Idea.Information, c.Status }); return(filtered); }
public void CreateConstructionController(string mainString, string helpString1, string helpString2) { if (currentConstructionController != null) { if (mainString == currentConstructionController.mainText.text) { return; } Destroy(currentConstructionController.gameObject); } else { currentConstructionController = Instantiate(constructionControllerPrefab); Transform canvasTransform = GameObject.Find("Canvas").GetComponent <Canvas>().transform; currentConstructionController.transform.SetParent(canvasTransform, false); controllerActive = true; SetupConstructionController(mainString, helpString1, helpString2); } }
private void UpdateConstructionProgress(ConstructionController constructionController) { constructionProgress.SetActive(true); resourcePile0.SetActive(true); resourcePile0Image.color = (constructionController.progress <= 0f) ? Color.white : progressColor; step0.SetActive(true); float gain = constructionController.data.constructionSteps.Length > 1 ? 2f : 1f; step0Slider.value = Mathf.Clamp(gain * constructionController.progress, 0f, 1f); step0Image.color = (constructionController.progress > 0f) ? progressColor : Color.white; if (constructionController.data.constructionSteps.Length > 1) { resourcePile1.SetActive(true); resourcePile1Image.color = (constructionController.progress <= 0.5f) ? Color.white : progressColor; step1.SetActive(true); step1Slider.value = Mathf.Clamp(gain * constructionController.progress - 1, 0f, 1f); step1Image.color = (constructionController.progress > 0.5f) ? progressColor : Color.white; } else { resourcePile1.SetActive(false); step1.SetActive(false); } if (constructionController.progress == 0f) { resourcePanel.SetActive(true); LoadConstructionCost(constructionController.data.GetStepResources(0), constructionController.GetComponent <ResourceContainer>().inventory); } else if (constructionController.progress == 0.5f) { resourcePanel.SetActive(true); LoadConstructionCost(constructionController.data.GetStepResources(1), constructionController.GetComponent <ResourceContainer>().inventory); } else { resourcePanel.SetActive(false); } }
private void FindnSetConstruction() { constructions = GameObject.FindGameObjectsWithTag("Construction"); builders = GameObject.FindGameObjectsWithTag("Builder"); if (constructions.Length > 0) { float minimumDistance = 99999999999f; //99999999999 as placeholder foreach (GameObject target in constructions) { foreach (GameObject otherBuilder in builders) { if (otherBuilder.GetComponent <Builder>().Building == null) { float distance = Vector3.Distance(otherBuilder.transform.position, target.transform.position); ConstructionController targetInfo = target.GetComponent <ConstructionController>(); if (!targetInfo.hasBuilder && minimumDistance > distance && targetInfo.Placed) { minimumDistance = distance; movementTarget = target; nearestBuilder = otherBuilder; } } } } if (movementTarget == null) { Finish(); } else if (!movementTarget.GetComponent <ConstructionController>().hasBuilder&& movementTarget != null) { if (nearestBuilder == gameObject) { GoWork(movementTarget); } } else { Finish(); } } }
private void btnStart_Click(object sender, RoutedEventArgs e) { object id_obj = ((Button)sender).CommandParameter; int id; int.TryParse(id_obj.ToString(), out id); if (ConstructionController.getInstance().start(id)) { MessageBox.Show("Success to start the construction!"); } else { MessageBox.Show("Construction has been started!"); } load(); }
public void Start() { ViewManagerSingleton.Instance.InstantiateAView("Canvas/GameView"); ConController = ViewManagerSingleton.CurrentView.AddComponent <ConstructionController>(); ConController.Initialize(); Button RollDiceButton = ViewManagerSingleton.CurrentView.transform.Find("PlayerInfo/RollDiceButton").GetComponent <Button>(); RollDiceButton.onClick.AddListener(RollDice); DiceRolled += DiceHasBeenRolled; CurrentGameState = GameState.RollDice; for (int i = 0; i < 4; i++) { if (i == 0) { Players.Add(new PlayerData(PlayerData.PlayerColors.BLUE, true)); } if (i == 1) { Players.Add(new PlayerData(PlayerData.PlayerColors.RED, true)); } if (i == 2) { Players.Add(new PlayerData(PlayerData.PlayerColors.PURPLE, true)); } if (i == 3) { Players.Add(new PlayerData(PlayerData.PlayerColors.YELLOW, true)); } } // real tmp work here UserPlayer = Players[0]; Players[0].CurrentPlayer = true; }
private void btnFinish_Click(object sender, RoutedEventArgs e) { object id_obj = ((Button)sender).CommandParameter; int id; int.TryParse(id_obj.ToString(), out id); MessageBoxResult messageBoxResult = System.Windows.MessageBox.Show("Are you sure?", "Finish Construction Confirmation", System.Windows.MessageBoxButton.YesNo); if (messageBoxResult == MessageBoxResult.Yes) { if (ConstructionController.getInstance().finish(id)) { MessageBox.Show("Success to finish the construction!"); } else { MessageBox.Show("Invalid!"); } } load(); }
void Update() { if (juicer.hovered) { // Construction progress constructionController = juicer.hovered.GetComponent <ConstructionController>(); if (constructionController != null) { UpdateConstructionProgress(constructionController); } else { ResetConstructionProgress(); } // local resource container resourceContainer = juicer.hovered.GetComponent <ResourceContainer>(); if (resourceContainer != null && constructionController == null) { UpdateContainerViewer(resourceContainer); } else { ResetContainerViewer(); } // simple interaction bool simpleInteraction = false; // talk interaction InteractionTalk interactionTalk = juicer.hovered.GetComponent <InteractionTalk>(); if (interactionTalk != null && !DiscussionSystem.instance.activated) { simpleInteractionText.gameObject.SetActive(true); simpleInteractionText.text = "Talk to " + interactionTalk.pnj.pnjName; simpleInteraction = true; } else { simpleInteractionText.gameObject.SetActive(simpleInteraction); } // forge interaction if (isForge(juicer.hovered) && !ForgeSystem.instance.activated) { simpleInteractionText.gameObject.SetActive(true); simpleInteractionText.text = "Open the forge"; simpleInteraction = true; } else { simpleInteractionText.gameObject.SetActive(simpleInteraction); } // resource collection interaction if (isResourceCollection(juicer.hovered)) { simpleInteractionText.gameObject.SetActive(true); InteractionType.Type collectionType = juicer.hovered.GetComponent <InteractionType>().type; if (ResourceDictionary.instance.resourcesFromType.ContainsKey(collectionType)) { simpleInteractionText.text = "Collect " + ResourceDictionary.instance.resourcesFromType[collectionType].name; } else { simpleInteractionText.text = "Error: ResourceDictionary doesn't contain resource for interaction " + collectionType.ToString(); } simpleInteraction = true; } else { simpleInteractionText.gameObject.SetActive(simpleInteraction); } } else { constructionController = null; resourceContainer = null; ResetConstructionProgress(); ResetContainerViewer(); simpleInteractionText.gameObject.SetActive(false); } }
void Awake() { instance = this; }
protected override void Update() { base.Update(); this.SetupText(ConstructionController.Get().CanCreateConstruction()); }
private void SetupText(bool can_create) { if (can_create) { if (!this.m_Create.activeSelf) { this.m_Create.SetActive(GreenHellGame.IsPCControllerActive()); } if (!this.m_CreatePad.activeSelf) { this.m_CreatePad.SetActive(GreenHellGame.IsPadControllerActive()); } if (this.m_Find.gameObject.activeSelf) { this.m_Find.gameObject.SetActive(false); return; } } else if (ConstructionController.Get() && ConstructionController.Get().GetGhost()) { if (this.m_Create.activeSelf) { this.m_Create.SetActive(false); } if (this.m_CreatePad.activeSelf) { this.m_CreatePad.SetActive(false); } if (!this.m_Find.gameObject.activeSelf) { this.m_Find.gameObject.SetActive(true); } this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindPlace", true); if (ConstructionController.Get().GetGhost().GetProhibitionType() == ConstructionGhost.ProhibitionType.Depth) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindPlace", true); return; } if (ConstructionController.Get().GetGhost().GetProhibitionType() == ConstructionGhost.ProhibitionType.Hard) { ConstructionGhost.GhostPlacingCondition placingCondition = ConstructionController.Get().GetGhost().m_PlacingCondition; if (placingCondition == ConstructionGhost.GhostPlacingCondition.NeedFirecamp) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindFire", true); return; } if (placingCondition == ConstructionGhost.GhostPlacingCondition.MustBeInWater) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindWater", true); return; } if (placingCondition != ConstructionGhost.GhostPlacingCondition.IsSnapped) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindPlace", true); return; } ItemID resultItemID = ConstructionController.Get().GetGhost().m_ResultItemID; if (resultItemID == ItemID.mud_wall || resultItemID == ItemID.mud_doorway || resultItemID == ItemID.mud_window_wall || resultItemID == ItemID.mud_wall_fireside) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_MudSnap", true); return; } if (resultItemID == ItemID.building_wall || resultItemID == ItemID.building_bamboo_wall || resultItemID == ItemID.building_shed || resultItemID == ItemID.building_bamboo_shed || resultItemID == ItemID.wooden_doorway || resultItemID == ItemID.bamboo_doorway || resultItemID == ItemID.building_banana_leaf_roof || resultItemID == ItemID.mud_ceiling || resultItemID == ItemID.building_roof) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_Snap", true); return; } if (resultItemID == ItemID.building_shed_roof || resultItemID == ItemID.building_banana_shed_roof || resultItemID == ItemID.mud_shed_wall || resultItemID == ItemID.mud_shed_ceiling) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_ShedSnap", true); return; } } else { if (ConstructionController.Get().GetGhost().GetProhibitionType() == ConstructionGhost.ProhibitionType.Soft) { this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HIDConstruction_CutPlants", true); return; } this.m_Find.text = GreenHellGame.Instance.GetLocalization().Get("HUDConstruction_FindPlace", true); } } }
private bool CanCrouch() { return(!Inventory3DManager.Get().IsActive() && !MapController.Get().IsActive() && !NotepadController.Get().IsActive() && !HeavyObjectController.Get().IsActive() && !WalkieTalkieController.Get().IsActive() && !ConstructionController.Get().IsActive() && !HUDItem.Get().m_Active&& !HUDWheel.Get().m_Active); }
public void FinishedBuilding(ConstructionController construction) { lastFinishedConstruction = construction.data; lastFinishedConstructionGo = MapModifier.instance.grid.GetRootOf(construction.gameObject); onConstructionFinished.Invoke(); }
private void BrushToolUpdate(Vector3Int tilePointing, Vector3 pointing) { // enable and disable element depending on pointer (only if needed) if (lastTilePointing != tilePointing) { MapModifier.TileGameObject pointedTile = modifier.GetObjectsAtTile(tilePointing); if (pointedTile != lastPointedTile) { if (targetLayer.layerType == ConstructionLayer.LayerType.Terrain) { if (lastPointedTile != null && lastPointedTile.terrain) { lastPointedTile.terrain.SetActive(true); } if (pointedTile != null && pointedTile.terrain) { pointedTile.terrain.SetActive(false); } } } lastPointedTile = pointedTile; } lastTilePointing = tilePointing; // if ponter is valid (we are on something with a brush) if (lastPointedTile != null) { // simple preview stuff preview.transform.position = pointing + new Vector3(2f * (brush.data.tileSize.x - 1), 0, 2f * (brush.data.tileSize.y - 1)); if (Input.GetKeyDown(rotationLeft)) { preview.transform.eulerAngles += new Vector3(0, 90, 0); } else if (Input.GetKeyDown(rotationRight)) { preview.transform.eulerAngles -= new Vector3(0, 90, 0); } string message = ""; List <GameObject> hovered = GetPointedObjects(preview.transform.position, ref message); currentPreviewMaterial.color = hovered.Count == 0 ? previewOk : previewInvalid; constructionUI.description.text = message; if (Input.GetMouseButtonDown(0)) { clickDownTilePointing = tilePointing; } if (!enableMultiConstruction) { clickDownTilePointing = tilePointing; } // multi placement preview if (Input.GetMouseButton(0) && brush.data.tile != null) { int multiplacementCount = 0; for (int i = Mathf.Min(tilePointing.x, clickDownTilePointing.x); i <= Mathf.Max(tilePointing.x, clickDownTilePointing.x) && multiplacementCount < maximumMultiplacement; i++) { for (int j = Mathf.Min(tilePointing.y, clickDownTilePointing.y); j <= Mathf.Max(tilePointing.y, clickDownTilePointing.y) && multiplacementCount < maximumMultiplacement; j++) { Vector3Int cell = new Vector3Int(i, j, tilePointing.z); if (cell == tilePointing) { continue; } Vector3 p = modifier.GetTileCenter(cell); bool blocked = HoveringObjects(p); multiPreviewRenderers[multiplacementCount].gameObject.SetActive(true); multiPreviewRenderers[multiplacementCount].transform.position = p; multiPreviewRenderers[multiplacementCount].transform.rotation = preview.transform.rotation; multiPreviewRenderers[multiplacementCount].transform.localScale = preview.transform.localScale; multiPreviewRenderers[multiplacementCount].material.color = blocked ? previewInvalid : previewOk; multiplacementCount++; } } for (int i = multiplacementCount; i < multiPreviewRenderers.Count; i++) { multiPreviewRenderers[i].gameObject.SetActive(false); } } // construction placement if (Input.GetMouseButtonUp(0) && (hovered.Count == 0 || tilePointing != clickDownTilePointing)) { // directly place building (free and no timing) if (instantConstruct || brush.data.incrementSpeed >= 1f) { if (brush.data.tile != null) { Quaternion finalRotation = Quaternion.Euler(brush.data.placementEulerOffset - new Vector3(0, 0, preview.transform.eulerAngles.y)); Matrix4x4 matrix = Matrix4x4.TRS(Vector3.zero, finalRotation, Vector3.one); int multiplacementCount = 0; for (int i = Mathf.Min(tilePointing.x, clickDownTilePointing.x); i <= Mathf.Max(tilePointing.x, clickDownTilePointing.x) && multiplacementCount < maximumMultiplacement; i++) { for (int j = Mathf.Min(tilePointing.y, clickDownTilePointing.y); j <= Mathf.Max(tilePointing.y, clickDownTilePointing.y) && multiplacementCount < maximumMultiplacement; j++) { Vector3Int cell = new Vector3Int(i, j, tilePointing.z); modifier.OverrideTile(brush.data.tile, matrix, cell, false); multiplacementCount++; } } } else { GameObject element = Instantiate(brush.data.prefab); element.name = brush.data.prefab.name; element.transform.position = preview.transform.position; element.transform.eulerAngles = new Vector3(0, preview.transform.eulerAngles.y, 0); element.transform.localScale = Vector3.one; modifier.grid.AddGameObject(element, brush.data.layer, true, false); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing, true); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 0, 0), true); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(0, 1, 0), true); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 1, 0), true); } } // place a construction interaction on the building in order to properly construct it else { if (brush.data.tile != null) { int multiplacementCount = 0; for (int i = Mathf.Min(tilePointing.x, clickDownTilePointing.x); i <= Mathf.Max(tilePointing.x, clickDownTilePointing.x) && multiplacementCount < maximumMultiplacement; i++) { for (int j = Mathf.Min(tilePointing.y, clickDownTilePointing.y); j <= Mathf.Max(tilePointing.y, clickDownTilePointing.y) && multiplacementCount < maximumMultiplacement; j++) { Vector3Int cell = new Vector3Int(i, j, tilePointing.z); Vector3 p = modifier.GetTileCenter(cell); if (HoveringObjects(p)) { continue; } GameObject prefab = Instantiate(constructionTilePrefab); prefab.name = brush.data.tile.name + "Construction"; prefab.transform.position = p; prefab.transform.eulerAngles = new Vector3(0, preview.transform.eulerAngles.y, 0); prefab.transform.localScale = Vector3.one; modifier.grid.AddGameObject(prefab, brush.data.layer, false, false); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, cell, true); // override interactor Transform previousInteractor = prefab.transform.Find("interactor"); if (previousInteractor != null) { Destroy(previousInteractor.gameObject); } ConstructionController interactor = Instantiate <ConstructionController>(constructionInteractor); interactor.transform.parent = prefab.transform; interactor.gameObject.name = "interactor"; interactor.transform.localPosition = Vector3.zero; interactor.transform.localRotation = Quaternion.identity; interactor.transform.localScale = Vector3.one; interactor.orientation = preview.transform.eulerAngles.y; interactor.data = brush.data; interactor.Initialize(); multiplacementCount++; } } } else { GameObject prefab = Instantiate(brush.data.prefab); prefab.name = brush.data.prefab.name + "Construction"; prefab.transform.position = preview.transform.position; prefab.transform.eulerAngles = new Vector3(0, preview.transform.eulerAngles.y, 0); prefab.transform.localScale = Vector3.one; modifier.grid.AddGameObject(prefab, brush.data.layer, false, false); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing, true); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 0, 0), true); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(0, 1, 0), true); modifier.OverrideTile(modifier.tileDictionary["Dirt"], Matrix4x4.identity, tilePointing + new Vector3Int(1, 1, 0), true); // override interactor Transform previousInteractor = prefab.transform.Find("interactor"); if (previousInteractor != null) { Destroy(previousInteractor.gameObject); } ConstructionController interactor = Instantiate <ConstructionController>(constructionInteractor); interactor.transform.parent = prefab.transform; interactor.gameObject.name = "interactor"; interactor.transform.localPosition = Vector3.zero; interactor.transform.localRotation = Quaternion.identity; interactor.transform.localScale = Vector3.one; interactor.orientation = preview.transform.eulerAngles.y; interactor.data = brush.data; interactor.Initialize(); } } } // clear multi view if (Input.GetMouseButtonUp(0)) { foreach (MeshRenderer mr in multiPreviewRenderers) { mr.gameObject.SetActive(false); } } } }
public void InteractionTick() { if (interactionTickTime != 0f) // because sometimes the functioon is called twice per frame { return; } interactionTime = interactionCooldown; interactionTickTime = interactionTickCooldown; if (hoveredInteractor) { if (lastInteraction == InteractionType.Type.collectWood) { interactionJuicer.treeInteractor = hoveredInteractor; CommonRessourceCollectionResolve(); } else if (InteractionType.isCollectingMinerals(lastInteraction)) { CommonRessourceCollectionResolve(); } else if (lastInteraction == InteractionType.Type.collectWheat) { CommonRessourceCollectionResolve(); } else if (lastInteraction == InteractionType.Type.construction) { List <AudioClip> sounds = ResourceDictionary.instance.resources["Iron"].collectingSound; AudioClip soundFx = sounds[Random.Range(0, sounds.Count)]; audiosource.clip = soundFx; if (soundFx) { audiosource.Play(); } // increment progress bar ConstructionController construction = hoveredInteractor.GetComponent <ConstructionController>(); if (construction && construction.Increment()) { interactionTime = 0f; hoveredInteractor = null; animator.SetBool("interaction", false); } } /*else if (lastInteraction == InteractionType.Type.destroyBuilding) * { * List<AudioClip> sounds = ResourceDictionary.instance.resources["Iron"].collectingSound; * AudioClip soundFx = sounds[Random.Range(0, sounds.Count)]; * audiosource.clip = soundFx; * if (soundFx) * audiosource.Play(); * * // increment progress bar * DestructionTemplate destruction = hoveredInteractor.GetComponent<DestructionTemplate>(); * if (destruction.Increment()) * { * interactionTime = 0f; * hoveredInteractor = null; * animator.SetBool("interaction", false); * } * }*/ else { // error interacting = false; hoveredInteractor = null; interactionTime = 0f; animator.SetBool("interaction", false); Debug.LogWarning("no interaction tick for this type implemented : " + lastInteraction.ToString()); } } else { // error interacting = false; hoveredInteractor = null; interactionTime = 0f; animator.SetBool("interaction", false); } }
void Start() { mainCamera = Camera.main; constructionController = FindObjectOfType <ConstructionController>(); }