예제 #1
0
    public EnemyView SpawnEnemy(EnemyData data, int spawnLane = -1)
    {
        float   jitter = Random.value * 0.2f;
        Vector3 origin = Vector3.zero;

        if (spawnLane == -1)
        {
            spawnLane = Random.Range(0, 7);
        }
        else
        {
            spawnLane = Mathf.Max(0, spawnLane);
        }

        origin = Mathfx.GetPointOnCircle(5.5f + jitter, (spawnLane * 45), Vector3.zero);
        return(SpawnEnemy(data, origin, Quaternion.Euler(0, 0, (spawnLane * 45) - 90)));
        //var es = Instantiate(enemySheet, origin, Quaternion.Euler(0, 0, (spawnLane * 45) - 90), transform);
        ////es.transform.eulerAngles = new Vector3(0, 0, (spawnLane * 45) - 90);
        //es.SetData(data);
        //es.mover.Mobilize(es.mover.transform.position, goal.position, es.enemyData.speed);

        //arrangeSortingLayer.CheckandReorder();

        //onSpawned.Invoke(es);

        //enemies.Add(es);
        //es.onDestroy.AddListener(OnEnemyDestroyed);
        //return es;
    }
예제 #2
0
    private BladeView AddBlade(int i)
    {
        float angle = 45 * i;
        var   circ  = Mathfx.GetPointOnCircle(bladePrefab.radiusOffset, angle + 90, Vector3.zero);
        var   b     = Instantiate(bladePrefab, transform);

        b.transform.localPosition    = circ;
        b.transform.localEulerAngles = new Vector3(0, 0, angle);
        b.name = "Blade" + i;
        b.transform.localScale = new Vector3(1, 0, 1);
        b.bladeData            = bladeData;

        if (bladeData.spriteStates.Count > 0)
        {
            b.spriteRenderer.sprite = bladeData.spriteStates[0];
        }

        switch (bladeData.type)
        {
        case GizLib.BladeType.Default:
            var dam = b.gameObject.AddComponent <BladeDamage>();
            b.onImpact.AddListener(dam.HandleImpact);
            break;
        }
        blades.Add(b);
        return(b);
    }
예제 #3
0
    public void Rebound()
    {
        var radius = Vector3.Distance(mover.transform.position, Vector3.zero) + (0.555f * span);
        var target = Mathfx.GetPointOnCircle(radius + (Random.value * 0.1f), mover.transform.eulerAngles.z + 90, Vector3.zero);

        mover.StartMovement(MoveType.Detour, mover.speed * 20, target);
    }
예제 #4
0
    public void FlankTarget(Transform flanked)
    {
        detouring = true;

        var radius = Vector3.Distance(mover.transform.position, Vector3.zero) + flankDistance;

        var target = Mathfx.GetPointOnCircle(radius, mover.transform.eulerAngles.z + 90, Vector3.zero);

        mover.StartMovement(MoveType.Detour, mover.speed * 20, target);
    }
예제 #5
0
    private void MoveToTarget()
    {
        sequence = DOTween.Sequence();
        var rt    = transform as RectTransform;
        var circ  = Mathfx.GetPointOnCircle(radius, target.eulerAngles.z + 90, Vector3.zero);
        var point = Camera.main.WorldToScreenPoint(circ);

        sequence.Append(transform.DOMove(point, 0.7f).SetEase(DG.Tweening.Ease.InOutQuad));
        sequence.OnComplete(Release);
    }
예제 #6
0
    public void DropScrap(int amount, bool phaseOut, float degrees, Vector3 startPosition)
    {
        var scraps = SpawnScrap(amount, phaseOut);

        foreach (var item in scraps)
        {
            item.transform.position = startPosition;
            item.mover.SetAngle(degrees);
            item.mover.SetEndPoint(item.mover.endRadius);
            item.dropped = true;
            Vector3 blow = Mathfx.GetPointOnCircle(0.5f, Random.Range(0, 360), startPosition);
            item.mover.StartMovement(MoveType.Detour, 2, blow);
        }
    }
예제 #7
0
    void PushAway()
    {
        var contacts = GetContacts();

        var sectors = new List <SectorHandler>();

        for (int i = 0; i < contacts.Length; i++)
        {
            var sector = contacts[i].GetComponent <SectorHandler>();
            if (sector)
            {
                sectors.Add(sector);
            }
        }

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

        SectorHandler sect = sectors[0];

        for (int i = 1; i < sectors.Count; i++)
        {
            if (Mathf.Abs(sectors[i].transform.eulerAngles.z - transform.eulerAngles.z) < Mathf.Abs(sect.transform.eulerAngles.z - transform.eulerAngles.z))
            {
                sect = sectors[i];
            }
        }

        for (int i = 0; i < contacts.Length; i++)
        {
            if (targetTags.Contains(contacts[i].gameObject.tag))
            {
                var mover = contacts[i].GetComponent <Mover>();
                if (!mover)
                {
                    mover = contacts[i].GetComponentInParent <Mover>();
                }
                if (mover)
                {
                    var radius = Vector3.Distance(mover.transform.position, Vector3.zero) + (0.555f * repelSpan);
                    var target = Mathfx.GetPointOnCircle(radius + (UnityEngine.Random.value * 0.1f), sect.transform.eulerAngles.z + 90, Vector3.zero);

                    mover.StartMovement(MoveType.Detour, repelSpeed, target);
                }
            }
        }
    }
예제 #8
0
 private void OnHealthChange(GizLib.IntValueChange intValue)
 {
     if (intValue.value <= 0 && EnemySpawner.Instance)
     {
         for (int i = 0; i < spawn.Count; i++)
         {
             var   distance = Vector3.Distance(transform.position, Vector3.zero) + (0.555f * 2.5f);
             var   en       = EnemySpawner.Instance.SpawnEnemy(spawn[i], transform.position, Quaternion.Euler(0, 0, transform.eulerAngles.z));
             float offset   = 45;
             if (i % 2 == 0)
             {
                 offset *= -1f;
                 en.transform.localScale = new Vector3(en.transform.localScale.x * -1, en.transform.localScale.y, en.transform.localScale.z);
             }
             var degree = transform.eulerAngles.z + offset + 90;
             var target = Mathfx.GetPointOnCircle(distance, degree, Vector3.zero);
             en.mover.StartMovement(MoveType.Detour, en.mover.speed * 20, target);
             en.mover.onDetour.AddListener(en.unitGraphics.OnActivateTrigger);
             en.transform.eulerAngles = new Vector3(0, 0, transform.eulerAngles.z + offset);
         }
     }
 }
예제 #9
0
    protected void SetCoarse()
    {
        if (transform.eulerAngles.z % 45 == 0)
        {
            mover.SetDirection((int)(transform.eulerAngles.z / 45));
            mover.Mobilize(mover.speed);
        }

        var rb = GetComponent <Rigidbody2D>();

        if (!rb)
        {
            Debug.LogWarning("No Rigid Body Found.");
            return;
        }
        var contacts = new Collider2D[50];
        var count    = rb.GetContacts(contacts);

        System.Array.Resize(ref contacts, count);

        var sectors = new List <SectorHandler>();

        for (int i = 0; i < contacts.Length; i++)
        {
            var sector = contacts[i].GetComponent <SectorHandler>();
            if (sector)
            {
                sectors.Add(sector);
            }
        }

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

        SectorHandler sect = sectors[0];

        for (int i = 1; i < sectors.Count; i++)
        {
            if (Mathf.Abs(sectors[i].transform.eulerAngles.z - transform.eulerAngles.z) < Mathf.Abs(sect.transform.eulerAngles.z - transform.eulerAngles.z))
            {
                sect = sectors[i];
            }
        }

        int direction = 0;

        if (sect.transform.eulerAngles.z >= 0)
        {
            direction = (int)(sect.transform.eulerAngles.z / 45f);
        }
        else
        {
            direction = (int)(360 + sect.transform.eulerAngles.z / 45f);
        }
        mover.SetDirection(direction);
        mover.Mobilize(mover.speed);
        transform.eulerAngles = sect.transform.eulerAngles;
        var radius = Vector3.Distance(transform.position, Vector3.zero) + 0.5f;
        var coarse = Mathfx.GetPointOnCircle(radius, (direction * 45) + 90, Vector3.zero);

        mover.StartMovement(MoveType.Detour, 3, coarse);
    }