private void FixedUpdate()
    {
        if (null == m_Weapon)
        {
            return;
        }
        /// 攻击模式
        if (m_FireMode != FireMode.WEAPON_MODE_AUTO)
        {
            return;
        }

        ShipManager.get();
        Ship   selfShip      = transform.parent.GetComponent <Ship>();
        string selfInfluence = selfShip.m_ShipStruct.Influence;

        for (int i = 0; i < ShipManager.get().NumShips; ++i)
        {
            var ship = ShipManager.get().GetShip(i);
            if (ship == transform.parent.gameObject)
            {
                continue;
            }
            var forward          = transform.rotation * ForwardDirection;
            var targetDifference = ship.transform.position - transform.position;
            var targetDirection  = targetDifference.normalized;
            var angle            = Vector3.Angle(forward, targetDirection);
            if (angle > AngleRange / 2)
            {
                continue;
            }
            float targetPositionDistance = targetDifference.magnitude;
            if (targetPositionDistance > m_Weapon.ShutRange)
            {
                continue;
            }
            if (InfluenceMG.get().isHostile(selfInfluence, ship.GetComponent <Ship>().m_ShipStruct.Influence))
            {
                arm(ship.transform.position);
                fire();
            }
            break;
        }
    }
Exemple #2
0
    void onInfluenceChanged(string newInfluenceName)
    {
        m_isPlayerEnemy = -1;
        var influence = InfluenceMG.get().find(newInfluenceName);

        if (influence.Name != InfluenceMG.INFLUENCE_PLAYER)
        {
            if (influence.findHostile(InfluenceMG.INFLUENCE_PLAYER) >= 0)
            {
                SpriteRenderer sprite = m_ShipInfluenceRelationFlag.GetComponent <SpriteRenderer>();
                sprite.material = Resources.Load <Material>("Materials/Colors/Enemy");
                m_isPlayerEnemy = 1;
            }
            else
            {
                SpriteRenderer sprite = m_ShipInfluenceRelationFlag.GetComponent <SpriteRenderer>();
                sprite.material = Resources.Load <Material>("Materials/Colors/Friend");
                m_isPlayerEnemy = 0;
            }
        }
    }
 public void FixedUpdate()
 {
     if (m_Trace && !m_Target && null != m_Influence)
     {
         float distance = 1000000000000;
         for (int i = 0; i < ShipManager.get().NumShips; ++i)
         {
             var ship    = ShipManager.get().GetShip(i);
             var shipCom = ship.GetComponent <Ship>();
             if (InfluenceMG.get().isHostile(m_Influence, shipCom.m_ShipStruct.Influence))
             {
                 var defference = ship.transform.position - transform.position;
                 if (defference.magnitude < distance)
                 {
                     distance = defference.magnitude;
                     m_Target = ship;
                 }
             }
         }
     }
 }
Exemple #4
0
    private void FixedUpdate()
    {
        currentTime += Time.fixedDeltaTime;
        if (currentTime < findTargetTime)
        {
            return;
        }
        currentTime    = 0;
        findTargetTime = Random.Range(0.2f, 1f);

        var        selfShipCom   = GetComponent <Ship>();
        var        selfInfluence = selfShipCom.m_ShipStruct.Influence;
        float      minDistance   = 111111111110;
        GameObject nearObj       = null;

        for (int i = 0; i < ShipManager.get().NumShips; ++i)
        {
            var shipObj        = ShipManager.get().GetShip(i);
            var shipDefference = shipObj.transform.position - transform.position;

            var shipCom = shipObj.GetComponent <Ship>();

            if (InfluenceMG.get().isHostile(selfInfluence, shipCom.m_ShipStruct.Influence))
            {
                var detectRange = shipCom.m_ShipStruct.DetectRange;
                var theDistance = shipDefference.magnitude;
                if (theDistance < detectRange &&
                    theDistance < minDistance)
                {
                    minDistance = theDistance;
                    nearObj     = shipObj;
                }
            }
        }
        if (nearObj)
        {
            Target = nearObj;
        }
    }
Exemple #5
0
 private void Awake()
 {
     BulletPool.get().init();
     SoundsPool.get().init();
     InfluenceMG.get().init();
 }