Beispiel #1
0
    public void AddTrackingObject(GameObject obj)
    {
        RadarObject pip = GameObject.Instantiate(pipPrefab, this.transform).GetComponent <RadarObject>();

        pip.trackedObject = obj;
        disctionary.Add(obj, pip);
    }
Beispiel #2
0
        public void UpdateIconForObject(RadarObject radarObject, bool isFirstDraw = false)
        {
            if (!radarObject.SelfIconTransform)
            {
                GameObject    spawnedIcon   = Instantiate(RadarSystem.sceneSingleton.settings.radarIconTemplate, objectsPanel);
                Image         iconImage     = spawnedIcon.GetComponent <Image>();
                RectTransform iconTransform = spawnedIcon.GetComponent <RectTransform>();

                iconImage.sprite = radarObject.IconSprite;
                iconImage.color  = radarObject.CustomColor;
                radarObject.SetSelfIcon(iconTransform);
                iconTransform.SetAsFirstSibling();
                iconTransform.sizeDelta *= RadarSystem.sceneSingleton.settings.iconsScale;

                isFirstDraw = true;
            }

            if (!isFirstDraw && (radarObject.IsStatic || !IsPointOnRadar(radarObject.SelfIconTransform.localPosition)))
            {
                return;
            }

            Vector2 centerObjectPosition = RadarSystem.sceneSingleton.centerObject.GetPosition();
            Vector2 radarObjectOffsetFromCenterObject = radarObject.GetPosition() - centerObjectPosition;
            Vector2 actualRadarTransformOffset        = RadarSystem.sceneSingleton.centerObject.GetOffsetFromStart();

            // У нас есть смещение объекта относительно игрока. И оно корректно. Но у нас так же смещён трансформ радара. Чтобы исключить
            // двойное смещение, вычитаем смещение радара.
            // Using the offset locally by player, and it is right. But we also have ofsetted transform of the radar.
            // To exclude double-offset, subtract the radar offset.
            radarObject.SelfIconTransform.localPosition = startPanelCenter + (radarObjectOffsetFromCenterObject - actualRadarTransformOffset) * RadarSystem.sceneSingleton.settings.radarScale;

            if (radarObject.ShouldBeVisibleAllTime)
            {
                Vector2 parentSize = mainRadarWindow.sizeDelta;
                Vector2 position   = radarObject.SelfIconTransform.position - mainRadarWindow.position;

                if (position.x >= parentSize.x)
                {
                    position.x = parentSize.x;
                }
                else if (position.x <= 0)
                {
                    position.x = 0;
                }

                if (position.y >= parentSize.y)
                {
                    position.y = parentSize.y;
                }
                else if (position.y <= 0)
                {
                    position.y = 0;
                }

                radarObject.SelfIconTransform.position = (Vector3)position + mainRadarWindow.position;
            }
        }
Beispiel #3
0
    /// <summary>
    /// Method that allows game objects to register themselves with the radar
    /// </summary>
    /// <param name="gameObject"></param>
    /// <param name="image"></param>
    public static void RegisterRadarObject(GameObject gameObject, Image image)
    {
        //simply create
        Image       instaniatedImage = Instantiate(image);
        RadarObject radarObject      = new RadarObject();

        radarObject.Icon  = instaniatedImage;
        radarObject.Owner = gameObject;

        //add to list
        radarObjects.Add(radarObject);
    }
    //This will add objects to the radar.
    public void RegisterRadarObject(GameObject o, Image i)
    {
        Image image  = Instantiate(i);
        var   newRad = new RadarObject()
        {
            owner = o, icon = image
        };

        radar_objects.Add(newRad);
        var rt = newRad.icon.GetComponent <RectTransform>();

        rt.SetParent(radar.transform);
        rt.anchorMin = new Vector2(0.5f, 0.5f);
        rt.anchorMax = new Vector2(0.5f, 0.5f);
    }
Beispiel #5
0
        /// <summary>
        /// Go through the ItemSource collection and calculate their canvas positions
        /// </summary>
        void UpdateData()
        {
            try
            {
                using (new PerformanceLogger("RadarUI UpdateData"))
                {
                    Logger.Debug("DataUpdating");

                    if (DesiredSize.Height <= 0 || DesiredSize.Width <= 0)
                    {
                        return;
                    }

                    if (!IsVisible || ZetaDia.Me == null || ZetaDia.IsLoadingWorld || !ZetaDia.IsInGame)
                    {
                        return;
                    }

                    Objects.Clear();

                    CanvasData.Update(DesiredSize, GridSize);

                    // Find the actor who should be in the center of the radar
                    // and whos position all other points should be plotted against.

                    var center = ZetaDia.Me;
                    if (center == null)
                    {
                        return;
                    }

                    CenterActor             = new RadarObject(center, CanvasData);
                    CanvasData.CenterVector = CenterActor.Actor.Position;
                    CanvasData.CenterMorph  = CenterActor.Morph;

                    // Calculate locations for all actors positions
                    // on RadarObject ctor; or with .Update();

                    foreach (var trinityObject in ItemsSource.OfType <DiaObject>())
                    {
                        var radarObject = new RadarObject(trinityObject, CanvasData);
                        Objects.Add(radarObject);
                    }

                    Logger.Debug("DataUpdated");

                    //UpdateRelativeDrawings();

                    //UpdateAvoidanceGridData();

                    //Logger.Log("Heading={0}",ZetaDia.Me.Movement.RotationDegrees);
                }

                // Trigger Canvas to Render
                InvalidateVisual();
            }
            catch (Exception ex)
            {
                Logger.Debug("Exception in RadarUI.UpdateData(). {0} {1}", ex.Message, ex.InnerException);
            }
        }