public override void OnBodyGUI() { var node = Node as IUniNode; if (node == null) { return; } var idEditingMode = EditorApplication.isPlayingOrWillChangePlaymode == false && EditorApplication.isCompiling == false && EditorApplication.isUpdating == false; if (idEditingMode) { node.UpdateNodePorts(); node.Validate(); } base.OnBodyGUI(); DrawPorts(node); SerializedObject?.ApplyModifiedPropertiesWithoutUndo(); }
/// <summary> /// Callback for painting the inspector GUI for the PrefabBrush in the Tile Palette. /// The PrefabBrush Editor overrides this to have a custom inspector for this Brush. /// </summary> public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); prefabBrush.m_PerlinScale = EditorGUILayout.Slider("Perlin Scale", prefabBrush.m_PerlinScale, 0.001f, 0.999f); EditorGUILayout.PropertyField(m_Prefabs, true); EditorGUILayout.PropertyField(m_Anchor); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
/// <summary> /// Callback for painting the inspector GUI for the PrefabBrush in the Tile Palette. /// The PrefabBrush Editor overrides this to have a custom inspector for this Brush. /// </summary> public override void OnPaintInspectorGUI() { m_SerializedObject.UpdateIfRequiredOrScript(); EditorGUILayout.PropertyField(m_Prefabs); EditorGUILayout.PropertyField(selectedSprite); EditorGUILayout.PropertyField(m_Anchor); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
// Change the target display of a game view. static void ChangeTargetDisplay(EditorWindow view, int displayIndex) { var serializedObject = new SerializedObject(view); var targetDisplay = serializedObject.FindProperty("m_TargetDisplay"); targetDisplay.intValue = displayIndex; serializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public static void ExecuteSetter(UnityEngine.Object obj, string propertyPath, Action <SerializedProperty> setter) { SerializedObject serializedObject = new SerializedObject(obj); SerializedProperty prop = serializedObject.FindProperty(propertyPath); setter.Invoke(prop); serializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public static void SetTrackParent(TrackAsset track, PlayableAsset parent) { SerializedObject trackSO = new SerializedObject(track); SerializedProperty parentProp = trackSO.FindProperty("m_Parent"); parentProp.objectReferenceValue = parent; trackSO.ApplyModifiedPropertiesWithoutUndo(); }
static void SetNavMeshData(NavMeshSurface navSurface, NavMeshData navMeshData) { var so = new SerializedObject(navSurface); var navMeshDataProperty = so.FindProperty("m_NavMeshData"); navMeshDataProperty.objectReferenceValue = navMeshData; so.ApplyModifiedPropertiesWithoutUndo(); }
// 重写Inspector检视面板 public override void OnInspectorGUI() { base.OnInspectorGUI(); var path = obj.FindProperty("LuaPath").stringValue; path = path ?? ""; EditorGUILayout.LabelField("LuaPath:"); var boxRect = EditorGUILayout.GetControlRect(); boxRect.height *= 1.2f; GUI.Box(boxRect, path); EditorGUILayout.Space(); EditorGUILayout.LabelField("请将 Lua 脚本文件拖到下边区域"); var sfxPathRect = EditorGUILayout.GetControlRect(); sfxPathRect.height = 200; GUI.Box(sfxPathRect, string.Empty); EditorGUILayout.LabelField(string.Empty, GUILayout.Height(185)); if ( Event.current.type == EventType.DragUpdated && sfxPathRect.Contains(Event.current.mousePosition) ) { //改变鼠标的外表 DragAndDrop.visualMode = DragAndDropVisualMode.Generic; if (DragAndDrop.paths != null && DragAndDrop.paths.Length > 0) { if (DragAndDrop.paths[0] != "") { var newPath = DragAndDrop.paths[0]; var resultString = Regex.Split(newPath, "/Lua/", RegexOptions.IgnoreCase); newPath = resultString[1]; newPath = newPath.Replace(".lua", ""); newPath = newPath.Replace("/", "."); obj.FindProperty("LuaPath").stringValue = newPath; obj.FindProperty("LuaFilePath").stringValue = DragAndDrop.paths[0].Replace(LuaConst.luaDir, ""); obj.ApplyModifiedPropertiesWithoutUndo(); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } } } if (!LuaConst.luaDir.IsNullOrEmpty()) { if (GUILayout.Button("选择脚本")) { // Selection.activeObject = // AssetDatabase.LoadAssetAtPath(LuaConst.luaDir,typeof(UnityEngine.Object)); // var path = AssetDatabase.GetAssetPath(Selection.activeObject); } } }
public void OnEnable() { trails = target as PlaygroundTrails; s_trails = new SerializedObject(trails); s_time = s_trails.FindProperty("time"); s_material = s_trails.FindProperty("material"); s_lifetimeColor = s_trails.FindProperty("lifetimeColor"); s_colorMode = s_trails.FindProperty("colorMode"); s_uvMode = s_trails.FindProperty("uvMode"); s_pointArrayAlpha = s_trails.FindProperty("pointArrayAlpha"); s_renderMode = s_trails.FindProperty("renderMode"); s_billboardTransform = s_trails.FindProperty("billboardTransform"); s_customRenderScale = s_trails.FindProperty("customRenderScale"); s_timeWidth = s_trails.FindProperty("timeWidth"); s_widthScale = s_trails.FindProperty("widthScale"); s_minVertexDistance = s_trails.FindProperty("minVertexDistance"); s_maxVertexDistance = s_trails.FindProperty("maxVertexDistance"); s_maxPathDeviation = s_trails.FindProperty("maxPathDeviation"); s_createPointsOnCollision = s_trails.FindProperty("createPointsOnCollision"); s_maxPoints = s_trails.FindProperty("maxPoints"); s_createFirstPointOnParticleBirth = s_trails.FindProperty("createFirstPointOnParticleBirth"); s_createLastPointOnParticleDeath = s_trails.FindProperty("createLastPointOnParticleDeath"); s_playgroundSystem = s_trails.FindProperty("playgroundSystem"); s_multithreading = s_trails.FindProperty("multithreading"); s_receiveShadows = s_trails.FindProperty("receiveShadows"); #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 s_castShadows = s_trails.FindProperty("castShadows"); #else s_castShadows = s_trails.FindProperty("shadowCastingMode"); #endif s_layer = s_trails.FindProperty("layer"); s_trails.Update(); if (s_layer.intValue < 0) { s_layer.intValue = trails.playgroundSystem.gameObject.layer; } s_layer.intValue = Mathf.Clamp(s_layer.intValue, 0, 32); #if UNITY_4_3 || UNITY_4_5 || UNITY_4_6 || UNITY_4_7 || UNITY_5_0 || UNITY_5_1 || UNITY_5_2 s_trails.ApplyModifiedProperties(); #else s_trails.ApplyModifiedPropertiesWithoutUndo(); #endif playgroundSettings = PlaygroundSettingsC.GetReference(); playgroundLanguage = PlaygroundSettingsC.GetLanguage(); // Issue a quick refresh if (!EditorApplication.isPlaying && Selection.activeTransform != null) { trails.ResetTrails(); } }
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, new GUIContent("Game Object")); m_SerializedObject.ApplyModifiedPropertiesWithoutUndo(); }
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 static void CheckVFXManager() { UnityObject vfxmanager = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>("ProjectSettings/VFXManager.asset"); if (vfxmanager == null) { return; } SerializedObject obj = new SerializedObject(vfxmanager); var pathProperty = obj.FindProperty("m_RenderPipeSettingsPath"); bool recompile = false; if (string.IsNullOrEmpty(pathProperty.stringValue)) { pathProperty.stringValue = GetDefaultPath(); recompile = true; } #if !VFX_HAS_HDRP if (pathProperty.stringValue == HDRPPath) { pathProperty.stringValue = GetDefaultPath(); recompile = true; } #endif #if !VFX_HAS_LWRP if (pathProperty.stringValue == LWRPPath) { pathProperty.stringValue = GetDefaultPath(); recompile = true; } #endif var indirectShaderProperty = obj.FindProperty("m_IndirectShader"); if (indirectShaderProperty.objectReferenceValue == null) { indirectShaderProperty.objectReferenceValue = AssetDatabase.LoadAssetAtPath <ComputeShader>("Packages/com.unity.visualeffectgraph/Shaders/VFXFillIndirectArgs.compute"); } var copyShaderProperty = obj.FindProperty("m_CopyBufferShader"); if (copyShaderProperty.objectReferenceValue == null) { copyShaderProperty.objectReferenceValue = AssetDatabase.LoadAssetAtPath <ComputeShader>("Packages/com.unity.visualeffectgraph/Shaders/VFXCopyBuffer.compute"); } var sortProperty = obj.FindProperty("m_SortShader"); if (sortProperty.objectReferenceValue == null) { sortProperty.objectReferenceValue = AssetDatabase.LoadAssetAtPath <ComputeShader>("Packages/com.unity.visualeffectgraph/Shaders/Sort.compute"); } obj.ApplyModifiedPropertiesWithoutUndo(); if (recompile) { VFXCacheManager.Build(); } }
public override void OnPaintInspectorGUI() { serialized.UpdateIfRequiredOrScript(); prefabBrush.chosenGameObject = EditorGUILayout.IntField("Prefab index", prefabBrush.chosenGameObject); prefabBrush.zPos = EditorGUILayout.IntField("Z Positon", prefabBrush.zPos); EditorGUILayout.PropertyField(prefabs, true); serialized.ApplyModifiedPropertiesWithoutUndo(); }
public static void SetData(MxMAnimationClipComposite a_data) { if (a_data != null) { m_data = a_data; m_data.VerifyData(); m_data.GenerateRootLookupTable(); m_soData = new SerializedObject(m_data); m_spPrimaryClip = m_soData.FindProperty("PrimaryClip"); m_spBeforeClips = m_soData.FindProperty("BeforeClips"); m_spAfterClips = m_soData.FindProperty("AfterClips"); m_spLooping = m_soData.FindProperty("Looping"); m_spIgnoreEdges = m_soData.FindProperty("IgnoreEdges"); m_spExtrapolateTrajectory = m_soData.FindProperty("ExtrapolateTrajectory"); m_spFlattenTrajectory = m_soData.FindProperty("FlattenTrajectory"); m_spRuntimeSplicing = m_soData.FindProperty("RuntimeSplicing"); m_spGlobalTags = m_soData.FindProperty("GlobalTags"); m_spGlobalFavourTags = m_soData.FindProperty("GlobalFavourTags"); m_spTagTracks = m_soData.FindProperty("TagTracks"); m_spEvents = m_soData.FindProperty("Events"); m_spTargetPreProcessData = m_soData.FindProperty("m_targetPreProcessData"); m_spTargetAnimModule = m_soData.FindProperty("m_targetAnimModule"); m_spTargetPrefab = m_soData.FindProperty("m_targetPrefab"); if (m_spTargetPreProcessData.objectReferenceValue != null) { if (m_spTargetPrefab.objectReferenceValue == null) { SerializedProperty spTargetPrefab = m_spTargetPreProcessData.FindPropertyRelative("m_targetPrefab"); if (spTargetPrefab != null && spTargetPrefab.objectReferenceValue != null) { m_spTargetPrefab.objectReferenceValue = spTargetPrefab.objectReferenceValue; m_soData.ApplyModifiedPropertiesWithoutUndo(); } } } MxMSettings settings = MxMSettings.Instance(); if (settings != null) { settings.ActiveComposite = a_data; } if (MxMTaggingWindow.Exists()) { MxMTaggingWindow.Inst().SetTarget(a_data); } } }
#pragma warning restore 649 public override bool CreateGameObject(out GameObject createdObj, Transform parentTransform = null) { MARSSession.EnsureRuntimeState(); createdObj = GenerateInitialGameObject(m_ObjectName, parentTransform); createdObj.AddComponent <Proxy>(); createdObj.AddComponent <ShowChildrenOnTrackingAction>(); createdObj.AddComponent <IsFaceCondition>(); var landmarksAction = createdObj.AddComponent <FaceLandmarksAction>(); var allLandmarkDefinitions = landmarksAction.AvailableLandmarkDefinitions; foreach (var def in allLandmarkDefinitions) { landmarksAction.CreateLandmarkAsChild(def, def.outputTypes[0]); } var entityVisualsModule = ModuleLoaderCore.instance.GetModule <EntityVisualsModule>(); var marsEntity = landmarksAction.GetComponentInParent <MARSEntity>(); if (entityVisualsModule != null && marsEntity != null) { entityVisualsModule.InvalidateVisual(marsEntity); } var depthMaskGO = new GameObject(k_DepthMaskGameObjName); depthMaskGO.AddComponent <MeshFilter>().sharedMesh = m_DepthMaskMesh; var depthFaceMaskRenderer = depthMaskGO.AddComponent <MeshRenderer>(); depthFaceMaskRenderer.sharedMaterial = m_DepthMaskMaterial; depthFaceMaskRenderer.renderingLayerMask = uint.MaxValue; //All layers depthMaskGO.transform.parent = createdObj.transform; var faceAction = createdObj.AddComponent <FaceAction>(); var serializedFaceActionObj = new SerializedObject(faceAction); var faceMeshProperty = serializedFaceActionObj.FindProperty(k_FaceMeshPropertyName); faceMeshProperty.objectReferenceValue = depthMaskGO; serializedFaceActionObj.ApplyModifiedPropertiesWithoutUndo(); createdObj.AddComponent <FaceExpressionAction>(); Undo.RegisterCreatedObjectUndo(createdObj, $"Create {createdObj.name}"); Selection.activeGameObject = createdObj; var simObjectsManager = ModuleLoaderCore.instance.GetModule <SimulatedObjectsManager>(); simObjectsManager?.DirtySimulatableScene(); return(true); }
private void SetUpClass(SerializedObject studentClass, int rank) { SerializedProperty sectionProperty = studentClass.FindProperty("m_section"); SerializedProperty rankProperty = studentClass.FindProperty("m_rank"); sectionProperty.objectReferenceValue = target; rankProperty.intValue = rank; studentClass.ApplyModifiedPropertiesWithoutUndo(); }
public static void SynBorderInfo() { return;//do not loss border info of sprite when atlas was modified string path = "Assets/Res/Atlas"; DirectoryInfo dir = new DirectoryInfo(path); foreach (var f in dir.GetFiles("*.png", SearchOption.TopDirectoryOnly)) { string infoFile = Application.dataPath + "/Res/Atlas/" + f.Name.Replace(".png", ".txt"); //Debugger.Log(infoFile); if (!File.Exists(infoFile)) { Debugger.LogError("not exist info file {0}", infoFile); return; } string[] lines = File.ReadAllLines(infoFile); Dictionary <string, Vector4> dic = new Dictionary <string, Vector4>(); foreach (var l in lines) { string[] strs = l.Split(';'); if (strs.Length == 2) { float[] vs = strs[1].ToArray <float>(); Vector4 border = new Vector4(vs[0], vs[1], vs[2], vs[3]); dic.Add(strs[0], border); } else { throw new System.Exception(string.Format("format error {0} 2 array", l)); } } Texture2D texture2D = AssetDatabase.LoadAssetAtPath <Texture2D>(path + "/" + f.Name); TextureImporter textureImporter = (AssetImporter.GetAtPath(path + "/" + f.Name) as TextureImporter); SerializedObject so = new SerializedObject(textureImporter); SerializedProperty sp = so.FindProperty("m_SpriteSheet.m_Sprites"); for (int i = 0, length = sp.arraySize; i < length; i++) { SerializedProperty sp1 = sp.GetArrayElementAtIndex(i); string spriteName = sp1.FindPropertyRelative("m_Name").stringValue; if (dic.ContainsKey(spriteName)) { sp1.FindPropertyRelative("m_Border").vector4Value = dic[spriteName]; so.ApplyModifiedPropertiesWithoutUndo(); } else { Debugger.LogError("not exist sprite name:{0}", spriteName); } } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Debugger.Log("syn border info success !"); }
private static void AttachSerializeObj(GameObject obj, string behaviourName, System.Reflection.Assembly assembly, List <IUIMark> processedMarks = null) { if (null == processedMarks) { processedMarks = new List <IUIMark>(); } var className = GetProjectNamespace() + "." + behaviourName; var t = assembly.GetType(className); var com = obj.GetComponent(t) ?? obj.AddComponent(t); var sObj = new SerializedObject(com); var uiMarks = obj.GetComponentsInChildren <QUIElement>(true); foreach (var elementMark in uiMarks) { if (processedMarks.Contains(elementMark)) { continue; } processedMarks.Add(elementMark); var uiType = elementMark.ComponentName; var propertyName = string.Format("{0}", elementMark.Transform.gameObject.name); if (sObj.FindProperty(propertyName) == null) { Log.I("sObj is Null:{0}", propertyName); continue; } sObj.FindProperty(propertyName).objectReferenceValue = elementMark.Transform.gameObject; AttachSerializeObj(elementMark.Transform.gameObject, elementMark.ComponentName, assembly, processedMarks); } var marks = obj.GetComponentsInChildren <QUIMark>(true); foreach (var elementMark in marks) { if (processedMarks.Contains(elementMark)) { continue; } processedMarks.Add(elementMark); var propertyName = string.Format("{0}", elementMark.Transform.gameObject.name); Log.I(propertyName); sObj.FindProperty(propertyName).objectReferenceValue = elementMark.Transform.gameObject; } sObj.ApplyModifiedPropertiesWithoutUndo(); }
/// <summary> /// Updates the <see cref="SubmoduleMap" /> asset. /// </summary> public static SubmoduleMap UpdateSubmoduleMap() { EditorUtility.DisplayProgressBar( "UpdateSubmoduleMap", "Finding submodule map...", 0 ); SubmoduleMap map; map = FindOrCreateSubmoduleMap(); SerializedObject obj; obj = new SerializedObject(map); EditorUtility.DisplayProgressBar( "UpdateSubmoduleMap", "Finding submodule types...", 0 ); System.Type[] types; types = SubmoduleMapEditorAdaptor.SubmoduleTypes; SerializedProperty elements; elements = obj.FindProperty("m_Elements"); elements.arraySize = types.Length; for (int index = 0; index < types.Length; index++) { EditorUtility.DisplayProgressBar( "UpdateSubmoduleMap", "Updating submodule map...", index / (float)(types.Length - 1) ); System.Type type; type = types[index]; SerializedProperty element; element = elements.GetArrayElementAtIndex(index); element.FindPropertyRelative("SubmoduleName").stringValue = SubmoduleMapEditorAdaptor.GetSubmoduleName(type); element.FindPropertyRelative("SubmodulePath").stringValue = SubmoduleMapEditorAdaptor.GetSubmodulePath(type); element.FindPropertyRelative("SubmoduleType").stringValue = type.FullName; } obj.ApplyModifiedPropertiesWithoutUndo(); EditorUtility.ClearProgressBar(); return(FindSubmoduleMap()); }
static void RemoveStandardMaterial(ModelImporter importer) { using (var serializedObject = new SerializedObject(importer)) { var externalObjects = serializedObject.FindProperty("m_ExternalObjects"); var materials = serializedObject.FindProperty("m_Materials"); for (int materialIndex = 0; materialIndex < materials.arraySize; materialIndex++) { var id = materials.GetArrayElementAtIndex(materialIndex); var name = id.FindPropertyRelative("name").stringValue; var type = id.FindPropertyRelative("type").stringValue; var assembly = id.FindPropertyRelative("assembly").stringValue; SerializedProperty materialProperty = null; for (int objectIndex = 0; objectIndex < externalObjects.arraySize; objectIndex++) { var pair = externalObjects.GetArrayElementAtIndex(objectIndex); var externalName = pair.FindPropertyRelative("first.name").stringValue; var externalType = pair.FindPropertyRelative("first.type").stringValue; if (externalName == name && externalType == type) { materialProperty = pair.FindPropertyRelative("second"); break; } } if (materialProperty != null) { if (materialProperty.objectReferenceValue != null) { var assetPath = AssetDatabase.GetAssetPath(materialProperty.objectReferenceValue); var mat = AssetDatabase.LoadAssetAtPath <Material>(assetPath); if (mat != null && postprocessorUtils.ContainsStandardShader(mat.shader.name)) { materialProperty.objectReferenceValue = null; } } } else { var index = externalObjects.arraySize++; var pair = externalObjects.GetArrayElementAtIndex(index); pair.FindPropertyRelative("first.name").stringValue = name; pair.FindPropertyRelative("first.type").stringValue = type; pair.FindPropertyRelative("first.assembly").stringValue = assembly; pair.FindPropertyRelative("second").objectReferenceValue = null; } } serializedObject.ApplyModifiedPropertiesWithoutUndo(); } }
private static void SetupMeshRenderer(Terrain terrain, MeshRenderer meshRenderer) { #if UNITY_EDITOR var terrainSerializedObject = new SerializedObject(terrain); var serializedObject = new SerializedObject(meshRenderer); var terrainLightmapParameters = terrainSerializedObject.FindProperty("m_LightmapParameters"); var lightmapParameters = serializedObject.FindProperty("m_LightmapParameters"); lightmapParameters.objectReferenceValue = terrainLightmapParameters.objectReferenceValue; serializedObject.ApplyModifiedPropertiesWithoutUndo(); #endif }
public static AssetMoveResult OnWillMoveAsset(string from, string to) { if (string.IsNullOrEmpty(from)) { return(AssetMoveResult.DidNotMove); } if (Path.GetExtension(from.ToLower()) != ".abc") { return(AssetMoveResult.DidNotMove); } var importer = AssetImporter.GetAtPath(from) as AlembicImporter; if (importer != null) { var so = new SerializedObject(importer); var prop = so.FindProperty("rootGameObjectName"); if (prop != null && string.IsNullOrEmpty(prop.stringValue)) { prop.stringValue = Path.GetFileNameWithoutExtension(from); so.ApplyModifiedPropertiesWithoutUndo(); } prop = so.FindProperty("rootGameObjectId"); if (prop != null && string.IsNullOrEmpty(prop.stringValue)) { prop.stringValue = Path.GetFileNameWithoutExtension(from); so.ApplyModifiedPropertiesWithoutUndo(); } AssetDatabase.WriteImportSettingsIfDirty(from); } AlembicStream.DisconnectStreamsWithPath(from); AlembicStream.RemapStreamsWithPath(from, to); AssetDatabase.Refresh(ImportAssetOptions.Default); AlembicStream.ReconnectStreamsWithPath(to); return(AssetMoveResult.DidNotMove); }
void ApplyPropertiesViaSerializedObj(Texture tex) { var so = new SerializedObject(tex); so.FindProperty("m_IsReadable").boolValue = m_IsReadable; so.FindProperty("m_StreamingMipmaps").boolValue = m_StreamingMipMaps; so.FindProperty("m_StreamingMipmapsPriority").intValue = m_StreamingMipMapPriority; //Set ColorSpace on ctr instead //so.FindProperty("m_ColorSpace").intValue = (int)(m_sRGBTexture ? ColorSpace.Gamma : ColorSpace.Linear); so.ApplyModifiedPropertiesWithoutUndo(); }
private void GenerateTexturedSpriteAsset(AssetImportContext ctx, Sprite sprite, string name) { if (sprite.texture != null) { sprite.texture.name = name + "Atlas"; } var tex = BuildTexture(sprite, name); var rect = new Rect(0, 0, tex.width, tex.height); // The pivot of the orignial sprite was properly computed, just translate it to the new textured sprite var pivot = sprite.pivot; pivot /= sprite.rect.size; float ratio = 1.0f; if (m_UseSVGPixelsPerUnit) { ratio = ((float)tex.width) / sprite.rect.width; ratio = Mathf.Max(0.001f, ratio); } var texturedSprite = Sprite.Create(tex, rect, pivot, SvgPixelsPerUnit * ratio, 0, TexturedSpriteMeshType, m_SpriteData.SpriteRect.border); texturedSprite.name = name; m_ImportingSprite = texturedSprite; m_ImportingTexture2D = tex; // Apply GUID from SpriteRect #if UNITY_2018_2_OR_NEWER texturedSprite.SetSpriteID(m_SpriteData.SpriteRect.spriteID); #else var so = new SerializedObject(texturedSprite); so.FindProperty("m_SpriteID").stringValue = m_SpriteData.SpriteRect.spriteID.ToString(); so.ApplyModifiedPropertiesWithoutUndo(); #endif texturedSprite.hideFlags = HideFlags.None; SetPhysicsShape(texturedSprite); ctx.AddObjectToAsset("sprite", texturedSprite); ctx.AddObjectToAsset("tex", tex); ctx.SetMainObject(tex); if (sprite.texture != null) { GameObject.DestroyImmediate(sprite.texture); } GameObject.DestroyImmediate(sprite); }
private void CheckName() { if (!authoring.IsNameValid) { return; } var automaticName = $"Room_{authoring.RoomName}"; var gameObject = authoring.gameObject; if (automaticName != gameObject.name) { var gameObjectSerializedObject = new SerializedObject(authoring.gameObject); var serializedProperty = gameObjectSerializedObject.FindProperty("m_Name"); gameObjectSerializedObject.ApplyModifiedPropertiesWithoutUndo(); serializedProperty.stringValue = automaticName; gameObjectSerializedObject.ApplyModifiedPropertiesWithoutUndo(); } }
public static UdonSharpBehaviour AddUdonSharpComponent(this GameObject gameObject, System.Type type) { if (type == typeof(UdonSharpBehaviour)) { throw new System.ArgumentException("Cannot add components of type 'UdonSharpBehaviour', you can only add subclasses of this type"); } if (!typeof(UdonSharpBehaviour).IsAssignableFrom(type)) { throw new System.ArgumentException("Type for AddUdonSharpComponent must be a subclass of UdonSharpBehaviour"); } UdonBehaviour udonBehaviour = gameObject.AddComponent <UdonBehaviour>(); UdonSharpProgramAsset programAsset = UdonSharpProgramAsset.GetProgramAssetForClass(type); udonBehaviour.programSource = programAsset; #pragma warning disable CS0618 // Type or member is obsolete udonBehaviour.SynchronizePosition = false; udonBehaviour.AllowCollisionOwnershipTransfer = false; #pragma warning restore CS0618 // Type or member is obsolete switch (programAsset.behaviourSyncMode) { case BehaviourSyncMode.Continuous: udonBehaviour.SyncMethod = Networking.SyncType.Continuous; break; case BehaviourSyncMode.Manual: udonBehaviour.SyncMethod = Networking.SyncType.Manual; break; case BehaviourSyncMode.None: udonBehaviour.SyncMethod = Networking.SyncType.None; break; } SerializedObject componentAsset = new SerializedObject(udonBehaviour); SerializedProperty serializedProgramAssetProperty = componentAsset.FindProperty("serializedProgramAsset"); serializedProgramAssetProperty.objectReferenceValue = programAsset.SerializedProgramAsset; componentAsset.ApplyModifiedPropertiesWithoutUndo(); UdonSharpBehaviour proxyComponent = UdonSharpEditorUtility.GetProxyBehaviour(udonBehaviour); if (EditorApplication.isPlaying) { udonBehaviour.InitializeUdonContent(); } return(proxyComponent); }
void FixDXRActivation(bool fromAsyncUnused) { if (!IsHdrpAssetUsedCorrect()) { FixHdrpAssetUsed(fromAsync: false); } //as property returning struct make copy, use serializedproperty to modify it var serializedObject = new SerializedObject(HDRenderPipeline.currentAsset); var propertySupportRayTracing = serializedObject.FindProperty("m_RenderPipelineSettings.supportRayTracing"); propertySupportRayTracing.boolValue = true; serializedObject.ApplyModifiedPropertiesWithoutUndo(); }
void FixDXRScreenSpaceShadow(bool fromAsyncUnused) { if (!IsHdrpAssetUsedCorrect()) { FixHdrpAssetUsed(fromAsync: false); } //as property returning struct make copy, use serializedproperty to modify it var serializedObject = new SerializedObject(HDRenderPipeline.currentAsset); var propertySupportScreenSpaceShadow = serializedObject.FindProperty("m_RenderPipelineSettings.hdShadowInitParams.supportScreenSpaceShadows"); propertySupportScreenSpaceShadow.boolValue = true; serializedObject.ApplyModifiedPropertiesWithoutUndo(); }
public void Editor_InputAsset_CanAddAndRemoveBindingThroughSerialization() { var map = new InputActionMap("set"); map.AddAction(name: "action1", binding: "/gamepad/leftStick"); map.AddAction(name: "action2", binding: "/gamepad/rightStick"); var asset = ScriptableObject.CreateInstance <InputActionAsset>(); asset.AddActionMap(map); var obj = new SerializedObject(asset); var mapProperty = obj.FindProperty("m_ActionMaps").GetArrayElementAtIndex(0); var action1Property = mapProperty.FindPropertyRelative("m_Actions").GetArrayElementAtIndex(0); InputActionSerializationHelpers.AppendBinding(action1Property, mapProperty); obj.ApplyModifiedPropertiesWithoutUndo(); // Maps and actions aren't UnityEngine.Objects so the modifications will not // be in-place. Look up the actions after each apply. var action1 = asset.actionMaps[0].TryGetAction("action1"); var action2 = asset.actionMaps[0].TryGetAction("action2"); Assert.That(action1.bindings, Has.Count.EqualTo(2)); Assert.That(action1.bindings[0].path, Is.EqualTo("/gamepad/leftStick")); Assert.That(action1.bindings[1].path, Is.EqualTo("")); Assert.That(action1.bindings[1].interactions, Is.EqualTo("")); Assert.That(action1.bindings[1].groups, Is.EqualTo("")); Assert.That(action2.bindings[0].path, Is.EqualTo("/gamepad/rightStick")); InputActionSerializationHelpers.RemoveBinding(action1Property, 1, mapProperty); obj.ApplyModifiedPropertiesWithoutUndo(); action1 = asset.actionMaps[0].TryGetAction("action1"); action2 = asset.actionMaps[0].TryGetAction("action2"); Assert.That(action1.bindings, Has.Count.EqualTo(1)); Assert.That(action1.bindings[0].path, Is.EqualTo("/gamepad/leftStick")); Assert.That(action2.bindings[0].path, Is.EqualTo("/gamepad/rightStick")); }
public void Editor_InputAsset_CanAddAndRemoveActionMapThroughSerialization() { var asset = ScriptableObject.CreateInstance <InputActionAsset>(); var obj = new SerializedObject(asset); InputActionSerializationHelpers.AddActionMap(obj); InputActionSerializationHelpers.AddActionMap(obj); obj.ApplyModifiedPropertiesWithoutUndo(); Assert.That(asset.actionMaps, Has.Count.EqualTo(2)); Assert.That(asset.actionMaps[0].name, Is.Not.Null.Or.Empty); Assert.That(asset.actionMaps[1].name, Is.Not.Null.Or.Empty); Assert.That(asset.actionMaps[0].name, Is.Not.EqualTo(asset.actionMaps[1].name)); var actionMap2Name = asset.actionMaps[1].name; InputActionSerializationHelpers.DeleteActionMap(obj, 0); obj.ApplyModifiedPropertiesWithoutUndo(); Assert.That(asset.actionMaps, Has.Count.EqualTo(1)); Assert.That(asset.actionMaps[0].name, Is.EqualTo(actionMap2Name)); }