private void RpcShowFakeObject(PickupableObject.PickupableType type)
 {
     if (!isLocalPlayer)
     {
         CommonShowFakeObject(type);
     }
 }
Beispiel #2
0
    /// <summary>
    /// Should only be called from server. Will also make RpcCommand to cache client-side
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    public GameObject CacheNewObject(PickupableObject.PickupableType type, bool isArespawn = false, bool respawnTriggerdByServer = true)
    {
        if (!isServer)
        {
            Debug.LogError("Should only be called from server");
        }

        GameObject modelToSpawn = spawnableInteractableObjects[(int)type];

        if (!isArespawn || (isArespawn && respawnTriggerdByServer))
        {
            serverAuthorityCachedObjects[(int)type] = Instantiate(modelToSpawn, new Vector3(0, 200 * ((int)type + 1), 0), modelToSpawn.transform.rotation);
            serverAuthorityCachedObjects[(int)type].GetComponent <Rigidbody>().useGravity  = (false);
            serverAuthorityCachedObjects[(int)type].GetComponent <Rigidbody>().isKinematic = (false);
            serverAuthorityCachedObjects[(int)type].GetComponent <ResettableObject>().wasSpawnedByGameManager = (true);
            serverAuthorityCachedObjects[(int)type] = serverAuthorityCachedObjects[(int)type];
            NetworkServer.Spawn(serverAuthorityCachedObjects[(int)type]);
        }

        if (!isArespawn || (isArespawn && !respawnTriggerdByServer))
        {
            clientAuthorityCachedObjects[(int)type] = Instantiate(modelToSpawn, new Vector3(0, 210 * ((int)type + 1), 0), modelToSpawn.transform.rotation);
            clientAuthorityCachedObjects[(int)type].GetComponent <Rigidbody>().useGravity  = (false);
            clientAuthorityCachedObjects[(int)type].GetComponent <Rigidbody>().isKinematic = (false);
            clientAuthorityCachedObjects[(int)type].GetComponent <ResettableObject>().wasSpawnedByGameManager = (true);
            NetworkServer.Spawn(clientAuthorityCachedObjects[(int)type]);
            SetPlayerAuthorityToHeldObject(GetNonLocalPlayer().GetComponent <NetworkIdentity>(), clientAuthorityCachedObjects[(int)type].GetComponent <NetworkIdentity>());
            clientAuthorityCachedObjects[(int)type] = clientAuthorityCachedObjects[(int)type];

            RpcCacheNewObject(clientAuthorityCachedObjects[(int)type], type);
        }

        return(serverAuthorityCachedObjects[(int)type]);
    }
Beispiel #3
0
 // When the player falls into lava with a carried object, the cached one should be reset and a new one should be cached
 public void ResetCachedObject(PickupableObject.PickupableType type)
 {
     if (isServer)
     {
         serverAuthorityCachedObjects[(int)type].GetComponent <ResettableObject>().Reset();
         serverAuthorityCachedObjects[(int)type] = CacheNewObject(type);
     }
 }
    private void LiftPickup(Transform other, PickupableObject.PickupableType type)
    {
        if (!Physics.CheckSphere(other.position, checkRadius, LayerMask.NameToLayer("Ignore Raycast")))
        {
            AkSoundEngine.PostEvent("pickup", gameObject);
            if (isLocalPlayer)
            {
                ResettableObject ro = other.GetComponent <ResettableObject>();

                if (!ro.hasOriginalPosition)
                {
                    positionOfResettableObject = other.transform.position;
                    rotationOfResettableObject = other.transform.rotation;
                }
                else
                {
                    positionOfResettableObject = ro.OriginalPosition;
                    rotationOfResettableObject = ro.OriginalRotation;
                }
            }

            // Only destroy objects on the server
            if (isServer)
            {
                NetworkServer.Destroy(other.gameObject);
            }
            else
            {
                CmdServerDestroy(other.gameObject);
            }

            CommonLiftPickup(type);

            // Local player only
            timeOfPickup = Time.time;

            if (isLocalPlayer)
            {
                if (isServer)
                {
                    RpcLiftPickup(type);
                }
                else
                {
                    CmdLiftPickup(type);
                }
            }
        }
        else
        {
            // TODO: handle not being able to pickup if necessary
            Debug.LogWarning("The player tried to lift something over it's head and something was in the way. Did it look/feel super bad?");
        }
    }
Beispiel #5
0
 /// <summary>
 /// Should only be called from server
 /// </summary>
 /// <param name="type"></param>
 public void CachedObjectWasUsed(PickupableObject.PickupableType type, bool usedByServer)
 {
     if (isServer)
     {
         serverAuthorityCachedObjects[(int)type] = CacheNewObject(type, true, usedByServer);
     }
     else
     {
         Debug.LogError("CacheObjectWas used called from server");
     }
 }
Beispiel #6
0
    private void RpcCacheNewObject(GameObject go, PickupableObject.PickupableType type)
    {
        if (isServer)
        {
            return;
        }

        clientAuthorityCachedObjects[(int)type] = go;
        clientAuthorityCachedObjects[(int)type].GetComponent <Rigidbody>().useGravity = false;
        clientAuthorityCachedObjects[(int)type].GetComponent <ResettableObject>().wasSpawnedByGameManager = (true);
    }
    /// <summary>
    /// Side effect: will set heldObjectType to type
    /// </summary>
    /// <param name="type"></param>
    private void ShowFakeObject(PickupableObject.PickupableType type)
    {
        CommonShowFakeObject(type);

        if (isServer)
        {
            RpcShowFakeObject(type);
        }
        else
        {
            CmdShowFakeObject(type);
        }
    }
Beispiel #8
0
 public GameObject GetCachedObject(PickupableObject.PickupableType type)
 {
     if (isServer)
     {
         serverAuthorityCachedObjects[(int)type].GetComponent <ResettableObject>().wasSpawnedByGameManager = (false);
         return(serverAuthorityCachedObjects[(int)type]);
     }
     else
     {
         clientAuthorityCachedObjects[(int)type].GetComponent <ResettableObject>().wasSpawnedByGameManager = (false);
         return(clientAuthorityCachedObjects[(int)type]);
     }
 }
 public void CmdResetCachedObject(PickupableObject.PickupableType type)
 {
     GManager.Instance.ResetCachedObject(type);
 }
 private void CmdShowFakeObject(PickupableObject.PickupableType type)
 {
     CommonShowFakeObject(type);
 }
 private void CommonShowFakeObject(PickupableObject.PickupableType type)
 {
     fakeObjects[(int)type].SetActive(true);
     heldObjectType = type;
 }
 private void CommonLiftPickup(PickupableObject.PickupableType type)
 {
     newHeldObj = HoldableType.Pickup;
     ShowFakeObject(type);
 }
 private void RpcLiftPickup(PickupableObject.PickupableType type)
 {
     CommonLiftPickup(type);
 }