Пример #1
0
        private void ChargeOneTool(ChargeTool tool, UnityAction onComplete)
        {
            var resources      = elementCtrl.GetElements <ChargeResource>();
            var chargeResource = resources.Find(x => tool.CanLoad(x.type) && x.Active);
            var value          = Mathf.Min(tool.capacity, chargeResource.current);
            var type           = chargeResource.type;

            tool.PickUpAble = false;
            tool.LoadData(chargeResource.transform.position, new ChargeData(type, value), () => {
                tool.PickUpAble = true;
            });
            chargeResource.Subtruct(value, () => { onComplete.Invoke(); });
        }
Пример #2
0
 /// <summary>
 /// 空间查找Resource
 /// </summary>
 /// <param name="item"></param>
 /// <param name="resourceItem"></param>
 /// <returns></returns>
 public static bool FindResource(ChargeTool item, out ChargeResource resourceItem)
 {
     Collider[] colliders = Physics.OverlapSphere(item.transform.position, item.Range, LayerMask.GetMask(Layers.chargeResourceLayer));
     if (colliders != null && colliders.Length > 0)
     {
         foreach (var collider in colliders)
         {
             ChargeResource temp = collider.GetComponentInParent <ChargeResource>();
             if (temp != null && item.CanLoad(temp.type))
             {
                 resourceItem = temp;
                 return(true);
             }
         }
     }
     resourceItem = null;
     return(false);
 }