Пример #1
0
        public static GameObject BuildBlockView(Block block)
        {
            GameObject blockPrefab = BlockViewSettings.Get().PrefabRoot;

            if (block.OutputConnection != null)
            {
                blockPrefab = BlockViewSettings.Get().PrefabRootOutput;
            }
            else if (block.PreviousConnection != null && block.NextConnection != null)
            {
                blockPrefab = BlockViewSettings.Get().PrefabRootPrevNext;
            }
            else if (block.PreviousConnection != null)
            {
                blockPrefab = BlockViewSettings.Get().PrefabRootPrev;
            }

            GameObject blockObj = GameObject.Instantiate(blockPrefab);

            blockObj.name = "Block_" + block.Type;
            RectTransform blockTrans = blockObj.GetComponent <RectTransform>();

            UniformRectTransform(blockTrans);

            //blockview script
            BlockView blockView = AddViewComponent <BlockView>(blockObj);

            //block view's background image
            blockView.AddBgImage(blockObj.GetComponent <Image>());

            //block view's childs: connection, lineGroup
            Transform mutatorEntry = null;

            foreach (Transform child in blockTrans)
            {
                string childName = child.name.ToLower();
                if (childName.StartsWith("connection"))
                {
                    //connection node views
                    ConnectionView conView = AddViewComponent <ConnectionView>(child.gameObject);
                    blockView.AddChild(conView, 0);

                    if (childName.EndsWith("output"))
                    {
                        conView.ConnectionType = Define.EConnection.OutputValue;
                    }
                    else if (childName.EndsWith("prev"))
                    {
                        conView.ConnectionType = Define.EConnection.PrevStatement;
                    }
                    else if (childName.EndsWith("next"))
                    {
                        conView.ConnectionType = Define.EConnection.NextStatement;
                    }

                    //connection node view background color
                    Image image = child.GetComponent <Image>();
                    if (image != null)
                    {
                        blockView.AddBgImage(image);
                    }
                }
                else if (childName.Equals("linegroup"))
                {
                    UniformRectTransform(child as RectTransform);
                    //lineGroup view
                    LineGroupView groupView = AddViewComponent <LineGroupView>(child.gameObject);
                    blockView.AddChild(groupView);
                }
                else if (childName.Equals("mutator_entry"))
                {
                    mutatorEntry = child;
                }
                else if (childName.StartsWith("block_count"))
                {
                    blockView.SetCountText(child.GetComponentInChildren <Text>());
                }
            }

            //check if has mutator entry
            if (mutatorEntry == null)
            {
                throw new Exception("There should be a mutator_entry image under block view prefab");
            }
            if (block.Mutator == null || !block.Mutator.NeedEditor)
            {
                GameObject.DestroyImmediate(mutatorEntry.gameObject);
            }
            else
            {
                blockView.GetLineGroup(0).ReservedStartX = ((RectTransform)mutatorEntry).rect.width + BlockViewSettings.Get().ContentSpace.x;
            }

            //block view's input views, including field's views
            BuildInputViews(block, blockView);

            //block view's layout, build from the very first field
            blockView.BuildLayout();

            //default background color
            blockView.ChangeBgColor(Color.blue);

            return(blockObj);
        }
Пример #2
0
        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);
        }