private float SpawnAllInputs(Vector2 pos, MethodButtonBehaviour parentBehaviour, UiMethodNameWithParameters method, Transform parent) { var overallHeight = 0f; foreach (var parameter in method.Parameters) { var height = this.SpawnInputsSingleParameter(pos, parameter, parentBehaviour, parent); overallHeight += height; pos.y -= height; } return(overallHeight); }
private float SpawnInputsSingleParameter(Vector2 pos, UiParameterWithType parameter, MethodButtonBehaviour parentBehaviour, Transform parent) { float overallHeight = 0; var height = this.SpawnOneLable( pos, parameter.Name + " " + this.ShortenPropTypes(parameter.Type.Name), parent, false, out GameObject _notused, false).Height; pos.y -= height; overallHeight += height; if (parameter.Type == typeof(Vector3)) { var inputField1 = this.SpawnOneInput(pos, parameter.Name, parent, "x: float"); pos.y -= this.inputY; var inputField2 = this.SpawnOneInput(pos, parameter.Name, parent, "y: float"); pos.y -= this.inputY; var inputField3 = this.SpawnOneInput(pos, parameter.Name, parent, "z: float"); parentBehaviour.RegisterNonColorParamater(parameter.Name, inputField1); parentBehaviour.RegisterNonColorParamater(parameter.Name, inputField2); parentBehaviour.RegisterNonColorParamater(parameter.Name, inputField3); overallHeight += 3 * this.inputY; } if (parameter.Type == typeof(Vector2)) { var inputField1 = this.SpawnOneInput(pos, parameter.Name, parent, "x: float"); pos.y -= this.inputY; var inputField2 = this.SpawnOneInput(pos, parameter.Name, parent, "y: float"); parentBehaviour.RegisterNonColorParamater(parameter.Name, inputField1); parentBehaviour.RegisterNonColorParamater(parameter.Name, inputField2); overallHeight += 2 * this.inputY; } if ( parameter.Type == typeof(string) || parameter.Type == typeof(float) || parameter.Type == typeof(decimal) || parameter.Type == typeof(int) || parameter.Type == typeof(short) || parameter.Type == typeof(long) || parameter.Type == typeof(char) ) { var inputField = this.SpawnOneInput(pos, parameter.Name, parent, parameter.Type.Name); parentBehaviour.RegisterNonColorParamater(parameter.Name, inputField); overallHeight += this.inputY; } if (parameter.Type == typeof(Color)) { var colorSelectionScript = this.SpawnOneColorButton(pos, parent); parentBehaviour.RegisterColorParam(parameter.Name, colorSelectionScript); overallHeight += this.inputY; } return(overallHeight); }
/// <summary> /// Creates the UI to visualise given mono's methods as buttons and their paramaters as inputs /// </summary> /// <param name="monoName">The name of the mono script</param> /// <param name="methods">Information abouth the methods in the script</param> /// <returns>The generated UI as well as meta data for it</returns> private CreateMonUIResult CreateScriptUI(string monoName, UiMethodNameWithParameters[] methods) { /// localGrandParent hold the whole UI /// Directly howds only the buttonLabel(the mono name) and the local parent /// the local parent holds everything else (method buttons and parameter inputs) /// clicking on the buttonLabel collapses the local parent GameObject localGrandParent = new GameObject(monoName + "GrandParent"); localGrandParent.transform.SetParent(this.parentTransform, false); localGrandParent.transform.position = this.parentTransform.position; GameObject localParent = new GameObject(monoName); localParent.transform.SetParent(localGrandParent.transform, false); localParent.transform.position = localGrandParent.transform.position; Transform localTransform = localParent.transform; float localHeight = 0f; ///assigning the label to the grandparent not the parent ActionUiLabelButtonWithHeight labelInfo = this.SpawnOneLable(new Vector2(this.marginX, localHeight), monoName, localGrandParent.transform, true, out GameObject intButtonLabel, true); LabelButtonMonoName lableButtonScript = labelInfo.labelButtonScript; localHeight -= labelInfo.Height; /// Collectiong all the method button behaviours so that we can extract /// all colorButton scripts from them. List <MethodButtonBehaviour> methodButtonBehs = new List <MethodButtonBehaviour>(); /// All others are assigned to the parent so we can deactivate them seperately. /// We are doing to buttons on the same time, putting them side by side for (int i = 0; i < methods.Length; i += 2) { /// If we have unevent mothod count, we place the last button individualy to the left if (i == methods.Length - 1) { UiMethodNameWithParameters method = methods[i]; Vector2 pos = new Vector2(marginX, localHeight); MethodButtonBehaviour beh = this.SpawnOneButton(pos, method.Name, monoName, localTransform); pos.y -= this.buttonY; float height = this.SpawnAllInputs(pos, beh, method, localTransform); localHeight -= (height + this.buttonY + this.marginY); methodButtonBehs.Add(beh); } /// Placing two buttons side by side. else { UiMethodNameWithParameters method1 = methods[i]; UiMethodNameWithParameters method2 = methods[i + 1]; Vector2 pos1 = new Vector2(marginX, localHeight); MethodButtonBehaviour beh1 = this.SpawnOneButton(pos1, method1.Name, monoName, localTransform); pos1.y -= this.buttonY; float height1 = this.SpawnAllInputs(pos1, beh1, method1, localTransform); Vector2 pos2 = new Vector2(marginX * 2 + this.buttonX, localHeight); MethodButtonBehaviour beh2 = this.SpawnOneButton(pos2, method2.Name, monoName, localTransform); pos2.y -= this.buttonY; float height2 = this.SpawnAllInputs(pos2, beh2, method2, localTransform); localHeight -= (Mathf.Max(height1, height2) + buttonY + marginY); methodButtonBehs.Add(beh1); methodButtonBehs.Add(beh2); } } ///Collecting all the color scripts so we can close Color Picker on colapse foreach (MethodButtonBehaviour methodScript in methodButtonBehs) { foreach (ParameterNameWithColorButtonScript colorButtonScript in methodScript.ColorParamaters) { lableButtonScript.ColorSelectionButtons.Add(colorButtonScript.colorScript); } } /// newly created item whould be activated later; localParent.SetActive(false); intButtonLabel.SetActive(false); var result = new CreateMonUIResult { ButtonLabel = intButtonLabel, CollapsedHeight = labelInfo.Height, FinalHeight = -localHeight, GrandParent = localGrandParent, LabelButtonScritp = labelInfo.labelButtonScript, Parent = localParent, }; return(result); }