Example #1
0
 public void Register(bool forceReplace)
 {
     NetworkInstantiator.Add(this.name, this.creator, this.destroyer, forceReplace);
     g.dict[this.name] = this;
 }
        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);
        }
Example #3
0
        public IEnumerator LoadAsset()
        {
            foreach (var bundleString in WorldEditorServer.Bundles)
            {
                if (string.IsNullOrEmpty(bundleString))
                {
                    continue;
                }
                var bundles = bundleString.Split('|');

                if (WorldEditorServer.PerformanceLog)
                {
                    Stopwatch.Start();
                }

                WWW www = WWW.LoadFromCacheOrDownload(bundles[1], 1);
                yield return(www);

                if (www.error != null)
                {
                    Logger.LogError("[WorldEditorServer] Failure to load www: " + www.error);
                }

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

                www.Dispose();

                foreach (UnityEngine.Object item in bundle.LoadAll())
                {
                    if (item.name.Equals("NewSupplyPrefab"))
                    {
                        if (item is GameObject)
                        {
                            Logger.Log(item.name);
                            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 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);

                            Logger.Log("Set new Supply.");
                        }
                    }
                }

                if (WorldEditorServer.PerformanceLog)
                {
                    Stopwatch.Stop();
                    WorldEditorServer.AddPerfLog("Loading bundle \"" + bundles[0] + "\" took " +
                                                 Stopwatch.ElapsedMilliseconds / 1000f + "s");
                    Stopwatch.Reset();
                    Stopwatch.Start();
                }

                LoadAllSetObjects(bundles[0]);

                if (WorldEditorServer.PerformanceLog)
                {
                    Stopwatch.Stop();
                    WorldEditorServer.AddPerfLog("Spawning assets took " + Stopwatch.ElapsedMilliseconds / 1000f + "s");
                    Stopwatch.Reset();
                }
            }

            SpawnManager.LoadSpawnedObjects();
            NukeManager.Start();

            Logger.Log("Loaded all custom objects.");
        }