Example #1
0
        //void Start()
        //{
        //    foreach(NetworkField f in fields)
        //    {
        //        f.InitializeSpecialFields();
        //    }
        //}



        public void Initialize()
        {
            if (networkID == -1)
            {
                networkID = NetTools.GenerateNetworkObjectID();
                sessionNetIDHistory.Add(networkID);
            }


            NetworkData.AddUsedNetID(networkID);
            lock (allNetObjs)
            {
                allNetObjs.Add(this);
            }
            allNetObjsDictionary[networkID] = this;

            initialized = true;


            if (detectNetworkStarts)
            {
                foreach (MonoBehaviour c in gameObject.GetComponents(typeof(MonoBehaviour)))
                {
                    if (c.GetType().GetMethod("NetworkStart") == null)
                    {
                        continue;
                    }
                    c.SendMessage("NetworkStart");
                }
            }


            DoRpcFieldInitialization();

            foreach (RPC r in rpcs)
            {
                //Debug.Log(r.queued.Count);
                foreach (KeyValuePair <Packet.sendType, object[]> call in r.queued)
                {
                    NetClient.instanceClient.SendPacket(r.GenerateRPCPacket(call.Key, call.Value)); //Send any RPCs requested before the netObj was initialized.
                }
                r.queued = new Dictionary <Packet.sendType, object[]>();                            //Clear it afterwards.
            }

            //If you want automatic Animator networking, a little buggy.
            if (!blockNetworkAnimator && NetTools.IsMultiplayerGame() && GetComponent <Animator>() != null && GetComponent <AnimationNetworker>() == null)
            {
                //If it is singleplayer game it doesn't need this so it doesn't add one automatically.
                AnimationNetworker aN = gameObject.AddComponent <AnimationNetworker>();
                aN.Initialize();
            }

            //StartCoroutine(NetworkFieldPacketHandler());
        }
Example #2
0
        void Awake()
        {
            instance = this;


            //Initializing moved to just happening when instantiating over the network.
            //foreach(GameObjectList gOL in networkPrefabList)
            //{
            //    foreach(NetworkField netField in gOL.defaultFields)
            //    {
            //        netField.InitializeDefaultValue(null);
            //    }
            //}
        }