125 lines
4.2 KiB
C#
125 lines
4.2 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using Sirenix.OdinInspector;
|
|||
|
using UnityEditor;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.Serialization;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
namespace HK
|
|||
|
{
|
|||
|
[CreateAssetMenu(fileName = "ProductObject", menuName = "ScriptableObjects/ProductObject", order = 1)]
|
|||
|
public class ProductScriptableObject : ThemeBaseScriptableObject
|
|||
|
{
|
|||
|
[LabelText("产品名称")] public string produceName;
|
|||
|
[LabelText("产品缩略图")] public Sprite icon;
|
|||
|
[LabelText("模板")] public Sprite[] templateSprites;
|
|||
|
|
|||
|
[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 bool is2D;
|
|||
|
public Vector3 modelPosition;
|
|||
|
|
|||
|
[Sirenix.OdinInspector.FilePath] [ReadOnly]
|
|||
|
public string productGameObjectPfbPath;
|
|||
|
|
|||
|
[LabelText("模型")] public GameObject productGameObjectPrefab;
|
|||
|
|
|||
|
[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;
|
|||
|
|
|||
|
[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();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[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;
|
|||
|
|
|||
|
public bool CheckIsNotGrid()
|
|||
|
{
|
|||
|
return layoutType == LayoutType.Vertical || layoutType == LayoutType.Horizontal;
|
|||
|
}
|
|||
|
|
|||
|
public void AutoInputIconName()
|
|||
|
{
|
|||
|
if (designItemPrefab != null)
|
|||
|
designItemAssetPath = AssetDatabase.GetAssetPath(designItemPrefab);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|