Example #1
0
        public NetworkIdentity ReadNetworkIdentity()
        {
            NetworkInstanceId netId = ReadNetworkId();

            if (netId.IsEmpty())
            {
                return(null);
            }
            GameObject go;

            if (NetworkServer.active)
            {
                go = NetworkServer.FindLocalObject(netId);
            }
            else
            {
                go = ClientScene.FindLocalObject(netId);
            }
            if (go == null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("ReadNetworkIdentity netId:" + netId + "go: null");
                }
                return(null);
            }

            return(go.GetComponent <NetworkIdentity>());
        }
Example #2
0
        protected void SetSyncVarGameObject(GameObject newGameObject, ref GameObject gameObjectField, ulong dirtyBit, ref NetworkInstanceId netIdField)
        {
            if (m_SyncVarGuard)
            {
                return;
            }

            NetworkInstanceId newGameObjectNetId = new NetworkInstanceId();

            if (newGameObject != null)
            {
                var uv = newGameObject.GetComponent <NetworkIdentity>();
                if (uv != null)
                {
                    newGameObjectNetId = uv.netId;
                    if (newGameObjectNetId.IsEmpty())
                    {
                        if (LogFilter.logWarn)
                        {
                            Debug.LogWarning("SetSyncVarGameObject GameObject " + newGameObject + " has a zero netId. Maybe it is not spawned yet?");
                        }
                    }
                }
            }

            NetworkInstanceId oldGameObjectNetId = new NetworkInstanceId();

            if (gameObjectField != null)
            {
                oldGameObjectNetId = gameObjectField.GetComponent <NetworkIdentity>().netId;
            }

            if (newGameObjectNetId != oldGameObjectNetId)
            {
                if (LogFilter.logDev)
                {
                    Debug.Log("SetSyncVar GameObject " + GetType().Name + " bit [" + dirtyBit + "] netfieldId:" + oldGameObjectNetId + "->" + newGameObjectNetId);
                }
                SetDirtyBit(dirtyBit);
                gameObjectField = newGameObject;
                netIdField      = newGameObjectNetId;
            }
        }
Example #3
0
        public Transform ReadTransform()
        {
            NetworkInstanceId netId = ReadNetworkId();

            if (netId.IsEmpty())
            {
                return(null);
            }
            GameObject go = ClientScene.FindLocalObject(netId);

            if (go == null)
            {
                if (LogFilter.logDebug)
                {
                    Debug.Log("ReadTransform netId:" + netId);
                }
                return(null);
            }

            return(go.transform);
        }