当前位置: 首页>>代码示例>>C#>>正文


C# PhotonStream类代码示例

本文整理汇总了C#中PhotonStream的典型用法代码示例。如果您正苦于以下问题:C# PhotonStream类的具体用法?C# PhotonStream怎么用?C# PhotonStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PhotonStream类属于命名空间,在下文中一共展示了PhotonStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnPhotonSerializeView

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if(stream.isWriting){
            // this is our player, we send of posision data here
            stream.SendNext(transform.position); //send our posision to the network
            stream.SendNext(transform.rotation); // send our rotation to the network
            stream.SendNext(anim.GetFloat("Speed"));
            stream.SendNext(anim.GetBool("Jumping"));
            stream.SendNext(anim.GetFloat("AimAngle"));
        }
        else {
            //this is everyone elses players, we recieve their posisions here

            // right now realPosition holds the player position on the Last frame
            // instead of simply updating "RealPosition" and continuing to lerp
            // we MAY want to set out transform.position IMMEDIITLY to this old "realPosition"
            // then update realPosition

            realPosition = (Vector3)stream.ReceiveNext(); //recieve others posisions
            realRotation = (Quaternion)stream.ReceiveNext(); // recieve others rotations
            anim.SetFloat("Speed", (float)stream.ReceiveNext());
            anim.SetBool("Jumping", (bool)stream.ReceiveNext());
            realAimAngle = (float)stream.ReceiveNext();

            if (gotFirstUpdate == false) {
                transform.position = realPosition;
                transform.rotation = realRotation;
                anim.SetFloat("AimAngle", realAimAngle);
                gotFirstUpdate = true;
            }
        }
    }
开发者ID:sharkbound,项目名称:Unity-Projects,代码行数:32,代码来源:NetworkPlayer.cs

示例2: OnPhotonSerializeView

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if(stream.isWriting) {
            // This is our player. We need to send our actual position to the network.

            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
            stream.SendNext(anim.GetFloat("Speed"));
            stream.SendNext(anim.GetBool("Jumping"));

        }
        else {
            // This is someone else's player. We need to reciece their position.

            // Right now, "realPosition" holds the other person's position at the LAST frame.
            // Instead of simply updating "realPosition" and continuing to lerp,
            //we MAY want to set our transform.position to immediately to this old "realPosition"
            //and then update realPosition

            realPosition = (Vector3)stream.ReceiveNext ();
            realRotation = (Quaternion)stream.ReceiveNext ();
            anim.SetFloat ("Speed", (float)stream.ReceiveNext() );
            anim.SetBool ("Jumping", (bool)stream.ReceiveNext() );

            if(gotFirstUpdate == false) {
                transform.position = realPosition;
                transform.rotation = realRotation;
                gotFirstUpdate = true;
            }

        }
    }
开发者ID:Goodyjake,项目名称:zombinc,代码行数:32,代码来源:NetworkCharacter.cs

示例3: OnPhotonSerializeView

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting == true)
        {
            if (this.m_SynchronizeVelocity == true)
            {
                stream.SendNext(this.m_Body.velocity);
            }

            if (this.m_SynchronizeAngularVelocity == true)
            {
                stream.SendNext(this.m_Body.angularVelocity);
            }
        }
        else
        {
            if (this.m_SynchronizeVelocity == true)
            {
                this.m_Body.velocity = (Vector3)stream.ReceiveNext();
            }

            if (this.m_SynchronizeAngularVelocity == true)
            {
                this.m_Body.angularVelocity = (Vector3)stream.ReceiveNext();
            }
        }
    }
开发者ID:CanPayU,项目名称:SuperSwungBall,代码行数:27,代码来源:PhotonRigidbodyView.cs

示例4: OnPhotonSerializeView

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            //We own this player: send the others our data
            ControllerPlayer controllerScript = GetComponent<ControllerPlayer>();
            stream.SendNext((int)controllerScript._characterState);
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);

            Stats statsScript = GetComponent<Stats>();
            stream.SendNext(statsScript.Health);
            stream.SendNext(statsScript.Lives);
        }
        else
        {
            //Network player, receive data
            this.correctPlayerPos = (Vector3)stream.ReceiveNext();
            this.correctPlayerRot = (Quaternion)stream.ReceiveNext();

            ControllerPlayer controllerScript = GetComponent<ControllerPlayer>();
            Stats statsScript = GetComponent<Stats>();
            controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
            statsScript.Health = (int)stream.ReceiveNext();
            statsScript.Lives = (int)stream.ReceiveNext();
        }
    }
开发者ID:micha224,项目名称:Jan_1GAM,代码行数:27,代码来源:NetworkMovement.cs

示例5: OnPhotonSerializeView

    private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        //Debug.Log("============>");
        if (stream.isWriting)
        {
            stream.SendNext(transform.position);
            PlayerController player = GetComponent<PlayerController>();
            string blockName = player.currentBlock == null ? "" : player.currentBlock.name;
            stream.SendNext(blockName);
        }
        else
        {
            PlayerController player = GetComponent<PlayerController>();

            this.playerPos = (Vector3)stream.ReceiveNext();
            string currentBlock = (string)stream.ReceiveNext();
            if (currentBlock != "")
            {
                player.transform.parent = null;
            }
            else
            {
                Node block = GameBoard.FindBlockByName(currentBlock);
                Debug.Log("===>"+block.name);
                player.transform.parent = block.transform;
            }
            transform.localPosition = this.playerPos;
        }
    }
开发者ID:azanium,项目名称:TruthNIslam-Unity,代码行数:29,代码来源:RemotePlayer.cs

示例6: SerializeState

	public void SerializeState( PhotonStream stream, PhotonMessageInfo info )
	{
//		Debug.Log ("Serialized State");
		//We only need to synchronize a couple of variables to be able to recreate a good
		//approximation of the ships position on each client
		//There is a lot of smoke and mirrors happening here
		//Check out Part 1 Lesson 2 http://youtu.be/7hWuxxm6wsA for more detailed explanations
		if( stream.isWriting == true )
		{
			Vector3 pos = transform.position;
			Quaternion rot = transform.rotation;
			stream.SendNext( pos );
			stream.SendNext( rot );
		}
		else
		{
			t=0;
			// achterlopende position naar nieuwe binnenkomende position lerpen
			startPosition = transform.position;
			m_NetworkPosition = (Vector3)stream.ReceiveNext();
			m_NetworkRotation = (Quaternion)stream.ReceiveNext();

			distance = Vector3.Distance(startPosition,m_NetworkPosition);
			time = distance/speed;
			m_LastNetworkDataReceivedTime = info.timestamp;
		}
	}
开发者ID:MiloBuwalda,项目名称:wizard,代码行数:27,代码来源:SpellObserver.cs

示例7: OnPhotonSerializeView

 void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
 {
     if (stream.isWriting)
         {
             //We own this player: send the others our data
             //stream.SendNext((int)controllerScript._characterState);
             //stream bool for grounded, float for running
             if (!cam.GetComponent<RTSCamera>())
             {
                 stream.SendNext(controllerScript.forwardInput);
                 stream.SendNext(controllerScript.grounded);
                 stream.SendNext(transform.position);
                 stream.SendNext(transform.rotation);
                 stream.SendNext(controllerScript.velocity);
             }
         }
         else
         {
             //Network player, receive data
             //controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
             //stream bool for grounded, float for running
             forwardInput = (float)stream.ReceiveNext();
             grounded = (bool)stream.ReceiveNext();
             correctPlayerPos = (Vector3)stream.ReceiveNext();
             correctPlayerRot = (Quaternion)stream.ReceiveNext();
             correctPlayerVelocity = (Vector3)stream.ReceiveNext();
         }
 }
开发者ID:coderDarren,项目名称:TheArchitect,代码行数:28,代码来源:thirdPersonNetwork.cs

示例8: OnPhotonSerializeView

    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            Vector3 pos = transform.localPosition;
            Quaternion rot = transform.localRotation;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);

        }
        else
        {

            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);

            latestCorrectPos = pos;
            onUpdatePos = transform.localPosition;
            fraction = 0;

            transform.localRotation = rot;
        }
    }
开发者ID:houseofkohina,项目名称:ProjectDoge,代码行数:27,代码来源:Projectile.cs

示例9: OnPhotonSerializeView

	void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info) {
		if(stream.isWriting) {
			stream.SendNext(transform.position);
		} else {
			position = (Vector3)stream.ReceiveNext();
		}
	}
开发者ID:rthill91,项目名称:Independent-Study,代码行数:7,代码来源:NetworkBullet.cs

示例10: OnPhotonSerializeView

	public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if(stream.isWriting)
        {
            // this is my player. need to send my actual position to the network
            stream.SendNext(transform.position);
            stream.SendNext(_charController.velocity);
            stream.SendNext(transform.rotation);

        }
        else
        {
            //this is another player. need to get his position data. then update my version of this player
            Vector3 syncPosition = (Vector3)stream.ReceiveNext();
            Vector3 syncVelocity = (Vector3)stream.ReceiveNext();
            syncEndRotation = (Quaternion)stream.ReceiveNext();

            syncStartRotation = transform.rotation;

            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;

            syncEndPosition = syncPosition + syncVelocity * syncDelay;
            syncStartPosition = transform.position;

        }
    }
开发者ID:Pecke123,项目名称:Genesis_Unknown,代码行数:28,代码来源:NetworkCharacter.cs

示例11: OnPhotonSerializeView

    // this method is called by PUN when this script is being "observed" by a PhotonView (setup in inspector)
    public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            // the controlling player of a cube sends only the position
            Vector3 pos = transform.localPosition;
            stream.Serialize(ref pos);
        }
        else
        {
            // other players (not controlling this cube) will read the position and timing and calculate everything else based on this
            Vector3 updatedLocalPos = Vector3.zero;
            stream.Serialize(ref updatedLocalPos);

            double timeDiffOfUpdates = info.timestamp - this.lastTime;  // the time that passed after the sender sent it's previous update
            this.lastTime = info.timestamp;


            // the movementVector calculates how far the "original" cube moved since it sent the last update.
            // we calculate this based on the sender's timing, so we exclude network lag. that makes our movement smoother.
            this.movementVector = (updatedLocalPos - this.latestCorrectPos) / (float)timeDiffOfUpdates;

            // the errorVector is how far our cube is away from the incoming position update. using this corrects errors somewhat, until the next update arrives.
            // with this, we don't have to correct our cube's position with a new update (which introduces visible, hard stuttering).
            this.errorVector = (updatedLocalPos - transform.localPosition) / (float)timeDiffOfUpdates;

            
            // next time we get an update, we need this update's position:
            this.latestCorrectPos = updatedLocalPos;
        }
    }
开发者ID:CanPayU,项目名称:SuperSwungBall,代码行数:32,代码来源:CubeExtra.cs

示例12: OnPhotonSerializeView

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if(stream.isWriting)
        {

            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
            if(anim.IsPlaying("Run"))
            {

                stream.SendNext(useThisMove = 1);

            }
            if(anim.IsPlaying ("Idle"))
            {
                stream.SendNext (useThisMove = -1);

            }
            if(anim.IsPlaying ("AutoAttack"))
            {
                stream.SendNext(useThisMove = -2);

            }

        }
        else
        {

            realPosition = (Vector3)stream.ReceiveNext();
            realRotation = (Quaternion)stream.ReceiveNext();

            useThisMove = (int)stream.ReceiveNext();

        }
    }
开发者ID:jordanepickett,项目名称:RPG,代码行数:35,代码来源:NetworkCharacter.cs

示例13: OnPhotonSerializeView

    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            //We own this player: send the others our data
            stream.SendNext((int)controllerScript._characterState);
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation); 
        }
        else
        {
            //Network player, receive data
            controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
            correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();

			// avoids lerping the character from "center" to the "current" position when this client joins
			if (firstTake)
			{
				firstTake = false;
				this.transform.position = correctPlayerPos;
				transform.rotation = correctPlayerRot;
			}

        }
    }
开发者ID:na2424,项目名称:ChatUni,代码行数:26,代码来源:ThirdPersonNetwork.cs

示例14: OnPhotonSerializeView

    /// <summary>
    /// While script is observed (in a PhotonView), this is called by PUN with a stream to write or read.
    /// </summary>
    /// <remarks>
    /// The property stream.isWriting is true for the owner of a PhotonView. This is the only client that
    /// should write into the stream. Others will receive the content written by the owner and can read it.
    /// 
    /// Note: Send only what you actually want to consume/use, too!
    /// Note: If the owner doesn't write something into the stream, PUN won't send anything.
    /// </remarks>
    /// <param name="stream">Read or write stream to pass state of this GameObject (or whatever else).</param>
    /// <param name="info">Some info about the sender of this stream, who is the owner of this PhotonView (and GameObject).</param>
    void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        Debug.Log ("OnPhotonSerializeView");
        if (stream.isWriting)
        {
            Vector3 pos = transform.localPosition;
            Quaternion rot = transform.localRotation;
            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref playerId);
            int _st = (int)stoneType;
            stream.Serialize(ref _st);
        }
        else
        {
            // Receive latest state information
            Vector3 pos = Vector3.zero;
            Quaternion rot = Quaternion.identity;
            int _st = (int)stoneType;

            stream.Serialize(ref pos);
            stream.Serialize(ref rot);
            stream.Serialize(ref playerId);
            stream.Serialize(ref _st);

            latestCorrectPos = pos;                 // save this to move towards it in FixedUpdate()
            onUpdatePos = transform.localPosition;  // we interpolate from here to latestCorrectPos
            fraction = 0;                           // reset the fraction we alreay moved. see Update()
            transform.localRotation = rot;          // this sample doesn't smooth rotation
            stoneType = (StoneType)_st;
        }
    }
开发者ID:hekk,项目名称:sprint_workshop,代码行数:44,代码来源:StoneNetwork.cs

示例15: OnPhotonSerializeView

    private void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            //We own this player: send the others our data
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);

            // animation data
            int[] animStates = _playerAnim.GetAnimationBooleans();
            stream.SendNext(animStates[0]);
            stream.SendNext(animStates[1]);
            stream.SendNext(animStates[2]);
        }
        else
        {
            //Network player, receive data
            _correctPlayerPos = (Vector3)stream.ReceiveNext();
            _correctPlayerRot = (Quaternion)stream.ReceiveNext();

            // animation data
            _playerAnim.ApplyNetworkAnimations((int)stream.ReceiveNext(), (int)stream.ReceiveNext(), (int)stream.ReceiveNext());

            syncTime = 0f;
            syncDelay = Time.time - lastSynchronizationTime;
            lastSynchronizationTime = Time.time;
        }
    }
开发者ID:poemdexter,项目名称:HorseWizardOnline,代码行数:28,代码来源:NetworkedPlayer.cs


注:本文中的PhotonStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。