Exemplo n.º 1
0
        private void DrawPackableElement(Rect rect, int index, bool selected, bool focused)
        {
            SerializedProperty arrayElementAtIndex = this.m_Packables.GetArrayElementAtIndex(index);
            int controlID = GUIUtility.GetControlID(SpriteAtlasInspector.s_Styles.packableElementHash, FocusType.Passive);

            UnityEngine.Object objectReferenceValue = arrayElementAtIndex.objectReferenceValue;
            EditorGUI.BeginChangeCheck();
            int arg_58_2 = controlID;

            UnityEngine.Object arg_58_3 = objectReferenceValue;
            Type arg_58_4 = typeof(UnityEngine.Object);
            SerializedProperty arg_58_5 = null;

            if (SpriteAtlasInspector.< > f__mg$cache0 == null)
            {
                SpriteAtlasInspector.< > f__mg$cache0 = new EditorGUI.ObjectFieldValidator(SpriteAtlasInspector.ValidateObjectForPackableFieldAssignment);
            }
            UnityEngine.Object objectReferenceValue2 = EditorGUI.DoObjectField(rect, rect, arg_58_2, arg_58_3, arg_58_4, arg_58_5, SpriteAtlasInspector.< > f__mg$cache0, false);
            if (EditorGUI.EndChangeCheck())
            {
                if (objectReferenceValue != null)
                {
                    this.spriteAtlas.Remove(new UnityEngine.Object[]
                    {
                        objectReferenceValue
                    });
                }
                arrayElementAtIndex.objectReferenceValue = objectReferenceValue2;
            }
            if (GUIUtility.keyboardControl == controlID && !selected)
            {
                this.m_PackableList.index = index;
            }
        }
        public static Object DoObjectField(Rect position, Object obj, Type type, int controlId, bool allowScene, bool allowAllObjects = false)
        {
            EditorGUI.ObjectFieldValidator validator = null;
            if (allowAllObjects)
            {
                validator = k_AllowAllObjectsValidator;
            }

#if UNITY_2020_1_OR_NEWER
            var newObject = EditorGUI.DoObjectField(position, position, controlId, obj, null, type, validator, allowScene, EditorStyles.objectField);
#else
            var newObject = EditorGUI.DoObjectField(position, position, controlId, obj, type, null, validator, allowScene, EditorStyles.objectField);
#endif
            return(newObject);
        }
Exemplo n.º 3
0
        static Object AssignSelectedObject(SerializedProperty property, EditorGUI.ObjectFieldValidator validator, System.Type objectType, Event evt)
        {
            Object[] references = { s_LastSelectedItem };
            Object   assigned   = validator(references, objectType, property, EditorGUI.ObjectFieldValidatorOptions.None);

            // Assign the value
            if (property != null)
            {
                property.objectReferenceValue = assigned;
            }

            GUI.changed = true;
            evt.Use();
            return(assigned);
        }
Exemplo n.º 4
0
        public int GUIListOfFloatObjectToggleFields(GUIContent label, SerializedProperty[] objectProps, EditorGUI.ObjectFieldValidator validator, GUIContent buttonTooltip, bool allowCreation)
        {
            int  result = -1;
            int  num    = objectProps.Length;
            Rect rect   = GUILayoutUtility.GetRect(0f, (float)(15 * num));

            rect.height = 13f;
            float num2  = 10f;
            float num3  = 35f;
            float num4  = 10f;
            float width = rect.width - num2 - num3 - num4 * 2f - 9f;

            ModuleUI.PrefixLabel(rect, label);
            for (int i = 0; i < num; i++)
            {
                SerializedProperty serializedProperty = objectProps[i];
                Rect rect2     = new Rect(rect.x + num2 + num3 + num4, rect.y, width, rect.height);
                int  controlID = GUIUtility.GetControlID(1235498, EditorGUIUtility.native, rect2);
                EditorGUI.DoObjectField(rect2, rect2, controlID, null, null, serializedProperty, validator, true, ParticleSystemStyles.Get().objectField);
                if (serializedProperty.objectReferenceValue == null)
                {
                    rect2 = new Rect(rect.xMax - 9f, rect.y + 3f, 9f, 9f);
                    if (!allowCreation || GUI.Button(rect2, buttonTooltip ?? GUIContent.none, ParticleSystemStyles.Get().plus))
                    {
                        result = i;
                    }
                }
                rect.y += 15f;
            }
            return(result);
        }
Exemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            if (ScriptExecutionOrderInspector.m_Styles == null)
            {
                ScriptExecutionOrderInspector.m_Styles = new ScriptExecutionOrderInspector.Styles();
            }
            if (this.m_Edited)
            {
                this.UpdateOrder(this.m_Edited);
                this.m_Edited = null;
            }
            EditorGUILayout.BeginVertical(EditorStyles.inspectorFullWidthMargins, new GUILayoutOption[0]);
            GUILayout.Label(ScriptExecutionOrderInspector.m_Styles.helpText, EditorStyles.helpBox, new GUILayoutOption[0]);
            EditorGUILayout.Space();
            Rect rect      = EditorGUILayout.BeginVertical(new GUILayoutOption[0]);
            int  controlID = GUIUtility.GetControlID(ScriptExecutionOrderInspector.s_DropFieldHash, FocusType.Passive, rect);
            Rect arg_B9_0  = rect;
            int  arg_B9_1  = controlID;
            Type arg_B9_2  = typeof(MonoScript);

            if (ScriptExecutionOrderInspector.< > f__mg$cache0 == null)
            {
                ScriptExecutionOrderInspector.< > f__mg$cache0 = new EditorGUI.ObjectFieldValidator(ScriptExecutionOrderInspector.MonoScriptValidatorCallback);
            }
            MonoScript monoScript = EditorGUI.DoDropField(arg_B9_0, arg_B9_1, arg_B9_2, ScriptExecutionOrderInspector.< > f__mg$cache0, false, ScriptExecutionOrderInspector.m_Styles.dropField) as MonoScript;

            if (monoScript)
            {
                this.AddScriptToCustomOrder(monoScript);
            }
            EditorGUILayout.BeginVertical(ScriptExecutionOrderInspector.m_Styles.boxBackground, new GUILayoutOption[0]);
            this.m_Scroll = EditorGUILayout.BeginVerticalScrollView(this.m_Scroll, new GUILayoutOption[0]);
            Rect rect2 = GUILayoutUtility.GetRect(10f, (float)(21 * this.m_CustomTimeScripts.Count), new GUILayoutOption[]
            {
                GUILayout.ExpandWidth(true)
            });
            int num = ScriptExecutionOrderInspector.DragReorderGUI.DragReorder(rect2, 21, this.m_CustomTimeScripts, new ScriptExecutionOrderInspector.DragReorderGUI.DrawElementDelegate(this.DrawElement));

            if (num >= 0)
            {
                this.SetExecutionOrderAtIndexAccordingToNeighbors(num, 0);
                this.UpdateOrder(this.m_CustomTimeScripts[num]);
                this.SetExecutionOrderAtIndexAccordingToNeighbors(num, 0);
            }
            EditorGUILayout.EndScrollView();
            EditorGUILayout.EndVertical();
            GUILayout.BeginHorizontal(ScriptExecutionOrderInspector.m_Styles.toolbar, new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUIContent iconToolbarPlus = ScriptExecutionOrderInspector.m_Styles.iconToolbarPlus;
            Rect       rect3           = GUILayoutUtility.GetRect(iconToolbarPlus, ScriptExecutionOrderInspector.m_Styles.toolbarDropDown);

            if (EditorGUI.ButtonMouseDown(rect3, iconToolbarPlus, FocusType.Passive, ScriptExecutionOrderInspector.m_Styles.toolbarDropDown))
            {
                this.ShowScriptPopup(rect3);
            }
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            this.ApplyRevertGUI();
            GUILayout.EndVertical();
            GUILayout.FlexibleSpace();
        }
Exemplo n.º 6
0
 internal static UnityEngine.Object DoDropField(Rect position, int id, System.Type objType, EditorGUI.ObjectFieldValidator validator, bool allowSceneObjects, GUIStyle style)
 {
   if (validator == null)
     validator = new EditorGUI.ObjectFieldValidator(EditorGUI.ValidateObjectFieldAssignment);
   EventType eventType1 = Event.current.type;
   if (!GUI.enabled && GUIClip.enabled && Event.current.rawType == EventType.MouseDown)
     eventType1 = Event.current.rawType;
   EventType eventType2 = eventType1;
   switch (eventType2)
   {
     case EventType.Repaint:
       style.Draw(position, GUIContent.none, id, DragAndDrop.activeControlID == id);
       break;
     case EventType.DragUpdated:
     case EventType.DragPerform:
       if (position.Contains(Event.current.mousePosition) && GUI.enabled)
       {
         UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
         UnityEngine.Object target = validator(objectReferences, objType, (SerializedProperty) null);
         if (target != (UnityEngine.Object) null && !allowSceneObjects && !EditorUtility.IsPersistent(target))
           target = (UnityEngine.Object) null;
         if (target != (UnityEngine.Object) null)
         {
           DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
           if (eventType1 == EventType.DragPerform)
           {
             GUI.changed = true;
             DragAndDrop.AcceptDrag();
             DragAndDrop.activeControlID = 0;
             Event.current.Use();
             return target;
           }
           DragAndDrop.activeControlID = id;
           Event.current.Use();
           break;
         }
         break;
       }
       break;
     default:
       if (eventType2 == EventType.DragExited && GUI.enabled)
       {
         HandleUtility.Repaint();
         break;
       }
       break;
   }
   return (UnityEngine.Object) null;
 }
Exemplo n.º 7
0
 internal static UnityEngine.Object DoObjectField(Rect position, Rect dropRect, int id, UnityEngine.Object obj, System.Type objType, SerializedProperty property, EditorGUI.ObjectFieldValidator validator, bool allowSceneObjects, GUIStyle style)
 {
   if (validator == null)
     validator = new EditorGUI.ObjectFieldValidator(EditorGUI.ValidateObjectFieldAssignment);
   Event current = Event.current;
   EventType eventType1 = current.type;
   if (!GUI.enabled && GUIClip.enabled && Event.current.rawType == EventType.MouseDown)
     eventType1 = Event.current.rawType;
   bool flag1 = EditorGUIUtility.HasObjectThumbnail(objType);
   EditorGUI.ObjectFieldVisualType objectFieldVisualType = EditorGUI.ObjectFieldVisualType.IconAndText;
   if (flag1 && (double) position.height <= 18.0 && (double) position.width <= 32.0)
     objectFieldVisualType = EditorGUI.ObjectFieldVisualType.MiniPreivew;
   else if (flag1 && (double) position.height > 16.0)
     objectFieldVisualType = EditorGUI.ObjectFieldVisualType.LargePreview;
   Vector2 iconSize = EditorGUIUtility.GetIconSize();
   if (objectFieldVisualType == EditorGUI.ObjectFieldVisualType.IconAndText)
     EditorGUIUtility.SetIconSize(new Vector2(12f, 12f));
   else if (objectFieldVisualType == EditorGUI.ObjectFieldVisualType.LargePreview)
     EditorGUIUtility.SetIconSize(new Vector2(64f, 64f));
   EventType eventType2 = eventType1;
   switch (eventType2)
   {
     case EventType.KeyDown:
       if (GUIUtility.keyboardControl == id)
       {
         if (current.keyCode == KeyCode.Backspace || current.keyCode == KeyCode.Delete)
         {
           if (property != null)
             property.objectReferenceValue = (UnityEngine.Object) null;
           else
             obj = (UnityEngine.Object) null;
           GUI.changed = true;
           current.Use();
         }
         if (current.MainActionKeyForControl(id))
         {
           ObjectSelector.get.Show(obj, objType, property, allowSceneObjects);
           ObjectSelector.get.objectSelectorID = id;
           current.Use();
           GUIUtility.ExitGUI();
           break;
         }
         break;
       }
       break;
     case EventType.Repaint:
       GUIContent content;
       if (EditorGUI.showMixedValue)
         content = EditorGUI.s_MixedValueContent;
       else if (property != null)
       {
         content = EditorGUIUtility.TempContent(property.objectReferenceStringValue, (Texture) AssetPreview.GetMiniThumbnail(property.objectReferenceValue));
         obj = property.objectReferenceValue;
         if (obj != (UnityEngine.Object) null)
         {
           UnityEngine.Object[] references = new UnityEngine.Object[1]{ obj };
           if (validator(references, objType, property) == (UnityEngine.Object) null)
             content = EditorGUIUtility.TempContent("Type mismatch");
         }
       }
       else
         content = EditorGUIUtility.ObjectContent(obj, objType);
       switch (objectFieldVisualType)
       {
         case EditorGUI.ObjectFieldVisualType.IconAndText:
           EditorGUI.BeginHandleMixedValueContentColor();
           style.Draw(position, content, id, DragAndDrop.activeControlID == id);
           EditorGUI.EndHandleMixedValueContentColor();
           break;
         case EditorGUI.ObjectFieldVisualType.LargePreview:
           EditorGUI.DrawObjectFieldLargeThumb(position, id, obj, content);
           break;
         case EditorGUI.ObjectFieldVisualType.MiniPreivew:
           EditorGUI.DrawObjectFieldMiniThumb(position, id, obj, content);
           break;
         default:
           throw new ArgumentOutOfRangeException();
       }
     case EventType.DragUpdated:
     case EventType.DragPerform:
       if (dropRect.Contains(Event.current.mousePosition) && GUI.enabled)
       {
         UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
         UnityEngine.Object target = validator(objectReferences, objType, property);
         if (target != (UnityEngine.Object) null && !allowSceneObjects && !EditorUtility.IsPersistent(target))
           target = (UnityEngine.Object) null;
         if (target != (UnityEngine.Object) null)
         {
           DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
           if (eventType1 == EventType.DragPerform)
           {
             if (property != null)
               property.objectReferenceValue = target;
             else
               obj = target;
             GUI.changed = true;
             DragAndDrop.AcceptDrag();
             DragAndDrop.activeControlID = 0;
           }
           else
             DragAndDrop.activeControlID = id;
           Event.current.Use();
           break;
         }
         break;
       }
       break;
     case EventType.ExecuteCommand:
       if (current.commandName == "ObjectSelectorUpdated" && ObjectSelector.get.objectSelectorID == id && GUIUtility.keyboardControl == id)
       {
         UnityEngine.Object[] references = new UnityEngine.Object[1]
         {
           ObjectSelector.GetCurrentObject()
         };
         UnityEngine.Object @object = validator(references, objType, property);
         if (property != null)
           property.objectReferenceValue = @object;
         GUI.changed = true;
         current.Use();
         return @object;
       }
       break;
     case EventType.DragExited:
       if (GUI.enabled)
       {
         HandleUtility.Repaint();
         break;
       }
       break;
     default:
       if (eventType2 == EventType.MouseDown && Event.current.button == 0 && position.Contains(Event.current.mousePosition))
       {
         Rect rect;
         switch (objectFieldVisualType)
         {
           case EditorGUI.ObjectFieldVisualType.IconAndText:
             rect = new Rect(position.xMax - 15f, position.y, 15f, position.height);
             break;
           case EditorGUI.ObjectFieldVisualType.LargePreview:
             rect = new Rect(position.xMax - 36f, position.yMax - 14f, 36f, 14f);
             break;
           case EditorGUI.ObjectFieldVisualType.MiniPreivew:
             rect = new Rect(position.xMax - 15f, position.y, 15f, position.height);
             break;
           default:
             throw new ArgumentOutOfRangeException();
         }
         EditorGUIUtility.editingTextField = false;
         if (rect.Contains(Event.current.mousePosition))
         {
           if (GUI.enabled)
           {
             GUIUtility.keyboardControl = id;
             ObjectSelector.get.Show(obj, objType, property, allowSceneObjects);
             ObjectSelector.get.objectSelectorID = id;
             current.Use();
             GUIUtility.ExitGUI();
             break;
           }
           break;
         }
         UnityEngine.Object @object = property == null ? obj : property.objectReferenceValue;
         Component component = @object as Component;
         if ((bool) ((UnityEngine.Object) component))
           @object = (UnityEngine.Object) component.gameObject;
         if (EditorGUI.showMixedValue)
           @object = (UnityEngine.Object) null;
         if (Event.current.clickCount == 1)
         {
           GUIUtility.keyboardControl = id;
           if ((bool) @object)
           {
             bool flag2 = current.shift || current.control;
             if (!flag2)
               EditorGUIUtility.PingObject(@object);
             if (flag2 && @object is Texture)
               PopupWindowWithoutFocus.Show(new RectOffset(6, 3, 0, 3).Add(position), (PopupWindowContent) new ObjectPreviewPopup(@object), new PopupLocationHelper.PopupLocation[3]
               {
                 PopupLocationHelper.PopupLocation.Left,
                 PopupLocationHelper.PopupLocation.Below,
                 PopupLocationHelper.PopupLocation.Right
               });
           }
           current.Use();
           break;
         }
         if (Event.current.clickCount == 2)
         {
           if ((bool) @object)
           {
             AssetDatabase.OpenAsset(@object);
             GUIUtility.ExitGUI();
           }
           current.Use();
           break;
         }
         break;
       }
       break;
   }
   EditorGUIUtility.SetIconSize(iconSize);
   return obj;
 }
Exemplo n.º 8
0
        public int GUIListOfFloatObjectToggleFields(GUIContent label, SerializedProperty[] objectProps, EditorGUI.ObjectFieldValidator validator, GUIContent buttonTooltip, bool allowCreation)
        {
            int  num1   = -1;
            int  length = objectProps.Length;
            Rect rect1  = GUILayoutUtility.GetRect(0.0f, (float)(15 * length));

            rect1.height = 13f;
            float num2  = 10f;
            float num3  = 35f;
            float num4  = 10f;
            float width = (float)((double)rect1.width - (double)num2 - (double)num3 - (double)num4 * 2.0 - 9.0);

            ModuleUI.PrefixLabel(rect1, label);
            for (int index = 0; index < length; ++index)
            {
                SerializedProperty objectProp = objectProps[index];
                Rect rect2     = new Rect(rect1.x + num2 + num3 + num4, rect1.y, width, rect1.height);
                int  controlId = GUIUtility.GetControlID(1235498, EditorGUIUtility.native, rect2);
                EditorGUI.DoObjectField(rect2, rect2, controlId, (UnityEngine.Object)null, (System.Type)null, objectProp, validator, true, ParticleSystemStyles.Get().objectField);
                if (objectProp.objectReferenceValue == (UnityEngine.Object)null)
                {
                    rect2 = new Rect(rect1.xMax - 9f, rect1.y + 3f, 9f, 9f);
                    if (!allowCreation || GUI.Button(rect2, buttonTooltip ?? GUIContent.none, ParticleSystemStyles.Get().plus))
                    {
                        num1 = index;
                    }
                }
                rect1.y += 15f;
            }
            return(num1);
        }
Exemplo n.º 9
0
        public int GUIListOfFloatObjectToggleFields(GUIContent label, SerializedProperty[] objectProps, EditorGUI.ObjectFieldValidator validator, GUIContent buttonTooltip, bool allowCreation)
        {
            int  num           = -1;
            int  length        = objectProps.Length;
            Rect totalPosition = GUILayoutUtility.GetRect(0f, (float)(15 * length));

            totalPosition.height = 13f;
            float num3  = 10f;
            float num4  = 35f;
            float num5  = 10f;
            float width = (((totalPosition.width - num3) - num4) - (num5 * 2f)) - 9f;

            PrefixLabel(totalPosition, label);
            for (int i = 0; i < length; i++)
            {
                SerializedProperty property = objectProps[i];
                Rect position = new Rect(((totalPosition.x + num3) + num4) + num5, totalPosition.y, width, totalPosition.height);
                int  id       = GUIUtility.GetControlID(0x12da2a, EditorGUIUtility.native, position);
                EditorGUI.DoObjectField(position, position, id, null, null, property, validator, true, ParticleSystemStyles.Get().objectField);
                if (property.objectReferenceValue == null)
                {
                    position = new Rect(totalPosition.xMax - 9f, totalPosition.y + 3f, 9f, 9f);
                    if (allowCreation)
                    {
                        if (buttonTooltip == null)
                        {
                        }
                        if (!GUI.Button(position, GUIContent.none, ParticleSystemStyles.Get().plus))
                        {
                            goto Label_0129;
                        }
                    }
                    num = i;
                }
Label_0129:
                totalPosition.y += 15f;
            }
            return(num);
        }
Exemplo n.º 10
0
		internal static UnityEngine.Object DoDropField(Rect position, int id, Type objType, EditorGUI.ObjectFieldValidator validator, bool allowSceneObjects, GUIStyle style)
		{
			if (validator == null)
			{
				validator = new EditorGUI.ObjectFieldValidator(EditorGUI.ValidateObjectFieldAssignment);
			}
			Event current = Event.current;
			EventType eventType = current.type;
			if (!GUI.enabled && GUIClip.enabled && Event.current.rawType == EventType.MouseDown)
			{
				eventType = Event.current.rawType;
			}
			EventType eventType2 = eventType;
			switch (eventType2)
			{
			case EventType.Repaint:
				style.Draw(position, GUIContent.none, id, DragAndDrop.activeControlID == id);
				goto IL_144;
			case EventType.Layout:
				IL_6B:
				if (eventType2 != EventType.DragExited)
				{
					goto IL_144;
				}
				if (GUI.enabled)
				{
					HandleUtility.Repaint();
				}
				goto IL_144;
			case EventType.DragUpdated:
			case EventType.DragPerform:
				if (position.Contains(Event.current.mousePosition) && GUI.enabled)
				{
					UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
					UnityEngine.Object @object = validator(objectReferences, objType, null);
					if (@object != null && !allowSceneObjects && !EditorUtility.IsPersistent(@object))
					{
						@object = null;
					}
					if (@object != null)
					{
						DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
						if (eventType == EventType.DragPerform)
						{
							GUI.changed = true;
							DragAndDrop.AcceptDrag();
							DragAndDrop.activeControlID = 0;
							Event.current.Use();
							return @object;
						}
						DragAndDrop.activeControlID = id;
						Event.current.Use();
					}
				}
				goto IL_144;
			}
			goto IL_6B;
			IL_144:
			return null;
		}
Exemplo n.º 11
0
		internal static UnityEngine.Object DoObjectField(Rect position, Rect dropRect, int id, UnityEngine.Object obj, Type objType, SerializedProperty property, EditorGUI.ObjectFieldValidator validator, bool allowSceneObjects, GUIStyle style)
		{
			if (validator == null)
			{
				validator = new EditorGUI.ObjectFieldValidator(EditorGUI.ValidateObjectFieldAssignment);
			}
			Event current = Event.current;
			EventType eventType = current.type;
			if (!GUI.enabled && GUIClip.enabled && Event.current.rawType == EventType.MouseDown)
			{
				eventType = Event.current.rawType;
			}
			bool flag = EditorGUIUtility.HasObjectThumbnail(objType);
			EditorGUI.ObjectFieldVisualType objectFieldVisualType = EditorGUI.ObjectFieldVisualType.IconAndText;
			if (flag && position.height <= 18f && position.width <= 32f)
			{
				objectFieldVisualType = EditorGUI.ObjectFieldVisualType.MiniPreivew;
			}
			else
			{
				if (flag && position.height > 16f)
				{
					objectFieldVisualType = EditorGUI.ObjectFieldVisualType.LargePreview;
				}
			}
			Vector2 iconSize = EditorGUIUtility.GetIconSize();
			if (objectFieldVisualType == EditorGUI.ObjectFieldVisualType.IconAndText)
			{
				EditorGUIUtility.SetIconSize(new Vector2(12f, 12f));
			}
			EventType eventType2 = eventType;
			switch (eventType2)
			{
			case EventType.KeyDown:
				if (GUIUtility.keyboardControl == id)
				{
					if (current.keyCode == KeyCode.Backspace || current.keyCode == KeyCode.Delete)
					{
						if (property != null)
						{
							property.objectReferenceValue = null;
						}
						else
						{
							obj = null;
						}
						GUI.changed = true;
						current.Use();
					}
					if (current.MainActionKeyForControl(id))
					{
						ObjectSelector.get.Show(obj, objType, property, allowSceneObjects);
						ObjectSelector.get.objectSelectorID = id;
						current.Use();
						GUIUtility.ExitGUI();
					}
				}
				goto IL_5EB;
			case EventType.KeyUp:
			case EventType.ScrollWheel:
			case EventType.Layout:
			case EventType.Ignore:
			case EventType.Used:
			case EventType.ValidateCommand:
				IL_FF:
				if (eventType2 != EventType.MouseDown)
				{
					goto IL_5EB;
				}
				if (Event.current.button != 0)
				{
					goto IL_5EB;
				}
				if (position.Contains(Event.current.mousePosition))
				{
					Rect rect;
					switch (objectFieldVisualType)
					{
					case EditorGUI.ObjectFieldVisualType.IconAndText:
						rect = new Rect(position.xMax - 15f, position.y, 15f, position.height);
						break;
					case EditorGUI.ObjectFieldVisualType.LargePreview:
						rect = new Rect(position.xMax - 32f, position.yMax - 14f, 32f, 14f);
						break;
					case EditorGUI.ObjectFieldVisualType.MiniPreivew:
						rect = new Rect(position.xMax - 15f, position.y, 15f, position.height);
						break;
					default:
						throw new ArgumentOutOfRangeException();
					}
					EditorGUIUtility.editingTextField = false;
					if (rect.Contains(Event.current.mousePosition))
					{
						if (GUI.enabled)
						{
							GUIUtility.keyboardControl = id;
							ObjectSelector.get.Show(obj, objType, property, allowSceneObjects);
							ObjectSelector.get.objectSelectorID = id;
							current.Use();
							GUIUtility.ExitGUI();
						}
					}
					else
					{
						UnityEngine.Object @object = (property == null) ? obj : property.objectReferenceValue;
						Component component = @object as Component;
						if (component)
						{
							@object = component.gameObject;
						}
						if (EditorGUI.showMixedValue)
						{
							@object = null;
						}
						if (Event.current.clickCount == 1)
						{
							GUIUtility.keyboardControl = id;
							if (@object)
							{
								bool flag2 = current.shift || current.control;
								if (!flag2)
								{
									EditorGUIUtility.PingObject(@object);
								}
								if (flag2 && @object is Texture)
								{
									PopupWindowWithoutFocus.Show(new RectOffset(6, 3, 0, 3).Add(position), new ObjectPreviewPopup(@object), new PopupLocationHelper.PopupLocation[]
									{
										PopupLocationHelper.PopupLocation.Left,
										PopupLocationHelper.PopupLocation.Below,
										PopupLocationHelper.PopupLocation.Right
									});
								}
							}
							current.Use();
						}
						else
						{
							if (Event.current.clickCount == 2)
							{
								if (@object)
								{
									AssetDatabase.OpenAsset(@object);
									GUIUtility.ExitGUI();
								}
								current.Use();
							}
						}
					}
				}
				goto IL_5EB;
			case EventType.Repaint:
			{
				GUIContent content;
				if (EditorGUI.showMixedValue)
				{
					content = EditorGUI.s_MixedValueContent;
				}
				else
				{
					if (property != null)
					{
						content = EditorGUIUtility.TempContent(property.objectReferenceStringValue, AssetPreview.GetMiniThumbnail(property.objectReferenceValue));
						obj = property.objectReferenceValue;
						if (obj != null)
						{
							UnityEngine.Object[] references = new UnityEngine.Object[]
							{
								obj
							};
							if (validator(references, objType, property) == null)
							{
								content = EditorGUIUtility.TempContent("Type mismatch");
							}
						}
					}
					else
					{
						content = EditorGUIUtility.ObjectContent(obj, objType);
					}
				}
				switch (objectFieldVisualType)
				{
				case EditorGUI.ObjectFieldVisualType.IconAndText:
					EditorGUI.BeginHandleMixedValueContentColor();
					style.Draw(position, content, id, DragAndDrop.activeControlID == id);
					EditorGUI.EndHandleMixedValueContentColor();
					break;
				case EditorGUI.ObjectFieldVisualType.LargePreview:
					EditorGUI.DrawObjectFieldLargeThumb(position, id, obj, content);
					break;
				case EditorGUI.ObjectFieldVisualType.MiniPreivew:
					EditorGUI.DrawObjectFieldMiniThumb(position, id, obj, content);
					break;
				default:
					throw new ArgumentOutOfRangeException();
				}
				goto IL_5EB;
			}
			case EventType.DragUpdated:
			case EventType.DragPerform:
				if (dropRect.Contains(Event.current.mousePosition) && GUI.enabled)
				{
					UnityEngine.Object[] objectReferences = DragAndDrop.objectReferences;
					UnityEngine.Object object2 = validator(objectReferences, objType, property);
					if (object2 != null && !allowSceneObjects && !EditorUtility.IsPersistent(object2))
					{
						object2 = null;
					}
					if (object2 != null)
					{
						DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
						if (eventType == EventType.DragPerform)
						{
							if (property != null)
							{
								property.objectReferenceValue = object2;
							}
							else
							{
								obj = object2;
							}
							GUI.changed = true;
							DragAndDrop.AcceptDrag();
							DragAndDrop.activeControlID = 0;
						}
						else
						{
							DragAndDrop.activeControlID = id;
						}
						Event.current.Use();
					}
				}
				goto IL_5EB;
			case EventType.ExecuteCommand:
			{
				string commandName = current.commandName;
				if (commandName == "ObjectSelectorUpdated" && ObjectSelector.get.objectSelectorID == id && GUIUtility.keyboardControl == id)
				{
					UnityEngine.Object[] references2 = new UnityEngine.Object[]
					{
						ObjectSelector.GetCurrentObject()
					};
					UnityEngine.Object object3 = validator(references2, objType, property);
					if (property != null)
					{
						property.objectReferenceValue = object3;
					}
					GUI.changed = true;
					current.Use();
					return object3;
				}
				goto IL_5EB;
			}
			case EventType.DragExited:
				if (GUI.enabled)
				{
					HandleUtility.Repaint();
				}
				goto IL_5EB;
			}
			goto IL_FF;
			IL_5EB:
			EditorGUIUtility.SetIconSize(iconSize);
			return obj;
		}
Exemplo n.º 12
0
        internal static Object DoDropField(Rect position, int id, System.Type objType, EditorGUI.ObjectFieldValidator validator, bool allowSceneObjects, GUIStyle style)
        {
            if (validator == null)
            {
                validator = EditorGUI.ValidateObjectFieldAssignment;
            }
            Event     evt       = Event.current;
            EventType eventType = evt.type;

            // special case test, so we continue to ping/select objects with the object field disabled
            if (!GUI.enabled && Utils.IsGUIClipEnabled() && (Event.current.rawType == EventType.MouseDown))
            {
                eventType = Event.current.rawType;
            }

            switch (eventType)
            {
            case EventType.DragExited:
                if (GUI.enabled)
                {
                    HandleUtility.Repaint();
                }
                break;

            case EventType.DragUpdated:
            case EventType.DragPerform:

                if (position.Contains(Event.current.mousePosition) && GUI.enabled)
                {
                    Object[] references      = DragAndDrop.objectReferences;
                    Object   validatedObject = validator(references, objType, null, EditorGUI.ObjectFieldValidatorOptions.None);

                    if (validatedObject != null)
                    {
                        // If scene objects are not allowed and object is a scene object then clear
                        if (!allowSceneObjects && !EditorUtility.IsPersistent(validatedObject))
                        {
                            validatedObject = null;
                        }
                    }

                    if (validatedObject != null)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        if (eventType == EventType.DragPerform)
                        {
                            GUI.changed = true;
                            DragAndDrop.AcceptDrag();
                            DragAndDrop.activeControlID = 0;
                            Event.current.Use();
                            return(validatedObject);
                        }
                        else
                        {
                            DragAndDrop.activeControlID = id;
                            Event.current.Use();
                        }
                    }
                }
                break;

            case EventType.Repaint:
                style.Draw(position, GUIContent.none, id, DragAndDrop.activeControlID == id);
                break;
            }
            return(null);
        }
Exemplo n.º 13
0
        static Object DoObjectField(Rect position, Rect dropRect, int id, Object obj, Object objBeingEdited, System.Type objType, SerializedProperty property, EditorGUI.ObjectFieldValidator validator, GUIStyle style, SearchContext context, SearchViewFlags searchViewFlags = SearchViewFlags.None)
        {
            if (validator == null)
            {
                validator = EditorGUI.ValidateObjectFieldAssignment;
            }
            if (property != null)
            {
                obj = property.objectReferenceValue;
            }
            Event     evt       = Event.current;
            EventType eventType = evt.type;

            // special case test, so we continue to ping/select objects with the object field disabled
            if (!GUI.enabled && Utils.IsGUIClipEnabled() && (Event.current.rawType == EventType.MouseDown))
            {
                eventType = Event.current.rawType;
            }

            bool hasThumbnail = EditorGUIUtility.HasObjectThumbnail(objType);

            // Determine visual type
            ObjectFieldVisualType visualType = ObjectFieldVisualType.IconAndText;

            if (hasThumbnail && position.height <= EditorGUI.kObjectFieldMiniThumbnailHeight && position.width <= EditorGUI.kObjectFieldMiniThumbnailWidth)
            {
                visualType = ObjectFieldVisualType.MiniPreview;
            }
            else if (hasThumbnail && position.height > EditorGUI.kSingleLineHeight)
            {
                visualType = ObjectFieldVisualType.LargePreview;
            }

            Vector2 oldIconSize = EditorGUIUtility.GetIconSize();

            if (visualType == ObjectFieldVisualType.IconAndText)
            {
                EditorGUIUtility.SetIconSize(new Vector2(12, 12));  // Have to be this small to fit inside a single line height ObjectField
            }
            else if (visualType == ObjectFieldVisualType.LargePreview)
            {
                EditorGUIUtility.SetIconSize(new Vector2(64, 64));
            }

            if ((eventType == EventType.MouseDown && Event.current.button == 1 || eventType == EventType.ContextClick) &&
                position.Contains(Event.current.mousePosition))
            {
                var actualObject = property != null ? property.objectReferenceValue : obj;
                var contextMenu  = new GenericMenu();

                if (EditorGUI.FillPropertyContextMenu(property, null, contextMenu) != null)
                {
                    contextMenu.AddSeparator("");
                }
                contextMenu.AddItem(Utils.GUIContentTemp("Properties..."), false, () => Utils.OpenPropertyEditor(actualObject));
                contextMenu.DropDown(position);
                Event.current.Use();
            }

            switch (eventType)
            {
            case EventType.DragExited:
                if (GUI.enabled)
                {
                    HandleUtility.Repaint();
                }

                break;

            case EventType.DragUpdated:
            case EventType.DragPerform:

                if (eventType == EventType.DragPerform)
                {
                    string errorString;
                    if (!ValidDroppedObject(DragAndDrop.objectReferences, objType, out errorString))
                    {
                        Object reference = DragAndDrop.objectReferences[0];
                        EditorUtility.DisplayDialog("Can't assign script", errorString, "OK");
                        break;
                    }
                }

                if (dropRect.Contains(Event.current.mousePosition) && GUI.enabled)
                {
                    Object[] references      = DragAndDrop.objectReferences;
                    Object   validatedObject = validator(references, objType, property, EditorGUI.ObjectFieldValidatorOptions.None);

                    if (validatedObject != null)
                    {
                        DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
                        if (eventType == EventType.DragPerform)
                        {
                            if (property != null)
                            {
                                property.objectReferenceValue = validatedObject;
                            }
                            else
                            {
                                obj = validatedObject;
                            }

                            GUI.changed = true;
                            DragAndDrop.AcceptDrag();
                            DragAndDrop.activeControlID = 0;
                        }
                        else
                        {
                            DragAndDrop.activeControlID = id;
                        }
                        Event.current.Use();
                    }
                }
                break;

            case EventType.MouseDown:
                if (position.Contains(Event.current.mousePosition) && Event.current.button == 0)
                {
                    // Get button rect for Object Selector
                    Rect buttonRect = GetButtonRect(visualType, position);

                    EditorGUIUtility.editingTextField = false;

                    if (buttonRect.Contains(Event.current.mousePosition))
                    {
                        if (GUI.enabled)
                        {
                            GUIUtility.keyboardControl = id;
                            ShowSearchPicker(context, searchViewFlags, property, property == null ? obj : null, id, evt, objType);
                        }
                    }
                    else
                    {
                        Object    actualTargetObject = property != null ? property.objectReferenceValue : obj;
                        Component com = actualTargetObject as Component;
                        if (com)
                        {
                            actualTargetObject = com.gameObject;
                        }
                        if (EditorGUI.showMixedValue)
                        {
                            actualTargetObject = null;
                        }

                        // One click shows where the referenced object is, or pops up a preview
                        if (Event.current.clickCount == 1)
                        {
                            GUIUtility.keyboardControl = id;

                            PingObjectOrShowPreviewOnClick(actualTargetObject, position);
                            evt.Use();
                        }
                        // Double click opens the asset in external app or changes selection to referenced object
                        else if (Event.current.clickCount == 2)
                        {
                            if (actualTargetObject)
                            {
                                AssetDatabase.OpenAsset(actualTargetObject);
                                evt.Use();
                                GUIUtility.ExitGUI();
                            }
                        }
                    }
                }
                break;

            case EventType.ExecuteCommand:
                string commandName = evt.commandName;
                if (commandName == k_PickerUpdatedCommand && s_LastPickerId == id && GUIUtility.keyboardControl == id && (property == null || !Utils.SerializedPropertyIsScript(property)))
                {
                    return(AssignSelectedObject(property, validator, objType, evt));
                }
                else if (commandName == k_PickerClosedCommand && s_LastPickerId == id && GUIUtility.keyboardControl == id)
                {
                    if (s_LastSelectionWasCanceled)
                    {
                        // User canceled object selection; don't apply
                        evt.Use();

                        // When we operate directly on objects, the undo system doesn't work.
                        // We added a hack that sets the s_LastSelectedItem to the original item
                        // when canceling with an object.
                        if (property == null)
                        {
                            return(s_LastSelectedItem);
                        }

                        break;
                    }

                    // When property is script, it is not assigned on update, so assign it on close
                    if (property != null && Utils.SerializedPropertyIsScript(property))
                    {
                        return(AssignSelectedObject(property, validator, objType, evt));
                    }

                    return(property != null ? property.objectReferenceValue : obj);
                }
                else if (Utils.IsCommandDelete(evt.commandName) && GUIUtility.keyboardControl == id)
                {
                    if (property != null)
                    {
                        property.objectReferenceValue = null;
                    }
                    else
                    {
                        obj = null;
                    }

                    GUI.changed = true;
                    evt.Use();
                }
                break;

            case EventType.ValidateCommand:
                if (Utils.IsCommandDelete(evt.commandName) && GUIUtility.keyboardControl == id)
                {
                    evt.Use();
                }
                break;

            case EventType.KeyDown:
                if (GUIUtility.keyboardControl == id)
                {
                    if (evt.keyCode == KeyCode.Backspace || (evt.keyCode == KeyCode.Delete && (evt.modifiers & EventModifiers.Shift) == 0))
                    {
                        if (property != null)
                        {
                            property.objectReferenceValue = null;
                        }
                        else
                        {
                            obj = null;
                        }

                        GUI.changed = true;
                        evt.Use();
                    }

                    // Apparently we have to check for the character being space instead of the keyCode,
                    // otherwise the Inspector will maximize upon pressing space.
                    if (Utils.MainActionKeyForControl(evt, id))
                    {
                        ShowSearchPicker(context, searchViewFlags, property, property == null ? obj : null, id, evt, objType);
                    }
                }
                break;

            case EventType.Repaint:
                GUIContent temp;
                if (EditorGUI.showMixedValue)
                {
                    temp = EditorGUI.mixedValueContent;
                }
                else
                {
                    // If obj or objType are both null, we have to rely on
                    // property.objectReferenceStringValue to display None/Missing and the
                    // correct type. But if not, EditorGUIUtility.ObjectContent is more reliable.
                    // It can take a more specific object type specified as argument into account,
                    // and it gets the icon at the same time.
                    if (obj == null && objType == null && property != null)
                    {
                        temp = Utils.GUIContentTemp(Utils.SerializedPropertyObjectReferenceStringValue(property));
                    }
                    else
                    {
                        // In order for ObjectContext to be able to distinguish between None/Missing,
                        // we need to supply an instanceID. For some reason, getting the instanceID
                        // from property.objectReferenceValue is not reliable, so we have to
                        // explicitly check property.objectReferenceInstanceIDValue if a property exists.
                        if (property != null)
                        {
                            temp = Utils.ObjectContent(obj, objType, property.objectReferenceInstanceIDValue);
                        }
                        else
                        {
                            temp = EditorGUIUtility.ObjectContent(obj, objType);
                        }
                    }

                    if (property != null)
                    {
                        if (obj != null)
                        {
                            Object[] references = { obj };
                            if (EditorSceneManager.preventCrossSceneReferences && EditorGUI.CheckForCrossSceneReferencing(obj, property.serializedObject.targetObject))
                            {
                                if (!EditorApplication.isPlaying)
                                {
                                    temp = s_SceneMismatch;
                                }
                                else
                                {
                                    temp.text = temp.text + string.Format(" ({0})", EditorGUI.GetGameObjectFromObject(obj).scene.name);
                                }
                            }
                            else if (validator(references, objType, property, EditorGUI.ObjectFieldValidatorOptions.ExactObjectTypeValidation) == null)
                            {
                                temp = s_TypeMismatch;
                            }
                        }
                    }
                }

                switch (visualType)
                {
                case ObjectFieldVisualType.IconAndText:
                    EditorGUI.BeginHandleMixedValueContentColor();
                    style.Draw(position, temp, id, DragAndDrop.activeControlID == id, position.Contains(Event.current.mousePosition));

                    Rect buttonRect = Utils.objectFieldButton.margin.Remove(GetButtonRect(visualType, position));
                    Utils.objectFieldButton.Draw(buttonRect, GUIContent.none, id, DragAndDrop.activeControlID == id, buttonRect.Contains(Event.current.mousePosition));
                    EditorGUI.EndHandleMixedValueContentColor();
                    break;

                case ObjectFieldVisualType.LargePreview:
                    DrawObjectFieldLargeThumb(position, id, obj, temp);
                    break;

                case ObjectFieldVisualType.MiniPreview:
                    DrawObjectFieldMiniThumb(position, id, obj, temp);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
                break;
            }

            EditorGUIUtility.SetIconSize(oldIconSize);

            return(obj);
        }
Exemplo n.º 14
0
 // Timeline package is using this internal overload so can't remove until that's fixed.
 internal static Object DoObjectField(Rect position, Rect dropRect, int id, Object obj, System.Type objType, SerializedProperty property, EditorGUI.ObjectFieldValidator validator, GUIStyle style, SearchContext context, SearchViewFlags searchViewFlags = SearchViewFlags.None)
 {
     return(DoObjectField(position, dropRect, id, objType, property, validator, context, searchViewFlags));
 }
Exemplo n.º 15
0
 // Takes object directly, no SerializedProperty.
 internal static Object DoObjectField(Rect position, Rect dropRect, int id, Object obj, Object objBeingEdited, System.Type objType, EditorGUI.ObjectFieldValidator validator, SearchContext context, SearchViewFlags searchViewFlags = SearchViewFlags.None, GUIStyle style = null)
 {
     return(DoObjectField(position, dropRect, id, obj, objBeingEdited, objType, null, validator, style != null ? style : EditorStyles.objectField, context, searchViewFlags));
 }