/// <summary>
        ///
        /// </summary>
        public void GenerateTiles()
        {
            var tileAnimators = GetComponentsInChildren <SpriteAnimator>();

            foreach (var item in tileAnimators)
            {
                UnityEditor.EditorApplication.delayCall += () =>
                {
                    DestroyImmediate(item.gameObject);
                };
            }

            for (var i = 0; i < _width; i++)
            {
                for (var j = 0; j < _height; j++)
                {
                    var obj      = new GameObject("TrapZoneTile");
                    var animator = obj.AddComponent <SpriteAnimator>();
                    animator.animations = new List <SpriteAnimation>();
                    animator.animations.Add(_buildUpAnimation);
                    var renderer = obj.GetComponent <SpriteRenderer>();
                    renderer.sortingLayerID = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.AboveFloor);
                    obj.GetComponent <SpriteRenderer>().sprite = _tileSprite;
                    obj.transform.localPosition = new Vector2(transform.localPosition.x + (_width > 1 ? ((_tileSize * i) - (_tileSize / 2 * _width) + _tileSize / 2) : 0),
                                                              transform.localPosition.y + (_height > 1 ? ((_tileSize * j) - (_tileSize / 2 * _height) + _tileSize / 2) : 0));
                    obj.transform.SetParent(this.gameObject.transform);
                    obj.layer = LayerMask.NameToLayer("Floor");
                }
            }
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        protected virtual void ApplyOrder()
        {
            var lightLayerNumber = ComputeLightLayerNumber();

            if (_renderer != null)
            {
                _renderer.sortingLayerID = SortingLayerHelper.GetLightSortingLayerValue(lightLayerNumber);
                _renderer.sortingOrder   = _additive;
            }

            /*if (_shadowCaster != null || _light != null)
             * {
             *  var layers = new int[lightLayerNumber - GameConstants.MinLightLayer + _floorSortingLayerValues.Length];
             *
             *  for(var i = 0; i < _floorSortingLayerValues.Length; ++i)
             *  {
             *      layers[i] = SortingLayerHelper.GetSortingLayerValue(_floorSortingLayerValues[i]);
             *  }
             *
             *  var x = _floorSortingLayerValues.Length;
             *  for (var i = lightLayerNumber - 1; i >= GameConstants.MinLightLayer; --i)
             *  {
             *      layers[x++] = SortingLayerHelper.GetLightSortingLayerValue(i);
             *  }
             *
             *  if (_shadowCaster != null)
             *  {
             *      _shadowCastersSortingLayersField.SetValue(_shadowCaster, layers);
             *  }
             *  if(_light != null)
             *  {
             *      _lightSortingLayersField.SetValue(_light, layers);
             *  }
             * }*/
        }
        /// <summary>
        ///
        /// </summary>
        private IEnumerator StartAnimationInternal(System.Action callback)
        {
            // Set variables needed

            var canvas = GameObject.FindObjectOfType <Canvas>();

            var x = canvas.transform.position.x;
            var y = canvas.transform.position.y;

            var launchKey = new GameObject("LaunchKey");

            launchKey.layer = LayerMask.NameToLayer(UILayerName);
            launchKey.AddComponent <SpriteAnimator>();
            var renderer = launchKey.GetComponent <SpriteRenderer>();

            renderer.sortingLayerID      = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.UIOverlay);
            renderer.sprite              = _keyLetterSprite;
            launchKey.transform.position = new Vector2(launchKey.transform.position.x + 512, launchKey.transform.position.y);


            _animationSequence = DOTween.Sequence();
            _animationSequence.Append(launchKey.transform.DOBlendableLocalMoveBy(new Vector3(x - 570, y), 1f));

            yield return(_animationSequence.WaitForCompletion());

            var keyLetterAnim = launchKey.GetComponent <SpriteAnimator>();

            keyLetterAnim.Play(_letterToKeyAnimation, true);

            keyLetterAnim.onFinish.AddListener(() => StartCoroutine(FirstKeyPlacement(launchKey, callback)));

            yield break;
        }
Exemple #4
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private IEnumerator Leave()
        {
            var position       = character.transform.position;
            var targetPosition = character.spawner.transform.position + character.spawner.spawnOffset
                                 + Vector3.up * GameConstants.TileSize;

            var orientation = new Vector2();

            if (targetPosition.x > position.x)
            {
                orientation.x = 1.0f;
            }
            else
            {
                orientation.x = -1.0f;
            }

            character.SetOrientations(orientation, orientation);

            foreach (var collider in character.GetComponents <Collider2D>())
            {
                collider.enabled = false;
            }

            yield return(new WaitForSeconds(2.0f));

            character.DropAllWeapons(false);

            var spriteAnimator = character.GetComponent <SpriteAnimator>();

            spriteAnimator.Stop();

            var jumpAnimation = character.skinDescriptor.jumpAnimation;

            if (jumpAnimation != null)
            {
                spriteAnimator.Play(jumpAnimation, true);
            }

            Tween tween = character.body.DOJump(targetPosition, 5.0f, 1, 0.4f, true);

            yield return(tween.WaitForCompletion());

            GameObject.Destroy(character.GetComponent <TileObjectRenderer>());

            var spriteRenderer = character.GetComponent <SpriteRenderer>();

            spriteRenderer.sortingLayerID  = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.KeySlotBottom);
            spriteRenderer.sortingOrder    = 1;
            spriteRenderer.maskInteraction = SpriteMaskInteraction.VisibleOutsideMask;

            targetPosition = character.spawner.transform.position + Vector3.down * GameConstants.TileSize;
            character.floorShadowRenderer.enabled = false;

            yield return(new WaitForSeconds(0.4f));

            tween = character.body.DOMove(targetPosition, 0.2f);
            yield return(tween.WaitForCompletion());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="text"></param>
        /// <param name="position"></param>
        /// <param name="spacing"></param>
        /// <returns></returns>
        public static DynamicText GenerateDynamicText(string text, Vector2 position, Color color, float spacing = 48)
        {
            GameObject[] objList = new GameObject[text.Length];
            var          midPos  = text.Length / 2;

            var uiLayer = LayerMask.NameToLayer("HUD");

            var containerObj = new GameObject("DynamicTextContainer");

            containerObj.layer = uiLayer;
            var dynamicText = containerObj.AddComponent <DynamicText>();

            containerObj.transform.position = GameObject.FindObjectOfType <Canvas>().transform.position;

            for (int i = 0; i < text.Length; i++)
            {
                var multiplier = i - midPos;
                var charObj    = new GameObject(text[i].ToString());
                charObj.layer              = uiLayer;
                charObj.transform.parent   = containerObj.transform;
                charObj.transform.position = position + new Vector2(position.x + (spacing * multiplier), position.y);
                charObj.AddComponent(typeof(SpriteRenderer));
                var renderer = charObj.GetComponent <SpriteRenderer>();
                renderer.sortingLayerID = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.UIOverlay);
                renderer.material       = Bootstrap.instance.data.colorSwapMaterial;
                renderer.material.SetColor("_DesiredColor", color);
                Sprite sprite;

                if (Bootstrap.instance.data.alphabetMap.TryGetValue(char.ToLower(text[i]), out sprite))
                {
                    renderer.sprite = sprite;
                }

                objList[i] = charObj;
            }

            foreach (var item in objList)
            {
                containerObj.GetComponent <DynamicText>().letters.Add(item);
            }

            return(dynamicText);
        }
Exemple #6
0
        /// <summary>
        ///
        /// </summary>
        private void Update()
        {
            if (_updateCount % frequency == 0)
            {
                var index = _updateCount / frequency;

                if (index >= explosions.Count)
                {
                    Destroy(gameObject);
                    return;
                }

                foreach (var pos in explosions[index])
                {
                    GameplayStatics.SpawnFireAndForgetAnimation(explosionAnimation, pos, Quaternion.identity)
                    .GetComponent <SpriteRenderer>().sortingLayerID = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.Default);
                }
            }

            ++_updateCount;
        }
Exemple #7
0
        /// <summary>
        ///
        /// </summary>
        private void CreateHollow()
        {
            var hollow = new GameObject().AddComponent <SpriteRenderer>();

            hollow.transform.position = character.transform.position;
            hollow.transform.rotation = character.transform.rotation;

            hollow.sortingLayerID = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.AboveSpawner); //_characterSpriteRenderer.sortingLayerID;
            hollow.sortingOrder   = 20;
            hollow.flipX          = _characterSpriteRenderer.flipX;
            hollow.color          = _characterSpriteRenderer.color.ChangeOpacity(0.5f);
            hollow.sprite         = _characterSpriteRenderer.sprite;
            var tween = hollow.DOFade(0.0f, 0.3f);

            tween.onComplete += () =>
            {
                Destroy(hollow.gameObject);
                _tweens.Remove(tween);
            };
            _tweens.Add(tween);
        }
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        private IEnumerator TriggerExplosions()
        {
            this.EmitSound(ShipDamageSoundKey);
            CameraShakeManager.instance.Shake(_lastShipHitGameCameraShake);

            yield return(new WaitForSeconds(2f));

            var halfWidth          = GameConstants.SceneWidth / 2.0f;
            var halfHeight         = GameConstants.SceneHeight / 2.0f;
            var explosionSoundSkip = 0;

            do
            {
                var pos   = new Vector2(Random.Range(halfWidth * -1.0f, halfWidth), Random.Range(halfHeight * -1.0f, halfHeight));
                var index = Random.Range(0, _endGameExplosionAnimations.Count);

                GameplayStatics.SpawnFireAndForgetAnimation(_endGameExplosionAnimations[index], pos, Quaternion.identity)
                .GetComponent <SpriteRenderer>().sortingLayerID = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.Default);

                explosionSoundSkip++;

                if (explosionSoundSkip > 5)
                {
                    this.EmitSound(ShipExplosionSoundKey, false);
                    explosionSoundSkip = 0;
                }

                CameraShakeManager.instance.Shake(_endGameCameraShake);

                if (_endGameExplosionRandomIntervalMax > _endGameExplosionIntervalMin)
                {
                    _endGameExplosionRandomIntervalMin -= _endGameExplosionDecrementValue;
                    _endGameExplosionRandomIntervalMax -= _endGameExplosionDecrementValue;
                }

                yield return(new WaitForSeconds(Random.Range(_endGameExplosionRandomIntervalMin, _endGameExplosionRandomIntervalMax)));
            } while (true);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="key"></param>
        private IEnumerator FirstKeyPlacement(GameObject key, System.Action callback)
        {
            // Set Variables

            var keyPos = key.transform.position;

            var canvas = GameObject.FindObjectOfType <Canvas>();

            var x = canvas.transform.position.x;
            var y = canvas.transform.position.y;

            var fakeLaunchKey = new GameObject();

            fakeLaunchKey.layer = LayerMask.NameToLayer(UILayerName);
            fakeLaunchKey.transform.position = keyPos;
            var spriteAnimator = fakeLaunchKey.AddComponent <SpriteAnimator>();
            var renderer       = fakeLaunchKey.GetComponent <SpriteRenderer>();

            renderer.sortingLayerID = renderer.sortingLayerID = SortingLayerHelper.GetSortingLayerValue(StaticSortingLayer.UIOverlay);

            Destroy(key);

            // Start Sequence

            spriteAnimator.Play(_keySpinAnimation);

            Sequence sequence = DOTween.Sequence();

            sequence.Append(fakeLaunchKey.transform.DOJump(new Vector3(x, y, 0), 20.0f, 1, 0.7f));
            sequence.AppendCallback(() => spriteAnimator.StopAtFrame(9));
            sequence.AppendCallback(() => Destroy(fakeLaunchKey));

            yield return(sequence.WaitForCompletion());

            callback?.Invoke();
        }