Exemplo n.º 1
0
    IEnumerator OnItemClickHandler()
    {
        int idx = slider.index;

        Logger.Log("clicked " + idx);
        okCancelPanel.Reset();
        Enabled      = false;
        configLoader = new ConfigLoader();
        //configLoader.loadedHandler = FileLoaded;
        configLoader.progressHandler = FileProgressing;
        configLoader.okCancelPanel   = okCancelPanel;
        XElement itemsEle = layout.Element("items");
        XElement item     = Xml.GetChild(itemsEle, idx);
        string   type     = Xml.Attribute(item, "type");
        string   name     = Xml.Attribute(item, "title");

        yield return(configLoader.LoadConfig(name + "/config.xml"));

        progressPanel.Hide();
        Enabled = true;
        if (!configLoader.forceBreak && !okCancelPanel.isCancel)
        {
            Hashtable arg = new Hashtable();
            arg.Add("type", type);
            arg.Add("name", name);
            arg.Add("data", Xml.GetChildByAttribute(itemsEle, "title", name));
            SceneManagerExtension.LoadScene("Scan", arg);
        }
    }
Exemplo n.º 2
0
    void InstantiateVideoObject(XElement info, TrackableBehaviour tb, out UnityEngine.Object asset)
    {
        asset = planePrefab;
        CustomTrackableEventHandler cte = tb.gameObject.GetComponent <CustomTrackableEventHandler> ();

        cte.videoPath = GetAssetsPath(Xml.Attribute(info, "videosrc"), true);
        InstantiateObject(tb, asset);
    }
Exemplo n.º 3
0
    IEnumerator readConfig()
    {
        if (initialized)
        {
            OnLoaded();
            yield return(null);
        }
        yield return(Request.ReadRemote("version.xml", (str) => {
            Debug.Log(str);
            XElement verXml = XDocument.Parse(str).Root;
            Version v = new Version(Xml.Attribute(verXml, "version"));
            if (v.GreaterThan(Director.version))
            {
                InitVersionPanel(Xml.Attribute(verXml, "forceupdate") == "true",
                                 Application.platform == RuntimePlatform.IPhonePlayer?Xml.Attribute(verXml, "ios"):Xml.Attribute(verXml, "android"));
            }
            else
            {
                versionLoaded = true;
            }
        }, () => versionLoaded = true));

        while (!versionLoaded)
        {
            yield return(null);
        }
        ConfigLoader loader = new ConfigLoader();

        //StartCoroutine (PrepareForStart (2));
        yield return(loader.LoadConfig("ui/config.xml"));

        yield return(Request.ReadPersistent("ui/config.xml", str => configStr = str));

        if (!String.IsNullOrEmpty(configStr))
        {
            yield return(I18n.Initialise(language));

            Director.Initialize(XDocument.Parse(configStr).Root);
            yield return(Director.Load());

            Director.style.mainColor = mainColor;
            Director.style.uiGrey    = uiGrey;
            OnLoaded();
        }
        else
        {
            if (I18n.language == Language.Chinese)
            {
                message.text = "初始化失败,请检查网络连接";
            }
            else
            {
                message.text = "Failed to initialise, please check your Internet Connection";
            }
        }
    }
    void InstantiateModelObject(XElement info, TrackableBehaviour tb, out UnityEngine.Object asset)
    {
        GameObject buttonCanvasPrefab = null, buttonPrefab = null;
        string     prefabName = Xml.Attribute(info, "prefab");

        asset = GetAsset(prefabName);
        var        buttonNodes = info.Elements();
        GameObject bPanel      = null;
        List <ToggleButtonShowHide> buttons = new List <ToggleButtonShowHide> ();

        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> ();
            ToggleButtonShowHide tgsh = button.GetComponent <ToggleButtonShowHide> ();
            tgsh.label          = Xml.Attribute(n, "label");
            tgsh.defaultShowing = Xml.Attribute(n, "show") == "false";
            //tgsh.target = asset as GameObject;
            tgsh.targetName = Xml.Attribute(n, "id");
            button.transform.SetParent(bPanel.transform.GetChild(0), false);
            buttons.Add(tgsh);
        }
        CustomTrackableEventHandler cte = tb.gameObject.GetComponent <CustomTrackableEventHandler> ();
        GameObject obj = InstantiateObject(tb, asset);

        obj.name = "model";
        TouchRotate touchrotate = obj.AddComponent <TouchRotate> ();

        //TouchRotate touchrotate = obj.GetComponent<TouchRotate> ();
        touchrotate.scalable       = Xml.Boolean(info, "scalable", true);
        touchrotate.upEnabled      = Xml.Boolean(info, "upEnabled", true);
        touchrotate.upDireciton    = Xml.Attribute(info, "upDirection", "x");
        touchrotate.rightEnabled   = Xml.Boolean(info, "rightEnabled", true);
        touchrotate.rightDirection = Xml.Attribute(info, "rightDirection", "-z");
        ITrackableController[] controllers = obj.GetComponents <ITrackableController> ();
        cte.controllers.AddRange(controllers);
        for (int i = 0; i < buttons.Count; i++)
        {
            buttons [i].target = obj;
            cte.controllers.Add(buttons [i]);
        }
    }
Exemplo n.º 5
0
    public static void Initialize(XElement config)
    {
        trackerManager = new TrackerManager();
        style          = new UIStyle();
        var trackers = config.Element("trackers").Elements();

        foreach (XElement n in trackers)
        {
            string   name    = Xml.Attribute(n, "name");
            ITracker tracker = null;
            if (name == "unity")
            {
                tracker = new UnityTracker();
            }
            else if (name == "umeng")
            {
                string appid = "";
                                #if UNITY_IPHONE
                appid = Xml.Attribute(n, "iosid");
                                #else
                appid = Xml.Attribute(n, "androidid");
                                #endif
                if (!string.IsNullOrEmpty(appid))
                {
                    tracker = new UmengTracker(appid);
                }
            }
            if (tracker != null)
            {
                var events = n.Element("events");
                if (events != null)
                {
                    var trackevents = events.Elements();
                    foreach (XElement nn in trackevents)
                    {
                        string eventname = Xml.Attribute(nn, "name");
                        tracker.eventBlacklist.Add(eventname, eventname);
                    }
                }
                trackerManager.AddTracker(tracker);
            }
        }
        userBehavior = new UserBehavior();
    }
Exemplo n.º 6
0
    void Update()
    {
        if (data == null || !playing)
        {
            return;
        }
        timing += Time.deltaTime;
        var nodes = data.Nodes();

        foreach (XElement node in nodes)
        {
            float time = float.Parse(Xml.Attribute(node, "time"));
            if (timing > time)
            {
                text.text = node.Value;
            }
            //Logger.Log (time.ToString () + "  " + node.Value);
        }
    }
Exemplo n.º 7
0
    IEnumerator initScene()
    {
        yield return(Request.ReadPersistent("ui/ui.xml", LayoutLoaded));

        if (layout != null)
        {
            XElement itemsEle = layout.Element("items");
            var      items    = itemsEle.Elements();
            int      index    = 0;
            foreach (XElement item in items)
            {
                string desc  = Xml.Attribute(item, "desc");
                string title = Xml.Attribute(item, "title");
                Logger.Log(desc + " " + title, "green");
                slider.SetItemDetails(index, I18n.Translate(title), I18n.Translate(desc));
                index++;
//				string help = Xml.Attribute (item, "help");
//				string icon = Xml.Attribute (item, "icon");
//				GameObject obj = GameObject.Instantiate (selectionItem);
//				//obj.transform.r
//				//obj.transform.parent = itemsPanel.gameObject.transform;
//				//obj.GetComponent<RectTransform> ().localPosition = Vector3.zero;
//				obj.transform.SetParent(itemsPanel.transform, false);
//				RectTransform rectT = obj.GetComponent<RectTransform> ();
//				rectT.localPosition = new Vector3 (rectT.localPosition.x, rectT.localPosition.y-168 * index);
//				selectionItems.Add (obj);
//
//				SelectionItem itemComp = obj.GetComponent<SelectionItem> ();
//				itemComp.name = title;
//				itemComp.type = Xml.Attribute (item, "type");
//				itemComp.title.text = I18n.Translate (title);
//				itemComp.description.text = I18n.Translate (desc);
//				itemComp.btnInfo.SetActive (false);// (!string.IsNullOrEmpty (help));
//				itemComp.helpLink = Request.RemoteUrl + help;
//				itemComp.SetOnClick (OnItemClick);
////				WWW www = new WWW(Path.Combine(Application.persistentDataPath, "ui/"+icon));
////				itemComp.image.sprite = Sprite.Create(www.texture, new Rect(0,0,www.texture.width, www.texture.height), new Vector2(0,0));
//				StartCoroutine(LoadIcon ("ui/"+icon, itemComp.image));
//				index++;
            }
        }
    }
    protected void ClearAndLoadDataSet()
    {
        ObjectTracker objectTracker = Vuforia.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>");
                }
            }
        }
    }
    void InstantiateVideoObject(XElement info, TrackableBehaviour tb, out UnityEngine.Object asset)
    {
        asset = planePrefab;
        CustomTrackableEventHandler cte = tb.gameObject.GetComponent <CustomTrackableEventHandler> ();

        cte.videoPath = GetAssetsPath(Xml.Attribute(info, "videosrc"), true);
        GameObject obj    = InstantiateObject(tb, asset);
        bool       showBg = Xml.Boolean(info, "showbg", false);

        if (showBg)
        {
            GameObject           videoPlane = obj.GetChildByName("plane");
            Vector3              scale      = videoPlane.transform.localScale;
            ImageTargetBehaviour itg        = (ImageTargetBehaviour)tb;
            Vector3              size       = itg.GetSize();
            Logger.Log(size.ToString(), "blue");
            float imageTargetRatio = size.x / size.y;
            if (imageTargetRatio > 1)
            {
                obj.transform.localScale = new Vector3(1, 1, 1 / imageTargetRatio);
            }
            else
            {
                obj.transform.localScale = new Vector3(imageTargetRatio, 1, 1);
            }
            float ratio = Xml.Float(info, "ratio", 1);
            if (ratio > size.x / size.y)
            {
                videoPlane.transform.localScale = scale.SetZ(scale.z * size.x / size.y / ratio);
            }
            else
            {
                videoPlane.transform.localScale = scale.SetX(scale.x * size.y / size.x * ratio);
            }
        }
    }
Exemplo n.º 10
0
//	void Start ()
//	{
//		StartCoroutine (initScene ());
//	}

    public IEnumerator Initialize()
    {
        yield return(Request.ReadPersistent("ui/ui.xml", LayoutLoaded));

        if (layout != null)
        {
            XElement      itemsEle = layout.Element("items");
            var           items    = itemsEle.Elements();
            List <string> icons    = new List <string> ();
            foreach (XElement item in items)
            {
                if (!(Xml.Attribute(item, "platform") == "ios" && Application.platform != RuntimePlatform.IPhonePlayer))
                {
                    string _desc  = Xml.Attribute(item, "desc");
                    string _icon  = Xml.Attribute(item, "icon");
                    string _title = Xml.Attribute(item, "title");
                    //string sub = Xml.Attribute (item, "help");
                    string _subtitle = Xml.Attribute(item, "subtitle");
                    string _scene    = Xml.Attribute(item, "scene", "Scan");
                    titles.Add(_title);
                    subtitles.Add(_subtitle);
                    descs.Add(_desc);
                    icons.Add(_icon);
                    scenes.Add(_scene);
                }
            }
            slider.onIndexChanged = (idx) => {
                title.text       = I18n.Translate(titles [idx]);
                description.text = I18n.Translate(descs [idx]);
                subtitle.text    = I18n.Translate(subtitles [idx]);
                Configuration.instant.sceneName = scenes[idx];
            };
            Configuration.instant.sceneName = scenes [0];
            yield return(slider.Initialize(icons));
        }
    }
Exemplo n.º 11
0
    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>");
        }
    }
Exemplo n.º 12
0
	protected virtual void SetTitle(){
		XElement info = scene.GetCurrentItemInfo ();
		Logger.Log ("set title" + info);
		if(info!=null)
			scene.title.text = Xml.Attribute(info, "title");
	}
Exemplo n.º 13
0
    public IEnumerator LoadConfig(string url)
    {
        localConfig       = null;
        remoteConfig      = null;
        forceBreak        = false;
        fileLoadedHandler = loadedHandler;
        //currentLoad = 0;
        //totalLoad = 0;
        fileSize = 0f;
        Logger.Log(url);
        yield return(Request.ReadPersistent(url, str => localConfig = XDocument.Parse(str).Root));

        yield return(Request.ReadRemote(url, str => remoteConfig = XDocument.Parse(str).Root));

        string platform = GetPlatformName();

        Dictionary <string, float> filenames = new Dictionary <string, float> ();

        if (remoteConfig == null)
        {
            Debug.Log("remoteConfig = null");
        }
        else if (localConfig == null)
        {
            Debug.Log("remoteConfig != null");
            //fileSize = Xml.Float(remoteConfig.Element ("all"), "size");
            var nodes = remoteConfig.Element("all").Elements();
            foreach (XElement node in nodes)
            {
                filenames.Add(node.Value, Xml.Float(node, "size"));
            }
        }
        else
        {
            string localVersion  = Xml.Version(localConfig);
            string preVersion    = Xml.Attribute(remoteConfig, "preversion");
            string remoteVersion = Xml.Version(remoteConfig);
            //float filesize = Xml.Float(remoteConfig, "size");
            if (localVersion != remoteVersion || Director.environment == Environment.Development)
            {
                //fileSize = Xml.Float(remoteConfig.Element ("update"), "size");
                var nodes = remoteConfig.Element("update").Elements();
                //List<string> updates = new List<string> ();
                foreach (XElement node in nodes)
                {
                    filenames.Add(node.Value, Xml.Float(node, "size"));
                }
                int    idx  = url.IndexOf("/");
                string path = idx == -1 ? url : url.Substring(0, idx);
                while (localVersion != preVersion)
                {
                    tempConfig = null;
                    yield return(Request.ReadRemote(path + "/version/" + preVersion + ".xml", str => tempConfig = XDocument.Parse(str).Root));

                    if (tempConfig == null)
                    {
                        var all = remoteConfig.Element("all").Elements();
                        filenames = new Dictionary <string, float> ();
                        foreach (XElement node in all)
                        {
                            filenames.Add(node.Value, Xml.Float(node, "size"));
                        }
                        break;
                    }
                    else
                    {
                        preVersion = Xml.Attribute(tempConfig, "preversion");
                        var updateNotes = tempConfig.Element("update").Elements();
                        foreach (XElement node in updateNotes)
                        {
                            //Logger.Log (node.Value,"blue");
                            if (!filenames.ContainsKey(node.Value))
                            {
                                filenames.Add(node.Value, Xml.Float(node, "size"));
                            }
                        }
                    }
                }
            }
        }
        foreach (string key in filenames.Keys)
        {
            fileSize += filenames [key];
        }
        if (okCancelPanel != null && Application.internetReachability != NetworkReachability.ReachableViaLocalAreaNetwork && fileSize > 3)
        {
            //if (panel != null && filesize > 3) {
            yield return(okCancelPanel.Show(string.Format(I18n.Translate("not_in_wifi"), fileSize.ToString() + "M")));

            if (okCancelPanel.isCancel)
            {
                yield break;
            }
        }
        yield return(LoadFiles(filenames, url));
    }
Exemplo n.º 14
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>");
        }
    }
Exemplo n.º 15
0
 public string GetValue(string name)
 {
     return(Xml.Attribute(data, name));
 }
Exemplo n.º 16
0
    IEnumerator StartGame()
    {
        loadedAssets = new Dictionary <string, UnityEngine.Object> ();
        SetState("idle");
        yield return(Request.ReadPersistent(sceneName + "/iteminfos.xml", str => itemInfos = XDocument.Parse(str).Root));

        var abNodes = data.Element("assetbundles").Nodes();

        foreach (XElement node in abNodes)
        {
            AssetBundle bundle  = null;
            string      abName  = Xml.Attribute(node, "src");
            string      keyName = sceneName + "_" + abName;
            Logger.Log(abName + " " + keyName, "blue");
            if (!AssetBundleManager.bundles.ContainsKey(keyName))
            {
                Logger.Log(GetAssetsPath(abName, true), "purple");
                WWW www = new WWW(GetAssetsPath(abName, true));
                yield return(www);

                if (string.IsNullOrEmpty(www.error))
                {
                    bundle = www.assetBundle;
                    AssetBundleManager.bundles.Add(keyName, bundle);
                }
                else
                {
                    Logger.Log(www.error, "blue");
                }
            }
            else
            {
                bundle = AssetBundleManager.bundles [keyName];
            }
            Logger.Log(bundle ? bundle.ToString() : "bundle is null", "blue");
            if (bundle != null)
            {
                string[] assetNames;
                try {
                    assetNames = bundle.GetAllAssetNames();
                    foreach (string name in assetNames)
                    {
                        string simpleName = Path.GetFileNameWithoutExtension(name);
                        //Instantiate(bundle.LoadAsset());
                        Logger.Log(simpleName, "purple");
                        if (loadedAssets.ContainsKey(simpleName))
                        {
                            loadedAssets [simpleName] = bundle.LoadAsset(simpleName);
                        }
                        else
                        {
                            loadedAssets.Add(simpleName, bundle.LoadAsset(simpleName));
                        }
                    }
                } catch (Exception e) {
                    //Log (e.StackTrace);
                }
            }
        }
        PrintLoadedAssets();
        StartCoroutine(LoadDataSet());
        //infoPanel.SetActive (Director.userBehavior.GetValue ("scantip") == "0");
    }
Exemplo n.º 17
0
        internal DocProperty(DocX document, XElement xml) : base(document, xml)
        {
            var instr = Xml.Attribute(XName.Get("instr", "http://schemas.openxmlformats.org/wordprocessingml/2006/main")).Value;

            this.Name = _extractName.Match(instr.Trim()).Groups["name"].Value;
        }
Exemplo n.º 18
0
    public static IEnumerator LoadConfig(string url, Action <int, int> loadedHandler = null, OKCancelPanel panel = null)
    {
        localConfig       = null;
        remoteConfig      = null;
        forceBreak        = false;
        fileLoadedHandler = loadedHandler;
        Logger.Log(url);
        yield return(Request.ReadPersistent(url, str => Config.localConfig = XDocument.Parse(str).Root));

        yield return(Request.ReadRemote(url, str => Config.remoteConfig = XDocument.Parse(str).Root));

        string platform = GetPlatformName();

        if (remoteConfig == null)
        {
            Debug.Log("remoteConfig = null");
        }
        else if (localConfig == null)
        {
            Debug.Log("remoteConfig != null");
//			var nodes = remoteConfig.Elements ();
//			int count = 0;
//			foreach (XElement node in nodes)
//				count++;
//			if (fileLoadedHandler != null) {
//				fileLoadedHandler.Invoke (0, count);
//			}
//			int index = 0;
//			foreach (XElement node in nodes) {
//				index++;
//				yield return Request.DownloadFile (node.Value.Replace ("{%platform%}", platform), node.Value.Replace ("{%platform%}", ""));
//				if (forceBreak) {
//					yield break;
//				} else {
//					if (fileLoadedHandler != null) {
//						fileLoadedHandler.Invoke (index, count);
//					}
//				}
//			}
//			//Debug.Log ("remoteConfig: " + remoteConfig.ToString ());
//			File.WriteAllText (Path.Combine(Application.persistentDataPath,  url), remoteConfig.ToString());
            var           nodes = remoteConfig.Element("all").Elements();
            List <string> names = new List <string> ();
            foreach (XElement node in nodes)
            {
                names.Add(node.Value);
            }
            yield return(LoadFiles(names, url));
        }
        else
        {
            string localVersion  = Xml.Version(localConfig);
            string preVersion    = Xml.Attribute(remoteConfig, "preversion");
            string remoteVersion = Xml.Version(remoteConfig);
            float  filesize      = Xml.Float(remoteConfig, "size");
            if (localVersion != remoteVersion)
            {
                if (panel != null && Application.internetReachability != NetworkReachability.ReachableViaLocalAreaNetwork && filesize > 3)
                {
                    //if (panel != null && filesize > 3) {
                    yield return(panel.Show(string.Format(I18n.Translate("not_in_wifi"), filesize.ToString() + "M")));

                    if (panel.isCancel)
                    {
                        yield break;
                    }
                }
                var           nodes   = remoteConfig.Element("update").Elements();
                List <string> updates = new List <string> ();
                foreach (XElement node in nodes)
                {
                    updates.Add(node.Value);
                }
                int    idx  = url.IndexOf("/");
                string path = idx == -1 ? url : url.Substring(0, idx);
                while (localVersion != preVersion)
                {
                    Config.tempConfig = null;
                    yield return(Request.ReadRemote(path + "/version/" + preVersion + ".xml", str => Config.tempConfig = XDocument.Parse(str).Root));

                    if (tempConfig == null)
                    {
                        var all = remoteConfig.Element("all").Elements();
                        updates = new List <string> ();
                        foreach (XElement node in all)
                        {
                            updates.Add(node.Value);
                        }
                        break;
                    }
                    else
                    {
                        preVersion = Xml.Attribute(tempConfig, "preversion");
                        var updateNotes = tempConfig.Element("update").Elements();
                        foreach (XElement node in updateNotes)
                        {
                            Logger.Log(node.Value, "blue");
                            if (!updates.Contains(node.Value))
                            {
                                updates.Add(node.Value);
                            }
                        }
                    }
                }
                yield return(LoadFiles(updates, url));;
            }
        }
    }