Esempio n. 1
0
    public override void OnExit()
    {
        base.OnExit();
        PopMenu menu = ScanSceneController.currentTrackableObject.GetComponent <PopMenu> ();

        menu.Hide();
    }
    protected virtual IEnumerator LoadDataSet()
    {
        ClearAndLoadDataSet();
        //int counter = 0;
        IEnumerable <TrackableBehaviour> tbs = Vuforia.TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();
        GameObject buttonCanvasPrefab = null, buttonPrefab = null;        // = Resources.Load("Prefab/ScanButtonCanvas") as GameObject;

        foreach (TrackableBehaviour tb in tbs)
        {
            Logger.Log(tb.TrackableName, "purple");

            tb.gameObject.name = tb.TrackableName;

            XElement info = Xml.GetChildByAttribute(itemInfos, "id", tb.TrackableName);
            if (info == null)
            {
                continue;
            }
            string objType = Xml.Attribute(info, "type");
            tb.gameObject.AddComponent <DefaultTrackableEventHandler> ();
            tb.gameObject.AddComponent <CustomTrackableEventHandler> ();
            tb.gameObject.AddComponent <TurnOffBehaviour> ();
            CustomTrackableEventHandler cte = tb.gameObject.GetComponent <CustomTrackableEventHandler> ();
            cte.type         = objType;
            cte.subtitlePath = GetAssetsPath(Xml.Attribute(info, "subtitle"), true);
            UnityEngine.Object asset = null;
            if (objType == "object")
            {
//				string prefabName = Xml.Attribute (info, "prefab");
//				asset = loadedAssets.ContainsKey (prefabName) ? loadedAssets [prefabName] : new GameObject ();
//				var buttonNodes = info.Elements ();
//				GameObject bPanel = null;
//				foreach (XElement n in buttonNodes) {
//					if (buttonCanvasPrefab == null)
//						buttonCanvasPrefab = Resources.Load ("Prefabs/ScanButtonCanvas") as GameObject;
//					if (buttonPrefab == null)
//						buttonPrefab = Resources.Load ("Prefabs/ScanButton") as GameObject;
//					if (bPanel == null) {
//						bPanel = Instantiate (buttonCanvasPrefab) as GameObject;
//						bPanel.transform.SetParent (tb.gameObject.transform, false);
//					}
//					GameObject button = Instantiate (buttonPrefab) as GameObject;
//					button.AddComponent<ToggleButtonShowHide> ();
//					button.transform.SetParent (bPanel.transform.GetChild(0), false);
//				}
                InstantiateModelObject(info, tb, out asset);
            }
            else if (objType == "video")
            {
                InstantiateVideoObject(info, tb, out asset);

                //cte.mediaPlayer = mediaPlayer;
            }
            else if (objType == "menu4")
            {
                //asset = planePrefab;
                //Renderer render = (planePrefab).GetComponent<Renderer> ();
                //render.material = videoMaterial;
                //CustomTrackableEventHandler cte = tb.gameObject.GetComponent<CustomTrackableEventHandler> ();
                //cte.videoPath = GetAssetsPath (tb.TrackableName + ".mp4");
                //cte.mediaPlayer = mediaPlayer;
                tb.gameObject.AddComponent <PopMenu> ();
                PopMenu popmenu = tb.gameObject.GetComponent <PopMenu> ();
                popmenu.menuItems = new List <PopMenuItem> ();
                //popmenu.playerMateral = videoMaterial;

                var menuNodes = info.Elements();
                //XElement res = null;
                int index = 0;
                foreach (XElement n in menuNodes)
                {
                    GameObject  planeItem = GameObject.Instantiate(Resources.Load("Prefabs/PlaneItem4")) as GameObject;
                    PopMenuItem pmi       = planeItem.GetComponent <PopMenuItem> ();
                    popmenu.menuItems.Add(pmi);
                    pmi.floatSpeed       = 5f;
                    pmi.floatAmplitude   = 0.03f;
                    pmi.index            = index;
                    pmi.menu             = popmenu;
                    pmi.trackableHandler = cte;
                    Vector3 position = planeItem.transform.localPosition;
                    planeItem.transform.SetParent(tb.gameObject.transform, false);
                    if (index == 1)
                    {
                        planeItem.transform.localPosition = position.SetX(-position.x);
                    }
                    else if (index == 2)
                    {
                        planeItem.transform.localPosition = position.SetZ(-position.z);
                    }
                    else if (index == 3)
                    {
                        planeItem.transform.localPosition = new Vector3(-position.x, position.y, -position.z);
                    }
                    pmi.Initiate();
                    string itemSrc   = Xml.Attribute(n, "src");
                    string videoPath = Xml.Attribute(n, "videosrc");
                    planeItem.name   = pmi.name = tb.TrackableName + "_" + Xml.Attribute(n, "id");
                    pmi.subtitlePath = GetAssetsPath(Xml.Attribute(n, "subtitle"), true);
                    if (!string.IsNullOrEmpty(videoPath))
                    {
                        pmi.videoPath = GetAssetsPath(videoPath);
                        planeItem.RegisterClickEvent();
                    }
                    else
                    {
                        GameObject prefab = GetAsset(Xml.Attribute(n, "prefab"));
                        pmi.threeDObject = GameObject.Instantiate(prefab, prefab.transform.position, prefab.transform.rotation) as GameObject;
                        pmi.threeDObject.transform.SetParent(tb.gameObject.transform, false);
                        ApplyItemInfo(pmi.threeDObject, n);
                    }
                    WWW www = new WWW(GetAssetsPath(itemSrc, true));
                    yield return(www);

                    Logger.Log(GetAssetsPath(itemSrc, true) + " " + www.texture.ToString());
                    pmi.material.mainTexture = www.texture;
                    //Logger.Log (planeItem.transform.localPosition.x.ToString() + " " +planeItem.transform.localPosition.y+ " " + planeItem.transform.localPosition.z, "blue");
                    index++;
                }
                popmenu.Hide();
                InstantiateObject(tb, asset);
            }
            //GameObject obj = (GameObject)GameObject.Instantiate (asset);
//			if (asset != null) {
//				GameObject prefab = asset as GameObject;
//				GameObject obj = (GameObject)GameObject.Instantiate (prefab, prefab.transform.position, prefab.transform.rotation);
//
//				obj.transform.SetParent (tb.gameObject.transform, false);
//				ApplyItemInfo (obj, Xml.GetChildByAttribute (itemInfos, "id", tb.TrackableName));
//				obj.RegisterClickEvent ();
//			}
        }

        ObjectTracker objectTracker = Vuforia.TrackerManager.Instance.GetTracker <ObjectTracker> ();

        if (!objectTracker.Start())
        {
            Debug.Log("<color=yellow>Tracker Failed to Start.</color>");
        }
    }
Esempio n. 3
0
    IEnumerator LoadDataSet()
    {
        ObjectTracker objectTracker = TrackerManager.Instance.GetTracker <ObjectTracker> ();

        objectTracker.DestroyAllDataSets(false);
        objectTracker.Stop();           // stop tracker so that we can add new dataset

        var tNodes = data.Element("trackings").Nodes();

        foreach (XElement node in tNodes)
        {
            string  dataSetName = Xml.Attribute(node, "src");
            DataSet dataSet     = objectTracker.CreateDataSet();
            if (dataSet.Load(GetAssetsPath(dataSetName), VuforiaUnity.StorageType.STORAGE_ABSOLUTE))
            {
                if (!objectTracker.ActivateDataSet(dataSet))
                {
                    // Note: ImageTracker cannot have more than 100 total targets activated
                    Debug.Log("<color=yellow>Failed to Activate DataSet: " + dataSetName + "</color>");
                }
            }
        }

        //int counter = 0;
        IEnumerable <TrackableBehaviour> tbs = TrackerManager.Instance.GetStateManager().GetTrackableBehaviours();

        foreach (TrackableBehaviour tb in tbs)
        {
            Logger.Log(tb.TrackableName, "purple");
            tb.gameObject.name = "AR-" + tb.TrackableName;

            XElement info = Xml.GetChildByAttribute(itemInfos, "id", tb.TrackableName);
            if (info == null)
            {
                continue;
            }
            string objType = Xml.Attribute(info, "type");
            tb.gameObject.AddComponent <DefaultTrackableEventHandler> ();
            tb.gameObject.AddComponent <CustomTrackableEventHandler> ();
            tb.gameObject.AddComponent <TurnOffBehaviour> ();
            CustomTrackableEventHandler cte = tb.gameObject.GetComponent <CustomTrackableEventHandler> ();
            cte.type         = objType;
            cte.subtitlePath = GetAssetsPath(Xml.Attribute(info, "subtitle"), true);
            UnityEngine.Object asset = null;
            if (objType == "object")
            {
                asset = loadedAssets.ContainsKey(tb.TrackableName) ? loadedAssets [tb.TrackableName] : new GameObject();
            }
            else if (objType == "video")
            {
                asset = planePrefab;
                //Renderer render = (planePrefab).GetComponent<Renderer> ();
                //render.material = videoMaterial;

                cte.videoPath = GetAssetsPath(Xml.Attribute(info, "videosrc"), true);
                //cte.mediaPlayer = mediaPlayer;
            }
            else if (objType == "menu4")
            {
                //asset = planePrefab;
                //Renderer render = (planePrefab).GetComponent<Renderer> ();
                //render.material = videoMaterial;
                //CustomTrackableEventHandler cte = tb.gameObject.GetComponent<CustomTrackableEventHandler> ();
                //cte.videoPath = GetAssetsPath (tb.TrackableName + ".mp4");
                //cte.mediaPlayer = mediaPlayer;
                tb.gameObject.AddComponent <PopMenu> ();
                PopMenu popmenu = tb.gameObject.GetComponent <PopMenu> ();
                popmenu.menuItems = new List <PopMenuItem> ();
                //popmenu.playerMateral = videoMaterial;

                var menuNodes = info.Elements();
                //XElement res = null;
                int index = 0;
                foreach (XElement n in menuNodes)
                {
                    GameObject  planeItem = GameObject.Instantiate(Resources.Load("Prefabs/PlaneItem4")) as GameObject;
                    PopMenuItem pmi       = planeItem.GetComponent <PopMenuItem> ();
                    popmenu.menuItems.Add(pmi);
                    pmi.floatSpeed       = 5f;
                    pmi.floatAmplitude   = 0.03f;
                    pmi.index            = index;
                    pmi.menu             = popmenu;
                    pmi.trackableHandler = cte;
                    planeItem.transform.SetParent(tb.gameObject.transform, false);
                    Vector3 position = planeItem.transform.localPosition;
                    if (index == 1)
                    {
                        planeItem.transform.localPosition = position.SetX(-position.x);
                    }
                    else if (index == 2)
                    {
                        planeItem.transform.localPosition = position.SetZ(-position.z);
                    }
                    else if (index == 3)
                    {
                        planeItem.transform.localPosition = new Vector3(-position.x, position.y, -position.z);
                    }
                    pmi.Initiate();
                    string itemSrc   = Xml.Attribute(n, "src");
                    string videoPath = Xml.Attribute(n, "videosrc");
                    pmi.subtitlePath = GetAssetsPath(Xml.Attribute(n, "subtitle"), true);
                    if (!string.IsNullOrEmpty(videoPath))
                    {
                        pmi.videoPath = GetAssetsPath(videoPath);
                    }
                    else
                    {
                        GameObject prefab = loadedAssets [Xml.Attribute(n, "prefab")] as GameObject;
                        pmi.threeDObject = GameObject.Instantiate(prefab, prefab.transform.position, prefab.transform.rotation) as GameObject;
                        pmi.threeDObject.transform.SetParent(tb.gameObject.transform, false);
                        ApplyItemInfo(pmi.threeDObject, n);
                    }
                    WWW www = new WWW(GetAssetsPath(itemSrc, true));
                    yield return(www);

                    Logger.Log(GetAssetsPath(itemSrc, true) + " " + www.texture.ToString());
                    pmi.material.mainTexture = www.texture;
                    //Logger.Log (planeItem.transform.localPosition.x.ToString() + " " +planeItem.transform.localPosition.y+ " " + planeItem.transform.localPosition.z, "blue");
                    index++;
                }
                popmenu.Hide();
            }
            //GameObject obj = (GameObject)GameObject.Instantiate (asset);
            if (asset != null)
            {
                GameObject prefab = asset as GameObject;
                GameObject obj    = (GameObject)GameObject.Instantiate(prefab, prefab.transform.position, prefab.transform.rotation);

                obj.transform.SetParent(tb.gameObject.transform, false);
                ApplyItemInfo(obj, Xml.GetChildByAttribute(itemInfos, "id", tb.TrackableName));
            }
            //obj.gameObject.SetActive (true);
        }


        if (!objectTracker.Start())
        {
            Debug.Log("<color=yellow>Tracker Failed to Start.</color>");
        }
    }