FM/Assets/Scripts/FUJIFILM/ScripttableObject/ProductScriptableObject.cs

166 lines
6.0 KiB
C#
Raw Normal View History

2025-08-20 11:14:21 +08:00
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEditor;
using UnityEngine;
using UnityEngine.Serialization;
using UnityEngine.UI;
namespace HK
{
public enum CapType
{
OneToOne,
OneToMany,
ManyToMany,
}
2025-08-20 11:14:21 +08:00
[CreateAssetMenu(fileName = "ProductObject", menuName = "ScriptableObjects/ProductObject", order = 1)]
public class ProductScriptableObject : ThemeBaseScriptableObject
{
[LabelText("产品名称")] public string produceName;
[LabelText("产品ID")] public string produceID;
[LabelText("英文产品缩略图")] public Sprite icon;
[LabelText("中文产品缩略图")] public Sprite icon_Chin;
2025-08-21 13:10:17 +08:00
[LabelText("是否能进入下一步")] public bool isCanGoNext = false;
2025-08-20 11:14:21 +08:00
[LabelText("模板")] public Sprite[] templateSprites;
2025-08-21 13:10:17 +08:00
[LabelText("是否显示模板图片内容")] public bool isShowTemplate = true;
2025-08-20 11:14:21 +08:00
[BoxGroup("GridLayout")] [LabelText("Template参数RectOffset")]
public RectOffset layoutRectOffset;
[BoxGroup("GridLayout")] [LabelText("Template参数cellSize")]
public Vector2 cellSize;
[BoxGroup("GridLayout")] [LabelText("Template参数SpacingSize")]
public Vector2 layoutSpacingSize;
[BoxGroup("GridLayout")] [LabelText("Template参数SpacingSize")]
public GridLayoutGroup.Constraint constraint;
[BoxGroup("GridLayout")] [LabelText("Template参数SpacingSize")]
public int constraintCount;
[Sirenix.OdinInspector.FilePath] [ReadOnly]
public string productUIPfbPath;
[LabelText("UI")] public GameObject productUIPrefab;
public Vector3 modelPosition;
[Sirenix.OdinInspector.FilePath] [ReadOnly]
public string productGameObjectPfbPath;
[LabelText("模型")] public GameObject productGameObjectPrefab;
2025-08-21 13:10:17 +08:00
[LabelText("是否需要显示协议页面")] public bool isShowTermPage;
2025-08-20 11:14:21 +08:00
public bool is2D;
[ShowIf("is2D")] [LabelText("截图类型")] public CapType capType = CapType.OneToOne;
[ShowIf("capType", CapType.OneToMany)] [LabelText("预览图是否显示底图")]
public bool isShowBaseMap = true;
[BoxGroup("OnceToManyGridLayout")] [LabelText("OnceToMany参数RectOffset")] [ShowIf("capType", CapType.OneToMany)]
public RectOffset layoutRectOffset_OnceToMany;
[BoxGroup("OnceToManyGridLayout")] [LabelText("OnceToMany参数cellSize")] [ShowIf("capType", CapType.OneToMany)]
public Vector2 cellSize_OnceToMany;
[BoxGroup("OnceToManyGridLayout")] [LabelText("OnceToMany参数SpacingSize")] [ShowIf("capType", CapType.OneToMany)]
public Vector2 layoutSpacingSize_OnceToMany;
[BoxGroup("OnceToManyGridLayout")] [LabelText("OnceToMany参数SpacingSize")] [ShowIf("capType", CapType.OneToMany)]
public GridLayoutGroup.Constraint constraint_OnceToMany;
[BoxGroup("OnceToManyGridLayout")] [LabelText("OnceToMany参数SpacingSize")] [ShowIf("capType", CapType.OneToMany)]
public int constraintCount_OnceToMany;
2025-08-21 13:10:17 +08:00
[LabelText("截图尺寸")] public Vector2 screenshotSize;
2025-08-22 00:33:25 +08:00
[LabelText("印刷尺寸,单位mm")] public Vector2 printingSize;
2025-08-20 11:14:21 +08:00
[LabelText("产品价格")] public int productPrice;
[LabelText("设计价格")] public int designPrice;
public int discountPrice;
[Sirenix.OdinInspector.FilePath] [ReadOnly]
public string productShopCartItemPfbPath;
[LabelText("购物车Item")] public GameObject productShopCartItemPrefab;
[LabelText("可设计的总数,必须跟模板对应上")] public List<DesignItem> designItems = new List<DesignItem>();
public Sprite[] photoSprites;
[LabelText("是否只允许贴一张")] public bool isOnlyOne;
2025-08-21 13:10:17 +08:00
#if UNITY_EDITOR
2025-08-20 11:14:21 +08:00
[Button("自动同步icon名字")]
public void AutoChangeName()
{
produceName = icon.name;
AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(Selection.activeObject), produceName);
}
[Button("自动同步预制体路径")]
public void AutoChangeProductUIPfbPath()
{
if (productUIPrefab != null)
productUIPfbPath = AssetDatabase.GetAssetPath(productUIPrefab);
if (productGameObjectPrefab != null)
productGameObjectPfbPath = AssetDatabase.GetAssetPath(productGameObjectPrefab);
if (productShopCartItemPrefab != null)
productShopCartItemPfbPath = AssetDatabase.GetAssetPath(productShopCartItemPrefab);
foreach (var designItem in designItems)
{
designItem.AutoInputIconName();
}
AssetDatabase.SaveAssets();
}
2025-08-21 13:10:17 +08:00
#endif
2025-08-20 11:14:21 +08:00
}
[System.Serializable]
public enum LayoutType
{
Horizontal,
Vertical,
Grid
}
[System.Serializable]
public class DesignItem
{
// [HK.PropertyAttribute.FilePath("Assets/Res/Texture/ProductIcon")]
[ReadOnly] [Sirenix.OdinInspector.FilePath]
public string designItemAssetPath;
[LabelText("设计Item")] public GameObject designItemPrefab;
public string description;
public int designItemId;
public LayoutType layoutType;
public int designItemCount;
[SerializeField] public RectOffset layoutRectOffset;
[ShowIf("CheckIsNotGrid")] public float layoutSpacing;
[ShowIf("layoutType", LayoutType.Grid)]
public Vector2 cellSize;
[ShowIf("layoutType", LayoutType.Grid)]
public Vector2 layoutSpacingSize;
2025-08-23 10:08:36 +08:00
[LabelText("印刷尺寸,单位mm")] public Vector2 printingSize;
2025-08-20 11:14:21 +08:00
public bool CheckIsNotGrid()
{
return layoutType == LayoutType.Vertical || layoutType == LayoutType.Horizontal;
}
2025-08-21 13:10:17 +08:00
#if UNITY_EDITOR
2025-08-20 11:14:21 +08:00
public void AutoInputIconName()
{
if (designItemPrefab != null)
designItemAssetPath = AssetDatabase.GetAssetPath(designItemPrefab);
}
2025-08-21 13:10:17 +08:00
#endif
2025-08-20 11:14:21 +08:00
}
}