Browse Source

Inspector fields can be private, ResourceRef default values as CustomAttributes

Josh Engebretson 10 years ago
parent
commit
26b2650815

+ 1 - 1
Build/AtomicNET/AtomicNETEngine/ComponentCore.cs

@@ -141,7 +141,7 @@ public static class ComponentCore
 
 
     if (!componentClassFields.ContainsKey(type))
     if (!componentClassFields.ContainsKey(type))
     {
     {
-      var fields = type.GetFields()
+      var fields = type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
           .Where(field => field.IsDefined(typeof(InspectorAttribute), true));
           .Where(field => field.IsDefined(typeof(InspectorAttribute), true));
 
 
       componentClassFields[type] = fields.ToArray<FieldInfo>();
       componentClassFields[type] = fields.ToArray<FieldInfo>();

+ 22 - 3
Build/AtomicNETTest/MyClass.cs

@@ -11,13 +11,28 @@ namespace AtomicNETTest
       Neutral
       Neutral
     }
     }
 
 
+
+    public class Spinner : CSComponent
+    {
+
+        [Inspector]
+        float speed = 1.0f;
+
+        public override void Update(float timeStep)
+        {
+          Node.Yaw(timeStep * speed * 75.0f);
+
+          Console.WriteLine("TICK! : {0}", speed);
+        }
+    }
+
     public class MyComponent : CSComponent
     public class MyComponent : CSComponent
     {
     {
 
 
         public override void Update(float timeStep)
         public override void Update(float timeStep)
         {
         {
-            Node.Yaw(timeStep * 75);
-            Console.WriteLine("TICK! : {0}", MySprite2DValue.Texture.Name);
+            //Node.Yaw(timeStep * 75);
+
         }
         }
 
 
         [Inspector]
         [Inspector]
@@ -44,9 +59,13 @@ namespace AtomicNETTest
         [Inspector]
         [Inspector]
         public BehaviorState State = BehaviorState.Neutral;
         public BehaviorState State = BehaviorState.Neutral;
 
 
-        [Inspector("Sprites/star.png")]
+        [Inspector("Textures/chest.png")]
         public Sprite2D MySprite2DValue;
         public Sprite2D MySprite2DValue;
 
 
+        [Inspector(DefaultValue = "Textures/chest.png")]
+        public Sprite2D MyOtherSprite2DValue;
+
+
     }
     }
 
 
 }
 }

+ 14 - 0
Source/AtomicNET/NETCore/NETAssemblyFile.cpp

@@ -98,6 +98,20 @@ bool NETAssemblyFile::ParseComponentClassJSON(const JSONValue& json)
             String fieldName = jfield.Get("name").GetString();
             String fieldName = jfield.Get("name").GetString();
             String defaultValue = jfield.Get("defaultValue").GetString();
             String defaultValue = jfield.Get("defaultValue").GetString();
 
 
+            if (!defaultValue.Length())
+            {
+                JSONArray caPos = jfield.Get("caPos").GetArray();
+                if (caPos.Size())
+                    defaultValue = caPos[0].GetString();
+            }
+
+            if (!defaultValue.Length())
+            {
+                JSONObject caNamed = jfield.Get("caNamed").GetObject();
+                if (caNamed.Contains("DefaultValue"))
+                    defaultValue = caNamed["DefaultValue"].GetString();
+            }
+
             if (isEnum && assemblyEnums_.Contains(typeName) && !enumsAdded.Contains(fieldName))
             if (isEnum && assemblyEnums_.Contains(typeName) && !enumsAdded.Contains(fieldName))
             {
             {
                 varType = VAR_INT;
                 varType = VAR_INT;