Exemplo n.º 1
0
    // ParseeTargetFolder
    #endregion

    #region CreateOutputPrefab

    /// <summary>
    /// Create the output prefab
    /// </summary>
    private void CreateOutputPrefab()
    {
        // create the output folder if we don't have one already
        string OutputFolder = string.Format("{0}/Output/", PsdApplicationFolder);

        if (!Directory.Exists(OutputFolder))
        {
            Directory.CreateDirectory(OutputFolder);
        }
        AssetDatabase.Refresh();

        // create an empty prefab to hold everything
        string AssetPrefabPath = string.Format("{0}/Output/PsdImportedOutput.prefab", PsdAssetFolderPath);
        Object EmptyPrefab     = PrefabUtility.CreateEmptyPrefab(AssetPrefabPath);

        // Create a new game object for the atlas
        GameObject go = new GameObject("PsdImportedOutput");

        go.AddComponent <PsdImportedOutput>();

        // Update the prefab
        PrefabUtility.ReplacePrefab(go, EmptyPrefab);

        // remove from the scene, save and refresh
        DestroyImmediate(go);
        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();

        // load asset into the object
        ActualOutput            = AssetDatabase.LoadAssetAtPath(AssetPrefabPath, typeof(PsdImportedOutput)) as PsdImportedOutput;
        ActualOutput.references = new Dictionary <int, int>();
    }
Exemplo n.º 2
0
 /// <summary>
 /// Resets all variables
 /// </summary>
 private void ResetVariables()
 {
     // clear ngui settings
     NGUISettings.SetString(NSettingsAtlasName, string.Empty);
     ActualOutput             = null;
     NGUISettings.atlas       = null;
     NGUISettings.fontData    = null;
     NGUISettings.fontTexture = null;
     TargetAtlas  = null;
     SourceFolder = string.Empty;
 }
Exemplo n.º 3
0
    // CreateProgressbar
    #endregion

    #region CreateSlicedSprite

    /// <summary>
    /// Creates a sliced sprite
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static void CreateSlicedSprite(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        GameObject NewSprite = CreateSprite(xmlNode, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput, targetWidth, targetHeight, psdAssetFolderPath);

        // set to sliced
        if (NewSprite != null)
        {
            NewSprite.GetComponent <UISprite>().type = UISprite.Type.Sliced;
        }
    }
Exemplo n.º 4
0
    // CreateSlider
    #endregion

    #region CreateProgressbar

    /// <summary>
    /// Creates a progressbar
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static void CreateProgressbar(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // create the base GO
        GameObject NewGO = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);

        // add the slider to the parent
        UIProgressBar ProgressGO = NewGO.AddComponent <UIProgressBar>();

        // add a sprite to the parent
        UISprite BackgroundSprite = AddSpriteToGo(NewGO, psdAssetFolderPath, WidgetInfo.Background, targetRootPanel, WidgetInfo.PosX, WidgetInfo.PosY, targetWidth, targetHeight);

        // fail if nothing returned
        if (BackgroundSprite == null)
        {
            Debug.LogWarning(string.Format("Could not load sprite: '{0}' with file name '{1}'", WidgetInfo.Name, WidgetInfo.Background));
            return;
        }

        // add the box collider
        NGUITools.AddWidgetCollider(NewGO);


        // create the foreground child object
        UISprite ForegroundChild = CreateChildSprite(
            NewGO,
            string.Format("{0} - Foreground", WidgetInfo.Name),
            psdAssetFolderPath,
            WidgetInfo.Foreground,
            targetRootPanel,
            WidgetInfo.PosX,
            WidgetInfo.PosY,
            targetWidth,
            targetHeight);

        // fail if nothing returned
        if (ForegroundChild == null)
        {
            Debug.LogWarning(string.Format("Could not load sprite: '{0}' with file name '{1}'", WidgetInfo.Name, WidgetInfo.Foreground));
            return;
        }


        // set slider properties
        ProgressGO.backgroundWidget = BackgroundSprite;
        ProgressGO.foregroundWidget = ForegroundChild;
    }
Exemplo n.º 5
0
    // AddTexture2DToAtlas
    #endregion

    #region CreateNguiChildBaseGo

    /// <summary>
    /// Creates a game object to hold all the child components
    /// </summary>
    /// <param name="widgetInfo"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="actualOutput"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <returns></returns>
    private static GameObject CreateNguiChildBaseGo(XmlWidgetInfo widgetInfo, float targetWidth, float targetHeight, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput)
    {
        // get the last root
        Transform lastRoot = targetRootPanel.transform;

        if (widgetInfo.ParentName.Equals(lastAnchorPath))
        {
            lastRoot = lastAnchor;
        }
        else
        {
            if (targetRootPanel.transform.FindChild(widgetInfo.ParentName))
            {
                lastRoot = targetRootPanel.transform.FindChild(widgetInfo.ParentName);
            }
        }

        GameObject NewGo = new GameObject(widgetInfo.Name);

        NewGo.transform.parent     = lastRoot;
        NewGo.transform.position   = AdjustPosition(widgetInfo.PosX, widgetInfo.PosY, targetWidth, targetHeight, targetRootPanel);
        NewGo.transform.localScale = Vector3.one;
        NewGo.layer = NewGo.transform.parent.gameObject.layer;
        actualOutput.references.Add(widgetInfo.LayerID, NewGo.GetInstanceID());

        // return the new object
        return(NewGo);
    }
Exemplo n.º 6
0
    // CreateEmptyPanel
    #endregion

    #region CreateCheckbox

    /// <summary>
    /// Creates a checkbox
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static void CreateCheckBox(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // create the base GO
        GameObject NewGO = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);

        // Create checkbox
        UIToggle NewToggle = NewGO.AddComponent <UIToggle>();

        // Create an atlas if one does not exist
        if (NGUISettings.atlas == null)
        {
            NGUISettings.atlas = PsdAtlasManager.CreateNewAtlas(psdAssetFolderPath);
        }

        // load the image
        UISpriteData WorkingSprite = GetSpriteData(psdAssetFolderPath, WidgetInfo.Background);

        if (WorkingSprite == null)
        {
            Debug.LogWarning(string.Format("Could not load sprite: '{0}' with file name '{1}'", WidgetInfo.Name, WidgetInfo.ImagePath));
            return;
        }

        // add a sprite
        UISprite SpriteWidget = NewGO.AddComponent <UISprite>();

        SpriteWidget.atlas                = NGUISettings.atlas;
        SpriteWidget.spriteName           = WorkingSprite.name;
        SpriteWidget.pivot                = NGUISettings.pivot;
        SpriteWidget.depth                = NGUITools.CalculateNextDepth(targetRootPanel.gameObject);
        SpriteWidget.transform.localScale = Vector3.one;
        SpriteWidget.transform.position   = AdjustPosition(WidgetInfo.PosX, WidgetInfo.PosY, targetWidth, targetHeight, targetRootPanel);
        SpriteWidget.width                = WorkingSprite.width;
        SpriteWidget.height               = WorkingSprite.height;
        SpriteWidget.MakePixelPerfect();

        // create a child sprite to hold the Checked state
        UISprite ChildSpriteWidget = CreateChildSprite(
            NewGO,
            string.Format("{0} - Checked Sprite", NewGO.name),
            psdAssetFolderPath,
            WidgetInfo.Checkmark,
            targetRootPanel,
            WidgetInfo.PosX,
            WidgetInfo.PosY,
            targetWidth,
            targetHeight);

        // fail if nothing returned
        if (ChildSpriteWidget == null)
        {
            Debug.LogWarning(string.Format("Could not load sprite: '{0}' with file name '{1}'", WidgetInfo.Name, WidgetInfo.ImagePath));
            return;
        }

        // set the toggle sprite
        NewToggle.activeSprite = ChildSpriteWidget;

        // add the box collider
        NGUITools.AddWidgetCollider(NewGO);
    }
Exemplo n.º 7
0
    // CreateEmptyWidget
    #endregion

    #region CreateEmptyPanel

    /// <summary>
    /// Creates an empty panel
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static GameObject CreateEmptyPanel(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // create the base GO
        GameObject NewGo = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);

        // add a panel
        UIPanel Panel = NewGo.AddComponent <UIPanel>();

        Panel.name  = string.Format("Panel - {0}", WidgetInfo.Name);
        Panel.depth = NGUITools.CalculateNextDepth(targetRootPanel.gameObject);
        Panel.transform.localScale    = Vector3.one;
        Panel.transform.localPosition = Vector3.zero; // position = AdjustPosition(WidgetInfo.PosX, WidgetInfo.PosY, targetWidth, targetHeight, targetRootPanel);

        // return the new widget
        return(NewGo);
    }
Exemplo n.º 8
0
    // CreateSprite
    #endregion

    #region CreateEmptyWidget

    /// <summary>
    /// Creates an empty widget
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static GameObject CreateEmptyWidget(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // create the base GO
        GameObject NewGo = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);

        // add a widget
        UIWidget Widget = NewGo.AddComponent <UIWidget>();

        Widget.name  = string.Format("Widget - {0}", WidgetInfo.Name);
        Widget.pivot = NGUISettings.pivot;
        Widget.depth = NGUITools.CalculateNextDepth(targetRootPanel.gameObject);
        Widget.transform.localScale = Vector3.one;
        Widget.transform.position   = AdjustPosition(WidgetInfo.PosX, WidgetInfo.PosY, targetWidth, targetHeight, targetRootPanel);
        Widget.width  = WidgetInfo.SpriteWidth;
        Widget.height = WidgetInfo.SpriteHeight;

        // return the new widget
        return(NewGo);
    }
Exemplo n.º 9
0
    // CreateInputLabel
    #endregion

    #region CreateSprite

    /// <summary>
    /// Creates a sprite
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    /// <returns></returns>
    public static GameObject CreateSprite(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // create the base GO
        GameObject NewGo = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);

        // Create an atlas if one does not exist
        if (NGUISettings.atlas == null)
        {
            NGUISettings.atlas = PsdAtlasManager.CreateNewAtlas(psdAssetFolderPath);
        }

        // load the image
        UISpriteData WorkingSprite = GetSpriteData(psdAssetFolderPath, WidgetInfo.ImagePath);

        if (WorkingSprite == null)
        {
            Debug.LogWarning(string.Format("Could not load sprite: '{0}' with file name '{1}'", WidgetInfo.Name, WidgetInfo.ImagePath));
            return(null);
        }

        // add a sprite
        UISprite SpriteWidget = NewGo.AddComponent <UISprite>();

        SpriteWidget.name                 = string.Format("Sprite - {0}", WidgetInfo.Name);
        SpriteWidget.atlas                = NGUISettings.atlas;
        SpriteWidget.spriteName           = WorkingSprite.name;
        SpriteWidget.pivot                = NGUISettings.pivot;
        SpriteWidget.depth                = NGUITools.CalculateNextDepth(targetRootPanel.gameObject);
        SpriteWidget.transform.localScale = Vector3.one;
        SpriteWidget.transform.position   = AdjustPosition(WidgetInfo.PosX, WidgetInfo.PosY, targetWidth, targetHeight, targetRootPanel);
        SpriteWidget.width                = WorkingSprite.width;
        SpriteWidget.height               = WorkingSprite.height;

        // check if this is a background sprite (size = psd)
        if ((targetWidth.Equals(WidgetInfo.SpriteWidth)) && (targetHeight.Equals(WidgetInfo.SpriteHeight)))
        {
            SpriteWidget.SetAnchor(NewGo.transform.parent.gameObject, 0, 0, 0, 0);
        }

        SpriteWidget.MakePixelPerfect();

        return(NewGo);
    }
Exemplo n.º 10
0
    // CreateTextLabel
    #endregion

    #region CreateInputLabel

    /// <summary>
    /// Creates an input label
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    public static void CreateInputLabel(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // create the label
        GameObject LabelGO  = CreateTextLabel(xmlNode, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput, targetWidth, targetHeight, psdAssetFolderPath);
        UILabel    TheLabel = LabelGO.GetComponent <UILabel>();

        // add input
        UIInput NewInputLabel = LabelGO.AddComponent <UIInput>();

        NewInputLabel.label           = TheLabel;
        NewInputLabel.activeTextColor = TheLabel.color;

        // add the box collider
        NGUITools.AddWidgetCollider(LabelGO);
    }
Exemplo n.º 11
0
    // CreateImageButton
    #endregion

    #region CreateTextLabel

    /// <summary>
    /// Creates a text label
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="psdAssetFolderPath"></param>
    /// <param name="targetHeight"></param>
    /// <param name="targetWidth"></param>
    public static GameObject CreateTextLabel(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // create the base GO
        GameObject LabelGO = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);

        // rename the Label
        LabelGO.name = WidgetInfo.LabelName;

        // Create Label:
        UILabel NewLabel = LabelGO.AddComponent <UILabel>();

        string[] FontColor = WidgetInfo.FontColor.Split(';');
        NewLabel.color          = new Color(float.Parse(FontColor[0]) / 255f, float.Parse(FontColor[1]) / 255f, float.Parse(FontColor[2]) / 255f);
        NewLabel.bitmapFont     = GetFont(WidgetInfo.FontName);
        NewLabel.overflowMethod = UILabel.Overflow.ResizeFreely;
        NewLabel.text           = WidgetInfo.TextContent;
        NewLabel.depth          = NGUITools.CalculateNextDepth(targetRootPanel.gameObject);
        NewLabel.pivot          = UIWidget.Pivot.Center;

        NewLabel.MakePixelPerfect();
        return(LabelGO);
    }
Exemplo n.º 12
0
    // CreateClippingPlane
    #endregion

    #region CreateImageButton

    /// <summary>
    /// Creates an image button
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetWidth"></param>
    /// <param name="targetHeight"></param>
    /// <param name="psdAssetFolderPath"></param>
    /// <returns></returns>
    public static GameObject CreateImageButton(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, string psdAssetFolderPath)
    {
        // get the widget info
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // Create an atlas if one does not exist
        if (NGUISettings.atlas == null)
        {
            NGUISettings.atlas = PsdAtlasManager.CreateNewAtlas(psdAssetFolderPath);
        }

        // get the button pressed states
        Dictionary <EButtonState, string> ButtonStatesDict = new Dictionary <EButtonState, string>();

        if (!string.IsNullOrEmpty(WidgetInfo.ButtonPressedState))
        {
            ButtonStatesDict.Add(EButtonState.Pressed, WidgetInfo.ButtonPressedState);
        }
        if (!string.IsNullOrEmpty(WidgetInfo.ButtonIdleState))
        {
            ButtonStatesDict.Add(EButtonState.Idle, WidgetInfo.ButtonIdleState);
        }
        if (!string.IsNullOrEmpty(WidgetInfo.ButtonHoverState))
        {
            ButtonStatesDict.Add(EButtonState.Hover, WidgetInfo.ButtonHoverState);
        }
        if (!string.IsNullOrEmpty(WidgetInfo.ButtonDisabledState))
        {
            ButtonStatesDict.Add(EButtonState.Disabled, WidgetInfo.ButtonDisabledState);
        }

        // create the button
        GameObject    NewGo          = CreateNguiChildBaseGo(WidgetInfo, targetWidth, targetHeight, targetRootPanel, lastAnchor, lastAnchorPath, actualOutput);
        UIImageButton NewImageButton = NewGo.AddComponent <UIImageButton>();

        // add the UISprite widget
        UISprite SpriteWidget = NewGo.AddComponent <UISprite>();

        SpriteWidget.atlas = NGUISettings.atlas;
        SpriteWidget.pivot = NGUISettings.pivot;
        SpriteWidget.depth = NGUITools.CalculateNextDepth(targetRootPanel.gameObject);

        SpriteWidget.MakePixelPerfect();
        NGUITools.AddWidgetCollider(NewImageButton.gameObject);
        NewImageButton.target = SpriteWidget;


        // set the UIImage button sprites
        bool WidthHeightSet = false;

        foreach (EButtonState ButtonKey in ButtonStatesDict.Keys)
        {
            // get the sprite, add to atlas if null
            UISpriteData ButtonSprite = GetSpriteData(psdAssetFolderPath, ButtonStatesDict[ButtonKey]);
            if (ButtonSprite == null)
            {
                continue;
            }

            // set sprite for the image button
            switch (ButtonKey)
            {
            case EButtonState.Idle:
                NewImageButton.normalSprite = ButtonSprite.name;
                break;

            case EButtonState.Pressed:
                NewImageButton.pressedSprite = ButtonSprite.name;
                break;

            case EButtonState.Hover:
                NewImageButton.hoverSprite = ButtonSprite.name;
                break;

            case EButtonState.Disabled:
                NewImageButton.disabledSprite = ButtonSprite.name;
                break;
            }

            // set dimensions, if not already set
            // NOTE: we check first, because setting the width/height performs a lot of calcs and redraws, so it's best to only set once
            if (!WidthHeightSet)
            {
                WidthHeightSet      = true;
                SpriteWidget.width  = ButtonSprite.width;
                SpriteWidget.height = ButtonSprite.height;
            }
        }

        // set the normal sprite
        SpriteWidget.spriteName = NewImageButton.normalSprite;

        return(NewGo);
    }
Exemplo n.º 13
0
    // CreateAnchor
    #endregion

    #region CreateClippingPlane

    /// <summary>
    /// Creates a clipping plane
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetHeight"></param>
    /// <param name="targetWidth"></param>
    /// <returns></returns>
    public static Transform CreateClippingPanel(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight)
    {
        // get the XML properties
        XmlWidgetInfo WidgetInfo = new XmlWidgetInfo(xmlNode);

        // get the anchor panel
        Transform NewContainer = CreateAnchor(targetRootPanel, lastAnchor, lastAnchorPath, actualOutput, targetWidth, targetHeight, WidgetInfo);

        // create a new panel
        UIPanel NewPanel = NewContainer.gameObject.AddComponent <UIPanel>();

        NewPanel.clipping       = UIDrawCall.Clipping.SoftClip;
        NewPanel.baseClipRegion = new Vector4(0, 0, WidgetInfo.ClipX, WidgetInfo.ClipY);
        NewPanel.clipSoftness   = new Vector2(5, 5);

        return(NewContainer);
    }
Exemplo n.º 14
0
    /// <summary>
    /// Creates an anchor
    /// </summary>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetHeight"></param>
    /// <param name="targetWidth"></param>
    /// <param name="widgetInfo"></param>
    /// <returns></returns>
    public static Transform CreateAnchor(UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight, XmlWidgetInfo widgetInfo)
    {
        Transform lastRoot = targetRootPanel.transform;

        if (widgetInfo.ParentName == lastAnchorPath)
        {
            lastRoot = lastAnchor;
        }
        else
        {
            if (targetRootPanel.transform.FindChild(widgetInfo.ParentName))
            {
                lastRoot = targetRootPanel.transform.FindChild(widgetInfo.ParentName);
            }
        }

        GameObject NewGO;

        if (actualOutput.references.ContainsKey(widgetInfo.LayerID))
        {
            NewGO = EditorUtility.InstanceIDToObject(actualOutput.references[widgetInfo.LayerID]) as GameObject;
            if (NewGO == null)
            {
                actualOutput.references.Remove(widgetInfo.LayerID);
                return(CreateAnchor(targetRootPanel, lastAnchor, lastAnchorPath, actualOutput, targetWidth, targetHeight, widgetInfo));
            }
        }
        else
        {
            NewGO = new GameObject(widgetInfo.Name);
            actualOutput.references.Add(widgetInfo.LayerID, NewGO.GetInstanceID());
        }


        // adjust position and scale
        NewGO.transform.parent     = lastRoot;
        NewGO.transform.position   = AdjustPosition(widgetInfo.PosX, widgetInfo.PosY, targetWidth, targetHeight, targetRootPanel);
        NewGO.transform.localScale = Vector3.one;

        return(NewGO.transform);
    }
Exemplo n.º 15
0
    // CreateChildSprite
    #endregion

    #region CreateAnchor

    /// <summary>
    /// Creates an anchor
    /// </summary>
    /// <param name="xmlNode"></param>
    /// <param name="targetRootPanel"></param>
    /// <param name="lastAnchor"></param>
    /// <param name="lastAnchorPath"></param>
    /// <param name="actualOutput"></param>
    /// <param name="targetHeight"></param>
    /// <param name="targetWidth"></param>
    /// <returns></returns>
    public static Transform CreateAnchor(XMLNode xmlNode, UIPanel targetRootPanel, Transform lastAnchor, string lastAnchorPath, PsdImportedOutput actualOutput, float targetWidth, float targetHeight)
    {
        // create a new widget info and use that
        return(CreateAnchor(targetRootPanel, lastAnchor, lastAnchorPath, actualOutput, targetWidth, targetHeight, new XmlWidgetInfo(xmlNode)));
    }
Exemplo n.º 16
0
    // OnEnable
    #endregion

    #region OnGUI

    /// <summary>
    /// Draw the window
    /// </summary>
    void OnGUI()
    {
        // header
        GUILayout.Label(STR_FastGUIName, EditorStyles.boldLabel);

        // draw a line
        DrawSeparator();

        #region PSD_Folder

        // PSD folder
        GUILayout.BeginHorizontal();
        GUILayout.Label(STR_ImportedPSDFolder);
        ObjPSDFolderToLoad = EditorGUILayout.ObjectField(ObjPSDFolderToLoad, typeof(Object), false);

        // confirm an XML file exists in the folder, if not, then reset object to null
        if ((ObjPSDFolderToLoad != null) && (AssetDatabase.GetAssetPath(ObjPSDFolderToLoad).IndexOf(".xml") > -1))
        {
            ObjPSDFolderToLoad = null;
        }

        PsdAssetFolderPath   = AssetDatabase.GetAssetPath(ObjPSDFolderToLoad);
        PsdApplicationFolder = applicationDataPath + PsdAssetFolderPath;
        GUILayout.EndHorizontal();

        // PSD_Folder
        #endregion

        #region Atlas_Images_Source_Test

        // check if the folder has an existing atlas (it was previously imported)
        GUILayout.BeginVertical();
        if ((PsdApplicationFolder != null) && (LastFolderChecked != PsdApplicationFolder))
        {
            ResetVariables();

            // check if we have an existing "output" folder
            string OutputFolder = string.Format("{0}{1}", PsdApplicationFolder, STR_OutputPath);
            if (Directory.Exists(OutputFolder))
            {
                if (Directory.GetFiles(OutputFolder, STR_PsdImportedOutputprefab, SearchOption.TopDirectoryOnly).Length > 0)
                {
                    ActualOutput = AssetDatabase.LoadAssetAtPath(string.Format("{0}{1}{2}", PsdAssetFolderPath, STR_OutputPath, STR_PsdImportedOutputprefab), typeof(PsdImportedOutput)) as PsdImportedOutput;
                }
            }

            // check if we have a source folder
            string SourceFolder = string.Format("{0}{1}", PsdApplicationFolder, STR_SourcePath);
            if ((Directory.Exists(SourceFolder)) && (ObjPSDFolderToLoad != null))
            {
                STR_ObjPSDFolderToLoadPrefab = string.Format("{0}.prefab", ObjPSDFolderToLoad.name);
                if (Directory.GetFiles(SourceFolder, STR_ObjPSDFolderToLoadPrefab, SearchOption.TopDirectoryOnly).Length > 0)
                {
                    TargetAtlas = AssetDatabase.LoadAssetAtPath(string.Format("{0}{1}", SourceFolder, STR_ObjPSDFolderToLoadPrefab), typeof(UIAtlas)) as UIAtlas;
                }
            }

            // check if we have an images folder
            string ImagesFolder = string.Format("{0}{1}", PsdApplicationFolder, STR_ImagesPath);
            if (Directory.Exists(ImagesFolder))
            {
                HasImagesFolder = (Directory.GetFiles(ImagesFolder, "*.png", SearchOption.TopDirectoryOnly).Length > 0);
            }
            else
            {
                HasImagesFolder = false;
            }

            // set last flags
            LastFolderChecked = PsdApplicationFolder;
            HasXMLFile        = CheckHasXML();
        }
        GUILayout.EndVertical();

        // Atlas_Images_Source_Test
        #endregion

        #region Parent_Panel

        // UIPanel setup
        GUILayout.BeginHorizontal();
        GUILayout.Label(STR_ParentPanel);
        TargetNguiPanel = EditorGUILayout.ObjectField(TargetNguiPanel, typeof(UIPanel), true) as UIPanel;
        GUILayout.EndHorizontal();

        // set flag for has panel
        HasTargetPanel = (TargetNguiPanel != null);

        // get the panel's root
        if ((HasTargetPanel) && ((LastCheckedNguiRootPanel != TargetNguiPanel) || (TargetUIRoot == null)))
        {
            // set last checked
            LastCheckedNguiRootPanel = TargetNguiPanel;

            // get the UIRoot of the panel
            TargetUIRoot = (TargetNguiPanel != null) ?
                           GetUIRoot(TargetNguiPanel.gameObject) :
                           null;

            HasRoot = (TargetUIRoot != null);
        }

        // Parent_Panel
        #endregion

        #region Target_Atlas

        GUILayout.BeginHorizontal();
        GUILayout.Label(STR_TargetAtlas);
        TargetAtlas = EditorGUILayout.ObjectField(TargetAtlas, typeof(UIAtlas), false) as UIAtlas;
        GUILayout.EndHorizontal();

        // Target_Atlas
        #endregion

        #region Font_Folder

        // Font folder
        GUILayout.BeginHorizontal();
        GUILayout.Label(STR_FontsPrefabFolder);
        ObjFontFolder = EditorGUILayout.ObjectField(ObjFontFolder, typeof(Object), false);

        // confirm we have prefabs in the folder
        if ((ObjFontFolder != null) && (AssetDatabase.GetAssetPath(ObjFontFolder).IndexOf(".prefab") > -1))
        {
            ObjFontFolder = null;
        }

        // set path strings
        if (ObjFontFolder != null)
        {
            FontAssetFolderPath   = AssetDatabase.GetAssetPath(ObjFontFolder);
            FontApplicationFolder = applicationDataPath + FontAssetFolderPath;
        }

        GUILayout.EndHorizontal();

        // Font_Folder
        #endregion

        #region Debug_Checkbox

        // Debug button

        // draw a line
        DrawSeparator();

        GUILayout.BeginHorizontal();
        GUILayout.Label("Write Debug Info to Console:");
        DebugOutput = EditorGUILayout.Toggle(DebugOutput);

        GUILayout.EndHorizontal();

        // Debug_Checkbox
        #endregion

        #region Action_Buttons

        GUILayout.Space(10);

        // when true, the UIRoot has the same dimensions as the the PSD
        bool IsRootSized = false;

        // if we have a root and folder, then confirm the root height matches the PSD
        if ((TargetUIRoot != null) && (ObjPSDFolderToLoad != null))
        {
            IsRootSized = (TargetUIRoot.manualHeight == PsdHeight && TargetUIRoot.minimumHeight >= PsdHeight);

            if (!IsRootSized)
            {
                GUI.backgroundColor = new Color(171f / 255, 26f / 255, 37f / 255, 1);
                if (GUILayout.Button(STR_UpdateTheUIRoot))
                {
                    UpdateUIRootSize();
                }
                GUI.backgroundColor = GuiBkgColor;
            }
        }

        if (HasXMLFile && HasRoot && HasImagesFolder && IsRootSized && HasTargetPanel)
        {
            GUI.backgroundColor = new Color(17f / 255, 146f / 255, 156f / 255, 1);
            if (GUILayout.Button(STR_ImportIt))
            {
                ParsePsdFolder();
            }
            GUI.backgroundColor = GuiBkgColor;
        }
        else
        {
            // update text displayed in debugger portion of window
            UpdateDebugger();
        }

        // Action_Buttons
        #endregion
    }