Example #1
0
 public GameObject FindCorrectValueWidget(Type type)
 {
     foreach (GameObject obj in valueWidgets)
     {
         IValueWidget widget = obj.GetComponent <IValueWidget> ();
         if (widget.CompatableTypes.Contains(type))
         {
             return(obj);
         }
     }
     return(null);
 }
Example #2
0
        public void CreateValueWidgetFor(HookAttachment inputWidget, InputHook inputHook)
        {
            GameObject widgetPrefab = FindCorrectValueWidget(inputHook.ValueType);

            object value = inputHook.ValueType.IsValueType ? Activator.CreateInstance(inputHook.ValueType) : null;

            Console.WriteLine(value);

            ValueNode valueNode = new ValueNode().SetPosition(new VectorPosition(0, 0)).SetProgram(ProgramEditor.CurrentEditor.CurrentProgram) as ValueNode;

            valueNode.InitChildren();

            valueNode.SetValue(value).SetType(inputHook.ValueType);

            GameObject newWidget = Instantiate(widgetPrefab, workspace.transform);

            newWidget.transform.position = Input.mousePosition;
            IValueWidget widget = newWidget.GetComponent <IValueWidget> ();

            widget.Initialize(valueNode);
            OnClickedHook(widget.OutputHookWidget);
        }
            public IEnumerator <KeyValuePair <string, IWidget> > GetEnumerator()
            {
                if (_value == null)
                {
                    yield break;
                }

                var i = 0;

                foreach (var field in _fields)
                {
                    IValueWidget widget = null;

                    try
                    {
                        // If property is expanded
                        // Do lazy widget lookup
                        if (_expanded.Get(i))
                        {
                            widget = _fieldWidgetsCache.Get(field);

                            if (widget != null)
                            {
                                var v = field.GetValue(_value);
                                widget.SetValue(v);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(e);
                    }

                    i += 1;
                    yield return(new KeyValuePair <string, IWidget>(field.Name, widget));
                }

                foreach (var prop in _props)
                {
                    IValueWidget widget = null;

                    try
                    {
                        // If property is expanded
                        // Do lazy widget lookup
                        if (_expanded.Get(i))
                        {
                            widget = _propWidgetsCache.Get(prop);

                            if (widget != null)
                            {
                                var v = prop.GetValue(_value, null);
                                widget.SetValue(v);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(e);
                    }

                    i += 1;
                    yield return(new KeyValuePair <string, IWidget>(string.Format("get {0}", prop.Name), widget));
                }
            }