public void Draw(SearchOptions options)
        {
            // GUILayout.Space(2);

            GUILayout.BeginHorizontal();
            SRWindow.Instance.CVS();
            GUILayout.BeginHorizontal();

            float lw = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = SRWindow.compactLabelWidth;
            ProjectScope newProjectScope = (ProjectScope)EditorGUILayout.EnumPopup("Scope:", projectScope);

            if (newProjectScope != projectScope)
            {
                projectScope = newProjectScope;
                SRWindow.Instance.PersistCurrentSearch();
            }
            if (projectScope == ProjectScope.SpecificLocation)
            {
                //Display interface for selecting a folder or scene.
                EditorGUIUtility.labelWidth = SRWindow.compactLabelWidth + 10;

                UnityEngine.Object newValue = EditorGUILayout.ObjectField(objID.obj, typeof(UnityEngine.Object), true);
                if (newValue != objID.obj)
                {
                    objID.SetObject(newValue);
                    SRWindow.Instance.PersistCurrentSearch();
                }
                GUILayout.EndHorizontal();

                if (objID.isDirectory)
                {
                    drawAssetScope();
                }
            }
            else if (projectScope == ProjectScope.SceneView)
            {
                //Don't display scope.
                GUILayout.EndHorizontal();
            }
            else if (projectScope == ProjectScope.CurrentSelection)
            {
                GUILayout.EndHorizontal();
            }
            else
            {
                //scope only.
                GUILayout.EndHorizontal();
                drawAssetScope();
            }
            EditorGUIUtility.labelWidth = lw; // i love stateful gui! :(

            SRWindow.Instance.CVE();
            GUILayout.EndHorizontal();
            drawDependencySelector();
        }
Beispiel #2
0
    public override void Draw()
    {
#if PSR_FULL
      GUILayout.BeginHorizontal();
      Type fieldType = type != null ? type : typeof(UnityEngine.Object);

      GUILayout.Label(Keys.Replace, GUILayout.Width(SRWindow.compactLabelWidthNP));
      UnityEngine.Object newObj = EditorGUILayout.ObjectField( objID.obj, fieldType, true);

      if(newObj != null)
      {
        if(!fieldType.IsAssignableFrom(newObj.GetType()))
        {
          // Debug.Log("[ReplaceItemObject] nulling out!"+newObj.GetType() + " : " +fieldType );
          newObj = null;
        }else
        if(!PrefabUtil.isPrefab(newObj))
        {
          Debug.Log("[Search & Replace] "+ newObj.name + " is not a prefab.");
          newObj = null;
        }
      }
      if(objID.obj != newObj)
      {
        objID.SetObject(newObj);
        SRWindow.Instance.PersistCurrentSearch();
      }
      drawSwap();
      GUILayout.EndHorizontal();
      GUILayout.BeginHorizontal();
      GUILayout.Space(SRWindow.compactLabelWidth);
      GUILayout.BeginVertical();
      bool newRename = EditorGUILayout.Toggle("Keep Name", rename);
      {
        if(newRename != rename)
        {
          rename = newRename;
          SRWindow.Instance.PersistCurrentSearch();
        }
      }
      bool newUpdateTransform = EditorGUILayout.Toggle("Keep Transform Values", updateTransform);
      {
        if(newUpdateTransform != updateTransform)
        {
          updateTransform = newUpdateTransform;
          SRWindow.Instance.PersistCurrentSearch();
        }
      }
      GUILayout.EndVertical();
      GUILayout.EndHorizontal();

#endif
    }
Beispiel #3
0
        public override void Draw(SearchOptions options)
        {
            GUILayout.BeginHorizontal(SRWindow.searchBox);
            SRWindow.Instance.CVS();
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            float lw = EditorGUIUtility.labelWidth;

            EditorGUIUtility.labelWidth = SRWindow.compactLabelWidth;

            UnityEngine.Object newObj = (UnityEngine.Object)EditorGUILayout.ObjectField("Prefab:", objID.obj, typeof(UnityEngine.Object), true, GUILayout.MaxWidth(SRWindow.Instance.position.width - SRWindow.boxPad));
            EditorGUIUtility.labelWidth = lw; // i love stateful gui! :(

            if (objID.obj != newObj)
            {
                newObj = PrefabUtil.getPrefabRoot(newObj);

                objID.SetObject(newObj);
                searchValid = validateSearch(objID.obj);
                SRWindow.Instance.PersistCurrentSearch();
            }
            GUILayout.EndHorizontal();

            DrawValidSearch(searchValid, objID.obj);
#if PSR_FULL
            if (options.searchType == SearchType.SearchAndReplace)
            {
                replaceItem.Draw();
            }
#endif


            drawAddRemoveButtons();
            GUILayout.EndVertical();
            SRWindow.Instance.CVE();

            GUILayout.EndHorizontal();
        }
        public override void Draw()
        {
#if PSR_FULL
            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();

            float lw = EditorGUIUtility.labelWidth;
            EditorGUIUtility.labelWidth = SRWindow.compactLabelWidth;
            UnityEngine.Object newObj = EditorGUILayout.ObjectField(Keys.Replace, objID.obj, typeof(UnityEngine.Object), true);
            EditorGUIUtility.labelWidth = lw; // i love stateful gui! :(

            if (objID.obj != newObj)
            {
                newObj = PrefabUtil.getPrefabRoot(newObj);
                objID.SetObject(newObj);
                searchValid = parentSearchItem.validateSearch(objID.obj);
                SRWindow.Instance.PersistCurrentSearch();
            }
            if (GUILayout.Button(GUIContent.none, SRWindow.swapToggle))
            {
                parentSearchItem.Swap();
            }
            GUILayout.EndHorizontal();
            parentSearchItem.DrawValidSearch(searchValid, objID.obj);
            GUILayout.EndVertical();

            GUILayout.BeginHorizontal();
            GUILayout.Space(SRWindow.compactLabelWidth);
            GUILayout.BeginVertical();
            bool newRename = EditorGUILayout.Toggle("Keep Name", rename);
            {
                if (newRename != rename)
                {
                    rename = newRename;
                    SRWindow.Instance.PersistCurrentSearch();
                }
            }
            bool newUpdateTransform = EditorGUILayout.Toggle("Keep Transform Values", updateTransform);
            {
                if (newUpdateTransform != updateTransform)
                {
                    updateTransform = newUpdateTransform;
                    SRWindow.Instance.PersistCurrentSearch();
                }
            }

            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
#endif
        }
Beispiel #5
0
        public static bool ValidateAndAssign(UnityEngine.Object newObj, ObjectID objID, PropertyPopupData searchProperty, ref InitializationContext initializationContext)
        {
            // First we need to attempt validation, or find the 'real' object we are
            // interested in.
            UnityEngine.Object contextObj = newObj;
            bool objectValid = true;

            // If the object is a 'scene' object, let's get the prefab object if it
            // exists.
            if (newObj != null)
            {
                if (newObj.GetInstanceID() < 0)
                {
                    // Debug.Log("[SearchItemProperty] finding prefab.");
#if UNITY_2018_2_OR_NEWER
                    UnityEngine.Object prefab = PrefabUtility.GetCorrespondingObjectFromSource(newObj);
#else
                    UnityEngine.Object prefab = PrefabUtility.GetPrefabParent(newObj);
#endif
                    if (prefab != null)
                    {
                        newObj = prefab;
                    }
                }
                PrefabTypes newObjPrefabType = PrefabUtil.GetPrefabType(newObj);
                if (newObjPrefabType == PrefabTypes.NotAPrefab)
                {
                    if (newObj is Component)
                    {
                        if (newObj is MonoBehaviour)
                        {
                            MonoScript script = MonoScript.FromMonoBehaviour((MonoBehaviour)newObj);
                            if (script != null)
                            {
                                newObj = script;
                            }
                        }
                    }
                }
            }

            if (newObj is MonoScript)
            {
                MonoScript m = (MonoScript)newObj;
                if (typeof(MonoBehaviour).IsAssignableFrom(m.GetClass()) || typeof(ScriptableObject).IsAssignableFrom(m.GetClass()))
                {
                    // Debug.Log("[SearchItemProperty] Valid monobehaviour"+m.GetClass());
                }
                else
                {
                    Debug.LogWarning("[Search And Replace] The object given does not contain a script.");
                    objectValid = false;
                }
            }

            //Ok, validation is complete, let's process the new object.
            if (objectValid)
            {
                objID.SetObject(newObj);
                searchProperty.SetType(objID.obj);
                initializationContext             = new InitializationContext(searchProperty.fieldData, contextObj);
                initializationContext.forceUpdate = true;
                SRWindow.Instance.PersistCurrentSearch();
                return(true);
            }
            return(false);
        }