Beispiel #1
0
        public void Instantiate(string path, PNetC.NetworkView newView, PNetC.Vector3 location, PNetC.Quaternion rotation)
        {
            GameObject gobj;
            bool       isCached = false;

            if (Net.resourceCaching && (isCached = ResourceCache.ContainsKey(path)))
            {
                gobj = ResourceCache[path];
            }
            else
            {
                gobj = Resources.Load(path) as GameObject;
            }

            if (Net.resourceCaching && !isCached)
            {
                ResourceCache.Add(path, gobj);
            }

            var instance = (GameObject)Instantiate(gobj, new Vector3(location.X, location.Y, location.Z), new Quaternion(rotation.X, rotation.Y, rotation.Z, rotation.W));

            if (instance == null)
            {
                Debug.LogWarning("could not find prefab " + path + " to instantiate");
                instance = new GameObject("BROKEN NETWORK PREFAB " + newView.ViewID);
            }

            UnityDebugLogger.Full("network instantiate of {0}. Loc: {1} Rot: {2}", null, path, location, rotation);

            //look for a networkview..
            var view = instance.GetComponent <NetworkView>();

            if (view == null)
            {
                view = instance.AddComponent <NetworkView>();
            }

            _manager.AddView(newView, view);

            var nBehaviours = instance.GetComponents <NetBehaviour>();

            foreach (var behave in nBehaviours)
            {
                behave.netView = view;

                view.OnFinishedCreation += behave.CallFinished;
            }

            view.DoOnFinishedCreation();
        }
Beispiel #2
0
        public void AddNetworkView(PNetC.NetworkView view, PNetC.NetworkView newView, string customFunction)
        {
            NetworkView uview;

            if (!_manager.TryGetView(view.ViewID, out uview))
            {
                Debug.LogError(
                    string.Format("Could not attach extra networkview {0} to networkview {1}. It might have been destroyed accidentally, or not yet instantiated",
                                  newView.ViewID,
                                  view.ViewID));
            }

            var unewView = uview.gameObject.AddComponent <NetworkView>();

            _manager.AddView(newView, unewView);

            UnityDebugLogger.Info("Attached extra networkview " + newView.ViewID.guid, uview.gameObject);

            if (!string.IsNullOrEmpty(customFunction))
            {
                uview.gameObject.SendMessage(customFunction, unewView, SendMessageOptions.DontRequireReceiver);
            }
        }