Esempio n. 1
0
 private void setPositionAtPointOnTopHit(RaycastHit topHit, ObjectManipulator selectedManipulator)
 {
     selectedManipulator.SetParent(Container);
     selectedManipulator.SetPosition(topHit.point);
     if (topHit.transform.gameObject.layer == LayerMask.NameToLayer("TerrainBarrier"))
     {
         selectedManipulator.AlignWith(topHit.normal, topHit.transform);
     }
 }
Esempio n. 2
0
        private void PositionDragItemForStacking(RaycastHit topHit, ObjectManipulator selectedManipulator, CollidableObject selectedCollidableObject, CollidableObject hitCollidableObject, Vector3 localAlignment)
        {
            List <CollidableObject> list = new List <CollidableObject>();

            CollidableObject[] componentsInChildren = hitCollidableObject.gameObject.GetComponentsInChildren <CollidableObject>();
            foreach (CollidableObject collidableObject in componentsInChildren)
            {
                if (collidableObject != selectedCollidableObject && !collidableObject.transform.IsChildOf(selectedCollidableObject.transform))
                {
                    list.Add(collidableObject);
                }
            }
            CollidableObject collidableObject2 = null;
            Vector3          vector            = Vector3.zero;

            for (int j = 0; j < list.Count; j++)
            {
                CollidableObject collidableObject3 = list[j];
                Vector3          a               = collidableObject3.transform.InverseTransformPoint(topHit.point);
                Vector3          vector2         = Vector3.Scale(a, Vector3.one - localAlignment);
                Vector3          localBoundsSize = collidableObject3.GetLocalBoundsSize();
                Vector3          vector3         = Vector3.Scale(localBoundsSize, localAlignment);
                vector3.x = Mathf.Abs(vector3.x);
                vector3.y = Mathf.Abs(vector3.y);
                vector3.z = Mathf.Abs(vector3.z);
                vector    = collidableObject3.transform.TransformPoint(vector3 + vector2);
                if (j == list.Count - 1)
                {
                    collidableObject2 = collidableObject3;
                    break;
                }
                bool flag = true;
                for (int k = j + 1; k < list.Count; k++)
                {
                    Bounds bounds = new Bounds(vector, selectedCollidableObject.GetBounds().size);
                    CollisionRuleResult collisionRule = GetCollisionRule(list[k]);
                    if (collisionRule == CollisionRuleResult.Intersect || collisionRule == CollisionRuleResult.NotAllowed)
                    {
                        flag = true;
                        break;
                    }
                    if (list[k].GetBounds().Intersects(bounds))
                    {
                        flag = false;
                        break;
                    }
                }
                if (flag)
                {
                    collidableObject2 = collidableObject3;
                    break;
                }
            }
            if (collidableObject2 != null)
            {
                selectedManipulator.SetPosition(vector);
                ManipulatableObject componentInParent = collidableObject2.GetComponentInParent <ManipulatableObject>();
                if (componentInParent != null)
                {
                    selectedManipulator.SetParent(componentInParent.transform);
                }
                else
                {
                    selectedManipulator.SetParent(Container);
                }
                selectedManipulator.AlignWith(collidableObject2.transform.TransformDirection(localAlignment), collidableObject2.transform);
            }
        }