Пример #1
0
    public void ReturnToStart()
    {
        if (HasSprite())
        {
            //Reset sprite to the first one of the array when left clicked so count++ works
            if (blockId == 1)
            {
                sr.sprite = spriteLoopBlock[0];
            }
            if (blockId == 2)
            {
                sr.sprite = spriteLoopBlockEnd[0];
            }
            currentSprite = 0;

            Vector2 middle = new Vector2(transform.position.x, transform.position.y);
            Drag    block  = Instantiate(codeBlock, middle, Quaternion.identity);
            block.follow = false;
            block.GetComponent <SpriteRenderer>().sprite = sr.sprite;
            block.startPos = _startPos;
            block.locked   = true;
            sr.sprite      = spriteOrig;
            //Return the block id to 0, since the block is gone
            blockId = 0;
        }
    }
Пример #2
0
 public void ChangeToBlock(Sprite changeTo, Vector3 startPos)
 {
     if (sr.sprite != spriteOrig)
     {
         Vector2 middle = new Vector2(transform.position.x, transform.position.y);
         Drag    block  = Instantiate(codeBlock, middle, Quaternion.identity);
         block.follow = false;
         block.GetComponent <SpriteRenderer>().sprite = sr.sprite;
         block.startPos = _startPos;
         block.locked   = true;
     }
     _startPos = startPos;
     sr.sprite = changeTo;
 }
Пример #3
0
 public override bool CanReceiveDrop(Drag dragObject)
 {
     var newCard = dragObject.GetComponent<Card>();
     if (stack.Count == 0)
     {
         return newCard.Value == 13;
     }
     else
     {
         var lastCard = GetLastCard();
         return lastCard.ColorType != newCard.ColorType
             && lastCard.Value == newCard.Value + 1;
     }
 }
Пример #4
0
    public override bool CanReceiveDrop(Drag dragObject)
    {
        var newCard = dragObject.GetComponent <Card>();

        if (stack.Count == 0)
        {
            return(newCard.Value == 13);
        }
        else
        {
            var lastCard = GetLastCard();
            return(lastCard.ColorType != newCard.ColorType &&
                   lastCard.Value == newCard.Value + 1);
        }
    }
    bool BeforeDragClick(Drag drag)
    {
        bool res = false;
        int  id  = drag.GetComponent <DragSkill>().SkillStack.Skill.Id;

        if (id != currentSelectedSkill)
        {
            currentSelectedSkill = id;
            res = false;
            RefreshUI();
        }
        else
        {
            res = true;
        }

        return(res);
    }
Пример #6
0
    public void Update()
    {
        int EmptyPlate = 0;

        GameObject[] FoodObjects = GameObject.FindGameObjectsWithTag("Drag");
        foreach (GameObject Drag in FoodObjects)
        {
            Collider2D billCollider = Drag.GetComponent <Collider2D>();
            if (billCollider.bounds.Intersects(GreenTrigger.bounds))
            {
                EmptyPlate += Drag.GetComponent <OliverDragandDrop>().Organizer;
            }
        }

        if (EmptyPlate == FoodTotal && LoopNumber.text == OrderNumber.text)
        {
            SceneManager.LoadScene("DinnerWinner");
        }
    }
Пример #7
0
    private void Update()
    {
        //Constantly update the text
        textUi.text = count.ToString();
        //Give codeblock when clicked
        Vector2 clickpo = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position);

        if (count > 0 && !GameManager.instance.running && Input.GetMouseButtonDown(0) && (clickpo.x > -range) && (clickpo.x < range) && (clickpo.y > -range) && (clickpo.y < range))
        {
            Vector2 middle = new Vector2(transform.position.x, transform.position.y);
            Drag    block  = Instantiate(blockToGive, middle, Quaternion.identity);

            block.GetComponent <SpriteRenderer>().sprite = sr.sprite;

            block.startPos = middle;

            count--;
        }
    }
Пример #8
0
    public void OnDrop(Drag dragObject)
    {
        var pos = dragObject.transform.position;

        dragObject.GetComponent <SpriteRenderer>().sortingOrder = stack.Count;
    }
Пример #9
0
    private void Update()
    {
        //Change id according to sprite
        if (Array.IndexOf(spriteLoopBlockEnd, sr.sprite) > -1)
        {
            blockId = 2;
        }
        if (Array.IndexOf(spriteLoopBlock, sr.sprite) > -1)
        {
            blockId = 1;
        }
        if (sr.sprite != spriteOrig && !GameManager.instance.running)
        {
            Vector2 clickpo       = (Camera.main.ScreenToWorldPoint(Input.mousePosition) - transform.position);
            Vector2 clickpoGlobal = (Camera.main.ScreenToWorldPoint(Input.mousePosition));
            //Check if mouse on top
            if ((clickpo.x > -0.16f) && (clickpo.x < 0.16f) && (clickpo.y > -0.16f) && (clickpo.y < 0.16f) && clickpoGlobal.x > 0.32f && clickpoGlobal.x < 6.08f)
            {
                //Give codeblock when clicked
                if (Input.GetMouseButtonDown(0))
                {
                    Vector2 middle = new Vector2(transform.position.x, transform.position.y);
                    Drag    block  = Instantiate(codeBlock, middle, Quaternion.identity);
                    block.GetComponent <SpriteRenderer>().sprite = sr.sprite;
                    block.startPos = _startPos;
                    sr.sprite      = spriteOrig;
                    blockId        = 0;
                }
                //Change with mouse wheel if id = 0 (loop)
                if (blockId == 1 || blockId == 2)
                {
                    //Up
                    if (Input.GetAxis("Mouse ScrollWheel") > 0)
                    {
                        if (currentSprite < 8)
                        {
                            currentSprite++;
                        }
                        if (blockId == 1)
                        {
                            sr.sprite = spriteLoopBlock[currentSprite];
                        }
                        else
                        {
                            sr.sprite = spriteLoopBlockEnd[currentSprite];
                        }
                    }
                    //Down
                    if (Input.GetAxis("Mouse ScrollWheel") < 0)
                    {
                        if (currentSprite > 0)
                        {
                            currentSprite--;
                        }
                        if (blockId == 1)
                        {
                            sr.sprite = spriteLoopBlock[currentSprite];
                        }
                        else
                        {
                            sr.sprite = spriteLoopBlockEnd[currentSprite];
                        }
                    }
                }

                //Destroy with left click
                if (Input.GetMouseButtonDown(1))
                {
                    ReturnToStart();
                }
            }
        }
    }
Пример #10
0
    public void InsertAt(int Order, GameObject GameObj)
    {
        GameObj.GetComponent <Drag>().order = Order;
        //Debug.Log("Inserting " + GameObj + " at " + Order);
        //TODO: When inserting/removing a block inside a resizable block, the block after the resizable block won't change pos most of the time
        int SkipsPoint = 0;

        temporary = obj;
        int  StartPoint = 0;
        int  V          = 0;
        Drag res        = null;
        bool Skip       = false;
        bool Reset      = false;

        int AdvencementPoints = 0;

        if (temporary.Count == 0)
        {
            Skip = true;
        }
        for (int i = 0; !Skip; i++)
        {
            //Debug.Log("I is " + i);
            if (Reset && 0 < temporary.Count)
            {
                //Debug.Log("I is 0");
                i     = 0;
                Reset = false;
            }
            else if (Reset && 0 >= temporary.Count)
            {
                //Debug.Log("Out of sequence");
                V = 0;
                break;
            }
            //First, check to see if the block is inside a resizable block (Or inside a resizable that is inside a resizable block...)
            //Debug.Log("Is " + temporary.ToArray()[i].name + " a resizable block? " + temporary.ToArray()[i].GetComponent<Resize>());
            if (temporary.ToArray()[i].GetComponent <Resize>())             //order was order-startpoint
            //Debug.Log("Checking if " + (Order-StartPoint) + " is > than " + (AdvencementPoints-1) + " and < than " + (AdvencementPoints+temporary.ToArray()[i].GetComponent<Resize>().Steps));
            {
                if (Order > AdvencementPoints - 1 /* + i*/ && Order < AdvencementPoints + temporary.ToArray()[i].GetComponent <Resize>().Steps)
                {
                    AdvencementPoints++;
                    //Debug.Log("What is temporairy?");
                    //Debug.Log("res: " + temporary.ToArray()[i].GetComponent<Drag>().strsources[0] + ", temporary: " + temporary.ToArray()[i].GetComponent<Drag>().childs.Count);
                    res       = temporary.ToArray()[i].GetComponent <Drag>();
                    temporary = temporary.ToArray()[i].GetComponent <Drag>().childs;
                    V         = i;
                    //Debug.Log("Adding " + (i+1) + " to the StartPoint");
                    StartPoint += i /*+1*/;
                    Reset       = true;
                    //Debug.Log("Iteration: " + i);
                }
                else
                {
                    AdvencementPoints += temporary.ToArray()[i].GetComponent <Resize>().Steps + 1;
                }
            }
            else
            {
                AdvencementPoints++;
            }
            //StartPoint += i+1;
            if ((i + 1 >= temporary.Count) && !Reset)
            {
                //Debug.Log("Breaking");
                break;
            }
        }
        if (res != null)
        {
            res.AddChild(GameObj, Mathf.Clamp((Order - (StartPoint)), 0, res.GetComponent <Resize>().Steps - 2));

            //res is GOOD!

            //res.Replace();
            return;
        }

        obj.Insert(Mathf.Clamp(Order, 0, obj.Count), GameObj);
        for (int i = 0; i < obj.Count; i++)
        {
            obj.ToArray()[i].GetComponent <RectTransform>().localPosition = new Vector3(GetComponent <RectTransform>().sizeDelta.x / 2 + 6 + (24 * obj.ToArray()[i].GetComponent <Drag>().Aligment), -20 - ((i + SkipsPoint) * 27), 0);
            if (obj.ToArray()[i].GetComponent <Resize>())
            {
                SkipsPoint += obj.ToArray()[i].GetComponent <Resize>().Steps;
            }
        }
        RedistributeReplaceAction();
    }
Пример #11
0
    public void OnDrop(Drag dragObject)
    {
        var pos = dragObject.transform.position;

        dragObject.GetComponent<SpriteRenderer>().sortingOrder = stack.Count;
    }