private void OnEnable() { for (int i = 0; i < Content.childCount; i++) { Destroy(Content.GetChild(i).gameObject); } for (int i = 0; i < DataManager.Instance.Cats.Length; i++) { PlacableData catData = DataManager.Instance.Cats[i]; GameObject obj = Instantiate(ButtonPrefab); obj.transform.SetParent(Content, false); (obj.transform as RectTransform).anchoredPosition = new Vector2(-220 + (i % 2) * 440, 500 - (i / 2) * 440); Image image = obj.transform.Find("Image").GetComponent <Image>(); image.sprite = catData.Icon; Button button = obj.GetComponent <Button>(); if (File.Exists(Application.persistentDataPath + "/" + catData.name + ".png")) { button.onClick.RemoveAllListeners(); button.onClick.AddListener(new UnityEngine.Events.UnityAction(() => { ShowPhoto(catData); })); image.color = Color.white; } else { button.interactable = false; image.color = Color.black; } } }
public void SetAttached(PlacableData placable) { RemoveAttached(); CurrentAttached = Instantiate(placable.Prefab).GetComponent <Placable>(); CurrentAttached.Data = placable; ItemController itemController = CurrentAttached.GetComponent <ItemController>(); if (itemController != null) { if (placable.Unlimited) { itemController.SetAmountLeft(1f); } else { itemController.SetAmountLeft(PlayerManager.Instance.GetItemHealth(placable) - (PlayerManager.Instance.GetInventoryCount(placable) - 1)); } } CurrentAttached.transform.SetParent(provider.holdAttachPoint); CurrentAttached.transform.localPosition = Vector3.zero; CurrentAttached.transform.localRotation = placable.Prefab.transform.rotation; CurrentAttached.transform.localScale = Vector3.one; playArea.CheckForCats(); }
public void SetPlacable(PlacableData placable) { Placable = placable; Icon.sprite = Placable.Icon; UpdateCount(); PlayerManager.Instance.onInventoryChange += UpdateCount; }
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(); } }
void AddButton(PlacableData componentData) { GameObject obj = Instantiate(ButtonPrefab); obj.transform.SetParent(Content, false); (obj.transform as RectTransform).anchoredPosition = new Vector2(120 + (buttonCount % 4) * 200, -120 - (buttonCount / 4) * 200); obj.GetComponent <InventoryDebugButton>().SetPlacable(componentData); buttonCount++; }
public float GetItemHealth(PlacableData data) { if (itemHealth.ContainsKey(data)) { return(itemHealth[data]); } return(0f); }
void SetRequButton(int i, PlacableData itemData) { requs[i].SetActive(true); PlacableButton image = requs[i].GetComponent <PlacableButton>(); image.SetPlacable(itemData); Button button = requs[i].GetComponent <Button>(); button.onClick.RemoveAllListeners(); button.onClick.AddListener(new UnityEngine.Events.UnityAction(() => { Book.ShowItem(itemData); })); }
public void AddCatPhoto(PlacableData data, Texture2D photo) { if (catPhotos.ContainsKey(data)) { catPhotos[data] = photo; } else { catPhotos.Add(data, photo); } }
void AddWeight(Dictionary <PlacableData, int> weights, PlacableData item, int weight, ref int totalWeight) { if (weights.ContainsKey(item)) { weights[item] += weight; } else { weights.Add(item, weight); } totalWeight += weight; }
public List <Placable> GetInArea(PlacableData data) { tempPlacables.Clear(); for (int i = 0; i < placedInArea.Count; i++) { if (data == placedInArea[i].Data) { tempPlacables.Add(placedInArea[i]); } } return(tempPlacables); }
public void ShowItem(PlacableData item) { for (int i = 0; i < tabs.Length; i++) { if (tabs[i].PlacableDataType == item.DataType) { tabs[i].ItemPage.SetItem(item); uiManager.ShowUI(tabs[i].ItemPage.gameObject); break; } } }
public bool HasRecipe(PlacableData data) { for (int i = 0; i < inventory.Count; i++) { RecipeData recipe = inventory[i] as RecipeData; if (recipe != null && recipe.Product == data) { return(true); } } return(false); }
public int GetInventoryCount(PlacableData data) { int count = 0; for (int i = 0; i < inventory.Count; i++) { if (inventory[i] == data) { count++; } } return(count); }
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 void SetPlacable(PlacableData placable) { Placable = placable; if (Placable.Icon != null) { Label.gameObject.SetActive(false); Icon.gameObject.SetActive(true); Icon.sprite = Placable.Icon; if ((placable.DataType == PlacableDataType.Cat && !CatManager.Instance.IsFound(placable as CatData)) || ((placable.DataType == PlacableDataType.Toy || placable.DataType == PlacableDataType.Treat) && !PlayerManager.Instance.HasRecipe(placable))) { Icon.color = Color.black; } else { Icon.color = Color.white; } } else { Icon.gameObject.SetActive(false); Label.gameObject.SetActive(true); Label.text = Placable.Name; } for (int i = 0; i < Backs.Length; i++) { Backs[i].SetActive(false); } if (placable.DataType == PlacableDataType.Tower) { Backs[0].SetActive(true); GetComponent <Button>().targetGraphic = Backs[0].GetComponent <Image>(); } else if (placable.DataType == PlacableDataType.Cat) { Backs[1].SetActive(true); GetComponent <Button>().targetGraphic = Backs[1].GetComponent <Image>(); } else if (placable.DataType == PlacableDataType.Toy) { Backs[2].SetActive(true); GetComponent <Button>().targetGraphic = Backs[2].GetComponent <Image>(); } else if (placable.DataType == PlacableDataType.Treat) { Backs[3].SetActive(true); GetComponent <Button>().targetGraphic = Backs[3].GetComponent <Image>(); } }
public void Load() { if (File.Exists(Application.persistentDataPath + "/" + gameObject.name + "_" + DataManager.saveVersion + ".txt")) { string[] placedNames = File.ReadAllLines(Application.persistentDataPath + "/" + gameObject.name + "_" + DataManager.saveVersion + ".txt"); for (int i = 0; i < placementLocations.Length; i++) { PlacableData item = DataManager.Instance.GetData(placedNames[2 * i]); if (item != null) { placementLocations[i].SetPlacable(item); if (placementLocations[i].CurrentPlacable.GetComponent <ItemController>() != null) { placementLocations[i].CurrentPlacable.GetComponent <ItemController>().SetAmountLeft(float.Parse(placedNames[2 * i + 1])); } } } for (int i = placementLocations.Length * 2; i < placedNames.Length; i += 4) { PlacableData item = DataManager.Instance.GetData(placedNames[i]); if (item != null) { CatController cat = item.Prefab.GetComponent <CatController>(); if (cat == null || cat.StayForever || CatManager.Instance.TimeSinceEnter(item as CatData) < cat.StayLength[CatManager.Instance.GetMood(item as CatData)]) { Vector3 pos = new Vector3(float.Parse(placedNames[i + 1]), float.Parse(placedNames[i + 2]), float.Parse(placedNames[i + 3])); PlacementManager.Instance.PlaceAt(this, item, pos); } else { CatManager.Instance.LeftAreaAfter(item as CatData, cat.StayLength[CatManager.Instance.GetMood(item as CatData)]); } } } } else { for (int i = 0; i < placementLocations.Length; i++) { placementLocations[i].SetPlacable(placementLocations[i].StartingPlacable); } for (int i = 0; i < startingInArea.Length; i++) { PlacementManager.Instance.PlaceAt(this, startingInArea[i].Placable, startingInArea[i].Position, startingInArea[i].Rotation); } } finishedLoading = true; }
public bool HasRecipe(PlacableData data) { for (int i = 0; i < letters.Count; i++) { foreach (KeyValuePair <PlacableData, int> pair in letters[i].Gifts) { RecipeData recipe = pair.Key as RecipeData; if (recipe != null && recipe.Product == data) { return(true); } } } return(false); }
public void AddItemHealth(PlacableData data, float health) { if (itemHealth.ContainsKey(data)) { itemHealth[data] += health; } else { itemHealth[data] = health; } if (itemHealth[data] < 0f) { itemHealth[data] = 0f; } }
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 Texture2D GetCatPhoto(PlacableData data) { if (catPhotos.ContainsKey(data)) { return(catPhotos[data]); } if (File.Exists(Application.persistentDataPath + "/" + data.name + ".png")) { Texture2D photo = new Texture2D(2, 2, TextureFormat.RGB24, false); photo.LoadImage(File.ReadAllBytes(Application.persistentDataPath + "/" + data.name + ".png")); catPhotos.Add(data, photo); return(photo); } return(null); }
private void Awake() { Instance = this; if (File.Exists(Application.persistentDataPath + "/inventory_" + DataManager.saveVersion + ".txt")) { string[] invNames = File.ReadAllLines(Application.persistentDataPath + "/inventory_" + DataManager.saveVersion + ".txt"); int i = 0; while (i < invNames.Length && invNames[i] != "----") { PlacableData item = DataManager.Instance.GetData(invNames[i]); if (item != null) { inventory.Add(item); } i++; } i++; while (i < invNames.Length) { PlacableData item = DataManager.Instance.GetData(invNames[i]); if (item != null) { itemHealth.Add(item, float.Parse(invNames[i + 1])); } i += 2; } } else { inventory.AddRange(startingInventory); } for (int i = 0; i < inventory.Count; i++) { if (inventory[i] is UpgradableData) { UpgradableData upgradable = inventory[i] as UpgradableData; if (upgradable.Level > DataManager.Instance.GetTowerLevel(upgradable.MaterialType)) { DataManager.Instance.SetTowerLevel(upgradable.MaterialType, upgradable.Level); } } } }
private void Update() { if (!awarded) { percentShown = Mathf.MoveTowards(percentShown, percentComplete, Time.deltaTime * 0.5f); fillImage.fillAmount = percentShown; if (percentShown >= 1f) { outlineImage.gameObject.SetActive(false); fillImage.gameObject.SetActive(false); PlacableData resource = resources[Random.Range(0, resources.Length)]; itemImage.sprite = resource.Icon; itemImage.gameObject.SetActive(true); PlayerManager.Instance.AddInventory(resource); PlacesManager.Instance.CompleteInteraction(); awarded = true; } } }
public virtual void SetArea() { if (File.Exists(Application.persistentDataPath + "/" + gameObject.name + "_" + DataManager.saveVersion + ".txt")) { string[] placedNames = File.ReadAllLines(Application.persistentDataPath + "/" + gameObject.name + "_" + DataManager.saveVersion + ".txt"); for (int i = 0; i < placedNames.Length; i += 4) { PlacableData item = DataManager.Instance.GetData(placedNames[i]); if (item != null) { Vector3 pos = new Vector3(float.Parse(placedNames[i + 1]), float.Parse(placedNames[i + 2]), float.Parse(placedNames[i + 3])); PlacementManager.Instance.PlaceAt(this, item, pos); } } } else { for (int i = 0; i < startingInArea.Length; i++) { PlacementManager.Instance.PlaceAt(this, startingInArea[i].Placable, startingInArea[i].Position); } } }
protected override void OnEnable() { for (int i = 0; i < Content.childCount; i++) { Destroy(Content.GetChild(i).gameObject); } MaterialType[] materialTypes = System.Enum.GetValues(typeof(MaterialType)) as MaterialType[]; for (int i = 0; i < materialTypes.Length; i++) { int level = DataManager.Instance.GetTowerLevel(materialTypes[i]); PlacableData itemData = DataManager.Instance.GetTower(materialTypes[i], level == 0 ? 1 : level); GameObject obj = Instantiate(ButtonPrefab); obj.transform.SetParent(Content, false); (obj.transform as RectTransform).anchoredPosition = new Vector2(175 + (i % 3) * 250, -125 - (i / 3) * 250); PlacableButton image = obj.GetComponent <PlacableButton>(); image.SetPlacable(itemData); Button button = obj.GetComponent <Button>(); button.onClick.RemoveAllListeners(); button.onClick.AddListener(new UnityEngine.Events.UnityAction(() => { ShowItem(itemData); })); } Book.ShowPage(PlacableDataType); }
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); }
void ShowPhoto(PlacableData data) { photoUI.ShowPhoto(data); //UIManager.Instance.ShowUI(photoUI.gameObject); }
protected void ShowItem(PlacableData item) { ItemPage.SetItem(item); uiManager.ShowUI(ItemPage.gameObject); }
public override void SetItem(PlacableData item) { currentMat = (item as UpgradableData).MaterialType; current = (int)currentMat; }
public void ShowPhoto(PlacableData data) { Image.texture = PlayerManager.Instance.GetCatPhoto(data); }
protected virtual void OnEnable() { for (int i = 0; i < buttons.Count; i++) { buttons[i].gameObject.SetActive(false); } PlacableData[] allData = DataManager.Instance.GetAllData(PlacableDataType); Button button; for (int i = 0; i < allData.Length; i++) { PlacableData itemData = allData[i]; if (i < buttons.Count) { button = buttons[i]; button.gameObject.SetActive(true); } else { GameObject obj = Instantiate(ButtonPrefab); obj.transform.SetParent(Content, false); (obj.transform as RectTransform).anchoredPosition = new Vector2(175 + (i % 3) * 250, -125 - (i / 3) * 250); button = obj.GetComponent <Button>(); buttons.Add(button); } PlacableButton image = button.GetComponent <PlacableButton>(); image.SetPlacable(itemData); button.onClick.RemoveAllListeners(); button.onClick.AddListener(new UnityEngine.Events.UnityAction(() => { ShowItem(itemData); })); } if ((HelpManager.Instance.CurrentStep == TutorialStep.CraftToy || HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) && PlacableDataType != PlacableDataType.Toy) { if (buttonFlash == null) { Destroy(buttonFlash); } for (int i = 0; i < buttons.Count; i++) { buttons[i].interactable = false; } Book.FlashTab(PlacableDataType.Toy); } else if (HelpManager.Instance.CurrentStep == TutorialStep.PlaceTreat || HelpManager.Instance.CurrentStep == TutorialStep.CraftToy || HelpManager.Instance.CurrentStep == TutorialStep.PlaceToy) { if (buttonFlash == null) { buttonFlash = Instantiate(uiManager.flashPrefab); } buttonFlash.GetComponent <FlashUI>().SetTarget(buttons[0].targetGraphic as Image); buttons[0].interactable = true; for (int i = 1; i < buttons.Count; i++) { buttons[i].interactable = false; } Book.SetInteractable(false); } else { if (buttonFlash != null) { Destroy(buttonFlash); } for (int i = 0; i < buttons.Count; i++) { buttons[i].interactable = true; } Book.SetInteractable(true); } Book.ShowPage(PlacableDataType); }