Beispiel #1
0
    // Do an animation where they break one by one
    //private IEnumerator BreakCoroutine()
    //{
    //    while (keysToBreak.Count > 0 || fragmentsToBreak.Count > 0)
    //    {
    //        bool itemBroken = false;
    //        if (keysToBreak.Count > 0 && Random.value < 0.5)
    //        {
    //            InputKey inputKey = keysToBreak[Random.Range(0, keysToBreak.Count)];
    //            keysToBreak.Remove(inputKey);
    //            BreakKey(inputKey);
    //            itemBroken = true;
    //        }
    //        else
    //        {
    //            InputFragment inputFragment = fragmentsToBreak[Random.Range(0, fragmentsToBreak.Count)];
    //            // Only break a fragment once any keys in it have been broken
    //            bool fragmentContainsKeys = false;
    //            foreach (InputSlot inputSlot in inputFragment.GetComponentsInChildren<InputSlot>())
    //            {
    //                if (inputSlot.GetInputKey() != null)
    //                {
    //                    fragmentContainsKeys = true;
    //                    break;
    //                }
    //            }
    //            if (!fragmentContainsKeys)
    //            {
    //                fragmentsToBreak.Remove(inputFragment);
    //                BreakFragment(inputFragment);
    //                itemBroken = true;
    //            }
    //        }
    //        if (itemBroken) { yield return new WaitForSeconds(0.2f); }
    //    }
    //}


    private void BreakKey(InputKey inputKey)
    {
        if (dragging && draggedKey == inputKey)
        {
            StopDragging();
        }

        Vector3 positionVector = inputKey.transform.position - keyParent.transform.position;

        positionVector    = CanvasScale.Instance.WorldToCanvas(positionVector);
        positionVector.x *= 2;
        positionVector.y *= 4;
        inputKey.Break(
            positionVector + (Vector3)Random.insideUnitCircle * 500f,
            Random.Range(-360, 360));
        InputSlot inputSlot = inputKey.GetInputSlot();

        if (inputSlot != null)
        {
            inputSlot.SetInputKey(null);
            InputMapper.Instance.RemoveMapping(inputSlot.GetAction());
        }
        inputKey.SetInputSlot(null);
        inputKeys.Remove(inputKey);
    }
Beispiel #2
0
    private void StartDragging(InputKey inputKey)
    {
        dragging   = true;
        draggedKey = inputKey;
        dragOffset = draggedKey.transform.position - Input.mousePosition;
        dropShadow.transform.SetAsLastSibling();
        inputKey.transform.SetAsLastSibling();
        inputKey.SetVelocity(Vector3.zero);

        // Check if it's being removed from a slot
        InputSlot oldInputSlot = draggedKey.GetInputSlot();

        if (oldInputSlot != null)
        {
            oldInputSlot.SetInputKey(null);
            draggedKey.SetInputSlot(null);
            InputMapper.Instance.RemoveMapping(oldInputSlot.GetAction());
        }

        dropShadow.enabled            = true;
        dropShadow.transform.position = draggedKey.transform.position + CanvasScale.Instance.CanvasToWorld(dropShadowOffset);

        AudioManager.Instance.Play("key_pickup");
    }