Esempio n. 1
0
        public void OnInspectorGUI(Action onValueChanged)
        {
            // anisoLevel
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Aniso Level");

                var changedVal = (int)EditorGUILayout.Slider(this.anisoLevel, 0, 16);// actually, max is not defined.
                if (changedVal != this.anisoLevel) {
                    this.anisoLevel = changedVal;
                    onValueChanged();
                }
            }

            // filterMode
            var newFilterMode = (UnityEngine.FilterMode)EditorGUILayout.Popup("Filter Mode", (int)this.filterMode, Enum.GetNames(typeof(UnityEngine.FilterMode)), new GUILayoutOption[0]);
            if (newFilterMode != this.filterMode) {
                this.filterMode = newFilterMode;
                onValueChanged();
            }

            // mipMapBias
            var newMipMapBias = EditorGUILayout.TextField("MipMap Bias", this.mipMapBias.ToString());
            if (newMipMapBias != this.mipMapBias.ToString()) {
                this.mipMapBias = float.Parse(newMipMapBias, CultureInfo.InvariantCulture.NumberFormat);
                onValueChanged();
            }

            // wrapMode
            var newWrapMode = (UnityEngine.TextureWrapMode)EditorGUILayout.Popup("Wrap Mode", (int)this.wrapMode, Enum.GetNames(typeof(UnityEngine.TextureWrapMode)), new GUILayoutOption[0]);
            if (newWrapMode != this.wrapMode) {
                this.wrapMode = newWrapMode;
                onValueChanged();
            }
        }
Esempio n. 2
0
 public CubemapModifier()
 {
     anisoLevel = 1;
     filterMode = FilterMode.Bilinear;
     mipMapBias = 0;
     wrapMode   = TextureWrapMode.Clamp;
 }
Esempio n. 3
0
        public void OnInspectorGUI(Action onValueChanged)
        {
            // wrapMode
            var newWrapMode = (UnityEngine.TextureWrapMode)EditorGUILayout.Popup("Wrap Mode", (int)this.wrapMode, Enum.GetNames(typeof(UnityEngine.TextureWrapMode)), new GUILayoutOption[0]);

            if (newWrapMode != this.wrapMode)
            {
                this.wrapMode = newWrapMode;
                onValueChanged();
            }

            // filterMode
            var newFilterMode = (UnityEngine.FilterMode)EditorGUILayout.Popup("Filter Mode", (int)this.filterMode, Enum.GetNames(typeof(UnityEngine.FilterMode)), new GUILayoutOption[0]);

            if (newFilterMode != this.filterMode)
            {
                this.filterMode = newFilterMode;
                onValueChanged();
            }

            // anisoLevel
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Aniso Level");

                var changedVal = (int)EditorGUILayout.Slider(this.anisoLevel, 0, 16);
                if (changedVal != this.anisoLevel)
                {
                    this.anisoLevel = changedVal;
                    onValueChanged();
                }
            }
            EditorGUILayout.HelpBox("Aniso Level can be set only when RenderTexture does not have depth buffer.", MessageType.Info);
        }
Esempio n. 4
0
        public override void DrawInspector(Action changed)
        {
            // wrapMode
            var newWrapMode = (UnityEngine.TextureWrapMode)EditorGUILayout.Popup("Wrap Mode", (int)this.wrapMode, Enum.GetNames(typeof(UnityEngine.TextureWrapMode)), new GUILayoutOption[0]);

            if (newWrapMode != this.wrapMode)
            {
                this.wrapMode = newWrapMode;
                changed();
            }

            // filterMode
            var newFilterMode = (UnityEngine.FilterMode)EditorGUILayout.Popup("Filter Mode", (int)this.filterMode, Enum.GetNames(typeof(UnityEngine.FilterMode)), new GUILayoutOption[0]);

            if (newFilterMode != this.filterMode)
            {
                this.filterMode = newFilterMode;
                changed();
            }

            // anisoLevel
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Aniso Level");

                var changedVal = (int)EditorGUILayout.Slider(this.anisoLevel, 0, 16);
                if (changedVal != this.anisoLevel)
                {
                    this.anisoLevel = changedVal;
                    changed();
                }
            }
            EditorGUILayout.HelpBox("Aniso Level can be set if target Asset(RenderTexture)'s Depth Buffer is No depth buffer. ", MessageType.Info);
        }
Esempio n. 5
0
 public CubemapModifier()
 {
     anisoLevel = 1;
     filterMode = FilterMode.Bilinear;
     mipMapBias = 0;
     wrapMode = TextureWrapMode.Clamp;
 }
        protected void DrawTexture()
        {
            int   num1       = Mathf.Max(this.m_Texture.width, 1);
            float num2       = Mathf.Min(this.m_MipLevel, (float)(TextureUtil.CountMipmaps((Texture)this.m_Texture) - 1));
            float mipMapBias = this.m_Texture.mipMapBias;

            TextureUtil.SetMipMapBiasNoDirty((Texture)this.m_Texture, num2 - this.Log2((float)num1 / this.m_TextureRect.width));
            UnityEngine.FilterMode filterMode = this.m_Texture.filterMode;
            TextureUtil.SetFilterModeNoDirty((Texture)this.m_Texture, UnityEngine.FilterMode.Point);
            if (this.m_ShowAlpha)
            {
                if ((UnityEngine.Object) this.m_TextureAlphaOverride != (UnityEngine.Object)null)
                {
                    EditorGUI.DrawTextureTransparent(this.m_TextureRect, (Texture)this.m_TextureAlphaOverride);
                }
                else
                {
                    EditorGUI.DrawTextureAlpha(this.m_TextureRect, (Texture)this.m_Texture);
                }
            }
            else
            {
                EditorGUI.DrawTextureTransparent(this.m_TextureRect, (Texture)this.m_Texture);
            }
            TextureUtil.SetMipMapBiasNoDirty((Texture)this.m_Texture, mipMapBias);
            TextureUtil.SetFilterModeNoDirty((Texture)this.m_Texture, filterMode);
        }
 protected void DoFilterModePopup()
 {
     EditorGUI.BeginChangeCheck();
     EditorGUI.showMixedValue = this.m_FilterMode.hasMultipleDifferentValues;
     UnityEngine.FilterMode intValue = (UnityEngine.FilterMode) this.m_FilterMode.intValue;
     intValue = (UnityEngine.FilterMode)EditorGUILayout.EnumPopup(EditorGUIUtility.TempContent("Filter Mode"), intValue, new GUILayoutOption[0]);
     EditorGUI.showMixedValue = false;
     if (EditorGUI.EndChangeCheck())
     {
         this.m_FilterMode.intValue = (int)intValue;
     }
 }
 // Parameter Attributes are applied below in Stop()
 public void In(
     [FriendlyName("Target", "The target Texture2D variable.")]
     Texture2D target,
     [FriendlyName("Width", "The width of the texture as an int variable.")]
     out int width,
     [FriendlyName("Height", "The height of the texture as an int variable.")]
     out int height,
     [FriendlyName("Size", "The size of the texture as a Vector2 variable (width, height).")]
     [SocketState(false, false)]
     out Vector2 size,
     [FriendlyName("Filter Mode", "The current filter mode of the texture.")]
     [SocketState(false, false)]
     out UnityEngine.FilterMode filterMode,
     [FriendlyName("Anisotropic Level", "The current anisotropic filtering level of the texture.")]
     [SocketState(false, false)]
     out int anisoLevel,
     [FriendlyName("Wrap Mode", "The current wrap mode setting of the texture (Repeat or Clamp).")]
     [SocketState(false, false)]
     out UnityEngine.TextureWrapMode wrapMode,
     [FriendlyName("Mip Map Bias", "The current mip map bias of the texture.")]
     [SocketState(false, false)]
     out float mipMapBias,
     [FriendlyName("Texture Name", "The current name of the Texture2D as a string variable.")]
     [SocketState(false, false)]
     out string name
     )
 {
     if (null != target)
     {
         size       = new Vector2(target.width, target.height);
         width      = target.width;
         height     = target.height;
         filterMode = target.filterMode;
         anisoLevel = target.anisoLevel;
         wrapMode   = target.wrapMode;
         mipMapBias = target.mipMapBias;
         name       = target.name;
     }
     else
     {
         size       = new Vector2(0, 0);
         width      = 0;
         height     = 0;
         filterMode = UnityEngine.FilterMode.Point;
         anisoLevel = 0;
         wrapMode   = UnityEngine.TextureWrapMode.Clamp;
         mipMapBias = 0f;
         name       = "null";
     }
 }
Esempio n. 9
0
 private CubemapOperator(
     string operatorType,
     int anisoLevel,
     FilterMode filterMode,
     float mipMapBias,
     TextureWrapMode wrapMode
     )
 {
     this.operatorType = operatorType;
     this.anisoLevel   = anisoLevel;
     this.filterMode   = filterMode;
     this.mipMapBias   = mipMapBias;
     this.wrapMode     = wrapMode;
 }
Esempio n. 10
0
 static void Texture_filterMode(JSVCall vc)
 {
     if (vc.bGet)
     {
         UnityEngine.Texture _this = (UnityEngine.Texture)vc.csObj;
         var result = _this.filterMode;
         JSApi.setEnum((int)JSApi.SetType.Rval, (int)result);
     }
     else
     {
         UnityEngine.FilterMode arg0  = (UnityEngine.FilterMode)JSApi.getEnum((int)JSApi.GetType.Arg);
         UnityEngine.Texture    _this = (UnityEngine.Texture)vc.csObj;
         _this.filterMode = arg0;
     }
 }
Esempio n. 11
0
 private void DrawObjectIcon(Rect position, Texture icon)
 {
     if (icon != null)
     {
         int num = Mathf.Min((int)position.width, (int)position.height);
         if (num >= (icon.width * 2))
         {
             num = icon.width * 2;
         }
         UnityEngine.FilterMode filterMode = icon.filterMode;
         icon.filterMode = UnityEngine.FilterMode.Point;
         GUI.DrawTexture(new Rect(position.x + ((((int)position.width) - num) / 2), position.y + ((((int)position.height) - num) / 2), (float)num, (float)num), icon, ScaleMode.ScaleToFit);
         icon.filterMode = filterMode;
     }
 }
Esempio n. 12
0
        private RenderTextureOperator(
            // Int32 width, Int32 height,
            // AntiAliasing antiAliasing,
            // UnityEngine.RenderTextureFormat colorFormat,
            // DepthBuffer depthBuffer,
            UnityEngine.TextureWrapMode wrapMode,
            UnityEngine.FilterMode filterMode,
            Int32 anisoLevel
            )
        {
            this.dataType = "UnityEngine.RenderTexture";

            this.wrapMode   = wrapMode;
            this.filterMode = filterMode;
            this.anisoLevel = anisoLevel;
        }
Esempio n. 13
0
        public override void DrawInspector(Action changed)
        {
            // anisoLevel
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Aniso Level");

                var changedVal = (int)EditorGUILayout.Slider(this.anisoLevel, 0, 16);                // actually, max is not defined.
                if (changedVal != this.anisoLevel)
                {
                    this.anisoLevel = changedVal;
                    changed();
                }
            }

            // filterMode
            var newFilterMode = (UnityEngine.FilterMode)EditorGUILayout.Popup("Filter Mode", (int)this.filterMode, Enum.GetNames(typeof(UnityEngine.FilterMode)), new GUILayoutOption[0]);

            if (newFilterMode != this.filterMode)
            {
                this.filterMode = newFilterMode;
                changed();
            }

            // mipMapBias
            var newMipMapBias = EditorGUILayout.TextField("MipMap Bias", this.mipMapBias.ToString());

            if (newMipMapBias != this.mipMapBias.ToString())
            {
                this.mipMapBias = float.Parse(newMipMapBias, CultureInfo.InvariantCulture.NumberFormat);
                changed();
            }

            // wrapMode
            var newWrapMode = (UnityEngine.TextureWrapMode)EditorGUILayout.Popup("Wrap Mode", (int)this.wrapMode, Enum.GetNames(typeof(UnityEngine.TextureWrapMode)), new GUILayoutOption[0]);

            if (newWrapMode != this.wrapMode)
            {
                this.wrapMode = newWrapMode;
                changed();
            }
        }
Esempio n. 14
0
 public static extern void SetFilterModeNoDirty(Texture tex, UnityEngine.FilterMode mode);
Esempio n. 15
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            Texture       target        = this.target as Texture;
            RenderTexture renderTexture = target as RenderTexture;

            if ((UnityEngine.Object)renderTexture != (UnityEngine.Object)null)
            {
                if (!SystemInfo.SupportsRenderTextureFormat(renderTexture.format))
                {
                    return;
                }
                renderTexture.Create();
            }
            if (this.IsCubemap())
            {
                this.m_CubemapPreview.OnPreviewGUI(target, r, background);
            }
            else
            {
                int   num1 = Mathf.Max(target.width, 1);
                int   num2 = Mathf.Max(target.height, 1);
                float levelForRendering = this.GetMipLevelForRendering();
                float num3  = Mathf.Min(Mathf.Min(r.width / (float)num1, r.height / (float)num2), 1f);
                Rect  rect1 = new Rect(r.x, r.y, (float)num1 * num3, (float)num2 * num3);
                PreviewGUI.BeginScrollView(r, this.m_Pos, rect1, (GUIStyle)"PreHorizontalScrollbar", (GUIStyle)"PreHorizontalScrollbarThumb");
                float mipMapBias = target.mipMapBias;
                TextureUtil.SetMipMapBiasNoDirty(target, levelForRendering - this.Log2((float)num1 / rect1.width));
                UnityEngine.FilterMode filterMode = target.filterMode;
                TextureUtil.SetFilterModeNoDirty(target, UnityEngine.FilterMode.Point);
                if (this.m_ShowAlpha)
                {
                    EditorGUI.DrawTextureAlpha(rect1, target);
                }
                else
                {
                    Texture2D texture2D = target as Texture2D;
                    if ((UnityEngine.Object)texture2D != (UnityEngine.Object)null && texture2D.alphaIsTransparency)
                    {
                        EditorGUI.DrawTextureTransparent(rect1, target);
                    }
                    else
                    {
                        EditorGUI.DrawPreviewTexture(rect1, target);
                    }
                }
                if ((double)rect1.width > 32.0 && (double)rect1.height > 32.0)
                {
                    TextureImporter  atPath = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath((UnityEngine.Object)target)) as TextureImporter;
                    SpriteMetaData[] spriteMetaDataArray = !((UnityEngine.Object)atPath != (UnityEngine.Object)null) ? (SpriteMetaData[])null : atPath.spritesheet;
                    if (spriteMetaDataArray != null && atPath.spriteImportMode == SpriteImportMode.Multiple)
                    {
                        Rect outScreenRect = new Rect();
                        Rect outSourceRect = new Rect();
                        GUI.CalculateScaledTextureRects(rect1, ScaleMode.StretchToFill, (float)target.width / (float)target.height, ref outScreenRect, ref outSourceRect);
                        int width  = target.width;
                        int height = target.height;
                        atPath.GetWidthAndHeight(ref width, ref height);
                        float num4 = (float)target.width / (float)width;
                        HandleUtility.ApplyWireMaterial();
                        GL.PushMatrix();
                        GL.MultMatrix(Handles.matrix);
                        GL.Begin(1);
                        GL.Color(new Color(1f, 1f, 1f, 0.5f));
                        foreach (SpriteMetaData spriteMetaData in spriteMetaDataArray)
                        {
                            Rect rect2 = spriteMetaData.rect;
                            this.DrawRect(new Rect()
                            {
                                xMin = outScreenRect.xMin + outScreenRect.width * (rect2.xMin / (float)target.width * num4),
                                xMax = outScreenRect.xMin + outScreenRect.width * (rect2.xMax / (float)target.width * num4),
                                yMin = outScreenRect.yMin + outScreenRect.height * (float)(1.0 - (double)rect2.yMin / (double)target.height * (double)num4),
                                yMax = outScreenRect.yMin + outScreenRect.height * (float)(1.0 - (double)rect2.yMax / (double)target.height * (double)num4)
                            });
                        }
                        GL.End();
                        GL.PopMatrix();
                    }
                }
                TextureUtil.SetMipMapBiasNoDirty(target, mipMapBias);
                TextureUtil.SetFilterModeNoDirty(target, filterMode);
                this.m_Pos = PreviewGUI.EndScrollView();
                if ((double)levelForRendering == 0.0)
                {
                    return;
                }
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + (object)levelForRendering);
            }
        }
        public void ObjectPreview(Rect r)
        {
            if ((double)r.height <= 0.0)
            {
                return;
            }
            if (LightingWindowObjectTab.s_Styles == null)
            {
                LightingWindowObjectTab.s_Styles = new LightingWindowObjectTab.Styles();
            }
            List <Texture2D> texture2DList = new List <Texture2D>();

            foreach (GITextureType previewTextureType in this.kObjectPreviewTextureTypes)
            {
                texture2DList.Add(LightmapVisualizationUtility.GetGITexture(previewTextureType));
            }
            if (texture2DList.Count == 0)
            {
                return;
            }
            if (this.m_ZoomablePreview == null)
            {
                this.m_ZoomablePreview           = new ZoomableArea(true);
                this.m_ZoomablePreview.hRangeMin = 0.0f;
                this.m_ZoomablePreview.vRangeMin = 0.0f;
                this.m_ZoomablePreview.hRangeMax = 1f;
                this.m_ZoomablePreview.vRangeMax = 1f;
                this.m_ZoomablePreview.SetShownHRange(0.0f, 1f);
                this.m_ZoomablePreview.SetShownVRange(0.0f, 1f);
                this.m_ZoomablePreview.uniformScale    = true;
                this.m_ZoomablePreview.scaleWithWindow = true;
            }
            GUI.Box(r, string.Empty, (GUIStyle)"PreBackground");
            Rect position1 = new Rect(r);

            ++position1.y;
            position1.height = 18f;
            GUI.Box(position1, string.Empty, EditorStyles.toolbar);
            Rect position2 = new Rect(r);

            ++position2.y;
            position2.height = 18f;
            position2.width  = 120f;
            Rect rect1 = new Rect(r);

            rect1.yMin  += position2.height;
            rect1.yMax  -= 14f;
            rect1.width -= 11f;
            int selectedIndex = Array.IndexOf <GUIContent>(LightingWindowObjectTab.kObjectPreviewTextureOptions, this.m_SelectedObjectPreviewTexture);

            if (selectedIndex < 0)
            {
                selectedIndex = 0;
            }
            int index = EditorGUI.Popup(position2, selectedIndex, LightingWindowObjectTab.kObjectPreviewTextureOptions, EditorStyles.toolbarPopup);

            if (index >= LightingWindowObjectTab.kObjectPreviewTextureOptions.Length)
            {
                index = 0;
            }
            this.m_SelectedObjectPreviewTexture = LightingWindowObjectTab.kObjectPreviewTextureOptions[index];
            LightmapType       lightmapType = this.kObjectPreviewTextureTypes[index] == GITextureType.Baked || this.kObjectPreviewTextureTypes[index] == GITextureType.BakedDirectional ? LightmapType.StaticLightmap : LightmapType.DynamicLightmap;
            SerializedProperty property     = new SerializedObject(LightmapEditorSettings.GetLightmapSettings()).FindProperty("m_LightmapsMode");
            bool flag = (this.kObjectPreviewTextureTypes[index] == GITextureType.Baked || this.kObjectPreviewTextureTypes[index] == GITextureType.BakedDirectional) && property.intValue == 2;

            if (flag)
            {
                GUIContent content   = GUIContent.Temp("Indirect");
                Rect       position3 = position2;
                position3.x    += position2.width;
                position3.width = EditorStyles.toolbarButton.CalcSize(content).x;
                this.m_HasSeparateIndirectUV = GUI.Toggle(position3, this.m_HasSeparateIndirectUV, content.text, EditorStyles.toolbarButton);
            }
            switch (Event.current.type)
            {
            case EventType.ValidateCommand:
            case EventType.ExecuteCommand:
                if (Event.current.commandName == "FrameSelected")
                {
                    Vector4 lightmapTilingOffset = LightmapVisualizationUtility.GetLightmapTilingOffset(lightmapType);
                    Vector2 lhs1 = new Vector2(lightmapTilingOffset.z, lightmapTilingOffset.w);
                    Vector2 lhs2 = lhs1 + new Vector2(lightmapTilingOffset.x, lightmapTilingOffset.y);
                    lhs1 = Vector2.Max(lhs1, Vector2.zero);
                    Vector2 vector2 = Vector2.Min(lhs2, Vector2.one);
                    float   num1    = 1f - lhs1.y;
                    lhs1.y    = 1f - vector2.y;
                    vector2.y = num1;
                    Rect rect2 = new Rect(lhs1.x, lhs1.y, vector2.x - lhs1.x, vector2.y - lhs1.y);
                    rect2.x -= Mathf.Clamp(rect2.height - rect2.width, 0.0f, float.MaxValue) / 2f;
                    rect2.y -= Mathf.Clamp(rect2.width - rect2.height, 0.0f, float.MaxValue) / 2f;
                    // ISSUE: explicit reference operation
                    // ISSUE: variable of a reference type
                    Rect& local = @rect2;
                    float num2  = Mathf.Max(rect2.width, rect2.height);
                    rect2.height = num2;
                    double num3 = (double)num2;
                    // ISSUE: explicit reference operation
                    (^ local).width = (float)num3;
                    if (flag && this.m_HasSeparateIndirectUV)
                    {
                        rect2.x += 0.5f;
                    }
                    this.m_ZoomablePreview.shownArea = rect2;
                    Event.current.Use();
                    break;
                }
                break;

            case EventType.Repaint:
                Texture2D texture = texture2DList[index];
                if ((bool)((UnityEngine.Object)texture) && Event.current.type == EventType.Repaint)
                {
                    Rect position3 = new Rect(this.ScaleRectByZoomableArea(this.CenterToRect(this.ResizeRectToFit(new Rect(0.0f, 0.0f, (float)texture.width, (float)texture.height), rect1), rect1), this.m_ZoomablePreview));
                    position3.x += 3f;
                    position3.y += rect1.y + 20f;
                    Rect drawableArea = new Rect(rect1);
                    drawableArea.y += position2.height + 3f;
                    float num = drawableArea.y - 14f;
                    position3.y    -= num;
                    drawableArea.y -= num;
                    UnityEngine.FilterMode filterMode = texture.filterMode;
                    texture.filterMode = UnityEngine.FilterMode.Point;
                    GITextureType previewTextureType = this.kObjectPreviewTextureTypes[index];
                    bool          drawSpecularUV     = flag && this.m_HasSeparateIndirectUV;
                    LightmapVisualizationUtility.DrawTextureWithUVOverlay(texture, Selection.activeGameObject, drawableArea, position3, previewTextureType, drawSpecularUV);
                    texture.filterMode = filterMode;
                    break;
                }
                break;
            }
            if (this.m_PreviousSelection != Selection.activeInstanceID)
            {
                this.m_PreviousSelection = Selection.activeInstanceID;
                this.m_ZoomablePreview.SetShownHRange(0.0f, 1f);
                this.m_ZoomablePreview.SetShownVRange(0.0f, 1f);
            }
            Rect rect3 = new Rect(r);

            rect3.yMin += position2.height;
            this.m_ZoomablePreview.rect = rect3;
            this.m_ZoomablePreview.BeginViewGUI();
            this.m_ZoomablePreview.EndViewGUI();
            GUILayoutUtility.GetRect(r.width, r.height);
        }
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            Texture       target   = base.target as Texture;
            RenderTexture texture2 = target as RenderTexture;

            if (texture2 != null)
            {
                if (!SystemInfo.SupportsRenderTextureFormat(texture2.format))
                {
                    return;
                }
                texture2.Create();
            }
            if (this.IsCubemap())
            {
                this.m_CubemapPreview.OnPreviewGUI(target, r, background);
            }
            else
            {
                int   num  = Mathf.Max(target.width, 1);
                int   num2 = Mathf.Max(target.height, 1);
                float mipLevelForRendering = this.GetMipLevelForRendering();
                float num4     = Mathf.Min(Mathf.Min((float)(r.width / ((float)num)), (float)(r.height / ((float)num2))), 1f);
                Rect  viewRect = new Rect(r.x, r.y, num * num4, num2 * num4);
                PreviewGUI.BeginScrollView(r, this.m_Pos, viewRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                float mipMapBias = target.mipMapBias;
                TextureUtil.SetMipMapBiasNoDirty(target, mipLevelForRendering - this.Log2(((float)num) / viewRect.width));
                UnityEngine.FilterMode filterMode = target.filterMode;
                TextureUtil.SetFilterModeNoDirty(target, UnityEngine.FilterMode.Point);
                if (this.m_ShowAlpha)
                {
                    EditorGUI.DrawTextureAlpha(viewRect, target);
                }
                else
                {
                    Texture2D textured = target as Texture2D;
                    if ((textured != null) && textured.alphaIsTransparency)
                    {
                        EditorGUI.DrawTextureTransparent(viewRect, target);
                    }
                    else
                    {
                        EditorGUI.DrawPreviewTexture(viewRect, target);
                    }
                }
                if ((viewRect.width > 32f) && (viewRect.height > 32f))
                {
                    TextureImporter  atPath      = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(target)) as TextureImporter;
                    SpriteMetaData[] spritesheet = atPath?.spritesheet;
                    if ((spritesheet != null) && (atPath.spriteImportMode == SpriteImportMode.Multiple))
                    {
                        Rect outScreenRect = new Rect();
                        Rect outSourceRect = new Rect();
                        GUI.CalculateScaledTextureRects(viewRect, ScaleMode.StretchToFill, ((float)target.width) / ((float)target.height), ref outScreenRect, ref outSourceRect);
                        int width  = target.width;
                        int height = target.height;
                        atPath.GetWidthAndHeight(ref width, ref height);
                        float num8 = ((float)target.width) / ((float)width);
                        HandleUtility.ApplyWireMaterial();
                        GL.PushMatrix();
                        GL.MultMatrix(Handles.matrix);
                        GL.Begin(1);
                        GL.Color(new Color(1f, 1f, 1f, 0.5f));
                        foreach (SpriteMetaData data in spritesheet)
                        {
                            Rect rect  = data.rect;
                            Rect rect5 = new Rect {
                                xMin = outScreenRect.xMin + (outScreenRect.width * ((rect.xMin / ((float)target.width)) * num8)),
                                xMax = outScreenRect.xMin + (outScreenRect.width * ((rect.xMax / ((float)target.width)) * num8)),
                                yMin = outScreenRect.yMin + (outScreenRect.height * (1f - ((rect.yMin / ((float)target.height)) * num8))),
                                yMax = outScreenRect.yMin + (outScreenRect.height * (1f - ((rect.yMax / ((float)target.height)) * num8)))
                            };
                            this.DrawRect(rect5);
                        }
                        GL.End();
                        GL.PopMatrix();
                    }
                }
                TextureUtil.SetMipMapBiasNoDirty(target, mipMapBias);
                TextureUtil.SetFilterModeNoDirty(target, filterMode);
                this.m_Pos = PreviewGUI.EndScrollView();
                if (mipLevelForRendering != 0f)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + mipLevelForRendering);
                }
            }
        }
Esempio n. 18
0
        public override void DrawInspector(Action changed)
        {
            // wrapMode
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Wrap Mode");

                var currentMode = this.wrapMode.ToString();

                if (GUILayout.Button(currentMode, "Popup"))
                {
                    var menu = new GenericMenu();
                    foreach (var item in Enum.GetValues(typeof(UnityEngine.TextureWrapMode)).Cast <UnityEngine.TextureWrapMode>().ToList())
                    {
                        var isCurrentChoose = false;
                        if (item == this.wrapMode)
                        {
                            isCurrentChoose = true;
                        }
                        var currentItem = item;

                        menu.AddItem(
                            new GUIContent(item.ToString()),
                            isCurrentChoose,
                            () => {
                            if (this.wrapMode != currentItem)
                            {
                                this.wrapMode = currentItem;
                                changed();
                            }
                        }
                            );
                    }
                    menu.ShowAsContext();
                }
            }

            // filterMode
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Filter Mode");

                var currentMode = this.filterMode.ToString();

                if (GUILayout.Button(currentMode, "Popup"))
                {
                    var menu = new GenericMenu();
                    foreach (var item in Enum.GetValues(typeof(UnityEngine.FilterMode)).Cast <UnityEngine.FilterMode>().ToList())
                    {
                        var isCurrentChoose = false;
                        if (item == this.filterMode)
                        {
                            isCurrentChoose = true;
                        }
                        var currentItem = item;

                        menu.AddItem(
                            new GUIContent(item.ToString()),
                            isCurrentChoose,
                            () => {
                            if (this.filterMode != currentItem)
                            {
                                this.filterMode = currentItem;
                                changed();
                            }
                        }
                            );
                    }
                    menu.ShowAsContext();
                }
            }

            // anisoLevel
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Aniso Level");

                var changedVal = (int)EditorGUILayout.Slider(this.anisoLevel, 0, 16);
                if (changedVal != this.anisoLevel)
                {
                    this.anisoLevel = changedVal;
                    changed();
                }
            }
            EditorGUILayout.HelpBox("Aniso Level can be set if target Asset(RenderTexture)'s Depth Buffer is No depth buffer. ", MessageType.Info);
        }
Esempio n. 19
0
        [SerializeField] public int anisoLevel;        // limit to 16.



        public RenderTextureModifier()
        {
            wrapMode   = TextureWrapMode.Clamp;
            filterMode = FilterMode.Bilinear;
            anisoLevel = 0;
        }
        public void OnInspectorGUI(Action onValueChanged)
        {
            // wrapMode
            var newWrapMode = (UnityEngine.TextureWrapMode)EditorGUILayout.Popup("Wrap Mode", (int)this.wrapMode, Enum.GetNames(typeof(UnityEngine.TextureWrapMode)), new GUILayoutOption[0]);
            if (newWrapMode != this.wrapMode) {
                this.wrapMode = newWrapMode;
                onValueChanged();
            }

            // filterMode
            var newFilterMode = (UnityEngine.FilterMode)EditorGUILayout.Popup("Filter Mode", (int)this.filterMode, Enum.GetNames(typeof(UnityEngine.FilterMode)), new GUILayoutOption[0]);
            if (newFilterMode != this.filterMode) {
                this.filterMode = newFilterMode;
                onValueChanged();
            }

            // anisoLevel
            using (new GUILayout.HorizontalScope()) {
                GUILayout.Label("Aniso Level");

                var changedVal = (int)EditorGUILayout.Slider(this.anisoLevel, 0, 16);
                if (changedVal != this.anisoLevel) {
                    this.anisoLevel = changedVal;
                    onValueChanged();
                }
            }
            EditorGUILayout.HelpBox("Aniso Level can be set only when RenderTexture does not have depth buffer.", MessageType.Info);
        }
        public void ObjectPreview(Rect r)
        {
            if (r.height > 0f)
            {
                if (s_Styles == null)
                {
                    s_Styles = new Styles();
                }
                List <Texture2D> list = new List <Texture2D>();
                foreach (GITextureType type in this.kObjectPreviewTextureTypes)
                {
                    list.Add(LightmapVisualizationUtility.GetGITexture(type));
                }
                if (list.Count != 0)
                {
                    Rect rect3;
                    Rect rect9;
                    if (this.m_ZoomablePreview == null)
                    {
                        this.m_ZoomablePreview           = new ZoomableArea(true);
                        this.m_ZoomablePreview.hRangeMin = 0f;
                        this.m_ZoomablePreview.vRangeMin = 0f;
                        this.m_ZoomablePreview.hRangeMax = 1f;
                        this.m_ZoomablePreview.vRangeMax = 1f;
                        this.m_ZoomablePreview.SetShownHRange(0f, 1f);
                        this.m_ZoomablePreview.SetShownVRange(0f, 1f);
                        this.m_ZoomablePreview.uniformScale    = true;
                        this.m_ZoomablePreview.scaleWithWindow = true;
                    }
                    GUI.Box(r, string.Empty, "PreBackground");
                    Rect position = new Rect(r);
                    position.y++;
                    position.height = 18f;
                    GUI.Box(position, string.Empty, EditorStyles.toolbar);
                    Rect rect2 = new Rect(r);
                    rect2.y++;
                    rect2.height = 18f;
                    rect2.width  = 120f;
                    rect3        = new Rect(r)
                    {
                        yMin  = rect3.yMin + rect2.height,
                        yMax  = rect3.yMax - 14f,
                        width = rect3.width - 11f
                    };
                    int index = Array.IndexOf <GUIContent>(kObjectPreviewTextureOptions, this.m_SelectedObjectPreviewTexture);
                    if (index < 0)
                    {
                        index = 0;
                    }
                    index = EditorGUI.Popup(rect2, index, kObjectPreviewTextureOptions, EditorStyles.toolbarPopup);
                    if (index >= kObjectPreviewTextureOptions.Length)
                    {
                        index = 0;
                    }
                    this.m_SelectedObjectPreviewTexture = kObjectPreviewTextureOptions[index];
                    LightmapType       lightmapType = ((this.kObjectPreviewTextureTypes[index] != GITextureType.Baked) && (this.kObjectPreviewTextureTypes[index] != GITextureType.BakedDirectional)) ? LightmapType.DynamicLightmap : LightmapType.StaticLightmap;
                    SerializedProperty property     = new SerializedObject(LightmapEditorSettings.GetLightmapSettings()).FindProperty("m_LightmapsMode");
                    bool flag = ((this.kObjectPreviewTextureTypes[index] == GITextureType.Baked) || (this.kObjectPreviewTextureTypes[index] == GITextureType.BakedDirectional)) && (property.intValue == 2);
                    if (flag)
                    {
                        GUIContent content = GUIContent.Temp("Indirect");
                        Rect       rect4   = rect2;
                        rect4.x    += rect2.width;
                        rect4.width = EditorStyles.toolbarButton.CalcSize(content).x;
                        this.m_HasSeparateIndirectUV = GUI.Toggle(rect4, this.m_HasSeparateIndirectUV, content.text, EditorStyles.toolbarButton);
                    }
                    switch (Event.current.type)
                    {
                    case EventType.ValidateCommand:
                    case EventType.ExecuteCommand:
                        if (Event.current.commandName == "FrameSelected")
                        {
                            Rect    rect5;
                            Vector4 lightmapTilingOffset = LightmapVisualizationUtility.GetLightmapTilingOffset(lightmapType);
                            Vector2 lhs     = new Vector2(lightmapTilingOffset.z, lightmapTilingOffset.w);
                            Vector2 vector3 = lhs + new Vector2(lightmapTilingOffset.x, lightmapTilingOffset.y);
                            lhs     = Vector2.Max(lhs, Vector2.zero);
                            vector3 = Vector2.Min(vector3, Vector2.one);
                            float num3 = 1f - lhs.y;
                            lhs.y     = 1f - vector3.y;
                            vector3.y = num3;
                            rect5     = new Rect(lhs.x, lhs.y, vector3.x - lhs.x, vector3.y - lhs.y)
                            {
                                x = rect5.x - (Mathf.Clamp(rect5.height - rect5.width, 0f, float.MaxValue) / 2f),
                                y = rect5.y - (Mathf.Clamp(rect5.width - rect5.height, 0f, float.MaxValue) / 2f)
                            };
                            float num5 = Mathf.Max(rect5.width, rect5.height);
                            rect5.height = num5;
                            rect5.width  = num5;
                            if (flag && this.m_HasSeparateIndirectUV)
                            {
                                rect5.x += 0.5f;
                            }
                            this.m_ZoomablePreview.shownArea = rect5;
                            Event.current.Use();
                        }
                        break;

                    case EventType.Repaint:
                    {
                        Texture2D texture = list[index];
                        if ((texture != null) && (Event.current.type == EventType.Repaint))
                        {
                            Rect rect7;
                            Rect rect8;
                            Rect rect = new Rect(0f, 0f, (float)texture.width, (float)texture.height);
                            rect  = this.ResizeRectToFit(rect, rect3);
                            rect  = this.CenterToRect(rect, rect3);
                            rect  = this.ScaleRectByZoomableArea(rect, this.m_ZoomablePreview);
                            rect7 = new Rect(rect)
                            {
                                x = rect7.x + 3f,
                                y = rect7.y + (rect3.y + 20f)
                            };
                            rect8 = new Rect(rect3)
                            {
                                y = rect8.y + (rect2.height + 3f)
                            };
                            float num4 = rect8.y - 14f;
                            rect7.y -= num4;
                            rect8.y -= num4;
                            UnityEngine.FilterMode filterMode = texture.filterMode;
                            texture.filterMode = UnityEngine.FilterMode.Point;
                            GITextureType textureType    = this.kObjectPreviewTextureTypes[index];
                            bool          drawSpecularUV = flag && this.m_HasSeparateIndirectUV;
                            LightmapVisualizationUtility.DrawTextureWithUVOverlay(texture, Selection.activeGameObject, rect8, rect7, textureType, drawSpecularUV);
                            texture.filterMode = filterMode;
                        }
                        break;
                    }
                    }
                    if (this.m_PreviousSelection != Selection.activeInstanceID)
                    {
                        this.m_PreviousSelection = Selection.activeInstanceID;
                        this.m_ZoomablePreview.SetShownHRange(0f, 1f);
                        this.m_ZoomablePreview.SetShownVRange(0f, 1f);
                    }
                    rect9 = new Rect(r)
                    {
                        yMin = rect9.yMin + rect2.height
                    };
                    this.m_ZoomablePreview.rect = rect9;
                    this.m_ZoomablePreview.BeginViewGUI();
                    this.m_ZoomablePreview.EndViewGUI();
                    GUILayoutUtility.GetRect(r.width, r.height);
                }
            }
        }
 public RenderTextureModifier()
 {
     wrapMode = TextureWrapMode.Clamp;
     filterMode = FilterMode.Bilinear;
     anisoLevel = 0;
 }