Skip to content

Commit

Permalink
Update to Unity 2019.2
Browse files Browse the repository at this point in the history
Add a new enum Inspector.
Upgrade to 2019.2
Add level test mode.
"This version use the project sub directorys"
  • Loading branch information
FALsGames committed Sep 15, 2019
1 parent 8e55e10 commit 4330922
Show file tree
Hide file tree
Showing 61 changed files with 4,218 additions and 5,351 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override void InitializeGUI()

_transform = (Transform) target;

pb_TypeInspector position_inspector = pb_InspectorResolver.GetInspector(typeof(Vector3));
pb_TypeInspector position_inspector = pb_InspectorResolver.GetInspector(typeof(Vector3));
pb_TypeInspector rotation_inspector = pb_InspectorResolver.GetInspector(typeof(Vector3));
pb_TypeInspector scale_inspector = pb_InspectorResolver.GetInspector(typeof(Vector3));

Expand Down Expand Up @@ -53,10 +53,13 @@ object UpdatePosition(int index)

void OnSetPosition(int index, object value)
{
_transform.position = (Vector3) value;
pb_Selection.OnExternalUpdate();
if (value != null)
{
_transform.position = (Vector3)value;
pb_Selection.OnExternalUpdate();

pb_ComponentDiff.AddDiff(target, "position", _transform.position);
pb_ComponentDiff.AddDiff(target, "position", _transform.position);
}
}

object UpdateRotation(int index)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace GILES.Interface
[pb_TypeInspector(typeof(object))]
public class pb_ObjectInspector : pb_TypeInspector
{
object value;
object value;

//private static readonly RectOffset RectOffset_Zero = new RectOffset(0,0,0,0);
private const int VERTICAL_LAYOUT_SPACING = 0;
Expand All @@ -25,11 +25,11 @@ void OnGUIChanged()

public override void InitializeGUI()
{
value = GetValue<object>();
value = GetValue<object>();

pb_GUIUtility.AddVerticalLayoutGroup(gameObject, new RectOffset(0,0,0,0), VERTICAL_LAYOUT_SPACING, true, false);
pb_GUIUtility.AddVerticalLayoutGroup(gameObject, new RectOffset(0, 0, 0, 0), VERTICAL_LAYOUT_SPACING, true, false);

BuildInspectorTree();
BuildInspectorTree();
}

protected override void OnUpdateGUI()
Expand Down Expand Up @@ -66,4 +66,5 @@ void BuildInspectorTree()
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace GILES.Interface
[pb_TypeInspector(typeof(Vector3))]
public class pb_Vector3Inspector : pb_TypeInspector
{
Vector3 vector;
Vector3 vector = new Vector3();

public UnityEngine.UI.Text title;

Expand Down Expand Up @@ -41,7 +41,7 @@ public override void InitializeGUI()

protected override void OnUpdateGUI()
{
vector = GetValue<Vector3>();
vector = GetValue<Vector3>();

input_x.text = vector.x.ToString();
input_y.text = vector.y.ToString();
Expand Down
214 changes: 114 additions & 100 deletions Assets/GILES/Code/Classes/GUI/pb_InspectorResolver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,121 +8,135 @@

namespace GILES.Interface
{
/**
/**
* Used by pb_TypeInspector to find the appropriate inspector subclasses to draw
* the inspector GUI.
*/
public static class pb_InspectorResolver
{
public const string TYPE_INSPECTOR_PATH = "Required/GUI/TypeInspector";
public static class pb_InspectorResolver
{
public const string TYPE_INSPECTOR_PATH = "Required/GUI/TypeInspector";

/// Link types to their respective best available pb_TypeInspector. This can include types that do not have an exact
/// inspector match, unlike inspectorLookup which only contains 1:1 matches.
private static Dictionary<Type, GameObject> inspectorPool = new Dictionary<Type, GameObject>();
/// Link types to their respective best available pb_TypeInspector. This can include types that do not have an exact
/// inspector match, unlike inspectorLookup which only contains 1:1 matches.
private static Dictionary<Type, GameObject> inspectorPool = new Dictionary<Type, GameObject>();

/// Store a lookup table of pb_TypeInspector prefabs.
private static Dictionary<IEnumerable<pb_TypeInspectorAttribute>, GameObject> inspectorLookup = null;
/// Store a lookup table of pb_TypeInspector prefabs.
private static Dictionary<pb_TypeInspectorAttribute, GameObject> inspectorLookup = null;

private static void InitializeLookup()
{
inspectorPool = new Dictionary<Type, GameObject>();
inspectorLookup = new Dictionary<IEnumerable<pb_TypeInspectorAttribute>, GameObject>();
private static void InitializeLookup()
{
inspectorPool = new Dictionary<Type, GameObject>();
inspectorLookup = new Dictionary<pb_TypeInspectorAttribute, GameObject>();

foreach(GameObject go in Resources.LoadAll(TYPE_INSPECTOR_PATH, typeof(GameObject)))
{
pb_TypeInspector typeInspector = go.GetComponent<pb_TypeInspector>();
foreach (GameObject go in Resources.LoadAll(TYPE_INSPECTOR_PATH, typeof(GameObject)))
{
pb_TypeInspector typeInspector = go.GetComponent<pb_TypeInspector>();

if(typeInspector == null)
continue;
if (typeInspector == null)
continue;

IEnumerable<Attribute> typeAttribs = (IEnumerable<Attribute>) typeInspector.GetType().GetCustomAttributes(true);
inspectorLookup.Add(typeAttribs.Where(x => x != null && x is pb_TypeInspectorAttribute).Cast<pb_TypeInspectorAttribute>(), go);
}
}
pb_TypeInspectorAttribute t = AttributeExtension.GetAttributeValue(typeInspector);
Attribute[] typeAttribs = new Attribute[1] { t };
inspectorLookup.Add(t, go);
}
}


/**
/**
* Get a type inspector that most closely matches type.
* If an exact type match is found, that inspector is returned. If no exact match is found,
* the first base class match found. If no base class is found, a generic object inspector
* is returned, which in turn will reflect the properties and fields contained and attempt to
* build inspectors for each.
*/
public static pb_TypeInspector GetInspector(Type type)
{
if( inspectorLookup == null )
InitializeLookup();

GameObject inspectorObject;

if(inspectorPool.TryGetValue(type, out inspectorObject))
return GameObject.Instantiate(inspectorObject).GetComponent<pb_TypeInspector>();

List<GameObject> inspectors = new List<GameObject>();

foreach(KeyValuePair<IEnumerable<pb_TypeInspectorAttribute>, GameObject> kvp in inspectorLookup)
{
foreach(pb_TypeInspectorAttribute attrib in kvp.Key)
{
if( attrib.CanEditType(type) )
{
if(attrib.type == type)
{
inspectors.Insert(0, kvp.Value);
goto EXACT_TYPE_INSPECTOR_FOUND;
}
else
{
inspectors.Add(kvp.Value);
}
}
}
}

EXACT_TYPE_INSPECTOR_FOUND:

if(inspectors.Count > 0)
{
inspectorPool.Add(type, inspectors[0]);
inspectorObject = GameObject.Instantiate(inspectors[0]);
pb_TypeInspector typeInspector = inspectorObject.GetComponent<pb_TypeInspector>();
typeInspector.SetDeclaringType(type);
return typeInspector;
}
else
{
GameObject go = new GameObject();
go.name = "Generic Object Inspector: " + type;
pb_TypeInspector typeInspector = go.AddComponent<pb_ObjectInspector>();
typeInspector.SetDeclaringType(type);
return typeInspector;
}
}

/**
public static pb_TypeInspector GetInspector(Type type)
{
if (inspectorLookup == null)
InitializeLookup();

GameObject inspectorObject;

if (inspectorPool.TryGetValue(type, out inspectorObject))
return GameObject.Instantiate(inspectorObject).GetComponent<pb_TypeInspector>();

List<GameObject> inspectors = new List<GameObject>();

foreach (KeyValuePair<pb_TypeInspectorAttribute, GameObject> kvp in inspectorLookup)
{
pb_TypeInspectorAttribute attrib = kvp.Key;

if (attrib.CanEditType(type))
{
if (attrib.type == type)
{
inspectors.Insert(0, kvp.Value);
goto EXACT_TYPE_INSPECTOR_FOUND;
}
else
{
inspectors.Add(kvp.Value);
}
}

}

EXACT_TYPE_INSPECTOR_FOUND:

if (inspectors.Count > 0)
{
inspectorPool.Add(type, inspectors[0]);
inspectorObject = GameObject.Instantiate(inspectors[0]);
pb_TypeInspector typeInspector = inspectorObject.GetComponent<pb_TypeInspector>();
typeInspector.SetDeclaringType(type);
return typeInspector;
}
else
{
GameObject go = new GameObject();
go.name = "Generic Object Inspector: " + type;
pb_TypeInspector typeInspector = go.AddComponent<pb_ObjectInspector>();
typeInspector.SetDeclaringType(type);
return typeInspector;
}
}

/**
* Add a new type inspector to parentTransform with a target and reflected property or field.
*/
public static pb_TypeInspector AddTypeInspector(object target, Transform parentTransform, PropertyInfo property = null, FieldInfo field = null)
{
pb_TypeInspector inspector = null;
System.Type type = property != null ? property.PropertyType : field.FieldType;

inspector = pb_InspectorResolver.GetInspector(type);

if(inspector != null)
{
if(property != null)
inspector.Initialize(target, property);
else
inspector.Initialize(target, field);

inspector.transform.SetParent(parentTransform);
}
else
{
Debug.LogError("No inspector found! Is `pb_ObjectInspector.cs` missing?");
}

return inspector;
}
}
}
public static pb_TypeInspector AddTypeInspector(object target, Transform parentTransform, PropertyInfo property = null, FieldInfo field = null)
{
pb_TypeInspector inspector = null;
System.Type type = property != null ? property.PropertyType : field.FieldType;

inspector = pb_InspectorResolver.GetInspector(type);

if (inspector != null)
{
if (property != null)
inspector.Initialize(target, property);
else
inspector.Initialize(target, field);

inspector.transform.SetParent(parentTransform);
}
else
{
Debug.LogError("No inspector found! Is `pb_ObjectInspector.cs` missing?");
}

return inspector;
}
}
public static class AttributeExtension
{
public static pb_TypeInspectorAttribute GetAttributeValue(pb_TypeInspector ti)
{
var att = ti.GetType().GetCustomAttribute(typeof (pb_TypeInspectorAttribute), true) as pb_TypeInspectorAttribute;
if (att != null && att is pb_TypeInspectorAttribute)
{
return att;
}
return null;
}
}
}
Loading

0 comments on commit 4330922

Please sign in to comment.