总结一下:

  1. Unity3D 中的 C# 和 JavaScript 脚本之间是可以互相访问并交互的,但是要求这些被访问和操作的 C# 和 JavaScript 组件必须放在名为 Standard Assets 或者 Plugins 目录下,这样保证被访问和操作的组件是第一时间被编译的,那么在这两个目录之外的其它脚本就可以随意使用它们了,同时呢,我们不要被 MonoDevelop 的一些表现给唬住;
  2. Blur 组件不生效的原因在于 Shader 资源没有被打包到执行程序中,而并不是其它别的原因,所以打蛇要打七寸就是这个道理。

Application.ExternalCall 外部调用

static function ExternalCall (functionName : string, params args : object[]) : void

Description描述

Calls a function in the containing web page (Web Player only).

调用一个包含在网页中的函数(只用于Web Player)。

This will call JavaScript function functionName in the web page that contains the web player, passing given arguments to it. Supported argument types are the primitive types (string, int, float, char) and arrays of them. Any other objects are converted to string (using ToString method) and passed as strings.

调用包含在网页中名为functionNameJavaScript函数,并传递给定的参数。支持原始的数据类型(string, int, float, char)和这些类型的数字。如何其他的对象被转化为字符串(使用ToString方法)并作为字符串传递。

The function is called non-blocking, i.e. ExternalCall immediately returns without waiting for the function that was called to complete.

这个函数调用时不会被阻塞,即ExternalCall立即返回的功能而不必等待被完成。

The number of passed arguments can be varying:

传递的参数数量是可变的。

// Calls MyFunction1 in web page with no arguments
// 调用网页上的MyFunction1并不使用参数。
Application.ExternalCall ("MyFunction1"); // Calls MyFunction2 in web page with a string
//调用网页上的MyFunction2并使用字符串参数。
Application.ExternalCall ("MyFunction2", "Hello from Unity!"); // Calls MyFunction3 in web page with several arguments of different types
//调用网页上的MyFunction3并使用几个不同类型的参数。
Application.ExternalCall ("MyFunction3", "one", 2, 3.0);

The functions to be called are just declared in the HTML page using standard syntax, for example:
被调用的在HTML中的函数只需要使用标准的语法即可,例如:

<script language="JavaScript" type="text/javascript">
<!--
// Using the above call from Unity, this will receive
// 使用来自Unity的调用,这将接受
// "Hello from Unity!" as the argument.
// "Hello from Unity!" 做为参数
function MyFunction2( arg )
{
alert( arg );
}
-->
</script>

Application.ExternalEval 外部运行

static function ExternalEval (script : string) : void

Description描述

Evaluates script snippet in the containing web page (Web Player only).

调用包含在网页中的片段脚本函数(只用于Web Player)。

This will execute JavaScript snippet script in the web page that contains the web player.

这将执行包含在网页中JavaScript片段script

// Navigates to the previous page
//返回前一页
Application.ExternalEval ("history.back()");
--------------------------------------------------------------

unity3D初入1 javaScript 和 C# 互相调用

using UnityEngine;
using System.Collections;

public class test2: MonoBehaviour {

    void OnGUI()
    {
        if(GUI.Button(new Rect(25,70,100,30), "CS Call JS"))
        {
            test1 c = (test1)gameObject.GetComponent("test1");
            c.testPrint();
        }
    }

    void PrintTest()
    {
        print("JS Call CS");
    }
}

function OnGUI()
{    
    if(GUI.Button(Rect(25,25,100,30),"JS Call CS" ))
    {
        var c = gameObject.GetComponent("test2");
        c.PrintTest();
    }
}

function testPrint()
{
    print("CS Call JS");
}

 

unity3d与web网页通信的更多相关文章

  1. Unity3d嵌入web网页

    应用场景 程序中的界面风格 UI内容等相关内容需要很容易方便的跟新替换,不使用unity传统的热加载方式,也不想使用和H5等做混合APP的时候, 就用嵌入web来实现. 假如我想替换某个背景图,一般来 ...

  2. 【Python之路】特别篇--微信Web网页版通信的全过程分析

    文章所使用Python版本为py3.5 1.微信服务器返回一个会话ID 微信Web版本不使用用户名和密码直接登录,而是采用二维码登录,所以服务器需要首先分配一个唯一的会话ID,用来标识当前的一次登录. ...

  3. TI IPNC Web网页之流程分析

    流程 Appro IPNC使用的web服务器是boa. 请仔细理解下面这段话. boa这个web服务器是GUI界面和IPNC应用程序之间的通信的桥梁.它的责任是从web GUI中接收HTTP请求,并且 ...

  4. [转]浏览器如何和Web服务器通信

    http://hi.baidu.com/ywqme/item/b5297014b2e58f4e6826bb74 概述 普通网民打开网页,访问网站,并不需要了解所谓HTTP协议.作为软件工程师,了解一下 ...

  5. 【Electron】Electron开发入门(三):main process和web page 通信

    一.main process 和 web page 通信 electron框架主进程(Main Process)与嵌入的网页(web page,也就是renderer process)之间的通信 Ma ...

  6. WebSocket实现web即时通信(后端nodejs实现)

    WebSocket实现web即时通信 一.首先看一下,HTTP.ajax轮询.long poll和WebSocket的区别: 1.HTTP 协议(短连接):一个 Request 一个 Response ...

  7. 利用XMLHttpRequest(XHR)对象实现与web服务器通信

    XMLHttpRequest对象:XMLHttpRequest是一个JS对象,页面利用它与web服务器通信.XHR对象的基本思想是让JS代码自己发送请求,以便随时获取数据,这种请求是异步的,也就是说请 ...

  8. web网页中使用vlc插件播放相机rtsp流视频

    可参考: 使用vlc播放器做rtsp服务器 使用vlc播放器播放rtsp视频 使用vlc进行二次开发做自己的播放器 vlc功能还是很强大的,有很多的现成的二次开发接口,不需配置太多即可轻松做客户端播放 ...

  9. WEB网页插件 如何实现 选择上传图片路径 【高级问题】

    发表于 2010-10-22 12:11 | |只看楼主       按键精灵程序里面的WEB网页插件 如何实现 选择上传图片路径 我想在上传图片的选框设置图片路径为 C:\fakepath\001. ...

随机推荐

  1. ios之快速枚举

    for(UIView * subView in self.view.subviews) { if([subView isKindOfClass:[XYZSeniorQueryView class]]) ...

  2. Xcode工程文件打不开:cannot be opened because the project file cannot be parsed

    svn更新代码后,打开xcode工程文件,会出现  xxx..xcodeproj  cannot be opened because the project file cannot be parsed ...

  3. spring-boot:run启动时,指定spring.profiles.active

    Maven启动指定Profile通过-P,如mvn spring-boot:run -Ptest,但这是Maven的Profile. 如果要指定spring-boot的spring.profiles. ...

  4. 哥谭第一季/全集Gotham迅雷下载

    哥谭市 第一季 Gotham (2014)本季看点:<哥谭镇>将由丹尼·加农掌镜,布鲁诺·海勒执笔剧本.电视剧集<哥谭>可以说<蝙蝠侠>的前传,剧集描述的是DC漫画 ...

  5. Android之多种Bitmap效果

    1. 将图片变为圆角 2. 获取缩略图图片 3. LOMO特效 4. 旧时光特效 5. 暖意特效 6. 根据饱和度.色相.亮度调整图片 7. 添加图片外边框 8. 添加内边框 9. 创建一个缩放的图片 ...

  6. 低版本系统兼容的ActionBar(二)ActionProvider+分离式ActionBar+分离式的ActionMode

           这篇文章主要讲的是在低版本兼容的ActionBar中实现自定义的ActionProvider,ShareActionProvider的使用方法,如何实现分离式ActionBar,外加在分 ...

  7. 在Android中实现图片的裁剪

        本实例的功能是将用户选择的图片裁剪后放入ImagView,布局文件是个Button和ImageView.为了图片的正常显示,我们在裁剪后先将裁剪好的图片先存放到SD卡中,这样就能在以后开启应用 ...

  8. 轻松看懂Java字节码

    java字节码 计算机只认识0和1.这意味着任何语言编写的程序最终都需要经过编译器编译成机器码才能被计算机执行.所以,我们所编写的程序在不同的平台上运行前都要经过重新编译才能被执行. 而Java刚诞生 ...

  9. caffe 生成检测框并绘图

    Step 1 使用训练好的模型检测图片: build/examples/ssd/ssd_detect.bin models/VGGNet/VOC0712/SSD_300x300/deploy.prot ...

  10. [转]Linux awk 命令 说明

    From : http://blog.csdn.net/tianlesoftware/article/details/6278273 一.  AWK 说明 awk是一种编程语言,用于在linux/un ...