Пример #1
0
    public virtual void OnGiveDamage(DamageTaker taker, float damage, Vector2 dealPoint)
    {
        base.OnGiveDamage(taker, damage, dealPoint);
        UnitComponent target = taker.GetComponent <UnitComponent>();

        if (target)
        {
            target.AddVelocity("hitted", (target.GetPosition() - (Vector2)tr.position).normalized * 3f, 0.5f, true);
        }
        OnDie();
    }
Пример #2
0
    public void OnEnemyDie(DamageDealer dealer, DamageTaker taker)
    {
        // TODO: Play death before return
        EnemyTracker tracker = taker.GetComponent <EnemyTracker>();

        this.roomDifficulty -= tracker.difficulty;
        this.enemyCount--;
        GenericItem death = this.silhouettes.Pop(tracker.transform.position);

        death.instance.GetComponent <SpriteRenderer>().sprite = tracker.GetComponent <SpriteRenderer>().sprite;
        this.level.StartCoroutine(DoDeath(death));
        tracker.Return();
    }
    public void UpdateSprite()
    {
        if (parentDir != DIRECTION.NULL)
        {
            spriteRoot = parentCharacter.spriteRoot;
        }
        PrefabUtility.DisconnectPrefabInstance(gameObject);
        string sheet = AssetDatabase.GetAssetPath(spriteRoot);

        Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath(sheet).OfType <Sprite>().ToArray();
        tr        = transform;
        sr        = GetComponent <SpriteRenderer>();
        sr.sprite = sprites[0];
        west      = false;
        east      = false;
        south     = false;
        north     = false;
        int numOfConnections = childrenCharacters.Count;

        if (parentDir != DIRECTION.NULL)
        {
            numOfConnections += 1;
        }
        for (int i = 0; i < childrenCharacters.Count; i++)
        {
            switch (childrenCharacters[i].parentDir)
            {
            case DIRECTION.EAST:
                west = true;
                break;

            case DIRECTION.WEST:
                east = true;
                break;

            case DIRECTION.SOUTH:
                north = true;
                break;

            case DIRECTION.NORTH:
                south = true;
                break;
            }
        }
        if (parentDir != DIRECTION.NULL)
        {
            switch (parentDir)
            {
            case DIRECTION.EAST:
                east = true;
                break;

            case DIRECTION.WEST:
                west = true;
                break;

            case DIRECTION.SOUTH:
                south = true;
                break;

            case DIRECTION.NORTH:
                north = true;
                break;
            }
        }



        if (numOfConnections == 1)
        {
            if (north)
            {
                switch (instanceType)
                {
                case INSTYPE.Tube:
                    sr.sprite = sprites[0];
                    break;

                case INSTYPE.Tower:
                    sr.sprite = sprites[8];
                    break;
                }
            }
            else if (east)
            {
                switch (instanceType)
                {
                case INSTYPE.Tube:
                    sr.sprite = sprites[1];
                    break;

                case INSTYPE.Tower:
                    sr.sprite = sprites[9];
                    break;
                }
            }
            else if (south)
            {
                switch (instanceType)
                {
                case INSTYPE.Tube:
                    sr.sprite = sprites[2];
                    break;

                case INSTYPE.Tower:
                    sr.sprite = sprites[11];
                    break;
                }
            }
            else if (west)
            {
                switch (instanceType)
                {
                case INSTYPE.Tube:
                    sr.sprite = sprites[3];
                    break;

                case INSTYPE.Tower:
                    sr.sprite = sprites[15];
                    break;
                }
            }
        }
        else if (numOfConnections == 2)
        {
            if (north && east)
            {
                sr.sprite = sprites[10];
            }
            else if (south && east)
            {
                sr.sprite = sprites[13];
            }
            else if (north && west)
            {
                sr.sprite = sprites[16];
            }
            else if (south && west)
            {
                sr.sprite = sprites[19];
            }
            else if (east && west)
            {
                if (instanceType == INSTYPE.Center)
                {
                    sr.sprite = sprites[7];
                }
                else if (parentCharacter.instanceType == INSTYPE.Center)
                {
                    sr.sprite = sprites[5];
                }
                else
                {
                    sr.sprite = sprites[17];
                }
            }
            else if (south && north)
            {
                if (instanceType == INSTYPE.Center)
                {
                    sr.sprite = sprites[6];
                }
                else if (parentCharacter.instanceType == INSTYPE.Center)
                {
                    sr.sprite = sprites[4];
                }
                else
                {
                    sr.sprite = sprites[12];
                }
            }
        }
        else if (numOfConnections == 3)
        {
            if (west == false)
            {
                sr.sprite = sprites[14];
            }
            else if (south == false)
            {
                sr.sprite = sprites[18];
            }
            else if (east == false)
            {
                sr.sprite = sprites[20];
            }
            else
            {
                sr.sprite = sprites[21];
            }
        }
        else
        {
            sr.sprite = sprites[22];
        }

        DamageDealer dd = gameObject.GetComponentInChildren <DamageDealer>();
        DamageTaker  dt = gameObject.GetComponentInChildren <DamageTaker>();

        DestroyImmediate(gameObject.GetComponent <Collider2D>());
        if (dd)
        {
            DestroyImmediate(dd.GetComponent <Collider2D>());
        }
        if (dt)
        {
            DestroyImmediate(dt.GetComponent <Collider2D>());
        }

        PolygonCollider2D root = gameObject.AddComponent <PolygonCollider2D>();

        if (dd)
        {
            PolygonCollider2D ddCollider = dd.gameObject.AddComponent <PolygonCollider2D>();
            ddCollider.pathCount = root.pathCount;
            for (int p = 0; p < root.pathCount; p++)
            {
                ddCollider.SetPath(p, root.GetPath(p));
            }
            ddCollider.isTrigger = true;
        }
        if (dt)
        {
            PolygonCollider2D dtCollider = dt.gameObject.AddComponent <PolygonCollider2D>();
            dtCollider.pathCount = root.pathCount;
            for (int p = 0; p < root.pathCount; p++)
            {
                dtCollider.SetPath(p, root.GetPath(p));
            }
            dtCollider.isTrigger = true;
        }
        DestroyImmediate(root);
    }