private void ShowGUI() { materialFoldout = EditorGUILayout.Foldout(materialFoldout, "Material", true, EditorGUIHelper.foldoutStyle); if (materialFoldout) { EditorGUILayout.PropertyField(new SerializedObject(myTarget).FindProperty("grassMaterial")); if (myTarget.grassMaterial != null) { myTarget.grassMaterial.SetMaterialToGrass(); } myTarget.CorrectGrassMaterialSettings(); } EditorGUILayout.Space(); physicsFoldout = EditorGUILayout.Foldout(physicsFoldout, "Physics", true, EditorGUIHelper.foldoutStyle); if (physicsFoldout) { myTarget.grassPhysics = EditorGUILayout.ObjectField("Grass Physics Script", myTarget.grassPhysics, typeof(GrassPhysics), true) as GrassPhysics; CorrectTabs(); myTarget.grassMode = (GrassPhysicsMode)GUILayout.Toolbar((int)myTarget.grassMode, tabNames); if (myTarget.grassMode == GrassPhysicsMode.Full && AssetsManager.IsLowEndPlatform()) { EditorGUILayout.HelpBox(fullPhysicsWarningForLowEndPlatform, MessageType.Warning); } } }
private void ResetShaderSettings(GrassSettings grassSettings, GrassManager grassManager) { if (grassSettings == null) { return; } if (grassSettings.useAuto) { if (grassManager == null) { return; } EditorUtility.SetDirty(grassSettings); AssetDatabase.SaveAssets(); grassManager.CorrectShaderSettings(); grassManager.CorrectGrassMaterialSettings(); if (grassManager.grassMaterial != null) { grassManager.grassMaterial.SetMaterialToGrass(); } } else { EditorUtility.SetDirty(grassSettings); AssetsManager.SetGrassShaderSettings(true, grassSettings.useSimple, grassSettings.useFull); } }
private void Awake() { if (null == computeShader) { computeShader = AssetsManager.GetTrailEffectComputeShader(); AssetDatabase.SaveAssets(); } }
private void OnGUI() { //Set scroll position scrollPos = EditorGUILayout.BeginScrollView(scrollPos); AssetsManager.ResetGrassPhysicsSettings(); EditorGUIUtility.labelWidth = 160; GrassManager grassManager; if (null == (grassManager = FindObjectOfType <GrassManager>())) { if (GUILayout.Button("Create grass manager")) { GameObject instance = new GameObject("GrassManager", typeof(GrassManager)); Selection.activeGameObject = instance; } } GrassSettings grassSettings = AssetsManager.GetGrassSettings(); if (grassSettings != null) { Undo.RecordObject(grassSettings, "Update in " + grassSettings.name); bool prevUseAuto = grassSettings.useAuto; grassSettings.useAuto = EditorGUILayout.Toggle("Use Auto Physics Mode", grassSettings.useAuto); if (grassSettings.useAuto) { if (!prevUseAuto && grassManager) { EditorUtility.SetDirty(grassSettings); AssetDatabase.SaveAssets(); grassManager.CorrectShaderSettings(); } EditorGUILayout.HelpBox("With Auto Mode Enabled you cannot have different grass physics modes in the same game build.\n" + "To use different physics modes for grass in multiple scenes, " + "you have to disable it and set which physics modes you want to use.", MessageType.Info); } else { EditorGUILayout.Space(); EditorGUI.indentLevel++; EditorGUILayout.LabelField("Used physics modes:", EditorStyles.boldLabel); grassSettings.useSimple = EditorGUILayout.Toggle("Simple Physics Mode", grassSettings.useSimple); grassSettings.useFull = EditorGUILayout.Toggle("Full Physics Mode", grassSettings.useFull); EditorUtility.SetDirty(grassSettings); AssetsManager.SetGrassShaderSettings(true, grassSettings.useSimple, grassSettings.useFull); } } if (GUILayout.Button(new GUIContent("Reload settings and shaders", "Use this when you think that some shaders or settings changes haven't been applied"))) { ReloadShadersAndSettings(); } EditorGUILayout.EndScrollView(); }
public static void ShowWindow() { GrassWindow window = GetWindow <GrassWindow>("Grass Settings"); string path = AssetsManager.GetGrassAssetPath() + (EditorGUIUtility.isProSkin?"/Icons/GrassLightIco.png":"/Icons/GrassDarkIco.png"); Texture2D texture = AssetDatabase.LoadAssetAtPath <Texture2D>(path); window.titleContent.image = texture; window.titleContent.text = "Grass Settings"; }
private void CreateNewMaterialProfileMenu(SerializedProperty property) { List <Type> types = AssetsManager.GetListOfType(typeof(GrassMaterialProfile)); GenericMenu menu = new GenericMenu(); foreach (Type type in types) { menu.AddItem(new GUIContent(GrassMaterialAttribute.GetNameFromClassType(type)), false, () => { CreateNewProfile(type, property); }); } menu.ShowAsContext(); }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { float standardHeight = EditorGUI.GetPropertyHeight(property, true); float totalHeight = standardHeight; if (AssetsManager.IsLowEndPlatform()) { totalHeight += 2 * standardHeight + EditorGUIUtility.standardVerticalSpacing; } return(totalHeight); }
private void HandleRegisryURP(UnityEditor.PackageManager.PackageInfo package) { if (GUILayout.Button("Apply Grass Shaders to URP")) { string targetPath = "Packages/" + Path.GetFileName(package.resolvedPath); AssetsManager.CopyDirectory(package.resolvedPath, targetPath); string destFilePath = targetPath + "/Shaders/Terrain/WavingGrassPasses.hlsl"; CopyUrpTemplatFile(destFilePath); AssetDatabase.Refresh(); } }
/// <summary> /// Returns path to root grass asset folder /// </summary> /// <returns>Path to root grass asset folder</returns> public static string GetGrassAssetPath() { AssetsManager script = ScriptableObject.CreateInstance <AssetsManager>(); MonoScript ms = MonoScript.FromScriptableObject(script); string filePath = AssetDatabase.GetAssetPath(ms); DestroyImmediate(script); DirectoryInfo dir = Directory.GetParent(filePath).Parent.Parent; string folderPath = AbsolutePathToRelative(dir.ToString()); return(folderPath); }
private void ReloadShadersAndSettings() { GrassSettings grassSettings = AssetsManager.GetGrassSettings(); GrassManager grassManager = FindObjectOfType <GrassManager>(); Shader.SetGlobalTexture("_GrassDepthTex", Texture2D.blackTexture); ResetShaderSettings(grassSettings, grassManager); AssetsManager.ResetGrassPhysicsSettings(); AssetsManager.ReimportGrassPhysicsShaders(); AssetDatabase.Refresh(); }
private void CreateNewProfile(SerializedProperty property) { GrassPostProcessProfile profile = AssetsManager.CreateNewScriptableObjectOfType <GrassPostProcessProfile>("Grass Post Process Profile location", AssetsManager.GetScenePath(property), "GrassPostProcessProfile", "asset"); if (null != profile) { property.objectReferenceValue = profile; } }
private void CreateNewProfile(Type type, SerializedProperty property) { GrassMaterialProfile profile = AssetsManager.CreateNewScriptableObjectOfType(type, "Grass Material location", AssetsManager.GetScenePath(property), GrassMaterialAttribute.GetFileNameFromClassType(type), "asset") as GrassMaterialProfile; if (null != profile) { property.objectReferenceValue = profile; property.serializedObject.ApplyModifiedProperties(); } }
private void OnAddDropdownCallback(Rect button, ReorderableList list) { GenericMenu menu = new GenericMenu(); #if UNITY_2018_2_OR_NEWER menu.allowDuplicateNames = true; #endif List <Type> types = AssetsManager.GetListOfType(typeof(GrassPostProcess)); foreach (Type type in types) { menu.AddItem(new GUIContent(NameAttribute.GetNameFromClassType(type), NameAttribute.GetDescriptionFromClassType(type)), false, AddPostProcessHandler, type.Name); } menu.ShowAsContext(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { float standardHeight = EditorGUI.GetPropertyHeight(property, true); position.height = standardHeight; if (AssetsManager.IsLowEndPlatform()) { LowEndPlatformWarningAttribute warningAttribute = attribute as LowEndPlatformWarningAttribute; Rect warningRect = new Rect(position.x, position.y, position.width, standardHeight * 2); EditorGUI.HelpBox(warningRect, warningAttribute.warning, MessageType.Warning); position.y += warningRect.height + EditorGUIUtility.standardVerticalSpacing; } EditorGUI.PropertyField(position, property, label); }
/// <summary> /// Pop ups <see cref="EditorUtility.SaveFilePanel"/> opened in given directory, /// then if chosen path is correct (selection wasn't canceled) /// <see cref="ScriptableObject"/> is created and saved in chosen path /// and then returned /// </summary> /// <param name="defaultPath">Path where <see cref="EditorUtility.SaveFilePanel"/> opens</param> /// <returns>Created <see cref="ScriptableObject"/> asset</returns> public static T CreateNewScriptableObjectOfType <T>(string title, string directory, string defaultName, string extension) where T : ScriptableObject { string path = EditorUtility.SaveFilePanel(title, directory, defaultName, extension); path = AssetsManager.AbsolutePathToRelative(path); if (!string.IsNullOrEmpty(path)) { T profile = ScriptableObject.CreateInstance <T>(); AssetDatabase.CreateAsset(profile, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); return(profile); } return(null); }
/// <summary> /// Sets (global) physics settings to correspond to what is in <see cref="grassProfile.grassMode"/> /// </summary> public void CorrectShaderSettings() { if (IsPrefabOrMultipleManagers()) { return; } GrassSettings settings = AssetsManager.GetGrassSettings(); if (settings != null && settings.useAuto) { bool isSimple = (grassMode == GrassPhysicsMode.Simple); bool isFull = (grassMode == GrassPhysicsMode.Full); AssetsManager.SetGrassShaderSettings(false, isSimple, isFull); } }
/// <summary> /// Sets (global) <see cref="GrassMaterialProfile"/> settings if current <see cref="GrassManager"/> is not a prefab /// </summary> public void CorrectGrassMaterialSettings() { if (IsPrefabOrMultipleManagers()) { return; } string shaderPath = AssetsManager.GetGrassAssetPath() + "/Shaders/WavingGrassPhysics.shader"; System.Type materialType = null; if (grassMaterial != null) { materialType = grassMaterial.GetType(); } AssetsManager.SetGrassFragmentInclude(GrassMaterialAttribute.GetFragmentShaderFromClassType(materialType)); AssetsManager.SetSurfInShaderFile(shaderPath, GrassMaterialAttribute.GetSurfFromClassType(materialType)); }
private void HandleEmbeddedURP(UnityEditor.PackageManager.PackageInfo package) { EditorGUILayout.LabelField("URP Grass is applied."); if (GUILayout.Button("Reapply Grass Shaders to URP")) { string destFilePath = package.resolvedPath + "/Shaders/Terrain/WavingGrassPasses.hlsl"; CopyUrpTemplatFile(destFilePath); AssetDatabase.Refresh(); } if (GUILayout.Button("Reset URP")) { string targetPath = "Library/PackageCache/" + Path.GetFileName(package.resolvedPath); AssetsManager.CopyDirectory(package.resolvedPath, targetPath); Directory.Delete(package.resolvedPath, true); AssetDatabase.Refresh(); } }
/// <summary> /// Returns <see cref="GrassSettings"/> scriptable object from "Settings" folder /// </summary> /// <returns>Grass mode settings</returns> public static GrassSettings GetGrassSettings() { string settingsPath = AssetsManager.GetGrassAssetPath() + "/Settings/GrassSettings.asset"; return(AssetsManager.LoadOrCreateObject(settingsPath, typeof(GrassSettings)) as GrassSettings); }