Exemplo n.º 1
0
    public void Inspect(object inspectObject, Action <object> OnValueChanged)
    {
        CleanContent();

        if (inspectObject == null)
        {
            return;
        }

        inspectingObject    = inspectObject;
        this.OnValueChanged = OnValueChanged;

        var degt = ReflectionUtilities.DesgloseInBasicTypes(inspectObject.GetType());

        Dictionary <string, GameObject> sublevels = new Dictionary <string, GameObject>();

        foreach (var deglossedType in degt)
        {
            foreach (var propertyPath in deglossedType.Value)
            {
                GameObject  instancedProperty = propertyPool.GetItem();
                GUIProperty gp = instancedProperty.GetComponent <GUIProperty>();

                string[] path = propertyPath.Split('/');

                GameObject pathParent = content.gameObject;

                if (path.Length > 1)
                {
                    string composedPath = "";

                    for (int i = 0; i < path.Length - 1; i++)
                    {
                        if (i == 0)
                        {
                            composedPath += path[i];

                            if (sublevels.ContainsKey(composedPath))
                            {
                                pathParent = sublevels[composedPath];
                            }
                            else
                            {
                                pathParent = GameObject.Instantiate(propertyObject.gameObject);
                                pathParent.transform.SetParent(content);

                                GUIPropertyObject gpo = pathParent.GetComponent <GUIPropertyObject>();
                                gpo.propertyName.text = path[i].NicifyString();
                                pathParent            = gpo.children.gameObject;

                                propertiesobjects.Add(gpo);
                                sublevels.Add(composedPath, pathParent);
                            }
                        }
                        else
                        {
                            composedPath += "/" + path[i];

                            if (sublevels.ContainsKey(composedPath))
                            {
                                pathParent = sublevels[composedPath];
                            }
                            else
                            {
                                pathParent = GameObject.Instantiate(propertyObject.gameObject, pathParent.transform);

                                GUIPropertyObject gpo = pathParent.GetComponent <GUIPropertyObject>();
                                gpo.propertyName.text = path[i].NicifyString();
                                pathParent            = gpo.children.gameObject;

                                propertiesobjects.Add(gpo);
                                sublevels.Add(composedPath, pathParent);
                            }
                        }
                    }
                }


                instancedProperty.transform.SetParent(pathParent.transform);

                properties.Add(gp);

                gp.OnValueChanged.RemoveAllListeners();

                if (deglossedType.Key.IsString())
                {
                    gp.SetData(ReflectionUtilities.GetValueOf(path.ToList(), inspectObject), propertyPath, GUIProperty.PropertyType.String);
                }
                else if (deglossedType.Key.IsNumber())
                {
                    gp.SetData(ReflectionUtilities.GetValueOf(path.ToList(), inspectObject), propertyPath, GUIProperty.PropertyType.Number);
                }
                else if (deglossedType.Key.IsBool())
                {
                    gp.SetData(ReflectionUtilities.GetValueOf(path.ToList(), inspectObject), propertyPath, GUIProperty.PropertyType.Boolean);
                }
                else if (deglossedType.Key.IsEnum)
                {
                    gp.SetData(ReflectionUtilities.GetValueOf(path.ToList(), inspectObject), propertyPath, GUIProperty.PropertyType.Enumeration);
                }
                else
                {
                    gp.SetData(ReflectionUtilities.GetValueOf(path.ToList(), inspectObject), propertyPath, GUIProperty.PropertyType.SceneReference);
                }

                gp.OnValueChanged.RemoveAllListeners();
                gp.OnValueChanged.AddListener(OnPropertyChanged);
            }
        }

        LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)content);
    }
    private void Awake()
    {
        if (node != null)
        {
            List <string> ignored = new List <string>();
            Dictionary <string, GameObject> listNodes = new Dictionary <string, GameObject>();

            foreach (NodePort port in node.Ports)
            {
                GameObject portGO;
                if (CheckTypeIsGenericDictionary(port.ValueType))
                {
                    portGO = Instantiate(graph.dynamicList, body.transform);
                    SetDefaultLabelText(portGO, port.fieldName);
                    listNodes.Add(port.fieldName, portGO);
                }
                else if (port.IsDynamic && port.fieldName.StartsWith("#List"))
                {
                    // Dynamic list elements
                    string[]   portName = port.fieldName.Split(new char[] { '#' }, StringSplitOptions.RemoveEmptyEntries);
                    GameObject dl       = listNodes[portName[1]];

                    var layout = dl.GetComponentInChildren <LayoutGroup>();
                    portGO = Instantiate(graph.dynamicPort, layout.transform);
                    SetDefaultLabelText(portGO, portName[2]);
                    SetDefaultListElementData(portGO, port);
                }
                else
                {
                    portGO = Instantiate(port.direction == NodePort.IO.Input ? graph.inputPort : graph.outputPort, body.transform);
                    SetDefaultLabelText(portGO, port.fieldName);
                    SetDefaultPortData(portGO, port);
                }
                ignored.Add(port.fieldName);
            }

            transform.Find("Header/Title").GetComponent <TextMeshProUGUI>().text = node.name;


            var d = ReflectionUtilities.DesgloseInBasicTypes(node.GetType(), ignored);

            foreach (KeyValuePair <Type, List <string> > kvp in d)
            {
                foreach (string variable in kvp.Value)
                {
                    GameObject variableGo = Instantiate(graph.Property, body.transform);


                    GUIProperty gp = variableGo.GetComponent <GUIProperty>();

                    object value = ReflectionUtilities.GetValueOf(variable.Split('/').ToList(), node);

                    if (kvp.Key.IsString())
                    {
                        gp.SetData(value, variable, GUIProperty.PropertyType.String);
                    }
                    else if (kvp.Key.IsNumber())
                    {
                        gp.SetData(value, variable, GUIProperty.PropertyType.Number);
                    }
                    else if (kvp.Key.IsBool())
                    {
                        gp.SetData(value, variable, GUIProperty.PropertyType.Boolean);
                    }
                    else if (kvp.Key.IsEnum)
                    {
                        gp.SetData(value, variable, GUIProperty.PropertyType.Enumeration);
                    }

                    gp.OnValueChanged.RemoveAllListeners();
                    gp.OnValueChanged.AddListener(PropertyChanged);
                }
            }

            if (node is NTNode)
            {
                ((RectTransform)transform).sizeDelta = new Vector2(((NTNode)node).GetWidth(), ((RectTransform)transform).sizeDelta.y);
            }
        }
        else
        {
            gameObject.SetActive(false);
        }

        ntNode = node as NTNode;
    }