Esempio n. 1
0
 void m_DragObject_OnOwnerChange(DragObject arg1, DragHolder arg2)
 {
     if (arg1.Owner != null)
     {
         m_DragObject_OnSorted(arg1, arg1.Index);
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Sets the owner of the object.
        /// </summary>
        public void SetOwner(DragHolder inOwner, bool inbForce = false)
        {
            // We don't need to do anything
            // if this is our owner already
            if (Owner == inOwner)
            {
                return;
            }

            DragHolder oldOwner = Owner;

            if (Owner != null)
            {
                Owner.RemoveObject(this, inbForce);
                Assert.True(Index == -1, "DragObject was able to be removed.");
            }

            Owner = inOwner;

            if (Owner != null)
            {
                Owner.AddObject(this, inbForce);
                Assert.True(Index >= 0, "DragObject was able to be added.");
            }

            if (OnOwnerChange != null)
            {
                OnOwnerChange(this, oldOwner);
            }
        }
Esempio n. 3
0
 void m_DragObject_OnOwnerChange(DragObject arg1, DragHolder arg2)
 {
     if (arg1.Owner != null)
     {
         LastValidHolder = arg1.Owner;
     }
 }
Esempio n. 4
0
 public void OnPointerUp(PointerEventData eventData)
 {
     if (m_DragObject.IsDragging)
     {
         DragHolder holder = FindHolder(eventData);
         m_DragObject.Controller.EndDrag(holder);
     }
 }
Esempio n. 5
0
        private void OnHolderRemoved(DragHolder inHolder, DragObject inObject)
        {
            ExpressionPiece piece = inObject.GetComponent <ExpressionPiece>();

            if (Expression[PieceIndex] == piece)
            {
                Expression[PieceIndex] = null;
            }
        }
Esempio n. 6
0
 public void SetHolder(DragHolder inHolder)
 {
     Holder = inHolder;
     m_DragObject.SetOwner(Holder, true);
     if (Holder.HasSeats)
     {
         Transform targetPosition = m_DragObject.Owner.GetSeat(m_DragObject);
         m_DragObject.transform.position = targetPosition.position;
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Attempts to finish a drag at the given drag space position.
        /// </summary>
        public void EndDrag(DragHolder inHolder)
        {
            if (DraggingObject != null)
            {
                DragEndState endState;
                DragObject   dragObject = DraggingObject;
                DraggingObject = null;

                if (inHolder == null)
                {
                    endState = DragEndState.Empty;
                }
                else
                {
                    if (inHolder.AllowAddObject(dragObject))
                    {
                        dragObject.SetOwner(inHolder);
                        endState = DragEndState.ValidZone;
                    }
                    else
                    {
                        LastValidSeat lastSeat      = dragObject.GetComponent <LastValidSeat>();
                        bool          bValidSwap    = lastSeat != null && lastSeat.LastValidHolder != null;
                        DragObject    swappedObject = null;
                        if (bValidSwap)
                        {
                            bValidSwap = inHolder.AllowSwapObject(dragObject, out swappedObject);
                        }
                        if (bValidSwap)
                        {
                            bValidSwap = lastSeat.LastValidHolder.AllowAddObject(swappedObject);
                        }

                        if (bValidSwap)
                        {
                            swappedObject.SetOwner(lastSeat.LastValidHolder);
                            dragObject.SetOwner(inHolder);
                            endState = DragEndState.ValidZone;
                        }
                        else
                        {
                            endState = DragEndState.InvalidZone;
                        }
                    }
                }

                dragObject.DraggingStops(endState);

                if (OnDragEnd != null)
                {
                    OnDragEnd(dragObject, endState);
                }
            }
        }
Esempio n. 8
0
        private void SpawnChickens()
        {
            using (PooledList <DragHolder> chickenNests = PooledList <DragHolder> .Create())
            {
                int maxChickens = Level.Chickens.Length;
                if (!Level.FixedOperator)
                {
                    maxChickens += 2;
                }
                for (int i = 0; i < maxChickens; ++i)
                {
                    float offset = i - ((maxChickens - 1) / 2.0f);

                    // Spawn the nest
                    DragHolder chickenNest = ((GameObject)Instantiate(ChickenNestPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <DragHolder>();
                    chickenNest.transform.SetParent(ChickenRoot, false);
                    chickenNests.Add(chickenNest);
                    SlotFinder.AddSlot(chickenNest);

                    if (i < Level.Chickens.Length)
                    {
                        // Spawn the chicken
                        ExpressionChicken chicken = ((GameObject)Instantiate(ValueChickenPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <ExpressionChicken>();
                        chicken.transform.SetParent(ChickenRoot, false);
                        chicken.GetComponent <StartingSeat>().SetHolder(chickenNest);
                        chicken.SetValue(Level.Chickens[i]);
                        chicken.SlotFinder = SlotFinder;
                    }
                    else
                    {
                        OperatorType operatorType = i == Level.Chickens.Length ? OperatorType.Add : OperatorType.Subtract;

                        // Spawn the operator chicken
                        ExpressionChicken chicken = ((GameObject)Instantiate(OperatorChickenPrefab, new Vector3(offset * ChickenSpacing, 0, 0), Quaternion.identity)).GetComponent <ExpressionChicken>();
                        chicken.transform.SetParent(ChickenRoot, false);
                        chicken.GetComponent <StartingSeat>().SetHolder(chickenNest);
                        chicken.SetOperator(operatorType);
                        chicken.SlotFinder = SlotFinder;
                    }
                }

                foreach (var nest in chickenNests)
                {
                    nest.transform.SetAsFirstSibling();
                }
            }
        }
Esempio n. 9
0
        void m_Holder_OnObjectAdded(DragHolder arg1, DragObject arg2)
        {
            NumberRoot.FindChild("Seat" + (arg2.Index + 1).ToStringLookup()).GetComponent <Animator>().SetTrigger("count");

            if (arg1.Count == arg1.MaxAllowed)
            {
                Win();
            }
            else
            {
                float percentComplete = arg1.Count / (float)arg1.MaxAllowed;
                foreach (var chicken in m_Objects)
                {
                    chicken.GetComponent <NestChicken>().SetPanicProgress(percentComplete);
                }
            }
        }
Esempio n. 10
0
        public DragHolder FindNearestSlot(DragObject inObject)
        {
            DragHolder nearest = null;
            float nearestSqrDistance = 0;
            for(int i = 0; i < m_Slots.Count; ++i)
            {
                DragHolder holder = m_Slots[i];
                if (holder.Count < holder.MaxAllowed)
                {
                    float sqrDistance = (holder.transform.position - inObject.transform.position).sqrMagnitude;
                    if (nearest == null || sqrDistance < nearestSqrDistance)
                    {
                        nearest = holder;
                        nearestSqrDistance = sqrDistance;
                    }
                }
            }

            return nearest;
        }
Esempio n. 11
0
        private void OnHolderAdded(DragHolder inHolder, DragObject inObject)
        {
            ExpressionPiece piece = inObject.GetComponent <ExpressionPiece>();

            Expression[PieceIndex] = piece;
        }
Esempio n. 12
0
 public void AddSlot(DragHolder inSlot)
 {
     m_Slots.Add(inSlot);
 }