/// <summary> /// 更新View 和 ViewModel的脚本 /// </summary> /// <param name="go"></param> /// <param name="components"></param> /// <param name="rule"></param> public static void UpdateScripts(GameObject go, List <ComponentItem> components, GenCodeRule rule) { rule.onGenerated = (viewScript) => { if (viewScript is PanelBase) { var viewScriptPath = AssetDatabase.GetAssetPath(viewScript); //!!!ViewModelScript需要放置到ViewScript下 var vmScriptTempPath = viewScriptPath.Replace(".cs", "_ViewModel.cs"); var viewModelScript = AssetDatabase.LoadAssetAtPath <MonoScript>(vmScriptTempPath); var viewModel = (viewScript as PanelBase).ViewModel; if (viewModelScript != null) { GenCodeUtil.UpdateViewModelScript(viewModelScript, components); } else { var vscript = MonoScript.FromMonoBehaviour(viewScript as PanelBase); string scriptPath = null; if (vscript.name == go.name) { scriptPath = AssetDatabase.GetAssetPath(vscript).Replace(".cs", "_ViewModel.cs"); } else { scriptPath = AssetDatabase.GetAssetPath(go).Replace(".prefab", "_ViewModel.cs"); } CreateNewViewModelScript(go.name + "_ViewModel", scriptPath, components); } } }; GenCodeUtil.CreateViewScript(go, components, rule); }
/// <summary> /// 更新View 和 ViewModel的脚本 /// </summary> /// <param name="go"></param> /// <param name="components"></param> /// <param name="rule"></param> public static void UpdateScripts(GameObject go, List <ComponentItem> components, GenCodeRule rule) { rule.onGenerated = (viewScript) => { if (viewScript is PanelBase) { var viewModel = (viewScript as PanelBase).ViewModel; if (viewModel) { GenCodeUtil.UpdateViewModelScript(viewModel, components); } } }; GenCodeUtil.CreateViewScript(go, components, rule); }
/// <summary> /// 更新View 和 ViewModel的脚本 /// </summary> /// <param name="go"></param> /// <param name="components"></param> /// <param name="rule"></param> public static void UpdateScripts(GameObject go, List <ComponentItem> components, GenCodeRule rule) { rule.onGenerated = (viewScript) => { if (viewScript is PanelBase) { var viewModel = (viewScript as PanelBase).ViewModel; if (viewModel is Binding.ViewModel && viewModel.GetType() != typeof(Binding.ViewModel)) { GenCodeUtil.UpdateViewModelScript(viewModel as Binding.ViewModel, components); } else if (viewModel is Binding.ViewModelContainer) { GenCodeUtil.UpdateViewModelScript((viewModel as Binding.ViewModelContainer).instence, components); } } }; GenCodeUtil.CreateViewScript(go, components, rule); }