private void OnPickStay(PickUpAbleItem item)
        {
            if (item is ChargeTool)
            {
                var currTool = chargeTool;
                if (chargeResource != null)
                {
                    var value = Mathf.Min(currTool.capacity, chargeResource.current);
                    var type  = chargeResource.type;
                    currTool.PickUpAble = false;
                    currTool.LoadData(chargeResource.transform.position, new ChargeData(type, value), () => {
                        currTool.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.PickUpAble = false;
                        currTool.OnCharge(chargeObj.transform.position, worpData.value, () => { currTool.PickUpAble = true; });
                        chargeObj.Charge(worpData, () => { chargeObj.JudgeComplete(); });
                    }
                    highter.UnHighLightTarget(chargeObj.gameObject);
                    lastMatchChargeObj = null;
                }
            }
        }
 public override void Update()
 {
     if (chargeTool != null)
     {
         if (chargeTool.charged)
         {
             if (ChargeUtil.FindChargeObj(chargeTool, out chargeObj))
             {
                 if (chargeObj != lastMatchChargeObj)
                 {
                     if (lastMatchChargeObj != null)
                     {
                         highter.UnHighLightTarget(lastMatchChargeObj.gameObject);
                     }
                     highter.HighLightTarget(chargeObj.gameObject, Color.green);
                     lastMatchChargeObj = chargeObj;
                 }
             }
             else
             {
                 if (lastMatchChargeObj != null)
                 {
                     highter.UnHighLightTarget(lastMatchChargeObj.gameObject);
                     lastMatchChargeObj = null;
                 }
             }
         }
         else
         {
             if (ChargeUtil.FindResource(chargeTool, out chargeResource))
             {
                 if (chargeResource != lastMatchChargeResource)
                 {
                     if (lastMatchChargeResource != null)
                     {
                         highter.UnHighLightTarget(lastMatchChargeResource.gameObject);
                     }
                     highter.HighLightTarget(chargeResource.gameObject, Color.green);
                     lastMatchChargeResource = chargeResource;
                 }
             }
             else
             {
                 if (lastMatchChargeResource != null)
                 {
                     highter.UnHighLightTarget(lastMatchChargeResource.gameObject);
                     lastMatchChargeResource = null;
                 }
             }
         }
     }
 }
Пример #3
0
        private void ActiveElements(ChargeObj element)
        {
            var actived = lockQueue.Find(x => x.Name == element.Name);

            if (actived == null)
            {
                var tools = ElementController.Instence.GetElements <ChargeTool>();
                if (tools != null)
                {
                    for (int i = 0; i < tools.Count; i++)
                    {
                        if (completeDatas.FindAll(y => tools[i].CanLoad(y.type)).Count == 0)
                        {
                            return;
                        }

                        if (log)
                        {
                            Debug.Log("ActiveElements:" + element.Name + (!tools[i].Active));
                        }

                        if (!tools[i].Active)
                        {
                            tools[i].StepActive();
                        }
                    }
                }

                var resources = ElementController.Instence.GetElements <ChargeResource>();
                if (resources != null)
                {
                    for (int i = 0; i < resources.Count; i++)
                    {
                        if (completeDatas.FindAll(y => y.type == resources[i].type).Count == 0)
                        {
                            continue;
                        }

                        if (log)
                        {
                            Debug.Log("ActiveElements:" + element.Name + (!resources[i].Active));
                        }

                        if (!resources[i].Active)
                        {
                            resources[i].StepActive();
                        }
                    }
                }
            }
            lockQueue.Add(element);
        }
        internal static bool FindChargeObj(ChargeTool item, out ChargeObj chargeObj)
        {
            Collider[] colliders = Physics.OverlapSphere(item.transform.position, item.Range, LayerMask.GetMask(Layers.chargeObjLayer));
            if (colliders != null && colliders.Length > 0)
            {
                foreach (var collider in colliders)
                {
                    ChargeObj temp = collider.GetComponentInParent <ChargeObj>();

                    if (temp != null && temp.Started && !temp.Complete && temp.completeDatas.FindAll(x => x.type == item.data.type).Count > 0)
                    {
                        chargeObj = temp;
                        return(true);
                    }
                }
            }
            chargeObj = null;
            return(false);
        }
Пример #5
0
        private void CompleteElements(ChargeObj element, bool undo)
        {
            lockQueue.Remove(element);
            var active = lockQueue.Find(x => x.Name == element.Name);

            if (active == null)
            {
                var tools = ElementController.Instence.GetElements <ChargeTool>();
                if (tools != null)
                {
                    for (int i = 0; i < tools.Count; i++)
                    {
                        if (log)
                        {
                            Debug.Log("CompleteElements:" + element.Name + tools[i].Active);
                        }

                        if (completeDatas.FindAll(y => tools[i].CanLoad(y.type)).Count == 0)
                        {
                            return;
                        }

                        if (tools[i].Active)
                        {
                            if (undo)
                            {
                                tools[i].StepUnDo();
                            }
                            else
                            {
                                tools[i].StepComplete();
                            }
                        }
                    }
                }

                var resources = ElementController.Instence.GetElements <ChargeResource>();
                if (resources != null)
                {
                    for (int i = 0; i < resources.Count; i++)
                    {
                        if (log)
                        {
                            Debug.Log("CompleteElements:" + element.Name + resources[i].Active);
                        }

                        if (completeDatas.FindAll(y => y.type == resources[i].type).Count == 0)
                        {
                            continue;
                        }

                        if (resources[i].Active)
                        {
                            if (undo)
                            {
                                resources[i].StepUnDo();
                            }
                            else
                            {
                                resources[i].StepComplete();
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
 protected virtual void Awake()
 {
     target          = GetComponent <ChargeObj>();
     target.onCharge = OnCharge;
 }