Beispiel #1
0
        private void PositionDragItem(RaycastHit topHit, TouchEquivalent touch)
        {
            if (this.BeforeDragPosition != null)
            {
                Cancelable cancelable = new Cancelable();
                this.BeforeDragPosition.InvokeSafe(touch.position, cancelable);
                if (cancelable.isCancelled())
                {
                    return;
                }
            }
            ObjectManipulator component  = CurrentlySelectedObject.GetComponent <ObjectManipulator>();
            CollidableObject  component2 = CurrentlySelectedObject.GetComponent <CollidableObject>();

            if (!(component != null))
            {
                return;
            }
            bool             flag = component.transform != Container;
            CollidableObject componentInParent = topHit.transform.gameObject.GetComponentInParent <CollidableObject>();

            if (componentInParent != null)
            {
                switch (GetCollisionRule(componentInParent))
                {
                case CollisionRuleResult.StackXNormal:
                    PositionDragItemForStacking(topHit, component, component2, componentInParent, Vector3.right);
                    break;

                case CollisionRuleResult.Stack:
                    PositionDragItemForStacking(topHit, component, component2, componentInParent, Vector3.up);
                    break;

                case CollisionRuleResult.NotAllowed:
                case CollisionRuleResult.Intersect:
                {
                    for (int i = 0; i < dragItemInputInteractionState.RaycastHits.Length; i++)
                    {
                        componentInParent = dragItemInputInteractionState.RaycastHits[i].transform.gameObject.GetComponentInParent <CollidableObject>();
                        if (componentInParent == null)
                        {
                            setPositionAtPointOnTopHit(dragItemInputInteractionState.RaycastHits[i], component);
                            break;
                        }
                        if (componentInParent.transform.IsChildOf(component2.transform))
                        {
                            continue;
                        }
                        switch (GetCollisionRule(componentInParent))
                        {
                        case CollisionRuleResult.Stack:
                            PositionDragItemForStacking(dragItemInputInteractionState.RaycastHits[i], component, component2, componentInParent, Vector3.up);
                            break;

                        case CollisionRuleResult.StackXNormal:
                            PositionDragItemForStacking(dragItemInputInteractionState.RaycastHits[i], component, component2, componentInParent, Vector3.right);
                            break;

                        default:
                            continue;
                        }
                        break;
                    }
                    break;
                }

                default:
                    setPositionAtPointOnTopHit(topHit, component);
                    break;
                }
            }
            else
            {
                setPositionAtPointOnTopHit(topHit, component);
            }
            if (NaturalDragFromTouchPosition && !flag)
            {
                Vector2 vector = Camera.main.WorldToScreenPoint(component.transform.position);
                dragItemInputInteractionState.TouchOffset = (touchOffset = vector - touch.position);
            }
        }