コード例 #1
0
    public void UpdateTransaction(GameObject sourceObject, int newMaxValue, int newCurrentValue, int newCurrentValueStep, bool investing,
                                  GameObject wsGaugeModel)
    {
        GameObject     boxSourceObject = null;
        TransactionBox boxComponent    = null;

        if ((sourceObject != null) && (boxSourceObjects != null))
        {
            for (int i = 0; i < boxSourceObjects.Length; i++)
            {
                boxSourceObject = boxSourceObjects[i];
                if (boxSourceObject == sourceObject)
                {
                    boxComponent = boxComponents[i];
                    boxComponent.ResetForReconstruction();
                    boxComponent.SetBoxLimits(boxLimits.x, boxLimits.y);
                    boxComponent.SetEssentials(symbolDatabase, bodySprite, "TO REPLACE", 0f, TextBox.TextAlignment.AlignMiddle,
                                               false, BOX_OPENING_SPEED);
                    boxComponent.SetOrnamentGauge(wsGaugeModel);
                    boxComponent.SetParameters(newMaxValue, newCurrentValue, newCurrentValueStep, investing);
                    boxComponent.Build();
                    return;
                }
            }
        }
    }
コード例 #2
0
    public bool CreateTransaction(GameObject sourceObject, ITransactionListener sourceListener, float sourceDistance,
                                  int maxValue, int currentValue, int currentValueStep, bool investing, bool tryAbove, GameObject wsGaugeModel)
    {
        GameObject     boxObject        = null;
        TransactionBox boxComponent     = null;
        Vector2        boxDimensions    = Vector2.zero;
        Vector2        boxOffset        = Vector2.zero;
        Vector3        boxPosition      = Vector3.zero;
        bool           boxPositionValid = false;
        GameObject     boxTailObject    = null;
        SpriteRenderer boxTailRenderer  = null;
        Vector2        tailOffset       = Vector2.zero;

        /*halmeida - if there is already a transaction with the sourceObject, we remove it immediately, before
         * creating a new one with the specified values.*/
        RemoveTransaction(sourceObject);
        if ((transactionBoxParent != null) && (symbolDatabase != null) && (sourceObject != null) && (sourceListener != null))
        {
            boxObject    = new GameObject("TransactionBox");
            boxComponent = boxObject.AddComponent <TransactionBox>();
            boxComponent.SetBoxLimits(boxLimits.x, boxLimits.y);
            boxComponent.SetEssentials(symbolDatabase, bodySprite, "TO REPLACE", 0f, TextBox.TextAlignment.AlignMiddle,
                                       false, BOX_OPENING_SPEED);
            boxComponent.SetOrnamentGauge(wsGaugeModel);
            boxComponent.SetParameters(maxValue, currentValue, currentValueStep, investing);
            boxTailObject          = new GameObject("TransactionBoxTail");
            boxTailRenderer        = boxTailObject.AddComponent <SpriteRenderer>();
            boxTailRenderer.sprite = tailSprite;

            boxComponent.Build();
            boxDimensions = boxComponent.GetBoxWorldDimensions();
            boxPosition   = GetBoxPositionForSource(sourceObject, sourceDistance, boxDimensions, tryAbove, ref boxPositionValid, ref tailOffset);
            if (boxPositionValid)
            {
                boxObject.transform.SetParent(transactionBoxParent.transform, false);

                /*halmeida - since the transactionBoxParent is at x = 0 and y = 0, I can use the local position of its
                 * children as if it was their position. Changing just the local position is faster.*/
                boxObject.transform.localPosition = boxPosition;
                boxTailObject.transform.SetParent(boxObject.transform, false);
                boxTailObject.transform.localPosition = new Vector3(tailOffset.x, tailOffset.y, boxComponent.GetBoxToTextDepth());
                if (tailOffset.y > 0f)
                {
                    boxTailObject.transform.rotation = Quaternion.Euler(0f, 0f, 180f);
                }
                boxComponent.Open();
                UsefulFunctions.IncreaseArray <GameObject>(ref boxObjects, boxObject);
                UsefulFunctions.IncreaseArray <TransactionBox>(ref boxComponents, boxComponent);
                UsefulFunctions.IncreaseArray <GameObject>(ref boxSourceObjects, sourceObject);
                UsefulFunctions.IncreaseArray <ITransactionListener>(ref boxSourceListeners, sourceListener);
                UsefulFunctions.IncreaseArray <float>(ref boxSourceDistances, sourceDistance);
                UsefulFunctions.IncreaseArray <bool>(ref boxTryAboves, tryAbove);
                UsefulFunctions.IncreaseArray <GameObject>(ref boxTailObjects, boxTailObject);
                UsefulFunctions.IncreaseArray <SpriteRenderer>(ref boxTailRenderers, boxTailRenderer);
                return(true);
            }
            boxComponent.Clear();
            GameObject.Destroy(boxObject);
            GameObject.Destroy(boxTailObject);
        }
        return(false);
    }