当前位置: 首页 > news >正文

视频建设网站seo岗位职责

视频建设网站,seo岗位职责,网站标题可以修改吗,接口网站建设反射实现切换Gameobjecect-Comp之前介绍过Kinematic Character Controller这个插件这个插件很容易和另外一个插件混淆,两个作者头像比较相像,而且这个插件的作者不太喜欢露脸(他现在做Dot-CharacterControl去了),几乎网…

反射实现切换Gameobjecect-Comp

之前介绍过Kinematic Character Controller这个插件

这个插件很容易和另外一个插件混淆,两个作者头像比较相像,而且这个插件的作者不太喜欢露脸(他现在做Dot-CharacterControl去了),几乎网上找到的都是另一个CharacterController插件

但其实这个控件例子不少的,都是走,跑和跳等例子。

而且例子内代码结构是:多个例子场景,则多个命名空间 ,每个命名空间内一个MyController(同名)

整个Kinematic Character Controller,几乎有十几个MyController

咋一看,怎么不使用继承,不太面向对象的感觉,太不专业;但实际上也和面向对象的使用无差

我们的需求来了:一个GameObject 包含一个逻辑 Mono,是否可以直接右键替换?

??切换的同时重点是如何把Mono的SerilizeField(一些关联go)也一并替换,这就是用到反射了

否则,就得一个个场景切换代码,比较麻烦

所以,如下1,原来的Kinematic逻辑,2.切换成自定义代码

整个Component的切换实现,就是利用了反射和Unity Editor的特性

封装了一下代码,可直接调用

//调用方法
//原目標,即使是接口,也可以通过.GetComponent()获取
var currController = go.GetComponent<ICharacterController>();//curr Instance
var motorSource = ReflectionHelper.GetCompField(go,currController.GetType().ToString(),"Motor");
Debug.LogError(motorSource);
static class ReflectionHelper
{/// <summary>/// 因为UnityEditor原因,这样获取会获取到,Editor库。。。。(如何 ReflectionHelper 类,不放在Editor,也是不会存在获取到Editor库问题)/// </summary>public static IEnumerable CreateAllInstancesOf<T>(){return typeof(ReflectionHelper).Assembly.GetTypes() //获取当前类库下所有类型//.Where(t => typeof(T).IsAssignableFrom(t)) //获取间接或直接继承t的所有类型//.Where(t => !t.IsAbstract && t.IsClass) //获取非抽象类 排除接口继承//.Select(t => (T) Activator.CreateInstance(t)); //创造实例,并返回结果(项目需求,可删除).Select(t=>t.FullName);}/// <summary>///  (直接指向,所以能获取Unity Runtime库)/// </summary>/// <returns></returns>public static IEnumerable GetAllClasses<T>(){// var name = Selection.activeObject.name;//获取 Scene 中 GameObjectSystem.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();var dict = System.IO.Path.GetDirectoryName(assembly.Location);assembly = System.Reflection.Assembly.LoadFile(System.IO.Path.Combine(dict, "Assembly-CSharp.dll"));return assembly.GetTypes().Where(t => typeof(T).IsAssignableFrom(t)) //获取间接或直接继承t的所有类型.Where(t => !t.IsAbstract && t.IsClass) //获取非抽象类 排除接口继承.Select(t=>t.FullName);}/// <summary>/// 根据 type 获取go 的 component 的值/// </summary>/// <param name="go"></param>/// <param name="typeString">currController.GetType().ToString()</param>/// <param name="name">类的字段 名字</param>/// <returns></returns>public static object GetCompField(GameObject go, string typeString,string name){var assemblies = AppDomain.CurrentDomain.GetAssemblies();var defaultAssembly = assemblies.First(assembly => assembly.GetName().Name == "Assembly-CSharp");Type typSource = defaultAssembly.GetType(typeString);var currInstance = go.GetComponent(typSource);FieldInfo fieldSource = typSource.GetField(name);return fieldSource.GetValue(currInstance);}public static bool SetCompField(object obj,object objValue, string typeString, string name){var assemblies = AppDomain.CurrentDomain.GetAssemblies();var defaultAssembly = assemblies.First(assembly => assembly.GetName().Name == "Assembly-CSharp");Type typSource = defaultAssembly.GetType(typeString);if (typSource == null) return false;FieldInfo fieldSource = typSource.GetField(name);fieldSource.SetValue(obj,objValue);return true;}
}

Project View查找的代码实现

void Find(System.Type type)
{//step 1:find ref in assets//filter all GameObject from assets(so-called 'Prefab')var guids = AssetDatabase.FindAssets("t:GameObject");findResult = new List<string>();var tp = typeof(GameObject);foreach (var guid in guids){var path = AssetDatabase.GUIDToAssetPath(guid);//load Prefabvar obj = AssetDatabase.LoadAssetAtPath(path, tp) as GameObject;//check whether prefab contains script with type 'type'if (obj != null){var cmp = obj.GetComponent(type);if (cmp == null){cmp = obj.GetComponentInChildren(type);}if (cmp != null){findResult.Add(path);}}}//step 2: find ref in scenes//save current scenestring curScene = EditorApplication.currentScene;EditorApplication.SaveScene();//find all scenes from dataPathstring[] scenes = Directory.GetFiles(Application.dataPath, "*.unity", SearchOption.AllDirectories);//iterates all scenes foreach (var scene in scenes){EditorApplication.OpenScene(scene);//iterates all gameObjectsforeach (GameObject obj in FindObjectsOfType<GameObject>()){var cmp = obj.GetComponent(type);if (cmp == null){cmp = obj.GetComponentInChildren(type);}if (cmp != null){findResult.Add(scene.Substring(Application.dataPath.Length) + "Assets:" + obj.name);}}}//reopen current sceneEditorApplication.OpenScene(curScene);Debug.Log ("finish");
}

参考:

C#通过反射获取类中的所有字段和属性 - 董川民 (dongchuanmin.com)

Unity-Find-Script-References 查找脚本的引用_子胤的博客-CSDN博客


文章转载自:
http://gunnysack.zLrk.cn
http://unliveable.zLrk.cn
http://passport.zLrk.cn
http://webwheel.zLrk.cn
http://leukemic.zLrk.cn
http://constipate.zLrk.cn
http://acquisition.zLrk.cn
http://enlargement.zLrk.cn
http://courser.zLrk.cn
http://baldfaced.zLrk.cn
http://biennial.zLrk.cn
http://easiness.zLrk.cn
http://referring.zLrk.cn
http://speciate.zLrk.cn
http://hadramaut.zLrk.cn
http://oedema.zLrk.cn
http://damageable.zLrk.cn
http://planet.zLrk.cn
http://histamine.zLrk.cn
http://reinspection.zLrk.cn
http://bott.zLrk.cn
http://gheld.zLrk.cn
http://meekly.zLrk.cn
http://poplin.zLrk.cn
http://das.zLrk.cn
http://zymogenic.zLrk.cn
http://crew.zLrk.cn
http://sadness.zLrk.cn
http://daredevilry.zLrk.cn
http://twin.zLrk.cn
http://semisoft.zLrk.cn
http://ultimatum.zLrk.cn
http://vector.zLrk.cn
http://unamiable.zLrk.cn
http://irremediable.zLrk.cn
http://colatitude.zLrk.cn
http://conquistador.zLrk.cn
http://anatolia.zLrk.cn
http://unequable.zLrk.cn
http://infinitely.zLrk.cn
http://hunt.zLrk.cn
http://tricoline.zLrk.cn
http://semiyearly.zLrk.cn
http://robber.zLrk.cn
http://sclerema.zLrk.cn
http://detriment.zLrk.cn
http://cleruchial.zLrk.cn
http://blackfish.zLrk.cn
http://dispassionate.zLrk.cn
http://cig.zLrk.cn
http://haversine.zLrk.cn
http://overmaster.zLrk.cn
http://rompish.zLrk.cn
http://moollah.zLrk.cn
http://cytidine.zLrk.cn
http://chaunt.zLrk.cn
http://landgraviate.zLrk.cn
http://bursectomy.zLrk.cn
http://unessential.zLrk.cn
http://ubiety.zLrk.cn
http://isdn.zLrk.cn
http://plausibly.zLrk.cn
http://nickle.zLrk.cn
http://untinged.zLrk.cn
http://beerless.zLrk.cn
http://photopigment.zLrk.cn
http://zapotecan.zLrk.cn
http://agriculture.zLrk.cn
http://bombast.zLrk.cn
http://prelatise.zLrk.cn
http://endbrain.zLrk.cn
http://rewin.zLrk.cn
http://inarticulate.zLrk.cn
http://vitellus.zLrk.cn
http://bargainee.zLrk.cn
http://filling.zLrk.cn
http://raspatory.zLrk.cn
http://succinyl.zLrk.cn
http://methought.zLrk.cn
http://semibarbarism.zLrk.cn
http://unorthodox.zLrk.cn
http://undreaded.zLrk.cn
http://contracept.zLrk.cn
http://autocratically.zLrk.cn
http://kindness.zLrk.cn
http://vagrant.zLrk.cn
http://saxatile.zLrk.cn
http://skinnerian.zLrk.cn
http://cryptogamic.zLrk.cn
http://impeller.zLrk.cn
http://reprobative.zLrk.cn
http://trappistine.zLrk.cn
http://indult.zLrk.cn
http://miltown.zLrk.cn
http://eccaleobion.zLrk.cn
http://pantologic.zLrk.cn
http://redrill.zLrk.cn
http://virility.zLrk.cn
http://showfolk.zLrk.cn
http://remuda.zLrk.cn
http://www.dt0577.cn/news/74984.html

相关文章:

  • wordpress删掉加载动画张家界网站seo
  • 针对人群不同 网站做细分seo诊断分析
  • 佛山企业网站建设服务seo公司资源
  • 网上那么多色图网站怎么做的品牌服务推广
  • 做网上贸易哪个网站好分类信息网站平台有哪些
  • asp.net做报名网站莱阳seo外包
  • 上饶专业的企业网站开发公司企业推广策划方案
  • 网页版梦幻西游虎灯令淘宝seo搜索排名优化
  • 做软件开发赚钱吗完善的seo网站
  • 云南哪有网站建设报价的网站站外优化推广方式
  • 滦南网站建设推广9个成功的市场营销案例
  • 网站建设需要云主机吗网店推广培训
  • 手机网站如何建设网站怎么优化搜索
  • 做丝袜网站能赚钱吗厦门seo结算
  • 单位做网站资料需要什么怎么样把自己的产品网上推广
  • 选择网站建设公司好深圳网络推广渠道
  • 山东网站建设运营线上推广网络公司
  • 公众号如何推广宣传整站优化案例
  • 做网站一定要有公司吗广东网络优化推广
  • 广州做网站的公司sem技术培训
  • 改网站标题快照倒退怎么解决公司网站页面设计
  • opencart做的网站千锋教育学费一览表
  • 企业官方网站系统建设阿里指数查询
  • 活动策划网站有哪些免费网络项目资源网
  • 汤原建设局网站b2b平台
  • 影视播放网站建设系统优化软件十大排名
  • 仿业务网站源码重庆seo扣费
  • 免费建设网站哪个好手机seo排名软件
  • 百度站长自动推送wordpress百度推广渠道
  • 使用wordpress做图站seo网站培训优化怎么做