public static bool IsBaseType(FieldOrProperty obj)
    {
        List <Type> signedInteger   = SignedIntegerTypes();
        List <Type> unsignedInteger = UnsignedIntegerTypes();
        List <Type> floatingPoint   = FloatingPointTypes();
        //MyDebugger.MyDebug(" level " + level);
        Type   objType = obj.Type();
        uint   u       = 1;
        byte   b       = 1;
        ulong  l       = 1;
        ushort s       = 1;

        l = s;
        //MyDebugger.MyDebug(obj.GetProperties()[0].PropertyType+" with name "+ obj.GetProperties()[0].Name);
        bool isBase = signedInteger.Contains(objType) || unsignedInteger.Contains(objType) || floatingPoint.Contains(objType);

        isBase |= objType == typeof(char) || objType == typeof(bool) || objType == typeof(Enum) || objType == typeof(string);
        return(isBase);
    }
    public Type isList(FieldOrProperty obj)
    {
        Type objType = obj.Type();

        return(isListOfType(objType));
    }
    public int isArrayOfRank(FieldOrProperty obj)
    {
        Type objType = obj.Type();

        return(objType.IsArray? objType.GetArrayRank():-1);
    }
    /*public void describeObject(object obj, int level, List<object> met, StreamWriter o)
     * {
     *  Type objType = obj.GetType();
     *  //Debug.Log( objType + "has following fields: \n");
     *  o.WriteLine(objType + " has following fields:");
     *  met.Add(obj);
     *  // Debug.Log(objType.GetProperties().Length);
     *   foreach (PropertyInfo child in objType.GetProperties())
     *   {
     *
     *       describing += child.PropertyType + " named " + child.Name + "\n";
     *   }
     *
     *  // Debug.Log(objType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public).Length);
     *  MemberInfo[] fields = objType.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
     *  MemberInfo[] properties = objType.GetProperties();
     *  var members = fields.Union(properties);
     *  foreach (MemberInfo child in members)
     *  {
     *      if (child.MemberType == MemberTypes.Field)
     *      {
     *
     *          if (met.Contains(((FieldInfo)child).GetValue(obj)))
     *          {
     *              continue;
     *          }
     *
     *      }
     *      else if (met.Contains(((PropertyInfo)child).GetValue(obj,null)))
     *      {
     *          continue;
     *      }
     *
     *      describeField(new FieldOrProperty(child), obj, level + 1, met, o);
     *  }
     *
     *
     * }*/

    /* public void describeField(FieldOrProperty m, object ob, int level, List<object> met, StreamWriter o)
     * {
     *
     *   List<Type> signedInteger = new List<Type> { typeof(sbyte), typeof(short), typeof(int), typeof(long) };
     *   List<Type> unsignedInteger = new List<Type> { typeof(byte), typeof(ushort), typeof(uint), typeof(ulong) };
     *   List<Type> floatingPoint = new List<Type> { typeof(double), typeof(float) };
     *   //Debug.Log(" level " + level);
     *   Type objType = m.Type();
     *
     *   //Debug.Log(obj.GetProperties()[0].PropertyType+" with name "+ obj.GetProperties()[0].Name);
     *   met.Add(objType);
     *   if (level > 5)
     *   {
     *       // Debug.Log("too many levels");
     *       o.WriteLine("too many levels");
     *
     *   }
     *   else if (signedInteger.Contains(objType))
     *   {
     *       //Debug.Log(m.Name + " is a signed integer");
     *       o.WriteLine(m.Name() + " is a signed integer with value "+m.GetValue(ob));
     *   }
     *   else if (unsignedInteger.Contains(objType))
     *   {
     *       // Debug.Log(m.Name + " is an unsigned integer");
     *       o.WriteLine(m.Name() + " is a unsigned integer with value " + m.GetValue(ob));
     *   }
     *   else if (floatingPoint.Contains(objType))
     *   {
     *       //Debug.Log(m.Name + " is a floating point number");
     *       o.WriteLine(m.Name() + " is a floating point number with value " + m.GetValue(ob));
     *   }
     *   else if (objType == typeof(char))
     *   {
     *       //Debug.Log(m.Name + " is a char");
     *       o.WriteLine(m.Name() + " is a char with value " + m.GetValue(ob));
     *   }
     *   else if (objType == typeof(bool))
     *   {
     *       //Debug.Log(m.Name + " is a bool");
     *       o.WriteLine(m.Name() + " is a bool with value " + m.GetValue(ob));
     *   }
     *   else if (objType == typeof(Enum))
     *   {
     *       //Debug.Log(m.Name + " is an Enum");
     *       o.WriteLine(m.Name() + " is an Enum with value " + m.GetValue(ob));
     *   }else if(objType == typeof(string))
     *   {
     *       o.WriteLine(m.Name() + " is a string with value" + m.GetValue(ob));
     *   }
     *   else if (objType.IsGenericType)
     *   {
     *       describeGeneric(m, ob, level,o);
     *
     *   }
     *   else
     *   {
     *       o.WriteLine(m.Name() + " is " + objType);
     *   }
     * }*/

    /* public void describeGeneric(FieldOrProperty m, object ob, int level, StreamWriter o)
     * {
     *   //Debug.Log(m.Name()+" "+m.Type());
     *   if (m.Type().GetGenericTypeDefinition() == typeof(List<>))
     *   {
     *       //Debug.Log("a list of " + m.GetValue(ob).GetType().GetGenericArguments()[0] + " named " + m.Name() + "\n");
     *       o.WriteLine("a list of " + m.GetValue(ob).GetType().GetGenericArguments()[0] + " named " + m.Name());
     *   }else if (m.Type().GetGenericTypeDefinition() == typeof(HashSet<>))
     *   {
     *       // Debug.Log("an hashset of " + m.GetValue(ob).GetType().GetGenericArguments()[0] + " named " + m.Name() + "\n");
     *       o.WriteLine("an hashset of " + m.GetValue(ob).GetType().GetGenericArguments()[0] + " named " + m.Name());
     *   }
     *   else if (m.Type().GetGenericTypeDefinition() == typeof(Dictionary<,>))
     *   {
     *       //Debug.Log("a dictionary of " + m.GetValue(ob).GetType().GetGenericArguments()[0]+","+ m.GetValue(ob).GetType().GetGenericArguments()[1] + " named " + m.Name() + "\n");
     *       o.WriteLine("a dictionary of " + m.GetValue(ob).GetType().GetGenericArguments()[0] + "," + m.GetValue(ob).GetType().GetGenericArguments()[1] + " named " + m.Name());
     *   }
     * }*/

    internal Type TypeOf(FieldOrProperty f)
    {
        return(f.Type());
    }
Ejemplo n.º 5
0
        protected void addSubProperties(object obj, string name, object objOwner)
        {
            if (tracker.ObjectsOwners.ContainsKey(obj) && !obj.GetType().IsValueType&& (!tracker.ObjectsOwners[obj].Key.Equals(objOwner) || !tracker.ObjectsOwners[obj].Value.Equals(name)) || obj.Equals(tracker.GO))
            {
                EditorGUI.BeginDisabledGroup(true);
                if (obj.Equals(tracker.GO))
                {
                    EditorGUILayout.ToggleLeft("This is " + chosenGO + " object", true);
                }
                else if (!tracker.ObjectsOwners[obj].Value.Equals(name))
                {
                    EditorGUILayout.ToggleLeft("object already listed as " + tracker.ObjectsOwners[obj].Value, true);
                }
                else
                {
                    EditorGUILayout.ToggleLeft("object already listed in an upper level", true);
                }
                EditorGUI.EndDisabledGroup();

                return;
            }
            if (!tracker.ObjectsToggled.ContainsKey(obj))
            {
                tracker.ObjectsToggled.Add(obj, false);
            }
            if (!tracker.ObjectsProperties.ContainsKey(obj))
            {
                tracker.updateDataStructures(obj, null, null);
            }
            foreach (FieldOrProperty f in tracker.ObjectsProperties[obj].Values)
            {
                bool disabled = tracker.ObjectDerivedFromFields[obj][f.Name()] == null;
                EditorGUI.BeginDisabledGroup(disabled);
                if (isMappable(f))
                {
                    EditorGUILayout.BeginHorizontal();
                    tracker.ObjectsToggled[f] = EditorGUILayout.ToggleLeft(f.Name(), tracker.ObjectsToggled[f]);
                    addCustomFields(f);
                    if (tracker.ObjectsToggled[f] && !tracker.IsBaseType(f))
                    {
                        bool configure = GUILayout.Button("Configure Object");
                        if (configure)
                        {
                            objectMode        = true;
                            objectToConfigure = f;
                            helpScroll        = new Vector2(0, 0);
                            //MyDebugger.MyDebug("num: "+tracker.basicTypeCollectionsConfigurations.Count);
                            if (!tracker.basicTypeCollectionsConfigurations.ContainsKey(f))
                            {
                                //MyDebugger.MyDebug("f " + tracker.basicTypeCollectionsConfigurations[f]);
                                MyDebugger.MyDebug("adding simple tracker for " + objectToConfigure.Name() + " that is a " + objectToConfigure.Type());

                                tracker.basicTypeCollectionsConfigurations.Add(f, new SimpleGameObjectsTracker(objectToConfigure.Type()));
                            }
                            tracker.basicTypeCollectionsConfigurations[f].getBasicProperties();
                            drawObjectProperties();
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                else
                {
                    tracker.ObjectsToggled[f] = EditorGUILayout.Foldout(tracker.ObjectsToggled[f], f.Name()) && !disabled;
                    if (tracker.ObjectsToggled[f])
                    {
                        EditorGUI.indentLevel++;
                        addSubProperties(tracker.ObjectDerivedFromFields[obj][f.Name()], f.Name(), obj);
                        EditorGUI.indentLevel--;
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
        }
Ejemplo n.º 6
0
        protected void addProperties()
        {
            using (var h = new EditorGUILayout.VerticalScope())
            {
                using (var scrollView = new EditorGUILayout.ScrollViewScope(mainScroll))
                {
                    GameObject gO = tracker.GO;
                    foreach (FieldOrProperty obj in tracker.ObjectsProperties[gO].Values)
                    {
                        bool disabled = tracker.ObjectDerivedFromFields[gO][obj.Name()] == null;
                        EditorGUI.BeginDisabledGroup(disabled);
                        if (isMappable(obj))
                        {
                            EditorGUILayout.BeginHorizontal();
                            tracker.ObjectsToggled[obj] = EditorGUILayout.ToggleLeft(obj.Name(), tracker.ObjectsToggled[obj]);
                            addCustomFields(obj);

                            if (tracker.ObjectsToggled[obj] && !tracker.IsBaseType(obj))
                            {
                                bool configure = GUILayout.Button("Configure Object");
                                if (configure)
                                {
                                    objectMode        = true;
                                    objectToConfigure = obj;
                                    helpScroll        = new Vector2(0, 0);
                                    if (!tracker.basicTypeCollectionsConfigurations.ContainsKey(obj))
                                    {
                                        MyDebugger.MyDebug("adding simple tracker for " + objectToConfigure.Name() + " that is a " + objectToConfigure.Type());
                                        tracker.basicTypeCollectionsConfigurations.Add(obj, new SimpleGameObjectsTracker(objectToConfigure.Type()));
                                    }
                                    tracker.basicTypeCollectionsConfigurations[obj].getBasicProperties();
                                    drawObjectProperties();
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                        }
                        else
                        {
                            tracker.ObjectsToggled[obj] = EditorGUILayout.Foldout(tracker.ObjectsToggled[obj], obj.Name()) && !disabled;
                            if (tracker.ObjectsToggled[obj])
                            {
                                EditorGUI.indentLevel++;
                                addSubProperties(tracker.ObjectDerivedFromFields[gO][obj.Name()], obj.Name(), gO);
                                EditorGUI.indentLevel--;
                            }
                        }
                        EditorGUI.EndDisabledGroup();
                    }


                    foreach (Component c in tracker.GOComponents[gO])
                    {
                        //MyDebugger.MyDebug(c);
                        tracker.ObjectsToggled[c] = EditorGUILayout.Foldout(tracker.ObjectsToggled[c], c.GetType().ToString());
                        if (tracker.ObjectsToggled[c])
                        {
                            EditorGUI.indentLevel++;
                            addSubProperties(c, c.GetType().ToString(), gO);
                            EditorGUI.indentLevel--;
                        }
                    }

                    mainScroll = scrollView.scrollPosition;
                }
            }
        }
Ejemplo n.º 7
0
    /*void OnDisable()
     * {
     *  if (!Directory.Exists("Assets/Resources/Sensors"))
     *  {
     *      Directory.CreateDirectory("Assets/Resources/Sensors");
     *  }
     *  if (AssetDatabase.LoadAssetAtPath("Assets/Resources/SensorsManager.asset", typeof(SensorsManager)) == null)
     *  {
     *      AssetDatabase.CreateAsset((SensorsManager)manager, "Assets/Resources/SensorsManager.asset");
     *  }
     *  else
     *  {
     *      EditorUtility.SetDirty((SensorsManager)manager);
     *      AssetDatabase.SaveAssets();
     *  }
     *  foreach (AbstractConfiguration conf in ((SensorsManager)manager).confs())
     *  {
     *      SensorConfiguration sensorConf = (SensorConfiguration)conf;
     *      if (AssetDatabase.LoadAssetAtPath("Assets/Resources/Sensors/" + sensorConf.configurationName + ".asset", typeof(SensorConfiguration)) == null)
     *      {
     *          AssetDatabase.CreateAsset(sensorConf, "Assets/Resources/Sensors/" + sensorConf.configurationName + ".asset");
     *      }
     *      else
     *      {
     *          EditorUtility.SetDirty(sensorConf);
     *          AssetDatabase.SaveAssets();
     *      }
     *  }
     * }*/



    internal override void addCustomFields(FieldOrProperty obj)
    {
        if (tracker.ObjectsToggled[obj])
        {
            if (!tracker.operationPerProperty.ContainsKey(obj))
            {
                tracker.operationPerProperty.Add(obj, 0);
            }

            tracker.operationPerProperty[obj] = EditorGUILayout.Popup(tracker.operationPerProperty[obj], Enum.GetNames(Operation.getOperationsPerType(obj.Type())));
            if (tracker.operationPerProperty[obj] == Operation.SPECIFIC)//thus is a specific_value
            {
                if (!tracker.specificValuePerProperty.ContainsKey(obj))
                {
                    tracker.specificValuePerProperty.Add(obj, "");
                }
                tracker.specificValuePerProperty[obj] = EditorGUILayout.TextField("Value to track", tracker.specificValuePerProperty[obj]);
            }
        }
    }
Ejemplo n.º 8
0
        protected override void advancedUpdate(FieldOrProperty property, string entire_name, object parent)
        {
            ////MyDebugger.MyDebug("updating " + entire_name);
            if (property.Type().IsArray&& property.Type().GetArrayRank() == 2)
            {
                ////MyDebugger.MyDebug(entire_name + " is a matrix");
                Array matrix = property.GetValue(parent) as Array;
                int   r      = matrix.GetLength(0);
                int   c      = matrix.GetLength(1);
                if (matrixProperties[entire_name] is null)
                {
                    matrixProperties[entire_name] = new SimpleSensor[r, c];
                }

                SimpleSensor[,] current = matrixProperties[entire_name];
                if (current.GetLength(0) != r || current.GetLength(1) != c)
                {
                    current = new SimpleSensor[r, c];
                    matrixProperties[entire_name] = current;
                }
                List <string> elementConf = advancedConf[entire_name].toSave;
                for (int i = 0; i < r; i++)
                {
                    for (int j = 0; j < c; j++)
                    {
                        ////MyDebugger.MyDebug(matrix.GetValue(i, j).GetType());
                        if (current[i, j] == null)
                        {
                            current[i, j] = new SimpleSensor(elementConf, advancedConf[entire_name].name, matrix.GetValue(i, j));
                        }
                        else
                        {
                            current[i, j].gO = matrix.GetValue(i, j);
                            current[i, j].init();
                        }
                        //current[i, j] = new SimpleSensor(elementConf, advancedConf[entire_name].name, matrix.GetValue(i, j));
                    }
                }
                ////MyDebugger.MyDebug("rows " + matrixProperties[entire_name].GetLength(0) + " columns " + matrixProperties[entire_name].GetLength(1));
                ////MyDebugger.MyDebug(matrixProperties[entire_name].GetValue(0, 0));
            }
            if (property.Type().IsGenericType&& property.Type().GetGenericTypeDefinition() == typeof(List <>))
            {
                IList list = property.GetValue(parent) as IList;

                List <SimpleSensor> current     = listProperties[entire_name];
                List <string>       elementConf = advancedConf[entire_name].toSave;
                ////MyDebugger.MyDebug("current count " + current.Count + " actual count " + list.Count);

                if (current.Count > list.Count)
                {
                    current.RemoveRange(list.Count, current.Count - list.Count);
                }
                for (int i = 0; i < list.Count; i++)
                {
                    if (current.Count < i + 1)
                    {
                        current.Add(new SimpleSensor(elementConf, advancedConf[entire_name].name, list[i]));
                    }
                    else
                    {
                        current[i].gO = list[i];
                        current[i].init();
                        //current[i] = new SimpleSensor(elementConf, advancedConf[entire_name].name, list[i]);
                    }
                }
                ////MyDebugger.MyDebug("elements in list " + listProperties[entire_name].Count);
            }
        }