Beispiel #1
0
    static RectTransform CreateHoritontalOrVertical(LayoutDirection dir, int count)
    {
        RectTransform target = null;

        if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent <RectTransform>() != null)
        {
            target = Selection.activeGameObject.GetComponent <RectTransform>();
            Undo.RecordObject(target, "adding layout 1");
            Undo.RecordObject(Selection.activeGameObject, "Adding layout");
            return(PopulateLayout(target.AddImageChild().GetComponent <RectTransform>(), dir, count));
        }
        else
        {
            Debug.LogError("Works on selected rect, please create or select a Panel ");
            return(null);
        }

        var canvas = CreateCanvasIfNotPresent();


        RectTransform container = canvas.GetComponent <RectTransform>();

        {
            Debug.Log("rect selection");
            container = Selection.activeGameObject.GetComponent <RectTransform>();

            var newObj = new GameObject("Layout", typeof(RectTransform), typeof(Image));
            Undo.RegisterCreatedObjectUndo(newObj, "Layout");

            newObj.transform.SetParent(container);
            container = newObj.GetComponent <RectTransform>();
            Selection.activeObject = container;
            //            container=container.gameObject.AddChildRectTransform();
        }

        if (container == null)
        {
            Debug.Log("no container");
            var newCont = new GameObject("RectContainer", typeof(RectTransform), typeof(Image));
            Undo.RegisterCreatedObjectUndo(newCont, "Layout");
            container = newCont.GetComponent <RectTransform>();
        }

        Image a = container.GetComponent <Image>();

        if (a != null)
        {
            a.enabled = false;
        }
    }
Beispiel #2
0
    static void CreateHorizontalLayout()
    {
        CreateCanvasIfNotPresent();

        RectTransform container = Selection.activeGameObject.rect();//.AddChild();
        Image         a         = container.GetComponent <Image>();

        if (a != null)
        {
            a.enabled = false;
        }
        Undo.RecordObject(Selection.activeGameObject, "Adding layout");
        CreateLayout(container.AddImageChild().GetComponent <RectTransform>(), false);
    }
        public static RectTransform CreateHoritontalOrVertical(RectTransform target, LayoutDirection dir, int count, float flex = -2)
        {
            if (target == null)
#if UNITY_EDITOR
            { if (Selection.activeGameObject != null && Selection.activeGameObject.GetComponent <RectTransform>() != null)
              {
                  target = Selection.activeGameObject.GetComponent <RectTransform>();
                  Undo.RecordObject(target, "adding layout 1");
                  Undo.RecordObject(Selection.activeGameObject, "Adding layout");
              }
            }
#else
            { return(null); }
#endif

            return(PopulateLayout(target.AddImageChild().GetComponent <RectTransform>(), dir, count, flex));


            // var canvas = CreateCanvasIfNotPresent();


            // RectTransform container = canvas.GetComponent<RectTransform>();
            // {
            //     Debug.Log("rect selection");
            //     container = Selection.activeGameObject.GetComponent<RectTransform>();

            //     var newObj = new GameObject("Layout", typeof(RectTransform), typeof(Image));
            //     Undo.RegisterCreatedObjectUndo(newObj, "Layout");

            //     newObj.transform.SetParent(container);
            //     container = newObj.GetComponent<RectTransform>();
            //     Selection.activeObject = container;
            //     //            container=container.gameObject.AddChildRectTransform();
            // }

            // if (container == null)
            // {
            //     Debug.Log("no container");
            //     var newCont = new GameObject("RectContainer", typeof(RectTransform), typeof(Image));
            //     Undo.RegisterCreatedObjectUndo(newCont, "Layout");
            //     container = newCont.GetComponent<RectTransform>();
            // }

            // Image a = container.GetComponent<Image>();
            // if (a != null) a.enabled = false;
        }