Пример #1
0
        private void ChargeOneTool(ChargeTool tool, UnityAction onComplete)
        {
            var resources      = elementCtrl.GetElements <ChargeResource>();
            var chargeResource = resources.Find(x => tool.CanLoad(x.type) && x.Actived);
            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
        private void ChargeCurrentObj(ChargeTool tool, UnityAction onComplete)
        {
            var        data     = tool.data;
            ChargeData worpData = JudgeLeft(data);

            if (!string.IsNullOrEmpty(worpData.type))
            {
                tool.PickUpAble = false;
                tool.OnCharge(transform.position, worpData.value, () => { tool.PickUpAble = true; });
                Charge(worpData, () =>
                {
                    onComplete();
                });
            }
        }
Пример #3
0
        public static bool FindChargeObj(ChargeTool item, out ChargeItem container)
        {
            var containerItems = SelectItems <ChargeItem>(ChargeItem.layer, CameraController.Instence.currentCamera.transform.position, item.transform.position, item.Range);

            if (containerItems == null || containerItems.Length == 0)
            {
                container = null;
                return(false);
            }
            else
            {
                for (int i = 0; i < containerItems.Length; i++)
                {
                    ChargeItem tempItem = containerItems[i];
                    if (tempItem != null && tempItem.Actived && tempItem.completeDatas.FindAll(x => x.type == item.data.type).Count > 0)
                    {
                        container = tempItem;
                        return(true);
                    }
                }
                container = null;
                return(false);
            }
        }
Пример #4
0
        /// <summary>
        /// 空间查找Resource
        /// </summary>
        /// <param name="item"></param>
        /// <param name="resourceItem"></param>
        public static bool FindResource(ChargeTool item, out ChargeResource resourceItem)
        {
            var resourceItems = SelectItems <ChargeResource>(ChargeResource.layer, CameraController.Instence.currentCamera.transform.position, item.transform.position, item.Range);

            if (resourceItems == null || resourceItems.Length == 0)
            {
                resourceItem = null;
                return(false);
            }
            else
            {
                for (int i = 0; i < resourceItems.Length; i++)
                {
                    ChargeResource tempItem = resourceItems[i];
                    if (tempItem != null && tempItem.Actived && item.CanLoad(tempItem.type) && tempItem.current > 0)
                    {
                        resourceItem = tempItem;
                        return(true);
                    }
                }
                resourceItem = null;
                return(false);
            }
        }
Пример #5
0
 protected virtual void Awake()
 {
     target          = GetComponent <ChargeTool>();
     target.onCharge = OnCharge;
     target.onLoad   = OnLoad;
 }