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;
        }
    // Draw the property inside the given rect
    public override void OnGUI( Rect position, SerializedProperty property, GUIContent label )
    {
        // Now draw the property as a Slider or an IntSlider based on whether it’s a float or integer.
        if ( property.type != "MinMaxRange" )
            Debug.LogWarning( "Use only with MinMaxRange type" );
        else
        {
            var range = attribute as MinMaxRangeAttribute;
            var minValue = property.FindPropertyRelative( "rangeStart" );
            var maxValue = property.FindPropertyRelative( "rangeEnd" );
            var newMin = minValue.floatValue;
            var newMax = maxValue.floatValue;

            var xDivision = position.width * 0.33f;
            var yDivision = position.height * 0.5f;
            EditorGUI.LabelField( new Rect( position.x, position.y, xDivision, yDivision ), label );

            EditorGUI.LabelField( new Rect( position.x, position.y + yDivision, position.width, yDivision ), range.minLimit.ToString( "0.##" ) );
            EditorGUI.LabelField( new Rect( position.x + position.width - 28f, position.y + yDivision, position.width, yDivision ), range.maxLimit.ToString( "0.##" ) );
            EditorGUI.MinMaxSlider( new Rect( position.x + 24f, position.y + yDivision, position.width - 48f, yDivision ), ref newMin, ref newMax, range.minLimit, range.maxLimit );

            EditorGUI.LabelField( new Rect( position.x + xDivision, position.y, xDivision, yDivision ), "From: " );
            newMin = Mathf.Clamp( EditorGUI.FloatField( new Rect( position.x + xDivision + 30, position.y, xDivision - 30, yDivision ), newMin ), range.minLimit, newMax );
            EditorGUI.LabelField( new Rect( position.x + xDivision * 2f, position.y, xDivision, yDivision ), "To: " );
            newMax = Mathf.Clamp( EditorGUI.FloatField( new Rect( position.x + xDivision * 2f + 24, position.y, xDivision - 24, yDivision ), newMax ), newMin, range.maxLimit );

            minValue.floatValue = newMin;
            maxValue.floatValue = newMax;
        }
    }
		// Draw the property inside the given rect
		public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
		{
			// Using BeginProperty / EndProperty on the parent property means that
			// prefab override logic works on the entire property.
			EditorGUI.BeginProperty(position, label, property);
			
			// Draw label
			//position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

			// Calculate rects
			var width = (position.width - 30) / 2;
			var openRect = new Rect(position.x, position.y, 30, position.height);
			var togglGORect = new Rect(position.x+31, position.y, width, position.height);
			var contentGORect = new Rect(position.x+30+width, position.y, width, position.height);

			// Draw fields - passs GUIContent.none to each so they are drawn without labels
			EditorGUI.PropertyField(openRect, property.FindPropertyRelative("Open"), GUIContent.none);
			EditorGUI.LabelField(openRect, new GUIContent("", "Is open on start?"));

			EditorGUI.PropertyField(togglGORect, property.FindPropertyRelative("ToggleObject"), GUIContent.none);
			EditorGUI.LabelField(togglGORect, new GUIContent("", "Toggle object. Click on this object show or hide Content object."));

			EditorGUI.PropertyField(contentGORect, property.FindPropertyRelative("ContentObject"), GUIContent.none);
			EditorGUI.LabelField(contentGORect, new GUIContent("", "Content object."));
			
			EditorGUI.EndProperty();
		}
		public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label) {


			SerializedProperty selection = prop.FindPropertyRelative("selection");
			SerializedProperty gameObject = prop.FindPropertyRelative("gameObject");

			CacheOwnerGameObject(prop.serializedObject);


			// draw the enum popup Field
			int oldEnumIndex = selection.enumValueIndex;

			EditorGUI.PropertyField(
				GetRectforRow(pos,0),
				selection,new GUIContent("Target"),true);

			if (oldEnumIndex !=selection.enumValueIndex)
			{
				if (selection.enumValueIndex==1)
				{
					gameObject.objectReferenceValue = ownerGameObject;
				}
			}

			if (selection.enumValueIndex==1)
			{
				EditorGUI.indentLevel++;

				EditorGUI.PropertyField(
					GetRectforRow(pos,1),
					gameObject,new GUIContent("Game Object"),true);
			}
	
		}
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        //EditorGUI.BeginProperty(position, GUIContent.none, property);
        //SerializedProperty memberProperty = property.FindPropertyRelative("PropertyName");
        //SerializedProperty typeProperty = property.FindPropertyRelative("Type");
        SerializedProperty propertyProperty = property.FindPropertyRelative("PropertyType");
        PropertyTypeInfo propertyTypeInfo = (PropertyTypeInfo) propertyProperty.enumValueIndex;
        SerializedProperty curve1Property = property.FindPropertyRelative("Curve1");
        SerializedProperty curve2Property = property.FindPropertyRelative("Curve2");
        SerializedProperty curve3Property = property.FindPropertyRelative("Curve3");
        SerializedProperty curve4Property = property.FindPropertyRelative("Curve4");

        int count = UnityPropertyTypeInfo.GetCurveCount(propertyTypeInfo);

        EditorGUI.indentLevel++;
            if(count > 0)
            EditorGUILayout.PropertyField(curve1Property);
            if (count > 1)
            EditorGUILayout.PropertyField(curve2Property);
            if (count > 2)
            EditorGUILayout.PropertyField(curve3Property);
            if (count > 3)
            EditorGUILayout.PropertyField(curve4Property);
        EditorGUI.indentLevel--;

        //EditorGUI.EndProperty();
    }
Example #6
0
    public static void Show(SerializedProperty list,
	                        EditorListOption options = EditorListOption.Default)
    {
        if (!list.isArray) {
            EditorGUILayout.HelpBox(list.name + " is neither an array nor a list!", MessageType.Error);
            return;
        }
        bool showListLabel = (options & EditorListOption.ListLabel) != 0;
        bool showListSize  = (options & EditorListOption.ListSize)  != 0;
        if (showListLabel) {
            EditorGUILayout.PropertyField(list);
            EditorGUI.indentLevel += 1;
        }
        if (!showListLabel || list.isExpanded) {
            SerializedProperty size = list.FindPropertyRelative("Array.size");
            if (showListSize) {
                EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));
            }
            if (size.hasMultipleDifferentValues) {
                EditorGUILayout.HelpBox("Not showing lists with different sizes.", MessageType.Info);
            } else {
                ShowElements(list, options);
            }
        }
        if (showListLabel) {
            EditorGUI.indentLevel -= 1;
        }
    }
        public static void DrawArrayElementLabelEffector(SerializedProperty effector, bool editHierarchy)
        {
            GUILayout.Space(Inspector.indent);
            if (editHierarchy) {
                EditorGUILayout.PropertyField(effector, new GUIContent(GetArrayName(effector.FindPropertyRelative("bones"), "Effector"), string.Empty), false, GUILayout.Width(100));
            } else {
                EditorGUILayout.LabelField(new GUIContent(GetArrayName(effector.FindPropertyRelative("bones"), "Effector"), string.Empty), GUILayout.Width(100));
            }

            GUILayout.Space(10);

            GUILayout.Label("Position", GUILayout.Width(50));
            effector.FindPropertyRelative("positionWeight").floatValue = GUILayout.HorizontalSlider(effector.FindPropertyRelative("positionWeight").floatValue, 0f, 1f, GUILayout.Width(50));

            GUILayout.Space(5);

            GUILayout.Label("Rotation", GUILayout.Width(50));
            effector.FindPropertyRelative("rotationWeight").floatValue = GUILayout.HorizontalSlider(effector.FindPropertyRelative("rotationWeight").floatValue, 0f, 1f, GUILayout.Width(50));

            if (!editHierarchy && effector.FindPropertyRelative("bones").arraySize > 1) {
                EditorGUILayout.LabelField(new GUIContent("Falloff", string.Empty), GUILayout.Width(50));
                EditorGUILayout.PropertyField(effector.FindPropertyRelative("falloff"), GUIContent.none);
                effector.FindPropertyRelative("falloff").floatValue = Mathf.Clamp(effector.FindPropertyRelative("falloff").floatValue, 0f, Mathf.Infinity);
            }
        }
	public static void construct(SerializedProperty prop){
		prop.FindPropertyRelative("name").stringValue = "Animation Set Name";         
		SerializedProperty animations = prop.FindPropertyRelative ("animations");
		animations.arraySize = 1;
		AnimationDrawer.construct (animations.GetArrayElementAtIndex(0));
		prop.serializedObject.ApplyModifiedProperties();
	}
Example #9
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);

            const int indentWidth = 16;
            var lineHeight = EditorGUIUtility.singleLineHeight;
            var lineSpace = EditorGUIUtility.standardVerticalSpacing;

            // these controls have single line height
            position.height = lineHeight;

            // interpolation type
            var type = property.FindPropertyRelative("_interpolationType");
            EditorGUI.PropertyField(position, type, label);

            if (CheckShouldExpand(property))
            {
                // indent the line
                position.width -= indentWidth;
                position.x += indentWidth;
                EditorGUIUtility.labelWidth -= indentWidth;

                // go to the next line
                position.y += lineHeight + lineSpace;

                // interpolation speed
                var speed = property.FindPropertyRelative("_interpolationSpeed");
                EditorGUI.PropertyField(position, speed, _textSpeed);
            }

            EditorGUI.EndProperty();
        }
Example #10
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        position.height = EditorGUIUtility.singleLineHeight;

        // First line: mode selector.
        var propMode = property.FindPropertyRelative("_mode");
        EditorGUI.IntPopup(position, propMode, modeLabels, modeValues, label);
        position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;

        // Indent the line.
        position.width -= 16;
        position.x += 16;
        EditorGUIUtility.labelWidth -= 16;

        // Reference box.
        var mode = (InjectorLink.Mode)propMode.intValue;
        if (propMode.hasMultipleDifferentValues || mode == InjectorLink.Mode.ByReference)
        {
            EditorGUI.PropertyField(position, property.FindPropertyRelative("_reference"));
            position.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing;
        }

        // Name box.
        if (propMode.hasMultipleDifferentValues || mode == InjectorLink.Mode.ByName)
            EditorGUI.PropertyField(position, property.FindPropertyRelative("_name"));

        // Update the link when it gets updated.
        if (GUI.changed) property.FindPropertyRelative("_forceUpdate").boolValue = true;

        EditorGUI.EndProperty();
    }
	public override void OnGUI (Rect position, SerializedProperty property, GUIContent label) 
	{
		label.text = "";
		
		// Using BeginProperty / EndProperty on the parent property means that
		// prefab override logic works on the entire property.
		EditorGUI.BeginProperty (position, label, property);
		
		// Draw label
		position = EditorGUI.PrefixLabel (position, GUIUtility.GetControlID (FocusType.Passive), label);
		
		// Don't make child fields be indented
		var indent = EditorGUI.indentLevel;
		EditorGUI.indentLevel = 0;
		
		// Calculate rects
		Rect pointsRect = new Rect (position.x, position.y, position.width * 0.6f, position.height);
		Rect streakRect = new Rect (pointsRect.x + pointsRect.width, position.y, position.width * 0.3f, position.height);
		
		// Draw fields - passs GUIContent.none to each so they are drawn without labels
		EditorGUIUtility.labelWidth = pointsRect.width * 0.5f;
		EditorGUI.PropertyField (pointsRect, property.FindPropertyRelative ("item"), GUIContent.none);
		EditorGUIUtility.labelWidth = streakRect.width * 0.3f;
		EditorGUI.PropertyField (streakRect, property.FindPropertyRelative ("percent"), new GUIContent("%"));
		
		// Set indent back to what it was
		EditorGUI.indentLevel = indent;
		
		EditorGUI.EndProperty ();
	}
	// Draw the property inside the given rect
	public override void OnGUI (Rect position, SerializedProperty property, GUIContent label)
	{
		// Using BeginProperty / EndProperty on the parent property means that
		// prefab override logic works on the entire property.
		EditorGUI.BeginProperty (position, label, property);

		//Get selected property
		int selectedValue = property.FindPropertyRelative("current").intValue;

		// Draw label
		label.text = "Property";
		position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

		//Get array of properties
		SerializedProperty sProp = property.FindPropertyRelative("properties");
		string[] properties = new string[sProp.arraySize];
		int[] values = new int[properties.Length];
		for (int i = 0; i < sProp.arraySize; i++)
		{
			properties[i] = sProp.GetArrayElementAtIndex(i).stringValue;
			values[i] = i;
		}

		//Draw enum
		selectedValue = EditorGUI.IntPopup(position, selectedValue, properties, values);

		//Save selected property
		property.FindPropertyRelative("current").intValue = selectedValue;


		EditorGUI.EndProperty();
	}
        // Draw the property inside the given rect
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(position, label, property);

            // Calculate rects:

            float halfWidth = position.width / 2;
            float questStateWidth = Mathf.Min(halfWidth, 160f) - 32f;
            float questNameWidth = position.width - questStateWidth - 16f;
            Rect questNameRect = new Rect(position.x + 16f, position.y, questNameWidth, position.height);
            Rect questStateRect = new Rect(position.x + questNameWidth + 16, position.y, questStateWidth, position.height);

            // Draw fields - pass GUIContent.none to each so they are drawn without labels
            var questName = property.FindPropertyRelative("questName");
            if (EditorTools.selectedDatabase == null) {
                EditorGUI.PropertyField(questNameRect, questName, GUIContent.none);
            } else {
                int questNameIndex;
                string[] questNames = GetQuestNames(questName.stringValue, out questNameIndex);
                int newQuestNameIndex = EditorGUI.Popup(questNameRect, questNameIndex, questNames);
                if (newQuestNameIndex != questNameIndex) {
                    questName.stringValue = GetQuestName(questNames, newQuestNameIndex);
                }
            }

            var questState = property.FindPropertyRelative("questState");
            EditorGUI.PropertyField(questStateRect, questState, GUIContent.none);

            EditorGUI.EndProperty();
        }
 private void DrawRangeField(Rect position, float labelWidth, float textFieldWidth, SerializedProperty prop, bool floatingPoint)
 {
     position.width = labelWidth;
     EditorGUI.LabelField(position, new GUIContent("Min", "Minimum value"));
     position.x += labelWidth;
     position.width = textFieldWidth;
     if (floatingPoint)
     {
         DrawFloatTextField(position, prop.FindPropertyRelative("Minimum"));
     }
     else
     {
         DrawIntTextField(position, prop.FindPropertyRelative("Minimum"));
     }
     position.x += textFieldWidth;
     position.width = labelWidth;
     EditorGUI.LabelField(position, new GUIContent("Max", "Maximum value"));
     position.x += labelWidth;
     position.width = textFieldWidth;
     if (floatingPoint)
     {
         DrawFloatTextField(position, prop.FindPropertyRelative("Maximum"));
     }
     else
     {
         DrawIntTextField(position, prop.FindPropertyRelative("Maximum"));
     }
 }
Example #15
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty(position, label, property);

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Presenter:", GUILayout.Width(65));
        EditorGUILayout.PropertyField(property.FindPropertyRelative("presenterName"), GUIContent.none);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Company:", GUILayout.Width(65));
        EditorGUILayout.PropertyField(property.FindPropertyRelative("company"), GUIContent.none);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Length (m):", GUILayout.Width(65));
        EditorGUILayout.IntSlider(property.FindPropertyRelative("presentationLength"), 0, 45, GUIContent.none);
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();
        GUILayout.Label("Title:", GUILayout.Width(65));
        EditorGUILayout.PropertyField(property.FindPropertyRelative("presentationTitle"), GUIContent.none);
        EditorGUILayout.EndHorizontal();

        EditorGUI.EndProperty();
    }
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        EditorGUI.BeginProperty (position, label, property);

        // Draw label
        position = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label);

        // Get properties
        var clipProp = property.FindPropertyRelative("clip");
        var volumeProp = property.FindPropertyRelative("volume");
        var vLabelContent = new GUIContent("Volume");

        // Calc rects
        var clipRect = new Rect(position.x, position.y, position.width, EditorGUIUtility.singleLineHeight);

        var volumeRect = new Rect(position.x, position.y + clipRect.height, position.width, EditorGUIUtility.singleLineHeight);
        var vLabelRect = new Rect(volumeRect.x, volumeRect.y, 50, volumeRect.height);
        var vSliderRect = new Rect(volumeRect.x + vLabelRect.width, volumeRect.y, volumeRect.width - vLabelRect.width, volumeRect.height);

        // Create labels
        var clipLabel = new GUIContent("clip");
        var volumeLabel = new GUIContent("volume");

        // Draw fields
        EditorGUI.BeginProperty(clipRect, clipLabel, clipProp);
            EditorGUI.PropertyField(clipRect, clipProp, GUIContent.none);
        EditorGUI.EndProperty();
        EditorGUI.BeginProperty(volumeRect, volumeLabel, volumeProp);
            EditorGUI.LabelField(vLabelRect, vLabelContent);
            EditorGUI.PropertyField(vSliderRect, volumeProp, GUIContent.none);
        EditorGUI.EndProperty();

        EditorGUI.EndProperty();
    }
		public override void OnGUI(Rect position, SerializedProperty prop, GUIContent label)
		{
			SerializedProperty hiddenValue = prop.FindPropertyRelative("hiddenValue");
			SetBoldIfValueOverridePrefab(prop, hiddenValue);

			SerializedProperty cryptoKey = prop.FindPropertyRelative("currentCryptoKey");
			SerializedProperty fakeValue = prop.FindPropertyRelative("fakeValue");
			SerializedProperty inited = prop.FindPropertyRelative("inited");

			int currentCryptoKey = cryptoKey.intValue;
			int val = 0;

			if (!inited.boolValue)
			{
				if (currentCryptoKey == 0)
				{
					currentCryptoKey = cryptoKey.intValue = ObscuredInt.cryptoKeyEditor;
				}
				hiddenValue.intValue = ObscuredInt.Encrypt(0, currentCryptoKey);
				inited.boolValue = true;
			}
			else
			{
				val = ObscuredInt.Decrypt(hiddenValue.intValue, currentCryptoKey);
			}

			EditorGUI.BeginChangeCheck();
			val = EditorGUI.IntField(position, label, val);
			if (EditorGUI.EndChangeCheck())
				hiddenValue.intValue = ObscuredInt.Encrypt(val, currentCryptoKey);

			fakeValue.intValue = val;
		}
        // 导出ExportAudioTrack
        private int ExportAudioTrack(AudioTrack audioTrack, JSONObject trackListArr, JSONObject clipListArr)
        {
            JSONObject trackJSON = GenerateBaseTrack(audioTrack, PlaybaleTrackTypeMap["AudioTrack"]);

#if UNITY_2019_1_OR_NEWER
            UnityEditor.SerializedObject   serializedObject           = new UnityEditor.SerializedObject(audioTrack);
            UnityEditor.SerializedProperty propertiesserializedObject = serializedObject.FindProperty("m_TrackProperties");
            float volume       = propertiesserializedObject.FindPropertyRelative("volume").floatValue;
            float stereoPan    = propertiesserializedObject.FindPropertyRelative("stereoPan").floatValue;
            float spatialBlend = propertiesserializedObject.FindPropertyRelative("spatialBlend").floatValue;
            trackJSON.AddField("volume", volume);
            trackJSON.AddField("stereoPan", stereoPan);
            trackJSON.AddField("spatialBlend", spatialBlend);
#else
            trackJSON.AddField("volume", 1);
            trackJSON.AddField("stereoPan", 0);
            trackJSON.AddField("spatialBlend", 0);
#endif

            JSONObject clipsIndexArr = trackJSON.GetField("clips");
            IEnumerable <TimelineClip> timelineClipList = audioTrack.GetClips();
            int num = 0;
            foreach (TimelineClip timelineClip in timelineClipList)
            {
                JSONObject clipJSON = GenerateBaseTimelineClip(timelineClip, PlaybaleClipTypeMap["Audio"]);
                JSONObject clipData = new JSONObject(JSONObject.Type.OBJECT);
                clipJSON.AddField("data", clipData);

                AudioPlayableAsset asset = (AudioPlayableAsset)timelineClip.asset;
                if ((UnityEngine.Object)asset.clip != (UnityEngine.Object)null)
                {
                    WXAudioClip converter = new WXAudioClip(asset.clip, gameObject);
                    string      clipPath  = AddDependencies(converter);
                    clipData.AddField("clip", clipPath);
                }
                else
                {
                    clipData.AddField("clip", JSONObject.nullJO);
                }
                // clipData.AddField("clipCaps", ClipCapsMap.ContainsKey(timelineClip.clipCaps) ? ClipCapsMap[timelineClip.clipCaps] : ClipCapsMap[ClipCaps.None]);
                // clipData.AddField("duration", (float)asset.duration);

                // 兼容2017没有loop
                UnityEditor.SerializedObject assetSerializedObject = new UnityEditor.SerializedObject(asset);
                bool loop = assetSerializedObject.FindProperty("m_Loop").boolValue;
                clipData.AddField("loop", loop);

#if UNITY_2019_1_OR_NEWER
                UnityEditor.SerializedProperty clipProperties = assetSerializedObject.FindProperty("m_ClipProperties");
                float clipVolume = clipProperties.FindPropertyRelative("volume").floatValue;
                clipData.AddField("volume", clipVolume);
#else
                clipData.AddField("volume", 1);
#endif

                clipsIndexArr.Add(ExportTimelineClip(clipJSON, clipListArr));
                num++;
            }
            return(ExportTrack(trackJSON, trackListArr));
        }
	public override void OnGUI (Rect pos, SerializedProperty prop, GUIContent label) {
		SerializedProperty context = prop.FindPropertyRelative ("context");
		SerializedProperty index = prop.FindPropertyRelative ("index");

		float p = TileRenderDrawer.previewSize((TileContext)context.enumValueIndex);
		float h = Mathf.Max (p + EditorUtil.padding, 2 * EditorUtil.row + 3);
		float w = pos.width;

		GUI.Box(new Rect (pos.x + 25, pos.y, w - 25, h), GUIContent.none);

		//
		EditorGUIUtility.labelWidth = 100;

		EditorGUI.BeginChangeCheck();

		EditorGUI.PropertyField (new Rect (pos.x, pos.y + h/2 - EditorUtil.row + 2, w - p - EditorUtil.padding, EditorUtil.height), context, new GUIContent("Context"));
		EditorGUI.PropertyField (new Rect (pos.x, pos.y + h/2 + 2, w - p - EditorUtil.padding, EditorUtil.height), index, new GUIContent("Index"));

		if (EditorGUI.EndChangeCheck ()) {
			prop.FindPropertyRelative("view").objectReferenceValue = TileRenderDrawer.constructPreview(prop);
		}

		Rect r = new Rect (pos.x + pos.width - p - 4, pos.y + 4 + (h - p - EditorUtil.padding)/2, p, p);
		Texture2D tex = (Texture2D)prop.FindPropertyRelative("view").objectReferenceValue;
		GUI.Box(r, tex == null? new GUIContent("Error"):new GUIContent(tex));
		
		EditorGUIUtility.labelWidth = 0;

		prop.serializedObject.ApplyModifiedProperties ();
	}
	public static Texture2D constructPreview(SerializedProperty spec){
		TextureAtlas atlas = TileSpecList.list.tileset;
		
		Texture2D tex = (Texture2D)spec.FindPropertyRelative ("view").objectReferenceValue;
		int index = spec.FindPropertyRelative ("index").intValue;
		
		switch ((TileContext)spec.FindPropertyRelative ("context").enumValueIndex) {
		case TileContext.None:
			tex = fillTexture(tex, 1, 1, atlas, new int[]{index});
			break;
		case TileContext.PartialContext:
			tex = fillTexture(tex, 3, 3, atlas, new int[]{
				index, index + 1, index + 2, 
				index + 4, index + 5, index + 6, 
				index + 8, index + 9, index + 10});
			break;
		case TileContext.FullContext:
			tex = fillTexture(tex, 5, 5, atlas, new int[]{
				index + 4, index + 34, index + 1, index + 33, index + 6, 
				index + 36, index + 22, index + 11, index + 20, index + 39, 
				index + 8, index + 25, index + 9, index + 25, index + 10,
				index + 40, index + 6, index + 11, index + 4, index + 43,
				index + 20, index + 46, index + 17, index + 45, index + 22});
			break;
		case TileContext.Slope:
			return null;
		}
		spec.FindPropertyRelative("view").objectReferenceValue = tex;
		spec.serializedObject.ApplyModifiedProperties ();
		return tex;
	}
    public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
    {
        var propText = property.FindPropertyRelative("text");
        var propTurnHead = property.FindPropertyRelative("turnHead");

        return EditorGUI.GetPropertyHeight(propText) + EditorGUI.GetPropertyHeight(propTurnHead);
    }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            float offset = 0f;
            if (!string.IsNullOrEmpty(label.text))
            {
                EditorGUI.LabelField(position, label);
                offset = 18f;
            }

            EditorGUI.BeginProperty(position, GUIContent.none, property);

            position.y += offset;
            EditorGUI.indentLevel++;

            var slopeRect = new Rect(position.x, position.y, position.width, 16f);
            var scaleRect = new Rect(position.x, position.y + 18f, position.width, 16f);
            var dropRect = new Rect(position.x, position.y + 36f, position.width, 16f);

            EditorGUI.PropertyField(slopeRect, property.FindPropertyRelative("maxSlopeAngle"), new GUIContent("Max Slope Angle", "The maximum angle at which a unit can walk."));
            EditorGUI.PropertyField(scaleRect, property.FindPropertyRelative("maxClimbHeight"), new GUIContent("Max Climb Height", "The maximum height that the unit can scale, i.e. walk onto even if it is a vertical move. Stairs for instance."));
            EditorGUI.PropertyField(dropRect, property.FindPropertyRelative("maxDropHeight"), new GUIContent("Max Drop Height", "The maximum height from which a unit can drop down to the ground below."));

            EditorGUI.indentLevel--;
            EditorGUI.EndProperty();
        }
    public override void OnEnable() {
        base.OnEnable();

        spriteObject = serializedObject.FindProperty("spriteObject");
        spriteObjectPivot = serializedObject.FindProperty("spriteObjectPivot");

        transformTranslate = serializedObject.FindProperty("transformTranslate");
        transformRotate = serializedObject.FindProperty("transformRotate");
        transformScale = serializedObject.FindProperty("transformScale");

        translateFunction = serializedObject.FindProperty("translateFunction");
        rotateFunction = serializedObject.FindProperty("rotateFunction");
        scaleFunction = serializedObject.FindProperty("scaleFunction");

        translateFunctionStart = translateFunction.FindPropertyRelative("startPosition");
        translateFunctionEnd = translateFunction.FindPropertyRelative("endPosition");
        translateAnimation = translateFunction.FindPropertyRelative("animationCurve");

        rotateFunctionStart = rotateFunction.FindPropertyRelative("startAngle");
        rotateFunctionEnd = rotateFunction.FindPropertyRelative("endAngle");
        rotateAnimation = rotateFunction.FindPropertyRelative("animationCurve");

        scaleFunctionStart = scaleFunction.FindPropertyRelative("startScale");
        scaleFunctionEnd = scaleFunction.FindPropertyRelative("endScale");
        scaleAnimation = scaleFunction.FindPropertyRelative("animationCurve");
    }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            this.targetTypeProperty = property.FindPropertyRelative("Type");
            this.providerProperty = property.FindPropertyRelative("Provider");
            this.constantProperty = property.FindPropertyRelative("Constant");
            this.referenceProperty = property.FindPropertyRelative("Reference");
            this.pathProperty = property.FindPropertyRelative("Path");

            var targetType = (DataBindingType)this.targetTypeProperty.enumValueIndex;
            float targetTypeHeight = 0;
            switch (targetType)
            {
                case DataBindingType.Context:
                    targetTypeHeight = EditorGUI.GetPropertyHeight(this.pathProperty);
                    break;
                case DataBindingType.Provider:
                    targetTypeHeight = EditorGUI.GetPropertyHeight(this.providerProperty);
                    break;
                case DataBindingType.Constant:
                    targetTypeHeight = EditorGUI.GetPropertyHeight(this.constantProperty);
                    break;
                case DataBindingType.Reference:
                    targetTypeHeight = EditorGUI.GetPropertyHeight(this.referenceProperty);
                    break;
            }

            return LineHeight + targetTypeHeight + LineSpacing;
        }
		public static void OnAddToArrayEffector(SerializedProperty effector) {
			effector.FindPropertyRelative("positionWeight").floatValue = 0f;
			effector.FindPropertyRelative("rotationWeight").floatValue = 0f;
			effector.FindPropertyRelative("falloff").floatValue = 0.5f;
			effector.FindPropertyRelative("position").vector3Value = Vector3.zero;
			effector.FindPropertyRelative("positionOffset").vector3Value = Vector3.zero;
		}
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //if (this.GetPropertyIsComplex(property))
            //{
            //    var ra = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            //    var rb = new Rect(position.xMin, position.yMin + EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight);

            //    var triggerProp = property.FindPropertyRelative("_trigger");
            //    _componentDrawer.OnGUI(ra, triggerProp, label);

            //    var idProp = property.FindPropertyRelative("_triggerId");
            //    var ids = (triggerProp.objectReferenceValue as IObservableTrigger).GetComplexIds();
            //    var oi = ids.IndexOf(idProp.stringValue);
            //    var ni = EditorGUI.Popup(rb, oi, ids);
            //    if (oi != ni)
            //    {
            //        idProp.stringValue = (ni >= 0) ? ids[ni] : null;
            //    }
            //}
            //else
            //{
            //    _componentDrawer.OnGUI(position, property.FindPropertyRelative("_trigger"), label);
            //}

            (_componentDrawer.ChoiceSelector as CustomComponentChoiceSelector).TriggerIdProp = property.FindPropertyRelative("_triggerId");
            _componentDrawer.OnGUI(position, property.FindPropertyRelative("_trigger"), label);
            (_componentDrawer.ChoiceSelector as CustomComponentChoiceSelector).TriggerIdProp = null;
        }
Example #27
0
        public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label)
        {
            SerializedProperty first = prop.FindPropertyRelative("first");
            SerializedProperty second = prop.FindPropertyRelative("second");

            // Using BeginProperty / EndProperty on the parent property means that
            // prefab override logic works on the entire property.
            EditorGUI.BeginProperty(pos, label, prop);

            // Draw label
            pos = EditorGUI.PrefixLabel(pos, GUIUtility.GetControlID(FocusType.Passive), label);

            // Don't make child fields be indented
            var indent = EditorGUI.indentLevel;
            EditorGUI.indentLevel = 0;

            // Calculate rects
            var amountRect = new Rect(pos.x, pos.y, 75, pos.height);
            var unitRect = new Rect(pos.x + 80, pos.y, 75, pos.height);

            // Draw fields - passs GUIContent.none to each so they are drawn without labels
            EditorGUI.PropertyField(amountRect, first, GUIContent.none);
            //EditorGUI.PropertyField(amountRect, prop.FindPropertyRelative("first"), GUIContent.none);
            EditorGUI.PropertyField(unitRect, second, GUIContent.none);

            // Set indent back to what it was
            EditorGUI.indentLevel = indent;

            EditorGUI.EndProperty();
        }
    /// <summary>
    /// 覆盖OnGUI方式,将使得BoolVector3的默认Inspector显示方式失效,采用自定义的显示方式
    /// </summary>
    /// <param name="position"></param>
    /// <param name="property"></param>
    /// <param name="label"></param>
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        // 默认显示方式
        // base.OnGUI(position, property, label);

        // 自定义
        {
            // 1.获得自定义属性类中,我们需要绘制的属性
            SerializedProperty x = property.FindPropertyRelative("x");
            SerializedProperty y = property.FindPropertyRelative("y");
            SerializedProperty z = property.FindPropertyRelative("z");

            float propWidth = position.width / 6.0f;

            // 2.创建对应属性的文本描述
            EditorGUI.LabelField(new Rect(position.x, position.y, propWidth, position.height), "X");
            // 3.创建对应属性的实际控制组件(如 bool,我们使用Toggle)
            x.boolValue = EditorGUI.Toggle(new Rect(position.x + propWidth * 1, position.y, propWidth, position.height), x.boolValue);

            EditorGUI.LabelField(new Rect(position.x + propWidth * 2, position.y, propWidth, position.height), "Y");
            y.boolValue = EditorGUI.Toggle(new Rect(position.x + propWidth * 3, position.y, propWidth, position.height), y.boolValue);

            EditorGUI.LabelField(new Rect(position.x + propWidth * 4, position.y, propWidth, position.height), "Z");
            z.boolValue = EditorGUI.Toggle(new Rect(position.x + propWidth * 5, position.y, propWidth, position.height), z.boolValue);
        }
    }
	public override void OnGUI (Rect position,
                                SerializedProperty property,
                                GUIContent label) 
	{
		// Using BeginProperty / EndProperty on the parent property means that		
		EditorGUI.BeginProperty (position, label, property);
		 
		EditorGUIUtility.LookLikeControls();
		
		string[] ver = UnityEditorInternal.InternalEditorUtility.GetFullUnityVersion().Substring(0,5).Replace('.',' ').Split(' ');
		if (int.Parse(ver[0]) == 4 && int.Parse(ver[1]) <=2)
		{
			position.x-=8;
		}
		
		// Draw label				
		_folded = EditorGUI.Foldout(position,_folded,label);	

		if (_folded)
		{
			position.height = 100;
			position.y +=18;
			position.x +=18; 
			EditorGUI.PropertyField(position, property.FindPropertyRelative("Position"));
			
			position.y +=18;
			EditorGUI.PropertyField(position, property.FindPropertyRelative("Rotation"));
			GUILayout.Space(35);
			
		}
		
		EditorGUI.EndProperty ();
		
		
	}
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
    {
        SerializedProperty direction = property.FindPropertyRelative ("direction");
        SerializedProperty accuracy = property.FindPropertyRelative ("accuracy");
        EditorGUI.BeginProperty (position, label, property);
        Rect contentPosition = EditorGUI.PrefixLabel (position, label);
        int indent = EditorGUI.indentLevel;
        EditorGUI.indentLevel = 0;

        float fullWidth = contentPosition.width;

        contentPosition.width = fullWidth * 0.2f;
        float x = contentPosition.x;

        contentPosition.x = x;
        EditorGUIUtility.labelWidth = 20f;
        EditorGUI.PropertyField (contentPosition, direction, new GUIContent ("Dir"));

        x += contentPosition.width;
        contentPosition.width = fullWidth * .4f;
        contentPosition.x = x;
        EditorGUIUtility.labelWidth = 50f;
        EditorGUI.PropertyField (contentPosition, accuracy);

        EditorGUI.indentLevel = indent;
        EditorGUI.EndProperty ();
    }
Example #31
0
    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) {
        GUI.Label(GetLineRect(position, 0), label);

        EditorGUI.indentLevel++;
        EditorGUI.PropertyField(GetLineRect(position, 1), property.FindPropertyRelative("chosenMethod"), new GUIContent("Lookup Method"));

        EditorGUI.indentLevel++;
        var method = GetChosenMethod(property);
        switch (method) {
            case ObjectFinder.Method.ByPath:
                EditorGUI.PropertyField(
                    GetLineRect(position, 2),
                    property.FindPropertyRelative("path"),
                    new GUIContent("Path"));
                break;
            case ObjectFinder.Method.ByTag:
                EditorGUI.PropertyField(
                    GetLineRect(position, 2),
                    property.FindPropertyRelative("tag"),
                    new GUIContent("Tag"));
                break;
            case ObjectFinder.Method.ByType:
                break;
            case ObjectFinder.Method.ByReference:
                EditorGUI.PropertyField(
                    GetLineRect(position, 2),
                    property.FindPropertyRelative("reference"),
                    new GUIContent("Camera"));
                break;
            default:
                throw new ArgumentOutOfRangeException();
        }
        EditorGUI.indentLevel -= 2;
    }
Example #32
0
        public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
        {
            var fpx = Helper.GetFPValue(property.FindPropertyRelative("x"));
            var fpy = Helper.GetFPValue(property.FindPropertyRelative("y"));
            var v   = UnityEditor.EditorGUI.Vector2Field(position, label, new Vector2(fpx, fpy));

            Helper.SetFPValue(property.FindPropertyRelative("x"), v.x);
            Helper.SetFPValue(property.FindPropertyRelative("y"), v.y);
        }
Example #33
0
        protected void RandomRangeVector3(string property, string label, float min, float max)
        {
            var volume = Property.FindPropertyRelative(property).vector3Value;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.MinMaxSlider(label, ref volume.x, ref volume.y, min, max);
            volume.x = Mathf.Round(volume.x * 100) / 100.0f;
            volume.y = Mathf.Round(volume.y * 100) / 100.0f;
            volume.x = EditorGUILayout.FloatField(volume.x, GUILayout.Width(50));
            volume.y = EditorGUILayout.FloatField(volume.y, GUILayout.Width(50));
            EditorGUILayout.EndHorizontal();

            Property.FindPropertyRelative(property).vector3Value = volume;
        }
        void UpdateNewTogglePropertyInfo(SP toggle)
        {
            var id             = toggle.FindPropertyRelative("id");
            var title          = toggle.FindPropertyRelative("title");
            var onDescription  = toggle.FindPropertyRelative("onDescription");
            var offDescription = toggle.FindPropertyRelative("offDescription");
            var interactable   = toggle.FindPropertyRelative("interactable");

            id.stringValue             = "TG" + (Math.Abs(toggle.GetHashCode())).ToString();
            title.stringValue          = String.Empty;
            onDescription.stringValue  = String.Empty;
            offDescription.stringValue = String.Empty;
            interactable.boolValue     = true;
        }
Example #35
0
        //EDITOR-ONLY SERIALIZATION:
#if UNITY_EDITOR
        public static E.SerializedProperty FindDeepProperty(this E.SerializedObject so, string path)
        {
            so.ApplyModifiedProperties();
            so.Update();

            string[] _pathArray = StringUtil.ToPathArray(path);

            E.SerializedProperty
                _so_parentDir = null,
                _so_targ      = null;

            if (_pathArray.Length > 1)
            {
                _so_parentDir = so.FindProperty(_pathArray[0]);
                for (int i = 0; i < _pathArray.Length - 1 /*go only through the parents, hence -1*/; i++)
                {
                    if (_so_parentDir != null)
                    {
                        if (i > 0)                         //iterate through the parents
                        {
                            _so_parentDir = _so_parentDir.FindPropertyRelative(_pathArray[i]);
                        }
                        _so_targ = _so_parentDir.FindPropertyRelative(_pathArray[i + 1]);
                    }
                    else
                    {
                        EditorUtil.Debug("[SETUtil_EditorUtil.FindDeepProperty ERROR] Invalid path element: " + _so_parentDir);
                    }
                }
            }
            else if (_pathArray.Length == 1)
            {
                _so_targ = so.FindProperty(_pathArray[0]);
            }
            else
            {
                EditorUtil.Debug("[SETUtil_EditorUtil.FindDeepProperty ERROR] Empty target path!");
                return(null);
            }

            if (_so_targ == null)
            {
                EditorUtil.Debug("[SETUtil_EditorUtil.FindDeepProperty ERROR] Nonexistent or inaccessible property: " + path + ". Make sure you are not targeting a MonoBehavior-derived class instance.");
                return(null);
            }

            return(_so_targ);
        }
        public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
        {
            KeyValuePairAttribute attr = (KeyValuePairAttribute)attribute;

            SerializedProperty keyProp = property.FindPropertyRelative(attr.KeyPropertyName);
            SerializedProperty valProp = property.FindPropertyRelative(attr.ValuePropertyName);

            GUIContent newLabel = new GUIContent(label);

            switch (keyProp.propertyType)
            {
            case SerializedPropertyType.String:
            case SerializedPropertyType.Integer:
            case SerializedPropertyType.Float:
            case SerializedPropertyType.LayerMask:
            case SerializedPropertyType.Character:
            case SerializedPropertyType.Enum:
                newLabel.text = keyProp.stringValue;
                break;

            case SerializedPropertyType.ObjectReference:
                newLabel.text = keyProp.objectReferenceValue == null ? string.Empty : keyProp.objectReferenceValue.name;
                break;
            }

            if (string.IsNullOrEmpty(newLabel.text))
            {
                newLabel.text = label.text;
            }

            newLabel = EditorGUI.BeginProperty(position, newLabel, property);
            position = EditorGUI.PrefixLabel(position, newLabel);

            using (GUIScopes.IndentLevelScope.SetIndent(0))
            {
                Rect keyPos = position;
                keyPos.width = (keyPos.width * 0.5f) - 2;

                EditorGUI.PropertyField(keyPos, keyProp, GUIContent.none, false);

                Rect valPos = keyPos;
                valPos.x += valPos.width + 4;

                EditorGUI.PropertyField(valPos, valProp, GUIContent.none, false);
            }

            EditorGUI.EndProperty();
        }
Example #37
0
    public static void GetClassFieldActions(FieldInfo[]  fieldInfos, UnityEditor.SerializedProperty serializedProperty,
                                            List <Action> actions)
    {
        for (int i = 0; i < fieldInfos.Length; i++)
        {
            var  fieldInfo   = fieldInfos[i];
            bool fieldIgnore = false;
            var  customAttrs = fieldInfo.GetCustomAttributes(false);
            foreach (var attr in customAttrs)
            {
                if (attr is IgnoreRelativeAttribute)
                {
                    fieldIgnore = true;
                    break;
                }
            }

            if (!fieldIgnore)
            {
                actions.Add(() => BuildSimple(serializedProperty.FindPropertyRelative(fieldInfo.Name), fieldInfo.Name));
            }
        }

        //  BuildVerticalBox(null, "SourceData");
    }
Example #38
0
    public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
    {
        string fieldName;
        bool   notifyPropertyChanged;

        {
            var attr = this.attribute as InspectorDisplayAttribute;
            fieldName             = (attr == null) ? "value" : attr.FieldName;
            notifyPropertyChanged = (attr == null) ? true : attr.NotifyPropertyChanged;
        }
        if (notifyPropertyChanged)
        {
            EditorGUI.BeginChangeCheck();
        }
        var targetSerializedProperty = property.FindPropertyRelative(fieldName);

        if (targetSerializedProperty == null)
        {
            UnityEditor.EditorGUI.LabelField(position, label, new GUIContent()
            {
                text = "InspectorDisplay can't find target:" + fieldName
            });
            if (notifyPropertyChanged)
            {
                EditorGUI.EndChangeCheck();
            }
            return;
        }
        else
        {
            EmitPropertyField(position, targetSerializedProperty, label);
        }
        if (notifyPropertyChanged)
        {
            if (EditorGUI.EndChangeCheck())
            {
                property.serializedObject.ApplyModifiedProperties();      // deserialize to field
                var paths             = property.propertyPath.Split('.'); // X.Y.Z...
                var attachedComponent = property.serializedObject.targetObject;
                var targetProp        = (paths.Length == 1)
                        ? fieldInfo.GetValue(attachedComponent)
                        : GetValueRecursive(attachedComponent, 0, paths);
                if (targetProp == null)
                {
                    return;
                }
                var propInfo      = targetProp.GetType().GetProperty(fieldName, BindingFlags.IgnoreCase | BindingFlags.GetProperty | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                var modifiedValue = propInfo.GetValue(targetProp, null);     // retrieve new value
                var methodInfo    = targetProp.GetType().GetMethod("SetValueAndForceNotify", BindingFlags.IgnoreCase | BindingFlags.InvokeMethod | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
                if (methodInfo != null)
                {
                    methodInfo.Invoke(targetProp, new object[] { modifiedValue });
                }
            }
            else
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }
    }
Example #39
0
    public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
    {
        if (popupStyle == null)
        {
            popupStyle = new GUIStyle(GUI.skin.GetStyle("PaneOptions"));
            popupStyle.imagePosition = ImagePosition.ImageOnly;
        }

        label    = UnityEditor.EditorGUI.BeginProperty(position, label, property);
        position = UnityEditor.EditorGUI.PrefixLabel(position, label);

        UnityEditor.EditorGUI.BeginChangeCheck();

        // Get properties
        UnityEditor.SerializedProperty useConstant   = property.FindPropertyRelative("UseConstant");
        UnityEditor.SerializedProperty constantValue = property.FindPropertyRelative("ConstantValue");
        UnityEditor.SerializedProperty variable      = property.FindPropertyRelative("Variable");

        // Calculate rect for configuration button
        Rect buttonRect = new Rect(position);

        buttonRect.yMin += popupStyle.margin.top;
        buttonRect.width = popupStyle.fixedWidth + popupStyle.margin.right;
        position.xMin    = buttonRect.xMax;

        // Store old indent level and set it to 0, the PrefixLabel takes care of it
        int indent = UnityEditor.EditorGUI.indentLevel;

        UnityEditor.EditorGUI.indentLevel = 0;

        int result = UnityEditor.EditorGUI.Popup(buttonRect, useConstant.boolValue ? 0 : 1, popupOptions, popupStyle);

        useConstant.boolValue = result == 0;

        UnityEditor.EditorGUI.PropertyField(position,
                                            useConstant.boolValue ? constantValue : variable,
                                            GUIContent.none);

        if (UnityEditor.EditorGUI.EndChangeCheck())
        {
            property.serializedObject.ApplyModifiedProperties();
        }

        UnityEditor.EditorGUI.indentLevel = indent;
        UnityEditor.EditorGUI.EndProperty();
    }
Example #40
0
        public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginChangeCheck();
            var targetSerializedProperty = property.FindPropertyRelative("component");

            UnityEditor.EditorGUI.PropertyField(position, targetSerializedProperty, label, includeChildren: true);
            EditorGUI.EndChangeCheck();
        }
Example #41
0
        public override void OnGUI(Rect pos, SP prop, GUIContent l)
        {
            if (l != GUIContent.none && !fieldInfo.FieldType.IsArray)
            {
                EditorGUI.PrefixLabel(pos, l);
            }

            pos.height = EditorGUIUtility.singleLineHeight;

            using (new EditorGUI.PropertyScope(pos, l, prop))
            {
                var cols  = pos.SliceHorizontalMixed(25f, 1f);
                var asset = prop.FindPropertyRelative(nameof(BuildScene.asset));
                var skip  = prop.FindPropertyRelative(nameof(BuildScene.skip));
                skip.boolValue = !EditorGUI.Toggle(cols[0], !skip.boolValue);
                EditorGUI.PropertyField(cols[1], asset, GUIContent.none);
            }
        }
Example #42
0
    //添加新的元素
    public void Add(string key, Object obj)
    {
        UnityEditor.SerializedObject serializedObject = new UnityEditor.SerializedObject(this);
        //根据PropertyPath读取数据
        //如果不知道具体的格式,可以右键用文本编辑器打开一个prefab文件(如Bundles/UI目录中的几个)
        //因为这几个prefab挂载了ReferenceCollector,所以搜索data就能找到存储的数据
        UnityEditor.SerializedProperty dataProperty = serializedObject.FindProperty("data");
        int i;

        //遍历data,看添加的数据是否存在相同key
        for (i = 0; i < data.Count; i++)
        {
            if (data[i].key == key)
            {
                break;
            }
        }
        //不等于data.Count意为已经存在于data List中,直接赋值即可
        if (i != data.Count)
        {
            //根据i的值获取dataProperty,也就是data中的对应ReferenceCollectorData,不过在这里,是对Property进行的读取,有点类似json或者xml的节点
            UnityEditor.SerializedProperty element = dataProperty.GetArrayElementAtIndex(i);
            //对对应节点进行赋值,值为gameobject相对应的fileID
            //fileID独一无二,单对单关系,其他挂载在这个gameobject上的script或组件会保存相对应的fileID
            element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
        }
        else
        {
            //等于则说明key在data中无对应元素,所以得向其插入新的元素
            dataProperty.InsertArrayElementAtIndex(i);
            UnityEditor.SerializedProperty element = dataProperty.GetArrayElementAtIndex(i);
            element.FindPropertyRelative("key").stringValue = key;
            element.FindPropertyRelative("gameObject").objectReferenceValue = obj;
        }
        //应用与更新
        UnityEditor.EditorUtility.SetDirty(this);
        serializedObject.ApplyModifiedProperties();
        serializedObject.UpdateIfRequiredOrScript();
    }
Example #43
0
        public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
        {
            var fpx = Helper.GetFPValue(property.FindPropertyRelative("x"));
            var fpy = Helper.GetFPValue(property.FindPropertyRelative("y"));
            var fpz = Helper.GetFPValue(property.FindPropertyRelative("z"));
            var fpw = Helper.GetFPValue(property.FindPropertyRelative("w"));
            var q   = new Quaternion(fpx, fpy, fpz, fpw);
            var v   = UnityEditor.EditorGUI.Vector3Field(position, label, q.eulerAngles);

            q = Quaternion.Euler(v);
            Helper.SetFPValue(property.FindPropertyRelative("x"), q.x);
            Helper.SetFPValue(property.FindPropertyRelative("y"), q.y);
            Helper.SetFPValue(property.FindPropertyRelative("z"), q.z);
            Helper.SetFPValue(property.FindPropertyRelative("w"), q.w);
        }
Example #44
0
        public static void ArrayField(UnityEditor.SerializedProperty list, string label = "")
        {
            UnityEditor.EditorGUILayout.PropertyField(list, new GUIContent((label.Length > 0) ? label : list.displayName));

            if (list.isExpanded)
            {
                UnityEditor.EditorGUI.indentLevel += 1;
                UnityEditor.EditorGUILayout.PropertyField(list.FindPropertyRelative("Array.size"));

                for (int i = 0; i < list.arraySize; i++)
                {
                    UnityEditor.EditorGUILayout.PropertyField(list.GetArrayElementAtIndex(i), true);
                }

                UnityEditor.EditorGUI.indentLevel -= 1;
            }
        }
Example #45
0
        public static void ShowRelativeProperty(UnityEditor.SerializedObject serializedObject, UnityEditor.SerializedProperty parentProperty, string propertyName)
        {
            UnityEditor.SerializedProperty property = parentProperty.FindPropertyRelative(propertyName);
            if (property != null)
            {
                UnityEditor.EditorGUI.indentLevel++;
                UnityEditor.EditorGUI.BeginChangeCheck();
                UnityEditor.EditorGUILayout.PropertyField(property, true);

                if (UnityEditor.EditorGUI.EndChangeCheck())
                {
                    serializedObject.ApplyModifiedProperties();
                }

                UnityEditor.EditorGUIUtility.labelWidth = 0f;
                UnityEditor.EditorGUI.indentLevel--;
            }
        }
        void UpdateNewButtonPropertyInfo(SP button)
        {
            var id                            = button.FindPropertyRelative("id");
            var title                         = button.FindPropertyRelative("title");
            var interactable                  = button.FindPropertyRelative("interactable");
            var titleColor                    = button.FindPropertyRelative("titleColor");
            var backgroundColor               = button.FindPropertyRelative("backgroundColor");
            var uninteractableTitleColor      = button.FindPropertyRelative("uninteractableTitleColor");
            var uninteractableBackgroundColor = button.FindPropertyRelative("uninteractableBackgroundColor");

            id.stringValue                           = "BT" + (Math.Abs(button.GetHashCode())).ToString();
            title.stringValue                        = String.Empty;
            interactable.boolValue                   = true;
            titleColor.colorValue                    = Color.white;
            backgroundColor.colorValue               = Color.gray;
            uninteractableTitleColor.colorValue      = Color.white;
            uninteractableBackgroundColor.colorValue = new Color(.25f, .25f, .25f, 1.0f);
        }
Example #47
0
                /// <summary>
                /// Draws the 'property' GUI in relation to the 'rootProperty' which was passed into
                /// <see cref="Editor.AnimancerStateSerializableDrawer.OnGUI"/>.
                /// </summary>
                protected override void DoPropertyGUI(ref Rect area,
                                                      UnityEditor.SerializedProperty baseProperty, UnityEditor.SerializedProperty property, GUIContent label)
                {
                    if (property.propertyPath.EndsWith("._StartTime"))
                    {
                        const float ToggleIndent = 13;
                        var         spacing      = UnityEditor.EditorGUIUtility.standardVerticalSpacing;

                        area.height = UnityEditor.EditorGUIUtility.singleLineHeight;

                        var timeArea   = area;
                        var toggleArea = new Rect(
                            UnityEditor.EditorGUIUtility.labelWidth + ToggleIndent,
                            timeArea.y,
                            area.height,
                            timeArea.height);

                        label.text = "Normalized";
                        if (_NormalizedWidth == 0)
                        {
                            _NormalizedWidth = Editor.AnimancerEditorUtilities.CalculateWidth(GUI.skin.toggle, label);
                        }

                        var normalizedArea = Editor.AnimancerEditorUtilities.StealWidth(ref timeArea, _NormalizedWidth);
                        normalizedArea.x += spacing;

                        var enabled = GUI.enabled;

                        // Set Start Time Toggle.

                        var wasUsingStartTime = !float.IsNaN(property.floatValue);

                        UnityEditor.EditorGUI.BeginProperty(toggleArea, GUIContent.none, property);
                        var useStartTime = GUI.Toggle(toggleArea, wasUsingStartTime, GUIContent.none);
                        UnityEditor.EditorGUI.EndProperty();

                        GUI.enabled = useStartTime;
                        float displayValue;
                        if (useStartTime)
                        {
                            if (!wasUsingStartTime)
                            {
                                property.floatValue = 0;
                            }

                            displayValue = property.floatValue;
                        }
                        else
                        {
                            if (wasUsingStartTime)
                            {
                                property.floatValue = float.NaN;
                            }

                            displayValue = 0;
                        }

                        // Time Field.

                        var labelWidth = UnityEditor.EditorGUIUtility.labelWidth;
                        UnityEditor.EditorGUIUtility.labelWidth += ToggleIndent + spacing;

                        label.text    = "Start Time";
                        label.tooltip = "If enabled, the animation's time will start at the following value";

                        UnityEditor.EditorGUI.BeginChangeCheck();
                        label        = UnityEditor.EditorGUI.BeginProperty(timeArea, label, property);
                        displayValue = UnityEditor.EditorGUI.FloatField(timeArea, label, displayValue);
                        UnityEditor.EditorGUI.EndProperty();
                        if (UnityEditor.EditorGUI.EndChangeCheck())
                        {
                            property.floatValue = displayValue;
                        }

                        UnityEditor.EditorGUIUtility.labelWidth = labelWidth;

                        // Normalized Toggle.

                        timeArea.x    = timeArea.xMax;
                        timeArea.xMax = area.xMax;

                        var normalizedProperty = baseProperty.FindPropertyRelative("_StartTimeIsNormalized");

                        UnityEditor.EditorGUI.BeginChangeCheck();

                        label.text = "Normalized";
                        label      = UnityEditor.EditorGUI.BeginProperty(normalizedArea, label, normalizedProperty);
                        var normalized = GUI.Toggle(normalizedArea, normalizedProperty.boolValue, label);
                        UnityEditor.EditorGUI.EndProperty();

                        if (UnityEditor.EditorGUI.EndChangeCheck())
                        {
                            normalizedProperty.boolValue = normalized;
                        }

                        GUI.enabled = enabled;

                        return;
                    }

                    base.DoPropertyGUI(ref area, baseProperty, property, label);
                }
        // 导出AnimationTrack
        private int ExportAnimationTrack(AnimationTrack animationTrack, JSONObject trackListArr, JSONObject clipListArr)
        {
            JSONObject trackJSON = GenerateBaseTrack(animationTrack, PlaybaleTrackTypeMap["AnimationTrack"]);

            trackJSON.AddField("applyAvatarMask", animationTrack.applyAvatarMask);
            JSONObject infiniteClipOffsetPositionArr = new JSONObject(JSONObject.Type.ARRAY);
            JSONObject infiniteClipOffsetRotationArr = new JSONObject(JSONObject.Type.ARRAY);

            trackJSON.AddField("infiniteClipOffsetPosition", infiniteClipOffsetPositionArr);
            trackJSON.AddField("infiniteClipOffsetRotation", infiniteClipOffsetRotationArr);
#if UNITY_2018_3_OR_NEWER
            trackJSON.AddField("trackOffset", TrackOffsetMap[animationTrack.trackOffset]);
#else
            if (animationTrack.applyOffsets)
            {
                trackJSON.AddField("trackOffset", TrackOffsetMap["ApplyTransformOffsets"]);
            }
            else
            {
                trackJSON.AddField("trackOffset", TrackOffsetMap["Auto"]);
            }
#endif
#if UNITY_2019_1_OR_NEWER
            infiniteClipOffsetPositionArr.Add(-animationTrack.infiniteClipOffsetPosition.x);
            infiniteClipOffsetPositionArr.Add(animationTrack.infiniteClipOffsetPosition.y);
            infiniteClipOffsetPositionArr.Add(animationTrack.infiniteClipOffsetPosition.z);
            infiniteClipOffsetRotationArr.Add(-animationTrack.infiniteClipOffsetRotation.x);
            infiniteClipOffsetRotationArr.Add(animationTrack.infiniteClipOffsetRotation.y);
            infiniteClipOffsetRotationArr.Add(animationTrack.infiniteClipOffsetRotation.z);
            infiniteClipOffsetRotationArr.Add(-animationTrack.infiniteClipOffsetRotation.w);
#else
            infiniteClipOffsetPositionArr.Add(-animationTrack.openClipOffsetPosition.x);
            infiniteClipOffsetPositionArr.Add(animationTrack.openClipOffsetPosition.y);
            infiniteClipOffsetPositionArr.Add(animationTrack.openClipOffsetPosition.z);
            infiniteClipOffsetRotationArr.Add(-animationTrack.openClipOffsetRotation.x);
            infiniteClipOffsetRotationArr.Add(animationTrack.openClipOffsetRotation.y);
            infiniteClipOffsetRotationArr.Add(animationTrack.openClipOffsetRotation.z);
            infiniteClipOffsetRotationArr.Add(-animationTrack.openClipOffsetRotation.w);
#endif
            if (animationTrack.avatarMask != null)
            {
                WXAvatarMask mask = new WXAvatarMask(animationTrack.avatarMask);
                string       uid  = AddDependencies(mask);
                trackJSON.AddField("avatarMask", uid);
            }
            else
            {
                trackJSON.AddField("avatarMask", new JSONObject(JSONObject.Type.NULL));
            }

            JSONObject positionArr = new JSONObject(JSONObject.Type.ARRAY);
            positionArr.Add(-animationTrack.position.x);
            positionArr.Add(animationTrack.position.y);
            positionArr.Add(animationTrack.position.z);
            trackJSON.AddField("position", positionArr);

            JSONObject rotationArr = new JSONObject(JSONObject.Type.ARRAY);
            rotationArr.Add(-animationTrack.rotation.x);
            rotationArr.Add(animationTrack.rotation.y);
            rotationArr.Add(animationTrack.rotation.z);
            rotationArr.Add(-animationTrack.rotation.w);
            trackJSON.AddField("rotation", rotationArr);

            JSONObject matchTargetFieldsJSON = new JSONObject(JSONObject.Type.OBJECT);
            trackJSON.AddField("matchTargetFields", matchTargetFieldsJSON);
            matchTargetFieldsJSON.AddField("PositionX", (animationTrack.matchTargetFields & MatchTargetFields.PositionX) == MatchTargetFields.PositionX);
            matchTargetFieldsJSON.AddField("PositionY", (animationTrack.matchTargetFields & MatchTargetFields.PositionY) == MatchTargetFields.PositionY);
            matchTargetFieldsJSON.AddField("PositionZ", (animationTrack.matchTargetFields & MatchTargetFields.PositionZ) == MatchTargetFields.PositionZ);
            matchTargetFieldsJSON.AddField("RotationX", (animationTrack.matchTargetFields & MatchTargetFields.RotationX) == MatchTargetFields.RotationX);
            matchTargetFieldsJSON.AddField("RotationY", (animationTrack.matchTargetFields & MatchTargetFields.RotationY) == MatchTargetFields.RotationY);
            matchTargetFieldsJSON.AddField("RotationZ", (animationTrack.matchTargetFields & MatchTargetFields.RotationZ) == MatchTargetFields.RotationZ);

            UnityEditor.SerializedObject   serializedObject = new UnityEditor.SerializedObject(animationTrack);
            UnityEditor.SerializedProperty serializedClip   = serializedObject.FindProperty("m_Clips");

            JSONObject clipsIndexArr = trackJSON.GetField("clips");
            if (animationTrack.inClipMode) // 普通clip
            // 貌似有时候序列化的m_Clips顺序跟 timelineClipList 的顺序对不上,但是很难复现。没有找到顺序可以必定对上的方法,先这样吧
            {
                IEnumerable <TimelineClip> timelineClipList = animationTrack.GetClips();
                int num = 0;
                foreach (TimelineClip timelineClip in timelineClipList)
                {
                    JSONObject clipJSON = GenerateBaseTimelineClip(timelineClip, PlaybaleClipTypeMap["Animation"]);
                    JSONObject clipData = new JSONObject(JSONObject.Type.OBJECT);
                    float      m_PostExtrapolationTime = (float)serializedClip.FindPropertyRelative("Array.data[" + num + "].m_PostExtrapolationTime").doubleValue;
                    float      m_PreExtrapolationTime  = (float)serializedClip.FindPropertyRelative("Array.data[" + num + "].m_PreExtrapolationTime").doubleValue;
                    clipJSON.SetField("postExtrapolationTime", m_PostExtrapolationTime);
                    clipJSON.SetField("preExtrapolationTime", m_PreExtrapolationTime);
                    clipJSON.AddField("data", clipData);

                    bool m_Recordable = serializedClip.FindPropertyRelative("Array.data[" + num + "].m_Recordable").boolValue;
                    clipData.AddField("recordable", m_Recordable);

                    string clipPath = ExportAnimationClip(timelineClip.animationClip);
                    if (string.IsNullOrEmpty(clipPath))
                    {
                        clipData.AddField("clip", JSONObject.nullJO);
                    }
                    else
                    {
                        clipData.AddField("clip", clipPath);
                    }


                    AnimationPlayableAsset asset = (AnimationPlayableAsset)timelineClip.asset;
                    // clipData.AddField("clipCaps", ClipCapsMap.ContainsKey(timelineClip.clipCaps) ? ClipCapsMap[timelineClip.clipCaps] : ClipCapsMap[ClipCaps.None]);
                    // clipData.AddField("duration", (float)asset.duration);
#if UNITY_2018_3_OR_NEWER
                    // 2018_3才开始支持
                    clipData.AddField("applyFootIK", asset.applyFootIK);
#else
                    clipData.AddField("applyFootIK", false);
#endif

#if UNITY_2019_1_OR_NEWER
                    // 2019_1才开始支持
                    clipData.AddField("loop", LoopModeMap[asset.loop]);
#else
                    clipData.AddField("loop", LoopModeMap["UseSourceAsset"]);
#endif

                    clipData.AddField("useTrackMatchFields", asset.useTrackMatchFields);

                    JSONObject clipMatchTargetFieldsJSON = new JSONObject(JSONObject.Type.OBJECT);
                    clipData.AddField("matchTargetFields", clipMatchTargetFieldsJSON);
                    clipMatchTargetFieldsJSON.AddField("PositionX", (asset.matchTargetFields & MatchTargetFields.PositionX) == MatchTargetFields.PositionX);
                    clipMatchTargetFieldsJSON.AddField("PositionY", (asset.matchTargetFields & MatchTargetFields.PositionY) == MatchTargetFields.PositionY);
                    clipMatchTargetFieldsJSON.AddField("PositionZ", (asset.matchTargetFields & MatchTargetFields.PositionZ) == MatchTargetFields.PositionZ);
                    clipMatchTargetFieldsJSON.AddField("RotationX", (asset.matchTargetFields & MatchTargetFields.RotationX) == MatchTargetFields.RotationX);
                    clipMatchTargetFieldsJSON.AddField("RotationY", (asset.matchTargetFields & MatchTargetFields.RotationY) == MatchTargetFields.RotationY);
                    clipMatchTargetFieldsJSON.AddField("RotationZ", (asset.matchTargetFields & MatchTargetFields.RotationZ) == MatchTargetFields.RotationZ);

                    JSONObject clipPositionArr = new JSONObject(JSONObject.Type.ARRAY);
                    clipPositionArr.Add(-asset.position.x);
                    clipPositionArr.Add(asset.position.y);
                    clipPositionArr.Add(asset.position.z);
                    clipData.AddField("position", clipPositionArr);

                    JSONObject clipRotationArr = new JSONObject(JSONObject.Type.ARRAY);
                    clipRotationArr.Add(-asset.rotation.x);
                    clipRotationArr.Add(asset.rotation.y);
                    clipRotationArr.Add(asset.rotation.z);
                    clipRotationArr.Add(-asset.rotation.w);
                    clipData.AddField("rotation", clipRotationArr);

                    clipsIndexArr.Add(ExportTimelineClip(clipJSON, clipListArr));
                    num++;
                }
            }
            else // infiniteClip
            {
#if UNITY_2019_1_OR_NEWER
                // 2019_1才开始支持
                AnimationClip infiniteClip = animationTrack.infiniteClip;
#else
                // 序列化取出私有变量
                UnityEditor.SerializedObject   trackSerializedObject = new UnityEditor.SerializedObject(animationTrack);
                UnityEditor.SerializedProperty animClipSerialize     = trackSerializedObject.FindProperty("m_AnimClip");
                AnimationClip infiniteClip = animClipSerialize.objectReferenceValue as AnimationClip;
#endif
                string infinityClipPath = ExportAnimationClip(infiniteClip);
                if (string.IsNullOrEmpty(infinityClipPath))
                {
                    trackJSON.SetField("infinityClip", JSONObject.nullJO);
                }
                else
                {
                    trackJSON.SetField("infinityClip", infinityClipPath);
                }
            }
            // 导出子track
            JSONObject childrenJSON = trackJSON.GetField("children");
            IEnumerable <TrackAsset> childTrackAssetList = animationTrack.GetChildTracks();
            List <int> indexList = ExportTrackList(childTrackAssetList, trackListArr, clipListArr);
            foreach (int index in indexList)
            {
                childrenJSON.Add(index);
            }
            return(ExportTrack(trackJSON, trackListArr));
        }
    public override void OnGUI(Rect position,
                               UnityEditor.SerializedProperty prop,
                               GUIContent label)
    {
        SerializedProperty defaultValue = prop.FindPropertyRelative("defaultValue");
        SerializedProperty exposedName  = prop.FindPropertyRelative("exposedName");

        var exposedNameStr = exposedName.stringValue;

        // 是默认值,GUID,还是名称
        var propertyMode = GetExposedPropertyMode(exposedNameStr);

        Rect propertyFieldPosition = position;

        propertyFieldPosition.xMax = propertyFieldPosition.xMax - ExposedReferencePropertyDrawer.kDriveWidgetWidth;

        Rect driveFieldPosition = position;

        driveFieldPosition.x     = propertyFieldPosition.xMax;
        driveFieldPosition.width = ExposedReferencePropertyDrawer.kDriveWidgetWidth;

        var exposedPropertyTable = GetExposedPropertyTable(prop);

        bool showContextMenu = exposedPropertyTable != null;
        var  propertyName    = new PropertyName(exposedNameStr);

        OverrideState currentOverrideState  = OverrideState.DefaultValue;
        var           currentReferenceValue = Resolve(propertyName, exposedPropertyTable, defaultValue.objectReferenceValue, out currentOverrideState);

        var previousColor      = GUI.color;
        var wasBoldDefaultFont = EditorGUIUtility.GetBoldDefaultFont();

        var valuePosition = DrawLabel(showContextMenu, currentOverrideState, label, position, exposedPropertyTable, exposedNameStr, exposedName, defaultValue);

        if (propertyMode == ExposedPropertyMode.DefaultValue || propertyMode == ExposedPropertyMode.NamedGUID)
        {
            OnRenderProperty(valuePosition, propertyName, currentReferenceValue, defaultValue, exposedName, propertyMode, exposedPropertyTable);
        }
        else
        {
            valuePosition.width /= 2;
            EditorGUI.BeginChangeCheck();
            exposedNameStr = EditorGUI.TextField(valuePosition, exposedNameStr);
            if (EditorGUI.EndChangeCheck())
            {
                exposedName.stringValue = exposedNameStr;
            }

            valuePosition.x += valuePosition.width;
            OnRenderProperty(valuePosition, new PropertyName(exposedNameStr), currentReferenceValue, defaultValue, exposedName, propertyMode, exposedPropertyTable);
        }

        GUI.color = previousColor;
        EditorGUIUtility.SetBoldDefaultFont(wasBoldDefaultFont);


        if (showContextMenu && GUI.Button(driveFieldPosition, GUIContent.none, kDropDownStyle))
        {
            GenericMenu menu = new GenericMenu();
            PopulateContextMenu(menu, currentOverrideState, exposedPropertyTable, exposedName, defaultValue);
            menu.ShowAsContext();
            Event.current.Use();
        }
    }
            public override float GetPropertyHeight(UnityEditor.SerializedProperty property, GUIContent label)
            {
                int extras = property.FindPropertyRelative(nameof(_originalImages)).arraySize;

                return(base.GetPropertyHeight(property, label) * (2 + _NUMBER_OF_FIELDS_DISPLAYED + (extras != 0 ? 1.3f * extras : 0)));
            }
            public override void OnGUI(Rect position, UnityEditor.SerializedProperty property, GUIContent label)
            {
                UnityEditor.EditorGUI.BeginProperty(position, label, property);

                var fieldLabel = new GUIStyle();

                fieldLabel.alignment = TextAnchor.UpperLeft;

                UnityEditor.EditorGUI.LabelField(position, label, fieldLabel);

                var   currentColorProperty = property.FindPropertyRelative(nameof(_currentColor));
                Color currentColor         = currentColorProperty.colorValue;

                var rendererRect = new Rect(position.x, position.y + _NEXT_FIELD_HEIGHT, position.width, _FIELD_HEIGHT);
                var spriteRect   = new Rect(position.x, position.y + _NEXT_FIELD_HEIGHT * 2, position.width, _FIELD_HEIGHT);

                UnityEditor.EditorGUI.indentLevel++;


                UnityEditor.EditorGUI.PropertyField(rendererRect, property.FindPropertyRelative(nameof(_renderer)));

                UnityEditor.EditorGUI.BeginDisabledGroup(true);
                int extraHeight = 0;

                if (!property.FindPropertyRelative(nameof(_hasManySprites)).boolValue)
                {
                    UnityEditor.EditorGUI.PropertyField(spriteRect, property.FindPropertyRelative(nameof(_originalImage)));
                }
                else
                {
                    var arrayProperty = property.FindPropertyRelative(nameof(_originalImages));
                    int length        = arrayProperty.arraySize;
                    extraHeight = length;
                    UnityEditor.EditorGUI.IntField(spriteRect, "Number of original images", length);
                    UnityEditor.EditorGUI.indentLevel++;
                    for (int i = 0; i < length; ++i)
                    {
                        spriteRect.y += _NEXT_FIELD_HEIGHT;
                        UnityEditor.EditorGUI.PropertyField(spriteRect, arrayProperty.GetArrayElementAtIndex(i));
                    }

                    UnityEditor.EditorGUI.indentLevel--;
                }

                var colorRect = new Rect(position.x, position.y + _NEXT_FIELD_HEIGHT * (3 + extraHeight), position.width, _FIELD_HEIGHT);
                var x         = Screen.width * 0.35f;

                float colorValuesRectHeight = position.y + _NEXT_FIELD_HEIGHT * (4 + extraHeight);

                var RRect      = new Rect(x, colorValuesRectHeight, position.width, _FIELD_HEIGHT);
                var RFieldRect = new Rect(x + _NEXT_COLOR_FIELD_WIDTH * 1, colorValuesRectHeight, _COLOR_FIELD_WIDTH, _FIELD_HEIGHT);
                var GRect      = new Rect(x + _NEXT_COLOR_FIELD_WIDTH * 3, colorValuesRectHeight, position.width, _FIELD_HEIGHT);
                var GFieldRect = new Rect(x + _NEXT_COLOR_FIELD_WIDTH * 4, colorValuesRectHeight, _COLOR_FIELD_WIDTH, _FIELD_HEIGHT);
                var BRect      = new Rect(x + _NEXT_COLOR_FIELD_WIDTH * 6, colorValuesRectHeight, position.width, _FIELD_HEIGHT);
                var BFieldRect = new Rect(x + _NEXT_COLOR_FIELD_WIDTH * 7, colorValuesRectHeight, _COLOR_FIELD_WIDTH, _FIELD_HEIGHT);
                var ARect      = new Rect(x + _NEXT_COLOR_FIELD_WIDTH * 9, colorValuesRectHeight, position.width, _FIELD_HEIGHT);
                var AFieldRect = new Rect(x + _NEXT_COLOR_FIELD_WIDTH * 10, colorValuesRectHeight, _COLOR_FIELD_WIDTH, _FIELD_HEIGHT);

                UnityEditor.EditorGUI.PropertyField(colorRect, currentColorProperty);

                UnityEditor.EditorGUI.indentLevel--;


                UnityEditor.EditorGUI.LabelField(RRect, "R", UnityEditor.EditorStyles.label);
                UnityEditor.EditorGUI.TextField(RFieldRect, (currentColor.r * 255f).ToString("0"));
                UnityEditor.EditorGUI.LabelField(GRect, "G", UnityEditor.EditorStyles.label);
                UnityEditor.EditorGUI.TextField(GFieldRect, (currentColor.g * 255f).ToString("0"));
                UnityEditor.EditorGUI.LabelField(BRect, "B", UnityEditor.EditorStyles.label);
                UnityEditor.EditorGUI.TextField(BFieldRect, (currentColor.b * 255f).ToString("0"));
                UnityEditor.EditorGUI.LabelField(ARect, "A", UnityEditor.EditorStyles.label);
                UnityEditor.EditorGUI.TextField(AFieldRect, (currentColor.a * 255f).ToString("0"));

                UnityEditor.EditorGUI.EndDisabledGroup();

                UnityEditor.EditorGUI.indentLevel++;
                UnityEditor.EditorGUI.PropertyField(new Rect(position.x, position.y + _NEXT_FIELD_HEIGHT * (5 + extraHeight), position.width, _FIELD_HEIGHT), property.FindPropertyRelative(nameof(_hasManySprites)));
                UnityEditor.EditorGUI.indentLevel--;

                UnityEditor.EditorGUI.EndProperty();
            }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.PropertyField(m_Sprite, Contents.spriteLabel);

            EditorGUILayout.PropertyField(m_Color, Contents.colorLabel, true);

            FlipToggles();

            Rect r = GUILayoutUtility.GetRect(
                EditorGUILayout.kLabelFloatMinW, EditorGUILayout.kLabelFloatMaxW,
                EditorGUI.kSingleLineHeight, EditorGUI.kSingleLineHeight);

            EditorGUI.showMixedValue = m_Material.hasMultipleDifferentValues;
            Object currentMaterialRef  = m_Material.GetArrayElementAtIndex(0).objectReferenceValue;
            Object returnedMaterialRef = EditorGUI.ObjectField(r, Contents.materialLabel, currentMaterialRef, typeof(Material), false);

            if (returnedMaterialRef != currentMaterialRef)
            {
                m_Material.GetArrayElementAtIndex(0).objectReferenceValue = returnedMaterialRef;
            }
            EditorGUI.showMixedValue = false;

            EditorGUILayout.PropertyField(m_DrawMode, Contents.drawModeLabel);

            m_ShowDrawMode.target = ShouldShowDrawMode();
            if (EditorGUILayout.BeginFadeGroup(m_ShowDrawMode.faded))
            {
                string notFullRectWarning = GetSpriteNotFullRectWarning();
                if (notFullRectWarning != null)
                {
                    EditorGUILayout.HelpBox(notFullRectWarning, MessageType.Warning);
                }

                EditorGUI.indentLevel++;
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(Contents.sizeLabel);
                EditorGUI.showMixedValue = m_Size.hasMultipleDifferentValues;
                FloatFieldLabelAbove(Contents.widthLabel, m_Size.FindPropertyRelative("x"));
                FloatFieldLabelAbove(Contents.heightLabel, m_Size.FindPropertyRelative("y"));
                EditorGUI.showMixedValue = false;
                EditorGUILayout.EndHorizontal();

                m_ShowTileMode.target = ShouldShowTileMode();
                if (EditorGUILayout.BeginFadeGroup(m_ShowTileMode.faded))
                {
                    EditorGUILayout.PropertyField(m_SpriteTileMode, Contents.fullTileLabel);

                    m_ShowAdaptiveThreshold.target = ShouldShowAdaptiveThreshold();
                    if (EditorGUILayout.BeginFadeGroup(m_ShowAdaptiveThreshold.faded))
                    {
                        EditorGUI.indentLevel++;
                        EditorGUILayout.Slider(m_AdaptiveModeThreshold, 0.0f, 1.0f, Contents.fullTileThresholdLabel);
                        EditorGUI.indentLevel--;
                    }
                    EditorGUILayout.EndFadeGroup();
                }
                EditorGUILayout.EndFadeGroup();
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndFadeGroup();

            RenderSortingLayerFields();

            EditorGUILayout.PropertyField(m_MaskInteraction, Contents.maskInteractionLabel);

            EditorGUILayout.PropertyField(m_SpriteSortPoint, Contents.spriteSortPointLabel);

            RenderRenderingLayer();

            CheckForErrors();

            serializedObject.ApplyModifiedProperties();
        }
Example #53
0
    public override void OnGUI(UnityEngine.Rect position, UnityEditor.SerializedProperty property, UnityEngine.GUIContent label)
    {
        SerializedProperty nameProp = property.FindPropertyRelative("_name");

        nameProp.stringValue = EditorGUI.TextField(position, nameProp.stringValue);
    }