private void DebugBlockUnitFlowRecursive(FlowBlockEditorUnit flowBlockEditorUnit, ref StringBuilder stringBuilder)
    {
        if (flowBlockEditorUnit != null)
        {
            if (flowBlockEditorUnit.PreviousFlowBlockEditorUnit != null)
            {
                stringBuilder.Append(flowBlockEditorUnit.PreviousFlowBlockEditorUnit.name);
            }

            stringBuilder.Append("   ---   ");

            if (flowBlockEditorUnit != null)
            {
                stringBuilder.Append(flowBlockEditorUnit.name);
            }

            stringBuilder.Append("   ---   ");

            if (flowBlockEditorUnit.NextFlowBlockEditorUnit != null)
            {
                stringBuilder.Append(flowBlockEditorUnit.NextFlowBlockEditorUnit.name);
            }

            stringBuilder.Append("\n");

            this.DebugBlockUnitFlowRecursive(flowBlockEditorUnit.NextFlowBlockEditorUnit, ref stringBuilder);
        }
    }
    /// <summary>
    /// Creates the flow block mock up.
    /// </summary>
    /// <param name="flowBlockEditorUnit">Flow block editor unit.</param>
    /// <param name="siblingIndex">Sibling index.</param>
    public void CreateFlowBlockMockUp(FlowBlockEditorUnit flowBlockEditorUnit, int siblingIndex = 0)
    {
        if (flowBlockEditorUnit == null)
        {
            return;
        }

        BlockMockupHelper spawnedMockUp = PoolManager.SpawnObject(RobotSourceCodeEditorWindow.instance.BlockMockUpPrefab).GetComponent <BlockMockupHelper>();

        RobotSourceCodeEditorWindow.instance.AddToSpawnedBlockMockUp(spawnedMockUp);

        spawnedMockUp.CopyTargetBlock(flowBlockEditorUnit);

        Transform attachPointRectTransform = this.AttachPointRectTransform;


        spawnedMockUp._RectTransform.SetParent(attachPointRectTransform);
        spawnedMockUp._RectTransform.SetAsFirstSibling();
        spawnedMockUp._RectTransform.SetSiblingIndex(siblingIndex);

        spawnedMockUp._RectTransform.localScale = Vector3.one;
        //if copyBlockEditorUnit is FlowBlockEditorUnit
        //SetBlockMockUp nextblock of FlowBlockEditorUnit
        if (flowBlockEditorUnit.NextFlowBlockEditorUnit != null)
        {
            this.CreateFlowBlockMockUp(flowBlockEditorUnit.NextFlowBlockEditorUnit, siblingIndex + 1);
        }
    }
    /// <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);
                }
            }
        }
    }
    public void ShowIsAttachable(BlockEditorUnit attachedBlockEditorUnit = null)
    {
        FlowBlockEditorUnit flowBlockEditorUnit = attachedBlockEditorUnit as FlowBlockEditorUnit;

        if (flowBlockEditorUnit != null)
        {
            this.CreateFlowBlockMockUp(flowBlockEditorUnit);
            //If this FlowBlockConnector is UpNotch Type, MockUpHeight
            if (_ConnectorType == FlowBlockConnector.ConnectorType.UpNotch)
            {
                this.SetRectHeightScaling(flowBlockEditorUnit.DescendantBlockCount + 2);
            }
        }
        else
        {
            this.SetRectHeightScaling(1);
        }
    }
    public static void ConnectFlowBlockEditorUnit(FlowBlockEditorUnit parentBlock, FlowBlockEditorUnit newChildBlock)
    {
        if (parentBlock == null && newChildBlock != null)
        {
            //disconnect block with parentblock

            if (newChildBlock.PreviousFlowBlockEditorUnit != null)
            {
                newChildBlock.PreviousFlowBlockEditorUnit.NextFlowBlockEditorUnit = null;
                newChildBlock.PreviousFlowBlockEditorUnit = null;
            }

            newChildBlock.ParentBlockEditorWindow.SetBlockEditorUnitRootAtSourceCodeViewer(newChildBlock);
            return;
        }

        if (parentBlock != null && newChildBlock == null)
        {
            if (parentBlock.NextFlowBlockEditorUnit != null)
            {
                parentBlock.NextFlowBlockEditorUnit.PreviousFlowBlockEditorUnit = null;
                parentBlock.NextFlowBlockEditorUnit = null;
            }
            return;
        }

        if (parentBlock != null && newChildBlock != null)
        {
            if (parentBlock.IsNextBlockEditorUnitAssignable && newChildBlock.IsPreviousBlockEditorUnitAssignable)
            {
                parentBlock.NextFlowBlockEditorUnit       = newChildBlock;
                newChildBlock.PreviousFlowBlockEditorUnit = parentBlock;
                newChildBlock.transform.SetParent(parentBlock.NextBlockConnector.AttachPointRectTransform);
                newChildBlock._RectTransform.anchoredPosition = Vector2.zero;
            }
            else
            {
                parentBlock.NextFlowBlockEditorUnit       = null;
                newChildBlock.PreviousFlowBlockEditorUnit = null;
            }

            return;
        }
    }
    protected override void Awake()
    {
        base.Awake();

        gameObject.tag = FlowBlockConnectorTag;

        OwnerFlowBlockEditorUnit = GetComponentInParent <FlowBlockEditorUnit>();
        if (OwnerFlowBlockEditorUnit == null)
        {
            Debug.LogError("ParentBlockEditorUnit is null");
        }

        this.OriginalRectHeight = _RectTransform.sizeDelta.y;

        /*
         * this._RectTransform.anchorMax = _ConnectorType == FlowBlockConnector.ConnectorType.UpNotch ? Vector2.up : Vector2.zero;
         * this._RectTransform.anchorMin = _ConnectorType == FlowBlockConnector.ConnectorType.UpNotch ? Vector2.up : Vector2.zero;
         *
         * this.connectionPointRectTransform.anchorMax = _ConnectorType == FlowBlockConnector.ConnectorType.UpNotch ? Vector2.zero : Vector2.up;
         * this.connectionPointRectTransform.anchorMin = _ConnectorType == FlowBlockConnector.ConnectorType.UpNotch ? Vector2.zero : Vector2.up;
         */
    }
예제 #7
0
    /// <summary>
    /// Spawn Flow Block Recursivly
    /// Spawned Block create child block again,
    /// and spawned child block create child of block of that ..........
    /// </summary>
    /// <param name="flowBlock"></param>
    public FlowBlockEditorUnit SpawnFlowBlockEditorUnit(FlowBlock createdNewFlowBlock, FlowBlockEditorUnit parentBlockEditorUnit, BlockEditorWindow blockEditorWindow, Transform parent)
    {
        if (createdNewFlowBlock == null)
        {
            return(null);
        }

        FlowBlockEditorUnit blockEditorUnit = this.CreateBlockEditorUnit(createdNewFlowBlock, blockEditorWindow, parent) as FlowBlockEditorUnit;

        if (parentBlockEditorUnit != null)
        {
            FlowBlockEditorUnit.ConnectFlowBlockEditorUnit(parentBlockEditorUnit, blockEditorUnit);
        }

        if (createdNewFlowBlock.NextBlock != null)
        {
            this.SpawnFlowBlockEditorUnit(createdNewFlowBlock.NextBlock, blockEditorUnit, blockEditorWindow, parent);
        }



        return(blockEditorUnit);
    }
    public override void OnInspectorGUI()
    {
        base.DrawDefaultInspector();

        FlowBlockEditorUnit targetFlowBlockEditorUnit = base.target as FlowBlockEditorUnit;

        if (GUILayout.Button("Debug Block Unit Flow"))
        {
            StringBuilder stringBuilder = Utility.stringBuilderCache;
            stringBuilder.Clear();

            DebugBlockUnitFlowRecursive(targetFlowBlockEditorUnit, ref stringBuilder);
            Debug.Log(stringBuilder.ToString());
        }

        if (GUILayout.Button("Debug Block Flow"))
        {
            StringBuilder stringBuilder = Utility.stringBuilderCache;
            stringBuilder.Clear();

            DebugBlockFlowRecursive(targetFlowBlockEditorUnit.TargetFlowBlock, ref stringBuilder);
            Debug.Log(stringBuilder.ToString());
        }
    }
    sealed public override bool AttachBlock()
    {
        if (this.AttachableEditorElement != null)
        {
            FlowBlockConnector flowBlockConnector = this.AttachableEditorElement as FlowBlockConnector;
            if (flowBlockConnector._ConnectorType == FlowBlockConnector.ConnectorType.UpNotch)
            {//if hit connector is up notch type
                ConnectFlowBlockEditorUnit(flowBlockConnector.OwnerFlowBlockEditorUnit.PreviousFlowBlockEditorUnit, this);
                ConnectFlowBlockEditorUnit(this.LowestDescendantBlockUnit ?? this, flowBlockConnector.OwnerFlowBlockEditorUnit);
            }
            else
            {
                FlowBlockEditorUnit originalNextBlock = flowBlockConnector.OwnerFlowBlockEditorUnit.NextFlowBlockEditorUnit;
                ConnectFlowBlockEditorUnit(flowBlockConnector.OwnerFlowBlockEditorUnit, this);
                ConnectFlowBlockEditorUnit(this.LowestDescendantBlockUnit ?? this, originalNextBlock);
            }

            return(true);
        }
        else
        {
            return(false);
        }
    }