private bool PlantAction(Inventory userInventory) { GridSelector gridSelector = userInventory.GetComponent <GridSelector>(); Vector3Int selectionLocation = gridSelector.GetGridSelectionPosition(); Vector3 loc = gridSelector.GetGridWorldSelectionPosition(); RaycastHit2D[] findObjects = Physics2D.BoxCastAll(loc, gridManager.Grid.cellSize * 0.5f, 0, Vector2.zero, 50); // In case there is already a crop on this location, return. for (int i = 0; i < findObjects.Length; i++) { if (findObjects[i].transform.CompareTag("Crop")) { return(false); } } if (gridManager.HasDirtHole(selectionLocation)) { GameObject gameObject = plantablePrefab.Retrieve <GameObject>(); gameObject.transform.position = gridManager.GetWorldLocation(selectionLocation); return(true); } else { return(false); } }
public void DropItem(int slotIndex) { if (!GetItem(slotIndex).Data.IsRemoveable) { return; } isDirty = true; LootableItem lootable = droppableItemPrefab.Retrieve <LootableItem>(); if (lootable != null) { Aimer getAimer = this.GetComponent <Aimer>(); Vector2 aimDirection = Vector2.zero; if (getAimer != null) { aimDirection = getAimer.GetAimDirection(); } lootable.transform.position = (Vector2)this.transform.position + (aimDirection * (lootable.PickupDistance() * 1.05f)); lootable.Configure(GetItem(slotIndex).Data, GetItem(slotIndex).Amount); lootable.gameObject.SetActive(true); foreach (var dispatcher in eventDispatchers.Values) { dispatcher.DispatchDropItem(slotIndex, lootable); } } RemoveItem(slotIndex); }
public void OnLoad(string data) { if (string.IsNullOrEmpty(data)) { return; } currentSaveGame = SaveUtility.LoadSave(currentSaveSlot.Value); if (currentSaveGame == null) { Debug.Log("Could not find current save"); return; } SaveData saveData = JsonUtility.FromJson <SaveData>(data); if (saveData.data != null && saveData.data.Count > 0) { for (int i = 0; i < saveData.data.Count; i++) { SaveablePrefab saveablePrefab = ScriptableAssetDatabase.GetAsset(saveData.data[i].prefabGUID) as SaveablePrefab; if (saveablePrefab == null) { Debug.Log($"Could not find reference in ScriptableAssetDatabase for Saveable Prefab : {saveData.data[i].prefabGUID}"); continue; } for (int i2 = 0; i2 < saveData.data[i].saveableGUIDs.Count; i2++) { Saveable getSaveable = saveablePrefab.Retrieve <Saveable>(saveData.data[i].saveableGUIDs[i2]); getSaveable.OnLoadRequest(currentSaveGame); #if UNITY_EDITOR getSaveable.transform.SetParent(this.transform, true); #endif } } } }
public void Spawn() { GameObject obj = sp.Retrieve <GameObject>(); }