コード例 #1
0
    private Vector3 GetNewPosition(Vector3 refPosition, Vector3 oldPosition, TargetAxes axes)
    {
        Vector3 newPosition;

        switch (axes)
        {
            case TargetAxes.x:
                newPosition = new Vector3(refPosition.x, oldPosition.y, oldPosition.z);
                break;
            case TargetAxes.y:
                newPosition = new Vector3(oldPosition.x, refPosition.y, oldPosition.z);
                break;
            case TargetAxes.z:
                newPosition = new Vector3(oldPosition.x, oldPosition.y, refPosition.z);
                break;
            default:
                newPosition = oldPosition;
                break;
        }

        return newPosition;
    }
コード例 #2
0
    private Vector3 GetPositionFrom(AlignmentTypes type, TargetAxes axes, Vector3 oldPosition, IEnumerable<Transform> possibleReferences)
    {
        switch (type)
        {
            case AlignmentTypes.Origin:
                return GetNewPosition(oldPosition, axes);

            case AlignmentTypes.FirstSelected:
                var first = possibleReferences.First().position;
                return GetNewPosition(first, oldPosition, axes);

            case AlignmentTypes.LastSelected:
                var last = possibleReferences.Last().position;
                return GetNewPosition(last, oldPosition, axes);

            case AlignmentTypes.CenterOfMass:

                var sum = possibleReferences.Select(t => t.position).Aggregate((t_A, t_B) => t_A + t_B);
                var count = possibleReferences.Count();
                var avg = new Vector3(sum.x / count, sum.y / count, sum.z / count);
                return avg;

            default:
                return oldPosition;
        }
    }