/// <summary> /// Draws the parameters rows. /// </summary> /// <param name="unityInterface">The unity interface.</param> /// <param name="foldout">If set to <c>true</c> [foldout].</param> /// <param name="fullMethodDescriptionsList">The full method descriptions list.</param> /// <param name="serializedObjects">The serialized objects.</param> /// <param name="lockParametersRows">If set to <c>true</c> [lock parameters rows].</param> public void DrawParametersRows(IUnityInterfaceWrapper unityInterface, bool foldout, List <FullMethodDescription> fullMethodDescriptionsList, Dictionary <Type, ISerializedObjectWrapper> serializedObjects, bool lockParametersRows) { if (fullMethodDescriptionsList != null && fullMethodDescriptionsList.Count > 0 && foldout /* && !lockParametersRows*/) { bool theCallBeforeMethodsHaveParameters = false; foreach (FullMethodDescription fullMethodDescription in fullMethodDescriptionsList) { if (fullMethodDescription.Parameters.Parameters.Length > 0) { if (fullMethodDescription.MainMethod != null) { theCallBeforeMethodsHaveParameters = true; } if (theCallBeforeMethodsHaveParameters) { unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutBeginHorizontal(); float currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); string text = this.GetHeaderTextForFullMethodDescription(fullMethodDescription); unityInterface.EditorGUILayoutLabelFieldTruncate(text, currentViewWidth); unityInterface.EditorGUILayoutEndHorizontal(); } this.DrawParametersRows(unityInterface, foldout, fullMethodDescription, serializedObjects, lockParametersRows); } } unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); } }
/// <summary> /// Draws the given errors. /// </summary> /// <param name="errors">The errors.</param> /// <param name="unityInterface">The unity interface.</param> public void Errors(List <UnityTestBDDError> errors, IUnityInterfaceWrapper unityInterface) { BDDExtensionRunner bddExtensionRunner = this.component.gameObject.GetComponent <BDDExtensionRunner>(); string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.OpenComponentButtonTextureFileName); string errorTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.ErrorTextureFileName); foreach (UnityTestBDDError error in errors) { unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutEndHorizontal(); unityInterface.EditorGUILayoutBeginHorizontal(); float currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); Texture2D errorTexture = unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)); GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; unityInterface.EditorGUILayoutLabelField(errorTexture, errorTextureOptions); float labelWidth = currentViewWidth - 100; unityInterface.EditorGUILayoutLabelField(error.Message, labelWidth); Texture2D openComponentButtonTexture = unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)); GUILayoutOption[] options = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; if (unityInterface.GUILayoutButton(openComponentButtonTexture, EditorStyles.label, options)) { if (error.MethodMethodInfo != null) { SourcesManagement.OpenMethodSourceCode(error.MethodMethodInfo, unityInterface); } else if (error.Component != null) { SourcesManagement.OpenSourceCode(error.Component, unityInterface); } else { MethodInfo[] methods = this.component.GetType().GetMethods(); foreach (MethodInfo method in methods) { if (method.DeclaringType.Name.Equals(this.component.GetType().Name)) { SourcesManagement.OpenSourceCode(method, unityInterface); } } } } unityInterface.EditorGUILayoutEndHorizontal(); } }
/// <summary> /// Draws the given errors. /// </summary> /// <param name="errors">The errors.</param> /// <param name="unityInterface">The unity interface.</param> /// <param name="bddExtensionRunner">The BDD extension runner.</param> public void Errors(List <UnityTestBDDError> errors, IUnityInterfaceWrapper unityInterface, BDDExtensionRunner bddExtensionRunner) { string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.OpenComponentButtonTextureFileName); string errorTextureFullPath = Utilities.GetAssetFullPath(bddExtensionRunner, this.ErrorTextureFileName); foreach (UnityTestBDDError error in errors) { unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutEndHorizontal(); unityInterface.EditorGUILayoutBeginHorizontal(); float currentViewWidth = unityInterface.EditorGUIUtilityCurrentViewWidth(); if (error.ShowRedExclamationMark) { Texture2D errorTexture = unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)); GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; unityInterface.EditorGUILayoutLabelField(errorTexture, errorTextureOptions); } float labelWidth = currentViewWidth - 100; unityInterface.EditorGUILayoutLabelField(error.Message, labelWidth); Texture2D openComponentButtonTexture = unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)); GUILayoutOption[] options = new GUILayoutOption[2] { unityInterface.GUILayoutWidth(24), unityInterface.GUILayoutHeight(24) }; if (error.ShowButton) { if (unityInterface.GUILayoutButton(openComponentButtonTexture, EditorStyles.label, options)) { if (error.MethodMethodInfo != null) { SourcesManagement.OpenMethodSourceCode(error.MethodMethodInfo, unityInterface); } else if (error.Component != null) { SourcesManagement.OpenSourceCode(error.Component, unityInterface); } } } unityInterface.EditorGUILayoutEndHorizontal(); } }
/// <summary> /// Draws the options. /// </summary> /// <param name="businessLogicData">The business logic data.</param> /// <param name="isStaticScenario">If set to <c>true</c> [is static scenario].</param> /// <param name="script">The script.</param> /// <param name="unityInterface">The unity interface.</param> /// <param name="bddComponents">The BDD components.</param> private void DrawOptions(RunnerEditorBusinessLogicData businessLogicData, bool isStaticScenario, BDDExtensionRunner script, IUnityInterfaceWrapper unityInterface, Component[] bddComponents) { Rect rect = unityInterface.EditorGUILayoutGetControlRect(); businessLogicData.OptionsFoldout = unityInterface.EditorGUIFoldout(rect, businessLogicData.OptionsFoldout, "Options"); if (businessLogicData.OptionsFoldout) { if (!isStaticScenario) { this.ForceRebuildParametersButton(script, bddComponents); } unityInterface.EditorGUILayoutSeparator(); this.ChooseBetweenUpdateAndFixedUpdate(script, this.unityIntefaceWrapper); float width = unityInterface.EditorGUIUtilityCurrentViewWidth(); int numberOfSeparatorChars = (int)width / 7; string text = string.Empty.PadLeft(numberOfSeparatorChars, '_'); unityInterface.EditorGUILayoutLabelFieldTruncate(text, width); } }
public void Errors_Should_CallTheExpectedUnityEditorStatements_Given_OneErrorOnAComponent() { UnityTestBDDComponentBaseEditorBusinessLogicTestFirstDynamicComponent component = UnitTestUtility.CreateComponent <UnityTestBDDComponentBaseEditorBusinessLogicTestFirstDynamicComponent>(); BDDExtensionRunner runner = UnitTestUtility.CreateComponent <BDDExtensionRunner>(component.gameObject); BaseBDDComponentEditorBusinessLogic unityTestBDDComponentBaseEditorBusinessLogic = new BaseBDDComponentEditorBusinessLogic(component); string expectedMessage = "Message"; List <UnityTestBDDError> errors = new List <UnityTestBDDError>(); UnityTestBDDError error = new UnityTestBDDError(); error.Message = expectedMessage; error.Component = component; error.MethodMethodInfo = null; errors.Add(error); string errorTextureFullPath = Utilities.GetAssetFullPath(runner, unityTestBDDComponentBaseEditorBusinessLogic.ErrorTextureFileName); string openComponentButtonTextureFullPath = Utilities.GetAssetFullPath(runner, unityTestBDDComponentBaseEditorBusinessLogic.OpenComponentButtonTextureFileName); IUnityInterfaceWrapper unityInterface = Substitute.For <IUnityInterfaceWrapper>(); unityInterface.EditorGUIUtilityCurrentViewWidth().Returns(600f); float labelWidth = 500f; Texture2D inputTexture = new Texture2D(10, 10); unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)).Returns(inputTexture); Texture2D errorTexture = new Texture2D(10, 10); unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)).Returns(errorTexture); GUILayoutOption buttonWidth = GUILayout.Width(16); unityInterface.GUILayoutWidth(24).Returns(buttonWidth); GUILayoutOption buttonHeight = GUILayout.Height(16); unityInterface.GUILayoutHeight(24).Returns(buttonHeight); GUILayoutOption[] options = new GUILayoutOption[2]; options[0] = buttonWidth; options[1] = buttonHeight; unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, options).Returns(false); GUILayoutOption[] errorTextureOptions = new GUILayoutOption[2]; errorTextureOptions[0] = buttonWidth; errorTextureOptions[1] = buttonHeight; unityTestBDDComponentBaseEditorBusinessLogic.Errors(errors, unityInterface); Received.InOrder(() => { unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutSeparator(); unityInterface.EditorGUILayoutEndHorizontal(); unityInterface.EditorGUILayoutBeginHorizontal(); unityInterface.EditorGUIUtilityCurrentViewWidth(); unityInterface.AssetDatabaseLoadAssetAtPath(errorTextureFullPath, typeof(Texture2D)); unityInterface.GUILayoutWidth(24); unityInterface.GUILayoutHeight(24); unityInterface.EditorGUILayoutLabelField(errorTexture, Arg.Is <GUILayoutOption[]>(x => x.SequenceEqual(errorTextureOptions) == true)); unityInterface.EditorGUILayoutLabelField(expectedMessage, labelWidth); unityInterface.AssetDatabaseLoadAssetAtPath(openComponentButtonTextureFullPath, typeof(Texture2D)); unityInterface.GUILayoutWidth(24); unityInterface.GUILayoutHeight(24); unityInterface.GUILayoutButton(inputTexture, EditorStyles.label, Arg.Is <GUILayoutOption[]>(x => x.SequenceEqual(options) == true)); unityInterface.EditorGUILayoutEndHorizontal(); }); }