Beispiel #1
0
 /// <summary>
 /// Performs a new scan for tweakable objects.
 /// </summary>
 private void RefreshContent()
 {
     tweakables = new List<TweakableClass>();
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         if (AssemblyNameLookedAt(assembly.GetName().Name))
             foreach (Type type in assembly.GetTypes())
             {
                 List<FieldInfo> sharedFields = new List<FieldInfo>();
                 List<FieldInfo> instancedFields = new List<FieldInfo>();
                 foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                 {
                     TweakableField tweakableAttribute = null;
                     bool isSerialized = field.IsPublic;
                     foreach (Attribute att in field.GetCustomAttributes(true))
                     {
                         if (att is TweakableField) tweakableAttribute = att as TweakableField;
                         isSerialized |= att is SerializeField;
                         if (tweakableAttribute != null && isSerialized)
                         {
                             if ((att as TweakableField).isSharedAmongAllInstances)
                             {
                                 sharedFields.Add(field);
                             }
                             else
                             {
                                 instancedFields.Add(field);
                             }
                             break;
                         }
                     }
                     if (tweakableAttribute != null && !isSerialized)
                     {
                         Debug.LogWarning("It appears some tweakable fields aren't seralized. This is probably due to the fields being marked as private without having the [SerializeField] attribute.");
                     }
                 }
                 if (sharedFields.Count > 0 || instancedFields.Count > 0)
                 {
                     TweakableClass c = new TweakableClass();
                     c.type = type;
                     c.sharedFields = sharedFields.ToArray();
                     c.instancedFields = instancedFields.ToArray();
                     c.objects = Resources.FindObjectsOfTypeAll(type);
                     UnityEngine.Object obj;
                     if(c.objects.Length > 0 && (obj = PrefabUtility.GetPrefabParent(c.objects[0])) != null) {
                         c.hasPrefab = true;
                         for (int i = 0; i < c.objects.Length; i++)
                         {
                             if (c.objects[i] == obj)
                             {
                                 var tObj = c.objects[0];
                                 c.objects[0] = c.objects[i];
                                 c.objects[i] = tObj;
                                 break;
                             }
                         }
                     }
                     else
                     {
                         c.hasPrefab = false;
                     }
                     tweakables.Add(c);
                 }
             }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Performs a new scan for tweakable objects.
 /// </summary>
 private void RefreshContent()
 {
     tweakables = new List <TweakableClass>();
     foreach (Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
     {
         if (AssemblyNameLookedAt(assembly.GetName().Name))
         {
             foreach (Type type in assembly.GetTypes())
             {
                 List <FieldInfo> sharedFields    = new List <FieldInfo>();
                 List <FieldInfo> instancedFields = new List <FieldInfo>();
                 foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic))
                 {
                     TweakableField tweakableAttribute = null;
                     bool           isSerialized       = field.IsPublic;
                     foreach (Attribute att in field.GetCustomAttributes(true))
                     {
                         if (att is TweakableField)
                         {
                             tweakableAttribute = att as TweakableField;
                         }
                         isSerialized |= att is SerializeField;
                         if (tweakableAttribute != null && isSerialized)
                         {
                             if ((att as TweakableField).isSharedAmongAllInstances)
                             {
                                 sharedFields.Add(field);
                             }
                             else
                             {
                                 instancedFields.Add(field);
                             }
                             break;
                         }
                     }
                     if (tweakableAttribute != null && !isSerialized)
                     {
                         Debug.LogWarning("It appears some tweakable fields aren't seralized. This is probably due to the fields being marked as private without having the [SerializeField] attribute.");
                     }
                 }
                 if (sharedFields.Count > 0 || instancedFields.Count > 0)
                 {
                     TweakableClass c = new TweakableClass();
                     c.type            = type;
                     c.sharedFields    = sharedFields.ToArray();
                     c.instancedFields = instancedFields.ToArray();
                     c.objects         = Resources.FindObjectsOfTypeAll(type);
                     UnityEngine.Object obj;
                     if (c.objects.Length > 0 && (obj = PrefabUtility.GetPrefabParent(c.objects[0])) != null)
                     {
                         c.hasPrefab = true;
                         for (int i = 0; i < c.objects.Length; i++)
                         {
                             if (c.objects[i] == obj)
                             {
                                 var tObj = c.objects[0];
                                 c.objects[0] = c.objects[i];
                                 c.objects[i] = tObj;
                                 break;
                             }
                         }
                     }
                     else
                     {
                         c.hasPrefab = false;
                     }
                     tweakables.Add(c);
                 }
             }
         }
     }
 }