using System.Threading;
using UnityEngine;
public class ModelLoader : MonoBehaviour
{
public Shader CustomShader;
public float ScaleFactor = 1f;
public bool ImportPMI = false;
private GameObject myResultGameObject;
private Thread myMDMLoadingThread;
private void Awake()
{
ProgressBar.SetActive(false);
}
private void Start()
{
Screen.SetResolution(1280, 800, false);
UniversalConverterHelper.UpdateSystemEnvironment();
string aKey = LicenseKey.Value();
if (!LicenseManager.Activate(aKey))
{
Debug.LogError("Failed to activate CAD Exchanger license.");
QuitApplication();
}
}
private void Update()
{
if (myMDMLoadingThread != null)
{
if (myMDMLoadingThread.ThreadState == ThreadState.Stopped)
{
myMDMLoadingThread = null;
if (myModel != null)
{
ButtonControl.SetState(ButtonControl.State.CreatingGO);
OnModelDataModelLoaded();
}
else
{
ButtonControl.SetState(ButtonControl.State.Available);
ProgressBar.SetActive(false);
}
}
}
}
public void AsyncImportModel(string thePath)
{
ButtonControl.SetState(ButtonControl.State.LoadingMDM);
var anObserver = new ProgressBar.Observer();
myMDMLoadingThread = new Thread(() => {
myModel = ModelImporter.ImportModel(thePath, ImportPMI, anObserver);
});
myMDMLoadingThread.Start();
}
public void OnCancel()
{
}
public void OpenFileDialog()
{
if (myResultGameObject != null)
{
Destroy(myResultGameObject);
}
SimpleFileBrowser.FileBrowser.ShowLoadDialog(AsyncImportModel, OnCancel);
}
void OnModelDataModelLoaded()
{
if (CustomShader)
{
}
var anObserver = new ProgressBar.Observer();
string aModelName = myModel.Name().ToString();
aFactory.
CreateAsync(myModel, aModelName, OnGameObjectCreated);
}
void OnGameObjectCreated(GameObject theGameObject)
{
if (theGameObject != null)
{
myResultGameObject = theGameObject;
GetComponent<CameraControl>().SetTarget(myResultGameObject.transform);
}
ProgressBar.SetActive(false);
ButtonControl.SetState(ButtonControl.State.Available);
}
void QuitApplication()
{
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
}
}
Provides CAD Exchanger data model.
Definition: ModelData_Model.hxx:43
Creates GameObject from ModelData_Model.
Definition: Unity_ObjectFactory.cs:31
void CreateAsync(ModelData_Model theModel, string theName, AsyncEndCallback theCallback=null, Dictionary< GameObject, ModelData_SceneGraphElement > theObjectsDictionary=null)
Asynchronously creates GameObject from ModelData_Model in the current scene with a specified name.
Definition: Unity_ObjectFactory.cs:74
Unity_ObjectFactoryParameters Parameters()
Returns parameters.
Definition: Unity_ObjectFactory.cs:87
void SetProgressStatusObserver(Base_ProgressStatus.Observer theObserver)
Sets progress status observer.
Definition: Unity_ObjectFactory.cs:102
void SetImportPMI(bool theOption)
Specifies whether Product and Manufacturing Information (PMI) should be imported into GameObject from...
Definition: Unity_ObjectFactoryParameters.cs:107
void SetShader(Shader theShader)
Specifies the shader that should be applied to the result GameObject.
Definition: Unity_ObjectFactoryParameters.cs:133
void SetScaleFactor(float theScaleFactor)
Sets the scale factor of the imported GameObject.
Definition: Unity_ObjectFactoryParameters.cs:149
Defines classes, types, and global functions related to CAD Exchanger.
Definition: A3DSTestLib.hxx:22