Пример #1
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.");
        }
Пример #2
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);
                }
            }
        }