//------------------------------------------------------------
// Game Framework
// Copyright © 2013-2021 loyalsoft. All rights reserved.
// Homepage: http://www.game7000.com/
// Feedback: http://www.game7000.com/
//------------------------------------------------------------
using GameFramework.UI;
using UnityEngine;
namespace UnityGameFramework.Runtime
{
///
/// 默认界面辅助器。
///
public class DefaultUIFormHelper : UIFormHelperBase
{
private ResourceComponent m_ResourceComponent = null;
///
/// 实例化界面。
///
/// 要实例化的界面资源。
/// 实例化后的界面。
public override object InstantiateUIForm(object uiFormAsset)
{
return Instantiate((Object)uiFormAsset);
}
///
/// 创建界面。
///
/// 界面实例。
/// 界面所属的界面组。
/// 用户自定义数据。
/// 界面。
public override IUIForm CreateUIForm(object uiFormInstance, IUIGroup uiGroup, object userData)
{
GameObject gameObject = uiFormInstance as GameObject;
if (gameObject == null)
{
Log.Error("UI form instance is invalid.");
return null;
}
Transform transform = gameObject.transform;
transform.SetParent(((MonoBehaviour)uiGroup.Helper).transform);
transform.localScale = Vector3.one;
return gameObject.GetOrAddComponent();
}
///
/// 释放界面。
///
/// 要释放的界面资源。
/// 要释放的界面实例。
public override void ReleaseUIForm(object uiFormAsset, object uiFormInstance)
{
m_ResourceComponent.UnloadAsset(uiFormAsset);
Destroy((Object)uiFormInstance);
}
private void Start()
{
m_ResourceComponent = GameEntry.GetComponent();
if (m_ResourceComponent == null)
{
Log.Fatal("Resource component is invalid.");
return;
}
}
}
}