Esempio n. 1
0
        public void DeleteMarker(FishingMarker marker)
        {
            if (_markers.Length - 1 > 0)
            {
                bool            deleted        = false;
                FishingMarker[] newMarkerArray = new FishingMarker[_markers.Length - 1];
                for (int i = 0; i < _markers.Length; i++)
                {
                    if (_markers[i] == marker)
                    {
                        deleted = true;
                    }
                    else if (!deleted)
                    {
                        newMarkerArray[i] = _markers[i];
                    }
                    else
                    {
                        newMarkerArray[i - 1] = _markers[i];
                        _markers[i].name      = "Marker " + (i);
                    }
                }

                _markers = newMarkerArray;
            }
            else
            {
                _markers = null;
            }

            DestroyImmediate(marker.gameObject);
        }
Esempio n. 2
0
        public FishingMarker NewMarker()
        {
            FishingMarker newMarker = new GameObject()
                                      .AddComponent <FishingMarker>();

            newMarker.SetContainingArea(this);
            newMarker.transform.SetParent(MarkersParent);

            if (_markers == null)
            {
                _markers = new FishingMarker[1] {
                    newMarker
                };
                newMarker.transform.position = transform.position;
                newMarker.name = "Marker 1";
            }
            else
            {
                FishingMarker[] newMarkerArray = new FishingMarker[_markers.Length + 1];
                for (int i = 0; i < _markers.Length + 1; i++)
                {
                    if (i < _markers.Length)
                    {
                        newMarkerArray[i] = _markers[i];
                    }
                    else
                    {
                        newMarkerArray[i]         = newMarker;
                        newMarker.gameObject.name = "Marker " + (i + 1);
                    }
                }

                if (_markers.Length > 2)
                {
                    newMarker.transform.position = GetMiddlePoint(
                        _markers[0].transform.position,
                        _markers[_markers.Length - 1].transform.position
                        );
                }
                else
                {
                    newMarker.transform.position = MarkersParent.transform.position;
                }

                _markers = newMarkerArray;
            }

            return(newMarker);
        }