[Unity3d] Homemade unityforandroid qr code scan plugin

Source: Internet
Author: User

A week or so finally the two-dimensional code generation and scanning function to achieve, and finally can ease the breath, from the beginning of the doubts why the different scan the client why sweep out the effect of different? Universal scanner scan out is a download apk, home-made scanner scan out is the desired effective information, and then analyze the fact that the two-dimensional code is simply a record of a simple message, is usually a URL, and then their own in the URL above the fuss! Learned the demand and then began to do two-dimensional code generation, with the open source framework QRCode, and then parse zxing, are standing on the shoulders of predecessors continue to do, I did not delve into the deep aspects of the two-dimensional code of Things, Probably just know that the build is based on a two-dimensional bool array and then draw a square picture of the pixel point parameter, where three corners and the middle piece is not containing information of the three corners is three small rectangle, is to locate the position, there is a square area in the middle there is no information to place the logo, compared to everyone is also more clear, Have seen, now the restaurant, the subway basically have sweeping sweep of the logo, hehe, two-dimensional code has become a universal propaganda means! Then I received this task after the analysis of the problem to solve the problem, from the generation of a two-dimensional code image, to batch generation to batch Generation page, and each page to be nested with the corresponding QR code, and then to learn Android, because there was no way to touch the Java direction of things, Then a simple two-day look at Android, Android Development has a general understanding and understanding, and then to learn Android and unity of the interaction, and then to make Android plug-ins and other processes, as of tonight finally will feature implementation, there is nothing to solve the problem, as long as the hands, Brain, everything is ok!

Next I share the production process, about the generation of QR code I wrote a tutorial, the results were also criticized, said. NET programmer on your level ... For this netizen, I am indeed very ashamed, my level is limited, write the content is indeed more superficial, can not meet you seek advanced technology of the discernment, but I write out is to more than the vast number of beginners, hope to give them a little getting started help! I want to say that someone outside, do not think that they are too bad to look at the novice or not your high level of people, perhaps he will be more powerful technology than you! In a word, perhaps to Daniel, this two-dimensional code generation and analysis is very simple, but I still insist on down, one is also on their own this week more time a summary, second or the previous sentence, hope and the vast number of beginners to learn and progress together, Exchange!

QR code generation and interaction you can see the article I wrote before: QR code generates http://blog.csdn.net/dingxiaowei2013/article/details/22925709,Unity and Android interaction/HTTP/ blog.csdn.net/dingxiaowei2013/article/details/24485937. On top of that, then implement the function!

More exciting content please follow my Weibo http://weibo.com/dingxiaowei2013 reprint please specify the Source: http://blog.csdn.net/dingxiaowei2013/article/details/24677795

:


the effect after the phone scan:




Description: Here is the unity interface called Android Java method to jump Android development activity view, and then in Android Java method calls unity back to the Unity interface.

Source CodeUnity:
Using unityengine;using System.collections;public class Newbehaviourscript:monobehaviour {    private Androidjavaobject activity;    private string result= "http://blog.csdn.net/dingxiaowei2013";  Result is used to receive the return value of the QR code    void Start ()    {        Androidjavaclass JC = new Androidjavaclass (" Com.unity3d.player.UnityPlayer ");        Activity = JC. Getstatic<androidjavaobject> ("currentactivity");    }    void Ongui ()    {        //click on the scan code to call the Android method        if (GUI. button (new Rect (SCREEN.WIDTH/2-50, 20, 100, 50), "hit Sweep Code"))        {            activity. Call ("Show");        }        Gui. Label (New Rect (SCREEN.WIDTH/2), result);    }    This is the method called by Android    void GetString (String str)    {        result = str;    }}

Android:
Package Com.example.qr_codescan;import Android.content.intent;import Android.os.bundle;import Android.widget.imageview;import Android.widget.textview;import Com.unity3d.player.unityplayer;import Com.unity3d.player.unityplayeractivity;public class Mainactivity extends Unityplayeractivity {private final static int Scannin_grequest_code = 1;/** * Show scan results */private TextView mtextview;/** * Show scanned picture */private ImageView Mimageview; @Overri deprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);//setcontentview ( R.layout.activity_main);//mtextview = (TextView) Findviewbyid (R.id.result); Mimageview = (ImageView) Findviewbyid (r.id.qrcode_bitmap),//////click the button to jump to the QR code scanning interface, here is Startactivityforresult jump/// /After the scan has been transferred to the interface//button Mbutton = (Button) Findviewbyid (R.id.button1);//mbutton.setonclicklistener (New Onclicklistener () {////@Override//public void OnClick (View v) {//intent Intent = new Intent ();//intent.setclass (Mainactivity.this, Mipcaactivitycapture.class);//intent.sEtflags (Intent.flag_activity_clear_top);//startactivityforresult (Intent, Scannin_grequest_code);//}//});} public void Show () {Intent Intent = new Intent (); Intent.setclass (Mainactivity.this, Mipcaactivitycapture.class); Intent.setflags (Intent.flag_activity_clear_top); Startactivityforresult (Intent, scannin_grequest_code);} @Override protected void Onactivityresult (int requestcode, int resultcode, Intent data) {Super.onactivityresult        (Requestcode, ResultCode, data); Switch (requestcode) {case Scannin_grequest_code:if (ResultCode = = RESULT_OK) {Bundle bundle = Data.getextras ();// Displays the contents of the scan//mtextview.settext (bundle.getstring ("result"));//Display//mimageview.setimagebitmap ((BITMAP) Data.getparcelableextra ("bitmap")); Unityplayer.unitysendmessage ("Cube", "GetString", bundle.getstring ("result"));    break;} }}

Export plugins:then I exported to plug-in, before a sweep code plugin is Easycodescanner, and then my future network called Aladdin, I also named a sweep code of the Android plugin, for Aladdincodescanner, In the future may continue to complete the addition of iOS Scan code function, perfect this plug-in, I am also deeply easycodescanner the torture decided to self-reliance! Before very hard to find a sweep code plug-in Easycodescanner, the results found that there will be errors and the key is not to achieve the Android scan code function, the Android part of the method has not been implemented, so also contributed to my own writing plugin idea, today, a relaxed! Time is not early, feel too late to the body a little unbearable, the body is the capital, tomorrow will continue to repair the project! Good night!


[Unity3d] Homemade unityforandroid qr code scan plugin

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.