Author Topic: Multi-object editing  (Read 4233 times)

eldee

  • Guest
Multi-object editing
« on: September 01, 2012, 10:08:21 PM »
Hi, just curious if there are plans to update the editor scripts to use unity 3.5's CanEditMultipleObjects? There are a lot of times where I need to change a common property on several objects (such as the atlas, sprite, color, or depth) but need to do it individually. Just curious! Thanks!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multi-object editing
« Reply #1 on: September 01, 2012, 10:51:56 PM »
Yeah it's on the list.

Dark Acre Jack

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 8
  • Cyberdrunk
    • View Profile
    • Dark Acre Games
Re: Multi-object editing
« Reply #2 on: January 07, 2014, 04:49:27 PM »
Bump.

Is there any quick fix for this? I'm pretty shaky on Editor modifying. I have dozens of Tween Alpha objects that need to get a lot of standard values and testing with mass-changes.

Cheers, keep up the great work.

AtomicBob

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 69
    • View Profile
Re: Multi-object editing
« Reply #3 on: January 08, 2014, 10:53:16 AM »
I know you said you're shaky on Editor modifying, but I'd say it's worthwhile to learn a bit about it. You can make a simple EditorWindow that can iterate through all the currently selected objects and modify them. You can learn how to do it in probably an afternoon and once you have, it takes about 10 minutes to implement something. If you don't like having to select things, you can use a tag or create a helper script that can be searched for. For example, tag all your TweenAlphas with 'TAType1' or something and just search for the tag, or have a script with just a Type enum to search for.

Here's a rough example I made yesterday to find and change all UIPanels in the scene:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEditor;
  5. using UnityEngine;
  6.  
  7. public class ChangeAllPanels : EditorWindow
  8. {
  9.         #region Fields & Structs
  10.  
  11.         private PanelSettings panelSettings = new PanelSettings();
  12.  
  13.         private class PanelSettings
  14.         {
  15.                 public int renderQ = 3000;
  16.                 public UIPanel.RenderQueue renderQSetting = UIPanel.RenderQueue.Automatic;
  17.         }
  18.  
  19.         #endregion
  20.  
  21.         #region Functionality
  22.  
  23.         private void ApplyPanelSettings ()
  24.         {
  25.                 Debug.Log("Applying UIPanel Settings");
  26.                 List<UIPanel> panels = GetAllObjectsInScene<UIPanel>();
  27.  
  28.                 foreach ( var p in panels )
  29.                 {
  30.                         Undo.RecordObject(p, "Apply Panel Settings");
  31.  
  32.                         p.startingRenderQueue = panelSettings.renderQ;
  33.                         p.renderQueue = panelSettings.renderQSetting;
  34.  
  35.                         EditorUtility.SetDirty(p);
  36.                 }
  37.         }
  38.  
  39.         public static List<T> GetAllObjectsInScene<T> () where T : Component
  40.         {
  41.                 var compsInScene = Resources.FindObjectsOfTypeAll<T>().ToList();
  42.  
  43.                 for ( int i = compsInScene.Count-1; i >= 0; --i )
  44.                 {
  45.                         T comp = compsInScene[i];
  46.  
  47.                         if ( ( comp.hideFlags & HideFlags.NotEditable ) == HideFlags.NotEditable
  48.                           || ( comp.hideFlags & HideFlags.HideAndDontSave ) == HideFlags.HideAndDontSave
  49.                           || !String.IsNullOrEmpty(AssetDatabase.GetAssetPath(comp.transform.root.gameObject)) )
  50.                                 compsInScene.RemoveAt(i);
  51.                 }
  52.  
  53.                 return compsInScene;
  54.         }
  55.  
  56.         #endregion
  57.  
  58.         #region GUI/Window Methods
  59.  
  60.         private void OnGUI ()
  61.         {
  62.                 PanelSettings ps = panelSettings;
  63.                 ps.renderQ = EditorGUILayout.IntField("Render Q", ps.renderQ);
  64.                 ps.renderQSetting = (UIPanel.RenderQueue) EditorGUILayout.EnumPopup("Render Q Setting", ps.renderQSetting);
  65.  
  66.                 if ( GUILayout.Button("Apply") )
  67.                         ApplyPanelSettings();
  68.         }
  69.  
  70.         #endregion
  71.  
  72.         #region Helper Methods
  73.  
  74.         [MenuItem("Pixel Dash/NGUI/Change All UIPanel Settings %#p")]
  75.         private static void CreateWindow ()
  76.         {
  77.                 GetWindow<ChangeAllPanels>(true, "Change All UIPanel Settings");
  78.         }
  79.  
  80.         #endregion
  81. }
« Last Edit: January 08, 2014, 12:20:20 PM by AtomicBob »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Multi-object editing
« Reply #4 on: January 08, 2014, 12:18:25 PM »
Most NGUI elements are multi-editable. Some are not. Tweens aren't. I update them as I find them.