I solved by manually positioning the message prefab inside the world space. Showing/hiding by making gameobject active/inactive.
And edited the SSTools.cs script as below. (it is crude though, as it skips position and time for the hardcoded values).
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class SSTools : MonoBehaviour {
public enum Time
{
threeSecond,
twoSecond,
oneSecond
};
public enum Position
{
top,
bottom
};
private static SSTools instance;
public static IEnumerator hide_messagePrefab(float secondsToWait, bool show = false){
yield return new WaitForSeconds (secondsToWait);
GameObject messagePrefab = GameObject.Find("Pvr_UnitySDK").transform.Find("Head").transform.Find("Message").gameObject;
messagePrefab.gameObject.SetActive(false);
}
public static void ShowMessage ( string msg, SSTools.Position position, SSTools.Time time )
{
//Load message prefab from resources folder
//GameObject messagePrefab = Resources.Load ( "Message" ) as GameObject;
GameObject messagePrefab = GameObject.Find("Pvr_UnitySDK").transform.Find("Head").transform.Find("Message").gameObject;
//Get container object of message
GameObject containerObject = messagePrefab.gameObject.transform.GetChild ( 0 ).gameObject;
//Get text object
GameObject textObject = containerObject.gameObject.transform.GetChild ( 0 ).GetChild ( 0 ).gameObject;
//Get text property
Text msg_text = textObject.GetComponent<Text> ( );
//Set message to text ui
msg_text.text = msg;
//Set position of container object of message
//SetPosition ( containerObject.GetComponent<RectTransform> ( ), position );
//Spawn message object with all changes
//GameObject clone = Instantiate ( messagePrefab );
messagePrefab.gameObject.SetActive(true);
// Destroy clone of message object according to the time
//RemoveClone ( messagePrefab, time );
if(!instance)
{
instance = FindObjectOfType<SSTools>();
if(!instance)
{
instance = new GameObject ("SSTools").AddComponent<SSTools>();
}
}
instance.StartCoroutine ( hide_messagePrefab(2.0f) );
}
private static void SetPosition ( RectTransform rectTransform, Position position )
{
if (position == Position.top)
{
rectTransform.anchorMin = new Vector2 ( 0.5f, 1f );
rectTransform.anchorMax = new Vector2 ( 0.5f, 1f );
rectTransform.anchoredPosition = new Vector3 ( 0.5f, -100f, 0 );
}
else
{
rectTransform.anchorMin = new Vector2 ( 0.5f, 0 );
rectTransform.anchorMax = new Vector2 ( 0.5f, 0 );
rectTransform.anchoredPosition = new Vector3 ( 0.5f, 100f, 0 ); // old (0.5f, 100f, 0)
}
}
private static void RemoveClone ( GameObject clone, Time time )
{
if (time == Time.oneSecond)
{
Destroy ( clone.gameObject, 1f );
}
else if (time == Time.twoSecond)
{
Destroy ( clone.gameObject, 2f );
}
else
{
Destroy ( clone.gameObject, 3f );
}
}
}