示例#1
0
        private static void CreateSprites(SpriterEntity entity, ChildData cd, Spriter spriter, GameObject parent)
        {
            int maxObjects = GetDrawablesCount(entity);

            cd.Sprites               = new GameObject[maxObjects];
            cd.SpritePivots          = new GameObject[maxObjects];
            cd.SpriteTransforms      = new Transform[maxObjects];
            cd.SpritePivotTransforms = new Transform[maxObjects];

            for (int i = 0; i < maxObjects; ++i)
            {
                GameObject pivot = new GameObject("Pivot " + i);
                GameObject child = new GameObject("Sprite " + i);

                pivot.SetParent(parent);
                child.SetParent(pivot);

                cd.SpritePivots[i]          = pivot;
                cd.Sprites[i]               = child;
                cd.SpritePivotTransforms[i] = pivot.transform;
                cd.SpriteTransforms[i]      = child.transform;

                child.transform.localPosition = Vector3.zero;

                child.AddComponent <SpriteRenderer>();
            }
        }
示例#2
0
        private static void CreateCollisionRectangles(SpriterEntity entity, ChildData cd, Spriter spriter, GameObject parent)
        {
            if (entity.ObjectInfos == null)
            {
                return;
            }
            var boxes = entity.ObjectInfos.Where(o => o.ObjectType == SpriterObjectType.Box).ToList();

            if (boxes.Count == 0)
            {
                return;
            }

            GameObject boxRoot = new GameObject("Boxes");

            boxRoot.SetParent(parent);

            cd.BoxPivots = new GameObject[boxes.Count];
            cd.Boxes     = new GameObject[boxes.Count];

            for (int i = 0; i < boxes.Count; ++i)
            {
                GameObject pivot = new GameObject("Pivot " + i);
                GameObject child = new GameObject("Box " + i);

                pivot.SetParent(boxRoot);
                child.SetParent(pivot);

                cd.BoxPivots[i] = pivot;
                cd.Boxes[i]     = child;

                child.AddComponent <BoxCollider2D>();
            }
        }
示例#3
0
        public UnityAnimator(SpriterEntity entity, ChildData childData, AudioSource audioSource) : base(entity)
        {
            this.childData   = childData;
            this.audioSource = audioSource;

            renderers = new SpriteRenderer[childData.Sprites.Length];
            for (int i = 0; i < childData.Sprites.Length; ++i)
            {
                renderers[i] = childData.Sprites[i].GetComponent <SpriteRenderer>();
            }
        }
示例#4
0
 private void OnEnable()
 {
     // CHECK TO SEE IF THE ENEMY IS COMPOSED OF A SINGLE SPRITE OR WAS IMPORTED IN FROM SPRITER PRO
     if (gameObject.GetComponent <SpriteRenderer>() != null)
     {
         _sprite = GetComponent <SpriteRenderer>();
     }
     else if (gameObject.GetComponent <SpriterDotNetUnity.SpriterDotNetBehaviour>() != null)
     {
         _entity = GetComponent <SpriterDotNetUnity.SpriterDotNetBehaviour>().ChildData;
     }
 }
示例#5
0
        private static void CreatePoints(SpriterEntity entity, ChildData cd, Spriter spriter, GameObject parent)
        {
            GameObject pointRoot = new GameObject("Points");

            pointRoot.SetParent(parent);

            int count = GetPointsCount(entity);

            cd.Points = new GameObject[count];

            for (int i = 0; i < count; ++i)
            {
                GameObject point = new GameObject("Point " + i);
                point.SetParent(pointRoot);
                cd.Points[i] = point;
            }
        }
示例#6
0
        private static void CreateSpriter(string path)
        {
            string  data       = File.ReadAllText(path);
            Spriter spriter    = SpriterReader.Default.Read(data);
            string  rootFolder = Path.GetDirectoryName(path);

            string      name        = Path.GetFileNameWithoutExtension(path);
            SpriterData spriterData = CreateSpriterData(spriter, rootFolder, name);

            foreach (SpriterEntity entity in spriter.Entities)
            {
                GameObject go       = new GameObject(entity.Name);
                GameObject sprites  = new GameObject(ObjectNameSprites);
                GameObject metadata = new GameObject(ObjectNameMetadata);

                SpriterDotNetBehaviour behaviour = go.AddComponent <SpriterDotNetBehaviour>();
                behaviour.UseNativeTags = UseNativeTags;
                if (HasSound(entity))
                {
                    go.AddComponent <AudioSource>();
                }

                sprites.SetParent(go);
                metadata.SetParent(go);

                ChildData cd = new ChildData();
                CreateSprites(entity, cd, spriter, sprites);
                CreateCollisionRectangles(entity, cd, spriter, metadata);
                CreatePoints(entity, cd, spriter, metadata);

                behaviour.EntityIndex = entity.Id;
                behaviour.enabled     = true;
                behaviour.SpriterData = spriterData;
                behaviour.ChildData   = cd;

                GameObject prefab = CreatePrefab(go, rootFolder);

                EntityImported(entity, prefab);
            }

            if (UseNativeTags)
            {
                CreateTags(spriter);
            }
        }
示例#7
0
        internal static void CreatePoints(SpriterEntity entity, ChildData cd, GameObject parent)
        {
            GameObject pointRoot = new GameObject("Points");

            pointRoot.SetParent(parent);

            int count = GetPointsCount(entity);

            cd.Points          = new GameObject[count];
            cd.PointTransforms = new Transform[count];

            for (int i = 0; i < count; ++i)
            {
                GameObject point = new GameObject("Point " + i);
                point.SetParent(pointRoot);
                cd.Points[i]          = point;
                cd.PointTransforms[i] = point.transform;
            }
        }
示例#8
0
        public static SpriterDotNetBehaviour CreateSpriter(string path, string entityName, Transform parent = null)
        {
            GameObject             go        = new GameObject(entityName);
            SpriterDotNetBehaviour behaviour = go.AddComponent <SpriterDotNetBehaviour>();
            SpriterEntity          entity    = FetchOrCacheSpriterEntityDataFromFile(path, entityName, behaviour);

            if (entity == null)
            {
                UnityEngine.Object.Destroy(go);
                return(null);
            }

            GameObject sprites  = new GameObject(ObjectNameSprites);
            GameObject metadata = new GameObject(ObjectNameMetadata);

            behaviour.UseNativeTags = false;
            if (SpriterImporterUtil.HasSound(entity))
            {
                go.AddComponent <AudioSource>();
            }

            sprites.SetParent(go);
            metadata.SetParent(go);

            ChildData cd = new ChildData();

            SpriterImporterUtil.CreateSprites(entity, cd, sprites);
            SpriterImporterUtil.CreateCollisionRectangles(entity, cd, metadata);
            SpriterImporterUtil.CreatePoints(entity, cd, metadata);
            cd.Verify();

            behaviour.EntityIndex = entity.Id;
            behaviour.enabled     = true;
            behaviour.ChildData   = cd;

            go.transform.parent = parent;
            return(behaviour);
        }
示例#9
0
    private void Update()
    {
        if (_entity == null)
        {
            _entity = GetComponent <SpriterDotNetUnity.SpriterDotNetBehaviour>().ChildData;
        }

        // if the player dies, stop any velocity the player had, place them at the last checkpoint, and reset their health to 100%.
        if (_health <= 0)
        {
            if (!_deathAnimationPlayed)
            {
                if (_inputManager == null)
                {
                    _inputManager = InputManager.Instance.GetComponent <InputManager>();
                }
                _inputManager.StopInput();

                GetComponent <BoxCollider2D>().enabled     = false;
                GetComponent <PolygonCollider2D>().enabled = false;

                _playerBody.SetActive(false);

                if (!_collisionState.OnSolidGround)
                {
                    _SOEffectHandler.PlayEffect(EffectEnums.Player_Death00, transform.position);
                }
                else
                {
                    _SOEffectHandler.PlayEffect(EffectEnums.Player_Death01, transform.position);
                }
                _deathAnimationPlayed = true;
                DeployBodyParts();
                _timer = Time.time;
                if (OnPlayerDeath != null)
                {
                    OnPlayerDeath();
                }                                                   // This tells the save file to add to the number of deaths.
            }

            GetComponent <Rigidbody2D>().velocity     = new Vector3(0.0f, 0.0f, 0.0f);
            GetComponent <Rigidbody2D>().gravityScale = 0.0f;
            GetComponent <PlayerMovementManager>().ClearQueue();

            StartCoroutine(ReloadLevelDelay());

            //if (Time.time - _timer > 1.0f) {

            //    transform.position = _GM.SOSaveHandler.CheckpointPosition;
            //    GetComponent<PlayerMovementManager>().ClearQueue();

            //    if (Camera.main.WorldToViewportPoint(_GM.SOSaveHandler.CheckpointPosition).x > 0.1f &&
            //        Camera.main.WorldToViewportPoint(_GM.SOSaveHandler.CheckpointPosition).x < 0.9f) {

            //        // Delay the player from any input for 1.5 seconds to ensure they do not immediate fly to their death
            //        // Call the respawn effect and restore all the default values for the player.
            //        _inputManager.PauseInput(1.25f);
            //        GetComponent<Rigidbody2D>().gravityScale = 40.0f;
            //        _SOEffectHandler.PlayEffect(EffectEnums.PlayerRespawn, _GM.SOSaveHandler.CheckpointPosition);
            //        _SOWeaponManager.Reload();
            //        _health = _maxHealth;
            //        _playerBody.SetActive(true);
            //        UpdateHealth(_health);
            //        _deathAnimationPlayed = false;
            //    }
            //}
        }

        if (_killPlayerCalled)
        {
            KillPlayer();
        }

        if (_effect != null)
        {
            // If an effect is playing and then the player dies, stop the effect at once.
            if (_health < 0)
            {
                _duration = 0.0f;
                _SOEffectHandler.StopEffect(_effect);

                foreach (GameObject sprite in _entity.Sprites)
                {
                    //Color spriteColor = sprite.GetComponent<SpriteRenderer>().color;
                    sprite.GetComponent <SpriteRenderer>().color = Color.white;
                }
            }
            // if there is any type of effect associated with the player, ensure it is following them with a slight offset.
            _effect.transform.position = transform.position + new Vector3(0.0f, 25.0f, 0.0f);
        }

        // If an enemy has damaged the player and their is an effect to be played,
        // keep calling the damage and effect to do damage over time.
        if (_duration != 0.0f)
        {
            if (Time.time - _timer < _duration)
            {
                if (_damageType == DamageEnum.Acid && _canTakeDamage)
                {
                    _scrnShkRequest.ShakeRequest();
                    StartCoroutine(RecoveryDelay());
                }

                ReturnToNormalColor();
            }
            else
            {
                _duration = 0.0f;
                _SOEffectHandler.StopEffect(_effect);
            }
        }
    }