using UnityEngine;
public class ModelLoader : MonoBehaviour
{
public Shader CustomShader;
public float ScaleFactor = 1f;
protected GameObject aResultGameObject;
void Start()
{
Screen.SetResolution(1280, 800, false);
string aKey = LicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
Debug.LogError("Failed to activate CAD Exchanger license.");
}
}
public virtual void ImportModel(string thePath)
{
var aModel = ModelImporter.ImportModel(thePath);
Unity_ObjectFactory aFactory = new Unity_ObjectFactory();
if(CustomShader)
aFactory.Parameters().SetShader(CustomShader);
aFactory.Parameters().SetScaleFactor(ScaleFactor);
string aModelName = Path.GetFileName(thePath);
aResultGameObject = aFactory.Create(aModel, aModelName);
GameObject.Find("Main Camera").GetComponent<CameraControl>().SetTarget(aResultGameObject.transform);
}
public virtual void OnCancel()
{
Debug.LogError("File cannot be opened!");
}
public void OpenFileDialog()
{
if (aResultGameObject != null)
{
Destroy(aResultGameObject);
}
SimpleFileBrowser.FileBrowser.ShowLoadDialog(ImportModel, OnCancel);
}
}