private void OnDisable() { if (inputManagerAsset != null) { inputManagerAsset.Dispose(); } }
private void SetupReferencedClip(string otherModelImporterPath) { SerializedObject targetImporter = GetModelImporterSerializedObject(otherModelImporterPath); // We may receive a path that doesn't have a importer. if (targetImporter != null) { targetImporter.CopyFromSerializedProperty(serializedObject.FindProperty("m_AnimationType")); SerializedProperty copyAvatar = targetImporter.FindProperty("m_CopyAvatar"); if (copyAvatar != null) { copyAvatar.boolValue = true; } SerializedProperty avatar = targetImporter.FindProperty("m_LastHumanDescriptionAvatarSource"); if (avatar != null) { avatar.objectReferenceValue = m_Avatar; } CopyHumanDescriptionToDestination(serializedObject, targetImporter); targetImporter.ApplyModifiedProperties(); targetImporter.Dispose(); } }
/// <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(); } } }
protected virtual void DisplayPriorities() { EditorGUILayout.Space(); EditorExtensions.LabelFieldCustom("Priority Settings", FontStyle.Bold); EditorGUILayout.PropertyField(entityDataManager); if (!entityDataManager.objectReferenceValue) { return; } //get data var entData = new SerializedObject(entityDataManager.objectReferenceValue); var entities = entData.FindProperty("entities"); chasePriorities.arraySize = entities.arraySize; fleePriorities.arraySize = entities.arraySize; lookAtPriorities.arraySize = entities.arraySize; //get id names var idNames = new string[chasePriorities.arraySize]; for (int i = 0; i < entities.arraySize; i++) { idNames[i] = i.ToString(); } //chase priorities DoPriorityList(chasePriorities, entities, idNames); DoPriorityList(lookAtPriorities, entities, idNames); DoPriorityList(fleePriorities, entities, idNames); entData.Dispose(); }
private void OnDisable() { if (m_SerializedObject != null) { m_SerializedObject.Dispose(); } }
public override void OnGUI(string searchContext) { GUIStyle style = new GUIStyle(EditorStyles.label) { alignment = TextAnchor.MiddleCenter, fontStyle = FontStyle.Bold }; foreach (var pair in m_settingsInstance) { if (GUILayout.Button(pair.Key.Name, style)) { Selection.activeObject = pair.Value; EditorUtility.FocusProjectWindow(); } SerializedObject sObj = new SerializedObject(pair.Value); foreach (FieldInfo field in pair.Key.GetFields()) { EditorGUILayout.PropertyField(sObj.FindProperty(field.Name), true); } EditorGUILayout.Space(); sObj.ApplyModifiedProperties(); sObj.Dispose(); } }
private static void RemoveNestedElements(SerializedProperty serializedProperty, int index) { var propertyElement = serializedProperty.GetArrayElementAtIndex(index); var collection = propertyElement.objectReferenceValue as ScriptableObjectCollectionBase; if (collection != null) { Undo.RegisterCompleteObjectUndo(collection, $"Remove {collection.name}"); var serializedObject = new SerializedObject(collection); var propertyCollection = serializedObject.FindProperty("m_collection"); for (int i = 0; i < propertyCollection.arraySize; i++) { var propertyCollectionElement = propertyCollection.GetArrayElementAtIndex(i); if (propertyCollectionElement.objectReferenceValue != null) { Undo.DestroyObjectImmediate(propertyCollectionElement.objectReferenceValue); } } propertyCollection.ClearArray(); serializedObject.ApplyModifiedProperties(); serializedObject.Dispose(); } }
private void CopyHumanDescriptionFromOtherModel(Avatar sourceAvatar) { string srcAssetPath = AssetDatabase.GetAssetPath(sourceAvatar); SerializedObject srcImporter = GetModelImporterSerializedObject(srcAssetPath); CopyHumanDescriptionToDestination(srcImporter, serializedObject); srcImporter.Dispose(); }
void OnDisable() { m_TargetPrefab = null; m_TargetAnimations = null; m_SerializedWindow.Dispose(); m_AnimationProperty.Dispose(); EditorApplication.update -= Tick; }
private static void Dispose(ref SerializedObject @object) { if (@object != null) { @object.Dispose(); @object = null; } }
/// <summary> /// 分析对象的引用 /// </summary> /// <param name="info"></param> /// <param name="o"></param> public void AnalyzeObjectReference(Object o, AssetBundle ab) { if (o == null || asset_ab_Dict.ContainsKey(o)) { return; } asset_ab_Dict.Add(o, ab); var serializedObject = new SerializedObject(o); bool isAsset = IsAsset(o); if (isAsset) { long guid; SerializedProperty pathIdProp = serializedObject.FindProperty("m_LocalIdentfierInFile"); if (pathIdProp == null) { pathIdProp = serializedObject.FindProperty("LocalIdentfierInFile"); } #if UNITY_5 || UNITY_5_3_OR_NEWER guid = pathIdProp.longValue; #else if (pathIdProp != null) { guid = pathIdProp.intValue; } else { guid = o.GetInstanceID(); } #endif assetGuidDict.Add(o, guid); guidAssetDict.Add(guid, o); } if (inspectorMode == null) { inspectorMode = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance); } inspectorMode.SetValue(serializedObject, InspectorMode.Debug, null); var it = serializedObject.GetIterator(); while (it.NextVisible(true)) { if (it.propertyType == SerializedPropertyType.ObjectReference && it.objectReferenceValue != null) { AnalyzeObjectReference(it.objectReferenceValue, ab); } } // 只能用另一种方式获取的引用 AnalyzeObjectReference2(o, ab); serializedObject.Dispose(); }
public override void OnInspectorGUI() { if (water.transform.rotation != Quaternion.identity) { string warning = "The water object is designed to work without rotation. Some features may not work correctly."; EditorGUILayout.LabelField(warning, PEditorCommon.WarningLabel); } water.Profile = PEditorCommon.ScriptableObjectField <PWaterProfile>("Profile", water.Profile); profile = water.Profile; if (water.Profile == null) { return; } so = new SerializedObject(profile); reflectionLayersSO = so.FindProperty("reflectionLayers"); refractionLayersSO = so.FindProperty("refractionLayers"); EditorGUI.BeginChangeCheck(); DrawMeshSettingsGUI(); DrawRenderingSettingsGUI(); DrawColorsSettingsGUI(); DrawFresnelSettingsGUI(); DrawRippleSettingsGUI(); DrawWaveSettingsGUI(); DrawLightAbsorbtionSettingsGUI(); DrawFoamSettingsGUI(); DrawReflectionSettings(); DrawRefractionSettings(); DrawCausticSettings(); if (EditorGUI.EndChangeCheck()) { EditorUtility.SetDirty(profile); water.UpdateMaterial(); } DrawEffectsGUI(); if (willDrawDebugGUI) { DrawDebugGUI(); } if (so != null) { so.Dispose(); } if (reflectionLayersSO != null) { reflectionLayersSO.Dispose(); } if (refractionLayersSO != null) { refractionLayersSO.Dispose(); } }
private void DrawTilableMeshGUI() { if (!isEditingTileIndices) { EditorGUI.BeginChangeCheck(); //water.MeshType = (PWaterMeshType)EditorGUILayout.EnumPopup("Mesh Type", water.MeshType); water.MeshType = (PWaterMeshType)EditorGUILayout.IntPopup("Mesh Type", (int)water.MeshType, meshTypeLabels, meshTypes); water.PlanePattern = (PPlaneMeshPattern)EditorGUILayout.EnumPopup("Pattern", water.PlanePattern); water.MeshResolution = EditorGUILayout.DelayedIntField("Resolution", water.MeshResolution); if (EditorGUI.EndChangeCheck()) { water.GenerateMesh(); water.ReCalculateBounds(); } water.MeshNoise = EditorGUILayout.FloatField("Noise", water.MeshNoise); EditorGUI.BeginChangeCheck(); water.TileSize = PEditorCommon.InlineVector2Field("Tile Size", water.TileSize); water.TilesFollowMainCamera = EditorGUILayout.Toggle("Follow Main Camera", water.TilesFollowMainCamera); SerializedObject so = new SerializedObject(water); SerializedProperty sp = so.FindProperty("tileIndices"); if (sp != null) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(sp, true); if (EditorGUI.EndChangeCheck()) { so.ApplyModifiedProperties(); } } sp.Dispose(); so.Dispose(); if (EditorGUI.EndChangeCheck()) { water.ReCalculateBounds(); } } if (!isEditingTileIndices) { if (GUILayout.Button("Edit Tiles")) { isEditingTileIndices = true; } } else { EditorGUILayout.LabelField("Edit water tiles in Scene View.", PEditorCommon.WordWrapItalicLabel); if (GUILayout.Button("End Editing Tiles")) { isEditingTileIndices = false; } } }
object GetSavedProp(Material mat, string name, string dataType, bool removeProp) { var obj = new SerializedObject(mat); var savedProps = obj.FindProperty("m_SavedProperties"); var elements = savedProps.FindPropertyRelative(dataType); object returnValue = null; int propIndex = -1; for (int i = 0; i < elements.arraySize; ++i) { var entry = elements.GetArrayElementAtIndex(i); SerializedProperty data = null; #if UNITY_5_6_OR_NEWER var nameProp = entry.FindPropertyRelative("first"); #else var nameProp = entry.FindPropertyRelative("first").FindPropertyRelative("name"); #endif if (nameProp.stringValue != name) { continue; } data = entry.FindPropertyRelative("second"); if (data != null) { var val = GetValue(data); if (val != null) { propIndex = i; returnValue = val; break; } else if (data.hasChildren) { var otherDataList = new List <object>(); otherDataList.Add(GetValue(data.FindPropertyRelative("m_Texture"))); otherDataList.Add(GetValue(data.FindPropertyRelative("m_Scale"))); otherDataList.Add(GetValue(data.FindPropertyRelative("m_Offset"))); propIndex = i; returnValue = otherDataList; break; } } } if (removeProp && propIndex > -1) { elements.DeleteArrayElementAtIndex(propIndex); } obj.ApplyModifiedPropertiesWithoutUndo(); obj.Dispose(); return(returnValue); }
public override void OnInspectorGUI() { serializedObject.Update(); StyleEditorEx.DrawContextField(_contextProp); DrawPropertiesExcluding(serializedObject, ExcludedProperties); EditorGUILayout.ObjectField(_targetProp); if (_targetProp.objectReferenceValue == null) { EditorGUILayout.HelpBox("Target is null", MessageType.Error); } GUILayout.Space(10); if (_assetProp != null) { EditorGUILayout.ObjectField(_assetProp); } if (_assetProp?.objectReferenceValue != null) { if (_styleAssetSerializedObject?.targetObject != _assetProp.objectReferenceValue) { _styleAssetSerializedObject?.Dispose(); _styleAssetSerializedObject = new SerializedObject(_assetProp.objectReferenceValue); _assetStyleListEditor = new StyleListEditor(_styleAssetSerializedObject, Apply, false); } _assetStyleListEditor.DoLayout(); } else { _styleAssetSerializedObject?.Dispose(); _styleAssetSerializedObject = null; _selfStyleListEditor.DoLayout(); } serializedObject.ApplyModifiedProperties(); }
public IEnumerator <SerializedProperty> GetEnumerator() { SerializedProperty end = prop.GetEndProperty(); while (prop.NextVisible(true) && !SerializedProperty.EqualContents(prop, end)) { yield return(prop); } serializedObject.Dispose(); }
private void OnDisable() { //set blend tile selection index EditorPrefs.SetInt(BT_INDEX_KEY, _bt_index); //set rule selection index EditorPrefs.SetInt(RL_INDEX_KEY, _rl_index); //set add blend rule object _rule_prop.Dispose(); _rule_obj.Dispose(); DestroyImmediate(_config); }
public IEnumerator <SerializedProperty> GetEnumerator() { SerializedProperty prop = serializedObject.GetIterator(); while (PauseIteratorOnce || prop.NextVisible(true)) { PauseIteratorOnce = false; yield return(prop); } serializedObject.Dispose(); }
public static void ScanObjects() { var allGameObjects = Object.FindObjectsOfType <GameObject>(); try { for (int i = 0; i < allGameObjects.Length; ++i) { EditorUtility.DisplayProgressBar("Scanning objects", allGameObjects[i].name, i / (float)allGameObjects.Length); foreach (var component in allGameObjects[i].GetComponents <Component>()) { var so = new SerializedObject(component); var sp = so.GetIterator(); while (sp.Next(true)) { if (sp.propertyPath == "m_PrefabParentObject") { continue; } if (sp.propertyType == SerializedPropertyType.ObjectReference) { if (sp.objectReferenceInstanceIDValue == 0) { continue; } if (sp.objectReferenceValue) { continue; } var rp = component as ReflectionProbe; if (rp && rp.mode != UnityEngine.Rendering.ReflectionProbeMode.Custom && sp.propertyPath == "m_CustomBakedTexture") { continue; } Debug.LogWarningFormat(component, "Component of type {0} on gameobject {1} has property \"{2}\" with a missing object reference.", component.GetType(), component.gameObject, sp.propertyPath); } } so.Dispose(); } } } finally { EditorUtility.ClearProgressBar(); } }
private void OnDisable() { if (_openWindow == this) { _openWindow = null; } if (_inputManagerAsset != null) { _inputManagerAsset.Dispose(); _inputManagerAsset = null; } }
static bool DoesHumanDescriptionMatch(ModelImporter importer, ModelImporter otherImporter) { SerializedObject so = new SerializedObject(new Object[] { importer, otherImporter }); so.maxArraySizeForMultiEditing = Math.Max(importer.transformPaths.Length, otherImporter.transformPaths.Length); SerializedProperty prop = so.FindProperty("m_HumanDescription"); bool matches = !prop.hasMultipleDifferentValues; so.Dispose(); return(matches); }
internal static void EnterPreview(SerializedProperty track) { // Debug.Log("Enter preview"); // restore old foreach (var cache in _previewing) { if (cache.clip.context == null) { continue; } if (cache.clip._setter == null) { continue; } cache.clip._setter(cache.value); } _previewing.Clear(); // enter new if (_pSo != null) { _pSo.Dispose(); } _pSp = track; _previewCounter = 0; _previewPlaying = false; if (track == null) { return; } _pSo = new SerializedObject(_pSp.serializedObject.targetObject); _pSp = _pSo.FindProperty(_pSp.propertyPath); var clipsSp = track.FindPropertyRelative("clips"); for (int i = 0; i < clipsSp.arraySize; ++i) { var clip = TweenerTrackClipDrawer.Get(clipsSp.GetArrayElementAtIndex(i)); TweenerTrack.Clip.Init(ref clip); _previewing.Add(new ClipCache { clip = clip, value = clip._getter() }); } EvaluateClips(); _previewDuration = track.FindPropertyRelative("duration").floatValue; _lastUpdate = EditorApplication.timeSinceStartup; }
public static void LayoutSyncSelectionArrayField (this SerializedProperty _layoutSyncSelectionArray, SerializedProperty _valueSelections, SerializedProperty _layoutMaster) { layoutMaster = _layoutMaster; var master = new SerializedObject(layoutMaster.objectReferenceValue); var layouts = master.FindProperty("layouts"); layoutNames = layouts.GetDisplayNames(); valueSelections = _valueSelections; _layoutSyncSelectionArray.ArrayFieldButtons("Value Sync", true, true, false, false, LayoutSyncSelectionField, true); master.Dispose(); }
private void DisposeSerializedObject() { mShowBuildTarget.valueChanged.RemoveListener(Repaint); if (mSerializedObject == null) { return; } if (mSerializedObject.targetObject) { mSerializedObject.ApplyModifiedProperties(); } mSerializedObject.Dispose(); mSerializedObject = null; }
private void DrawAreaMeshGUI() { if (!isEditingAreaMesh) { EditorGUI.BeginChangeCheck(); //water.MeshType = (PWaterMeshType)EditorGUILayout.EnumPopup("Mesh Type", water.MeshType); water.MeshType = (PWaterMeshType)EditorGUILayout.IntPopup("Mesh Type", (int)water.MeshType, meshTypeLabels, meshTypes); water.MeshResolution = EditorGUILayout.DelayedIntField("Resolution", water.MeshResolution); if (EditorGUI.EndChangeCheck()) { water.GenerateMesh(); water.ReCalculateBounds(); } water.MeshNoise = EditorGUILayout.FloatField("Noise", water.MeshNoise); SerializedObject so = new SerializedObject(water); SerializedProperty sp = so.FindProperty("areaMeshAnchors"); if (sp != null) { EditorGUI.BeginChangeCheck(); EditorGUILayout.PropertyField(sp, true); if (EditorGUI.EndChangeCheck()) { so.ApplyModifiedProperties(); } } sp.Dispose(); so.Dispose(); } if (!isEditingAreaMesh) { if (GUILayout.Button("Edit Area")) { isEditingAreaMesh = true; } } else { if (GUILayout.Button("End Editing Area")) { isEditingAreaMesh = false; water.GenerateAreaMesh(); water.ReCalculateBounds(); } } }
/// <summary> /// 分析对象的引用 /// </summary> /// <param name="info"></param> /// <param name="o"></param> public void SettingObjectReference(Object o) { if (new_asset_Setting_Dict.ContainsKey(o)) { return; } new_asset_Setting_Dict.Add(o, true); var serializedObject = new SerializedObject(o); if (inspectorMode == null) { inspectorMode = typeof(SerializedObject).GetProperty("inspectorMode", BindingFlags.NonPublic | BindingFlags.Instance); } inspectorMode.SetValue(serializedObject, InspectorMode.Debug, null); bool hasSet = false; var it = serializedObject.GetIterator(); while (it.NextVisible(true)) { if (it.propertyType == SerializedPropertyType.ObjectReference && it.objectReferenceValue != null) { if (new_asset_obj_Dict.ContainsKey(it.objectReferenceValue)) { hasSet = true; it.objectReferenceValue = new_asset_obj_Dict[it.objectReferenceValue]; } else { Object uo = GetUnityAssset(it.objectReferenceValue); if (uo != null) { hasSet = true; it.objectReferenceValue = uo; } } } } if (hasSet) { serializedObject.ApplyModifiedProperties(); } SettingObjectReference2(o); serializedObject.Dispose(); }
private void DrawInternalShaderSettings() { string label = "Internal Shaders"; string id = "runtime-settings-internal-shaders"; GEditorCommon.Foldout(label, false, id, () => { SerializedObject so = new SerializedObject(instance); SerializedProperty internalShaders = so.FindProperty(nameof(instance.internalShaders)); EditorGUILayout.PropertyField(internalShaders, new GUIContent("Internal Shaders"), true); so.ApplyModifiedProperties(); internalShaders.Dispose(); so.Dispose(); }); }
public static string[] GetInputAxisNames() { //put all input managers axis into an array var inputManager = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]; var obj = new SerializedObject(inputManager); var axisArray = obj.FindProperty("m_Axes"); var inputAxisNames = new string[axisArray.arraySize]; for (int i = 0; i < inputAxisNames.Length; i++) { inputAxisNames[i] = axisArray.GetArrayElementAtIndex(i).FindPropertyRelative("m_Name").stringValue; } obj.Dispose(); return(inputAxisNames); }
public void ResetBindings() { fieldValues?.Clear(); if (fields?.Count > 0) { fields.ForEach(f => f.UnregisterValueChangedCallback(HandleValueChanged)); fields.Clear(); } if (serializedObject != null) { serializedObject.Dispose(); serializedObject = null; } }
static HashSet <Texture> CollectTexturesFromMaterial(Material mat) { var result = new HashSet <Texture>(); var so = new SerializedObject(mat); var texturesProp = so.FindProperty("m_SavedProperties.m_TexEnvs"); for (int i = 0; i < texturesProp.arraySize; ++i) { var tex = texturesProp.GetArrayElementAtIndex(i).FindPropertyRelative("second.m_Texture").objectReferenceValue as Texture; if (tex) { result.Add(tex); } } so.Dispose(); return(result); }