Ejemplo n.º 1
0
    // on double click in type 2 questions split
    // currently if you double click in the middle it glitches so fix that
    public void OnPointerClick(PointerEventData eventData)
    {
        Coefficient coef = this.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>();

        if (eventData.clickCount == 2 && coef != null && (typeOfItem == Draggable.Slot.Value || typeOfItem == Draggable.Slot.Variable))
        {
            if (coef.GetValue() > 1)
            {
                StartCoroutine(ShowSplit(coef.GetFractionValue() - 1));
            }
        }
    }
Ejemplo n.º 2
0
    // if Draggable object dropped onto this. Assuming all items dropped on it are Draggable.
    public void OnDrop(PointerEventData eventData)
    {
        glow.SetActive(false);
        showColor = false;

        int size = GetCurrentSize();

        if (size < capacity)
        {
            GameObject drop;
            if (!(eventData.pointerDrag.name.EndsWith("(Clone)")))
            {
                // dragging from a restock zone then hopefully
                RestockZone restock = eventData.pointerDrag.GetComponent <RestockZone>();
                if (restock != null)
                {
                    drop = restock.newObject;
                }
                else
                {
                    drop = eventData.pointerDrag;
                }
            }
            else
            {
                drop = eventData.pointerDrag;
            }

            Draggable dragged = drop.GetComponent <Draggable>();
            if (dragged != null)
            {
                dragged.parentToReturnTo = terms.transform;

                if (typeOfSide == Slot.Positive)
                {
                    dragged.ShowOnPositiveSide();
                    Transform coefficient = drop.transform.Find("Coefficient");
                    if (coefficient != null)
                    {
                        Coefficient coef = coefficient.gameObject.GetComponent <Coefficient>();
                        if (coef.GetValue() < 0)
                        {
                            coef.NegativeCurrentValue();
                        }
                    }
                }
                else if (typeOfSide == Slot.Negative)
                {
                    dragged.ShowOnNegativeSide();
                    Transform coefficient = drop.transform.Find("Coefficient");
                    if (coefficient != null)
                    {
                        Coefficient coef = coefficient.gameObject.GetComponent <Coefficient>();
                        if (coef.GetValue() > 0)
                        {
                            coef.NegativeCurrentValue();
                        }
                    }
                }
            }
        }
        else
        {
            OverCapacity();
        }
    }
Ejemplo n.º 3
0
    // when a term has been dropped on it react accordingly
    public void TermDroppedOn(bool alreadyDropped = true)
    {
        string dragData = "Bracket Coefficient dragged onto Bracket Inside Term " + numDroppedOn.ToString();

        dataController.StoreDragData(dragData);


        if (alreadyDropped)
        {
            numDroppedOn++;

            if (numDroppedOn == numTerms)
            {
                // we have successfully expanded the bracket
                Debug.Log("Expanded");
                soundEffects.PlayExpanded();

                int i           = 0;
                int numChildren = this.gameObject.transform.Find("TermsInBracket").childCount;
                while (i < numChildren)
                {
                    Transform child = this.gameObject.transform.Find("TermsInBracket").GetChild(i);

                    // multiply out coefficients
                    Coefficient coef    = child.Find("Coefficient").gameObject.GetComponent <Coefficient>();
                    Fraction    newCoef = coef.GetFractionValue() * this.gameObject.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>().GetFractionValue();
                    coef.SetValue(newCoef);

                    // reset as draggable
                    // child.gameObject.GetComponent<Draggable>().SetBracketStatus(false);
                    Destroy(child.gameObject.transform.Find("Coefficient").GetComponent <BracketInsideCoefficient>());

                    i++;
                }

                // update arrows
                Coefficient coeff = this.gameObject.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>();

                arrow1.gameObject.SetActive(true);
                arrow1.sprite = solidArrow;
                arrow1Text.SetActive(true);
                arrow1Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coeff.GetValue().ToString() + "x";

                arrow2.gameObject.SetActive(true);
                arrow2.gameObject.GetComponent <Image>().sprite = solidArrow;
                arrow2Text.SetActive(true);
                arrow2Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coeff.GetValue().ToString() + "x";

                coeff.SetValue(1);
                expanded = true;
            }
            else // first drop
            {
                soundEffects.PlayOneDragged();

                // show the arrows
                double coef = this.transform.Find("Coefficient").gameObject.GetComponent <Coefficient>().GetValue();
                if (this.transform.Find("TermsInBracket").GetChild(0).Find("Coefficient").gameObject.GetComponent <BracketInsideCoefficient>().droppedOn)
                {
                    // first item in bracket was dropped on
                    arrow1.gameObject.SetActive(true);
                    arrow1.sprite = solidArrow;
                    arrow1Text.SetActive(true);
                    arrow1Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coef.ToString() + "x";

                    arrow2.gameObject.SetActive(true);
                    arrow2.gameObject.GetComponent <Image>().sprite = dashedArrow;
                }
                else
                {
                    arrow2.gameObject.SetActive(true);
                    arrow2.sprite = solidArrow;
                    arrow2Text.SetActive(true);
                    arrow2Text.transform.Find("Text").gameObject.GetComponent <Text>().text = coef.ToString() + "x";

                    arrow1.gameObject.SetActive(true);
                    arrow1.gameObject.GetComponent <Image>().sprite = dashedArrow;
                }
            }
        }
    }