89 lines
3.5 KiB
C#
89 lines
3.5 KiB
C#
|
using System.Collections.Generic;
|
|||
|
using HK;
|
|||
|
using HK.FUJIFILM;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using ZGame;
|
|||
|
|
|||
|
public class Model_Fixed : MonoBehaviour
|
|||
|
{
|
|||
|
public RectTransform designParent;
|
|||
|
public ProductScriptableObject productScriptableObject;
|
|||
|
public RenderPrintingManagerOption option;
|
|||
|
|
|||
|
private void OnEnable()
|
|||
|
{
|
|||
|
EventManager.Instance.Subscribe(MugActualModel_Fixed_GenPhotoEventArgs.EventId,
|
|||
|
MugActualModel_Fixed_GenPhotoEvent);
|
|||
|
EventManager.Instance.Subscribe(ProduceDesign_CopyDesignItemAssetEventArgs.EventId,
|
|||
|
ProduceDesign_CopyDesignItemAssetEvent);
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
EventManager.Instance.Unsubscribe(MugActualModel_Fixed_GenPhotoEventArgs.EventId,
|
|||
|
MugActualModel_Fixed_GenPhotoEvent);
|
|||
|
EventManager.Instance.Unsubscribe(ProduceDesign_CopyDesignItemAssetEventArgs.EventId,
|
|||
|
ProduceDesign_CopyDesignItemAssetEvent);
|
|||
|
}
|
|||
|
|
|||
|
[ContextMenu("AutoAddDesignParent")]
|
|||
|
void AutoAddDesignParent()
|
|||
|
{
|
|||
|
designParent = transform.GetChild(0).transform as RectTransform;
|
|||
|
}
|
|||
|
|
|||
|
protected virtual void MugActualModel_Fixed_GenPhotoEvent(object sender, GameEventArgs e)
|
|||
|
{
|
|||
|
var args = e as MugActualModel_Fixed_GenPhotoEventArgs;
|
|||
|
if (!designItems.TryGetValue(args.ID, out ImageDesignItem designItem))
|
|||
|
{
|
|||
|
return;
|
|||
|
}
|
|||
|
|
|||
|
var loadGameObject = GameObject.Instantiate(args.go, designItem.DesignParent);
|
|||
|
|
|||
|
loadGameObject.transform.localPosition = args.go.transform.localPosition;
|
|||
|
var image = loadGameObject.GetComponent<Image>();
|
|||
|
loadGameObject.AddComponent<HK.UpdateTransform>().SetData(args.go.transform);
|
|||
|
loadGameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
protected Dictionary<string, ImageDesignItem> designItems = new Dictionary<string, ImageDesignItem>();
|
|||
|
|
|||
|
protected virtual void ProduceDesign_CopyDesignItemAssetEvent(object sender, GameEventArgs e)
|
|||
|
{
|
|||
|
var args = e as ProduceDesign_CopyDesignItemAssetEventArgs;
|
|||
|
designItems.Clear();
|
|||
|
for (var i = 0; i < designParent.transform.childCount; i++)
|
|||
|
{
|
|||
|
GameObject.Destroy(designParent.transform.GetChild(i).gameObject);
|
|||
|
}
|
|||
|
|
|||
|
productScriptableObject = args.productScriptableObject;
|
|||
|
designParent.GetComponent<Image>().sprite = args.sprite;
|
|||
|
var instantiate = GameObject.Instantiate(args.go, designParent);
|
|||
|
if (instantiate.TryGetComponent(typeof(Image), out var image))
|
|||
|
{
|
|||
|
var component = ((Image)image);
|
|||
|
component.sprite = args.sprite;
|
|||
|
component.enabled = productScriptableObject.isShowTemplate;
|
|||
|
}
|
|||
|
|
|||
|
// var componentInChildren = args.go.GetComponentInChildren<UpdateInput>();
|
|||
|
// var updateInput = instantiate.GetComponentInChildren<UpdateInput>();
|
|||
|
// if (componentInChildren != null && updateInput != null)
|
|||
|
// updateInput.SetData(componentInChildren.inpChinName, componentInChildren.inpEngName,
|
|||
|
// componentInChildren.inpID,
|
|||
|
// componentInChildren.inpBirth, componentInChildren.inpIssue, componentInChildren.inpBianHao);
|
|||
|
|
|||
|
instantiate.transform.GetComponent<RectTransform>().anchoredPosition = Vector2.zero;
|
|||
|
var list = instantiate.transform.FindChildDeeps<ImageDesignItem>();
|
|||
|
|
|||
|
foreach (var imageDesignItem in list)
|
|||
|
{
|
|||
|
imageDesignItem.IsHideBtnAdd(true);
|
|||
|
designItems.Add(imageDesignItem.ID, imageDesignItem);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|