Created
October 14, 2018 02:22
-
-
Save SunXiaoShan/b1c26fd324093cb8e618e36f680e1f42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class EmojiNode: SCNNode { | |
var options: [String] | |
var index = 0 | |
init(with options: [String], width: CGFloat = 0.06, height: CGFloat = 0.06) { | |
self.options = options | |
super.init() | |
let plane = SCNPlane(width: width, height: height) | |
plane.firstMaterial?.diffuse.contents = (options.first ?? " ").image() | |
plane.firstMaterial?.isDoubleSided = true | |
geometry = plane | |
} | |
} | |
extension String { | |
func image() -> UIImage? { | |
let size = CGSize(width: 20, height: 22) | |
UIGraphicsBeginImageContextWithOptions(size, false, 0) | |
UIColor.clear.set() | |
let rect = CGRect(origin: .zero, size: size) | |
UIRectFill(CGRect(origin: .zero, size: size)) | |
(self as AnyObject).draw(in: rect, withAttributes: [.font: UIFont.systemFont(ofSize: 15)]) | |
let image = UIGraphicsGetImageFromCurrentImageContext() | |
UIGraphicsEndImageContext() | |
return image | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment