playMaker

Author Topic: [SOLVED] Implementing Depth into GUITexture?  (Read 3625 times)

kiriri

  • Hero Member
  • *****
  • Posts: 506
[SOLVED] Implementing Depth into GUITexture?
« on: May 20, 2012, 01:20:02 PM »
Hi, I'm in a terrible struggle with the GUITexture action :D . I want it to define its depth too, but for some reason it's not working. I had to use a real int and not an FSMint because the FSMint gave me an error, stating that it couldn't be converted to a normal int.  If I knew how to convert it I would have done so though :D
So in the end all I could do is define the depth int and then use it... I don't understand why it isn't working :S

Quote
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
   [ActionCategory(ActionCategory.GUI)]
   [Tooltip("Draws a GUI Texture. NOTE: Uses OnGUI so you need a PlayMakerGUI component in the scene.")]
   public class DrawTexture : FsmStateAction
   {
      [RequiredField]
      public FsmTexture texture;
      
      [UIHint(UIHint.Variable)]
      [Tooltip("Rectangle on the screen to draw the texture within. Alternatively, set or override individual properties below.")]
      [Title("Position")]
      public FsmRect screenRect;
      
      public FsmFloat left;
      public FsmFloat top;
      public FsmFloat width;
      public FsmFloat height;
      
      public int depth;

      [Tooltip("How to scale the image when the aspect ratio of it doesn't fit the aspect ratio to be drawn within.")]
      public ScaleMode scaleMode;
   
      [Tooltip("Whether to alpha blend the image on to the display (the default). If false, the picture is drawn on to the display.")]
      public FsmBool alphaBlend;
      
      [Tooltip("Aspect ratio to use for the source image. If 0 (the default), the aspect ratio from the image is used. Pass in w/h for the desired aspect ratio. This allows the aspect ratio of the source image to be adjusted without changing the pixel width and height.")]
      public FsmFloat imageAspect;
      
      [Tooltip("Use normalized screen coordinates (0-1)")]
      public FsmBool normalized;

      private Rect rect;
      
      public override void Reset()
      {
         texture = null;
         screenRect = null;
         left = 0;
         top = 0;
         width = 1;
         height = 1;
         scaleMode = ScaleMode.StretchToFill;
         alphaBlend = true;
         imageAspect = 0;
         normalized = true;
         depth = 0;
      }

      public override void OnGUI()
      {
         if (texture.Value == null)
         {
            return;
         }
         
         rect = !screenRect.IsNone ? screenRect.Value : new Rect();
         
         if (!left.IsNone) rect.x = left.Value;
         if (!top.IsNone) rect.y = top.Value;
         if (!width.IsNone) rect.width = width.Value;
         if (!height.IsNone) rect.height = height.Value;
         
         if (normalized.Value)
         {
            rect.x *= Screen.width;
            rect.width *= Screen.width;
            rect.y *= Screen.height;
            rect.height *= Screen.height;
         }
         GUI.depth = depth;
         GUI.DrawTexture(rect, texture.Value, scaleMode, alphaBlend.Value, imageAspect.Value);
      }
   }
}

could anyone spare a short moment for my ignorance?
« Last Edit: May 21, 2012, 01:43:06 PM by Alex Chouls »
Best,
Sven

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Implementing Depth into GUITexture?
« Reply #1 on: May 20, 2012, 02:00:58 PM »
Unfortunately GUI.depth doesn't currently work with PlayMakerGUI optimizations.

This problem is discussed more here:
http://hutonggames.com/playmakerforum/index.php?topic=1492.0

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Implementing Depth into GUITexture?
« Reply #2 on: May 20, 2012, 04:00:59 PM »
oh, that poses a big problem then... Is there a way to implement an option to revert to the old GUI system (multiple GUIs, like having a checkbox to switch between the optimized and old way?)
Best,
Sven

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 4002
  • Official Playmaker Support
    • LinkedIn
Re: Implementing Depth into GUITexture?
« Reply #3 on: May 20, 2012, 04:12:35 PM »
I'm exploring a solution in the beta for 1.4.1. I'll send you an invite...

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Implementing Depth into GUITexture?
« Reply #4 on: May 20, 2012, 04:35:33 PM »
that would be great, thanks !
Best,
Sven