108 lines
3.3 KiB
C#
108 lines
3.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public enum LayoutGroupType
|
|
{
|
|
Horizontal,
|
|
Vertical,
|
|
Grid
|
|
}
|
|
|
|
[RequireComponent(typeof(RenderPrintingManagerOptionHelper))]
|
|
public class RenderPrintingManagerOption : MonoBehaviour
|
|
{
|
|
public RenderPrintingManagerOptionHelper helper;
|
|
public Vector2 renderPrintSize;
|
|
public Vector2 renderPreviewSize;
|
|
public Transform pivot;
|
|
[LabelText("需要输出的图合集")] public List<GameObject> objectsToRender = new List<GameObject>();
|
|
|
|
public Vector2 modelPosition;
|
|
public Vector3 modelScale;
|
|
|
|
public bool isChangeLayout;
|
|
[ShowIf("isChangeLayout")] public Transform layoutGroupTransform;
|
|
[ShowIf("isChangeLayout")] public LayoutGroupType type;
|
|
[ShowIf("isChangeLayout")] public RectOffset padding;
|
|
[ShowIf("isChangeLayout")] public Vector2 cellSize = new Vector2(0f, 0f);
|
|
[ShowIf("isChangeLayout")] public Vector2 spacing = new Vector2(0f, 0f);
|
|
|
|
[ShowIf("isChangeLayout")] [ShowIf("type", LayoutGroupType.Grid)]
|
|
public GridLayoutGroup.Constraint constraint;
|
|
|
|
[ShowIf("isChangeLayout")] [ShowIf("type", LayoutGroupType.Grid)]
|
|
public int constraintCount = 0;
|
|
|
|
private void Awake()
|
|
{
|
|
helper = GetComponent<RenderPrintingManagerOptionHelper>();
|
|
}
|
|
|
|
[ContextMenu("AutoInput")]
|
|
void AutoInput()
|
|
{
|
|
renderPrintSize = GetComponent<RectTransform>().sizeDelta;
|
|
pivot = GetComponent<RectTransform>();
|
|
modelScale = transform.localScale;
|
|
}
|
|
|
|
[ContextMenu("ResetLayout")]
|
|
void ResetLayout()
|
|
{
|
|
padding = new RectOffset(0, 0, 0, 0);
|
|
cellSize = new Vector2(0f, 0f);
|
|
spacing = new Vector2(0f, 0f);
|
|
constraintCount = 0;
|
|
type = LayoutGroupType.Horizontal;
|
|
isChangeLayout = false;
|
|
}
|
|
|
|
[ContextMenu("AutoAddGameObject")]
|
|
void AutoAddGameObject()
|
|
{
|
|
objectsToRender.Clear();
|
|
for (var i = 0; i < transform.childCount; i++)
|
|
{
|
|
objectsToRender.Add(transform.GetChild(i).gameObject);
|
|
}
|
|
}
|
|
|
|
[ContextMenu("CopyLayout")]
|
|
void CopyLayout()
|
|
{
|
|
if (layoutGroupTransform != null)
|
|
{
|
|
var layoutGroup = layoutGroupTransform.GetComponent<LayoutGroup>();
|
|
padding = layoutGroup.padding;
|
|
switch (type)
|
|
{
|
|
case LayoutGroupType.Horizontal:
|
|
spacing.x = ((HorizontalLayoutGroup)layoutGroup).spacing;
|
|
break;
|
|
case LayoutGroupType.Vertical:
|
|
spacing.x = ((VerticalLayoutGroup)layoutGroup).spacing;
|
|
break;
|
|
case LayoutGroupType.Grid:
|
|
var gridLayoutGroup = ((GridLayoutGroup)layoutGroup);
|
|
cellSize = gridLayoutGroup.cellSize;
|
|
spacing = gridLayoutGroup.spacing;
|
|
constraintCount = gridLayoutGroup.constraintCount;
|
|
constraint = gridLayoutGroup.constraint;
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException();
|
|
}
|
|
}
|
|
}
|
|
|
|
public virtual void InitPreviewData()
|
|
{
|
|
}
|
|
|
|
public virtual void InitPrintingData()
|
|
{
|
|
}
|
|
} |