public static int CalculateLayoutInputVertical(IntPtr l) { int result; try { LayoutElement layoutElement = (LayoutElement)LuaObject.checkSelf(l); layoutElement.CalculateLayoutInputVertical(); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
public static void AttachAndSetupShadow() { GameObject sourceGameObject = Selection.activeGameObject; Undo.RecordObject(sourceGameObject, sourceGameObject.name); RectTransform sourceRectTransform = sourceGameObject.GetComponent <RectTransform>(); Vector3 sourcePos = sourceRectTransform.position; Vector2 sourceSize = sourceRectTransform.sizeDelta; Vector2 sourceLayoutSize = sourceRectTransform.GetProperSize(); Image sourceImage = sourceGameObject.GetAddComponent <Image>(); CreateShadow(); GameObject shadowGameObject = Selection.activeGameObject; shadowGameObject.name = sourceGameObject.name + " Shadow"; ShadowGenerator shadowGenerator = shadowGameObject.GetAddComponent <ShadowGenerator>(); shadowGenerator.sourceImage = sourceImage; RectTransform shadowTransform = shadowGameObject.GetAddComponent <RectTransform>(); shadowTransform.anchorMin = sourceRectTransform.anchorMin; shadowTransform.anchorMax = sourceRectTransform.anchorMax; shadowTransform.pivot = sourceRectTransform.pivot; bool probablyHasLayout = (sourceGameObject.GetComponent <LayoutGroup>() != null || sourceGameObject.GetComponent <LayoutElement>() != null); GameObject newParentGameObject = new GameObject(sourceGameObject.name); newParentGameObject.transform.SetParent(sourceRectTransform.parent); RectTransform newParentRectTransform = newParentGameObject.GetAddComponent <RectTransform>(); newParentRectTransform.SetSiblingIndex(sourceRectTransform.GetSiblingIndex()); newParentRectTransform.anchorMin = sourceRectTransform.anchorMin; newParentRectTransform.anchorMax = sourceRectTransform.anchorMax; newParentRectTransform.pivot = sourceRectTransform.pivot; newParentRectTransform.position = sourcePos; newParentRectTransform.sizeDelta = sourceSize; LayoutElement layoutElement = null; if (probablyHasLayout) { layoutElement = newParentGameObject.AddComponent <LayoutElement>(); layoutElement.preferredWidth = sourceLayoutSize.x; layoutElement.preferredHeight = sourceLayoutSize.y; } shadowGameObject.GetComponent <RectTransform>().SetParent(newParentRectTransform, true); sourceRectTransform.SetParent(newParentRectTransform, true); sourceGameObject.name = sourceGameObject.name + " Image"; if (probablyHasLayout) { layoutElement.CalculateLayoutInputHorizontal(); layoutElement.CalculateLayoutInputVertical(); } shadowGenerator.GenerateShadowFromImage(); Selection.activeObject = newParentGameObject; Undo.RegisterCreatedObjectUndo(shadowGameObject, shadowGameObject.name); Undo.RegisterCreatedObjectUndo(newParentGameObject, newParentGameObject.name); }