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?
 
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.
 
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);

    }
}
 
Without testing it that looks correct. The object is setup within PunMultiplayerAddOnInspector.SetupObject.
 
Did this ever get added to the Pun addon? I cant find it. Also Im trying to implement the mentioned solution without success. (Could be to my lack of advanced knowledge in C#)
 
This seems to work!

Code:
/// ---------------------------------------------
/// 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;
using Opsive.Shared.Game;


namespace Opsive.UltimateCharacterController.AddOns.Multiplayer.PhotonPun.Objects
{

    /// <summary>
    /// Initializes the grenade over the network.
    /// </summary>
    public class PunTrajectoryObject : TrajectoryObject, ISpawnDataObject
    {
        private object[] m_SpawnData;
        private object[] m_InstantiationData;
        public object[] InstantiationData { get => m_InstantiationData; set => m_InstantiationData = value; }

        /// <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);

        }
    }

}
 
Top