本文整理汇总了C#中UnityEditor.SerializedObject.Update方法的典型用法代码示例。如果您正苦于以下问题:C# SerializedObject.Update方法的具体用法?C# SerializedObject.Update怎么用?C# SerializedObject.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEditor.SerializedObject
的用法示例。
在下文中一共展示了SerializedObject.Update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnSceneGUI
void OnSceneGUI()
{
PointPath pointPath = (PointPath)target;
float pixelSize = HandleUtility.GetHandleSize ( Vector3.zero ) / 160;
// Handles.color = Color.white;
Handles.color = Color.clear;
for ( int i = 0; i < pointPath.Points.Count; i++ )
{
Vector3 oldPoint = pointPath.Points[i];
Vector3 newPoint = Handles.FreeMoveHandle ( oldPoint, Quaternion.identity, pixelSize * 7, pointSnap, Handles.DotCap );
if ( oldPoint != newPoint )
{
SerializedObject so = new SerializedObject ( target );
if ( so != null )
{
so.Update ();
SerializedProperty PointsArray = so.FindProperty ( "Points" );
SerializedProperty point = PointsArray.GetArrayElementAtIndex ( i );
if ( point != null )
point.vector3Value = newPoint;
so.ApplyModifiedProperties ();
}
}
}
}
示例2: Draw
private void Draw(){
SerializedObject cacheObject = new SerializedObject (cache);
cacheObject.Update();
SerializedProperty property = cacheObject.FindProperty ("prefabs");
if (property != null) {
int removeIndex=-1;
for(int i=0;i< property.arraySize;i++){
GUILayout.BeginHorizontal();
SerializedProperty nameProperty=property.GetArrayElementAtIndex(i).FindPropertyRelative("name");
EditorGUILayout.PropertyField(nameProperty,GUIContent.none);
SerializedProperty prefabProperty=property.GetArrayElementAtIndex(i).FindPropertyRelative("prefab");
bool isNull=prefabProperty.objectReferenceValue==null;
EditorGUILayout.PropertyField(prefabProperty,GUIContent.none);
if(isNull && prefabProperty.objectReferenceValue!=null){
nameProperty.stringValue=prefabProperty.objectReferenceValue.name;
}
if(GUILayout.Button(EditorGUIUtility.FindTexture("Toolbar Minus"),"label",GUILayout.Width(20))){
removeIndex=i;
}
GUILayout.EndHorizontal();
}
if(removeIndex != -1){
property.DeleteArrayElementAtIndex(removeIndex);
}
}
cacheObject.ApplyModifiedProperties();
}
示例3: SavePose
public static void SavePose(Pose pose, Transform root)
{
List<Bone2D> bones = new List<Bone2D>(50);
root.GetComponentsInChildren<Bone2D>(true,bones);
SerializedObject poseSO = new SerializedObject(pose);
SerializedProperty entriesProp = poseSO.FindProperty("m_PoseEntries");
poseSO.Update();
entriesProp.arraySize = bones.Count;
for (int i = 0; i < bones.Count; i++)
{
Bone2D bone = bones [i];
if(bone)
{
SerializedProperty element = entriesProp.GetArrayElementAtIndex(i);
element.FindPropertyRelative("path").stringValue = BoneUtils.GetBonePath(root,bone);
element.FindPropertyRelative("localPosition").vector3Value = bone.transform.localPosition;
element.FindPropertyRelative("localRotation").quaternionValue = bone.transform.localRotation;
element.FindPropertyRelative("localScale").vector3Value = bone.transform.localScale;
}
}
poseSO.ApplyModifiedProperties();
}
示例4: DrawInspector
// ===========================================================
// Static Methods
// ===========================================================
public static void DrawInspector(SerializedObject so) {
so.Update();
var mode = so.FindProperty("mode");
var position = so.FindProperty("position");
var anchorObject = so.FindProperty("anchorObject");
var anchorCamera = so.FindProperty("anchorCamera");
MadGUI.PropertyField(mode, "Mode");
switch ((MadAnchor.Mode) mode.enumValueIndex) {
case MadAnchor.Mode.ObjectAnchor:
MadGUI.PropertyField(anchorObject, "Anchor Object", MadGUI.ObjectIsSet);
MadGUI.PropertyField(anchorCamera, "Anchor Camera", property => property.objectReferenceValue != null || HasMainCamera());
if (!HasMainCamera()) {
GUIMissingMainCameraWarning();
} else if (anchorCamera.objectReferenceValue == null) {
GUIMainCameraWillBeUsed();
}
break;
case MadAnchor.Mode.ScreenAnchor:
MadGUI.PropertyField(position, "Position");
break;
default:
MadDebug.Assert(false, "Unknown mode: " + (MadAnchor.Mode) mode.enumValueIndex);
break;
}
so.ApplyModifiedProperties();
}
示例5: Draw
public void Draw(Condition condition, SerializedObject serializedObject)
{
foldout = EditorGUILayout.Foldout(foldout, "Condition Editor");
if (!foldout || (serializedObject == null)) return;
serializedObject.Update();
if (drawReferenceDatabase) {
EditorTools.selectedDatabase = EditorGUILayout.ObjectField(new GUIContent("Reference Database", "Database to use for Lua and Quest conditions"), EditorTools.selectedDatabase, typeof(DialogueDatabase), true) as DialogueDatabase;
}
luaConditionWizard.database = EditorTools.selectedDatabase;
if (luaConditionWizard.database != null) {
if (!luaConditionWizard.IsOpen) {
luaConditionWizard.OpenWizard(string.Empty);
}
currentLuaWizardContent = luaConditionWizard.Draw(new GUIContent("Lua Condition Wizard", "Use to add Lua conditions below"), currentLuaWizardContent, false);
if (!luaConditionWizard.IsOpen && !string.IsNullOrEmpty(currentLuaWizardContent)) {
List<string> luaList = new List<string>(condition.luaConditions);
luaList.Add(currentLuaWizardContent);
condition.luaConditions = luaList.ToArray();
currentLuaWizardContent = string.Empty;
luaConditionWizard.OpenWizard(string.Empty);
}
}
EditorWindowTools.StartIndentedSection();
SerializedProperty conditions = serializedObject.FindProperty("condition");
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(conditions, true);
if (EditorGUI.EndChangeCheck()) serializedObject.ApplyModifiedProperties();
EditorWindowTools.EndIndentedSection();
}
示例6: OnGUI
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
position.x += 4;
position.width -= 6;
if (!initialized) {
AIEditorWindow[] windows=Resources.FindObjectsOfTypeAll<AIEditorWindow>();
if(windows.Length >0){
controller = windows[0].controller;
}
initialized=true;
}
if (controller != null) {
NamedParameter param=(NamedParameter)property.objectReferenceValue;
if(param == null){
property.objectReferenceValue=param=CreateUserParameter();
}
position.width-=15;
Rect r= new Rect(position);
r.x+=position.width;
r.width=20;
param.userVariable=GUI.Toggle(r,param.userVariable,GUIContent.none);
if(param != null && param.userVariable){
param.Name=string.Empty;
SerializedObject paramObject= new SerializedObject(param);
paramObject.Update();
EditorGUI.PropertyField(position,paramObject.FindProperty("value"),new GUIContent(label.text));
paramObject.ApplyModifiedProperties();
}else{
string[] parameters=null;
if(fieldInfo.FieldType == typeof(Vector3Parameter)){
parameters=controller.GetParameterNames(fieldInfo.FieldType,typeof(GameObjectParameter));
}else{
parameters=controller.GetParameterNames(fieldInfo.FieldType);
}
if(parameters.Length == 0){
System.Array.Resize (ref parameters, parameters.Length + 1);
parameters[parameters.Length - 1] = "None";
List<string> list= new List<string>(parameters);
list.Swap(0,parameters.Length-1);
parameters=list.ToArray();
}
for(int i=0;i< parameters.Length;i++){
if(parameters[i] == param.Name){
selectedIndex=i;
}
}
GUI.color=(parameters[selectedIndex]=="None"?Color.red:Color.white);
selectedIndex=EditorGUI.Popup(position,label.text,selectedIndex,parameters);
GUI.color=Color.white;
if(parameters[selectedIndex]!="None"){
param.Name=parameters[selectedIndex];
}
}
}
}
示例7: DrawColors
protected void DrawColors ()
{
if (serializedObject.FindProperty("tweenTarget").objectReferenceValue == null) return;
if (NGUIEditorTools.DrawHeader("Colors", "Colors", false, true))
{
NGUIEditorTools.BeginContents(true);
NGUIEditorTools.SetLabelWidth(76f);
UIButtonColor btn = target as UIButtonColor;
if (btn.tweenTarget != null)
{
UIWidget widget = btn.tweenTarget.GetComponent<UIWidget>();
if (widget != null)
{
EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);
{
SerializedObject obj = new SerializedObject(widget);
obj.Update();
NGUIEditorTools.DrawProperty("Normal", obj, "mColor");
obj.ApplyModifiedProperties();
}
EditorGUI.EndDisabledGroup();
}
}
NGUIEditorTools.DrawProperty("Hover", serializedObject, "hover");
NGUIEditorTools.DrawProperty("Pressed", serializedObject, "pressed");
NGUIEditorTools.DrawProperty("Disabled", serializedObject, "disabledColor");
NGUIEditorTools.EndContents();
}
}
示例8: App
void App(GameObject src, GameObject dst)
{
dst.transform.localPosition=src.transform.localPosition;
Component comp=src.GetComponent<MeshFilter>();
Component dst_comp = dst.AddComponent(comp.GetType());
SerializedObject src_ser_obj = new SerializedObject(comp);
SerializedObject dst_ser_obj = new SerializedObject(dst_comp);
src_ser_obj.Update();
dst_ser_obj.Update();
SerializedProperty ser_prop = src_ser_obj.GetIterator();
bool enterChildren = true;
while (ser_prop.Next(enterChildren)) {
enterChildren = true;
string path = ser_prop.propertyPath;
bool skip = false;
foreach (string blacklisted_path in propertyBlacklist) {
if (path.EndsWith(blacklisted_path)) {
skip = true;
break;
}
}
if (skip) {
enterChildren = false;
continue;
}
//Debug.Log(path);
SerializedProperty dst_ser_prop = dst_ser_obj.FindProperty(path);
AssignSerializedProperty(ser_prop, dst_ser_prop);
}
dst_ser_obj.ApplyModifiedProperties();
}
示例9: DoVariable
private void DoVariable(FsmVariable variable){
SerializedObject serializedObject = new SerializedObject (variable);
SerializedProperty nameProperty = serializedObject.FindProperty ("name");
SerializedProperty valueProperty = serializedObject.FindProperty ("value");
GUILayout.BeginHorizontal ();
serializedObject.Update ();
EditorGUILayout.PropertyField(nameProperty,GUIContent.none);
if (valueProperty != null) {
if (valueProperty.propertyType == SerializedPropertyType.Boolean) {
EditorGUILayout.PropertyField (valueProperty, GUIContent.none, GUILayout.Width (17));
} else {
EditorGUILayout.PropertyField (valueProperty, GUIContent.none);
}
}
serializedObject.ApplyModifiedProperties ();
GUILayout.FlexibleSpace ();
if (GUILayout.Button (FsmEditorStyles.toolbarMinus,FsmEditorStyles.label)) {
FsmEditor.Root.Variables=ArrayUtility.Remove<FsmVariable>(FsmEditor.Root.Variables,variable);
UnityEngine.Object.DestroyImmediate(variable,true);
AssetDatabase.SaveAssets();
}
GUILayout.EndHorizontal ();
}
示例10: RecursiveCopy
void RecursiveCopy(GameObject src, GameObject dst)
{
Debug.Log("Copying from " + src.name + " to " + dst.name);
Component[] src_components = src.GetComponents(typeof(Component));
foreach (Component comp in src_components) {
if (comp is Transform || comp is Renderer || comp is Animation)
continue;
//Debug.Log("Adding " + comp.GetType().Name + " to " + dst.name);
Component dst_comp = dst.AddComponent(comp.GetType());
SerializedObject src_ser_obj = new SerializedObject(comp);
SerializedObject dst_ser_obj = new SerializedObject(dst_comp);
src_ser_obj.Update();
dst_ser_obj.Update();
SerializedProperty ser_prop = src_ser_obj.GetIterator();
bool enterChildren = true;
while (ser_prop.Next(enterChildren)) {
enterChildren = true;
string path = ser_prop.propertyPath;
bool skip = false;
foreach (string blacklisted_path in propertyBlacklist) {
if (path.EndsWith(blacklisted_path)) {
skip = true;
break;
}
}
if (skip) {
enterChildren = false;
continue;
}
//Debug.Log(path);
SerializedProperty dst_ser_prop = dst_ser_obj.FindProperty(path);
AssignSerializedProperty(ser_prop, dst_ser_prop);
}
dst_ser_obj.ApplyModifiedProperties();
}
foreach (Transform child_transform in src.transform) {
GameObject child = child_transform.gameObject;
string dst_object_name = namePrefix + child.name;
GameObject dst_object = findChildWithName(dst, dst_object_name);
if (dst_object == null) {
Debug.LogWarning("Didn't find matching GameObject for " + child.name);
continue;
}
RecursiveCopy(child, dst_object);
}
}
示例11: OnEnable
protected virtual void OnEnable(){
database = ItemDatabase.Load ();
parameterTypeNames = TypeUtility.GetSubTypeNames (typeof(FsmVariable));
parameterTypeNames = ArrayUtility.Insert<string> (parameterTypeNames, "None", 0);
customDataList = new ReorderableList(serializedObject,
serializedObject.FindProperty("customData"),
true, true, true, true);
customDataList.elementHeight = EditorGUIUtility.singleLineHeight * 3+10;
customDataList.onRemoveCallback = (ReorderableList list) => {
list.serializedProperty.serializedObject.Update();
DestroyImmediate(list.serializedProperty.GetArrayElementAtIndex(list.index).objectReferenceValue,true);
AssetDatabase.SaveAssets();
list.serializedProperty.DeleteArrayElementAtIndex(list.index);
list.serializedProperty.serializedObject.ApplyModifiedProperties();
};
customDataList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => {
var element = customDataList.serializedProperty.GetArrayElementAtIndex(index);
FsmVariable variable = element.objectReferenceValue as FsmVariable;
rect.y+=2;
int m = parameterTypeNames.ToList ().FindIndex (x => x == (variable!= null?variable.GetType ().Name:""));
m = Mathf.Clamp (m, 0, int.MaxValue);
rect.height=EditorGUIUtility.singleLineHeight;
m = EditorGUI.Popup (rect,"Parameter Type", m, parameterTypeNames);
string typeName=parameterTypeNames [m];
string variableTypeName = (variable == null ? "None" : variable.GetType ().Name);
if(typeName != variableTypeName){
DestroyImmediate(element.objectReferenceValue,true);
if(typeName != "None"){
variable = ScriptableObject.CreateInstance (TypeUtility.GetTypeByName(typeName)[0]) as FsmVariable;
variable.hideFlags = HideFlags.HideInHierarchy;
if (EditorUtility.IsPersistent (element.serializedObject.targetObject)) {
AssetDatabase.AddObjectToAsset (variable, element.serializedObject.targetObject);
AssetDatabase.SaveAssets ();
}
element.serializedObject.Update();
element.objectReferenceValue = variable;
element.serializedObject.ApplyModifiedProperties ();
}
}
if(variable != null){
SerializedObject mVariable=new SerializedObject(variable);
mVariable.Update();
rect.y+=EditorGUIUtility.singleLineHeight+2;
EditorGUI.PropertyField(rect,mVariable.FindProperty("name"));
rect.y+=EditorGUIUtility.singleLineHeight+2;
EditorGUI.PropertyField(rect,mVariable.FindProperty("value"));
mVariable.ApplyModifiedProperties();
}
};
customDataList.drawHeaderCallback = (Rect rect) => {
EditorGUI.LabelField(rect, "Custom Data");
};
}
示例12: DrawInspector
public static void DrawInspector(Editor wcEditor, System.Type baseType, List<string> ignoreClasses = null) {
var so = new SerializedObject(wcEditor.targets);
var target = wcEditor.target;
so.Update();
var baseTypes = new List<System.Type>();
var baseTargetType = target.GetType();
baseTypes.Add(baseTargetType);
while (baseType != baseTargetType) {
baseTargetType = baseTargetType.BaseType;
baseTypes.Add(baseTargetType);
}
baseTypes.Reverse();
SerializedProperty prop = so.GetIterator();
var result = prop.NextVisible(true);
EditorGUILayout.PropertyField(prop, false);
if (result == true) {
var currentType = EditorUtilitiesEx.FindTypeByProperty(baseTypes, prop);
EditorGUILayout.BeginVertical();
{
while (prop.NextVisible(false) == true) {
var cType = EditorUtilitiesEx.FindTypeByProperty(baseTypes, prop);
if (cType != currentType) {
currentType = cType;
var name = cType.Name;
if (ignoreClasses != null && ignoreClasses.Contains(name) == true) continue;
EditorUtilitiesEx.DrawSplitter(name);
}
EditorGUILayout.PropertyField(prop, true);
}
prop.Reset();
}
EditorGUILayout.EndVertical();
}
so.ApplyModifiedProperties();
}
示例13: GetSerializedProperties
internal static SerializedProperty[] GetSerializedProperties(this Object go) {
var so = new SerializedObject(go);
so.Update();
var result = new List<SerializedProperty>();
var iterator = so.GetIterator();
while (iterator.NextVisible(true)) result.Add(iterator.Copy());
return result.ToArray();
}
示例14: DrawSerializedProperty
public static void DrawSerializedProperty(SerializedObject serializedObject, string propertyName)
{
serializedObject.Update();
var property = serializedObject.FindProperty(propertyName);
if (property == null) return;
EditorGUI.BeginChangeCheck();
EditorGUILayout.PropertyField(property, true);
if (EditorGUI.EndChangeCheck()) {
serializedObject.ApplyModifiedProperties();
}
}
示例15: OnInspectorGUI
public override void OnInspectorGUI()
{
var fb = target as FixedBase;
var obj = new SerializedObject(fb);
EditorGUILayout.PropertyField(obj.FindProperty("m_safeFloor"));
if (GUI.changed)
{
obj.ApplyModifiedProperties();
obj.Update();
}
}