你可以使用 .NET Framework 中的System.Drawing.Printing命名空间来实现打印功能
using System;
using System.Drawing.Printing;
public class Printer
{
private string _textToPrint;
public Printer(string text)
{
_textToPrint = text;
}
public void Print()
{
PrintDocument printDoc = new PrintDocument();
printDoc.PrintPage += new PrintPageEventHandler(PrintPage);
printDoc.Print();
}
private void PrintPage(object sender, PrintPageEventArgs e)
{
e.Graphics.DrawString(_textToPrint, new Font("Arial", 12), Brushes.Black, new PointF(100, 100));
}
}
在 Unity 中调用此类:
Printer printer =newPrinter("This is the text to print");
printer.Print();
方法未经过尝试,只存在理论上的可行性。