private void OnEnable() { m_Target = (ComponentAutoBindTool)target; m_BindDatas = serializedObject.FindProperty("BindDatas"); m_BindComs = serializedObject.FindProperty("m_BindComs"); m_HelperTypeNames = GetTypeNames(typeof(IAutoBindRuleHelper), s_AssemblyNames); string[] paths = AssetDatabase.FindAssets("t:AutoBindGlobalSetting"); if (paths.Length == 0) { Debug.LogError("不存在AutoBindGlobalSetting"); return; } if (paths.Length > 1) { Debug.LogError("AutoBindGlobalSetting数量大于1"); return; } string path = AssetDatabase.GUIDToAssetPath(paths[0]); m_Setting = AssetDatabase.LoadAssetAtPath <AutoBindGlobalSetting>(path); m_Namespace = serializedObject.FindProperty("m_Namespace"); m_ClassName = serializedObject.FindProperty("m_ClassName"); m_CodePath = serializedObject.FindProperty("m_CodePath"); m_Namespace.stringValue = string.IsNullOrEmpty(m_Namespace.stringValue) ? m_Setting.Namespace : m_Namespace.stringValue; m_ClassName.stringValue = string.IsNullOrEmpty(m_ClassName.stringValue) ? m_Target.gameObject.name : m_ClassName.stringValue; m_CodePath.stringValue = string.IsNullOrEmpty(m_CodePath.stringValue) ? m_Setting.CodePath : m_CodePath.stringValue; serializedObject.ApplyModifiedProperties(); }
private static void CreateAutoBindGlobalSetting() { string[] paths = AssetDatabase.FindAssets("t:AutoBindGlobalSetting"); if (paths.Length >= 1) { string path = AssetDatabase.GUIDToAssetPath(paths[0]); EditorUtility.DisplayDialog("警告", "已存在AutoBindGlobalSetting,路径" + path, "确认"); return; } AutoBindGlobalSetting setting = CreateInstance <AutoBindGlobalSetting>(); AssetDatabase.CreateAsset(setting, "Assets/AutoBindGlobalSetting.asset"); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }