Exemplo n.º 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!");
            }
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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));
 }
Exemplo n.º 6
0
 public GameObject SpawnObject(AssetBundle bundle, string assetPath, Vector3 pos, bool init = true)
 {
     return(SpawnObject(bundle, assetPath, pos, Quaternion.identity, init));
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
 }
Exemplo n.º 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);
 }