总结一下:

  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. 【CentOS】centos7 稳定使用版本,centos镜像的下载

    命令: cat /etc/redhat-release 下载地址: https://wiki.centos.org/Download 下载版本:

  2. IllegalStateException: Can not perform this action after onSaveInstanceState

    http://www.cnblogs.com/zgz345/archive/2013/03/04/2942553.html 今天使用Fragment的时候,出现了这个错误 IllegalStateEx ...

  3. Redis客户端集群

        1.Redis集群一般分为两类,即3.0版本后的服务端集群实现,3.0版本前的客户端集群实现,服务端集群即Redis Cluster(官方实现),采用slot槽的概念(分片,所有服务端redi ...

  4. WebRTC 基于GCC的拥塞控制(上)

    转自:http://blog.csdn.net/doitsjz/article/details/56481981 实时流媒体应用的最大特点是实时性,而延迟是实时性的最大敌人.从媒体收发端来讲,媒体数据 ...

  5. End2endIT

    "C:\Program Files\Java\jdk1.8.0_112\bin\java" -ea -Didea.test.cyclic.buffer.size=1048576 & ...

  6. 开源项目MultiChoiceAdapter详解(五)——可扩展的MultiChoiceBaseAdapter

    上次写到了开源项目MultiChoiceAdapter详解(四)——MultiChoiceBaseAdapter的使用,其实我们仍旧可以不使用ActionMode的,所以这里就写一个自己扩展的方法. ...

  7. [转]有关Apache alias的一点问题

    转自:http://www.thinkphp.cn/topic/11973.html Apache 的Alias 指令映射URL到文件系统的特定区域 一个简单的例子: Alias /mytest /w ...

  8. python模块uuid产生唯一id

    使用版本4:uuid4就可以了 UUID4缺点:糟糕的随机数发生器使得它更有可能发生碰撞,但是概率真的很小 UUID1缺点:暴露隐私 If all you want is a unique ID, y ...

  9. HTTP和HTTPS的区别(转)

    原文链接:HTTP和HTTPS的区别 HTTPS(Secure Hypertext Transfer Protocol)安全超文本传输协议 它是一个安全通信通道,它基于HTTP开发,用于在客户计算机和 ...

  10. 关掉Windows Firewall的PowerShell

    在Windows 8或Windows 2012 R2上, 使用下面的命令: Set-NetFirewallProfile -Profile Domain,Public,Private -Enabled ...