当前位置: 首页>>代码示例>>C#>>正文


C# SerializedObject.ApplyModifiedPropertiesWithoutUndo方法代码示例

本文整理汇总了C#中UnityEditor.SerializedObject.ApplyModifiedPropertiesWithoutUndo方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedObject.ApplyModifiedPropertiesWithoutUndo方法的具体用法?C# SerializedObject.ApplyModifiedPropertiesWithoutUndo怎么用?C# SerializedObject.ApplyModifiedPropertiesWithoutUndo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEditor.SerializedObject的用法示例。


在下文中一共展示了SerializedObject.ApplyModifiedPropertiesWithoutUndo方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateNewGameLevel

    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();
        }
    }
开发者ID:WCC-Tech-Club,项目名称:Unity-3D-Platformer-1,代码行数:59,代码来源:MenuItems.cs

示例2: OnGUI

    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();
        }
    }
开发者ID:Ryxali,项目名称:GameTweaker,代码行数:82,代码来源:GameTweaker.cs

示例3: SceneUpdate

 // 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();
         }
     }
 }
开发者ID:hydro-team,项目名称:hydro,代码行数:60,代码来源:EventBrowser.cs

示例4: UpdateTextureReferences

        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
        }
开发者ID:abstractmachine,项目名称:Fungus-3D-Template,代码行数:43,代码来源:FungusEditorResources.cs

示例5: DisplayShared

    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--;
    }
开发者ID:Ryxali,项目名称:Passpartout,代码行数:40,代码来源:GameTweaker.cs


注:本文中的UnityEditor.SerializedObject.ApplyModifiedPropertiesWithoutUndo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。