zoukankan      html  css  js  c++  java
  • unity3d与web网页通信

    总结一下:

    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;

    unity3D初入1 javaScript 和 C  互相调用 - 博者 - 记忆空间public class test2: MonoBehaviour {

        void OnGUI()
    unity3D初入1 javaScript 和 C  互相调用 - 博者 - 记忆空间    {
            if(GUI.Button(new Rect(25,70,100,30), "CS Call JS"))
    unity3D初入1 javaScript 和 C  互相调用 - 博者 - 记忆空间        {
                test1 c = (test1)gameObject.GetComponent("test1");
                c.testPrint();
            }
        }

        void PrintTest()
    unity3D初入1 javaScript 和 C  互相调用 - 博者 - 记忆空间    {
            print("JS Call CS");
        }
    }



    function OnGUI()
    unity3D初入1 javaScript 和 C  互相调用 - 博者 - 记忆空间{    
        if(GUI.Button(Rect(25,25,100,30),"JS Call CS" ))
    unity3D初入1 javaScript 和 C  互相调用 - 博者 - 记忆空间    {
            var c = gameObject.GetComponent("test2");
            c.PrintTest();
        }
    }

    function testPrint()
    unity3D初入1 javaScript 和 C  互相调用 - 博者 - 记忆空间{
        print("CS Call JS");
    }
     
  • 相关阅读:
    Y2K Accounting Bug(POJ 2586)
    Power of Cryptography(POJ 2109 math )
    codeforces C. Valera and Tubes
    codeforces C. Devu and Partitioning of the Array
    codeforces C. Ryouko's Memory Note
    codeforces C. k-Tree
    codeforces C. Prime Swaps
    codeforces C. Xor-tree
    codeforces B. Prison Transfer
    codeforces C. Sereja and Swaps
  • 原文地址:https://www.cnblogs.com/fx2008/p/5165569.html
Copyright © 2011-2022 走看看