protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result)
    {
#if PSR_FULL
      if(prop.name == "m_Script")
      {
        if(replaceValue.obj == null)
        {
          //don't do it.
          result.actionTaken = SearchAction.Error;
          result.replaceStrRep = "(null)";
          result.error = "Cannot set a MonoBehaviour's Script to null.";
          return;
        }
      }
      if(typeof(Component).IsAssignableFrom(type))
      {
        GameObject go = ObjectUtil.GetGameObject(prop.serializedObject.targetObject);

        UnityEngine.Object replaceVal = go.GetComponent(type);
        prop.objectReferenceValue = replaceVal;
        // prop.objectReferenceValue = replaceValue.obj;
        string objName = replaceVal == null ? "(null)" : replaceVal.ToString();
        result.replaceStrRep = objName;
      }
#endif 

    }
示例#2
0
 protected override void replace(SearchJob job, SerializedProperty prop, SearchResult result)
 {
     if (subItem != null)
     {
         UnityEngine.Object originalObj = prop.serializedObject.targetObject;
         // figure out how this object relates to our replace object.
         FieldData          fd          = initializationContext.fieldData;
         SerializedProperty replaceProp = null;
         if (fd.objectType == originalObj.GetType())
         {
             // easy enough! they match.
             replaceProp = prop.serializedObject.FindProperty(fd.fieldName);
         }
         else
         {
             GameObject go = ObjectUtil.GetGameObject(originalObj);
             if (go != null)
             {
                 Component c = go.GetComponent(fd.objectType);
                 if (c != null)
                 {
                     SerializedObject so = new SerializedObject(c);
                     replaceProp = so.FindProperty(fd.fieldName);
                 }
             }
         }
         if (replaceProp != null)
         {
             result.pathInfo = PathInfo.GetPathInfo(replaceProp.serializedObject.targetObject, job);
             result.strRep   = subItem.StringValueFor(replaceProp);
             subItem.ReplaceInternal(job, replaceProp, result);
             replaceProp.serializedObject.ApplyModifiedProperties();
             // This is pretty slow. We may want to find a better solution.
             if (PrefabUtil.isInstanceModification(replaceProp))
             {
                 PrefabUtility.RecordPrefabInstancePropertyModifications(replaceProp.serializedObject.targetObject);
             }
         }
     }
 }
示例#3
0
 // utility function to get a game object from this object if possible.
 public GameObject GetGameObject()
 {
     return(ObjectUtil.GetGameObject(obj));
 }