private static IEnumerator importVCB(OnImportReadyDelegate _onReady, OnImportFinishDelegate _onFinish, OnImportErrorDelegate _onError) { string path = System.IO.Path.Combine(VRXX.Platform.GetStreamingAssetsPath(), "latest.vcb"); WWW www = new WWW(path); yield return(www); if (null != www.error) { _onError(www.error); Log.Error("EditorMgr::importVCB", www.error); yield break; } _onReady(); yield return(1); try { //Read json Log.Info("EditorMgr::importVCB", "parse bean success"); JSONNode root = JSON.Parse(www.text); JSONNode nodeSets = root["sets"]; JSONNode nodeKV = root["kv"]; JSONNode nodeHash = root["hash"]; //parse slates JSONArray arySlates = nodeSets["screenplay_slates_guids"].AsArray; List <Dictionary <string, string> > assets = new List <Dictionary <string, string> >(); //create slate foreach (JSONNode slateNode in arySlates) { string slateUUID = slateNode.Value; Log.Trace("EditorMgr:importVCB", "new a image {0}", slateUUID); NewImage(slateUUID); //parse skybox string skyboxFile = nodeKV[string.Format("screenplay_slate_guid_1_preload_skybox_file:[{0}]", slateUUID)].Value; string skyboxPackage = nodeKV[string.Format("screenplay_slate_guid_1_preload_skybox_package:[{0}]", slateUUID)].Value; Dictionary <string, string> assetSkybox = new Dictionary <string, string>(); assetSkybox["package"] = skyboxPackage; assetSkybox["file"] = skyboxFile; assetSkybox["image"] = slateUUID; assetSkybox["uuid"] = ""; assetSkybox["type"] = "skybox"; assets.Add(assetSkybox); //parse agent JSONArray aryAgents = nodeSets[string.Format("screenplay_slate_guid_1_preloads_guids:[{0}]", slateUUID)].AsArray; foreach (JSONNode agentNode in aryAgents) { string agentUUID = agentNode.Value; Log.Trace("EditorMgr:importVCB", "import a agent {0}", agentUUID); string agentFile = nodeKV[string.Format("screenplay_slate_guid_1_preload_guid_2_asset_file:[{0}]:[{1}]", slateUUID, agentUUID)].Value; string agentPackage = nodeKV[string.Format("screenplay_slate_guid_1_preload_guid_2_asset_package:[{0}]:[{1}]", slateUUID, agentUUID)].Value; float posX = nodeKV[string.Format("screenplay_preload_guid_1_px:[{0}]", agentUUID)].AsFloat; float posY = nodeKV[string.Format("screenplay_preload_guid_1_py:[{0}]", agentUUID)].AsFloat; float posZ = nodeKV[string.Format("screenplay_preload_guid_1_pz:[{0}]", agentUUID)].AsFloat; float rotX = nodeKV[string.Format("screenplay_preload_guid_1_rx:[{0}]", agentUUID)].AsFloat; float rotY = nodeKV[string.Format("screenplay_preload_guid_1_ry:[{0}]", agentUUID)].AsFloat; float rotZ = nodeKV[string.Format("screenplay_preload_guid_1_rz:[{0}]", agentUUID)].AsFloat; float scaleX = nodeKV[string.Format("screenplay_preload_guid_1_sx:[{0}]", agentUUID)].AsFloat; float scaleY = nodeKV[string.Format("screenplay_preload_guid_1_sy:[{0}]", agentUUID)].AsFloat; float scaleZ = nodeKV[string.Format("screenplay_preload_guid_1_sz:[{0}]", agentUUID)].AsFloat; Dictionary <string, string> assetAgent = new Dictionary <string, string>(); assetAgent["package"] = agentPackage; assetAgent["file"] = agentFile; assetAgent["image"] = slateUUID; assetAgent["uuid"] = agentUUID; assetAgent["type"] = "agent"; assetAgent["pos.x"] = posX.ToString(); assetAgent["pos.y"] = posY.ToString(); assetAgent["pos.z"] = posZ.ToString(); assetAgent["rot.x"] = rotX.ToString(); assetAgent["rot.y"] = rotY.ToString(); assetAgent["rot.z"] = rotZ.ToString(); assetAgent["scale.x"] = scaleX.ToString(); assetAgent["scale.y"] = scaleY.ToString(); assetAgent["scale.z"] = scaleZ.ToString(); assets.Add(assetAgent); } //foreach (JSONNode agentNode in aryAgents) //parse trigger JSONArray aryTriggers = nodeSets[string.Format("screenplay_slate_guid_1_triggers_guids:[{0}]", slateUUID)].AsArray; foreach (JSONNode triggerNode in aryTriggers) { string triggerUUID = triggerNode.Value; Log.Trace("EditorMgr:importVCB", "import a trigger {0}", triggerUUID); float posX = nodeKV[string.Format("diagram_trigger_1_px:[{0}]", triggerUUID)].AsFloat; float posY = nodeKV[string.Format("diagram_trigger_1_py:[{0}]", triggerUUID)].AsFloat; float posZ = nodeKV[string.Format("diagram_trigger_1_pz:[{0}]", triggerUUID)].AsFloat; float rotX = nodeKV[string.Format("diagram_trigger_1_rx:[{0}]", triggerUUID)].AsFloat; float rotY = nodeKV[string.Format("diagram_trigger_1_ry:[{0}]", triggerUUID)].AsFloat; float rotZ = nodeKV[string.Format("diagram_trigger_1_rz:[{0}]", triggerUUID)].AsFloat; string alias = nodeKV[string.Format("diagram_trigger_1_alias:[{0}]", triggerUUID)].Value; string type = nodeKV[string.Format("diagram_trigger_1_type:[{0}]", triggerUUID)].Value; if (type.Equals("sight")) { Log.Trace("EditorMgr:importVCB", "update sight property {0}", triggerUUID); int icon = nodeKV[string.Format("diagram_gaze_1_icon:[{0}]", triggerUUID)].AsInt; int colorR = nodeKV[string.Format("diagram_gaze_1_color_r:[{0}]", triggerUUID)].AsInt; int colorG = nodeKV[string.Format("diagram_gaze_1_color_g:[{0}]", triggerUUID)].AsInt; int colorB = nodeKV[string.Format("diagram_gaze_1_color_b:[{0}]", triggerUUID)].AsInt; int colorA = nodeKV[string.Format("diagram_gaze_1_color_a:[{0}]", triggerUUID)].AsInt; TriggerMgr.NewEditorSightTrigger(triggerUUID); TriggerMgr.AdjustSightTrigger(triggerUUID, new Vector3(posX, posY, posZ), new Vector3(rotX, rotY, rotZ)); TriggerMgr.ModifyGazeAlias(triggerUUID, alias); TriggerMgr.ModifyGazeIcon(triggerUUID, icon); TriggerMgr.ModifyGazeColor(triggerUUID, colorR, colorG, colorB, colorA); Editor.Image image = fsm.FindState(slateUUID) as Editor.Image; image.triggers.Add(triggerUUID); } } }// foreach (JSONNode slateNode in arySlates) TriggerMgr.ToggleAllTrigger(false); Log.Debug("EditorMgr:importVCB", "Batch preload asset"); batchPreloadAsset(assets, () => { _onFinish(); }); } catch (System.Exception e) { Log.Exception("EditorMgr::importVX", e); } }
public static void ImportVCB(OnImportReadyDelegate _onReady, OnImportFinishDelegate _onFinish, OnImportErrorDelegate _onError) { VRXX.Manager.CoroutineMgr.Start(importVCB(_onReady, _onFinish, _onError)); }