Beispiel #1
0
        internal void DoOnRemove(byte reasonCode)
        {
            CleanupNetView();

            if (DestroyGameObjectOnNetworkDestroy)
            {
                UnityDebugLogger.Full("Network Destruction. Destroying networkview and gameobject", this);
                Destroy(gameObject);
            }
            else
            {
                UnityDebugLogger.Full("Network destruction. Only destroying networkview", this);
                Destroy(this);
            }

            if (OnRemove == null)
            {
                return;
            }

            try
            {
                OnRemove(reasonCode);
                OnRemove = null;
            }
            catch (Exception e)
            {
                Debug.LogError(e, this);
            }
        }
Beispiel #2
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();
        }