Hi, this is my third day with unity coding but not new to c#.
i downloaded a sample code from online and try to modify it. but when i move the button click event to “Void start” . nothing happens after the event is triggered when clicked event was fired from the script. it should generate a 3D face model. but if i run the same code and trigger the click event from the UI. everything works fine.
the reason why i use timer to trigger the click event is because the start method is loading the licenses.so i wait till the license is loaded then i run the generator.
i also tried triggering the click event method “GenerateRandomAvatar” directly from the timer directly.code finished running but nothing happens also. any help will be really appreciated .
i also attached the picture before and after from click event.
Button startButton;
protected virtual void Start()
{
var ui = controls.Select(b => b.gameObject).ToArray();
if (!SampleUtils.CheckIfSupported(progressText, ui, sdkType))
return;
// first of all, initialize the SDK
if (!AvatarSdkMgr.IsInitialized)
AvatarSdkMgr.Init(sdkType: sdkType);
StartCoroutine(Initialize());
// Anti-aliasing is required for hair shader, otherwise nice transparent texture won't work.
// Another option is to use cutout shader, but the look with this shader isn't that great.
#if UNITY_STANDALONE_WIN || UNITY_EDITOR || UNITY_EDITOR
QualitySettings.antiAliasing = 8;
#else
QualitySettings.antiAliasing = 4;
#endif
foreach (var b in controls)
{
if (b is Button)
{
if(b.name.Contains("Random")){
startButton = (Button)b;
//get button from the UI
}
}
}
startTimer();//trigger the button click after 10 second after screen initilise
}
Timer timer;
public void startTimer() {
timer=new Timer();
timer.Interval = 1000 * 10;
timer.Elapsed += OnTimer;
timer.Start();
}
public void OnTimer(object obj,ElapsedEventArgs args) {
timer.Stop();
startButton.onClick.Invoke();
}
//button click
public virtual void GenerateRandomAvatar()
{
string photoPath = @"myphoto.jpg";
byte[] bytes = File.ReadAllBytes(photoPath);
// StartCoroutine(GenerateAvatarFunc(testPhoto.bytes));
StartCoroutine(GenerateAvatarFunc(bytes));
}
protected virtual IEnumerator GenerateAvatarFunc(byte[] photoBytes)
{
var avatarObject = GameObject.Find("ItSeez3D Avatar");
Destroy(avatarObject);
SetControlsInteractable(false);
photoPreview.gameObject.SetActive(false);
yield return StartCoroutine(GenerateAndDisplayHead(photoBytes, pipelineType));
SetControlsInteractable(true);
if (generateHaircutButton != null)
generateHaircutButton.gameObject.SetActive(pipelineType == PipelineType.FACE);
}
,I am extreme new to unity(third days i think?) ,i downloaded an online source and modify myself but i am not new to C#.
i have a button on the screen. if i manually click on the button and trigger the button event then everything will work fine. So i decide to move the code to program “Start” method or manually click the button from the “Start” function .But the screen refuse to change to new scene.
below is my code
Button startButton;
protected virtual void Start()
{
var ui = controls.Select(b => b.gameObject).ToArray();
if (!SampleUtils.CheckIfSupported(progressText, ui, sdkType))
return;
// first of all, initialize the SDK
if (!AvatarSdkMgr.IsInitialized)
AvatarSdkMgr.Init(sdkType: sdkType);
StartCoroutine(Initialize());
// Anti-aliasing is required for hair shader, otherwise nice transparent texture won't work.
// Another option is to use cutout shader, but the look with this shader isn't that great.
#if UNITY_STANDALONE_WIN || UNITY_EDITOR || UNITY_EDITOR
QualitySettings.antiAliasing = 8;
#else
QualitySettings.antiAliasing = 4;
#endif
foreach (var b in controls)
{
if (b is Button)
{
if(b.name.Contains("Random")){
startButton = (Button)b;
//get button from the UI
}
}
}
public void startTimer() {
timer=new Timer();
timer.Interval = 1000 * 10;
timer.Elapsed += OnTimer;
timer.Start();
}
public void OnTimer(object obj,ElapsedEventArgs args) {
timer.Stop();
startButton.onClick.Invoke();
}
//button click
public virtual void GenerateRandomAvatar()
{
string photoPath = @"myphoto.jpg";
byte[] bytes = File.ReadAllBytes(photoPath);
// StartCoroutine(GenerateAvatarFunc(testPhoto.bytes));
StartCoroutine(GenerateAvatarFunc(bytes));
}
protected virtual IEnumerator GenerateAvatarFunc(byte[] photoBytes)
{
var avatarObject = GameObject.Find("ItSeez3D Avatar");
Destroy(avatarObject);
SetControlsInteractable(false);
photoPreview.gameObject.SetActive(false);
yield return StartCoroutine(GenerateAndDisplayHead(photoBytes, pipelineType));
SetControlsInteractable(true);
if (generateHaircutButton != null)
generateHaircutButton.gameObject.SetActive(pipelineType == PipelineType.FACE);
}