示例#1
0
    public void Combine()
    {
        _combineButton.gameObject.SetActive(false);

        GameSounds.PostEvent2D(GameSound.SFX_BlockCombine);

        // TODO: Calculate what item we need to give here

        ItemButtonWidget itemButton = Instantiate <ItemButtonWidget>(_itemButtonPrefabs.Random(), _breedRect);

        itemButton.transform.ResetLocals();

        for (int i = 0; i < _itemSlots.Count; i++)
        {
            if (!_itemSlots[i].used)
            {
                _itemSlots[i].used = true;
                itemButton.FlyToSlot(_itemSlots[i]);
                break;
            }
        }

        _addedBlockTypes.Clear();

        for (int i = 0; i < _bitSlots.Count; i++)
        {
            _bitSlots[i].used = false;

            foreach (Transform child in _bitSlots[i].transform)
            {
                Destroy(child.gameObject);
            }
        }
    }
示例#2
0
    public void AssignBlock(Block block)
    {
        foreach (var kvp in block.GetSpriteToSlotMap())
        {
            BitSlotWidget slot = kvp.Value;
            slot.used = true;

            Transform spriteParent = new GameObject(gameObject.name + "SpriteRoot").transform;
            spriteParent.localScale = block.transform.localScale;
            spriteParent.SetParent(slot.transform);

            float slotAlpha = _bitSlots.IndexOf(slot) / (float)_bitSlots.Count;
            spriteParent.position = slot.transform.position + -Camera.main.transform.forward * _slotOffsetRange.Lerp(slotAlpha);

            SpriteRenderer sprite = kvp.Key;
            sprite.transform.SetParent(spriteParent);
            sprite.transform.localPosition           = Vector3.zero;
            sprite.GetComponent <Collider>().enabled = false;
        }

        string    soundName  = "SFX_BlockPlacement" + (Mathf.Clamp(_addedBlockTypes.Count, 0, 3) + 1);
        GameSound placeSound = (GameSound)System.Enum.Parse(typeof(GameSound), soundName);

        GameSounds.PostEvent2D(placeSound);

        _addedBlockTypes.Add(block.GetBlockType());

        if (_addedBlockTypes.Count > 1)
        {
            _combineButton.gameObject.SetActive(true);
        }
    }
示例#3
0
    void OnMouseUp()
    {
        if (_activeInputLens != null)
        {
            CameraOrbit.unlockedLens.RemoveRequestsWithContext(this);
            CameraOrbit.inputFreeLens.RemoveRequestsWithContext(this);
            _activeInputLens = null;

            List <BitSlotWidget> bitSlots = GetBreed().GetBitSlots();
            for (int i = 0; i < bitSlots.Count; i++)
            {
                bitSlots[i].SetHighlight(false);
            }

            ResetFadeoutTimer();

            bool allMatched = _spriteToSlotMap.Count == _bitSprites.Length;
            if (allMatched)
            {
                GetBreed().AssignBlock(this);
                Destroy(gameObject);
            }
            else
            {
                GameSounds.PostEvent2D(GameSound.SFX_BlockDeny);

                Vector2 screenMin       = Vector2.zero;
                Vector2 screenMax       = new Vector2(Screen.width, Screen.height);
                Vector2 screenBoundDiff = screenMax - screenMin;
                screenMin += screenBoundDiff * 0.001f;
                screenMax -= screenBoundDiff * 0.001f;
                Vector3 mousePos = ((Vector3)WadeUtils.Clamp((Vector2)Input.mousePosition, screenMin, screenMax)).SetZ(Input.mousePosition.z);

                bool uiOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetBreedRect(), mousePos, Camera.main);
                if (!uiOverlap)
                {
                    Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
                    if (Physics.Raycast(worldPos, Camera.main.transform.forward, out _hitInfo, Mathf.Infinity, _planetLayer, QueryTriggerInteraction.Ignore))
                    {
                        _dropPos = _hitInfo.point + _hitInfo.normal * _dropGroundOffset;
                    }
                }

                if (_changeScaleRoutine != null)
                {
                    StopCoroutine(_changeScaleRoutine);
                }

                _changeScaleRoutine = StartCoroutine(ChangeScaleRoutine(false));
                _dropRoutine        = StartCoroutine(DropRoutine());
            }

            BreedPanel breedPanel = UIManager.GetPanel <BreedPanel>();
            breedPanel.GetLeftRotateRect().gameObject.SetActive(false);
            breedPanel.GetRightRotateRect().gameObject.SetActive(false);
        }
    }
示例#4
0
    void OnMouseDrag()
    {
        if (_activeInputLens != null)
        {
            Vector2 screenMin = Vector2.zero;
            Vector2 screenMax = new Vector2(Screen.width, Screen.height);

            Vector3 mousePos = ((Vector3)WadeUtils.Clamp((Vector2)Input.mousePosition, screenMin, screenMax)).SetZ(Input.mousePosition.z);

            Vector2 screenBoundDiff = screenMax - screenMin;
            screenMin += screenBoundDiff * 0.001f;
            screenMax -= screenBoundDiff * 0.001f;
            mousePos   = ((Vector3)WadeUtils.Clamp((Vector2)mousePos, screenMin, screenMax)).SetZ(mousePos.z);

            Vector3 worldPos          = Camera.main.ScreenToWorldPoint(mousePos);
            Vector3 rotatePivotOffset = _rotatePivot.position - transform.position;
            transform.position = worldPos + Camera.main.transform.forward * _selectedCamOffset - rotatePivotOffset;

            bool uiOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetBreedRect(), mousePos, Camera.main);
            if (uiOverlap != _prevUIOverlap)
            {
                if (_changeScaleRoutine != null)
                {
                    StopCoroutine(_changeScaleRoutine);
                }

                _changeScaleRoutine = StartCoroutine(ChangeScaleRoutine(uiOverlap));

                _groundShadow.GetShadow().gameObject.SetActive(!uiOverlap);
                _prevUIOverlap = uiOverlap;
            }

            if (!uiOverlap)
            {
                if (Physics.Raycast(worldPos, Camera.main.transform.forward - Camera.main.transform.up * 0.17f, out _hitInfo, Mathf.Infinity, _planetLayer, QueryTriggerInteraction.Ignore))
                {
                    _groundShadow.SetPos(_hitInfo.point);
                }
            }

            bool leftOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetLeftRotateRect(), mousePos, Camera.main);
            if (leftOverlap != _prevLeftOverlap)
            {
                if (leftOverlap)
                {
                    GameSounds.PostEvent2D(GameSound.SFX_BlockRotateCounterClockwise);

                    if (_rotateRoutine != null)
                    {
                        StopCoroutine(_rotateRoutine);
                    }

                    _rotateRoutine = StartCoroutine(RotateRoutine(false));
                }

                _prevLeftOverlap = leftOverlap;
            }

            bool rightOverlap = RectTransformUtility.RectangleContainsScreenPoint(GetBreed().GetRightRotateRect(), mousePos, Camera.main);
            if (rightOverlap != _prevRightOverlap)
            {
                if (rightOverlap)
                {
                    GameSounds.PostEvent2D(GameSound.SFX_BlockRotateClockwise);

                    if (_rotateRoutine != null)
                    {
                        StopCoroutine(_rotateRoutine);
                    }

                    _rotateRoutine = StartCoroutine(RotateRoutine(true));
                }

                _prevRightOverlap = rightOverlap;
            }

            _spriteToSlotMap.Clear();
            List <BitSlotWidget> bitSlots = GetBreed().GetBitSlots();
            for (int i = 0; i < bitSlots.Count; i++)
            {
                bitSlots[i].SetHighlight(false);
            }

            for (int i = 0; i < _bitSprites.Length; i++)
            {
                SpriteRenderer bitSprite     = _bitSprites[i];
                Vector3        spriteViewPos = Camera.main.WorldToViewportPoint(bitSprite.transform.position);
                for (int j = 0; j < bitSlots.Count; j++)
                {
                    BitSlotWidget bitSlot = bitSlots[j];
                    if (!bitSlot.used)
                    {
                        Vector3 slotViewPos = Camera.main.WorldToViewportPoint(bitSlot.transform.position);
                        if (Vector2.Distance(spriteViewPos, slotViewPos) < _gridSlotMaxDist)
                        {
                            // Temp-mark used so slots are distinct
                            bitSlot.used = true;
                            bitSlot.SetHighlight(true);
                            _spriteToSlotMap.Add(bitSprite, bitSlot);
                            break;
                        }
                    }
                }
            }

            // Unmark temp-used slots
            foreach (var kvp in _spriteToSlotMap)
            {
                kvp.Value.used = false;
            }

            ResetFadeoutTimer();
        }
    }
    IEnumerator ReadChunkRoutine(DialogueChunk dialogueChunk, PlayerNPCInput npc, GameSound voiceEventOverride)
    {
        bool hasNPC = (npc != null);

        if (_showWidgetRoutine != null)
        {
            StopCoroutine(_showWidgetRoutine);
        }

        _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(true));
        yield return(_showWidgetRoutine);

        if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Choice)
        {
            _optionLayout.SetActive(true);

            for (int i = 0; i < dialogueChunk.responses.Length; i++)
            {
                _optionButtons[i].gameObject.SetActive(true);
                GetOptionTexts()[i].color = GetOptionTexts()[i].color.SetA(0f);
                GetOptionTexts()[i].text  = dialogueChunk.responses[i].response;
            }
        }

        string dialogueText = LocUtils.Translate(dialogueChunk.dialogueTerm);

        foreach (KeyValuePair <string, string> kvp in _locDynamicText)
        {
            if (dialogueText.Contains(kvp.Key))
            {
                dialogueText = dialogueText.Replace(kvp.Key, LocUtils.Translate(kvp.Value));
            }
        }

        if (_textSpeed > Mathf.Epsilon)
        {
            _lineText.text = dialogueText;

            if (_resetMouthRoutine != null)
            {
                StopCoroutine(_resetMouthRoutine);
                _resetMouthRoutine = null;
            }

            GameSound dialogueSound = voiceEventOverride;
            if (dialogueSound == GameSound.NONE)
            {
                string soundName = "SFX_UI_Dialogue_" + dialogueChunk.character.ToString();
                if (Enum.IsDefined(typeof(GameSound), soundName))
                {
                    dialogueSound = (GameSound)Enum.Parse(typeof(GameSound), soundName);
                }
            }

            GameSounds.PostEvent2D(dialogueSound);

            float lineStartTime = Time.time;
            for (int i = 0; i < dialogueText.Length; i++)
            {
                // Skip rich text
                if (dialogueText[i] == '<')
                {
                    while (dialogueText[i] != '>')
                    {
                        i++;
                    }

                    i++;
                }

                _lineText.ScaleCharacter(i);

                float timer = 0;
                while (timer < _textSpeed)
                {
                    if (hasNPC && npc.GetPlayer().HasMouthBlend())
                    {
                        float timeSinceLineState = Time.time - lineStartTime;
                        float mouthBlendWeight   = (Mathf.Sin(timeSinceLineState * _mouthFlapSpeed * Mathf.PI) * 0.5f + 0.5f) * 100f;

                        if (npc.GetPlayer().GetSkinnedMeshRenderer())
                        {
                            npc.GetPlayer().GetSkinnedMeshRenderer().SetBlendShapeWeight(npc.GetPlayer().GetMouthBlendIndex(), mouthBlendWeight);
                        }
                    }

                    if (!GameManager.GSM.IsStateActive(GameStateType.PauseMenu) && InputManager.ActiveDevice.AnyButtonWasPressed)
                    {
                        _lineText.ForceAllScaled();
                        goto lineFinished;
                    }

                    timer += Time.deltaTime;
                    yield return(null);
                }
            }

lineFinished:

            if (hasNPC && npc.GetPlayer().HasMouthBlend())
            {
                _resetMouthRoutine = StartCoroutine(ResetMouthRoutine(npc));
            }

            if (dialogueSound != GameSound.NONE)
            {
                GameSounds.PostEvent2D(dialogueSound, EventAction.StopSound);
            }
        }
        else
        {
            _lineText.text = dialogueText;
        }

        if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Default)
        {
            _continuePrompt.SetActive(true);

            yield return(null);

            while (!InputManager.ActiveDevice.AnyButtonWasPressed)
            {
                yield return(null);
            }

            if (_continuePrompt != null)
            {
                _continuePrompt.SetActive(false);
            }
        }
        else
        {
            yield return(StartCoroutine(DialogueOptionsRoutine(dialogueChunk)));
        }

        _lineText.text = string.Empty;

        if (_showWidgetRoutine != null)
        {
            StopCoroutine(_showWidgetRoutine);
        }

        _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(false));
        yield return(_showWidgetRoutine);

        _readChunkRoutine = null;
    }