コード例 #1
0
        public void UpdateAxis(Part part, Space space, bool compoundTargetSelected)
        {
            if (part == null)
            {
                Hide();
                return;
            }

            bool isRootPart = (part.parent == null);

            if (visible && space == axisSpace && compoundTargetSelected == axisCompoundTargetSelected && part.transform.position == transform.position &&
                (isRootPart || part.parent.transform.rotation == transform.rotation))
            {
                return;
            }

            bool isTargetActive = PartUtil.IsTargetActive(part, compoundTargetSelected);

            transform.position         = PartUtil.GetPosition(part, Space.World, isTargetActive);
            transform.rotation         = isRootPart ? part.transform.rotation : part.parent.transform.rotation;
            axisSpace                  = space;
            axisCompoundTargetSelected = compoundTargetSelected;
            Vector3[] directions = new Vector3[] { transform.right, transform.up, transform.forward };

            for (int index = 0; index < axis.Length; index++)
            {
                LineRenderer lineRenderer = axis[index].GetComponent <LineRenderer>();
                Vector3[]    axisBounds   = (axisSpace == Space.World || isRootPart) ? GetWorldSpaceAxisBounds(transform.position, index) : GetSelfSpaceAxisBounds(transform.position, directions[index]);
                lineRenderer.SetPosition(0, axisBounds[0]);
                lineRenderer.SetPosition(1, axisBounds[1]);
            }
        }
コード例 #2
0
        private string SetPosition(int vectorIndex, string value)
        {
            Vector3 newPosition = GetWorldPositionToBeSet(vectorIndex, value);
            Vector3 oldPosition = PartUtil.GetPosition(part, Space.World, compoundTargetSelected);
            Bounds  partBounds;

            if (PartUtil.IsTargetActive(part, compoundTargetSelected))
            {
                partBounds = FindChildGameObjectByName(part.gameObject, "obj_targetCollider").GetComponent <Collider>().bounds;
            }
            else
            {
                partBounds = part.collider.bounds;
            }

            if (!AreBoundsOutOfHangarBounds(partBounds))
            {
                Vector3 boundsOffset = partBounds.center - oldPosition;

                partBounds.center = newPosition + boundsOffset;
                if (AreBoundsOutOfHangarBounds(partBounds))
                {
                    return(value);
                }
            }
            if (newPosition == oldPosition)
            {
                return(value);
            }

            if (part.isCompund)
            {
                CompoundPartTransform.SetWorldPosition((CompoundPart)part, newPosition, compoundTargetSelected);
            }
            else
            {
                PartTransform.SetWorldPosition(part, newPosition);
            }

            return(value);
        }