예제 #1
0
        void SwapWith(Slot _slot, bool readOnlySource, bool readOnlyTarget)
        {
            if (_slot == null)
            {
                // call a virtual function on the container that can eg spawn the item into the world
                if (slot.container != null)
                {
                    slot.container.ThrowAway(this);
                }

                // dispose if we're throwing the item away, no slot was under the mouse
                if (!readOnlySource)
                {
                    SetObject(null);
                }
            }
            else
            {
                // swap the two valid slot items around
                Draggable other = _slot.item;
                if (other)
                {
                    UnityEngine.Object o = obj;
                    if (!readOnlyTarget)
                    {
                        other.SetObject(o);
                        if (o != null && other.slot != null)
                        {
                            other.slot.onSlot.Invoke();
                        }
                    }
                }
            }
        }
예제 #2
0
        // create a Slot (or use the optional supplied one) and populate it with the given object
        protected Slot MakeSlot(UnityEngine.Object obj, Slot preMade = null)
        {
            GameObject go   = null;
            Slot       slot = preMade;

            if (slot != null)
            {
                // use the existing one and get its GameObject
                go = slot.gameObject;
            }
            else
            {
                // make a child slot
                go   = Instantiate(slotPrefab.gameObject, transform);
                slot = go.GetComponent <Slot>();
            }

            // make an item object inside it as a child
            GameObject goi  = Instantiate(itemPrefab.gameObject, slot.GetSlot());
            Draggable  item = goi.GetComponent <Draggable>();

            item.SetObject(obj);

            // set up all required pointers
            slot.item      = item;
            slot.container = this;
            item.slot      = slot;

            return(slot);
        }