Ejemplo n.º 1
0
        public void AddToSequence(SelectionBlock selectionBlock)
        {
            GameObject newBlock    = Instantiate(blockPrefab, transform);
            Block      blockScript = newBlock.GetComponent <Block>();

            if (blockScript == null)
            {
                Debug.LogError("Could not find Block script on the Block Prefab");
                return;
            }

            blockScript.Initialize(selectionBlock.MethodInfo, selectionBlock);
            blocks.Add(blockScript);

            // Scroll the sequence to the bottom
            scrollRect.normalizedPosition = Vector2.down;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates the blocks which only contain the function name on the selection panel
        /// </summary>
        void CreateSelectionBlocks()
        {
            MethodInfo[] mInfos = commandObject.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
            foreach (MethodInfo m in mInfos)
            {
                Command[] commands = m.GetCustomAttributes(typeof(Command), true) as Command[];

                foreach (Command com in commands)
                {
                    GameObject     newGameObject = Instantiate(selectionBlockPrefab, transform);
                    SelectionBlock blockScript   = newGameObject.GetComponent <SelectionBlock>();
                    if (blockScript != null)
                    {
                        blockScript.Initliaze(commandObject, m, sequencer);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void Initialize(MethodInfo info, SelectionBlock selected)
        {
            nameText.text = info.Name;
            SelectedBlock = selected;

            /* Iterate through parameters here and construct a new block
             * from the given parameter prefabs (e.g. FloatFieldPrefab, BoolFieldPrefab etc.)
             * Add new parameters in this loop
             * It's necessary to add a listener that will change the block's parameters
             */
            ParameterInfo[] infos = info.GetParameters();
            Parameters = (infos.Length > 0) ? new object[infos.Length] : null;
            for (int i = 0; i < infos.Length; i++)
            {
                Type parameterType = infos[i].ParameterType;
                int  index         = i;

                if (parameterType == typeof(int))
                {
                    InputField inputField = InstantiateBlockParameter <InputField>(IntFieldPrefab); // Instantiate the parameter UI
                    Parameters[index] = Int32.Parse(inputField.text);                               // Get the initial value

                    // Add a listener that changes the parameter property when edited
                    inputField.onEndEdit.AddListener(delegate
                    {
                        if (inputField.text == "")
                        {
                            inputField.text = "0";
                        }

                        Parameters[index] = Int32.Parse(inputField.text);
                    });
                }
                else if (parameterType.BaseType == typeof(Enum))
                {
                    Dropdown dropdown = InstantiateBlockParameter <Dropdown>(DropdownPrefab);

                    // Populate the dropdown list
                    foreach (var option in Enum.GetValues(infos[i].ParameterType))
                    {
                        dropdown.options.Add(new Dropdown.OptionData(option.ToString()));
                    }

                    Parameters[index] = dropdown.value;
                    dropdown.onValueChanged.AddListener(delegate { Parameters[index] = dropdown.value; });
                }
                else if (parameterType == typeof(float))
                {
                    InputField inputField = InstantiateBlockParameter <InputField>(FloatFieldPrefab);
                    Parameters[index] = float.Parse(inputField.text);
                    inputField.onEndEdit.AddListener(delegate
                    {
                        if (inputField.text == "")
                        {
                            inputField.text = "0";
                        }

                        Parameters[index] = float.Parse(inputField.text);
                    });
                }
                else if (parameterType == typeof(string))
                {
                    InputField inputField = InstantiateBlockParameter <InputField>(StringFieldPrefab);
                    Parameters[index] = inputField.text;
                    inputField.onEndEdit.AddListener(x => Parameters[index] = inputField.text);
                }
                else if (parameterType == typeof(bool))
                {
                    Toggle toggle = InstantiateBlockParameter <Toggle>(BoolFieldPrefab);
                    Parameters[index] = toggle.isOn;
                    toggle.onValueChanged.AddListener(x => Parameters[index] = toggle.isOn);
                }
            }

            Canvas.ForceUpdateCanvases();
            FitToChildren();
        }