unity3d教程 虚拟现实
unity3d 虚拟现实懂得的人会知道这到底是什么,但是不懂的人就会非常的困惑了。现在小编就来帮助众多对于unity3d 虚拟现实有疑惑的人士更为清楚的来学习unity3d 虚拟现实,让大家知道unity3d 虚拟现实到底是什么。
public class MyModelBinder:IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
return "获取的值并返回";
}
}
[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]string Temp1,[ModelBinder(typeof(MyModelBinder))]string Temp2)
{
return Content(Temp1+temp2);
}
//[ModelBinder(typeof(MyModelBinder))]
public interface IValueProvider
{
bool ContainsPrefix(string prefix);
ValueProviderResult GetValue(string key);
}
<h2>Index</h2>
<form id="form0" action="../Home/Index" method="post">
<input type="text" name="Temp" />
<input type="submit" value="Submit"/>
</form>
//Action
[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]string Temp)
{
return Content(Temp);
}
//自定义ModelBinder
public class MyModelBinder:IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
IValueProvider valueProvider = bindingContext.ValueProvider;
string key = bindingContext.ModelName;
Type modelType = bindingContext.ModelType;
if (valueProvider.ContainsPrefix(key))
{
return valueProvider.GetValue(key).ConvertTo(modelType);
}
return null;
}
public class MyModelBinder:IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
return bindingContext.ValueProvider.GetValue(bindingContext.ModelName).ConvertTo(bindingContext.ModelType);
}
}
//自定义ValueProvider
public class MyValueProvider:IValueProvider
{
public bool ContainsPrefix(string prefix)
string strResult = HttpContext.Current.Request.Form[key];
//将原始值(数组),和值的字符串形式封装到一个ValueProviderResult中
ValueProviderResult vpr = new ValueProviderResult(objResult, strResult, System.Globalization.CultureInfo.CurrentCulture);
return vpr;
}
}
//自定义ValueProviderFactory
public class MyValueProviderFactory:ValueProviderFactory
{
public override IValueProvider GetValueProvider(ControllerContext controllerContext)
{
//此处构造了无参数的构造函数
return new MyValueProvider();
}
}
//在程序启动时将自定义的ValueProvider添加到程序中
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);
//因为在ValueProvider中,只要没有找到响应的值就会向下进行,所以我们将其他的ValueProvider移除
ValueProviderFactories.Factories.RemoveAt(4);
ValueProviderFactories.Factories.RemoveAt(3);
ValueProviderFactories.Factories.RemoveAt(2);
ValueProviderFactories.Factories.RemoveAt(1);
ValueProviderFactories.Factories.RemoveAt(0);
ValueProviderFactories.Factories.Insert(0,new MyValueProviderFactory());
//ValueProviderFactories.Factories.Add(new MyValueProviderFactory());
}
public class User
{
public int ID{set;get;}
public string Name{set;get;}
}
//前台
<form id="form0" action="../Home/Index" method="post">
<input type="text" name="use.Name" />
<input type="text" name="Name" />
<input type="submit" value="Submit"/>
</form>
//Action
[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]User use, [ModelBinder(typeof(MyModelBinder))]User uu)
{
return Content(use.Id.ToString()+use.Name);
}
//自定义的ModelBinder
public class MyModelBinder:IModelBinder
{
public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
return GetModel(bindingContext.ValueProvider, bindingContext.ModelType, bindingContext.ModelName);
}
public object GetModel(IValueProvider valueProvider, Type modelType, string modelName)
{
ModelMetadata modelMetadata = ModelMetadataProviders.Current.GetMetadataForType(() => null, modelType);
//如果绑定的类型是简单类型
if (!modelMetadata.IsComplexType)
{
return valueProvider.GetValue(modelName).ConvertTo(modelType);
}
object model = Activator.CreateInstance(modelType);
//如果是复杂类型
//前台表单标签的name属性的值有modelName的前缀
if (valueProvider.ContainsPrefix(modelName))
{
foreach (PropertyDescriptor porperty in TypeDescriptor.GetProperties(modelType))
{
string strkey = modelName + "." + porperty.Name;
if (HttpContext.Current.Request.Form.AllKeys.Contains<string>(strkey))
porperty.SetValue(model, valueProvider.GetValue(strkey).ConvertTo(porperty.PropertyType));
}
}
//不包含前缀,但是标签的name属性的值等于绑定类的属性的名字
else
{
foreach (PropertyDescriptor porperty in TypeDescriptor.GetProperties(modelType))
{
string strkey = porperty.Name;
if (HttpContext.Current.Request.Form.AllKeys.Contains<string>(strkey))
porperty.SetValue(model, valueProvider.GetValue(strkey).ConvertTo(porperty.PropertyType));
}
}
return model;
}
}
//自定义的ValueProvider
public class MyValueProvider:IValueProvider
{
private string[] allKeys;
public MyValueProvider(ControllerContext controllerContext)
{
allKeys = controllerContext.RequestContext.HttpContext.Request.Form.AllKeys;
以上的内容就是关于unity3d 虚拟现实的部分内容介绍了。大家要是对于unity3d 虚拟现实不了解那么就从这部分的知识信息开始了解吧。总结性的知识信息介绍,相信对于您快速的掌握unity3d 虚拟现实是一个很大的好处。
标签: unity3d unity3d教程 unity培训