Exemplo n.º 1
0
        private static bool IsTileAccessible(Data.Vector2 position)
        {
            int          accessibleLayerMask = LayerMask.GetMask("Ground");
            RaycastHit2D hit = Physics2D.Raycast(position.ToUnityVector(), UnityEngine.Vector2.zero);

            return((hit.collider != null) && (accessibleLayerMask == (accessibleLayerMask | (1 << hit.collider.gameObject.layer))));
        }
Exemplo n.º 2
0
        public IEnumerable <CharacterModel> GetCharactersOnLine(Data.Vector2 origin, Data.Vector2 end)
        {
            //Debug.LogFormat("[UnityCharacterFinder] GetCharactersOnLine (Origin: {0}, End: {1})", origin, end);
            //Debug.DrawLine(origin.ToUnityVector(), end.ToUnityVector(), Color.red, 3);

            return(Physics2D.LinecastAll(origin.ToUnityVector(), end.ToUnityVector(), layerMask)
                   .Select(target => target.collider.GetComponentInParent <CharacterView>()?.Model).Where(target => (target != null)));
        }
Exemplo n.º 3
0
        public CharacterModel GetCharacter(Data.Vector2 position)
        {
            //Debug.LogFormat("[UnityCharacterFinder] GetCharacter (Position: {0})", position);
            //Debug.DrawLine(position.ToUnityVector() - new UnityEngine.Vector2(0.5f, 0.5f),
            //	position.ToUnityVector() + new UnityEngine.Vector2(0.5f, 0.5f), Color.red, 3);

            RaycastHit2D hit = Physics2D.Raycast(position.ToUnityVector(), UnityEngine.Vector2.zero, 0, layerMask);

            return(hit.collider?.GetComponentInParent <CharacterView>()?.Model);
        }
Exemplo n.º 4
0
 private void OnAbilityCast(CharacterModel model, IAbility ability, Data.Vector2 target)
 {
     if (ability is ProjectileAbility)
     {
         ProjectileView projectile = GameObjectExtensions.Instantiate(projectilePrefab, transform.parent).GetComponent <ProjectileView>();
         projectile.Animator.runtimeAnimatorController
             = UnityDataProvider.LoadAsset <RuntimeAnimatorController>("Abilities/Ability_" + ability.Name + "_Projectile");
         projectile.transform.localPosition = model.Position.ToUnityVector();
         projectile.Target = target.ToUnityVector();
     }
 }
Exemplo n.º 5
0
        public IEnumerable <CharacterModel> GetCharactersAround(Data.Vector2 center, int width, int height, int rotation)
        {
            UnityEngine.Vector2 bottomLeft = new UnityEngine.Vector2(-width / 2f, -height / 2f);
            UnityEngine.Vector2 topRight   = new UnityEngine.Vector2(width / 2f, height / 2f);
            bottomLeft  = Quaternion.AngleAxis(rotation, UnityEngine.Vector3.forward) * bottomLeft;
            topRight    = Quaternion.AngleAxis(rotation, UnityEngine.Vector3.forward) * topRight;
            bottomLeft += center.ToUnityVector();
            topRight   += center.ToUnityVector();

            //Debug.LogFormat("[UnityCharacterFinder] GetCharactersAround (BottomLeft: {0}, TopRight: {1})",
            //	bottomLeft.ToModelVector(), topRight.ToModelVector());
            //Debug.DrawLine(bottomLeft, topRight, Color.red, 3);

            return(Physics2D.OverlapAreaAll(bottomLeft, topRight, layerMask)
                   .Select(target => target.GetComponentInParent <CharacterView>()?.Model).Where(target => (target != null)));
        }
 public static UnityEngine.Vector2 ToUnityVector(this Data.Vector2 vector)
 {
     return(new UnityEngine.Vector2(vector.X, vector.Y));
 }