private UnityEngine.Object getValue(Rect position, SerializedProperty property, SerializedProperty idProp, SerializedProperty pathProp)
 {
     UnityEngine.Object obj = null;
     if (idProp.intValue > 0)
     {
         InstanceManager manager = (property.serializedObject.targetObject as Component).gameObject.scene.findInstance <InstanceManager>();
         if (manager != null)
         {
             SavableInstance instance = manager.getInstanceById(idProp.intValue);
             if (!string.IsNullOrEmpty(pathProp.stringValue))
             {
                 GameObject child = instance.findChild(pathProp.stringValue);
                 if (child != null)
                 {
                     if (_refType == typeof(GameObject))
                     {
                         obj = child;
                     }
                     else
                     {
                         obj = child.GetComponent(_refType);
                     }
                 }
             }
             else
             {
                 if (_refType == typeof(GameObject))
                 {
                     obj = instance.gameObject;
                 }
                 else
                 {
                     obj = instance.GetComponent(_refType);
                 }
             }
         }
         else
         {
             GUI.Box(position, "场景里没有" + nameof(InstanceManager));
             obj = null;
         }
     }
     else if (!string.IsNullOrEmpty(pathProp.stringValue))
     {
         Scene      scene = (property.serializedObject.targetObject as Component).gameObject.scene;
         GameObject child = scene.findGameObjectAt(pathProp.stringValue);
         if (child != null)
         {
             if (_refType == typeof(GameObject))
             {
                 obj = child;
             }
             else
             {
                 obj = child.GetComponent(_refType);
             }
         }
     }
     return(obj);
 }
Ejemplo n.º 2
0
 public T findInstanceIn <T>(InstanceManager manager)
 {
     if (id > 0)
     {
         SavableInstance instance = manager.getInstanceById(id);
         if (string.IsNullOrEmpty(path))
         {
             return(instance.GetComponent <T>());
         }
         else
         {
             string[]  names = path.Split('/');
             Transform child = instance.transform;
             for (int i = 0; i < names.Length; i++)
             {
                 child = child.Find(names[i]);
             }
             if (child != null)
             {
                 return(child.GetComponent <T>());
             }
             else
             {
                 return(default);