Esempio n. 1
0
 public static void UseUGCSkybox(string _file)
 {
     UGCMgr.Res   res = UGCMgr.Find(_file);
     Editor.Image img = (fsm.current as Editor.Image);
     img.skybox = res.data as Material;
     CameraMgr.ApplySkybox(res.data as Material);
 }
Esempio n. 2
0
        public static void Run(byte[] _beanData)
        {
            Log.Info("BeanMgr", "Run Bean data, size is  [{0}]", _beanData.Length);
            int    beanSize;
            string beanJson = takeBeanJsonFromData(_beanData, out beanSize);

            Log.Info("BeanMgr", "Run Bean {0}", beanJson);
            parseBeanJson(beanJson);
            int offset = 4 + beanSize;

            int ugcfiles_count = bytesToInt(_beanData, offset);

            offset += 4;
            Log.Info("BeanMgr", "has {0} ugc files", ugcfiles_count);
            //skip ugcfiles_count;

            for (int i = 0; i < ugcfiles_count; ++i)
            {
                int size_ugcfile_filename = bytesToInt(_beanData, offset);
                offset += 4;
                string filename = bytesToString(_beanData, offset, size_ugcfile_filename);
                Log.Info("BeanMgr", "take ugcfile : [{0}]", filename);
                offset += size_ugcfile_filename;
                int size_ugcfile_data = bytesToInt(_beanData, offset);
                offset += 4;
                byte[] filedata = new byte[size_ugcfile_data];
                System.Array.Copy(_beanData, offset, filedata, 0, size_ugcfile_data);
                UGCMgr.Cache(filename, filedata);
                offset += size_ugcfile_data;
            }

            int cachefiles_count = bytesToInt(_beanData, offset);

            offset += 4;
            Log.Info("BeanMgr", "has {0} cache files", cachefiles_count);
            //skip ugcfiles_count;
            for (int i = 0; i < cachefiles_count; ++i)
            {
                int size_cachefile_filename = bytesToInt(_beanData, offset);
                offset += 4;
                string filename = bytesToString(_beanData, offset, size_cachefile_filename);
                Log.Info("BeanMgr", "take cachefile : [{0}]", filename);
                offset += size_cachefile_filename;
                int size_cachefile_data = bytesToInt(_beanData, offset);
                offset += 4;
                byte[] filedata = new byte[size_cachefile_data];
                System.Array.Copy(_beanData, offset, filedata, 0, size_cachefile_data);
                offset += size_cachefile_data;

                UGCMgr.Cache(filename, filedata);
            }

            SlateMgr.Run();
        }
Esempio n. 3
0
        public void DoEnter()
        {
            //preload assets
            foreach (Asset asset in assets.Values)
            {
                // asset has format like as .wav
                if (asset.file.Contains("."))
                {
                    byte[] data = UGCMgr.Take(asset.file);
                    if (null == data)
                    {
                        this.LogError("Missing asset, group:{0} package:{1} file:{2} ", asset.group, asset.package, asset.file);
                        continue;
                    }
                    if (asset.group.Equals("skybox"))
                    {
                        Material skybox = UGCMgr.BuildSkybox(data);
                        CameraMgr.ApplySkybox(skybox);
                    }
                }
                else
                {
                    Object obj = ResourceMgr.FindFromPreload(asset.package, asset.file);
                    if (null == obj)
                    {
                        this.LogError("Missing asset, group:{0} package:{1} file:{2} ", asset.group, asset.package, asset.file);
                        continue;
                    }

                    if (asset.group.Equals("agent"))
                    {
                        GameObject clone = ResourceMgr.CloneGameObject(asset.package, asset.file, asset.guid);
                        agents.Add(asset.guid);
                        clone.transform.position   = new Vector3(asset.px, asset.py, asset.pz);
                        clone.transform.rotation   = Quaternion.Euler(asset.rx, asset.ry, asset.rz);
                        clone.transform.localScale = new Vector3(asset.sx, asset.sy, asset.sz);

                        if (asset.gaze)
                        {
                            ReticleHandler handler = clone.AddComponent <ReticleHandler>();
                            handler.path    = asset.slate;
                            handler.trigger = asset.gazeAlias;
                            EventTrigger et = clone.AddComponent <EventTrigger>();

                            EventTrigger.Entry entryEnter = new EventTrigger.Entry();
                            entryEnter.eventID = EventTriggerType.PointerEnter;
                            entryEnter.callback.AddListener((data) => { handler.onPointerEnter(); });
                            et.triggers.Add(entryEnter);

                            EventTrigger.Entry entryExit = new EventTrigger.Entry();
                            entryExit.eventID = EventTriggerType.PointerExit;
                            entryExit.callback.AddListener((data) => { handler.onPointerExit(); });
                            et.triggers.Add(entryExit);

                            EventTrigger.Entry entryClick = new EventTrigger.Entry();
                            entryClick.eventID = EventTriggerType.PointerClick;
                            entryClick.callback.AddListener((data) => { handler.onPointerClick(); });
                            et.triggers.Add(entryClick);

                            Collider collider = clone.GetComponent <Collider>();
                            if (null != collider)
                            {
                                collider.enabled = true;
                            }
                        }
                    }
                    else if (asset.group.Equals("skybox"))
                    {
                        CameraMgr.ApplySkybox(obj as Material);
                    }
                }
            }

            //hide all triggers
            TriggerMgr.ToggleAllTrigger(false);
            //show trigger in current slate
            foreach (string trigger in triggers)
            {
                TriggerMgr.ToggleTrigger(trigger, true);
            }

            // execute startup blocks
            foreach (string guid in blocks)
            {
                Block block = BlockMgr.FindBlock(guid);
                if (block.action.Equals("Entry:Startup"))
                {
                    block.Execute();
                }
            }
        }
Esempio n. 4
0
        private static IEnumerator importVX()
        {
            string path = System.IO.Path.Combine(VRXX.Platform.GetPersistentDataPath(), "latest.vx");
            WWW    www  = new WWW(path);

            yield return(www);

            if (null != www.error)
            {
                Log.Error("EditorMgr::importVX", www.error);
                yield break;
            }

            try
            {
                //Read json
                int    jsonSize = VRXX.Convert.ByteToInt(www.bytes, 0);
                string json     = VRXX.Convert.ByteToString(www.bytes, 4, jsonSize);

                Log.Info("EditorMgr::importVX", "parse bean success");

                JSONNode  root     = JSON.Parse(json);
                JSONArray slateAry = root["slates"].AsArray;

                foreach (JSONNode slateNode in slateAry)
                {
                    string slateUUID = slateNode["guid"].Value;
                    Log.Trace("EditorMgr:importVX", "new a image {0}", slateUUID);
                    NewImage(slateUUID);
                    Editor.Image image = fsm.FindState(slateUUID) as Editor.Image;

                    JSONArray preloadAry = slateNode["preloads"].AsArray;
                    foreach (JSONNode node in preloadAry)
                    {
                        string group   = node["group"].Value;
                        string package = node["package"].Value;
                        string file    = node["file"].Value;
                        string guid    = node["guid"].Value;
                        //string id = package + "@" + file;

                        if (group.Equals("skybox"))
                        {
                            ResourceMgr.PreloadAsset(package, file
                                                     , () =>
                            {
                                //startLoading();
                            }
                                                     , (_obj) =>
                            {
                                image.skybox = _obj as Material;
                            }
                                                     , (_err) =>
                            {
                                //onNotify(_err);
                            });
                        }
                    }

                    JSONArray triggerAry = slateNode["triggers"].AsArray;
                    foreach (JSONNode node in triggerAry)
                    {
                        string cloneUUID = node["uuid"].Value;
                        string alias     = node["alias"].Value;
                        float  px        = node["px"].AsFloat;
                        float  py        = node["py"].AsFloat;
                        float  pz        = node["pz"].AsFloat;
                        float  rx        = node["rx"].AsFloat;
                        float  ry        = node["ry"].AsFloat;
                        float  rz        = node["rz"].AsFloat;
                    }
                }

                //offset
                int count_ugcfile = VRXX.Convert.ByteToInt(www.bytes, 4 + jsonSize);
                Log.Info("EditorMgr", "has {0} ugcfiles", count_ugcfile);

                int offset = 4 + jsonSize + 4;
                for (int i = 0; i < count_ugcfile; ++i)
                {
                    int filenamesize = VRXX.Convert.ByteToInt(www.bytes, offset);
                    offset += 4;

                    string filename = VRXX.Convert.ByteToString(www.bytes, offset, filenamesize);
                    offset += filenamesize;

                    Log.Info("EditorMgr", "ugcfile is {0}", filename);

                    int filesize = VRXX.Convert.ByteToInt(www.bytes, offset);
                    offset += 4;

                    byte[] bytes = new byte[filesize];
                    System.Array.Copy(www.bytes, offset, bytes, 0, filesize);
                    offset += filesize;
                    UGCMgr.Cache(filename, bytes);
                }
            }
            catch (System.Exception e)
            {
                Log.Exception("EditorMgr::importVX", e);
            }
            JSAPI.MessageToJS(JSAPI.MSG.JSEditorOnImportFinish, "", "");
        }