public override object DrawControl(Rect position, SerializedProperty property, GUIContent label, object value)
        {
            var attr = (GroupAttribute)attribute;

            if (fieldInfo.FieldType.IsClass &&
                !typeof(Object).IsAssignableFrom(fieldInfo.FieldType) &&
                !typeof(IList).IsAssignableFrom(fieldInfo.FieldType)) {

                if (attr.drawFoldout) {
                    EditorGUI.PropertyField(position, property, label, true);
                } else {
                    property.isExpanded = true;

                    SerializedProperty endProperty = property.GetEndProperty();
                    property.NextVisible(true);

                    while (!SerializedProperty.EqualContents(property, endProperty)) {
                        position.height = EditorGUI.GetPropertyHeight(property);
                        EditorGUI.PropertyField(position, property, true);
                        position.y += position.height + EditorGUIUtility.standardVerticalSpacing;
                        property.NextVisible(false);
                    }
                }

                return value;
            } else {
                throw new InvalidCastException(String.Format(
                    "Field '{0}' of type '{1}' must be a class not derived from UnityEngine.Object to be used with the Inspector.Group attribute.",
                    fieldInfo.Name, fieldInfo.FieldType));
            }
        }
		public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
		{
			float num = 0f;
			if (this.m_DecoratorDrawers != null)
			{
				foreach (DecoratorDrawer current in this.m_DecoratorDrawers)
				{
					num += current.GetHeight();
				}
			}
			if (this.propertyDrawer != null)
			{
				num += this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
			}
			else
			{
				if (!includeChildren)
				{
					num += EditorGUI.GetSinglePropertyHeight(property, label);
				}
				else
				{
					property = property.Copy();
					SerializedProperty endProperty = property.GetEndProperty();
					num += EditorGUI.GetSinglePropertyHeight(property, label);
					bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
					while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
					{
						num += ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
						enterChildren = false;
						num += 2f;
					}
				}
			}
			return num;
		}
 public static float GetPropertyHeight(SerializedProperty property, GUIContent label)
 {
     //PropertyDrawer drawer = PropertyDrawer.GetDrawer(property);
     //if (drawer != null)
     //{
     //    return drawer.GetPropertyHeight(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
     //}
     property = property.Copy();
     SerializedProperty endProperty = property.GetEndProperty();
     float height = EditorGUIEx.GetSinglePropertyHeight(property, label);
     bool enterChildren = property.isExpanded && EditorGUIEx.HasVisibleChildFields(property);
     while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
     {
         //drawer = PropertyDrawer.GetDrawer(property);
         //if (drawer != null)
         //{
         //    height += drawer.GetPropertyHeight(property.Copy(), EditorGUIUtility.TempContent(property.displayName));
         //    enterChildren = false;
         //}
         //else
         {
             height += EditorGUIEx.GetSinglePropertyHeight(property);
             enterChildren = (property.isExpanded && EditorGUIEx.HasVisibleChildFields(property));
         }
     }
     return height;
 }
		private bool DrawSerializedProperty (SerializedProperty _property)
		{
			if (_property == null)
				return false;

			// Draw header
			bool	_isSelected		= UnityEditorUtility.DrawPropertyHeader(_property);

			// Draw immediate childrens
			if (_property.hasVisibleChildren && _property.isExpanded)
			{
				SerializedProperty	_propertyCopy	= _property.Copy();
				SerializedProperty 	_endProperty	= _property.GetEndProperty();

				// Move to immediate child property
				_propertyCopy.NextVisible(true);
				
				GUILayout.Space(-4f);
				GUILayout.BeginHorizontal("HelpBox");
				{
					GUILayout.Space(8f);
					GUILayout.BeginVertical();
					{
						do
						{
							if (SerializedProperty.EqualContents(_propertyCopy, _endProperty))
								break;

							// Lets make all properties expanded
							_propertyCopy.isExpanded	= true;
							
							EditorGUILayout.PropertyField(_propertyCopy, true);
						}while (_propertyCopy.NextVisible(false));
					}
					GUILayout.EndVertical();
				}
				GUILayout.EndHorizontal();
			}

			return _isSelected;
		}
        internal bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            TestInvalidateCache();

            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer - retrieve it BEFORE increasing nesting.
                PropertyDrawer drawer = propertyDrawer;

                using (var nestingContext = IncrementNestingContext())
                {
                    drawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName, tooltip));
                }

                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                if (UseReorderabelListControl(property))
                {
                    ReorderableListWrapper reorderableList;
                    string key = ReorderableListWrapper.GetPropertyIdentifier(property);

                    if (!s_reorderableLists.TryGetValue(key, out reorderableList))
                    {
                        // Manual layout controls don't call GetHeight() method so we need to have a way to initialized list as we prepare to render it here
                        reorderableList         = new ReorderableListWrapper(property, label, true);
                        s_reorderableLists[key] = reorderableList;
                    }

                    // Calculate visibility rect specifically for reorderable list as when applied for the whole serialized object,
                    // it causes collapsed out of sight array elements appear thus messing up scroll-bar experience
                    var screenPos = GUIUtility.GUIToScreenPoint(position.position);

                    screenPos.y = Mathf.Clamp(screenPos.y,
                                              GUIView.current?.screenPosition.yMin ?? 0,
                                              GUIView.current?.screenPosition.yMax ?? Screen.height);

                    Rect listVisibility = new Rect(screenPos.x, screenPos.y,
                                                   GUIView.current?.screenPosition.width ?? Screen.width,
                                                   GUIView.current?.screenPosition.height ?? Screen.height);

                    listVisibility = GUIUtility.ScreenToGUIRect(listVisibility);

                    reorderableList.Property = property;
                    reorderableList.Draw(label, position, listVisibility, tooltip, includeChildren);
                    return(!includeChildren && property.isExpanded);
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                if (property.isArray)
                {
                    EditorGUI.BeginIsInsideList(prop.depth);
                }

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        if (GUI.isInsideList && prop.depth <= EditorGUI.GetInsideListDepth())
                        {
                            EditorGUI.EndIsInsideList();
                        }

                        if (prop.isArray)
                        {
                            EditorGUI.BeginIsInsideList(prop.depth);
                        }

                        var handler = ScriptAttributeUtility.GetHandler(prop);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, UseReorderabelListControl(prop) && includeChildren);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, UseReorderabelListControl(prop)) && EditorGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EditorGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                if (GUI.isInsideList && property.depth <= EditorGUI.GetInsideListDepth())
                {
                    EditorGUI.EndIsInsideList();
                }
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
        internal bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren, Rect visibleArea)
        {
            float oldLabelWidth, oldFieldWidth;

            float propHeight = position.height;

            position.height = 0;
            if (m_DecoratorDrawers != null && !isCurrentlyNested)
            {
                foreach (DecoratorDrawer decorator in m_DecoratorDrawers)
                {
                    position.height = decorator.GetHeight();

                    oldLabelWidth = EditorGUIUtility.labelWidth;
                    oldFieldWidth = EditorGUIUtility.fieldWidth;
                    decorator.OnGUI(position);
                    EditorGUIUtility.labelWidth = oldLabelWidth;
                    EditorGUIUtility.fieldWidth = oldFieldWidth;

                    position.y += position.height;
                    propHeight -= position.height;
                }
            }

            position.height = propHeight;
            if (propertyDrawer != null)
            {
                // Remember widths
                oldLabelWidth = EditorGUIUtility.labelWidth;
                oldFieldWidth = EditorGUIUtility.fieldWidth;
                // Draw with custom drawer
                propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName));
                // Restore widths
                EditorGUIUtility.labelWidth = oldLabelWidth;
                EditorGUIUtility.fieldWidth = oldFieldWidth;

                return(false);
            }
            else
            {
                if (!includeChildren)
                {
                    return(EditorGUI.DefaultPropertyField(position, property, label));
                }

                // Remember state
                Vector2 oldIconSize = EditorGUIUtility.GetIconSize();
                bool    wasEnabled  = GUI.enabled;
                int     origIndent  = EditorGUI.indentLevel;

                int relIndent = origIndent - property.depth;

                SerializedProperty prop = property.Copy();

                position.height = EditorGUI.GetSinglePropertyHeight(prop, label);

                // First property with custom label
                EditorGUI.indentLevel = prop.depth + relIndent;
                bool childrenAreExpanded = EditorGUI.DefaultPropertyField(position, prop, label) && EditorGUI.HasVisibleChildFields(prop);
                position.y += position.height + EditorGUI.kControlVerticalSpacing;

                // Loop through all child properties
                if (childrenAreExpanded)
                {
                    SerializedProperty endProperty = prop.GetEndProperty();
                    while (prop.NextVisible(childrenAreExpanded) && !SerializedProperty.EqualContents(prop, endProperty))
                    {
                        var handler = ScriptAttributeUtility.GetHandler(prop);
                        EditorGUI.indentLevel = prop.depth + relIndent;
                        position.height       = handler.GetHeight(prop, null, false);

                        if (position.Overlaps(visibleArea))
                        {
                            EditorGUI.BeginChangeCheck();
                            childrenAreExpanded = handler.OnGUI(position, prop, null, false) && EditorGUI.HasVisibleChildFields(prop);
                            // Changing child properties (like array size) may invalidate the iterator,
                            // so stop now, or we may get errors.
                            if (EditorGUI.EndChangeCheck())
                            {
                                break;
                            }
                        }

                        position.y += position.height + EditorGUI.kControlVerticalSpacing;
                    }
                }

                // Restore state
                GUI.enabled = wasEnabled;
                EditorGUIUtility.SetIconSize(oldIconSize);
                EditorGUI.indentLevel = origIndent;

                return(false);
            }
        }
 public float GetHeight(SerializedProperty property, GUIContent label, bool includeChildren)
 {
   float num1 = 0.0f;
   if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
   {
     using (List<DecoratorDrawer>.Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator())
     {
       while (enumerator.MoveNext())
       {
         DecoratorDrawer current = enumerator.Current;
         num1 += current.GetHeight();
       }
     }
   }
   float num2;
   if (this.propertyDrawer != null)
     num2 = num1 + this.propertyDrawer.GetPropertyHeightSafe(property.Copy(), label ?? EditorGUIUtility.TempContent(property.displayName));
   else if (!includeChildren)
   {
     num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
   }
   else
   {
     property = property.Copy();
     SerializedProperty endProperty = property.GetEndProperty();
     num2 = num1 + EditorGUI.GetSinglePropertyHeight(property, label);
     bool enterChildren = property.isExpanded && EditorGUI.HasVisibleChildFields(property);
     while (property.NextVisible(enterChildren) && !SerializedProperty.EqualContents(property, endProperty))
     {
       float num3 = num2 + ScriptAttributeUtility.GetHandler(property).GetHeight(property, EditorGUIUtility.TempContent(property.displayName), true);
       enterChildren = false;
       num2 = num3 + 2f;
     }
   }
   return num2;
 }
Example #8
0
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            float num = position.height;

            position.height = 0f;
            if (this.m_DecoratorDrawers != null && !this.isCurrentlyNested)
            {
                foreach (DecoratorDrawer current in this.m_DecoratorDrawers)
                {
                    position.height = current.GetHeight();
                    float labelWidth = EditorGUIUtility.labelWidth;
                    float fieldWidth = EditorGUIUtility.fieldWidth;
                    current.OnGUI(position);
                    EditorGUIUtility.labelWidth = labelWidth;
                    EditorGUIUtility.fieldWidth = fieldWidth;
                    position.y += position.height;
                    num        -= position.height;
                }
            }
            position.height = num;
            bool result;

            if (this.propertyDrawer != null)
            {
                float labelWidth = EditorGUIUtility.labelWidth;
                float fieldWidth = EditorGUIUtility.fieldWidth;
                this.propertyDrawer.OnGUISafe(position, property.Copy(), label ?? EditorGUIUtility.TempContent(property.localizedDisplayName));
                EditorGUIUtility.labelWidth = labelWidth;
                EditorGUIUtility.fieldWidth = fieldWidth;
                result = false;
            }
            else if (!includeChildren)
            {
                result = EditorGUI.DefaultPropertyField(position, property, label);
            }
            else
            {
                Vector2            iconSize           = EditorGUIUtility.GetIconSize();
                bool               enabled            = GUI.enabled;
                int                indentLevel        = EditorGUI.indentLevel;
                int                num2               = indentLevel - property.depth;
                SerializedProperty serializedProperty = property.Copy();
                SerializedProperty endProperty        = serializedProperty.GetEndProperty();
                position.height       = EditorGUI.GetSinglePropertyHeight(serializedProperty, label);
                EditorGUI.indentLevel = serializedProperty.depth + num2;
                bool enterChildren = EditorGUI.DefaultPropertyField(position, serializedProperty, label) && EditorGUI.HasVisibleChildFields(serializedProperty);
                position.y += position.height + 2f;
                while (serializedProperty.NextVisible(enterChildren) && !SerializedProperty.EqualContents(serializedProperty, endProperty))
                {
                    EditorGUI.indentLevel = serializedProperty.depth + num2;
                    position.height       = EditorGUI.GetPropertyHeight(serializedProperty, null, false);
                    EditorGUI.BeginChangeCheck();
                    enterChildren = (ScriptAttributeUtility.GetHandler(serializedProperty).OnGUI(position, serializedProperty, null, false) && EditorGUI.HasVisibleChildFields(serializedProperty));
                    if (EditorGUI.EndChangeCheck())
                    {
                        break;
                    }
                    position.y += position.height + 2f;
                }
                GUI.enabled = enabled;
                EditorGUIUtility.SetIconSize(iconSize);
                EditorGUI.indentLevel = indentLevel;
                result = false;
            }
            return(result);
        }
        public override void OnInspectorGUI()
        {
            if (initializeException != null)
            {
                ShowLoadErrorExceptionGUI(initializeException);
                ApplyRevertGUI();
                return;
            }

            extraDataSerializedObject.Update();

            var platforms = Compilation.CompilationPipeline.GetAssemblyDefinitionPlatforms();
            var optionalUnityReferences = CustomScriptAssembly.OptinalUnityAssemblies;

            using (new EditorGUI.DisabledScope(false))
            {
                if (targets.Length > 1)
                {
                    using (new EditorGUI.DisabledScope(true))
                    {
                        var value = string.Join(", ", extraDataTargets.Select(t => t.name).ToArray());
                        EditorGUILayout.TextField(Styles.name, value, EditorStyles.textField);
                    }
                }
                else
                {
                    EditorGUILayout.PropertyField(m_AssemblyName, Styles.name);
                }

                GUILayout.Label(Styles.generalOptions, EditorStyles.boldLabel);
                EditorGUILayout.BeginVertical(GUI.skin.box);
                EditorGUILayout.PropertyField(m_AllowUnsafeCode, Styles.allowUnsafeCode);
                EditorGUILayout.PropertyField(m_AutoReferenced, Styles.autoReferenced);
                EditorGUILayout.PropertyField(m_OverrideReferences, Styles.overrideReferences);

                EditorGUILayout.EndVertical();
                GUILayout.Space(10f);

                GUILayout.Label(Styles.defineConstraints, EditorStyles.boldLabel);
                m_DefineConstraints.DoLayoutList();

                GUILayout.Label(Styles.references, EditorStyles.boldLabel);

                EditorGUILayout.BeginVertical(GUI.skin.box);
                EditorGUILayout.PropertyField(m_UseGUIDs, Styles.useGUIDs);
                EditorGUILayout.EndVertical();

                if (extraDataTargets.Any(data => ((AssemblyDefinitionState)data).references != null && ((AssemblyDefinitionState)data).references.Any(x => x.asset == null)))
                {
                    EditorGUILayout.HelpBox("The grayed out assembly references are missing and will not be referenced during compilation.", MessageType.Info);
                }

                m_ReferencesList.DoLayoutList();

                if (m_OverrideReferences.boolValue && !m_OverrideReferences.hasMultipleDifferentValues)
                {
                    GUILayout.Label(Styles.precompiledReferences, EditorStyles.boldLabel);

                    if (extraDataTargets.Any(data => ((AssemblyDefinitionState)data).precompiledReferences.Any(x => string.IsNullOrEmpty(x.path) && !string.IsNullOrEmpty(x.name))))
                    {
                        EditorGUILayout.HelpBox("The grayed out assembly references are missing and will not be referenced during compilation.", MessageType.Info);
                    }

                    UpdatePrecompiledReferenceListEntry();
                    m_PrecompiledReferencesList.DoLayoutList();
                }

                GUILayout.Label(Styles.unityReferences, EditorStyles.boldLabel);
                EditorGUILayout.BeginVertical(GUI.skin.box);
                for (int i = 0; i < optionalUnityReferences.Length; ++i)
                {
                    SerializedProperty property;
                    if (i >= m_OptionalUnityReferences.arraySize)
                    {
                        m_OptionalUnityReferences.arraySize++;
                        property           = m_OptionalUnityReferences.GetArrayElementAtIndex(i);
                        property.boolValue = false;
                    }
                    else
                    {
                        property = m_OptionalUnityReferences.GetArrayElementAtIndex(i);
                    }
                    EditorGUILayout.PropertyField(property, new GUIContent(optionalUnityReferences[i].DisplayName, optionalUnityReferences[i].Tooltip));

                    if (!property.hasMultipleDifferentValues && property.boolValue)
                    {
                        EditorGUILayout.HelpBox(optionalUnityReferences[i].AdditinalInformationWhenEnabled, MessageType.Info);
                    }
                }

                EditorGUILayout.EndVertical();
                GUILayout.Space(10f);

                GUILayout.Label(Styles.platforms, EditorStyles.boldLabel);
                EditorGUILayout.BeginVertical(GUI.skin.box);

                using (var change = new EditorGUI.ChangeCheckScope())
                {
                    EditorGUILayout.PropertyField(m_CompatibleWithAnyPlatform, Styles.anyPlatform);
                    if (change.changed)
                    {
                        // Invert state include/exclude compatibility of states that have the opposite compatibility,
                        // so all states are either include or exclude.
                        var compatibleWithAny = m_CompatibleWithAnyPlatform.boolValue;
                        var needToSwap        = extraDataTargets.Cast <AssemblyDefinitionState>().Where(p => p.compatibleWithAnyPlatform != compatibleWithAny).ToList();
                        extraDataSerializedObject.ApplyModifiedProperties();
                        foreach (var state in needToSwap)
                        {
                            InversePlatformCompatibility(state);
                        }
                        extraDataSerializedObject.Update();
                    }
                }

                if (!m_CompatibleWithAnyPlatform.hasMultipleDifferentValues)
                {
                    GUILayout.Label(m_CompatibleWithAnyPlatform.boolValue ? Styles.excludePlatforms : Styles.includePlatforms, EditorStyles.boldLabel);

                    for (int i = 0; i < platforms.Length; ++i)
                    {
                        SerializedProperty property;
                        if (i >= m_PlatformCompatibility.arraySize)
                        {
                            m_PlatformCompatibility.arraySize++;
                            property           = m_PlatformCompatibility.GetArrayElementAtIndex(i);
                            property.boolValue = false;
                        }
                        else
                        {
                            property = m_PlatformCompatibility.GetArrayElementAtIndex(i);
                        }
                        EditorGUILayout.PropertyField(property, new GUIContent(platforms[i].DisplayName));
                    }

                    EditorGUILayout.Space();

                    GUILayout.BeginHorizontal();

                    if (GUILayout.Button(Styles.selectAll))
                    {
                        var prop = m_PlatformCompatibility.GetArrayElementAtIndex(0);
                        var end  = m_PlatformCompatibility.GetEndProperty();
                        do
                        {
                            prop.boolValue = true;
                        }while (prop.Next(false) && !SerializedProperty.EqualContents(prop, end));
                    }

                    if (GUILayout.Button(Styles.deselectAll))
                    {
                        var prop = m_PlatformCompatibility.GetArrayElementAtIndex(0);
                        var end  = m_PlatformCompatibility.GetEndProperty();
                        do
                        {
                            prop.boolValue = false;
                        }while (prop.Next(false) && !SerializedProperty.EqualContents(prop, end));
                    }

                    GUILayout.FlexibleSpace();
                    GUILayout.EndHorizontal();
                }

                EditorGUILayout.EndVertical();
                GUILayout.Space(10f);

                EditorGUILayout.BeginVertical(GUI.skin.box);
                GUILayout.Label(Styles.versionDefines, EditorStyles.boldLabel);
                m_VersionDefineList.DoLayoutList();
                EditorGUILayout.EndVertical();
            }

            extraDataSerializedObject.ApplyModifiedProperties();

            ApplyRevertGUI();
        }