コード例 #1
0
    internal void updateDataStructures(string chosenGO, AbstractConfiguration s)
    {
        if (chosenGO != null)
        {
            configurationName = "";
            GO = GetGameObject(chosenGO);
        }
        else
        {
            GO = GetGameObject(s.gOName);
            configurationName = s.configurationName;
        }
        cleanDataStructures();
        List <FieldOrProperty> p = GetFieldsAndProperties(GO);;

        ObjectsProperties.Add(GO, new Dictionary <string, FieldOrProperty>());
        ObjectDerivedFromFields.Add(GO, new Dictionary <string, object>());
        foreach (FieldOrProperty obj in p)
        {
            object gOValueForObj;
            try
            {
                gOValueForObj = obj.GetValue(GO);
            }
            catch (Exception e)
            {
                gOValueForObj = null;
            }
            ObjectsProperties[GO].Add(obj.Name(), obj);
            if (gOValueForObj != null && !IsMappable(obj))
            {
                if (!ObjectsOwners.ContainsKey(gOValueForObj))
                {
                    ObjectsOwners.Add(gOValueForObj, new KeyValuePair <object, string>(GO, obj.Name()));
                }
            }

            ObjectDerivedFromFields[GO].Add(obj.Name(), gOValueForObj);
            if (!ObjectsToggled.ContainsKey(obj))
            {
                if (s != null && s.properties.Contains(obj.Name()))
                {
                    //Debug.Log(obj.Name() + " found.");
                    ObjectsToggled.Add(obj, true);
                    if (!IsMappable(obj) && gOValueForObj != null)
                    {
                        // Debug.Log("calling update");
                        updateDataStructures(gOValueForObj, s, obj.Name());
                    }
                    else
                    {
                        if (IsMappable(obj) && !IsBaseType(obj))
                        {
                            foreach (SimpleGameObjectsTracker st in s.advancedConf)
                            {
                                if (st.propertyName.Equals(obj.Name()))
                                {
                                    //st.objType = obj.Type().GetElementType().ToString();
                                    basicTypeCollectionsConfigurations.Add(obj, st);
                                    //Debug.Log("Adding st for " + obj.Name() + " whit type " + st.objType);
                                    break;
                                }
                            }
                        }
                        if (s.GetType() == typeof(SensorConfiguration))
                        {
                            foreach (StringIntPair pair in ((SensorConfiguration)s).operationPerProperty)
                            {
                                if (pair.Key.Equals(obj.Name()))
                                {
                                    operationPerProperty.Add(obj, pair.Value);
                                    if (pair.Value == Operation.SPECIFIC)
                                    {
                                        foreach (StringStringPair pair2 in ((SensorConfiguration)s).specificValuePerProperty)
                                        {
                                            if (pair2.Key.Equals(obj.Name()))
                                            {
                                                specificValuePerProperty.Add(obj, pair2.Value);
                                                break;
                                            }
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    ObjectsToggled.Add(obj, false);
                }
            }
        }
        GOComponents.Add(GO, GetComponents(GO));
        foreach (Component c in GOComponents[GO])
        {
            if (s != null && s.properties.Contains(c.GetType().ToString()))
            {
                //Debug.Log("component "+c+" name "+c.name+" type "+c.GetType());
                ObjectsToggled.Add(c, true);
                updateDataStructures(c, s, c.GetType().ToString());
            }
            else
            {
                ObjectsToggled.Add(c, false);
            }
        }
    }
コード例 #2
0
    internal void updateDataStructures(object obj, AbstractConfiguration s, string parent)
    {
        //Debug.Log("updating " + parent);

        List <FieldOrProperty> p = GetFieldsAndProperties(obj);

        ObjectsProperties.Add(obj, new Dictionary <string, FieldOrProperty>());
        //Debug.Log("Adding derived from fields entry");
        ObjectDerivedFromFields.Add(obj, new Dictionary <string, object>());

        foreach (FieldOrProperty ob in p)
        {
            //Debug.Log("Property " + ob.Name());
            object objValueForOb;
            try
            {
                objValueForOb = ob.GetValue(obj);
            }
            catch (Exception e)
            {
                //Debug.Log("cannot get value for property " + ob.Name());
                objValueForOb = null;
            }
            ObjectsProperties[obj].Add(ob.Name(), ob);
            //Debug.Log("complete name " + parent + "^" + ob.Name());
            if (objValueForOb != null)
            {
                if (!ObjectsOwners.ContainsKey(objValueForOb))
                {
                    ObjectsOwners.Add(objValueForOb, new KeyValuePair <object, string>(obj, ob.Name()));
                }
                //Debug.Log(ob.Name() + " owner is " + ObjectsOwners[objValueForOb]+"and its value is "+objValueForOb);
            }
            if (s != null && s.properties.Contains(parent + "^" + ob.Name()))
            {
                //Debug.Log("s contains " + parent + "^" + ob.Name());
                ObjectsToggled.Add(ob, true);
                if (!IsMappable(ob) && objValueForOb != null)
                {
                    updateDataStructures(objValueForOb, s, parent + "^" + ob.Name());
                }
                else
                {
                    if (IsMappable(ob) && !IsBaseType(ob))
                    {
                        foreach (SimpleGameObjectsTracker st in s.advancedConf)
                        {
                            if (st.propertyName.Equals(parent + "^" + ob.Name()))
                            {
                                //st.objType = ob.Type().GetElementType().ToString();
                                //Debug.Log("Adding st for " + ob.Name() + " whit type " + st.objType);
                                basicTypeCollectionsConfigurations.Add(ob, st);
                                break;
                            }
                        }
                    }
                    if (s.GetType() == typeof(SensorConfiguration))
                    {
                        foreach (StringIntPair pair in ((SensorConfiguration)s).operationPerProperty)
                        {
                            if (pair.Key.Equals(parent + "^" + ob.Name()))
                            {
                                operationPerProperty.Add(ob, pair.Value);
                                if (pair.Value == Operation.SPECIFIC)
                                {
                                    foreach (StringStringPair pair2 in ((SensorConfiguration)s).specificValuePerProperty)
                                    {
                                        if (pair2.Key.Equals(parent + "^" + ob.Name()))
                                        {
                                            specificValuePerProperty.Add(ob, pair2.Value);
                                            break;
                                        }
                                    }
                                }
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                ObjectsToggled.Add(ob, false);
            }

            ObjectDerivedFromFields[obj].Add(ob.Name(), objValueForOb);
        }
        if (obj.GetType() == typeof(GameObject))
        {
            GOComponents[(GameObject)obj] = GetComponents((GameObject)obj);
            foreach (Component c in GOComponents[(GameObject)obj])
            {
                if (s != null && s.properties.Contains(c.GetType().ToString()))
                {
                    //Debug.Log(obj.Name() + " found.");
                    ObjectsToggled.Add(c, true);
                    updateDataStructures(c, s, c.GetType().ToString());
                }
                else
                {
                    ObjectsToggled.Add(c, false);
                }
            }
        }
    }