示例#1
0
    public void OnDrop(PointerEventData data)
    {
        if (receivingImage == null)
        {
            return;
        }

        //get locate
        var container = this.gameObject.transform.parent;

        y = getOrder(container); // 0 - 4

        var singleInstruction = container.parent;

        x = getOrder(singleInstruction); //0 - inf


        //recongize which type
        Sprite dropSprite = GetDropSprite(data);

        if (dropSprite != null)
        {
            DragRelease.Play();
            //record type
            currentType = GetTypeFromStr(dropSprite.name);

            bool needEnableDelete = InstructionController.instructions[x, y] == SensorAndAction.None;

            if (InstructionController.AddOneIns(x, y, currentType))
            {
                isDrop     = true;
                isPositive = true;

                //active next one & next line
                if (y < InstructionController.GetLength() - 1)
                {
                    container.parent.GetChild(y + 1).gameObject.SetActive(true);
                }
                if (x < InstructionController.GetHeight() - 1)
                {
                    singleInstruction.parent.GetChild(x + 1).GetChild(0).gameObject.SetActive(true);
                }

                //change png
                receivingImage.color =
                    new Color(receivingImage.color.r, receivingImage.color.g, receivingImage.color.b, 1f);
                containerImage.color =
                    new Color(containerImage.color.r, containerImage.color.g, containerImage.color.b, 0f);
                //receivingImage.overrideSprite = dropSprite;
                receivingImage.sprite = dropSprite;

                if (needEnableDelete)
                {
                    gameObject.GetComponent <DragToDelete>().enabled = true;
                    if (y > 0)
                    {
                        gameObject.transform.parent.parent.transform.GetChild(y - 1).GetChild(0).gameObject
                        .GetComponent <DragToDelete>().enabled = false;
                    }
                }
            }
        }
    }