Unity3d 利用dll C#脚本反射

1、构建ClassLibrary工程,生成:ABTestImport.dll。将dll放到web项目目录下。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ABTest : MonoBehaviour 
{
	// Use this for initialization
	void Start () 
	{
            Debug.Log("Run to ABTest.");		
	}
}

2、将脚本挂到摄像机。

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Reflection;

public class Load : MonoBehaviour
{
    // Use this for initialization
    IEnumerator Start()
    {
        yield return StartCoroutine(StartLoad());
        LoadScript();
    }

    Assembly assembly = null;
    private IEnumerator StartLoad()
    {
        //string url = "file://" + Application.streamingAssetsPath + "/ABTestImport.dll";
        string url = "http://localhost:8080/examples/servlets/StreamingAssets/ABTestImport.dll";

        WWW www = new WWW(url);

        yield return www;

        if (www.error != null)
        {
            Debug.Log("www error = " + www.error);
            yield return null;
        }
        else
        {
            assembly = Assembly.Load(www.bytes);
        }
    }

    private void LoadScript()
    {
        Debug.Log("LoadScript");
        if (assembly != null)
        {
            Type t = assembly.GetType("ABTest");
            GameObject go = new GameObject("ABTest");
            go.AddComponent(t);
        }
    }
}

 

Mirror-BumpSpec.shader 实时镜面反射shader 可以配合法线贴图一起用 适用于平面物体 Mirror-AlphaBumpSpec.shader 实时镜面发射、透明材质,可以同时反射和透明效果,也可以配合法线贴图,适用于平面物体 Mirror-AlphaSpecSphere.shader 与上面材质相同,适用于球面物体,不能使用法线贴图 使用很简单,就几个参数,具体效果要慢慢调节,简单解说几个关键参数: Main Material Blend Level:主材质的混合浓度 Bump Rate:法线贴图强度 Reflection Rate 反射强度 Reflective Color 反射颜色 Reflective Distortion 反射图受法线影响强度 Transparency 同时透明、反射的材质,调节透明反射混合的比例 ,0是全反射 1是全透明 Distortion 反射、透明受法线影响的强度 另外每个shader都有个自动的贴图是不需要设置的,由脚本自动设置 Mirror脚本参数: Disable Pixel Lights 禁用Pixel Lights,对应unity摄像机的这个设置 Texture Size 反射贴图精度 缺省是256 如果觉得反射很模糊直接把这个加大就行了 即时生效 所以不要设太大了,1024足以应付绝大多数要求了。 Is Flat Mirror:如果是平面反射物体就勾上,球体点掉,材质也要选择相应的 Reflect Layer 反射的culling mask,可以屏蔽掉指定的层 shader和脚本都是参考unity的water效果,脚本基本就是water包里反射脚本的简化版 由于只是模拟,并不是真正的光线跟踪效果,所以折射效果并不准确,但是基本能满足观感。 注意:目前只适用于forward 渲染,Deferred下会有贴图倒置、光线暗淡的问题 尽量避免反射物体互相反射,消耗巨大而且效果不准确 实时反射本身也开销极大,尽量不要滥用
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值