/// <summary> /// Don call this every tick, update /// </summary> /// <returns></returns> sealed public override bool IsAttatchable() { FlowBlockConnector.ConnectorType expectedConnectorTypeFlag = FlowBlockConnector.ConnectorType.None; if (IsPreviousBlockEditorUnitAssignable == true && PreviousFlowBlockEditorUnit == null) { expectedConnectorTypeFlag = expectedConnectorTypeFlag | FlowBlockConnector.ConnectorType.DownBump; } if (IsNextBlockEditorUnitAssignable == true && NextFlowBlockEditorUnit == null) { expectedConnectorTypeFlag = expectedConnectorTypeFlag | FlowBlockConnector.ConnectorType.UpNotch; } FlowBlockConnector flowBlockConnector = this.GetTopFlowBlockConnector(transform.position, expectedConnectorTypeFlag); if (flowBlockConnector == null && this.NextFlowBlockEditorUnit != null) {//if Fail to find flowblockconnector //Find Top Block Connector at LowestDescendantBlock Postion FlowBlockEditorUnit lowestDescendantBlockUnit = this.LowestDescendantBlockUnit; flowBlockConnector = this.GetTopFlowBlockConnector(lowestDescendantBlockUnit.transform.position, FlowBlockConnector.ConnectorType.UpNotch); } if (flowBlockConnector == null || flowBlockConnector.OwnerFlowBlockEditorUnit == this || flowBlockConnector.OwnerBlockEditorUnit._BlockEditorUnitFlag.HasFlag(BlockEditorUnitFlag.IsAttachable) == false) { base.AttachableEditorElement = null; return(false); } else { if (flowBlockConnector._ConnectorType == FlowBlockConnector.ConnectorType.UpNotch) {//if hit connector is up notch type if (this.IsNextBlockEditorUnitAssignable) { base.AttachableEditorElement = flowBlockConnector; return(true); } else { base.AttachableEditorElement = null; return(false); } } else {//if hit connector is down bump type if (this.IsPreviousBlockEditorUnitAssignable) { base.AttachableEditorElement = flowBlockConnector; return(true); } else { base.AttachableEditorElement = null; return(false); } } } }
/// <summary> /// Gets the top flow block connector. /// </summary> /// <returns>The top flow block connector.</returns> /// <param name="worldPoint">World position.</param> /// <param name="exceptedUnitList">Excepted unit list.</param> /// <param name="expectedConnectorType">Expected connector type. if this value is 2 , UpNotch, DownBump is ok</param> private FlowBlockConnector GetTopFlowBlockConnector(Vector2 worldPoint, FlowBlockConnector.ConnectorType expectedConnectorTypeFlag) { return(UiUtility.GetTopBlockEditorElementWithWorldPoint <FlowBlockConnector>(worldPoint, FlowBlockConnector.FlowBlockConnectorTag, x => expectedConnectorTypeFlag.HasFlag(x._ConnectorType) == true)); }