/// <summary> /// Generates a collection of Placeable objects in the world and sets them on planes that match their affinity. /// </summary> /// <param name="horizontalSurfaces">Horizontal surface planes (floors, tables).</param> /// <param name="verticalSurfaces">Vertical surface planes (walls).</param> public void GenerateItemsInWorld(List <GameObject> horizontalSurfaces, List <GameObject> verticalSurfaces) { List <GameObject> horizontalObjects = new List <GameObject>(); List <GameObject> verticalObjects = new List <GameObject>(); foreach (GameObject prefab in objectPrefabs) { Placable placeable = prefab.GetComponent <Placable>(); if (placeable.PlacementSurface == PlacementSurfaces.Horizontal) { horizontalObjects.Add(prefab); } else { verticalObjects.Add(prefab); } } if (horizontalObjects.Count > 0) { CreateSpaceObjects(horizontalObjects, horizontalSurfaces, PlacementSurfaces.Horizontal); } if (verticalObjects.Count > 0) { CreateSpaceObjects(verticalObjects, verticalSurfaces, PlacementSurfaces.Vertical); } }
public override void Enable(GameObject obj) { base.Enable(obj); Placable pla = obj.GetComponent <Placable> (); pla.Cell.Select = true; }
public void StartPlacing(PlacableData placable) { if (currentPlacing != null) { Destroy(currentPlacing.gameObject); } currentPlacing = Instantiate(placable.Prefab).GetComponent <Placable>(); currentPlacing.Data = placable; ItemController itemController = currentPlacing.GetComponent <ItemController>(); if (itemController != null) { if (placable.Unlimited) { itemController.SetAmountLeft(1f); } else { itemController.SetAmountLeft(PlayerManager.Instance.GetItemHealth(placable) - (PlayerManager.Instance.GetInventoryCount(placable) - 1)); } } lastPos = null; HelpUI.gameObject.SetActive(true); playArea.ShowPlacing(true); PlaceCurrent(); placingDown = false; if (IsNonXR) { BookController.Instance.ReturnBook(); } }
public void PlaceObject(Placable p) { if (placeObjectHandler == null) { placeObjectHandler = gameObject.AddComponent <PlaceableObjectHandler> (); placeObjectHandler.Init(p, this); } }
public override void AddToArea(Placable placable) { base.AddToArea(placable); if (isPlaced) { CheckForCats(); } }
public virtual void AddToArea(Placable placable) { if (!placedInArea.Contains(placable)) { placedInArea.Add(placable); placable.AddedToArea(); } areaDirty = true; }
public virtual void RemoveFromArea(Placable placable) { if (placedInArea.Contains(placable)) { placedInArea.Remove(placable); placable.RemovedFromArea(); } areaDirty = true; }
bool IsAtLoc(Placable placable) { for (int i = 0; i < placementLocations.Length; i++) { if (placementLocations[i].CurrentPlacable == placable) { return(true); } } return(false); }
public void Replace(Placable oldPlacable, PlacableData newData) { currentPlacing = Instantiate(newData.Prefab).GetComponent <Placable>(); currentPlacing.Data = newData; currentPlacing.transform.SetParent(oldPlacable.transform.parent); currentPlacing.transform.localPosition = oldPlacable.transform.localPosition; currentPlacing.transform.localRotation = oldPlacable.transform.localRotation; currentPlacing.transform.localScale = oldPlacable.transform.localScale; currentArea.RemoveFromArea(oldPlacable); Destroy(oldPlacable.gameObject); currentArea.AddToArea(currentPlacing); currentPlacing = null; }
public override void Enable(GameObject obj) { base.Enable(obj); Placable pla = obj.GetComponent <Placable> (); radiusAttack = MeshMap.Instance.CellRadius(pla.Cell, po); foreach (Cell c in radiusAttack) { if (c.Content == null || c.Content.GetComponent <Entity>() != null) { c.Select = true; } } }
// Update is called once per frame void Update() { Ray mouseRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(mouseRay, out hit) == true) { //we know - // it hit something // what ever it hit, that info is stored in 'hit' variable //(lowkey making an assumtion - what is that? we hit a tile) // tile has our Placable // lets try to get that Placable p = hit.collider.GetComponent <Placable>(); if (p != null && p.isAvailable == true) //if we were able to actually get the Placable component { //>>Hover Mechanic<< // Get hologram of current tower GameObject holgram = holograms[currentHolo]; // Activate hologram holgram.SetActive(true); // Position hologram to tile holgram.transform.position = p.GetPivotPoint(); //>>Placement Mechanic<< // If left mouse is down if (Input.GetMouseButtonDown(0)) { // Get the current tower prefab GameObject tower = towers[currentTower]; // Spawn a new tower GameObject clone = Instantiate(tower, towerParent); // Position new tower to tile clone.transform.position = p.GetPivotPoint(); //clone.po // Tile is no longer placeable p.isAvailable = false; } } } else { DisableAllHolograms(); } }
public void SetPlacable(PlacableData placable, bool showEffect = false) { if (CurrentPlacable != null) { PlacementManager.Instance.Remove(Owner, CurrentPlacable); CurrentPlacable = null; } if (placable != null) { CurrentPlacable = PlacementManager.Instance.PlaceAt(Owner, placable, transform.localPosition); CurrentPlacable.gameObject.AddComponent <RelayClickable>().ParentClickable = this; if (showEffect && placeEfect != null) { placeEfect.Play(); } } }
public void Place(GameObject placePreviewPrefab, GameObject placePreviewInvalidPrefab, Placable placable, CheckPlace checkPlace, bool showOverlay) { placePreviewValid = Instantiate(placePreviewPrefab); if (placePreviewInvalidPrefab != null) { placePreviewInvalid = Instantiate(placePreviewInvalidPrefab); } placing = true; waitingPlacable = placable; waitingCheckPlace = checkPlace; if (showOverlay) { overlay.StartOverlay(); } }
IEnumerator WaitToSpawnCat() { if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) { yield return(new WaitForSeconds(1f)); } else { yield return(new WaitForSeconds(waitingCat.Prefab.GetComponent <CatController>().SpawnWait[CatManager.Instance.GetMood(waitingCat)])); } Placable cat = PlacementManager.Instance.PlaceAt(this, waitingCat, CatSpawnPoint.localPosition, true); CatManager.Instance.EnterArea(waitingCat); cat.GetComponent <CatController>().EnterArea(); waitingCat = null; CheckForCats(); }
public void ShowUpgrade(UpgradeClickable upgradable) { placable = upgradable; upgradeData = upgradable.Data as UpgradableData; if (upgradeData.Upgrade != null) { Dictionary <PlacableData, int> upRequs = new Dictionary <PlacableData, int>(); for (int i = 0; i < upgradeData.UpgradeRequirements.Length; i++) { if (upRequs.ContainsKey(upgradeData.UpgradeRequirements[i])) { upRequs[upgradeData.UpgradeRequirements[i]]++; } else { upRequs.Add(upgradeData.UpgradeRequirements[i], 1); } } upgradeAllowed = true; string requsText = ""; foreach (KeyValuePair <PlacableData, int> pair in upRequs) { int invCount = PlayerManager.Instance.GetInventoryCount(pair.Key); requsText += invCount + " / " + pair.Value + " " + pair.Key.Name; if (invCount < pair.Value) { upgradeAllowed = false; } } RequsLabel.text = requsText; UpgradeButton.interactable = upgradeAllowed; } else { upgradeAllowed = false; RequsLabel.text = "Not upgradable"; UpgradeButton.interactable = upgradeAllowed; } }
void OnCompleteTutorialStep(TutorialStep currentStep) { if (currentStep == TutorialStep.Mail) { targetPos = MailboxManager.Instance.transform.localPosition; SetState <TutorialWalkState>(); } else if (currentStep == TutorialStep.GrabBook) { targetPos = BookController.Instance.transform.localPosition; SetState <TutorialWalkState>(); } else if (currentStep == TutorialStep.PlaceTreat) { SetState <SitState>(); } else if (currentStep == TutorialStep.CraftToy) { target = playArea.GetInArea(PlacableDataType.Treat)[0]; SetState <WalkState>(); } }
public Placable PlaceAt(PlacementArea area, PlacableData placable, Vector3 position, Vector3 rotation, bool onNav = false) { Placable newPlacable = null; if (onNav) { newPlacable = Instantiate(placable.Prefab, GetWorldNavPos(position), Quaternion.identity).GetComponent <Placable>(); newPlacable.Data = placable; newPlacable.transform.SetParent(area.Contents); } else { newPlacable = Instantiate(placable.Prefab).GetComponent <Placable>(); newPlacable.Data = placable; newPlacable.transform.SetParent(area.Contents); newPlacable.transform.localPosition = position; } newPlacable.transform.localRotation = Quaternion.Euler(rotation); newPlacable.transform.localScale = Vector3.one; area.AddToArea(newPlacable); return(newPlacable); }
public override void RemoveFromArea(Placable placable) { base.RemoveFromArea(placable); CheckWaitingCat(); }
} // core function for init modular set public bool StrokeModularPlacable(ModularPieceData PieceData, System.Action <ModularPlacableObject> OnPlaced, System.Func <int, bool> CanPlace) { if (PieceData != null) { // init new modular set GameManager.I.Modular.ScopedSet = InitNewModularSet(); GameManager.I.Modular.ScopedSet.InitializeEditable(); // place HashSet <ModularSet> AffectedSets = new HashSet <ModularSet> (); if (PieceData.Prefab != null && PieceData.Prefab.GetComponent <StrokeModularPiece> () != null) { StrokeModularPiece StrokePiece = PieceData.Prefab.GetComponent <StrokeModularPiece> (); // get stroke piece from prefab ModularStrokeSetData StrokeSet = GameManager.I.Modular.FindStrokeSet(PieceData.Key); if (StrokeSet != null) // if there is found a strokeset { return(StrokeModularPlacable(PieceData, (ModularPlacableObject Placable) => { // on deleted if (typeof(ModularPiece).IsAssignableFrom(Placable.GetType())) { ModularPiece Piece = (ModularPiece)Placable; ModularSet ParentSet = Piece.ParentSet; if (ParentSet != null) { bool NotDestoryed = ParentSet.RemoveModularPiece(Piece); // remove piece from set if (!AffectedSets.Contains(ParentSet)) // add set to affected sets { AffectedSets.Add(ParentSet); } else if (!NotDestoryed) { AffectedSets.Remove(ParentSet); } } } }, OnPlaced, (object[] Data) => { // on cancel if (!AffectedSets.Contains(GameManager.I.Modular.ScopedSet)) { AffectedSets.Add(GameManager.I.Modular.ScopedSet); } foreach (ModularSet Set in AffectedSets) { Set.FinalizeSet(Management.GameManager.I.Modular.ModularPieceLayer); } // Update render sets of affected modular sets Statemachine.changeState(new ModularSpectate(), this); }, (StrokeType Type) => { // return information return StrokeSet.FindStrokePieceComponent(Type); }, (StrokeType Type) => { // return new instance ModularPieceData Piece = StrokeSet.FindPiece(Type); if (Piece == null) { Piece = PieceData; } var Object = InitStoreItem(Piece, Vector3.one); Object.InitializeEditable(); GameManager.I.Modular.ScopedSet.AddModularPiece(Object); // add piece to set return Object; }, CanPlace)); } } } return(false); }
public void Remove(Placable oldPlacable) { Remove(currentArea, oldPlacable); }
//private PlayerController pc; public void Init(Placable neoObject, PlayerController pc) { //this.pc = pc; myPlacable = neoObject; placableInstance = Instantiate(myPlacable.prefab, transform.position + transform.forward * offsetZ + Vector3.up * 0.05f, Quaternion.identity); }
public void Remove(PlacementArea area, Placable oldPlacable) { area.RemoveFromArea(oldPlacable); Destroy(oldPlacable.gameObject); }
void Update() { if (provider == null) { return; } if (placingArea) { BoundedPlane plane; if (provider.GetPlane(out plane)) { playArea.transform.position = plane.Center; playArea.transform.rotation = plane.Pose.rotation; float scale = Mathf.Min(1f, plane.Size.x, plane.Size.y); playArea.transform.localScale = Vector3.one * scale; playArea.gameObject.SetActive(true); Vector3 forword = -playArea.transform.forward; forword.y = 0f; Vector3 look = Camera.main.transform.position - playArea.transform.position; look.y = 0f; float angle = Vector3.SignedAngle(look, forword, Vector3.up); if (angle > 135f || angle < -135f) { playArea.transform.Rotate(playArea.transform.up, 180f); } else if (angle > 45f) { playArea.transform.Rotate(playArea.transform.up, -90f); } else if (angle < -45f) { playArea.transform.Rotate(playArea.transform.up, 90f); } HelpUI.ShowPlace(); if (provider.GetClickDown()) { placingArea = false; provider.holdAttachPoint.localPosition = provider.holdAttachPoint.localPosition * scale; provider.holdAttachPoint.localScale = Vector3.one * scale; //UIManager.Instance.GoBackToUI(MainUI); LoadingUI.SetActive(false); HelpUI.gameObject.SetActive(false); playArea.SetArea(); provider.FinishInit(); } } else { playArea.gameObject.SetActive(false); HelpUI.ShowLooking(); } } else if (heldBook != null) { if (provider.GetClickUp()) { heldBook.transform.SetParent(playArea.transform); heldBook.PlaceBook(); heldBook = null; HelpUI.gameObject.SetActive(false); } } else if (currentPlacing == null) { if (currentClickable == null) { #if UNITY_EDITOR || UNITY_STANDALONE if (provider.GetClickDown()) #else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) #endif { RaycastHit hit; if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity, (1 << LayerMask.NameToLayer("Placable")) | (1 << LayerMask.NameToLayer("UI")))) { if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Placable")) { currentClickable = hit.transform.GetComponentInParent <Clickable>(); if (currentClickable != null) { currentClickable.ClickDown(hit); } else if (currentArea.AllowMovement) { currentPlacing = hit.transform.GetComponentInParent <Placable>(); lastPos = currentPlacing.transform.localPosition; placingDown = true; } } } } } else { if (provider.GetClickUp()) { RaycastHit hit; if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity, 1 << LayerMask.NameToLayer("Placable"))) { Clickable upClickable = hit.transform.GetComponentInParent <Clickable>(); if (upClickable == currentClickable) { currentClickable.Click(hit); } } currentClickable.ClickUp(hit); currentClickable = null; } } } else { PlaceCurrent(); if (provider.GetClickDown()) { placingDown = true; } else if (placingDown && provider.GetClickUp()) { if (placed) { if (lastPos.HasValue) { if (currentArea != null) { currentArea.MoveInArea(currentPlacing); } } else { if (currentArea != null) { currentArea.AddToArea(currentPlacing); PlayerManager.Instance.RemoveInventory(currentPlacing.Data); } } currentPlacing = null; HelpUI.gameObject.SetActive(false); playArea.ShowPlacing(false); if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceTreat) { HelpManager.Instance.CompleteTutorialStep(TutorialStep.PlaceTreat); } else if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) { HelpManager.Instance.CompleteTutorialStep(TutorialStep.PlaceToy); } placingDown = false; SoundManager.Instance.PlayGroup("PlaceItem"); if (IsNonXR) { GrabBook(BookController.Instance); } } /*else * { * /*if (lastPos.HasValue) * currentPlacing.transform.localPosition = lastPos.Value; * else* * if (currentArea != null) * currentArea.RemoveFromArea(currentPlacing); * PlayerManager.Instance.AddInventory(currentPlacing.Data); * Destroy(currentPlacing.gameObject); * }*/ } } if (currentClickable == null) { #if UNITY_EDITOR || UNITY_STANDALONE if (provider.GetClickDown()) #else if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)) #endif { RaycastHit hit; if (Physics.Raycast(provider.GetClickRay(), out hit, Mathf.Infinity)) { if (hit.collider.gameObject.layer == LayerMask.NameToLayer("Base")) { BookController.Instance.ReturnBook(); } } } } }
protected virtual void Awake() { placable = GetComponent <Placable>(); }
public virtual void MoveInArea(Placable placable) { placable.MoveInArea(); areaDirty = true; }