public void SubAsync(ChargeData arg0, float lerpTime)
        {
            var data = arg0;

            data.value = -arg0.value;
            AddAsync(data, lerpTime);
        }
        public void Sub(ChargeData arg0)
        {
            var data = arg0;

            data.value = -arg0.value;
            Add(data);
        }
 protected override void OnCharge(Vector3 center, ChargeData data, UnityAction onComplete)
 {
     if (onComplete != null)
     {
         scaleCtrl.AddAsync(data, animTime);
         StartAsync(onComplete);
     }
     else
     {
         scaleCtrl.Add(data);
     }
 }
        protected override void OnLoad(Vector3 center, ChargeData data, UnityAction onComplete)
        {
            if (onComplete != null)
            {
                StartAsync(onComplete);//先执行异步计时,不然重置动画的依据不足

                scaleCtrl.AddAsync(data, animTime);
                animCtrl.PlayAnim(loadAnimName, center, animTime);
            }
            else
            {
                scaleCtrl.Add(data);
            }
        }
        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();
                });
            }
        }
Exemple #6
0
        /// <summary>
        /// 吸入
        /// </summary>
        /// <param name="chargeResource"></param>
        internal void LoadData(Vector3 center, ChargeData data, UnityAction onComplete)
        {
            chargeData = data;

            if (onLoad != null)
            {
                onLoad.Invoke(center, data, onComplete);
            }
            else
            {
                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// 导出
        /// </summary>
        internal void OnCharge(Vector3 center, float value, UnityAction onComplete)
        {
            var left = data.value - value;

            if (onCharge != null)
            {
                var d = new ChargeData(data.type, value);
                onCharge.Invoke(center, d, onComplete);
            }
            else
            {
                if (onComplete != null)
                {
                    onComplete.Invoke();
                }
            }
            chargeData.value = left;
        }
        /// <summary>
        /// 返回一个比0大的数
        /// </summary>
        /// <param name="data"></param>
        /// <returns></returns>
        public virtual void Charge(ChargeData data, UnityAction onComplete)
        {
            var complete = completeDatas.Find(x => x.type == data.type);

            if (!string.IsNullOrEmpty(complete.type))
            {
                if (onCharge != null)
                {
                    onCharge.Invoke(transform.position, data, onComplete);
                }
                else
                {
                    if (onComplete != null)
                    {
                        onComplete.Invoke();
                    }
                }
                _currentList.Add(data);
            }
        }
        /// <summary>
        /// 判断并填充
        /// </summary>
        /// <param name="complete"></param>
        /// <param name="data"></param>
        /// <param name="onCharge"></param>
        /// <returns></returns>
        public ChargeData JudgeLeft(ChargeData data)
        {
            var complete = completeDatas.Find(x => x.type == data.type);

            if (!string.IsNullOrEmpty(complete.type))
            {
                var   currents = _currentList.FindAll(x => x.type == data.type);
                float full     = 0;
                foreach (var item in currents)
                {
                    full += item.value;
                }
                float left = (full + data.value) - complete.value;
                left = left > 0 ? left : 0;
                var charge = new ChargeData(data.type, data.value - left);
                return(charge);
            }
            else
            {
                return(default(ChargeData));
            }
        }
        private void CompleteOneElement(ChargeData complete, UnityAction onComplete)
        {
            var   currents = currentList.FindAll(x => x.type == complete.type);
            float total    = 0;

            foreach (var item in currents)
            {
                total += item.value;
            }

            if (complete.value - total > 0)
            {
                var         tools           = elementCtrl.GetElements <ChargeTool>();
                var         tool            = tools.Find(x => x.CanLoad(complete.type) && x.Actived);
                UnityAction chargeObjAction = () =>
                {
                    ChargeCurrentObj(tool, () =>
                    {
                        CompleteOneElement(complete, onComplete);
                    });
                };
                if (!tool.charged)
                {
                    ChargeOneTool(tool, chargeObjAction);
                }
                else
                {
                    chargeObjAction.Invoke();
                }
            }
            else
            {
                onComplete.Invoke();
                Debug.Log("Charge Complete:" + complete.type);
            }
        }
        private void OnPickStay(PickUpAbleComponent item)
        {
            var chargeTool = item.GetComponentInParent <ChargeTool>();

            if (chargeTool)
            {
                var currTool = chargeTool;
                if (chargeResource != null)
                {
                    var value = Mathf.Min(currTool.capacity, chargeResource.current);
                    var type  = chargeResource.type;
                    currTool.RetriveFeature <PickUpAbleFeature>().PickUpAble = false;
                    currTool.LoadData(chargeResource.transform.position, new ChargeData(type, value), () =>
                    {
                        currTool.RetriveFeature <PickUpAbleFeature>().PickUpAble = true;
                    });
                    chargeResource.Subtruct(value, () => { });

                    highter.UnHighLightTarget(chargeResource.gameObject);
                    lastMatchChargeResource = chargeResource = null;
                }
                else if (chargeObj != null)
                {
                    var        data     = currTool.data;
                    ChargeData worpData = chargeObj.JudgeLeft(data);
                    if (!string.IsNullOrEmpty(worpData.type))
                    {
                        currTool.RetriveFeature <PickUpAbleFeature>().PickUpAble = false;
                        currTool.OnCharge(chargeObj.transform.position, worpData.value, () => { currTool.RetriveFeature <PickUpAbleFeature>().PickUpAble = true; });
                        chargeObj.Charge(worpData, () => { chargeObj.JudgeComplete(); });
                    }
                    highter.UnHighLightTarget(chargeObj.gameObject);
                    lastMatchChargeObj = null;
                }
            }
        }
 protected abstract void OnCharge(Vector3 center, ChargeData data, UnityAction onComplete);
 public void Add(ChargeData arg0)
 {
     currentValue += arg0.value;
     QuickSet();
 }
 public void AddAsync(ChargeData arg0, float lerpTime)
 {
     currentValue += arg0.value;
     AsyncSet(lerpTime);
 }