Exemplo n.º 1
0
    private IEnumerator PlantGrow(ResourcePlantable resource)
    {
        yield return(new WaitForSeconds(resource.growTimeSeconds));

        if (resourcePlantable != null)
        {
            Destroy(plantObject);
            plantObject = Instantiate(resource.prefabs[1], transform);
            paramsData.havePlantGrown = true;
        }
        yield return(null);
    }
Exemplo n.º 2
0
    private void GatherSlot()
    {
        if (resourcePlantable != null && paramsData.havePlantGrown)
        {
            int pos = Array.IndexOf(resourcePlantable.gatherToolsID, toolsManager.activeTool.id);
            if (pos > -1)
            {
                resourcesManager.AddResourcePlantable(resourcePlantable.id, 1);

                notificationsManager.CreateNotificationGatherable(this.transform, resourcePlantable, 1);

                Destroy(plantObject);
                resourcePlantable         = null;
                paramsData.havePlantGrown = false;
            }
        }

        if (resourceSettable != null)
        {
            int pos = Array.IndexOf(resourceSettable.gatherToolsID, toolsManager.activeTool.id);
            if (pos > -1)
            {
                if (resourcePlantable != null)
                {
                    resourcesManager.AddResourcePlantable(resourcePlantable.id, 1);

                    if (paramsData.havePlantGrown)
                    {
                        notificationsManager.CreateNotificationGatherable(this.transform, resourcePlantable, 1);
                    }
                }

                resourcesManager.AddResourceSettable(resourceSettable.id, 1);

                Destroy(setObject);
                Destroy(plantObject);
                resourceSettable          = null;
                resourcePlantable         = null;
                paramsData.havePlantGrown = false;

                if (plantGrow != null)
                {
                    StopCoroutine(plantGrow);
                    plantGrow = null;
                }
            }
        }
    }
Exemplo n.º 3
0
    public void CreateNotificationGatherable(Transform slotFrom, ResourcePlantable resourceOrig, int addAmount)
    {
        Vector3 fromPos = Camera.main.WorldToScreenPoint(slotFrom.position);
        Vector3 toPos   = GameManager.Instance.resourcesManager.GetResourceGatherableTransform(resourceOrig.gatherToID).position;

        GameObject newNotif = Instantiate(gatherPrefab, fromPos, Quaternion.identity, notifOrigin);

        newNotif.GetComponent <Image>().sprite = resourceOrig.iconSprite;

        newNotif.transform.DOMove(toPos, 1f).OnComplete(() =>
        {
            GameManager.Instance.resourcesManager.AddResourceGatherable(resourceOrig.gatherToID, 1);
            Destroy(newNotif);
        });

        newNotif.GetComponent <Image>().DOFade(0f, 0.25f).SetDelay(0.75f);
    }
Exemplo n.º 4
0
    private void Spawn()
    {
        foreach (var resource in resourcesConfig.resourcesSettable)
        {
            ResourceSettable newRes = Instantiate(resourcesConfig.prefabSettable, originSettable).GetComponent <ResourceSettable>();

            if (SetIntoList(ref resourcesSettable, newRes, resource.id))
            {
                newRes.Initialize(resource);

                newRes.prefab        = resource.prefab;
                newRes.gatherToolsID = resource.gatherToolsID;
            }
        }

        foreach (var resource in resourcesConfig.resourcesPlantable)
        {
            ResourcePlantable newRes = Instantiate(resourcesConfig.prefabPlantable, originPlantable).GetComponent <ResourcePlantable>();

            if (SetIntoList(ref resourcesPlantable, newRes, resource.id))
            {
                newRes.Initialize(resource);

                newRes.growTimeSeconds = resource.growTimeSeconds;
                newRes.needSettableID  = resource.needSettableID;
                newRes.gatherToID      = resource.gatherToID;
                newRes.gatherToolsID   = resource.gatherToolsID;
                newRes.prefabs         = resource.prefabs;
            }
        }

        foreach (var resource in resourcesConfig.resourcesGatherable)
        {
            ResourceGatherable newRes = Instantiate(resourcesConfig.prefabGatherable, originGatherable).GetComponent <ResourceGatherable>();

            if (SetIntoList(ref resourcesGatherable, newRes, resource.id))
            {
                newRes.Initialize(resource);
            }
        }
    }
Exemplo n.º 5
0
    private void CreatePlantable(ResourcePlantable resource)
    {
        if (!resource.CheckAmount(-1))
        {
            return;
        }

        if (resourceSettable != null && resourcePlantable == null)
        {
            foreach (var id in resource.needSettableID)
            {
                if (resourceSettable.id == id)
                {
                    resourcePlantable = resource;
                    plantObject       = Instantiate(resource.prefabs[0], transform);
                    plantGrow         = PlantGrow(resource);
                    StartCoroutine(plantGrow);

                    resource.ChangeAmount(-1);
                }
            }
        }
    }