/// <summary> /// update all child inputviews to align right /// </summary> /// <param name="width"></param> public void UpdateAlignRight(float width) { if (Mathf.Approximately(this.Width, width)) { return; } this.Width = width; ConnectionInputView conView = ((InputView)LastChild).GetConnectionView(); if (conView != null && conView.ConnectionInputViewType == ConnectionInputViewType.Statement) { conView.Width = width - (LastChild.XY.x + conView.XY.x); } else { float startX = this.XY.x + width; for (int i = Childs.Count - 1; i >= 0; i--) { InputView inputView = Childs[i] as InputView; if (i < Childs.Count - 1) { startX -= BlockViewSettings.Get().ContentSpace.x; } startX -= inputView.Width; inputView.XY = new Vector2(startX, inputView.XY.y); } } }
protected internal override void OnXYUpdated() { if (InToolbox) { return; } mBlock.XY = XY; //update all connection's location foreach (var view in Childs) { if (view.Type == ViewType.Connection) { view.OnXYUpdated(); } else if (view.Type == ViewType.LineGroup) { LineGroupView groupView = view as LineGroupView; foreach (var inputView in groupView.Childs) { ConnectionInputView conInputView = ((InputView)inputView).GetConnectionView(); if (conInputView != null) { conInputView.OnXYUpdated(); } } } } }
/// <summary> /// Get the size for drawing background /// </summary> public Vector2 GetDrawSize() { //I know it is a little bit awkward here... //but to make it seem prettier...maybe refactor later Vector2 size = Size; ConnectionInputView conView = ((InputView)LastChild).GetConnectionView(); if (conView != null && !conView.IsSlot) { size.x -= conView.Width; } return(size); }
public static InputView BuildInputView(Input input, LineGroupView groupView, BlockView blockView) { GameObject inputPrefab; ConnectionInputViewType viewType; if (input.Type == Define.EConnection.NextStatement) { inputPrefab = BlockViewSettings.Get().PrefabInputStatement; viewType = ConnectionInputViewType.Statement; } else if (input.SourceBlock.InputList.Count > 1 && input.SourceBlock.GetInputsInline()) { inputPrefab = BlockViewSettings.Get().PrefabInputValueSlot; viewType = ConnectionInputViewType.ValueSlot; } else { inputPrefab = BlockViewSettings.Get().PrefabInputValue; viewType = ConnectionInputViewType.Value; } GameObject inputObj = GameObject.Instantiate(inputPrefab); inputObj.name = "Input_" + (!string.IsNullOrEmpty(input.Name) ? input.Name : ""); RectTransform inputTrans = inputObj.GetComponent <RectTransform>(); inputTrans.SetParent(groupView.transform, false); UniformRectTransform(inputTrans); Transform conInputTrans = inputTrans.GetChild(0); InputView inputView = AddViewComponent <InputView>(inputObj); inputView.AlignRight = input.Align == Define.EAlign.Right; // build child field views of this input view List <Field> fields = input.FieldRow; foreach (Field field in fields) { FieldView fieldView = BuildFieldView(field); inputView.AddChild(fieldView); RectTransform fieldTrans = fieldView.GetComponent <RectTransform>(); UniformRectTransform(fieldTrans); } if (input.Type == Define.EConnection.DummyInput) { //dummy input doesn't need to have a connection point GameObject.DestroyImmediate(conInputTrans.gameObject); } else { ConnectionInputView conInputView = AddViewComponent <ConnectionInputView>(conInputTrans.gameObject); conInputView.ConnectionType = input.Type; conInputView.ConnectionInputViewType = viewType; inputView.AddChild(conInputView); conInputView.BgImage.raycastTarget = false; if (viewType != ConnectionInputViewType.ValueSlot) { blockView.AddBgImage(conInputView.BgImage); } } return(inputView); }