zoukankan      html  css  js  c++  java
  • unity3d与web交互的方法

    通过web,url传入数值的方法:
    代码:
    var version : int = 1;

    function CheckVersion ()
    {
        var update_url = "http://mysite.com/myGame/version.txt";
        update_post = WWW(update_url);
        yield update_post; //等待数据传递
        if(update_post.error)
        {
            print("URL输入错误: " + update_post.error);
        }
        else
        {
            var latestVersion : int;
            //取得传入的值
            latestVersion = int.Parse(update_post.data);
            if (latestVersion > version)
            {
                //你的代码写在下面
            }
        }
    }


    unity3d输出数据的方式如下,采用Application.ExternalCall,该方法只适合在web3d环境下使用。
    该方法支持基本类型的传递和数组传递,任何类型都会转换成字符串类型使用。
    例子代码://不待参数的调用函数 MyFunction1
    Application.ExternalCall ("MyFunction1");

    //调用函数MyFunction2,传递一个字符串
    Application.ExternalCall ("MyFunction2", "Hello from Unity!");

    //调用函数MyFunction3,传递混合参数
    Application.ExternalCall ("MyFunction3", "one", 2, 3.0);

    在web中使用的函数,接受参数的能力。

  • 相关阅读:
    100篇论文
    Tengine vs openresty
    Dottrace跟踪代码执行时间
    Linux Server
    Linux+Apache+Mysql+Php
    linux+nginx+mysql+php
    tshark命令行的使用(转)
    tcpdump VS tshark用法(转)
    Lua语言在Wireshark中使用(转)
    doc-remote-debugging.html
  • 原文地址:https://www.cnblogs.com/yanghaihao/p/2805036.html
Copyright © 2011-2022 走看看