Exemplo n.º 1
1
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            _audioOption = property.GetValue<AudioOption>();
            _dynamicValue = _audioOption.Value;
            _hasCurve = _audioOption.HasCurve();
            _typeProperty = property.FindPropertyRelative("_type");
            _delayProperty = property.FindPropertyRelative("_delay");

            UpdateProperties();

            InitializeValue(_typeProperty.GetValue<AudioOption.Types>());

            float height = 16f;

            if (property.isExpanded)
            {
                height += 38f + EditorGUI.GetPropertyHeight(_valueProperty, label, true);

                if (_timeProperty != null)
                    height += EditorGUI.GetPropertyHeight(_timeProperty) + 2f;
                if (_easeProperty != null)
                    height += EditorGUI.GetPropertyHeight(_easeProperty) + 2f;
            }

            return height;
        }
		public void ToggleButton(SerializedProperty boolProperty, GUIContent trueLabel, GUIContent falseLabel) {
			Rect indentedPosition = EditorGUI.IndentedRect(currentPosition);
			boolProperty.SetValue(EditorGUI.Toggle(indentedPosition, boolProperty.GetValue<bool>(), new GUIStyle("button")));
			
			if (boolProperty.GetValue<bool>()) {
				Rect labelPosition = new Rect(indentedPosition.x + indentedPosition.width / 2 - trueLabel.text.GetWidth(EditorStyles.standardFont) / 2 - 16, indentedPosition.y, indentedPosition.width, indentedPosition.height);
				EditorGUI.LabelField(labelPosition, trueLabel);
			}
			else {
				Rect labelPosition = new Rect(indentedPosition.x + indentedPosition.width / 2 - falseLabel.text.GetWidth(EditorStyles.standardFont) / 2 - 16, indentedPosition.y, indentedPosition.width, indentedPosition.height);
				EditorGUI.LabelField(labelPosition, falseLabel);
			}
			
			currentPosition.y += currentPosition.height + 2;
		}
Exemplo n.º 3
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;

            Begin(position, property, label);

            float min = ((SliderAttribute)attribute).min;
            float max = ((SliderAttribute)attribute).max;

            EditorGUI.BeginChangeCheck();

            currentPosition.height = 16;
            object value = property.GetValue();

            if (value is int) {
                property.SetValue(EditorGUI.IntSlider(currentPosition, label, (int)value, (int)min, (int)max));
            }
            else if (value is float) {
                property.SetValue(EditorGUI.Slider(currentPosition, label, (float)value, min, max));
            }
            else if (value is double) {
                property.SetValue(EditorGUI.Slider(currentPosition, label, (float)(double)value, min, max));
            }
            else {
                EditorGUI.HelpBox(currentPosition, "The type of the field must be numerical.", MessageType.Error);
            }

            if (EditorGUI.EndChangeCheck()) {
                property.Clamp(min, max);
            }

            End();
        }
Exemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            rtpc = property.GetValue<AudioRTPC>();

            Begin(position, property, label);

            string rtpcName = string.Format("{4}{0} | {1} [{2}, {3}]", rtpc.Name, rtpc.Type, rtpc.MinValue, rtpc.MaxValue, rtpc.Scope == AudioRTPC.RTPCScope.Global ? "*" : "");
            PropertyField(property, rtpcName.ToGUIContent(), false);

            if (property.isExpanded)
            {
                EditorGUI.indentLevel++;

                PropertyField(property.FindPropertyRelative("Scope"), GUIContent.none);
                PropertyField(property.FindPropertyRelative("Name"));
                PropertyField(property.FindPropertyRelative("Type"));
                PropertyField(property.FindPropertyRelative("MinValue"));
                PropertyField(property.FindPropertyRelative("MaxValue"));
                PropertyField(property.FindPropertyRelative("Curve"));

                EditorGUI.indentLevel--;
            }

            End();
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            float height = base.GetPropertyHeight(property, label);
            CheckRequiredComponents(property.GetValue<EntityBehaviour>());

            return height;
        }
Exemplo n.º 6
0
        void ShowPolar3D(SerializedProperty property)
        {
            var xProperty = property.FindPropertyRelative("x");
            var yProperty = property.FindPropertyRelative("y");
            var zProperty = property.FindPropertyRelative("z");
            var vector = property.GetValue<Vector3>().ToPolar().Round(0.0001f);
            currentPosition.width = currentPosition.width / 3f - 1f;

            EditorGUI.BeginChangeCheck();
            EditorGUI.BeginProperty(currentPosition, xProperty.ToGUIContent(), xProperty);

            vector.x = EditorGUI.FloatField(currentPosition, "R", vector.x);
            currentPosition.x += currentPosition.width + 2f;

            EditorGUI.EndProperty();

            EditorGUI.BeginProperty(currentPosition, yProperty.ToGUIContent(), yProperty);

            vector.y = EditorGUI.FloatField(currentPosition, "ϴ", vector.y);
            currentPosition.x += currentPosition.width + 2f;

            EditorGUI.EndProperty();

            EditorGUI.BeginProperty(currentPosition, zProperty.ToGUIContent(), zProperty);

            vector.z = EditorGUI.FloatField(currentPosition, "Z", vector.z);

            EditorGUI.EndProperty();

            if (EditorGUI.EndChangeCheck())
                property.SetValue(vector.ToCartesian());
        }
        void OnGroupSelected(FlagsOption option, SerializedProperty property)
        {
            var groups = property.GetValue<ByteFlag>();

            switch (option.Type)
            {
                case FlagsOption.OptionTypes.Everything:
                    foreach (var data in groupData)
                        groups |= data.Group;
                    break;
                case FlagsOption.OptionTypes.Nothing:
                    groups = ByteFlag.Nothing;
                    break;
                case FlagsOption.OptionTypes.Custom:
                    var group = ((GroupData)option.Value).Group;

                    if (option.IsSelected)
                        groups &= ~group;
                    else
                        groups |= group;
                    break;
            }

            for (int i = 1; i <= 8; i++)
            {
                var flagName = "f" + i;
                property.FindPropertyRelative(flagName).intValue = groups.GetValueFromMember<int>(flagName);
            }

            property.serializedObject.ApplyModifiedProperties();
            EditorUtility.SetDirty(property.serializedObject.targetObject);
        }
Exemplo n.º 8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;

            Begin(position, property, label);

            string arrayName = ((PopupAttribute)attribute).arrayName;
            string onChangeCallback = ((PopupAttribute)attribute).onChangeCallback;
            SerializedProperty array = property.serializedObject.FindProperty(arrayName);
            int selectedIndex = 0;

            List<string> displayedOptions = new List<string>();
            if (array != null && property.GetValue() != null) {
                for (int i = 0; i < array.arraySize; i++) {
                    object value = array.GetArrayElementAtIndex(i).GetValue();

                    if (property.GetValue().Equals(value)) {
                        selectedIndex = i;
                    }

                    if (value != null) {
                        if (value as Object != null) {
                            displayedOptions.Add(string.Format("{0} [{1}]", value.GetType().Name, i));
                        }
                        else {
                            displayedOptions.Add(string.Format("{0}", value));
                        }
                    }
                    else {
                        displayedOptions.Add(" ");
                    }
                }
            }

            EditorGUI.BeginChangeCheck();
            selectedIndex = Mathf.Clamp(EditorGUI.Popup(_currentPosition, label, selectedIndex, displayedOptions.ToGUIContents()), 0, array.arraySize - 1);

            if (array != null && array.arraySize != 0 && array.arraySize > selectedIndex) {
                property.SetValue(array.GetArrayElementAtIndex(selectedIndex).GetValue());
            }

            if (EditorGUI.EndChangeCheck()) {
                if (!string.IsNullOrEmpty(onChangeCallback)) ((MonoBehaviour)property.serializedObject.targetObject).Invoke(onChangeCallback, 0);
            }

            End();
        }
Exemplo n.º 9
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            messageEnum = property.GetValue<MessageEnum>();

            return lineHeight;
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            reference = property.GetValue<IPropertyReference>();

            return property.isExpanded ? (lineHeight + 2f) * 3f : lineHeight + 2f;
        }
Exemplo n.º 11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;

            Begin(position, property, label);

            property.SetValue(EditorGUI.LayerField(currentPosition, label, property.GetValue<int>()));

            End();
        }
Exemplo n.º 12
0
 void CleanUpLayers(SerializedProperty layersProperty)
 {
     if (!Application.isPlaying && machine != null) {
         for (int i = layersProperty.arraySize - 1; i >= 0; i--) {
             if (layersProperty.GetValue<UnityEngine.Object>(i) == null) {
                 DeleteFromArray(layersProperty, i);
             }
         }
     }
 }
Exemplo n.º 13
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Begin(position, property, label);

            currentPosition = EditorGUI.PrefixLabel(currentPosition, label);
            currentPosition.x -= 1f;

            BeginIndent(0);
            BeginLabelWidth(27f);

            if (isEditingMin && !EditorGUIUtility.editingTextField)
            {
                property.SetValue("max", Mathf.Max(property.GetValue<float>("max"), property.GetValue<float>("min")));
                isEditingMin = false;
            }
            else if (isEditingMax && !EditorGUIUtility.editingTextField)
            {
                property.SetValue("min", Mathf.Min(property.GetValue<float>("min"), property.GetValue<float>("max")));
                isEditingMax = false;
            }

            EditorGUI.BeginChangeCheck();

            currentPosition.width = currentPosition.width / 2f;
            EditorGUI.PropertyField(currentPosition, property.FindPropertyRelative("min"));

            if (EditorGUI.EndChangeCheck())
            {
                if (EditorGUIUtility.editingTextField)
                    isEditingMin = true;
                else
                    property.SetValue("max", Mathf.Max(property.GetValue<float>("max"), property.GetValue<float>("min")));
            }

            EditorGUI.BeginChangeCheck();

            currentPosition.x += currentPosition.width + 1f;
            EditorGUI.PropertyField(currentPosition, property.FindPropertyRelative("max"));

            if (EditorGUI.EndChangeCheck())
            {
                if (EditorGUIUtility.editingTextField)
                    isEditingMax = true;
                else
                    property.SetValue("min", Mathf.Min(property.GetValue<float>("min"), property.GetValue<float>("max")));
            }

            EndLabelWidth();
            EndIndent();

            End();
        }
Exemplo n.º 14
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            pExpression = property.GetValue<PExpression>();
            textProperty = property.FindPropertyRelative("Text");
            int lineCount = textProperty.stringValue.Count(c => c == '\n' || c == '\r') + 1;
            height = Mathf.Max(lineCount * (lineHeight - 3f) + 4f, lineHeight);

            return height;
        }
Exemplo n.º 15
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            enumValue = property.GetValue<IEnum>();
            enumValues = enumValue.GetValues();
            enumNames = enumValue.GetNames().Convert(name => name.Replace('_', '/'));
            isFlag = enumValue is IEnumFlag;

            return 16f;
        }
Exemplo n.º 16
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            dynamicValue = property.GetValue<DynamicValue>();
            height = GetHeight();

            if (height == 0f)
                return 18f;
            else
                return height;
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            data = property.GetValue<PropertyOscillator.OscillatorData>();
            height = GetHeight();
            UpdateProperties();

            if (height == 0f)
                return 18f;
            else
                return height;
        }
        public virtual void ShowSource(SerializedProperty arrayProperty, int index, SerializedProperty sourceProperty)
        {
            sourceSettingsProperty = sourceProperty.FindPropertyRelative("Settings");
            var settings = sourceSettingsProperty.GetValue<AudioSettingsBase>();

            Foldout(sourceProperty, string.Format("{0}", settings == null ? "null" : settings.name).ToGUIContent(), PEditorStyles.BoldFoldout);

            var rect = EditorGUI.IndentedRect(GUILayoutUtility.GetLastRect());
            rect.width += 6f;
            rect.height = 15f;

            DropArea<AudioSettingsBase>(rect, OnSettingsDropped);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;
            height = 0;

            Begin(position, property, label);

            position.height = EditorGUI.GetPropertyHeight(property, label, true);

            EditorGUI.PropertyField(position, property);

            if (property.GetValue() != null)
                property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);

            height += position.height;
            position.y += position.height;

            if (property.isExpanded && serialized != null)
            {
                iterator = serialized.GetIterator();
                iterator.NextVisible(true);
                iterator.NextVisible(true);

                EditorGUI.indentLevel += 1;
                int currentIndent = EditorGUI.indentLevel;

                while (true)
                {
                    position.height = EditorGUI.GetPropertyHeight(iterator, iterator.displayName.ToGUIContent(), false);

                    height += position.height;

                    EditorGUI.indentLevel = currentIndent + iterator.depth;
                    EditorGUI.PropertyField(position, iterator);

                    position.y += position.height;

                    if (!iterator.NextVisible(iterator.isExpanded))
                    {
                        break;
                    }
                }

                EditorGUI.indentLevel = currentIndent;
                EditorGUI.indentLevel -= 1;

                serialized.ApplyModifiedProperties();
            }

            End();
        }
        public MergeActionChangeValues(GameObject ours, Object ourObject, SerializedProperty ourProperty, SerializedProperty theirProperty)
            : base(ours, null)
        {
            this.ourObject = ourObject;

            this.ourProperty = ourProperty;
            this.theirProperty = theirProperty;

            fieldname = ourObject.GetPlainType() + "." + ourProperty.GetPlainName();

            ourInitialValue = ourProperty.GetValue();
            theirInitialValue = theirProperty.GetValue();

            ourString = SerializedValueString(ourProperty);
            theirString = SerializedValueString(theirProperty);
        }
Exemplo n.º 21
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            base.GetPropertyHeight(property, label);

            _dynamicValue = property.GetValue<DynamicValue>();
            _typeProperty = property.FindPropertyRelative("_type");
            _isArrayProperty = property.FindPropertyRelative("_isArray");
            _valueProperty = GetValueProperty(_typeProperty.GetValue<DynamicValue.ValueTypes>(), _isArrayProperty.GetValue<bool>());

            if (property.isExpanded)
                if (_valueProperty == null)
                    return 32f;
                else
                    return EditorGUI.GetPropertyHeight(_valueProperty, label, true) + 32f;
            else
                return 16f;
        }
Exemplo n.º 22
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            Begin(position, property, label);

            if (_valueProperty != null)
                _valueProperty.SetValue(_dynamicValue.GetValue());

            _currentPosition.height = 16f;
            EditorGUI.PropertyField(_currentPosition, property, label, false);
            _currentPosition.y += 16f;

            if (property.isExpanded)
            {
                EditorGUI.indentLevel++;

                EditorGUI.BeginChangeCheck();

                EditorGUI.PropertyField(new Rect(_currentPosition.x, _currentPosition.y, _currentPosition.width - 48f, _currentPosition.height), _typeProperty, GUIContent.none);
                EditorGUI.PropertyField(new Rect(_currentPosition.width - 27f - EditorGUI.indentLevel * 16f, _currentPosition.y, 40f + EditorGUI.indentLevel * 16f, _currentPosition.height), _isArrayProperty);
                _currentPosition.y += 16f;

                if (EditorGUI.EndChangeCheck())
                {
                    _valueProperty = GetValueProperty(_typeProperty.GetValue<DynamicValue.ValueTypes>(), _isArrayProperty.GetValue<bool>());
                    _dynamicValue.SetValue(_valueProperty == null ? null : _valueProperty.GetValue());
                }

                if (_valueProperty != null)
                {
                    EditorGUI.BeginChangeCheck();

                    EditorGUI.PropertyField(_currentPosition, _valueProperty, new GUIContent("Value"), true);

                    if (EditorGUI.EndChangeCheck())
                    {
                        _dummySerialized.ApplyModifiedProperties();
                        _valueProperty = GetValueProperty(_typeProperty.GetValue<DynamicValue.ValueTypes>(), _isArrayProperty.GetValue<bool>());
                        _dynamicValue.SetValue(_valueProperty.GetValue());
                    }
                }

                EditorGUI.indentLevel--;
            }

            End();
        }
Exemplo n.º 23
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;

            Begin(position, property, label);

            EditorGUI.BeginChangeCheck();

            Array enumValues = Enum.GetValues(fieldInfo.FieldType);
            int value = (int)enumValues.GetValue(property.GetValue<int>());
            string[] options = GetDisplayOptions();
            value = EditorGUI.MaskField(currentPosition, label, value, options);

            if (EditorGUI.EndChangeCheck()) {
                object enumValue = value == -1 ? Array.IndexOf(enumValues, Enum.ToObject(fieldInfo.FieldType, SumOptions(options))) : Array.IndexOf(enumValues, Enum.ToObject(fieldInfo.FieldType, value));
                property.SetValue(enumValue);
            }

            End();
        }
Exemplo n.º 24
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;

            Begin(position, property, label);

            var types = ((TypePopupAttribute)attribute).Types;
            var typeNames = types.Convert(type => type.Name);
            var typeName = property.GetValue<string>();
            var typeIndex = Array.IndexOf(types, Type.GetType(typeName));

            EditorGUI.BeginChangeCheck();
            BeginIndent(0);

            typeIndex = EditorGUI.Popup(currentPosition, typeIndex, typeNames);

            EndIndent();
            if (EditorGUI.EndChangeCheck())
                property.SetValue(types[typeIndex].AssemblyQualifiedName);

            End();
        }
Exemplo n.º 25
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            drawPrefixLabel = false;

            if (fieldInfo.FieldType.IsArray)
            {
                Debug.LogError(string.Format("{0} must not be applied to arrays or lists.", attribute.GetType().Name));
                return;
            }

            Begin(position, property, label);

            EditorGUI.BeginChangeCheck();

            if (drawerOverride == null)
                EditorGUI.PropertyField(currentPosition, property, label, true);
            else
                drawerOverride.OnGUI(currentPosition, property, label);

            var value = property.GetValue();

            if (hasChanged)
            {
                var propertyPath = property.GetAdjustedPath();
                var propertyPathSplit = propertyPath.Split('.');

                propertyPathSplit[propertyPathSplit.Length - 1] = propertyPathSplit.Last().Replace("_", "").Capitalized();
                propertyPath = propertyPathSplit.Concat(".");
                property.serializedObject.ApplyModifiedProperties();
                Array.ForEach(targets, t => t.SetValueToMemberAtPath(propertyPath, value));
                property.serializedObject.Update();
                hasChanged = false;
            }

            hasChanged = EditorGUI.EndChangeCheck();

            End();
        }
Exemplo n.º 26
0
        void OnEnumFlagSelected(FlagsOption option, SerializedProperty property)
        {
            var flags = property.GetValue<IEnumFlag>();

            switch (option.Type)
            {
                case FlagsOption.OptionTypes.Everything:
                    foreach (IEnumFlag value in enumValues)
                        flags = flags.Add(value);
                    break;
                case FlagsOption.OptionTypes.Nothing:
                    foreach (IEnumFlag value in enumValues)
                        flags = flags.Remove(value);
                    break;
                case FlagsOption.OptionTypes.Custom:
                    if (option.IsSelected)
                        flags = flags.Remove((IEnumFlag)option.Value);
                    else
                        flags = flags.Add((IEnumFlag)option.Value);
                    break;
            }

            property.SetValue(flags);
        }
 private string SerializedValueString(SerializedProperty p)
 {
     if(fieldname == "GameObject.StaticEditorFlags")
     {
         switch(p.intValue)
         {
             case 0:
                 return "Not static";
             case -1:
                 return "Static";
             default:
                 return "Mixed static";
         }
     }
     else if(p.IsRealArray())
     {
         return "Array[" + p.arraySize + "]";
     }
     return ValueString(p.GetValue());
 }
Exemplo n.º 28
0
 public static T GetSerializedValue <T>(this UnityEditor.SerializedProperty property)
 {
     return((T)property.GetValue());
 }
Exemplo n.º 29
0
        void ShowCallbacks()
        {
            callbacksProperty = serializedObject.FindProperty("callbacks");

            EditorGUI.BeginDisabledGroup(Application.isPlaying);
            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.PrefixLabel("Callbacks");
            int callerMask = EditorGUILayout.MaskField(callbacksProperty.GetValue<int>(), callbacks);
            callbacksProperty.SetValue(callerMask);

            EditorGUILayout.EndHorizontal();
            EditorGUI.EndDisabledGroup();

            List<StateMachineCaller> callers = new List<StateMachineCaller>();

            for (int i = 0; i < callbackTypes.Length; i++) {
                if ((callerMask & 1 << i) != 0) {
                    StateMachineCaller caller = stateMachine.GetOrAddComponent(callbackTypes[i]) as StateMachineCaller;

                    caller.machine = stateMachine;
                    caller.hideFlags = HideFlags.HideInInspector;
                    callers.Add(caller);
                }
            }

            for (int i = existingCallers.Length - 1; i >= 0; i--) {
                StateMachineCaller caller = existingCallers[i];

                if (caller != null && !callers.Contains(caller)) {
                    callers.Remove(caller);
                    caller.Remove();
                }
            }
        }
Exemplo n.º 30
0
		void ShowStates() {
			for (int i = 0; i < statesProperty.arraySize; i++) {
				currentStateProperty = statesProperty.GetArrayElementAtIndex(i);
				currentState = currentStateProperty.GetValue<State>();
				
				if (currentState == null) {
					DeleteFromArray(statesProperty, i);
					break;
				}
				
				BeginBox();
				
				Foldout(currentStateProperty, FormatStateType(currentState.GetType(), currentLayer).ToGUIContent(), GetStateStyle());
				Reorderable(statesProperty, i, true);
				
				ShowState();
				
				EndBox();
			}
		}
Exemplo n.º 31
0
		void ShowLayers() {
			layersProperty = serializedObject.FindProperty("layers");
			CleanUpLayers();
			
			ShowAddLayer();
			
			if (layersProperty.arraySize > 0) {
				Separator();
			}
			
			for (int i = 0; i < layersProperty.arraySize; i++) {
				currentLayerProperty = layersProperty.GetArrayElementAtIndex(i);
				currentLayer = currentLayerProperty.GetValue<StateLayer>();
				currentLayerSerialized = new SerializedObject(currentLayerProperty.objectReferenceValue);
				statesProperty = currentLayerSerialized.FindProperty("states");
				currentStatesProperty = currentLayerSerialized.FindProperty("currentStates");
				
				BeginBox();
				
				GUIStyle style = new GUIStyle("foldout");
				style.fontStyle = FontStyle.Bold;
				if (DeleteFoldOut(layersProperty, i, currentLayer.GetType().Name.ToGUIContent(), style, OnLayerDeleted)) {
					break;
				}
				
				ShowLayer();
				
				EndBox();
			}
		}