本文整理汇总了C#中UnityEditor.SerializedObject.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedObject.Dispose方法的具体用法?C# SerializedObject.Dispose怎么用?C# SerializedObject.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.SerializedObject
的用法示例。
在下文中一共展示了SerializedObject.Dispose方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAudioAssets
private static void CreateAudioAssets()
{
if(Selection.objects.Length > 0)
{
foreach(Object obj in Selection.objects)
{
if(obj.GetType() == typeof(AudioClip))
{
string path = AssetDatabase.GetAssetPath(obj);
if(!string.IsNullOrEmpty(path))
{
path = Path.ChangeExtension(path, ".asset");
SerializedObject asset = new SerializedObject(CreateAudioAssetAtPath(path));
asset.FindProperty("audioClip").objectReferenceValue = obj;
asset.ApplyModifiedProperties();
asset.Dispose();
}
}
}
AssetDatabase.SaveAssets();
}
}
示例2: ChangeVersionControlMode
public static void ChangeVersionControlMode(VersionControlMods vcm, AssetSerializationMods asm)
{
var editorSettings =
new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/EditorSettings.asset")[0]);
editorSettings.FindProperty("m_ExternalVersionControlSupport").stringValue = vcm.ToString().Replace("_", " ");
editorSettings.FindProperty("m_SerializationMode").intValue = (int) asm;
editorSettings.ApplyModifiedProperties();
editorSettings.Dispose();
}
示例3: GetEditorId
private int GetEditorId( Object obj )
{
int editorId = 0;
PropertyInfo inspectorModeInfo = typeof(UnityEditor.SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance);
SerializedObject sObj = new SerializedObject(obj);
inspectorModeInfo.SetValue( sObj, UnityEditor.InspectorMode.Debug, null );
SerializedProperty sProp = sObj.FindProperty( "m_LocalIdentfierInFile" );
if ( sProp != null )
{
editorId = sProp.intValue;
sProp.Dispose();
}
sObj.Dispose();
return editorId;
}
示例4: CloneStates
/// <summary>
/// Paste the state in StateUtility.stateToPaste in the supplied fsm.
/// <param name="gameObject">The target gameObject.</param>
/// <param name="originalStates">The original states.</param>
/// <param name="parent">Optionally parent for the cloned states.</param>
/// </summary>
public static void CloneStates (GameObject gameObject, InternalStateBehaviour[] originalStates, ParentBehaviour parent) {
if (gameObject != null && originalStates != null && originalStates.Length > 0) {
var orginalClone = new Dictionary<InternalStateBehaviour, InternalStateBehaviour>();
var originalFsm = parent != null ? originalStates[0].parent as InternalStateMachine : null;
var newFsm = parent as InternalStateMachine;
InternalStateBehaviour startState = null, concurrentState = null;
InternalAnyState anyState = null;
// Copy blackboard data?
var newBlackboard = gameObject.GetComponent<InternalBlackboard>();
if (newBlackboard == null) {
// Get the original blackboard
InternalBlackboard originalBlackboard = originalStates[0].GetComponent<InternalBlackboard>();
#if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
Undo.RegisterSceneUndo("Paste State");
// Create the new blacbkoard
newBlackboard = gameObject.AddComponent(originalBlackboard.GetType()) as InternalBlackboard;
#else
// Create the new blacbkoard
newBlackboard = gameObject.AddComponent(originalBlackboard.GetType()) as InternalBlackboard;
if (newBlackboard != null)
Undo.RegisterCreatedObjectUndo(newBlackboard, "Paste State");
#endif
// Copy serialized values
EditorUtility.CopySerialized(originalBlackboard, newBlackboard);
}
foreach (InternalStateBehaviour state in originalStates) {
// Don't clone AnyState in StateMachines
if (state != null && (newFsm == null || !(state is InternalAnyState) || newFsm.anyState == null)) {
#if UNITY_4_0_0 || UNITY_4_1 || UNITY_4_2
Undo.RegisterSceneUndo("Paste State");
// Create a new state
var newState = gameObject.AddComponent(state.GetType()) as InternalStateBehaviour;
#else
// Create a new state
var newState = gameObject.AddComponent(state.GetType()) as InternalStateBehaviour;
if (newState != null)
Undo.RegisterCreatedObjectUndo(newState, "Paste State");
#endif
if (newState != null) {
// Store state
orginalClone.Add(state, newState);
// Copy serialized values
EditorUtility.CopySerialized(state, newState);
// Update blackboard
if (state.gameObject != newState.gameObject) {
var serialObj = new SerializedObject(newState);
serialObj.FindProperty("m_Blackboard").objectReferenceValue = newBlackboard;
serialObj.ApplyModifiedProperties();
serialObj.Dispose();
}
// Update the AnyState, StartState and ConcurrentState
if (newState is InternalStateMachine) {
var fsm = newState as InternalStateMachine;
fsm.startState = null;
fsm.concurrentState = null;
fsm.anyState = null;
}
EditorUtility.SetDirty(newState);
// Set new parent
if (parent != null) {
newState.parent = parent;
// Update position
if (parent == state.parent)
newState.position += new Vector2(20f, 20f);
}
else
newState.parent = null;
// Saves state and sets dirty flag
INodeOwner nodeOwner = newState as INodeOwner;
if (nodeOwner != null) {
nodeOwner.LoadNodes();
StateUtility.SetDirty(nodeOwner);
}
else
EditorUtility.SetDirty(newState);
// Try to get the StartState, AnyState and ConcurrentState
if (originalFsm != null) {
if (originalFsm.startState == state)
startState = newState;
if (anyState == null)
anyState = newState as InternalAnyState;
//.........这里部分代码省略.........
示例5: DoesHumanDescriptionMatch
private static bool DoesHumanDescriptionMatch(ModelImporter importer, ModelImporter otherImporter)
{
SerializedObject serializedObject = new SerializedObject(new UnityEngine.Object[]
{
importer,
otherImporter
});
SerializedProperty serializedProperty = serializedObject.FindProperty("m_HumanDescription");
bool result = !serializedProperty.hasMultipleDifferentValues;
serializedObject.Dispose();
return result;
}
示例6: PopulateReferenceMap
/// <summary>
/// Populate a reference map that goes SerializedProperty -> Object
/// </summary>
/// <param name="map">The map to populate entries into</param>
/// <param name="allObjects">The objects to read in order to determine the references</param>
private static void PopulateReferenceMap( List<KeyValuePair<SerializedProperty, Object>> map, IEnumerable<Object> allObjects )
{
foreach( var obj in allObjects )
{
// Flags that indicate we aren't rooted in the scene
if ( obj.hideFlags == HideFlags.HideAndDontSave )
continue;
SerializedObject so = new SerializedObject(obj);
SerializedProperty sp = so.GetIterator();
bool bCanDispose = true;
while ( sp.Next(true) )
{
// Only care about object references
if ( sp.propertyType != SerializedPropertyType.ObjectReference )
continue;
// Skip the nulls
if ( sp.objectReferenceInstanceIDValue == 0 )
continue;
map.Add( new KeyValuePair<SerializedProperty,Object>(sp.Copy(), sp.objectReferenceValue) );
bCanDispose = false;
}
// This will help relieve memory pressure (thanks llde_chris)
if ( bCanDispose )
{
sp.Dispose();
so.Dispose();
}
}
}
示例7: ApplyRootMotionBoneName
/// <summary>
/// Sets the name of the root motion bone.
/// </summary>
/// <param name="imp">Imp.</param>
/// <param name="szValue">Size value.</param>
public static void ApplyRootMotionBoneName(ModelImporter imp, string szValue)
{
SerializedObject impSO = new SerializedObject(imp);
SerializedProperty rootMotion = impSO.FindProperty(PType.m_HumanDescription.ToString()).FindPropertyRelative(PType.m_RootMotionBoneName.ToString());
rootMotion.stringValue = szValue;
SerializedProperty type = impSO.FindProperty(PType.m_AnimationType.ToString());
type.enumValueIndex = 2;
impSO.ApplyModifiedProperties();
impSO.Dispose();
}
示例8: EditElement
void EditElement(CGElement element,CreateGUI main)
{
GUILayout.BeginHorizontal("helpbox");
GUILayout.Label(element.GetType()+" - "+element.name+"","BoldLabel");
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal("helpbox");
element.name = EditorGUILayout.TextField("Name",element.name);
GUILayout.EndHorizontal();
GUILayout.BeginVertical();
FieldInfo [] fields = element.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
foreach(FieldInfo fi in fields){
if(!fi.IsNotSerialized){
GUILayout.BeginHorizontal("helpbox");
char[] propertyName = fi.Name.ToCharArray();
if(propertyName.Length>0) propertyName[0] = char.ToUpper(propertyName[0]);
SerializedObject tempSerializedObj = new SerializedObject(element);
SerializedProperty targetProperty = tempSerializedObj.FindProperty(fi.Name);
EditorGUILayout.PropertyField(targetProperty,true);
tempSerializedObj.ApplyModifiedProperties();
tempSerializedObj.Dispose();
GUILayout.EndHorizontal();
}
}
GUILayout.EndVertical();
GUILayout.Space(10);
}
示例9: DoesHumanDescriptionMatch
private static bool DoesHumanDescriptionMatch(ModelImporter importer, ModelImporter otherImporter)
{
SerializedObject serializedObject = new SerializedObject(new UnityEngine.Object[2]{ (UnityEngine.Object) importer, (UnityEngine.Object) otherImporter });
bool flag = !serializedObject.FindProperty("m_HumanDescription").hasMultipleDifferentValues;
serializedObject.Dispose();
return flag;
}
示例10: CopyBehaviour
static void CopyBehaviour( StateBehaviour source,StateBehaviour dest,bool checkStateLink )
{
if( dest == null )
{
return;
}
ArborFSMInternal stateMachine = dest.stateMachine;
int stateID = dest.stateID;
bool expanded = dest.expanded;
EditorUtility.CopySerialized( source,dest );
dest.expanded = expanded;
SerializedObject serializedObject = new SerializedObject( dest );
serializedObject.Update();
SerializedProperty stateMachineProperty = serializedObject.FindProperty( "_StateMachine" );
stateMachineProperty.objectReferenceValue = stateMachine;
SerializedProperty stateIDProperty = serializedObject.FindProperty( "_StateID" );
stateIDProperty.intValue = stateID;
if( checkStateLink )
{
SerializedProperty iterator = serializedObject.GetIterator();
while( iterator.NextVisible(true) )
{
if( iterator.type == "StateLink" )
{
if( iterator.isArray )
{
for( int i=0;i<iterator.arraySize;i++ )
{
SerializedProperty stateLinkProperty = iterator.GetArrayElementAtIndex( i );
SerializedProperty property = stateLinkProperty.FindPropertyRelative( "stateID" );
if( property.intValue == stateID || stateMachine != source.stateMachine || stateMachine.GetStateFromID( property.intValue ) == null )
{
property.intValue = 0;
}
}
}
else
{
SerializedProperty property = iterator.FindPropertyRelative( "stateID" );
if( property.intValue == stateID || stateMachine != source.stateMachine || stateMachine.GetStateFromID( property.intValue ) == null )
{
property.intValue = 0;
}
}
}
}
}
serializedObject.ApplyModifiedProperties();
serializedObject.Dispose();
}
示例11: StateTitlebar
public static void StateTitlebar( Rect position,State state )
{
int controlId = GUIUtility.GetControlID(s_StateTitlebarHash,EditorGUIUtility.native, position);
Event current = Event.current;
EventType typeForControl = current.GetTypeForControl(controlId);
// position.x -= 4;
// position.width += 3+5;
position.y -= 5;
position.height += 5+3;
Rect namePosition = s_StateTitlebar.padding.Remove(position);
namePosition.height = 16;
namePosition.width -= 16+8;
Rect popupPosition = new Rect( namePosition.xMax+8 , namePosition.y , 16 , namePosition.height );
if( current.type == EventType.Repaint )
{
s_StateTitlebar.Draw( position,GUIContent.none,controlId,false );
}
string name = EditorGUI.TextField( namePosition,state.name );
if( name != state.name )
{
ArborFSMInternal stateMachine = state.stateMachine;
Undo.RecordObject( stateMachine,"Rename State" );
state.name = name;
EditorUtility.SetDirty( stateMachine );
}
switch (typeForControl)
{
case EventType.MouseDown:
if( popupPosition.Contains( current.mousePosition ) )
{
GenericMenu menu = new GenericMenu();
SerializedObject serializedObject = new SerializedObject( state.stateMachine );
SerializedProperty startStateIDPropery = serializedObject.FindProperty( "_StartStateID" );
if( startStateIDPropery.intValue == state.stateID )
{
menu.AddDisabledItem( GetTextContent("Set Start State") );
}
else
{
menu.AddItem( GetTextContent("Set Start State"),false,SetStartStateContextMenu,state );
}
BehaviourMenuUtility.AddMenu( state,menu );
if( _CopyBehaviour != null )
{
menu.AddItem( GetTextContent("Paste Behaviour"),false,PasteBehaviourToStateContextMenu,state );
}
else
{
menu.AddDisabledItem( GetTextContent("Paste Behaviour") );
}
serializedObject.Dispose();
menu.DropDown( popupPosition );
current.Use();
}
break;
case EventType.Repaint:
s_BehaviourTitlebarText.Draw(popupPosition, s_ContextPopupContent, controlId, false);
break;
}
}
示例12: SetStartStateContextMenu
static void SetStartStateContextMenu( object obj )
{
State state = obj as State;
ArborFSMInternal stateMachine = state.stateMachine;
SerializedObject serializedObject = new SerializedObject( stateMachine );
serializedObject.Update();
SerializedProperty startStateIDPropery = serializedObject.FindProperty( "_StartStateID" );
startStateIDPropery.intValue = state.stateID;
serializedObject.ApplyModifiedProperties();
serializedObject.Dispose();
}
示例13: DoesHumanDescriptionMatch
private static bool DoesHumanDescriptionMatch(ModelImporter importer, ModelImporter otherImporter)
{
UnityEngine.Object[] objs = new UnityEngine.Object[] { importer, otherImporter };
SerializedObject obj2 = new SerializedObject(objs);
bool flag = !obj2.FindProperty("m_HumanDescription").hasMultipleDifferentValues;
obj2.Dispose();
return flag;
}
示例14: ClearMaterialCrum
void ClearMaterialCrum(Material mat) {
var so = new SerializedObject(mat);
so.Update();
var textures = so.FindProperty("m_SavedProperties.m_TexEnvs");
ClearMaterialArray(PropType.Texture, textures);
var floats = so.FindProperty("m_SavedProperties.m_Floats");
ClearMaterialArray(PropType.Float, floats);
var colors = so.FindProperty("m_SavedProperties.m_Colors");
ClearMaterialArray(PropType.Color, colors);
so.ApplyModifiedProperties();
so.Dispose();
}
示例15: DisconnectPropertyFromPrefab
/// <summary>
/// Disconnect a property from a prefab.
/// <param name="target">The target Object.</param>
/// <param name="propertyPath">The target property to be disconnect.</param>
/// </summary>
public static void DisconnectPropertyFromPrefab (UnityEngine.Object target, string propertyPath) {
var serialObj = new SerializedObject(target);
var targetProperty = serialObj.FindProperty(propertyPath);
if (targetProperty != null) {
var endProperty = targetProperty.GetEndProperty();
do {
if (!targetProperty.prefabOverride) {
switch (targetProperty.propertyType) {
case SerializedPropertyType.Integer:
if (targetProperty.intValue == 0)
targetProperty.intValue = 1;
else
targetProperty.intValue = 0;
break;
case SerializedPropertyType.String:
var stringValue = targetProperty.stringValue;
if (stringValue.Equals(" "))
targetProperty.stringValue = string.Empty;
else
targetProperty.stringValue = " ";
break;
case SerializedPropertyType.Float:
if (targetProperty.floatValue == 0f)
targetProperty.floatValue = 1f;
else
targetProperty.floatValue = 0f;
break;
case SerializedPropertyType.Boolean:
targetProperty.boolValue = !targetProperty.boolValue;
break;
case SerializedPropertyType.Color:
targetProperty.colorValue = ChangeColor(targetProperty.colorValue);
break;
case SerializedPropertyType.Enum:
targetProperty.enumValueIndex = targetProperty.enumValueIndex + 1;
break;
case SerializedPropertyType.ObjectReference:
if (targetProperty.objectReferenceValue == null || targetProperty.objectReferenceValue != target)
targetProperty.objectReferenceValue = target;
else
targetProperty.objectReferenceValue = null;
break;
}
}
} while (targetProperty.Next(true) && !SerializedProperty.EqualContents(targetProperty, endProperty));
serialObj.ApplyModifiedProperties();
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
// targetProperty.Dispose();
// Edit array size == 0
serialObj.Update();
targetProperty = serialObj.FindProperty(propertyPath);
endProperty = targetProperty.GetEndProperty();
do {
if (!targetProperty.prefabOverride && targetProperty.propertyType == SerializedPropertyType.ArraySize)
targetProperty.arraySize = 1;
} while (targetProperty.Next(true) && !SerializedProperty.EqualContents(targetProperty, endProperty));
serialObj.ApplyModifiedProperties();
PrefabUtility.RecordPrefabInstancePropertyModifications(target);
targetProperty.Dispose();
}
serialObj.Dispose();
}