Пример #1
0
        /// <summary>
        /// Disables sampling of a color map in the grass shader. This must be called when a color map was used, but the current game context no longer as one active
        /// </summary>
        public static void DisableGlobally()
        {
            Shader.SetGlobalTexture("_ColorMap", null);
            Shader.SetGlobalVector("_ColorMapUV", Vector4.zero);

            Active = null;
        }
Пример #2
0
        public static GrassColorMap SaveColorMapToAsset(GrassColorMap colorMap)
        {
            string assetPath = "Assets/";

            assetPath = EditorUtility.SaveFolderPanel("Asset destination folder", assetPath, "");
            if (assetPath == string.Empty)
            {
                return(colorMap);
            }

            assetPath  = assetPath.Replace(Application.dataPath, "Assets/");
            assetPath += colorMap.name + ".asset";

            AssetDatabase.CreateAsset(colorMap, assetPath);

            colorMap = (GrassColorMap)AssetDatabase.LoadAssetAtPath(assetPath, typeof(GrassColorMap));

            //Save texture to asset
            if (!colorMap.texture)
            {
                colorMap.texture = new Texture2D(colorMap.resolution, colorMap.resolution);
            }

            colorMap.texture.name = colorMap.name + " Texture";
            AssetDatabase.AddObjectToAsset(colorMap.texture, colorMap);
            string path = AssetDatabase.GetAssetPath(colorMap.texture);

            AssetDatabase.ImportAsset(path);

            //Reference serialized texture asset
            colorMap.texture = (Texture2D)AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D));

            return(colorMap);
        }
Пример #3
0
        public static GrassColorMap NewColorMap()
        {
            GrassColorMap colorMap = ScriptableObject.CreateInstance <GrassColorMap>();

            SetName(colorMap);

            return(colorMap);
        }
Пример #4
0
        private void OnEnable()
        {
            colorMap = (GrassColorMap)target;

            texture         = serializedObject.FindProperty("texture");
            overrideTexture = serializedObject.FindProperty("overrideTexture");
            customTex       = serializedObject.FindProperty("customTex");
            bounds          = serializedObject.FindProperty("bounds");
        }
        private void OnDisable()
        {
            Instance = null;
            //Disable sampling of color map
            GrassColorMap.DisableGlobally();

#if UNITY_EDITOR
            EditorSceneManager.sceneSaved -= OnSceneSave;
#endif
        }
Пример #6
0
        public void SetActive()
        {
            if (!texture || (overrideTexture && !customTex))
            {
                Debug.LogWarning("Tried to activate grass color map with null texture", this);
                return;
            }

            Shader.SetGlobalTexture("_ColorMap", overrideTexture? customTex : texture);

            //Enables sampling of color map in shader
            uv.w = 1f;

            Shader.SetGlobalVector("_ColorMapUV", uv);

            Active = this;
        }
Пример #7
0
        public void OnEnable()
        {
            Instance = this;

            Init();

            if (colorMap)
            {
                colorMap.SetActive();
            }
            else
            {
                if (!GrassColorMapRenderer.Instance)
                {
                    GrassColorMap.DisableGlobally();
                }
            }

#if UNITY_EDITOR
            UnityEditor.SceneView.duringSceneGui += OnSceneGUI;
#endif
        }
Пример #8
0
        public static void SetName(GrassColorMap colorMap)
        {
            string prefix = EditorSceneManager.GetActiveScene().name;

            if (prefix == "")
            {
                prefix = "Untitled";
            }

#if UNITY_EDITOR
            colorMap.name = EditorSceneManager.GetActiveScene().name + "_GrassColormap";
            if (colorMap.texture != null)
            {
                colorMap.texture.name = EditorSceneManager.GetActiveScene().name + "_GrassColormap";
            }
#else
            colorMap.name = EditorSceneManager.GetActiveScene().name + "_GrassColormap";
            if (colorMap.texture != null)
            {
                colorMap.texture.name = "GrassColorMap_" + colorMap.GetInstanceID();
            }
#endif
        }
Пример #9
0
 public static void ApplyUVFromTerrainBounds(GrassColorMap colorMap, GrassColorMapRenderer renderer)
 {
     colorMap.bounds = ColorMapEditor.GetTerrainBounds(renderer.terrainObjects);
     colorMap.uv     = ColorMapEditor.BoundsToUV(renderer.colorMap.bounds);
 }
 private void OnDisable()
 {
     Instance = null;
     //Disable sampling of color map
     GrassColorMap.DisableGlobally();
 }