예제 #1
0
        /// <summary>
        /// Returns the type that a codeblock with the specified source item should have.
        /// </summary>
        protected static UIBlockType GetBlockType(CodeblockItem source)
        {
            if (source == null)
            {
                return(UIBlockType.Entry);
            }

            if (source is IDynamicEvaluateableCodeblock)
            {
                return(UIBlockType.Evaluateable);
            }

            if (source is IExecuteableCodeblock)
            {
                if (source is IControlFlowBlock)
                {
                    return(UIBlockType.ControlFlow);
                }
                else
                {
                    return(UIBlockType.Executable);
                }
            }

            return(UIBlockType.Unknown);
        }
예제 #2
0
        private T TestBlockCreation <T>() where T : CodeblockItem
        {
            CodeblockItem x         = System.Activator.CreateInstance <T>();
            Transform     transform = UICodeblock.Generate(x).transform;

            transform.SetParent(Parent, false);
            transform.position = new Vector3(Screen.width * Random.value, Screen.height * Random.value);

            return(x as T);
        }
예제 #3
0
        /// <summary>
        /// Dynamically generates a UI codeblock.
        /// </summary>
        public static UICodeblock Generate(CodeblockItem source)
        {
            UIBlockType type = GetBlockType(source);
            string      name =
                source != null
                ? $"Dynamic UI Codeblock [{ type.ToString() }] ({ source.Identity.ID })"
                : $"Entry Codeblock";

            string     requiredPrefab = System.Enum.GetName(typeof(UIBlockType), (int)type);
            GameObject prefab         = Resources.Load <GameObject>($"Codeblock_{requiredPrefab}");

            GameObject blockObject = Instantiate(prefab);

            blockObject.name = name;

            UICodeblock codeblock = blockObject.GetComponent <UICodeblock>();

            codeblock.Source = source;

            return(codeblock);
        }
예제 #4
0
 public ContentResolver(CodeblockItem target)
 {
     _item = target;
 }