示例#1
0
        protected override NetworkViewBase OnCreate(string prefabName, NetworkInstantiateArgs args, NetworkMessageInfo info)
        {
            var instantiator = NetworkInstantiator.Find(prefabName);
            var creator      = instantiator.creator;

            if (creator != null)
            {
                Log.Debug(NetworkLogFlags.Instantiate, "Calling creator for prefab '", prefabName, "' with viewID ", args.viewID, " (in ", args.group, "), owner ", args.owner, ", position ", args.position, ", rotation ", args.rotation);

                Profiler.BeginSample("Calling Creator");
                var nv = creator(prefabName, args, info);
                Profiler.EndSample();

                if (!nv.IsNullOrDestroyed())
                {
                    nv.instantiator = instantiator;

                    if (nv.viewID != args.viewID)
                    {
                        Log.Warning(NetworkLogFlags.Instantiate, "Creator failed to correctly setup the ", nv, ", which is it's responsibility. Please make sure your custom NetworkInstantiator is calling NetworkInstantiatorUtility.Instantiate or NetworkInstantiateArgs.SetupNetworkView.");
                    }

                    return(nv);
                }

                Log.Error(NetworkLogFlags.Instantiate, "Creator for prefab '", prefabName, "' failed to return a instantiated NetworkView!");
                return(null);
            }

            Log.Error(NetworkLogFlags.Instantiate, "Missing Creator for prefab '", prefabName, "'");
            return(null);
        }
        private static void Add(string prefabName, NetworkInstantiator instantiator, bool replaceIfExists)
        {
            if (!replaceIfExists && _instantiators.ContainsKey(prefabName))
            {
                Log.Error(NetworkLogFlags.Instantiate, "Instantiator for prefab '", prefabName, "' already exists");
                return;
            }

            _instantiators[prefabName] = instantiator;

            Log.Debug(NetworkLogFlags.Instantiate, "Added Instantiator for prefab '", prefabName, "'");
        }