//挂载脚本 public void MountScript() { if (GConfigure.selectTransform == null) { return; } if (EditorApplication.isCompiling) { EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.editorCompiling, GConfigure.ok); return; } var name = GConfigure.MainFileName; //一定要添加命名空间 var scriptType = GGlobalFun.GetAssembly().GetType(GConfigureDefine.namespaceStr + "." + name); if (scriptType == null) { EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.notCreate, GConfigure.ok); return; } var root = GConfigure.selectTransform.gameObject; var target = root.GetComponent(scriptType); if (target == null) { target = root.AddComponent(scriptType); return; } EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.hasMount, GConfigure.ok); }
public void BindingUI() { if (GConfigure.selectTransform == null) { return; } if (EditorApplication.isCompiling) { EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.editorCompiling, GConfigure.ok); return; } if (GConfigure.selectTransform.GetComponent(GConfigure.MainFileName) == null) { EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.noMountScript, GConfigure.ok); return; } var assembly = GGlobalFun.GetAssembly(); var type = assembly.GetType(GConfigureDefine.namespaceStr + "." + GConfigure.MainFileName); if (type == null) { EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.notCreate, GConfigure.ok); return; } var root = GConfigure.selectTransform; var target = root.GetComponent(type); var so = AssetDatabase.LoadAssetAtPath <GScriptInfo>(GConfigure.InfoPath); if (so == null) { return; } var infos = so.GetFieldInfos(GConfigure.MainFileName); if (infos == null) { EditorUtility.DisplayDialog(GConfigure.msgTitle, GConfigure.plugCreate, GConfigure.ok); return; } foreach (var info in infos) { if (string.IsNullOrEmpty(info.mainAttrInfo.name)) { continue; } BindAttributeByInfo(type, root, target, info, info.mainAttrInfo); foreach (var subInfo in info.subField) { if (string.IsNullOrEmpty(subInfo.name)) { continue; } BindAttributeByInfo(type, root, target, info, subInfo); } } }