总结一下:

  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. ORACLE的init.ora配置文件中参数详解

    db_name = "orcl"   一个数据库标识符,应与CREATE DATABASE 语句中指定的名称相对应. instance_name = orcl在多个例程使用相同服务 ...

  2. 《王者荣耀》技术总监复盘回炉历程:没跨过这三座大山,就是另一款MOBA霸占市场了

    如今已经大获市场成功的<王者荣耀>一直是业内各方关注的对象,而我们也知道这款产品在成为国民级游戏之前,也遇到过一段鲜有人知的调优期.也就是在2015年8月18号正式不删档测试版本推出之后, ...

  3. NSObject的hash方法

    NSObject的hash方法 说明 本示例仅仅演示一个对象什么时候执行hash方法. 细节 1. 必要的Model类,重载了hash方法用以反映Hash方法是否被调用了 2. 测试 // // Vi ...

  4. 一幅图秒懂LoadAverage(负载)

    转自:http://www.habadog.com/2015/02/27/what-is-load-average/ 一幅图秒懂LoadAverage(负载)   一.什么是Load Average? ...

  5. Material Designer的低版本兼容实现(四)—— ToolBar

       Toolbar其实是一个ActionBar的变体,大大扩展了Actionbar.我们可以像对待一个独立控件一样去使用ToolBar,可以将它放到屏幕的任何位置,不必拘泥于顶部,还可以将它改变高度 ...

  6. 用开源项目CropImage实现图片的裁剪(不推荐)

       之前介绍过一个截图的办法(http://www.cnblogs.com/tianzhijiexian/p/3900241.html),这里再分享个开源项目.它也是截图,但是效果不是很好,首先还是 ...

  7. MVC的Ajax异步请求

    @using (Ajax.BeginForm("GetTime","order",new AjaxOptions() { Confirm="你确认这么 ...

  8. CountDownLatch使用场景及分析

    JDk1.5提供了一个非常有用的包,Concurrent包,这个包主要用来操作一些并发操作,提供一些并发类,可以方便在项目当中傻瓜式应用. JDK1.5以前,使用并发操作,都是通过Thread,Run ...

  9. Error: Program type already present: android.arch.lifecycle.LifecycleRegistry$1

    com.firebaseui:firebase-ui-firestore:3.1.0 depends on android.arch.lifecycle:extensions:1.0.0-beta1. ...

  10. Set a Room Mailbox to Show Details of a Meeting in its Calendar – Office 365

    You may notice that meetings with a ‘Room’ mailbox will by default only show a “Busy” status. Many, ...