Esempio n. 1
0
        private void SetHandleByOperation(OperationEnum operation)
        {
            switch (operation)
            {
            case OperationEnum.None:
                ActiveHandle = null;
                break;

            case OperationEnum.Drag:
                foreach (GameObject obj in Interactibles)
                {
                    BoundingBoxHandle h = obj.GetComponent <BoundingBoxHandle>();
                    if (h.HandleType == BoundingBoxHandle.HandleTypeEnum.Drag)
                    {
                        ActiveHandle = h;
                        break;
                    }
                }
                break;

            default:
                //TODO link up other operations here
                break;
            }
        }
Esempio n. 2
0
 private void RefreshActiveHandles()
 {
     foreach (GameObject handleGo in Interactibles)
     {
         BoundingBoxHandle handle          = handleGo.GetComponent <BoundingBoxHandle>();
         OperationEnum     handleOperation = GetBoundingBoxOperationFromHandleType(handle.HandleType);
         handleGo.SetActive((handleOperation & permittedOperations) != 0);
     }
 }
Esempio n. 3
0
        private void TryToSetHandle(GameObject obj, Vector3 position, AFocuser newFocuser)
        {
            if (!acceptInput)
            {
                UnityEngine.Debug.Log("Not accepting input");
                return;
            }

            BoundingBoxHandle newHandle = obj.GetComponent <BoundingBoxHandle>();

            if (newHandle != null)
            {
                activeHandle    = newHandle;
                lastNavigatePos = position;
                ManipulatingNow = true;
                focuser         = newFocuser;
                focuser.LockFocus();
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Stores target under our transform helper and prepares for manipulation
        /// </summary>
        private void StartManipulating()
        {
            // Goes without saying
            if (!acceptInput)
            {
                return;
            }

            if (target == null)
            {
                return;
            }

            if (manipulatingNow)
            {
                return;
            }

            manipulatingNow = true;

            if (!Application.isPlaying)
            {
                return;
            }

            CreateTransforms();

            // Reset the transform helper to 1,1,1 / idenity
            transformHelper.localScale = Vector3.one;
            transformHelper.rotation   = Quaternion.identity;
            adjustedScaleTarget        = Vector3.one;
            smoothVelocity             = Vector3.zero;

            // Set up our transforms and gestures based on the operation we're performing
            OperationEnum operation = GetBoundingBoxOperationFromHandleType(ActiveHandle.HandleType);

            switch (operation)
            {
            case OperationEnum.ScaleUniform:
            case OperationEnum.ScaleX:
            case OperationEnum.ScaleY:
            case OperationEnum.ScaleZ:
                // If we're scaling, move the transform helper to the position OPPOSITE the scale handle
                // That way the object will grow in the right direction
                BoundingBoxHandle oppositeHandle = null;
                BoundingBoxHandle.HandleTypeEnum oppositeHandleType = BoundingBoxHandle.GetOpposingHandle(ActiveHandle.HandleType);
                foreach (GameObject bbhGo in Interactibles)
                {
                    BoundingBoxHandle bbh = bbhGo.GetComponent <BoundingBoxHandle>();
                    if (bbh != null && bbh.HandleType == oppositeHandleType)
                    {
                        oppositeHandle = bbh;
                        break;
                    }
                }
                if (oppositeHandle == null)
                {
                    UnityEngine.Debug.LogWarning("Couldn't find opposing handle for type " + ActiveHandle.HandleType);
                    transformHelper.position = transform.position;
                    targetStandIn.position   = target.transform.position;
                }
                else
                {
                    transformHelper.position = oppositeHandle.transform.position;
                    targetStandIn.position   = target.transform.position;
                }
                break;

            case OperationEnum.Drag:
                // If we're rotating or moving, move the transform helper to the center of the gizmo
                transformHelper.position = transform.position;
                targetStandIn.position   = target.transform.position;
                break;

            case OperationEnum.RotateX:
            case OperationEnum.RotateY:
            case OperationEnum.RotateZ:
            default:
                // Rotation
                // If we're rotating or moving, move the transform helper to the center of the gizmo
                transformHelper.position = transform.position;
                targetStandIn.position   = target.transform.position;
                break;
            }

            scaleOnStartManipulation = targetStandIn.localScale;

            if (target != null)
            {
                // Set our transforms to the target immediately
                targetStandIn.position   = target.transform.position;
                targetStandIn.rotation   = target.transform.rotation;
                targetStandIn.localScale = target.transform.lossyScale;
            }
        }