コード例 #1
0
ファイル: DropZoneCtrl.cs プロジェクト: PWLPavan/Pavan
    void OnMouseUp()
    {
        if (!isDragging)
        {
            return;
        }

        StopDrag();

        // check for bounding box intersections between group and place value subtraction car
        Bounds dragGroupBounds = dragGroup.GetComponent <SpriteRenderer>().bounds;
        int    dragValue       = dragGroup.GetComponent <DragGroup>().value;

        PlaceValueCtrl draggedColumn = null;

        if (dragGroupBounds.Intersects(column.bounds))
        {
            draggedColumn = column;
        }
        else if (convertColumn != null && dragGroupBounds.Intersects(convertColumn.bounds) && (value == 1 || convertColumn.allowDragConvert))
        {
            draggedColumn = convertColumn;
        }

        if (draggedColumn != null)
        {
            bool bFlashAlt = false;
            if (value == 1 && draggedColumn == convertColumn)
            {
                draggedColumn = column;
                bFlashAlt     = true;
            }

            int creaturesToAdd = (dragValue / draggedColumn.value);
            if (draggedColumn.numCreatures + creaturesToAdd <= draggedColumn.creatureMax)
            {
                if (draggedColumn.value == 1)
                {
                    //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn");
                    Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn"));
                }
                else
                {
                    //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn");
                    Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn"));
                }

                // remove creatures from list
                CreatureCtrl[] children = dragGroup.GetComponentsInChildren <CreatureCtrl>();
                for (int i = 0; i < children.Length; ++i)
                {
                    _creatures.Remove(children[i]);
                }

                // place into column
                if (draggedColumn.numCreatures > 9)
                {
                    dragGroup.GetComponent <DragGroup>().SetCreaturesBool("fullTen", true);
                }
                dragGroup.GetComponent <DragGroup>().SetCreaturesBool("inColumn", true);
                dragGroup.GetComponent <DragGroup>().SetCreaturesBool("inCar", false);
                dragGroup.GetComponent <DragGroup>().SetCreaturesTrigger("reset");

                if (creaturesToAdd > 1)
                {
                    column.Explode(dragGroup.GetComponent <DragGroup>());
                    draggedColumn.screen.Poof();
                    SoundManager.instance.PlayOneShot(SoundManager.instance.chickenConvertToOnes);
                }
                else
                {
                    draggedColumn.AddDragGroup(dragGroup.GetComponent <DragGroup>());
                    if (bFlashAlt)
                    {
                        SoundManager.instance.PlayOneShot(SoundManager.instance.chickenSnapBack);
                        convertColumn.ShowIncorrectFeedback();
                    }
                }
            }
            else
            {
                SnapBack();
            }
        }
        else
        {
            //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.sub.snapback");
            //Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.sub.snapback"));
            SnapBack();
        }

        column.ForceDragOverFalse();
        if (convertColumn != null)
        {
            convertColumn.UpdateDragOver(false, 10);
            convertColumn.ForceDragOverFalse();
        }

        // dispose of drag group
        Destroy(dragGroup);
        dragGroup = null;
    }
コード例 #2
0
ファイル: DragGroup.cs プロジェクト: PWLPavan/Pavan
    void OnMouseUp()
    {
        if (!isDragging)
        {
            return;
        }

        StopDrag();

        PlaceValueCtrl ones = container.controller.screen.GetComponent <MyScreen>().onesColumn;
        PlaceValueCtrl tens = container.controller.screen.GetComponent <MyScreen>().tensColumn;

        // update place value column over states
        ones.UpdateDragOver(false, (numOnes == 0 ? numTens * 10 : numOnes));
        tens.UpdateDragOver(false, numTens);

        // check for bounding box intersections between group and place value columns
        bool onesPlacement = this.GetComponent <SpriteRenderer>().bounds.Intersects(ones.bounds) && (ones.numCreatures + numOnes + numTens * 10) <= ones.creatureMax &&
                             (!isMultipleOfTen || ones.allowDragConvert);
        bool tensPlacement = this.GetComponent <SpriteRenderer>().bounds.Intersects(tens.bounds) && (tens.numCreatures + numTens) <= tens.creatureMax && !onesPlacement;

        if ((onesPlacement || tensPlacement) && !isMultipleOfTen && isGreaterThanNine)
        {
            //NOTE: this probably doesn't happen any more, should confirm
            //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.eitherColumn");
            Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.eitherColumn"));
            ones.ForceDragOverFalse(value);
            RemoveFromContainerDistributeToPlaceValue();
        }
        else if (onesPlacement && !tensPlacement && isLessThanTen)
        {
            //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn");
            Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn"));
            // if on the correct place-value column, snap to place-value column (remove from queue)
            // try to place in ones column
            ones.ForceDragOverFalse(value);
            RemoveFromContainerAddToPlaceValue(ones);
        }
        else if (tensPlacement && !onesPlacement && isMultipleOfTen)
        {
            //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn");
            Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn"));
            // try to place in tens column
            tens.ForceDragOverFalse(value);
            RemoveFromContainerAddToPlaceValue(tens);
        }
        else if (tensPlacement && !onesPlacement && !isMultipleOfTen)
        {
            //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn");
            Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.tensColumn"));
            // highlight tens column as incorrect placement (reminder)
            tens.ShowIncorrectFeedback();
            SoundManager.instance.PlayOneShot(SoundManager.instance.chickenSnapBack);
            // try to place in ones column
            ones.ForceDragOverFalse(value);
            RemoveFromContainerAddToPlaceValue(ones, true);
        }
        else if (onesPlacement && isMultipleOfTen && ones.numCreatures < 10 && ones.allowDragConvert)
        {
            //Genie.instance.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn");
            Genie.I.LogEvent(OE_INTERACT.Create(OE_INTERACT.Type.DROP, "gameplay.onesColumn"));
            EnlearnInstance.I.LogActions(EnlearnInstance.Action.AddNestToOnes);
            // place a 10s in 1s column
            ones.ForceDragOverFalse(value);

            CreatureCtrl[] children = this.GetComponentsInChildren <CreatureCtrl>();
            bool           bIsBrown = children[0].color == CreatureCtrl.COLOR_BROWN;

            SoundManager.instance.PlayOneShot(SoundManager.instance.chickenConvertToOnes);
            ones.Add(10, bIsBrown);
            // add explosion effects
            container.controller.screen.Poof();
            Cleanup();
        }
        else
        {
            if (onesPlacement)
            {
                // update place value column over states
                ones.ForceDragOverFalse(value);
                ones.GetComponent <Animator>().SetTrigger("correct");
            }
            if (tensPlacement)
            {
                tens.ForceDragOverFalse(value);
                tens.GetComponent <Animator>().SetTrigger("correct");
            }

            // else, if we're overlapping with both or neither
            // snap back to QueueContainer
            //SnapBack();
            CreatureCtrl[] children = this.GetComponentsInChildren <CreatureCtrl>();
            children[0].Drop();
            Cleanup();
        }
    }