public static void CreateNewGameLevel() { // Ask the user if they would like to save the current scene if need be, if they do not press cancel... if (EditorApplication.SaveCurrentSceneIfUserWantsTo()) { // ... then load a new scene. EditorApplication.NewScene(); // We do not want the default `Main Camera` object do destroy that. Object.DestroyImmediate(GameObject.Find("Main Camera")); // For each required prefab file name... foreach (string levelRequirement in LevelRequirementPrefabs) { // ... load the prefab from the asset database. GameObject requiredPrefab = AssetDatabase.LoadAssetAtPath<GameObject>(RootLevelRequirements + levelRequirement); // Instantiate it within the new scene connected to the prefab. PrefabUtility.InstantiatePrefab(requiredPrefab); } // Reference the objects that need connecting to each other. EndOfLevel endOfLevel = Object.FindObjectOfType<EndOfLevel>(); LevelController levelController = Object.FindObjectOfType<LevelController>(); CameraController cameraController = Object.FindObjectOfType<CameraController>(); Player player = Object.FindObjectOfType<Player>(); // Disconect required objects from prefabs if appropriate to do so. PrefabUtility.DisconnectPrefabInstance(endOfLevel); // Create a new serialized object of the end of level. SerializedObject serializedEndOfLevel = new SerializedObject(endOfLevel); // Set the appropriate properties to their correct values. serializedEndOfLevel.FindProperty("menuSwitcher").objectReferenceValue = Object.FindObjectOfType<MenuSwitcher>(); // Apply the changed properties without an undo. serializedEndOfLevel.ApplyModifiedPropertiesWithoutUndo(); // Create a new serialized object of the level controller. SerializedObject serializedLevelController = new SerializedObject(levelController); // Set the appropriate properties to their correct values. serializedLevelController.FindProperty("cameraController").objectReferenceValue = cameraController; serializedLevelController.FindProperty("player").objectReferenceValue = player; // Apply the changed properties without an undo. serializedLevelController.ApplyModifiedPropertiesWithoutUndo(); // Create a new serialized object of the camera controller. SerializedObject serializedCameraController = new SerializedObject(cameraController); // Set the appropriate properties to their correct values. serializedCameraController.FindProperty("target").objectReferenceValue = player.GetComponent<CameraTarget>(); // Apply the changed properties without an undo. serializedCameraController.ApplyModifiedPropertiesWithoutUndo(); } }
public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); prefabBrush.currentBrush = (TileType)EditorGUILayout.EnumPopup("Brush Type", prefabBrush.currentBrush); EditorGUILayout.PropertyField(m_Prefabs, true); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); prefabBrush.index = EditorGUILayout.IntField("Index", prefabBrush.index); EditorGUILayout.PropertyField(m_Prefabs, true); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); prefabBrush.m_PerlinScale = EditorGUILayout.Slider("Perlin Scale", prefabBrush.m_PerlinScale, 0.001f, 0.999f); prefabBrush.m_Z = EditorGUILayout.IntField("Position Z", prefabBrush.m_Z); EditorGUILayout.PropertyField(m_Prefabs, true); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); cellBrush.m_PerlinScale = EditorGUILayout.Slider("Perlin Scale", cellBrush.m_PerlinScale, 0.001f, 0.999f); cellBrush.m_Z = EditorGUILayout.IntField("Position Z", cellBrush.m_Z); cellBrush.allowOverlap = EditorGUILayout.Toggle("Allow Overlap", cellBrush.allowOverlap); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); prefabBrush.m_Index = EditorGUILayout.IntSlider("Index to spawn", prefabBrush.m_Index, 0, prefabBrush.m_Prefabs.Length - 1); prefabBrush.m_Z = EditorGUILayout.IntField("Position Z", prefabBrush.m_Z); EditorGUILayout.PropertyField(m_Prefabs, true); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); // prefabBrush.m_PerlinScale = EditorGUILayout.Slider("Perlin Scale", prefabBrush.m_PerlinScale, 0.001f, 0.999f); prefabBrush.m_Z = EditorGUILayout.IntField("Position Z", prefabBrush.m_Z); prefabBrush.m_Amount = (EditorGUILayout.IntSlider("Amount", prefabBrush.m_Amount, 5, 500) / 5) * 5; prefabBrush.m_ItemType = (ItemType)EditorGUILayout.EnumPopup("ItemType", prefabBrush.m_ItemType); EditorGUILayout.PropertyField(m_Prefabs, true); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public override bool ApplyRevert(bool apply) { if (apply) { if (containsMultipleSprites) { var oldNames = new List <string>(); var newNames = new List <string>(); for (int i = 0; i < m_RectsCache.spriteRects.Count; i++) { SpriteRect spriteRect = (SpriteRect)m_RectsCache.spriteRects[i]; if (string.IsNullOrEmpty(spriteRect.name)) { spriteRect.name = "Empty"; } if (!string.IsNullOrEmpty(spriteRect.originalName)) { oldNames.Add(spriteRect.originalName); newNames.Add(spriteRect.name); } } var so = new SerializedObject(m_SpriteDataProvider.targetObject); if (oldNames.Count > 0) { PatchImportSettingRecycleID.PatchMultiple(so, 213, oldNames.ToArray(), newNames.ToArray()); } so.ApplyModifiedPropertiesWithoutUndo(); } m_SpriteDataProvider.SetSpriteRects(m_RectsCache?.spriteRects.ToArray()); if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); } } else { if (m_RectsCache != null) { undoSystem.ClearUndo(m_RectsCache); m_RectsCache.spriteRects = m_SpriteDataProvider.GetSpriteRects().ToList(); spriteEditor.spriteRects = m_RectsCache.spriteRects; if (spriteEditor.selectedSpriteRect != null) { spriteEditor.selectedSpriteRect = m_RectsCache.spriteRects.FirstOrDefault(x => x.spriteID == spriteEditor.selectedSpriteRect.spriteID); } } } return(true); }
void FixBrokenReferenceBug() { #if UNITY_EDITOR if (script == null && !Object.ReferenceEquals(script, null)) { var so = new UnityEditor.SerializedObject(this); var id = script.GetInstanceID(); so.FindProperty("script").objectReferenceInstanceIDValue = 0; so.FindProperty("script").objectReferenceInstanceIDValue = id; so.ApplyModifiedPropertiesWithoutUndo(); } #endif }
public void UpdateObject(SyncObjectMessage msg) { Object obj = EditorUtility.InstanceIDToObject(msg.object_id); if (obj) { SerializedObject ser_obj = new UnityEditor.SerializedObject(obj); ser_obj.CopyFromSerializedProperty(msg.prop); ser_obj.ApplyModifiedPropertiesWithoutUndo(); EditorSceneManager.MarkSceneDirty(m_scene); } }
public override void OnPaintInspectorGUI() { serializedObject.Update(); _serializedObject.UpdateIfRequiredOrScript(); EditorGUILayout.PropertyField(_event, true); if (GUILayout.Button("要素更新")) { ElementEnumUpdate(); } _serializedObject.ApplyModifiedPropertiesWithoutUndo(); serializedObject.ApplyModifiedProperties(); }
public override void OnPaintInspectorGUI() { OnInspectorGUI(); serializedObject.Update(); _serializedObject.UpdateIfRequiredOrScript(); _enumList.DoLayoutList(); if (GUILayout.Button("要素更新")) { ElementEnumUpdate(); } _serializedObject.ApplyModifiedPropertiesWithoutUndo(); serializedObject.ApplyModifiedProperties(); }
public override bool ApplyRevert(bool apply) { if (apply) { if (this.containsMultipleSprites) { List <string> list = new List <string>(); List <string> list2 = new List <string>(); for (int i = 0; i < this.m_RectsCache.spriteRects.Count; i++) { SpriteRect spriteRect = this.m_RectsCache.spriteRects[i]; if (string.IsNullOrEmpty(spriteRect.name)) { spriteRect.name = "Empty"; } if (!string.IsNullOrEmpty(spriteRect.originalName)) { list.Add(spriteRect.originalName); list2.Add(spriteRect.name); } } SerializedObject serializedObject = new SerializedObject(this.m_SpriteDataProvider.targetObject); if (list.Count > 0) { PatchImportSettingRecycleID.PatchMultiple(serializedObject, 213, list.ToArray(), list2.ToArray()); } serializedObject.ApplyModifiedPropertiesWithoutUndo(); } this.m_SpriteDataProvider.SetSpriteRects((this.m_RectsCache != null) ? this.m_RectsCache.spriteRects.ToArray() : null); if (this.m_RectsCache != null) { this.undoSystem.ClearUndo(this.m_RectsCache); } } else if (this.m_RectsCache != null) { this.undoSystem.ClearUndo(this.m_RectsCache); this.m_RectsCache.spriteRects = this.m_SpriteDataProvider.GetSpriteRects().ToList <SpriteRect>(); base.spriteEditor.spriteRects = this.m_RectsCache.spriteRects; if (base.spriteEditor.selectedSpriteRect != null) { base.spriteEditor.selectedSpriteRect = this.m_RectsCache.spriteRects.FirstOrDefault((SpriteRect x) => x.spriteID == base.spriteEditor.selectedSpriteRect.spriteID); } } return(true); }
public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); prefabBrush.index = EditorGUILayout.IntPopup("Selected Prefab", prefabBrush.index, options.ToArray(), optionsIndex.ToArray()); //Selectable prefab to paint prefabBrush.m_Rotation = EditorGUILayout.IntSlider("Rotation", prefabBrush.m_Rotation, 0, 359); // Selectable rotation of our prefab EditorGUILayout.Space(); EditorGUILayout.Space(); EditorGUILayout.Space(); prefabBrush.m_Z = EditorGUILayout.IntField("Position Z", prefabBrush.m_Z); prefabBrush.m_PerlinScale = EditorGUILayout.Slider("Perlin Scale", prefabBrush.m_PerlinScale, 0.001f, 0.999f); EditorGUILayout.PropertyField(m_Prefabs, true); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
void ISpriteEditorDataProvider.Apply() { var so = new SerializedObject(this); m_SpriteSingle.Apply(so); var spriteSheetSO = so.FindProperty("m_SpriteSheet.m_Sprites"); GUID[] guids = new GUID[spriteSheetSO.arraySize]; for (int i = 0; i < spriteSheetSO.arraySize; ++i) { var element = spriteSheetSO.GetArrayElementAtIndex(i); guids[i] = SpriteRect.GetSpriteIDFromSerializedProperty(element); // find the GUID in our sprite list and apply to it; var smd = m_SpritesMultiple.Find(x => x.spriteID == guids[i]); if (smd == null) // we can't find it, it is already deleted { spriteSheetSO.DeleteArrayElementAtIndex(i); --i; } else { smd.Apply(element); } } // Add new ones var newSprites = m_SpritesMultiple.Where(x => !guids.Contains(x.spriteID)); foreach (var newSprite in newSprites) { spriteSheetSO.InsertArrayElementAtIndex(spriteSheetSO.arraySize); var element = spriteSheetSO.GetArrayElementAtIndex(spriteSheetSO.arraySize - 1); newSprite.Apply(element); } so.ApplyModifiedPropertiesWithoutUndo(); }
internal override void PostApply() { // But we might not be done yet! // For all models which did not have own humanoid before but should have it now, // we need to perform auto-mapping. (For the opposite case we also need to clear the mapping.) // Iterate through all the models... for (int i = 0; i < targets.Length; i++) { // If this model had its own humanoid avatar before but shouldn't have it now... if (oldModelSettings[i].usesOwnAvatar && !newModelSettings[i].usesOwnAvatar && !newModelSettings[i].copyAvatar) { // ...then clear auto-setup on this model. SerializedObject so = new SerializedObject(targets[i]); AvatarSetupTool.ClearAll(so); so.ApplyModifiedPropertiesWithoutUndo(); } if (!m_CopyAvatar.boolValue && !newModelSettings[i].humanoid && rootIndex > 0) { ModelImporter importer = targets[i] as ModelImporter; GameObject go = AssetDatabase.LoadMainAssetAtPath(importer.assetPath) as GameObject; // The character could be optimized right now // 'm_OptimizeGameObjects' can't be used to tell if it is optimized, because the user can change this value from UI, // and the change hasn't been applied yet. Animator animator = go.GetComponent <Animator>(); bool noTransformHierarchy = animator && !animator.hasTransformHierarchy; if (noTransformHierarchy) { go = Instantiate(go) as GameObject; AnimatorUtility.DeoptimizeTransformHierarchy(go); } SerializedObject so = new SerializedObject(targets[i]); so.ApplyModifiedPropertiesWithoutUndo(); if (noTransformHierarchy) { DestroyImmediate(go); } } // If this model should have its own humanoid avatar before and didn't have it before, // then we need to perform auto-mapping. if (!oldModelSettings[i].usesOwnAvatar && newModelSettings[i].usesOwnAvatar) { ModelImporter importer = targets[i] as ModelImporter; // Special case if the model didn't have animation before... if (oldModelSettings[i].hasNoAnimation && assetTargets[i] != null) { // We have to do an extra import first, before the automapping works. // Because the model doesn't have any skinned meshes when it was last imported with // Animation Mode: None. And the auro-mapping relies on information in the skinned meshes. var targetAnimationType = importer.animationType; importer.animationType = ModelImporterAnimationType.Generic; // we dont want to build humanoid here, since it will generate errors. AssetDatabase.ImportAsset(importer.assetPath); importer.animationType = targetAnimationType; } // Perform auto-setup on this model. SerializedObject so = new SerializedObject(targets[i]); GameObject go = assetTargets[i] as GameObject; // The character could be optimized right now // 'm_OptimizeGameObjects' can't be used to tell if it is optimized, because the user can change this value from UI, // and the change hasn't been applied yet. if (go != null) { Animator animator = go.GetComponent <Animator>(); bool noTransformHierarchy = animator && !animator.hasTransformHierarchy; if (noTransformHierarchy) { go = Instantiate(go) as GameObject; AnimatorUtility.DeoptimizeTransformHierarchy(go); } AvatarSetupTool.AutoSetupOnInstance(go, so); m_IsBiped = AvatarBipedMapper.IsBiped(go.transform, m_BipedMappingReport); if (noTransformHierarchy) { DestroyImmediate(go); } } so.ApplyModifiedPropertiesWithoutUndo(); } } oldModelSettings = null; newModelSettings = null; }
void OnGUI() { try { scroll = EditorGUILayout.BeginScrollView(scroll); foreach (TweakableClass c in tweakables) { if (c.objects.Length > 0) { EditorGUILayout.LabelField(c.type.ToString(), EditorStyles.boldLabel); EditorGUI.indentLevel++; EditorGUILayout.LabelField("Shared Settings", EditorStyles.boldLabel); EditorGUI.indentLevel++; SerializedObject o = new SerializedObject(c.objects[0]); List<SerializedProperty> props = new List<SerializedProperty>(); foreach (FieldInfo field in c.sharedFields) { SerializedProperty p = o.FindProperty(field.Name); if (p == null) { Debug.LogWarning("non-properties aren't supported yet. The type: (" + field.FieldType + ") of \"" + c.type + "." + field.Name + "\" is currently illegal."); } else { PropertyField(p); props.Add(p); } } o.ApplyModifiedProperties(); EditorGUI.indentLevel--; foreach (UnityEngine.Object obj in c.objects) { EditorGUILayout.LabelField(obj.name, EditorStyles.boldLabel); EditorGUI.indentLevel++; SerializedObject instObj = new SerializedObject(obj); foreach (SerializedProperty p in props) // copy shared props { instObj.CopyFromSerializedProperty(p); } instObj.ApplyModifiedPropertiesWithoutUndo(); GUI.changed = false; foreach (FieldInfo field in c.instancedFields) { SerializedProperty prop = instObj.FindProperty(field.Name); if (prop == null) { Debug.LogWarning("non-properties aren't supported yet. The type: (" + field.FieldType + ") of \"" + c.type + "." + field.Name + "\" is currently illegal."); } else PropertyField(prop); } instObj.ApplyModifiedProperties(); UnityEngine.Object objParent; if (GUI.changed && (objParent = PrefabUtility.GetPrefabParent(obj)) != null && objParent != obj) { PrefabUtility.RecordPrefabInstancePropertyModifications(obj); } GUI.changed = false; EditorGUI.indentLevel--; } EditorGUI.indentLevel--; } EditorGUILayout.Separator(); } EditorGUILayout.EndScrollView(); } catch (UnityException e) { Debug.LogWarning("error occured, refreshing...\n" + e.Message); RefreshContent(); } }
private void DisplayShared(List<UnityEngine.Object> objRef) { SerializedObject o = new SerializedObject(objRef[0]); Type type = objRef[0].GetType(); FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.FlattenHierarchy); EditorGUILayout.LabelField(type.ToString(), EditorStyles.boldLabel); EditorGUI.indentLevel++; foreach (FieldInfo field in fields) { bool hasShowinTweakerAttribute = false; foreach (Attribute at in field.GetCustomAttributes(true)) { if (at is TweakableField) { hasShowinTweakerAttribute = ((TweakableField)at).isSharedAmongAllInstances; } } if (hasShowinTweakerAttribute) { var prop = o.FindProperty(field.Name); if (prop.isArray) { DrawArrayProperty(prop); } else { EditorGUILayout.PropertyField(prop); } for (int i = 1; i < objRef.Count; i++) { SerializedObject o2 = new SerializedObject(objRef[i]); o2.CopyFromSerializedProperty(prop); o2.ApplyModifiedPropertiesWithoutUndo(); } o.ApplyModifiedProperties(); } } EditorGUI.indentLevel--; }
// This is an event handler on the scene view to handle dragging our objects from the browser // and creating new gameobjects void SceneUpdate(SceneView sceneView) { Event e = Event.current; if (e.type == EventType.dragPerform) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && (DragAndDrop.objectReferences[0].GetType() == typeof(EditorEventRef) || DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef))) { GameObject newObject = null; if (DragAndDrop.objectReferences[0].GetType() == typeof(EditorEventRef)) { string path = ((EditorEventRef)DragAndDrop.objectReferences[0]).Path; string name = path.Substring(path.LastIndexOf("/") + 1); newObject = new GameObject(name + " Emitter"); var emitter = newObject.AddComponent<StudioEventEmitter>(); emitter.Event = path; var so = new SerializedObject(emitter); EditorUtils.UpdateParamsOnEmmitter(so); so.ApplyModifiedPropertiesWithoutUndo(); Undo.RegisterCreatedObjectUndo(newObject, "Create FMOD Studio Emitter"); } else { newObject = new GameObject("FMOD Studio Loader"); var loader = newObject.AddComponent<StudioBankLoader>(); loader.Banks = new List<string>(); loader.Banks.Add(((EditorBankRef)DragAndDrop.objectReferences[0]).Name); Undo.RegisterCreatedObjectUndo(newObject, "Create FMOD Studio Loader"); } Ray ray = HandleUtility.GUIPointToWorldRay(e.mousePosition); var hit = HandleUtility.RaySnap(ray); if (hit != null) { newObject.transform.position = ((RaycastHit)hit).point; } else { newObject.transform.position = ray.origin + ray.direction * 10.0f; } Selection.activeObject = newObject; e.Use(); } } if (e.type == EventType.DragUpdated) { if (DragAndDrop.objectReferences.Length > 0 && DragAndDrop.objectReferences[0] != null && (DragAndDrop.objectReferences[0].GetType() == typeof(EditorEventRef) || DragAndDrop.objectReferences[0].GetType() == typeof(EditorBankRef))) { DragAndDrop.visualMode = DragAndDropVisualMode.Move; DragAndDrop.AcceptDrag(); e.Use(); } } }
internal override void PostApply() { for (int i = 0; i < base.targets.Length; i++) { if (this.oldModelSettings[i].usesOwnAvatar && !this.newModelSettings[i].usesOwnAvatar && !this.newModelSettings[i].copyAvatar) { SerializedObject serializedObject = new SerializedObject(base.targets[i]); AvatarSetupTool.ClearAll(serializedObject); serializedObject.ApplyModifiedPropertiesWithoutUndo(); } if (!this.m_CopyAvatar.boolValue && !this.newModelSettings[i].humanoid && this.rootIndex > 0) { ModelImporter modelImporter = base.targets[i] as ModelImporter; GameObject gameObject = AssetDatabase.LoadMainAssetAtPath(modelImporter.assetPath) as GameObject; Animator component = gameObject.GetComponent <Animator>(); bool flag = component && !component.hasTransformHierarchy; if (flag) { gameObject = (this.Instantiate(gameObject) as GameObject); AnimatorUtility.DeoptimizeTransformHierarchy(gameObject); } Transform transform = gameObject.transform.Find(this.m_RootMotionBoneList[this.rootIndex].text); if (transform != null) { this.m_RootMotionBoneRotation.quaternionValue = transform.rotation; } SerializedObject serializedObject2 = new SerializedObject(base.targets[i]); serializedObject2.ApplyModifiedPropertiesWithoutUndo(); if (flag) { this.DestroyImmediate(gameObject); } } if (!this.oldModelSettings[i].usesOwnAvatar && this.newModelSettings[i].usesOwnAvatar) { ModelImporter modelImporter2 = base.targets[i] as ModelImporter; if (this.oldModelSettings[i].hasNoAnimation) { ModelImporterAnimationType animationType = modelImporter2.animationType; modelImporter2.animationType = ModelImporterAnimationType.Generic; AssetDatabase.ImportAsset(modelImporter2.assetPath); modelImporter2.animationType = animationType; } SerializedObject serializedObject3 = new SerializedObject(base.targets[i]); GameObject gameObject2 = AssetDatabase.LoadMainAssetAtPath(modelImporter2.assetPath) as GameObject; Animator component2 = gameObject2.GetComponent <Animator>(); bool flag2 = component2 && !component2.hasTransformHierarchy; if (flag2) { gameObject2 = (this.Instantiate(gameObject2) as GameObject); AnimatorUtility.DeoptimizeTransformHierarchy(gameObject2); } AvatarSetupTool.AutoSetupOnInstance(gameObject2, serializedObject3); this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject2.transform, this.m_BipedMappingReport); if (flag2) { this.DestroyImmediate(gameObject2); } serializedObject3.ApplyModifiedPropertiesWithoutUndo(); } } this.oldModelSettings = null; this.newModelSettings = null; }
internal override void Apply() { ModelImporterRigEditor.MappingRelevantSettings[] array = new ModelImporterRigEditor.MappingRelevantSettings[base.targets.Length]; for (int i = 0; i < base.targets.Length; i++) { SerializedObject serializedObject = new SerializedObject(base.targets[i]); SerializedProperty serializedProperty = serializedObject.FindProperty("m_AnimationType"); SerializedProperty serializedProperty2 = serializedObject.FindProperty("m_CopyAvatar"); array[i].humanoid = (serializedProperty.intValue == 3); array[i].hasNoAnimation = (serializedProperty.intValue == 0); array[i].copyAvatar = serializedProperty2.boolValue; } ModelImporterRigEditor.MappingRelevantSettings[] array2 = new ModelImporterRigEditor.MappingRelevantSettings[base.targets.Length]; Array.Copy(array, array2, base.targets.Length); for (int j = 0; j < base.targets.Length; j++) { if (!this.m_AnimationType.hasMultipleDifferentValues) { array2[j].humanoid = (this.m_AnimationType.intValue == 3); } if (!this.m_CopyAvatar.hasMultipleDifferentValues) { array2[j].copyAvatar = this.m_CopyAvatar.boolValue; } } base.Apply(); for (int k = 0; k < base.targets.Length; k++) { if (array[k].usesOwnAvatar && !array2[k].usesOwnAvatar && !array2[k].copyAvatar) { SerializedObject serializedObject2 = new SerializedObject(base.targets[k]); AvatarSetupTool.ClearAll(serializedObject2); serializedObject2.ApplyModifiedPropertiesWithoutUndo(); } if (!this.m_CopyAvatar.boolValue && !array2[k].humanoid && this.rootIndex > 0) { ModelImporter modelImporter = base.targets[k] as ModelImporter; GameObject gameObject = AssetDatabase.LoadMainAssetAtPath(modelImporter.assetPath) as GameObject; Animator component = gameObject.GetComponent <Animator>(); bool flag = component && !component.hasTransformHierarchy; if (flag) { gameObject = UnityEngine.Object.Instantiate <GameObject>(gameObject); AnimatorUtility.DeoptimizeTransformHierarchy(gameObject); } Transform transform = gameObject.transform.Find(this.m_RootMotionBoneList[this.rootIndex].text); if (transform != null) { this.m_RootMotionBoneRotation.quaternionValue = transform.rotation; } SerializedObject serializedObject3 = new SerializedObject(base.targets[k]); serializedObject3.ApplyModifiedPropertiesWithoutUndo(); if (flag) { UnityEngine.Object.DestroyImmediate(gameObject); } } if (!array[k].usesOwnAvatar && array2[k].usesOwnAvatar) { ModelImporter modelImporter2 = base.targets[k] as ModelImporter; if (array[k].hasNoAnimation) { ModelImporterAnimationType animationType = modelImporter2.animationType; modelImporter2.animationType = ModelImporterAnimationType.Generic; AssetDatabase.ImportAsset(modelImporter2.assetPath); modelImporter2.animationType = animationType; } SerializedObject serializedObject4 = new SerializedObject(base.targets[k]); GameObject gameObject2 = AssetDatabase.LoadMainAssetAtPath(modelImporter2.assetPath) as GameObject; Animator component2 = gameObject2.GetComponent <Animator>(); bool flag2 = component2 && !component2.hasTransformHierarchy; if (flag2) { gameObject2 = UnityEngine.Object.Instantiate <GameObject>(gameObject2); AnimatorUtility.DeoptimizeTransformHierarchy(gameObject2); } AvatarSetupTool.AutoSetupOnInstance(gameObject2, serializedObject4); this.m_IsBiped = AvatarBipedMapper.IsBiped(gameObject2.transform, this.m_BipedMappingReport); if (flag2) { UnityEngine.Object.DestroyImmediate(gameObject2); } serializedObject4.ApplyModifiedPropertiesWithoutUndo(); } } }
internal static void UpdateTextureReferences(FungusEditorResources instance) { // Iterate through all fields in instance and set texture references var serializedObject = new SerializedObject(instance); var prop = serializedObject.GetIterator(); var rootFolder = new [] { GetRootFolder() }; prop.NextVisible(true); while (prop.NextVisible(false)) { if (prop.propertyType == SerializedPropertyType.Generic) { var guids = AssetDatabase.FindAssets(prop.name + " t:Texture2D", rootFolder); var paths = guids.Select(guid => AssetDatabase.GUIDToAssetPath(guid)).Where( path => path.Contains(prop.name + ".") ); foreach (var path in paths) { var texture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture2D; if (path.ToLower().Contains("/pro/")) { prop.FindPropertyRelative("pro").objectReferenceValue = texture; } else { prop.FindPropertyRelative("free").objectReferenceValue = texture; } } } } serializedObject.FindProperty("updateOnReloadScripts").boolValue = false; // The ApplyModifiedPropertiesWithoutUndo() function wasn't documented until Unity 5.2 #if UNITY_5_0 || UNITY_5_1 var flags = BindingFlags.Instance | BindingFlags.NonPublic; var applyMethod = typeof(SerializedObject).GetMethod("ApplyModifiedPropertiesWithoutUndo", flags); applyMethod.Invoke(serializedObject, null); #else serializedObject.ApplyModifiedPropertiesWithoutUndo(); #endif }