Esempio n. 1
0
        void SearchNearestResourcesField()
        {
            if (recheckTimer > 0)
            {
                recheckTimer -= Time.deltaTime;
                return;
            }

            var   allFields = ResourcesField.sceneResourceFields;
            float distance  = float.MaxValue - 1f;

            for (int i = 0; i < allFields.Count; i++)
            {
                float curDistance = (transform.position - allFields[i].transform.position).sqrMagnitude;

                if (curDistance < distance)
                {
                    resourcesField = allFields[i];
                    distance       = curDistance;
                }
            }

            if (resourcesField)
            {
                SetHarvestState(HarvestState.MoveToField);
            }

            recheckTimer = 1f;
        }
Esempio n. 2
0
        public void OnUnitReceivedOrder(Unit unit, Order order)
        {
            if (order is MovePositionOrder)
            {
                var position = (order as MovePositionOrder).movePosition;

                var size = Physics.OverlapSphereNonAlloc(position, 7f, nearestColliders);

                for (int i = 0; i < size; i++)
                {
                    var field = nearestColliders[i].GetComponent <ResourcesField>();

                    if (field)
                    {
                        resourcesField = field;
                        SetHarvestState(HarvestState.MoveToField);

                        return;
                    }
                }
            }
            else if (order is FollowOrder)
            {
                var target = (order as FollowOrder).followTarget;

                var refinery = target.GetComponent <Refinery>();

                if (refinery)
                {
                    SetRefinery(refinery);

                    if (harvestedResources > 0)
                    {
                        SetHarvestState(HarvestState.MoveToRefinery);
                    }

                    return;
                }
            }

            SetHarvestState(HarvestState.Idle);
        }