コード例 #1
0
        public IEnumerator LoadAsset()
        {
            WWW www = WWW.LoadFromCacheOrDownload(CustomObjectsServer.AssetPath, 1);

            yield return(www);

            if (www.error != null)
            {
                Logger.LogError("Error loading asset. " + www.error);
                //return;
            }
            bundle = www.assetBundle;
            www.Dispose();

            GameObject           ourobject = new GameObject();
            LoadObjectFromBundle handler   = ourobject.AddComponent <LoadObjectFromBundle>();

            handler.Create("personal_transport_helicopter", new Vector3(6592f, 380f, -2653f), new Quaternion(0, 0, 0, 0), new Vector3(1, 1, 1));
            UnityEngine.Object.DontDestroyOnLoad(ourobject);

            ourobject = new GameObject();
            handler   = ourobject.AddComponent <LoadObjectFromBundle>();
            handler.Create("militarycar", new Vector3(6592f, 380f, -2653f), new Quaternion(0, 0, 0, 0), new Vector3(1, 1, 1));
            UnityEngine.Object.DontDestroyOnLoad(ourobject);

            bundle.Unload(false);
            Logger.Log("Objects loaded.");
        }
コード例 #2
0
        private void LoadAllSetObjects()
        {
            if (!File.Exists(RustBuster2016.API.Hooks.GameDirectory + "\\RB_Data\\WorldEditor\\ClientSideAssets.txt"))
            {
                return;
            }
            foreach (string line in File.ReadAllLines(RustBuster2016.API.Hooks.GameDirectory + "\\RB_Data\\WorldEditor\\ClientSideAssets.txt"))
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                try
                {
                    string[] pares = line.Split(':');

                    var nombre = pares[0];
                    var loc    = pares[1];
                    var qua    = pares[2];
                    var siz    = pares[3];

                    // Position
                    string[] locsplit = loc.ToString().Split(',');
                    float    posx     = float.Parse(locsplit[0]);
                    float    posy     = float.Parse(locsplit[1]);
                    float    posz     = float.Parse(locsplit[2]);

                    // Quaternion
                    string[] quasplit = qua.ToString().Split(',');
                    float    quax     = float.Parse(quasplit[0]);
                    float    quay     = float.Parse(quasplit[1]);
                    float    quaz     = float.Parse(quasplit[2]);
                    float    quaw     = float.Parse(quasplit[3]);

                    // Size
                    string[] sizsplit = siz.ToString().Split(',');
                    float    sizx     = float.Parse(sizsplit[0]);
                    float    sizy     = float.Parse(sizsplit[1]);
                    float    sizz     = float.Parse(sizsplit[2]);


                    GameObject           TempGameObject = new GameObject();
                    LoadObjectFromBundle SpawnedObject  =
                        TempGameObject.AddComponent <LoadingHandler.LoadObjectFromBundle>();
                    SpawnedObject.Create(nombre, new Vector3(posx, posy, posz), new Quaternion(quax, quay, quaz, quaw),
                                         new Vector3(sizx, sizy, sizz));
                    UnityEngine.Object.DontDestroyOnLoad(TempGameObject);
                }
                catch
                {
                    RustBuster2016.API.Hooks.LogData("Error", "Failure to load: " + line);
                }
            }
        }
コード例 #3
0
        private void LoadAllSetObjects()
        {
            foreach (string line in File.ReadAllLines(Util.GetRootFolder() + "\\Save\\WorldEditorServer\\ClientSideAssets.txt"))
            {
                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                try
                {
                    string[] pares = line.Split(':');

                    var nombre = pares[0];
                    var loc    = pares[1];
                    var qua    = pares[2];
                    var siz    = pares[3];

                    // Position
                    string[] locsplit = loc.ToString().Split(',');
                    float    posx     = float.Parse(locsplit[0]);
                    float    posy     = float.Parse(locsplit[1]);
                    float    posz     = float.Parse(locsplit[2]);

                    // Quaternion
                    string[] quasplit = qua.ToString().Split(',');
                    float    quax     = float.Parse(quasplit[0]);
                    float    quay     = float.Parse(quasplit[1]);
                    float    quaz     = float.Parse(quasplit[2]);
                    float    quaw     = float.Parse(quasplit[3]);

                    // Size
                    string[] sizsplit = siz.ToString().Split(',');
                    float    sizx     = float.Parse(sizsplit[0]);
                    float    sizy     = float.Parse(sizsplit[1]);
                    float    sizz     = float.Parse(sizsplit[2]);


                    GameObject           TempGameObject = new GameObject();
                    LoadObjectFromBundle SpawnedObject  =
                        TempGameObject.AddComponent <LoadingHandler.LoadObjectFromBundle>();
                    SpawnedObject.Create(nombre, new Vector3(posx, posy, posz), new Quaternion(quax, quay, quaz, quaw),
                                         new Vector3(sizx, sizy, sizz));
                    UnityEngine.Object.DontDestroyOnLoad(TempGameObject);
                }
                catch
                {
                    Logger.LogError("[WorldEditorServer] Failure to load: " + line);
                }
            }
        }
コード例 #4
0
        public IEnumerator LoadAsset()
        {
            WWW www = WWW.LoadFromCacheOrDownload(WorldEditor.AssetPath, 1);

            yield return(www);

            if (www.error != null)
            {
                RustBuster2016.API.Hooks.LogData("WorldEditor", "www: " + www.error);
                //return;
            }
            bundle = www.assetBundle;
            www.Dispose();
            ourobject = new GameObject();
            Spawner   = ourobject.AddComponent <LoadObjectFromBundle>();
            UnityEngine.Object.DontDestroyOnLoad(ourobject);

            foreach (UnityEngine.Object item in bundle.LoadAll())
            {
                if (item.name.ToLower().Contains("mat") || item.name.ToLower().Contains("avatar") || item.name.ToLower().Contains("img"))
                {
                    continue;
                }
                GameObject           go = new GameObject();
                LoadObjectFromBundle lo = go.AddComponent <LoadObjectFromBundle>();
                // Test if we can create the object. If not, it's probably not a prefab so we don't need it.
                bool b = lo.Create(item.name, new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), new Vector3(1, 1, 1));
                if (!b)
                {
                    UnityEngine.Object.Destroy(go);
                    continue;
                }
                UnityEngine.Object.Destroy(lo.ObjectInstantiate);
                UnityEngine.Object.Destroy(go);

                if (!WorldEditor.Instance.Prefabs.Contains(item.name))
                {
                    WorldEditor.Instance.Prefabs.Add(item.name);
                }
            }

            LoadAllSetObjects();
            WorldEditor.Instance.Editor = WorldEditor.Instance.MainHolder.AddComponent <Editor>();
        }
コード例 #5
0
        public IEnumerator LoadAsset()
        {
            WWW www = WWW.LoadFromCacheOrDownload(WorldEditorServer.AssetPath, 1);

            yield return(www);

            if (www.error != null)
            {
                Logger.LogError("[WorldEditorServer] Failure to load www: " + www.error);
            }
            bundle = www.assetBundle;
            www.Dispose();
            ourobject = new GameObject();
            Spawner   = ourobject.AddComponent <LoadObjectFromBundle>();
            UnityEngine.Object.DontDestroyOnLoad(ourobject);

            foreach (UnityEngine.Object item in bundle.LoadAll())
            {
            }

            LoadAllSetObjects();
            bundle.Unload(false);
        }
コード例 #6
0
        public IEnumerator LoadAsset()
        {
            _maxBundles = WorldEditor.Bundles.Count;

//            var stopwatch = new Stopwatch();
            foreach (var bundleString in WorldEditor.Bundles)
            {
                if (string.IsNullOrEmpty(bundleString))
                {
                    continue;
                }
                var bundles = bundleString.Split('|');
//                RustBuster2016.API.Hooks.LogData("WorldEditor", "Downloading and loading " + bundles[1]);

//                stopwatch.Start();
//                isCached = Caching.IsVersionCached(bundles[1], 1);
//                var s = "Downloading " + bundles[0] + ".unity3d - ";
//                _progressString += !isCached ? (s + "PERCENT%\n") : (s + "100%\n");

//                Directory.CreateDirectory(RustBuster2016.API.Hooks.GameDirectory + "\\RB_Data\\Test\\");
//                var fileName = RustBuster2016.API.Hooks.GameDirectory + "\\RB_Data\\Test\\" + bundles[0] + ".unity3d";
//                new WebClient().DownloadFile(bundles[1], fileName);
//                stopwatch.Stop();
//                File.AppendAllText("WE.log", "Downloading took " + stopwatch.ElapsedMilliseconds + "ms\n");
//                stopwatch.Reset();

//                stopwatch.Start();
                _currentWWW = WWW.LoadFromCacheOrDownload(bundles[1], 1);
//                _currentWWW = WWW.LoadFromCacheOrDownload("file://" + fileName, 1);
                while (_currentWWW.progress < 1)
                {
                    yield return(_currentWWW);
                }

                if (_currentWWW.error != null)
                {
                    RustBuster2016.API.Hooks.LogData("WorldEditor", "www: " + _currentWWW.error);
                    yield return(null);
                }
//                stopwatch.Stop();
//                File.AppendAllText("WE.log", "LoadFromCacheOrDownload() took " + stopwatch.ElapsedMilliseconds + "ms\n");
//                stopwatch.Reset();

//                _progressString = _progressString.Replace("PERCENT", progress != 0 ? progress.ToString() : "100");
//                _progressString += "Loading " + bundles[0] + ".unity3d\n";

                var bundle = _currentWWW.assetBundle;
                bundleDictionary.Add(bundles[0], bundle);

                _currentWWW.Dispose();
                _currentWWW = null;
            }

            foreach (var bundleName in bundleDictionary.Keys)
            {
                var bundle = bundleDictionary[bundleName];

//                stopwatch.Start();
                ourobject = new GameObject();
                Spawner   = ourobject.AddComponent <LoadObjectFromBundle>();
                UnityEngine.Object.DontDestroyOnLoad(ourobject);
                foreach (UnityEngine.Object item in bundle.LoadAll())
                {
                    if (item.name.Equals("NewSupplyPrefab"))
                    {
                        if (item is GameObject)
                        {
                            var _ObjectInstantiate = ((GameObject)item);
//                            _ObjectInstantiate = (GameObject) Instantiate(_ObjectInstantiate, Vector3.zero, Quaternion.identity);
                            var newSupplyDropPlane = _ObjectInstantiate.AddComponent <NewSupplyDropPlane>();
//                            newSupplyDropPlane.propellers = new GameObject[0];
                            newSupplyDropPlane.maxSpeed             = 250;
                            newSupplyDropPlane.TEMP_numCratesToDrop = 3;
                            var newSupplyNetworkView = _ObjectInstantiate.AddComponent <uLinkNetworkView>();
                            newSupplyNetworkView.gameObject.name = "C130";
                            newSupplyNetworkView.observed        = newSupplyDropPlane;
                            newSupplyNetworkView.rpcReceiver     = RPCReceiver.ThisGameObject;
                            newSupplyNetworkView.prefabRoot      = _ObjectInstantiate;
                            var newTransformInterpolator = _ObjectInstantiate.AddComponent <TransformInterpolator>();
                            newTransformInterpolator.allowDifference = 0.1f;
                            newTransformInterpolator.exterpolate     = false;
                            newTransformInterpolator.target          = _ObjectInstantiate.transform;
//                            var firstNetDoppler = _ObjectInstantiate.transform.FindChild("uh60").gameObject.AddComponent<NetDoppler>();
//                            firstNetDoppler.minPitch = 0.75f;
//                            var secondNetDoppler = _ObjectInstantiate.transform.FindChild("uh602").gameObject.AddComponent<NetDoppler>();
//                            secondNetDoppler.minPitch = 0.75f;

                            var allField = Type
                                           .GetType(
                                "NetCull+AutoPrefabs, Assembly-CSharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null")
                                           .GetField("all");
                            Dictionary <string, uLinkNetworkView> allDictionary =
                                (Dictionary <string, uLinkNetworkView>)allField.GetValue(null);

                            allDictionary.Remove("C130");
                            allDictionary.Add("C130", newSupplyNetworkView);

                            allField.SetValue(null, allDictionary);

                            NetworkInstantiator.Remove("C130");
                            NetworkInstantiator.AddPrefab(newSupplyNetworkView.gameObject);

                            Hooks.LogData("WorldEditor", "Replaced supply.");
                        }

                        continue;
                    }

                    if (item.name.ToLower().Contains("movie"))
                    {
                        if (item is GameObject)
                        {
                            var movieGo = (GameObject)item;
                            movieGo.AddComponent <MoviePlay>();
//                            Debug.Log("Added MoviePlay");
                        }
                    }

                    if (item.name.ToLower().Contains("mat") || item.name.ToLower().Contains("avatar") ||
                        item.name.ToLower().Contains("img"))
                    {
                        continue;
                    }

//                    GameObject go = new GameObject();
//                    LoadObjectFromBundle lo = go.AddComponent<LoadObjectFromBundle>();
//
//                    Vector3 scale = new Vector3(1, 1, 1);
//                    if (item is GameObject)
//                    {
//                        var itemGo = item as GameObject;
//                        if (itemGo.transform != null)
//                        {
//                            scale = transform.localScale;
//                        }
//                    }
//
//                    bool b = lo.Create(item.name, bundleName, new Vector3(0, 0, 0), new Quaternion(0, 0, 0, 0), scale);
//                    if (!b)
//                    {
//                        UnityEngine.Object.Destroy(go);
//                        continue;
//                    }
//
//                    UnityEngine.Object.Destroy(lo.ObjectInstantiate);
//                    UnityEngine.Object.Destroy(go);

                    if (!WorldEditor.Instance.Prefabs.Contains(item.name))
                    {
                        WorldEditor.Instance.Prefabs.Add(item.name);
                    }

                    if (!WorldEditor.Instance.PrefabBundleDictionary.ContainsKey(item.name))
                    {
                        WorldEditor.Instance.PrefabBundleDictionary.Add(item.name, bundleName);
                    }
                }

//                stopwatch.Stop();
//                File.AppendAllText("WE.log", "Creating objects took " + stopwatch.ElapsedMilliseconds + "ms\n");
//                stopwatch.Reset();

//                stopwatch.Start();
                LoadAllSetObjects(bundleName);
//                stopwatch.Stop();
//                File.AppendAllText("WE.log", "LoadAllSetObjects() took " + stopwatch.ElapsedMilliseconds + "ms\n");
//                stopwatch.Reset();

//                _loadedBundles++;
            }

            WorldEditor.Instance.Editor = WorldEditor.Instance.MainHolder.AddComponent <Editor>();

            _showSplash = false;
            WorldEditor.Instance.SendMessageToServer("worldedit_finished");
            Finished?.Invoke();
            yield return(null);
        }
コード例 #7
0
        private void LoadAllSetObjects(string bundle)
        {
            Stopwatch watch = null;

            if (WorldEditorServer.PerformanceLog)
            {
                watch = new Stopwatch();
            }

            foreach (string line in File.ReadAllLines(Util.GetRootFolder() +
                                                      "\\Save\\WorldEditorServer\\ClientSideAssets.txt"))
            {
                if (WorldEditorServer.PerformanceLog)
                {
                    watch.Start();
                }

                if (string.IsNullOrEmpty(line))
                {
                    continue;
                }

                try
                {
                    string[] pares = line.Split(':');

                    if (pares[0] != bundle)
                    {
                        continue;
                    }

                    var nombre = pares[1];
                    var loc    = pares[2];
                    var qua    = pares[3];
                    var siz    = pares[4];

                    // Position
                    string[] locsplit = loc.ToString().Split(',');
                    float    posx     = float.Parse(locsplit[0]);
                    float    posy     = float.Parse(locsplit[1]);
                    float    posz     = float.Parse(locsplit[2]);

                    // Quaternion
                    string[] quasplit = qua.ToString().Split(',');
                    float    quax     = float.Parse(quasplit[0]);
                    float    quay     = float.Parse(quasplit[1]);
                    float    quaz     = float.Parse(quasplit[2]);
                    float    quaw     = float.Parse(quasplit[3]);

                    // Size
                    string[] sizsplit = siz.ToString().Split(',');
                    float    sizx     = float.Parse(sizsplit[0]);
                    float    sizy     = float.Parse(sizsplit[1]);
                    float    sizz     = float.Parse(sizsplit[2]);


                    GameObject           TempGameObject = new GameObject();
                    LoadObjectFromBundle SpawnedObject  =
                        TempGameObject.AddComponent <LoadingHandler.LoadObjectFromBundle>();
                    SpawnedObject.Create(nombre, bundle, new Vector3(posx, posy, posz),
                                         new Quaternion(quax, quay, quaz, quaw),
                                         new Vector3(sizx, sizy, sizz));
                    UnityEngine.Object.DontDestroyOnLoad(TempGameObject);

                    if (WorldEditorServer.PerformanceLog)
                    {
                        watch.Stop();
                        WorldEditorServer.AddPerfLog("Spawning asset \"" + nombre + "\" took " +
                                                     watch.ElapsedMilliseconds / 1000f + "s");
                        watch.Reset();
                    }
                }
                catch
                {
                    Logger.LogError("[WorldEditorServer] Failure to load: " + line);
                }
            }
        }