예제 #1
0
    public void resourcesMined(int amountMined)
    {
        int maxPerFloating = (int)((float)this.planetResource.maxCount / (float)resourceIndicatorCount);

        if (maxPerFloating == 0)
        {
            maxPerFloating = 1;
        }

        GameObject       obj      = null;
        FloatingResource floating = null;

        if (freeResources.Count == 0)
        {
            // TODO: They CAN exceeed maxPerFloating, but i really donot care by now...
            addNewFloating(out obj, out floating);
        }
        else
        {
            obj      = this.freeResources[this.freeResources.Count - 1];
            floating = obj.GetComponent <FloatingResource>();

            if (this.freeResources.Count == 0 || floating.resourceCount > maxPerFloating)
            {
                addNewFloating(out obj, out floating);
            }
        }

        // TODO: By now, resources CAN have more than maxPerFloating, but i do not want to fix this
        floating.resourceCount  += amountMined;
        obj.transform.localScale = Vector3.one * (float)floating.resourceCount / (float)maxPerFloating * maxResourceScale;
    }
예제 #2
0
    public int emptyFloatingListAndReturnAccumulatedValues(out ResourceTypes resourceType)
    {
        int resources = 0;

        for (int i = freeResources.Count - 1; i >= 0; i--)
        {
            FloatingResource floating = freeResources[i].GetComponent <FloatingResource>();
            if (floating != null)
            {
                resources += floating.resourceCount;
            }
            Destroy(freeResources[i]);
        }
        resourceType       = this.planetResource.resource.resourceType;
        this.freeResources = new List <GameObject>();
        return(resources);
    }
예제 #3
0
    public void addNewFloating(out GameObject obj, out FloatingResource floating)
    {
        obj = new GameObject("FloatingResource");
        obj.transform.parent = this.transform;

        floating          = obj.AddComponent <FloatingResource>();
        floating.resource = Instantiate(this.planetResource.resource);
        floating.resource.transform.parent = obj.transform;

        float t       = scale * Random.Range(0, 2 * (float)Math.PI);
        float scaling = 1.25f;

        obj.transform.localPosition = new Vector2((float)Math.Cos(t) * scaling, (float)Math.Sin(t) * scaling);
        floating.resource.transform.localPosition = obj.transform.localPosition;
        floating.resourceCount = 0;

        PolygonCollider2D colldier = obj.AddComponent <PolygonCollider2D>();

        colldier.isTrigger = true;

        this.freeResources.Add(obj);
    }