TrajectoryObject Question

vgwizardx

New member
So I see there is a Pun Grenade and Pun Projectile. But I don't see a Pun Trajectory Object. Am I missing something?
 

Justin

Administrator
Staff member
You're not missing anything. I can add it to my list to add. The demo doesn't contain any non-grenade trajectory objects so I simply forgot to add it. It should be really similar to the PunGrenade though.
 

vgwizardx

New member
Would this be it?

C#:
/// ---------------------------------------------
/// Ultimate Character Controller
/// Copyright (c) Opsive. All Rights Reserved.
/// https://www.opsive.com
/// ---------------------------------------------

using Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Game;
using Opsive.UltimateCharacterController.Objects;
using Opsive.UltimateCharacterController.Utility;
using Photon.Pun;
using UnityEngine;

/// <summary>
/// Initializes the grenade over the network.
/// </summary>
public class PunTrajectoryObject : TrajectoryObject, ISpawnDataObject
{
    private object[] m_SpawnData;

    /// <summary>
    /// Returns the initialization data that is required when the object spawns. This allows the remote players to initialize the object correctly.
    /// </summary>
    /// <returns>The initialization data that is required when the object spawns.</returns>
    public object[] SpawnData()
    {
        if (m_SpawnData == null)
        {
            m_SpawnData = new object[4];
        }
        m_SpawnData[0] = m_Velocity;
        m_SpawnData[1] = m_Torque;
        m_SpawnData[2] = m_ImpactLayers.value;
        m_SpawnData[3] = m_Originator.GetCachedComponent<PhotonView>().ViewID;

        return m_SpawnData;
    }

    /// <summary>
    /// The object has been spawned. Initialize the grenade.
    /// </summary>
    public void ObjectSpawned()
    {
        var photonView = gameObject.GetCachedComponent<PhotonView>();
        if (photonView == null || photonView.InstantiationData == null)
        {
            return;
        }

        // Initialize the grenade from the data within the InitializationData field.
        var originator = PhotonNetwork.GetPhotonView((int)photonView.InstantiationData[9]);
        Initialize((Vector3)photonView.InstantiationData[0], (Vector3)photonView.InstantiationData[1], originator.gameObject, false);

    }
}
 

Justin

Administrator
Staff member
Without testing it that looks correct. The object is setup within PunMultiplayerAddOnInspector.SetupObject.
 
Top