Пример #1
0
        public Planet(float radius = 10f, int resourcePointsCount = 20, List <ExcludeVolume> excludeVolumes = null)
        {
            const float gridCellSize = 0.3f;
            int         density      = Mathf.CeilToInt((2f * Mathf.PI * radius / 6f) / gridCellSize);

            Graph     = NavigationGridBuilder.Generate(radius, density, excludeVolumes);
            Radius    = radius;
            Resources = new ResourcePoint[resourcePointsCount];
            for (int i = 0; i < Resources.Length; i++)
            {
                Resources[i] = new ResourcePoint(GetRandomPosition(), 10);
            }
        }
Пример #2
0
        public bool FindNearestResourcePoint(Vector3 position, out ResourcePoint resourcePoint, float maxDistance = 0.5f)
        {
            resourcePoint = null;
            var nearestDistance = 0f;

            foreach (var point in Resources)
            {
                if (point == null || point.Count == 0)
                {
                    continue;
                }
                var distance = Vector3.Distance(point.Position, position);
                if (distance < maxDistance && (distance < nearestDistance || resourcePoint == null))
                {
                    nearestDistance = distance;
                    resourcePoint   = point;
                }
            }
            return(resourcePoint != null);
        }
Пример #3
0
 public ResourceTask(ResourcePoint point, Action <int> onCollectResource)
 {
     resourcePoint     = point;
     collectionTimer   = resourceCollectionTime;
     OnCollectResource = onCollectResource;
 }
Пример #4
0
 public void AddResourceTask(ResourcePoint resourcePoint)
 {
     taskList.Add(new MoveTask(resourcePoint.Position, Mover));
     taskList.Add(new ResourceTask(resourcePoint, ChangeResourceCount));
     view.OnUpdateTaskList();
 }