Exemple #1
0
        private void InitializeObject(ulong startObjectId, int count)
        {
            if (!OwningNetWorker.IsServer)
            {
                return;
            }

            for (int i = 0; i < count; i++)
            {
                if (NetworkedBehaviors.ContainsKey(startObjectId + (ulong)i))
                {
                    if (NetworkedBehaviors[startObjectId + (ulong)i] is NetworkedMonoBehavior)
                    {
                        ((NetworkedMonoBehavior)NetworkedBehaviors[startObjectId + (ulong)i]).AutoritativeSerialize();
                    }
                }
            }
        }
Exemple #2
0
        public void NetworkInstantiate(ulong ownerId, ulong startNetworkId, string name, Vector3 position, Quaternion rotation, int callbackId = 0)
        {
            lock (NetworkedBehaviorsMutex)
            {
                if (NetworkedBehaviors.ContainsKey(startNetworkId))
                {
                    return;
                }

                SimpleNetworkedMonoBehavior[] NetBehaviors = null;

#if BARE_METAL
                NetBehaviors = new SimpleNetworkedMonoBehavior[behaviorsAndRefCount[name].Length];

                for (int i = 0; i < NetBehaviors.Length; i++)
                {
                    //if (CreateObject != null)
                    //	NetBehaviors[i] = CreateObject(name + "(Clone)(Child)" + i, behaviorsAndRefCount[name][i]);

                    if (behaviorsAndRefCount[name][i] == typeof(SimpleNetworkedMonoBehavior).ToString() || behaviorsAndRefCount[name][i] == typeof(NetworkedMonoBehavior).ToString())
                    {
                        NetBehaviors[i] = (SimpleNetworkedMonoBehavior)Activator.CreateInstance(typeof(SimpleNetworkedMonoBehavior).Assembly.GetType(behaviorsAndRefCount[name][i]), name, behaviorsAndRefCount[name][i]);
                    }
                    else
                    {
                        foreach (System.Reflection.Assembly assembly in AppDomain.CurrentDomain.GetAssemblies())
                        {
                            if (assembly.FullName.Contains("ForgeBareMetalGame"))
                            {
                                NetBehaviors[i] = (SimpleNetworkedMonoBehavior)Activator.CreateInstance(assembly.GetType(behaviorsAndRefCount[name][i]), name, behaviorsAndRefCount[name][i]);
                                break;
                            }
                        }
                    }
                }
#else
                GameObject o = Instance.PullObject((ownerId != OwningNetWorker.Me.NetworkId ? name + "(Remote)" : name), name);
                NetBehaviors = GetAllSimpleMonoBehaviors(o);

                if (NetBehaviors.Length == 0)
                {
                    Debug.LogError("Instantiating on the Network is only for objects that derive from BaseNetworkedMonoBehavior, " +
                                   "if object does not need to be serialized consider using a RPC with GameObject.Instantiate");

                    return;
                }

                GameObject tmp = (Instantiate(o, position, rotation) as GameObject);
                NetBehaviors = GetAllSimpleMonoBehaviors(tmp);
#endif

                while (ObjectCounter < startNetworkId + (ulong)NetBehaviors.Length - 1)
                {
                    GenerateUniqueId();
                }

                for (int i = 0; i < NetBehaviors.Length; i++)
                {
                    NetBehaviors[i].Setup(OwningNetWorker, OwningNetWorker.Uniqueidentifier == ownerId, startNetworkId + (ulong)i, ownerId);
                }

#if !BARE_METAL
                if (ownerId == OwningNetWorker.Me.NetworkId)
                {
                    Networking.RunInstantiateCallback(callbackId, NetBehaviors[0].GetComponent <SimpleNetworkedMonoBehavior>());
                }
#else
                if (ownerId == OwningNetWorker.Me.NetworkId)
                {
                    Networking.RunInstantiateCallback(callbackId, NetBehaviors[0]);
                }
#endif
            }
        }