상속: UnityEngine.MonoBehaviour, IDropHandler, IPointerEnterHandler, IPointerExitHandler
        public void ItemButtonClick(int itemArrayIndex)
        {
            if (_selectedItemIndex != itemArrayIndex)
            {
                UnselectSelectedItem();

                _selectedItemIndex = itemArrayIndex;

                _selectedItem = _currentlyLoadedItemArray[itemArrayIndex];

                System.Action <Item> trueAction = delegate(Item item)
                {
                    item.SetShaderOutline(_itemSettings.InstantiateOutlineColor);
                    item.State = ItemState.Instantiate;
                };
                System.Action <Item> falseAction = delegate(Item item)
                {
                    item.SetShaderNormal();
                    item.State = ItemState.NoInstantiate;
                };
                System.Func <Item, bool> filterAction = delegate(Item item)
                {
                    ItemDrop     itemDrop  = item.GetComponent <ItemDrop>();
                    ItemColor    itemColor = item.GetComponent <ItemColor>();
                    const string colorTag  = "Color";
                    if (itemDrop != null)
                    {
                        return(itemDrop.CanAttach(_selectedItem.TagArray));
                    }
                    if (itemColor != null && _selectedItem.HasTag(colorTag))
                    {
                        return(true);
                    }
                    return(false);
                };

                int trueCount = Root.CallDelegateTagFilter(filterAction, trueAction, falseAction);

                if (trueCount == 0)
                {
                    _selectedItem = null;
                    Root.SetAllOutlineNormalAttach();
                    _selectedItemIndex = -1;
                }
                else
                {
                    System.Action action = delegate()
                    {
                        UnselectSelectedItem();
                    };
                    _catcher.EmptyClickAction = action;

                    ItemBarHorizontalGroupItemList[_selectedItemIndex].GetComponent <Transform>().FindChild("ItemBarItemHighlight").GetComponent <Image>().enabled = true;
                }
            }
            else
            {
                UnselectSelectedItem();
            }
        }
예제 #2
0
        public IEnumerator DestroyItemCoroutine()
        {
            UnHighlight();
            SetShaderOutline(Color.red);

            ItemDrop dropItem = GetComponent <ItemDrop>();

            if (dropItem != null)
            {
                for (int i = 0; i < dropItem.ChildItemDragList.Count; ++i)
                {
                    StartCoroutine(dropItem.ChildItemDragList[i].GetComponent <Item>().DestroyItemCoroutine());
                }
            }

            yield return(new WaitForSeconds(.4f));

            RemoveUniqueTickRecursive(this);
            Destroy(GetComponent <ItemDrag>().TargetTransform.gameObject);
            Destroy(gameObject);

            //TODO use Resources.UnloadAsset and find all assets to do this faster
            Resources.UnloadUnusedAssets();
            System.GC.Collect();
        }
예제 #3
0
        public void CallDelegateItemRaycast(Item item, System.Action <Item> action)
        {
            action(item);
            ItemDrop itemDrop = item.GetComponent <ItemDrop>();

            if (itemDrop != null)
            {
                for (int i = 0; i < itemDrop.ChildItemDragList.Count; ++i)
                {
                    CallDelegateItemRaycast(itemDrop.ChildItemDragList[i].GetComponent <Item>(), action);
                }
            }
        }
        public void TranslateTargetPositionRotationRecursive(Vector3 deltaPosition, Vector3 deltaDirection)
        {
            TargetTransform.Translate(deltaPosition, Space.World);
            TargetTransform.forward = TargetTransform.forward + deltaDirection;
            ItemDrop dropItemMod = GetComponent <ItemDrop>();

            if (dropItemMod != null)
            {
                for (int i = 0; i < dropItemMod.ChildItemDragList.Count; ++i)
                {
                    dropItemMod.ChildItemDragList[i].TranslateTargetPositionRotationRecursive(deltaPosition, deltaDirection);
                }
            }
        }
예제 #5
0
        public void SetLayerRecursive(int layer)
        {
            for (int i = 0; i < ColliderGameObjectArray.Length; i++)
            {
                ColliderGameObjectArray[i].layer = layer;
            }
            ItemDrop dropItem = GetComponent <ItemDrop>();

            if (dropItem != null)
            {
                for (int i = 0; i < dropItem.ChildItemDragList.Count; i++)
                {
                    dropItem.ChildItemDragList[i].GetComponent <Item>().SetLayerRecursive(layer);
                }
            }
        }
예제 #6
0
        private void OnPointerUpInstantiate(PointerEventData data)
        {
                        #if LOG
            Debug.Log("OnPointerUpAttachedHighlighted " + this.name);
                        #endif

            VisualizationUI plannerUI            = FindObjectOfType <VisualizationUI>();
            Item            instantiatedItem     = plannerUI.InstantiateSelectedItem(data);
            ItemDrag        instantiatedItemDrag = instantiatedItem.GetComponent <ItemDrag>();
            ItemDrop        itemDrop             = GetComponent <ItemDrop>();
            if (itemDrop != null)
            {
                instantiatedItemDrag.ThisEnteredDropItem = itemDrop;
                instantiatedItemDrag.ParentItemDrop      = itemDrop;

                ItemSnap itemSnap = instantiatedItemDrag.NearestItemSnap(data);
                instantiatedItemDrag.ParentItemSnap = itemSnap;
                Ray ray = itemSnap.Snap(instantiatedItem, data);
                instantiatedItemDrag.SetTargetPositionRotation(ray.origin, ray.direction);
                //set to outline and normal to get rid of quirk where instantied shader isn't immediately properly lit
                instantiatedItem.SetShaderOutline(_itemSettings.InstantiateOutlineColor);
                instantiatedItem.SetShaderNormal();
                instantiatedItem.State = ItemState.NoInstantiate;

                //TODO this should always be able to attach, why are we checking?
                if (itemDrop.CanAttach(instantiatedItem.TagArray))
                {
                    SetShaderOutline(_itemSettings.InstantiateOutlineColor);
                }
                else
                {
                    SetShaderNormal();
                    State = ItemState.NoInstantiate;
                }
            }
            ItemColor itemColor = GetComponent <ItemColor>();
            if (itemColor != null)
            {
                Item item = GetComponent <Item>();
                item.SetBlendMaterial(instantiatedItem.MaterialArray[0].mainTexture);
                SetShaderNormal();
                State = ItemState.NoInstantiate;
                StartCoroutine(instantiatedItem.DestroyItemCoroutine());
            }
        }
        private void SwitchAttachedToDragging(PointerEventData data)
        {
            AccessoryRendererState = false;
            ParentItemDrop         = null;
            Item item = GetComponent <Item>();

            item.ResetColliderSize();
            item.AddToHoldList();
            item.State = ItemState.Dragging;

            //This ensure that the item is still hovering over the item_Drop it was attached to
            //otherwise it disattaches it, this is done because OnPointerExit will only get called on
            //the item_Drop if the mouse pointer actuall exits it's collider, which may not always occur
            if (data.pointerCurrentRaycast.gameObject == null ||
                (data.pointerCurrentRaycast.gameObject != null && ThisEnteredDropItem != null &&
                 data.pointerCurrentRaycast.gameObject.transform.parent.gameObject != ThisEnteredDropItem.gameObject))
            {
                ThisEnteredDropItem = null;
            }
        }
예제 #8
0
        private void RemoveUniqueTickRecursive(Item item)
        {
            Root.UniqueTickDictionary.Remove(item.UniqueTick);
            ItemDrop item_Drop = item.GetComponent <ItemDrop>();

            if (item_Drop != null)
            {
                for (int i = 0; i < item_Drop.ItemSnapArray.Length; ++i)
                {
                    Root.UniqueTickDictionary.Remove(item_Drop.ItemSnapArray[i].UniqueTick);
                }
            }
            ItemDrop itemDrop = item.GetComponent <ItemDrop>();           //TODO WHY IS THIS TWICE??

            if (itemDrop != null)
            {
                for (int i = 0; i < itemDrop.ChildItemDragList.Count; ++i)
                {
                    RemoveUniqueTickRecursive(itemDrop.ChildItemDragList[i].GetComponent <Item>());
                }
            }
        }
예제 #9
0
        private int CallDelegateTagFilterItemRaycast(Item item, System.Func <Item, bool> filterAction, System.Action <Item> trueAction, System.Action <Item> falseAction)
        {
            int trueCount = 0;

            if (filterAction(item))
            {
                trueAction(item);
                trueCount = 1;
            }
            else if (falseAction != null)
            {
                falseAction(item);
            }
            ItemDrop itemDrop = item.GetComponent <ItemDrop>();

            if (itemDrop != null)
            {
                for (int i = 0; i < itemDrop.ChildItemDragList.Count; ++i)
                {
                    trueCount += CallDelegateTagFilterItemRaycast(itemDrop.ChildItemDragList[i].GetComponent <Item>(), filterAction, trueAction, falseAction);
                }
            }
            return(trueCount);
        }
예제 #10
0
        private void SwitchAttachedToDragging(PointerEventData data)
        {
            AccessoryRendererState = false;
            ParentItemDrop = null;
            Item item = GetComponent<Item>();
            item.ResetColliderSize();
            item.AddToHoldList();
            item.State = ItemState.Dragging;

            //This ensure that the item is still hovering over the item_Drop it was attached to
            //otherwise it disattaches it, this is done because OnPointerExit will only get called on
            //the item_Drop if the mouse pointer actuall exits it's collider, which may not always occur
            if (data.pointerCurrentRaycast.gameObject == null ||
               (data.pointerCurrentRaycast.gameObject != null && ThisEnteredDropItem != null &&
               data.pointerCurrentRaycast.gameObject.transform.parent.gameObject != ThisEnteredDropItem.gameObject))
            {
                ThisEnteredDropItem = null;
            }
        }