예제 #1
0
    void InitializeLayouters()
    {
        if (target != null)
        {
            Transform targetParent = target.CachedTransform.parent;
            if (targetParent != null)
            {
                if (targetCellLayouter == null)
                {
                    targetCellLayouter = targetParent.GetComponent <GUILayouter>();
                }

                if (rootLayouter == null)
                {
                    GUILayouter[] layouters = target.GetComponentsInParent <GUILayouter>();
                    for (int i = 0; i < layouters.Length; i++)
                    {
                        if (layouters[i].IsRootLayouter)
                        {
                            rootLayouter = layouters[i];
                            break;
                        }
                    }
                }
            }
        }
    }
예제 #2
0
    void CheckRootLayouter()
    {
        GUILayouter targetLayouter = (GUILayouter)target;

        targetLayouter.IsRootLayouter = true;

        GUILayoutCell[] parentCells = targetLayouter.GetComponentsInParent <GUILayoutCell>(true);

        foreach (var cell in parentCells)
        {
            if (cell.LayoutHandlerObjects.Contains(targetLayouter.gameObject))
            {
                targetLayouter.IsRootLayouter = false;
            }
        }
    }
예제 #3
0
    public static GUILayoutCell GetParentCell(GUILayouter layouter)
    {
        GUILayoutCell[] cells = layouter.GetComponentsInParent <GUILayoutCell>();

        foreach (var c in cells)
        {
            foreach (var obj in c.LayoutHandlerObjects)
            {
                if (obj == layouter.gameObject)
                {
                    return(c);
                }
            }
        }

        return(null);
    }
예제 #4
0
    bool IsPositionedHorizontallyInParents(GUILayoutCell cell)
    {
        if (cell != null)
        {
            GUILayouter topLayouter = cell.transform.parent.GetComponent <GUILayouter>();

            if (topLayouter != null)
            {
                if (topLayouter.Type == GUILayouterType.Horizontal)
                {
                    return(true);
                }
                else
                {
                    return(IsPositionedHorizontallyInParents(GetParentCell(topLayouter)));
                }
            }
        }

        return(false);
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        GUILayoutCell targetLayouterCell = (GUILayoutCell)target;

        GUILayout.Space(10);
        EditorGUILayout.Separator();
        GUILayout.Space(10);

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create VerticalLayouter ", GUILayout.MinWidth(20)))
        {
            GameObject  newLayouterObj = new GameObject("VerticalLayout");
            GUILayouter newLayoter     = newLayouterObj.AddComponent <GUILayouter> ();
            newLayoter.Type = GUILayouterType.Vertical;

            newLayouterObj.transform.parent        = targetLayouterCell.CachedTransform;
            newLayouterObj.transform.localPosition = Vector3.zero;
            newLayouterObj.layer = targetLayouterCell.gameObject.layer;

            targetLayouterCell.LayoutHandlerObjects.Add(newLayouterObj);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create HorizontalLayouter ", GUILayout.MinWidth(20)))
        {
            GameObject  newLayouterObj = new GameObject("HorizontalLayout");
            GUILayouter newLayoter     = newLayouterObj.AddComponent <GUILayouter> ();
            newLayoter.Type = GUILayouterType.Horizontal;

            newLayouterObj.transform.parent        = targetLayouterCell.CachedTransform;
            newLayouterObj.transform.localPosition = Vector3.zero;
            newLayouterObj.layer = targetLayouterCell.gameObject.layer;

            targetLayouterCell.LayoutHandlerObjects.Add(newLayouterObj);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create TextMesh ", GUILayout.MinWidth(20)))
        {
            GameObject newLayouterObj = new GameObject("Label");
            newLayouterObj.AddComponent <tk2dTextMesh> ();

            newLayouterObj.transform.parent        = targetLayouterCell.CachedTransform;
            newLayouterObj.transform.localPosition = Vector3.zero;
            newLayouterObj.layer = targetLayouterCell.gameObject.layer;

            targetLayouterCell.LayoutHandlerObjects.Add(newLayouterObj);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create Independent Sprite ", GUILayout.MinWidth(20)))
        {
            GameObject newLayouterObj = new GameObject("Sprite");
            newLayouterObj.AddComponent <tk2dSprite> ();

            newLayouterObj.transform.parent        = targetLayouterCell.CachedTransform;
            newLayouterObj.transform.localPosition = Vector3.zero;
            newLayouterObj.layer = targetLayouterCell.gameObject.layer;
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create Fill Sprite ", GUILayout.MinWidth(20)))
        {
            GameObject newLayouterObj = new GameObject("Sprite");
            newLayouterObj.AddComponent <tk2dSprite> ();

            newLayouterObj.transform.parent        = targetLayouterCell.CachedTransform;
            newLayouterObj.transform.localPosition = Vector3.zero;
            newLayouterObj.layer = targetLayouterCell.gameObject.layer;

            targetLayouterCell.LayoutHandlerObjects.Add(newLayouterObj);
        }
        EditorGUILayout.EndHorizontal();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create SlicedSprite ", GUILayout.MinWidth(20)))
        {
            GameObject newLayouterObj = new GameObject("SlicedSprite");
            newLayouterObj.AddComponent <tk2dSlicedSprite> ();

            newLayouterObj.transform.parent        = targetLayouterCell.CachedTransform;
            newLayouterObj.transform.localPosition = Vector3.zero;
            newLayouterObj.layer = targetLayouterCell.gameObject.layer;

            targetLayouterCell.LayoutHandlerObjects.Add(newLayouterObj);
        }
        EditorGUILayout.EndHorizontal();
    }
예제 #6
0
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        GUILayouter targetLayouter = (GUILayouter)target;

        GUILayout.Space(10);
        EditorGUILayout.Separator();
        GUILayout.Space(10);

        CheckRootLayouter();

        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Create\nFlexible cell", GUILayout.MinWidth(20)))
        {
            GameObject    newCellObj = new GameObject("__FlexSpace");
            GUILayoutCell newCell    = newCellObj.AddComponent <GUILayoutCell> ();
            newCell.Type      = GUILayoutCellType.Flexible;
            newCell.SizeValue = 1;

            newCellObj.transform.parent        = targetLayouter.CachedTransform;
            newCellObj.transform.localPosition = Vector3.zero;
        }

        if (GUILayout.Button("Create\nFixedSize cell", GUILayout.MinWidth(20)))
        {
            GameObject    newCellObj = new GameObject("__FixedSpace");
            GUILayoutCell newCell    = newCellObj.AddComponent <GUILayoutCell> ();
            newCell.Type      = GUILayoutCellType.FixedSize;
            newCell.SizeValue = 0;

            newCellObj.transform.parent        = targetLayouter.CachedTransform;
            newCellObj.transform.localPosition = Vector3.zero;
        }

        if (GUILayout.Button("Create\nRelativeFixed cell", GUILayout.MinWidth(20)))
        {
            GameObject    newCellObj = new GameObject("__RelativeFixedSpace");
            GUILayoutCell newCell    = newCellObj.AddComponent <GUILayoutCell> ();
            newCell.Type      = GUILayoutCellType.RelativeFixedSize;
            newCell.SizeValue = 0;

            newCellObj.transform.parent        = targetLayouter.CachedTransform;
            newCellObj.transform.localPosition = Vector3.zero;
        }

        EditorGUILayout.EndHorizontal();


        EditorGUILayout.BeginHorizontal();

        if (GUILayout.Button("Verify Hierarchy", GUILayout.MinWidth(20)))
        {
            bool isHierarchyCorrupted = false;

            GUILayoutCell[] allCells = targetLayouter.CachedTransform.GetComponentsInChildren <GUILayoutCell> ();

            foreach (var cell in allCells)
            {
                foreach (var handlerObj in cell.LayoutHandlerObjects)
                {
                    if (handlerObj == null)
                    {
                        Debug.LogError("NULL Handler Found!");
                        Selection.activeGameObject = cell.gameObject;
                        isHierarchyCorrupted       = true;
                        break;
                    }
                }

                if (isHierarchyCorrupted)
                {
                    break;
                }
            }

            if (!isHierarchyCorrupted)
            {
                Debug.Log("NO NULL Handlers Found!");
            }
        }

        EditorGUILayout.EndHorizontal();
    }