版本: Unity 6 (6000.0)
语言English
  • C#

SerializedProperty.hasMultipleDifferentValues

建议修改

成功!

感谢您帮助我们改进 Unity 文档的质量。虽然我们无法接受所有提交,但我们确实阅读了用户提出的每一个建议修改,并在适用的情况下进行更新。

关闭

提交失败

由于某些原因,您的建议修改无法提交。请<a>稍后再试</a>。感谢您抽出时间帮助我们改进 Unity 文档的质量。

关闭

取消

public bool hasMultipleDifferentValues;

描述

由于多对象编辑,此属性是否表示多个不同的值?(只读)

当存在多个目标对象,并且它们的值不都相同的时候返回 true。其他资源:SerializedObject.targetObjectsSerializedObject.SetIsDifferentCacheDirty

using UnityEngine;
using UnityEditor;

public class SerializePropertyHasMultipleDifferentValuesExample : ScriptableObject { public int m_Matching; public int m_Different;

[MenuItem("Example/SerializedProperty hasMultipleDifferentValues Example")] static void HasMultipleDifferentValuesExample() { var instance1 = ScriptableObject.CreateInstance<SerializePropertyHasMultipleDifferentValuesExample>(); instance1.m_Matching = 1; instance1.m_Different = 1;

var instance2 = ScriptableObject.CreateInstance<SerializePropertyHasMultipleDifferentValuesExample>(); instance2.m_Matching = 1; instance2.m_Different = 2;

using (var serializedObject = new SerializedObject(new ScriptableObject[] { instance1, instance2 })) { var matchingProperty = serializedObject.FindProperty("m_Matching"); var differentProperty = serializedObject.FindProperty("m_Different");

// Outputs //m_Matching value: 1, matching: True //m_Different value: 1, matching: False Debug.Log($"m_Matching value: {matchingProperty.intValue}, matching: {!matchingProperty.hasMultipleDifferentValues}\n" + $"m_Different value: {differentProperty.intValue}, matching: {!differentProperty.hasMultipleDifferentValues}"); } } }