示例#1
0
        private void FindAssetBundleForAsset(string assetPath, out AssetBundle bundle)
        {
            bundle = null;
            foreach (AssetBundle assetBundle in AssetManager.Bundles.Where(assetBundle => assetBundle.Contains(assetPath)))
            {
                if (bundle != null)
                {
                    throw new Exception("Multiple asset bundles include the asset \"" + assetPath + "\", please specify the bundle!");
                }
                bundle = assetBundle;
            }

            if (bundle == null)
            {
                throw new Exception("Asset " + assetPath + " not found!");
            }
        }
示例#2
0
        private GameObject LoadObject(AssetBundle bundle, string assetPath)
        {
            var obj = bundle.LoadAsset <GameObject>(assetPath);

            if (obj == null)
            {
                throw new Exception("Object with path: " + assetPath + " in bundle " + bundle.Name + " not found");
            }

            //obj has not collider, add a default one
            if (!obj.GetComponent <Collider>() && !obj.GetComponentsInChildren <Transform>().Any(t => t.GetComponent <Collider>()))
            {
                ObjectUtils.AddDefaultCollider(obj);
            }

            return(obj);
        }
示例#3
0
        private GameObject SpawnObjectInternal(AssetBundle bundle, string assetPath, Vector3 pos, Quaternion rotation, bool init, uint callback, bool networkCall)
        {
            if (!networkCall && !IsServer())
            {
                throw new Exception("SpawnObject can only be used from Serverside!");
            }
            var obj = LoadObject(bundle, assetPath);

            if (init)
            {
                obj = (GameObject)Instantiate(obj, pos, rotation);
                if (!networkCall)
                {
                    Channel.Send(nameof(Networn_SpawnObject), ECall.Clients, bundle.Name, assetPath, pos, rotation, callback, true);
                }
            }

            return(obj);
        }
示例#4
0
        public void Network_RequestSpawnObject(Identity ident, string bundle, string asset, Vector3 position,
                                               Quaternion rotation, uint callbackId)
        {
            List <Action <uint, bool, GameObject> > serverCallbacks = null;

            if (_callbacks.ContainsKey(ident) && _callbacks[ident].ContainsKey(callbackId))
            {
                serverCallbacks = _callbacks[ident][callbackId];
            }
            AssetBundle             assetBundle  = AssetManager.GetAssetBundle(bundle);
            ObjectSpawnRequestEvent requestEvent = new ObjectSpawnRequestEvent(bundle, asset, position, rotation, callbackId);

            requestEvent.Fire();
            if (requestEvent.IsCancelled)
            {
                Channel.Send(nameof(Networn_SpawnObject), ident, bundle, asset, position, rotation, callbackId, false);
                if (serverCallbacks != null)
                {
                    foreach (var t in serverCallbacks)
                    {
                        t.Invoke(callbackId, false, null);
                    }

                    _callbacks[ident].Remove(callbackId);
                }
                return;
            }

            var obj = SpawnObject(assetBundle, asset, position, rotation, true, callbackId);

            if (serverCallbacks != null)
            {
                foreach (var t in serverCallbacks)
                {
                    t.Invoke(callbackId, true, obj);
                }

                _callbacks[ident].Remove(callbackId);
            }
        }
示例#5
0
 public GameObject SpawnObject(AssetBundle bundle, string assetPath, Vector3 pos, Quaternion rotation, bool init = true, uint callback = 0)
 {
     return(SpawnObjectInternal(bundle, assetPath, pos, rotation, init, callback, false));
 }
示例#6
0
 public GameObject SpawnObject(AssetBundle bundle, string assetPath, Vector3 pos, bool init = true)
 {
     return(SpawnObject(bundle, assetPath, pos, Quaternion.identity, init));
 }
示例#7
0
        public GameObject SpawnObject(string bundle, string assetPath, Vector3 pos, Quaternion rotation, bool init = true)
        {
            AssetBundle assetBundle = AssetManager.GetAssetBundle(bundle);

            return(SpawnObject(assetBundle, assetPath, pos, rotation, init));
        }
示例#8
0
 public void SpawnRequestClient(Action <uint, bool, GameObject> callback, AssetBundle bundle, string asset, Vector3 postion, Quaternion rotation, out uint objectId)
 {
     SpawnRequestClient(callback, bundle.Name, asset, postion, rotation, out objectId);
 }
示例#9
0
 public void SpawnRequestClient(Action <uint, bool, GameObject> callback, AssetBundle bundle, string asset, Vector3 postion, out uint callbackId)
 {
     SpawnRequestClient(callback, bundle, asset, postion, Quaternion.identity, out callbackId);
 }