Exemplo n.º 1
0
    // ---------
    void UpdateRadarInternal(bool forced = false)
    {
        if (!Camera.main || !Player.LocalInstance)
        {
            return;
        }

        foreach (FlagInfo info in m_FlagData)
        {
            info.UpdateDistance();
        }

        Transform playerTrans = Player.LocalInstance.transform;
        Vector3   playerPos   = playerTrans.position;
        Vector3   playerDir   = playerTrans.forward;

        playerDir.y = 0;

        // ----------
        foreach (FlagInfo info in m_FlagData)
        {
            ShowRadarPos(info.RadarFlag.Widget, info.Pos, playerPos, playerDir);
            if (info.IsChanging)
            {
                if (!info.CoroutineActive)
                {
                    info.RadarFlag.Widget.StopAllCoroutines();
                    info.CoroutineActive = true;
                    info.RadarFlag.Widget.StartCoroutine(HighlightObject(info.RadarFlag.Widget, info));
                }
            }
            else
            {
                if (info.CoroutineActive)
                {
                    info.RadarFlag.Widget.StopAllCoroutines();
                    info.CoroutineActive = false;
                }
                info.RadarFlag.Widget.FadeAlpha = 1.0f;
                info.RadarFlag.Widget.Color     = info.Color;
            }
        }

        PlayerPersistantInfo ppi = PPIManager.Instance.GetPPI(Player.LocalInstance.networkView.owner);
        E_Team playerTeam        = (ppi != null) ? ppi.Team : E_Team.None;

        // ----------
        //int indexFriend = 0;
        int indexEnemy = 0;

        foreach (KeyValuePair <uLink.NetworkPlayer, ComponentPlayer> pair in Player.Players)
        {
            if (pair.Value == Player.LocalInstance)
            {
                continue;
            }
            AgentHuman a = pair.Value.Owner;
            if (a.IsAlive == false)
            {
                continue;
            }

            PlayerPersistantInfo ppi2 = PPIManager.Instance.GetPPI(pair.Key);
            if (ppi2 == null)
            {
                continue;
            }

            if (a.IsFriend(Player.LocalInstance.Owner))
            {
                // ----------
                RadarFriend free  = null;
                bool        found = false;
                foreach (RadarFriend friend in RadarFriends)
                {
                    if (friend.m_Used && (friend.m_Agent == a))
                    {
                        found = true;
                        break;
                    }
                    else if (!friend.m_Used)
                    {
                        free = friend;
                    }
                }
                if (!found && (free != null))
                {
                    free.SetAgent(a);
                }
                else
                {
                    if (!found && (free == null))
                    {
                        Debug.LogWarning("Free sprite for radar - friend not found!");
                    }
                }
            }
            else if (a.BlackBoard.IsDetected)
            {
                if (a.IsAlive == false)
                {
                    continue;
                }

                if (a.GadgetsComponent.IsBoostActive(E_ItemBoosterBehaviour.Invisible) &&
                    Player.LocalInstance.Owner.GadgetsComponent.GetGadget(E_ItemID.EnemyDetectorII) == null)
                {
                    continue;
                }

                if (!a.IsFriend(Player.LocalInstance.Owner))
                {
                    if (indexEnemy < RadarEnemies.Length)
                    {
                        E_Team enemyTeam = (playerTeam == E_Team.Bad) ? E_Team.Good : E_Team.Bad;
                        ShowRadarPos(RadarEnemies[indexEnemy].Widget, a.Position, playerPos, playerDir);
                        RadarEnemies[indexEnemy].Widget.Color = ZoneControlFlag.Colors[enemyTeam];
                        ++indexEnemy;
                    }
                }
            }
        }

        // ----------
        foreach (RadarFriend friend in RadarFriends)
        {
            friend.Refresh(forced);
            if (friend.m_Used)
            {
                ShowRadarPos(friend.m_MultiSprite.Widget, friend.m_Agent.Position, playerPos, playerDir);
            }
        }

        // ----------
        for (; indexEnemy < RadarEnemies.Length; indexEnemy++)
        {
            if (RadarEnemies[indexEnemy].Widget.IsVisible() || forced)
            {
                RadarEnemies[indexEnemy].Widget.Show(false, false);
            }
        }
    }
Exemplo n.º 2
0
    // ---------------------------------------------------------------------------------------------------------------------------------
    //                      P U B L I C      P A R T
    // ---------------------------------------------------------------------------------------------------------------------------------

    // ---------
    protected override bool OnInit()
    {
        if (base.OnInit() == false)
        {
            return(false);
        }

        //m_DetectedAgents = null;

        m_FlagData.Clear();
        GUIBase_Pivot pivot = MFGuiManager.Instance.GetPivot(s_PivotMainName);

        if (!pivot)
        {
            Debug.LogError("'" + s_PivotMainName + "' not found!!! Assert should come now");
            return(false);
        }
        GUIBase_Layout layout = pivot.GetLayout(s_LayoutMainName);

        if (!layout)
        {
            Debug.LogError("'" + s_LayoutMainName + "' not found!!! Assert should come now");
            return(false);
        }

        Radar       = layout.GetWidget(s_RadarName).GetComponent <GUIBase_Widget>();
        RadarBkg    = layout.GetWidget(s_RadarBackgroundName).GetComponent <GUIBase_Sprite>();
        RadarCenter = layout.GetWidget(s_RadarCenterName).GetComponent <GUIBase_Sprite>();
        Pulse       = layout.GetWidget(s_PulseName).GetComponent <GUIBase_Sprite>();
        Pulse.transform.localScale = Vector3.zero;
        Pulse.Widget.SetModify();
        PulseTimer = 0;

        RadarEnemies = new GUIBase_Sprite[s_RadarEnemyNames.Length];
        int index = 0;

        foreach (string name in s_RadarEnemyNames)
        {
            RadarEnemies[index++] = layout.GetWidget(name).GetComponent <GUIBase_Sprite>();
        }

        PlayerPersistantInfo ppi = (Player.LocalInstance) ? PPIManager.Instance.GetPPI(Player.LocalInstance.networkView.owner) : null;

        //E_Team                    playerTeam	= (ppi != null) ? ppi.Team : E_Team.None;
        RadarFriends = new RadarFriend[s_RadarFriendNames.Length];
        index        = 0;
        foreach (string name in s_RadarFriendNames)
        {
            RadarFriends[index] = new RadarFriend(layout.GetWidget(name).GetComponent <GUIBase_MultiSprite>());
            ++index;
        }

        // ------
        GameZoneZoneControl zone = Mission.Instance.GameZone as GameZoneZoneControl;

        if (zone != null)
        {
            foreach (ZoneControlFlag flag in zone.Zones)
            {
                m_FlagData.Add(new FlagInfo(flag));
            }
        }
        foreach (FlagInfo flagInfo in m_FlagData)
        {
            index = flagInfo.Flag.ZoneNameIndex - 0500480;
            if ((index < 0) || (index > s_RadarFlagNames.Length))
            {
                Debug.LogWarning("Can't translate Flag.ZoneNameIndex into index for radar!");
                m_FlagData.Clear();
                break;
            }
            else
            {
                flagInfo.RadarFlag = layout.GetWidget(s_RadarFlagNames[index]).GetComponent <GUIBase_Sprite>();
            }
        }
        RadarFlags = new GUIBase_Sprite[s_RadarFlagNames.Length];
        index      = 0;
        foreach (string name in s_RadarFlagNames)
        {
            RadarFlags[index] = layout.GetWidget(name).GetComponent <GUIBase_Sprite>();
            ++index;
        }
        // ------

        Transform radarTrans = Radar.transform;
        Vector3   lossyScale = radarTrans.lossyScale;

        //Debug.Log("Radar.Widget.m_Width: "+Radar.Widget.m_Width);
        Vector2 size = new Vector2(RadarBkg.Widget.GetWidth() - 60, RadarBkg.Widget.GetWidth() - 60);

        // layout.LayoutSpaceDeltaToScreen(new Vector2(RadarBkg.Widget.m_Width - 16, RadarBkg.Widget.m_Width - 16));
        size.x            = size.x * lossyScale.x;
        size.y            = size.y * lossyScale.y;
        RadarScreenRadius = size.x / 2.0f;
        size = new Vector2(RadarCenter.Widget.GetWidth(), RadarCenter.Widget.GetWidth());
        //layout.LayoutSpaceDeltaToScreen(new Vector2(RadarCenter.Widget.m_Width, RadarCenter.Widget.m_Width));
        size.x            *= lossyScale.x;
        size.y            *= lossyScale.y;
        RadarCenterRadius  = size.x / 2.0f;
        RadarScreenRadius -= RadarCenterRadius;

        RadarRange  = RadarMaxRange;
        HasDetector = false;
        // -----
        if (Player.LocalInstance)
        {
            ppi = PPIManager.Instance.GetPPI(Player.LocalInstance.Owner.NetworkView.owner);
            foreach (PPIItemData d in ppi.EquipList.Items)
            {
                ItemSettings item = ItemSettingsManager.Instance.Get(d.ID);
                if (item.ItemBehaviour == E_ItemBehaviour.Detector)
                {
                    HasDetector = true;
                    break;
                }
            }
        }

        return(true);
    }