예제 #1
0
        internal void Create(GameObject[] gameObjects)
        {
            if (!CanCreate())
            {
                return;
            }

            CreateScript();

            foreach (var go in gameObjects)
            {
                var script = AssetDatabase.LoadAssetAtPath(TargetPath(), typeof(MonoScript)) as MonoScript;
                script.SetScriptTypeWasJustCreatedFromComponentMenu();
                InternalEditorUtility.AddScriptComponentUncheckedUndoable(go, script);
            }

            AddComponentWindow.SendUsabilityAnalyticsEvent(new AddComponentWindow.AnalyticsEventData
            {
                name        = m_ClassName,
                filter      = AddComponentWindow.s_AddComponentWindow.searchString,
                isNewScript = true
            });

            AddComponentWindow.s_AddComponentWindow.Close();
        }
        internal static bool Show(Rect rect, GameObject[] gos)
        {
            UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(AddComponentWindow));
            bool result;

            if (array.Length > 0)
            {
                ((EditorWindow)array[0]).Close();
                result = false;
            }
            else
            {
                long num = DateTime.Now.Ticks / 10000L;
                if (num >= AddComponentWindow.s_LastClosedTime + 50L)
                {
                    Event.current.Use();
                    if (AddComponentWindow.s_AddComponentWindow == null)
                    {
                        AddComponentWindow.s_AddComponentWindow = ScriptableObject.CreateInstance <AddComponentWindow>();
                    }
                    AddComponentWindow.s_AddComponentWindow.Init(rect);
                    AddComponentWindow.s_AddComponentWindow.m_GameObjects = gos;
                    result = true;
                }
                else
                {
                    result = false;
                }
            }
            return(result);
        }
예제 #3
0
 internal static bool Show(Rect rect, GameObject[] gos)
 {
     AddComponentWindow.CloseAllOpenWindows <AddComponentWindow>();
     Event.current.Use();
     AddComponentWindow.s_AddComponentWindow = AdvancedDropdownWindow.CreateAndInit <AddComponentWindow>(rect);
     AddComponentWindow.s_AddComponentWindow.m_GameObjects       = gos;
     AddComponentWindow.s_AddComponentWindow.m_ComponentOpenTime = DateTime.UtcNow;
     return(true);
 }
예제 #4
0
 protected override void OnEnable()
 {
     base.OnEnable();
     gui                  = new AddComponentGUI();
     dataSource           = new AddComponentDataSource();
     s_AddComponentWindow = this;
     m_Search             = EditorPrefs.GetString(kComponentSearch, "");
     showHeader           = true;
 }
        internal static void ExecuteAddComponentMenuItem()
        {
            InspectorWindow inspectorWindow = AddComponentWindow.FirstInspectorWithGameObject();

            if (inspectorWindow != null)
            {
                inspectorWindow.SendEvent(EditorGUIUtility.CommandEvent("OpenAddComponentDropdown"));
            }
        }
        internal static void ExecuteAddComponentMenuItem()
        {
            InspectorWindow inspectorWindow = AddComponentWindow.FirstInspectorWithGameObject();

            if (!((UnityEngine.Object)inspectorWindow != (UnityEngine.Object)null))
            {
                return;
            }
            inspectorWindow.SendEvent(EditorGUIUtility.CommandEvent("OpenAddComponentDropdown"));
        }
 private void OnEnable()
 {
     AddComponentWindow.s_AddComponentWindow = this;
     AddComponentWindow.s_Lang = (AddComponentWindow.Language)EditorPrefs.GetInt("NewScriptLanguage", 0);
     if (!Enum.IsDefined(typeof(AddComponentWindow.Language), AddComponentWindow.s_Lang))
     {
         EditorPrefs.SetInt("NewScriptLanguage", 0);
         AddComponentWindow.s_Lang = AddComponentWindow.Language.CSharp;
     }
     this.m_Search = EditorPrefs.GetString("ComponentSearchString", "");
 }
 public override bool OnAction()
 {
     AddComponentWindow.SendUsabilityAnalyticsEvent(new AddComponentWindow.AnalyticsEventData
     {
         name        = base.name,
         filter      = AddComponentWindow.s_AddComponentWindow.searchString,
         isNewScript = false
     });
     GameObject[] gameObjects = AddComponentWindow.s_AddComponentWindow.m_GameObjects;
     EditorApplication.ExecuteMenuItemOnGameObjects(this.m_MenuPath, gameObjects);
     return(true);
 }
예제 #9
0
 private void Create(GameObject[] gameObjects)
 {
     if (this.CanCreate())
     {
         this.CreateScript();
         for (int i = 0; i < gameObjects.Length; i++)
         {
             GameObject gameObject = gameObjects[i];
             MonoScript monoScript = AssetDatabase.LoadAssetAtPath(this.TargetPath(), typeof(MonoScript)) as MonoScript;
             monoScript.SetScriptTypeWasJustCreatedFromComponentMenu();
             InternalEditorUtility.AddScriptComponentUncheckedUndoable(gameObject, monoScript);
         }
         AddComponentWindow.SendUsabilityAnalyticsEvent(new AddComponentWindow.AnalyticsEventData
         {
             name        = this.m_ClassName,
             filter      = AddComponentWindow.s_AddComponentWindow.searchString,
             isNewScript = true
         });
         AddComponentWindow.s_AddComponentWindow.Close();
     }
 }
예제 #10
0
 internal static bool Show(Rect rect, GameObject[] gos)
 {
     UnityEngine.Object[] objectsOfTypeAll = Resources.FindObjectsOfTypeAll(typeof(AddComponentWindow));
     if (objectsOfTypeAll.Length > 0)
     {
         ((EditorWindow)objectsOfTypeAll[0]).Close();
         return(false);
     }
     if (DateTime.Now.Ticks / 10000L < AddComponentWindow.s_LastClosedTime + 50L)
     {
         return(false);
     }
     Event.current.Use();
     if ((UnityEngine.Object)AddComponentWindow.s_AddComponentWindow == (UnityEngine.Object)null)
     {
         AddComponentWindow.s_AddComponentWindow = ScriptableObject.CreateInstance <AddComponentWindow>();
     }
     AddComponentWindow.s_AddComponentWindow.Init(rect);
     AddComponentWindow.s_AddComponentWindow.m_GameObjects = gos;
     return(true);
 }
		private List<AddComponentWindow.Element> GetChildren(AddComponentWindow.Element[] tree, AddComponentWindow.Element parent)
		{
			List<AddComponentWindow.Element> list = new List<AddComponentWindow.Element>();
			int num = -1;
			int i;
			for (i = 0; i < tree.Length; i++)
			{
				if (tree[i] == parent)
				{
					num = parent.level + 1;
					i++;
					break;
				}
			}
			if (num == -1)
			{
				return list;
			}
			while (i < tree.Length)
			{
				AddComponentWindow.Element element = tree[i];
				if (element.level < num)
				{
					break;
				}
				if (element.level <= num || this.hasSearch)
				{
					list.Add(element);
				}
				i++;
			}
			return list;
		}
 static AddComponentWindow()
 {
     AddComponentWindow.s_AddComponentWindow = null;
     AddComponentWindow.s_DirtyList          = false;
     AddComponentWindow.s_DirtyList          = true;
 }
예제 #13
0
 protected override void OnDisable()
 {
     s_AddComponentWindow = null;
     EditorPrefs.SetString(kComponentSearch, m_Search);
 }
 private List<AddComponentWindow.Element> GetChildren(AddComponentWindow.Element[] tree, AddComponentWindow.Element parent)
 {
   List<AddComponentWindow.Element> elementList = new List<AddComponentWindow.Element>();
   int num = -1;
   int index;
   for (index = 0; index < tree.Length; ++index)
   {
     if (tree[index] == parent)
     {
       num = parent.level + 1;
       ++index;
       break;
     }
   }
   if (num == -1)
     return elementList;
   for (; index < tree.Length; ++index)
   {
     AddComponentWindow.Element element = tree[index];
     if (element.level >= num)
     {
       if (element.level <= num || this.hasSearch)
         elementList.Add(element);
     }
     else
       break;
   }
   return elementList;
 }
 private void ListGUI(AddComponentWindow.Element[] tree, AddComponentWindow.GroupElement parent)
 {
   parent.scroll = GUILayout.BeginScrollView(parent.scroll);
   EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
   List<AddComponentWindow.Element> children = this.GetChildren(tree, (AddComponentWindow.Element) parent);
   Rect rect1 = new Rect();
   for (int index = 0; index < children.Count; ++index)
   {
     AddComponentWindow.Element e = children[index];
     Rect rect2 = GUILayoutUtility.GetRect(16f, 20f, new GUILayoutOption[1]{ GUILayout.ExpandWidth(true) });
     if ((Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown) && (parent.selectedIndex != index && rect2.Contains(Event.current.mousePosition)))
     {
       parent.selectedIndex = index;
       this.Repaint();
     }
     bool flag = false;
     if (index == parent.selectedIndex)
     {
       flag = true;
       rect1 = rect2;
     }
     if (Event.current.type == EventType.Repaint)
     {
       (!(e is AddComponentWindow.ComponentElement) ? AddComponentWindow.s_Styles.groupButton : AddComponentWindow.s_Styles.componentButton).Draw(rect2, e.content, false, false, flag, flag);
       if (!(e is AddComponentWindow.ComponentElement))
       {
         Rect position = new Rect((float) ((double) rect2.x + (double) rect2.width - 13.0), rect2.y + 4f, 13f, 13f);
         AddComponentWindow.s_Styles.rightArrow.Draw(position, false, false, false, false);
       }
     }
     if (Event.current.type == EventType.MouseDown && rect2.Contains(Event.current.mousePosition))
     {
       Event.current.Use();
       parent.selectedIndex = index;
       this.GoToChild(e, true);
     }
   }
   EditorGUIUtility.SetIconSize(Vector2.zero);
   GUILayout.EndScrollView();
   if (!this.m_ScrollToSelected || Event.current.type != EventType.Repaint)
     return;
   this.m_ScrollToSelected = false;
   Rect lastRect = GUILayoutUtility.GetLastRect();
   if ((double) rect1.yMax - (double) lastRect.height > (double) parent.scroll.y)
   {
     parent.scroll.y = rect1.yMax - lastRect.height;
     this.Repaint();
   }
   if ((double) rect1.y >= (double) parent.scroll.y)
     return;
   parent.scroll.y = rect1.y;
   this.Repaint();
 }
 private void ListGUI(AddComponentWindow.Element[] tree, float anim, AddComponentWindow.GroupElement parent, AddComponentWindow.GroupElement grandParent)
 {
   anim = Mathf.Floor(anim) + Mathf.SmoothStep(0.0f, 1f, Mathf.Repeat(anim, 1f));
   Rect position1 = this.position;
   position1.x = (float) ((double) this.position.width * (1.0 - (double) anim) + 1.0);
   position1.y = 30f;
   position1.height -= 30f;
   position1.width -= 2f;
   GUILayout.BeginArea(position1);
   Rect rect = GUILayoutUtility.GetRect(10f, 25f);
   string name = parent.name;
   GUI.Label(rect, name, AddComponentWindow.s_Styles.header);
   if (grandParent != null)
   {
     Rect position2 = new Rect(rect.x + 4f, rect.y + 7f, 13f, 13f);
     if (Event.current.type == EventType.Repaint)
       AddComponentWindow.s_Styles.leftArrow.Draw(position2, false, false, false, false);
     if (Event.current.type == EventType.MouseDown && rect.Contains(Event.current.mousePosition))
     {
       this.GoToParent();
       Event.current.Use();
     }
   }
   if (parent is AddComponentWindow.NewScriptElement)
     (parent as AddComponentWindow.NewScriptElement).OnGUI();
   else
     this.ListGUI(tree, parent);
   GUILayout.EndArea();
 }
 private void GoToChild(AddComponentWindow.Element e, bool addIfComponent)
 {
   if (e is AddComponentWindow.NewScriptElement && !this.hasSearch)
   {
     this.m_ClassName = AssetDatabase.GenerateUniqueAssetPath((e as AddComponentWindow.NewScriptElement).TargetPath());
     this.m_ClassName = Path.GetFileNameWithoutExtension(this.m_ClassName);
   }
   if (e is AddComponentWindow.ComponentElement)
   {
     if (!addIfComponent)
       return;
     EditorApplication.ExecuteMenuItemOnGameObjects(((AddComponentWindow.ComponentElement) e).menuPath, this.m_GameObjects);
     this.Close();
   }
   else
   {
     if (this.hasSearch && !(e is AddComponentWindow.NewScriptElement))
       return;
     this.m_LastTime = DateTime.Now.Ticks;
     if (this.m_AnimTarget == 0)
     {
       this.m_AnimTarget = 1;
     }
     else
     {
       if ((double) this.m_Anim != 1.0)
         return;
       this.m_Anim = 0.0f;
       this.m_Stack.Add(e as AddComponentWindow.GroupElement);
     }
   }
 }
 internal static bool Show(Rect rect, GameObject[] gos)
 {
   UnityEngine.Object[] objectsOfTypeAll = Resources.FindObjectsOfTypeAll(typeof (AddComponentWindow));
   if (objectsOfTypeAll.Length > 0)
   {
     ((EditorWindow) objectsOfTypeAll[0]).Close();
     return false;
   }
   if (DateTime.Now.Ticks / 10000L < AddComponentWindow.s_LastClosedTime + 50L)
     return false;
   Event.current.Use();
   if ((UnityEngine.Object) AddComponentWindow.s_AddComponentWindow == (UnityEngine.Object) null)
     AddComponentWindow.s_AddComponentWindow = ScriptableObject.CreateInstance<AddComponentWindow>();
   AddComponentWindow.s_AddComponentWindow.Init(rect);
   AddComponentWindow.s_AddComponentWindow.m_GameObjects = gos;
   return true;
 }
		private void ListGUI(AddComponentWindow.Element[] tree, AddComponentWindow.GroupElement parent)
		{
			parent.scroll = GUILayout.BeginScrollView(parent.scroll, new GUILayoutOption[0]);
			EditorGUIUtility.SetIconSize(new Vector2(16f, 16f));
			List<AddComponentWindow.Element> children = this.GetChildren(tree, parent);
			Rect rect = default(Rect);
			for (int i = 0; i < children.Count; i++)
			{
				AddComponentWindow.Element element = children[i];
				Rect rect2 = GUILayoutUtility.GetRect(16f, 20f, new GUILayoutOption[]
				{
					GUILayout.ExpandWidth(true)
				});
				if ((Event.current.type == EventType.MouseMove || Event.current.type == EventType.MouseDown) && parent.selectedIndex != i && rect2.Contains(Event.current.mousePosition))
				{
					parent.selectedIndex = i;
					base.Repaint();
				}
				bool flag = false;
				if (i == parent.selectedIndex)
				{
					flag = true;
					rect = rect2;
				}
				if (Event.current.type == EventType.Repaint)
				{
					GUIStyle gUIStyle = (!(element is AddComponentWindow.ComponentElement)) ? AddComponentWindow.s_Styles.groupButton : AddComponentWindow.s_Styles.componentButton;
					gUIStyle.Draw(rect2, element.content, false, false, flag, flag);
					if (!(element is AddComponentWindow.ComponentElement))
					{
						Rect position = new Rect(rect2.x + rect2.width - 13f, rect2.y + 4f, 13f, 13f);
						AddComponentWindow.s_Styles.rightArrow.Draw(position, false, false, false, false);
					}
				}
				if (Event.current.type == EventType.MouseDown && rect2.Contains(Event.current.mousePosition))
				{
					Event.current.Use();
					parent.selectedIndex = i;
					this.GoToChild(element, true);
				}
			}
			EditorGUIUtility.SetIconSize(Vector2.zero);
			GUILayout.EndScrollView();
			if (this.m_ScrollToSelected && Event.current.type == EventType.Repaint)
			{
				this.m_ScrollToSelected = false;
				Rect lastRect = GUILayoutUtility.GetLastRect();
				if (rect.yMax - lastRect.height > parent.scroll.y)
				{
					parent.scroll.y = rect.yMax - lastRect.height;
					base.Repaint();
				}
				if (rect.y < parent.scroll.y)
				{
					parent.scroll.y = rect.y;
					base.Repaint();
				}
			}
		}
 private void OnDisable()
 {
     AddComponentWindow.s_LastClosedTime     = DateTime.Now.Ticks / 10000L;
     AddComponentWindow.s_AddComponentWindow = null;
 }
예제 #21
0
 internal static bool ValidateAddComponentMenuItem()
 {
     return((UnityEngine.Object)AddComponentWindow.FirstInspectorWithGameObject() != (UnityEngine.Object)null);
 }
예제 #22
0
 protected override void OnDisable()
 {
     AddComponentWindow.s_AddComponentWindow = null;
     EditorPrefs.SetString("ComponentSearchString", this.m_Search);
 }
예제 #23
0
 protected override void OnEnable()
 {
     base.OnEnable();
     AddComponentWindow.s_AddComponentWindow = this;
     this.m_Search = EditorPrefs.GetString("ComponentSearchString", "");
 }
 internal static bool ValidateAddComponentMenuItem()
 {
     return(AddComponentWindow.FirstInspectorWithGameObject() != null);
 }
 private void OnEnable()
 {
   AddComponentWindow.s_AddComponentWindow = this;
   AddComponentWindow.s_Lang = (AddComponentWindow.Language) EditorPrefs.GetInt("NewScriptLanguage", 0);
   if (!Enum.IsDefined(typeof (AddComponentWindow.Language), (object) AddComponentWindow.s_Lang))
   {
     EditorPrefs.SetInt("NewScriptLanguage", 0);
     AddComponentWindow.s_Lang = AddComponentWindow.Language.CSharp;
   }
   this.m_Search = EditorPrefs.GetString("ComponentSearchString", string.Empty);
 }
 private void OnDisable()
 {
   AddComponentWindow.s_LastClosedTime = DateTime.Now.Ticks / 10000L;
   AddComponentWindow.s_AddComponentWindow = (AddComponentWindow) null;
 }
		internal static bool Show(Rect rect, GameObject[] gos)
		{
			UnityEngine.Object[] array = Resources.FindObjectsOfTypeAll(typeof(AddComponentWindow));
			if (array.Length > 0)
			{
				((EditorWindow)array[0]).Close();
				return false;
			}
			long num = DateTime.Now.Ticks / 10000L;
			if (num >= AddComponentWindow.s_LastClosedTime + 50L)
			{
				Event.current.Use();
				if (AddComponentWindow.s_AddComponentWindow == null)
				{
					AddComponentWindow.s_AddComponentWindow = ScriptableObject.CreateInstance<AddComponentWindow>();
				}
				AddComponentWindow.s_AddComponentWindow.Init(rect);
				AddComponentWindow.s_AddComponentWindow.m_GameObjects = gos;
				return true;
			}
			return false;
		}