Exemplo n.º 1
0
 void GeneralSync()
 {
     SNet_Network.instance.SpawnPlayer(identity.prefab, transform.position, transform.rotation, transform.localScale);
     MonoBehaviourExtensions.Invoke(this, GeneralSync, 5f);
     MonoBehaviourExtensions.Invoke(this, SyncData, 3f);
 }
Exemplo n.º 2
0
 public void Cooldown(Cooldown cooldown, Action finalAction)
 {
     this.StartCoroutine(MonoBehaviourExtensions.StartCooldownRoutine(this, cooldown, finalAction));
 }
Exemplo n.º 3
0
    void Start()
    {
        list.Add(this);

        cameraHolder = transform.Find("CameraHolder"); // standart camera position
        if (cameraHolder != null)
        {
            defaultCamPosition = cameraHolder.localPosition;
        }
        focusHolder = transform.Find("FocusHolder"); // camera position when right mouse aimed

        aim       = new A();
        identity  = GetComponent <SNet_Identity>();
        health    = new Health(identity.identity);
        inventory = GetComponent <PlayerInventory>();
        ik        = GetComponent <IKFixer>();

        // Add default starting item of the map.
        if (!string.IsNullOrEmpty(GameMap.instance.startingItem))
        {
            inventory.AddItem(ResourcesLoader.prefabs.Find(x => x.name == GameMap.instance.startingItem).GetComponent <Item>().item);
        }
        //

        aimBone = identity.animator.animator.GetBoneTransform(HumanBodyBones.Spine);

        if (isLocalPlayer)
        {
            /*
             * Local players & host controlled NPCs must sync themselves
             * */
            MonoBehaviourExtensions.Invoke(this, GeneralSync, 5f);

            // Hide the player spawner panel, because we are already spawned.
            SNet_Manager.instance.panel_Game.transform.Find("playerSpawner").gameObject.SetActive(false);
        }
        else
        {
            // Other players UI
            UI_PlayerAgent = Instantiate(SNet_Manager.instance.UI_PlayerAgent, aimBone.parent);
            UI_PlayerAgent.localPosition = SNet_Manager.instance.UI_PlayerAgent.localPosition;
            UI_PlayerAgent.Find("steamAvatar").GetComponent <Facepunch_Avatar>().Fetch(identity.identity);
            UI_PlayerAgent.Find("steamName").GetComponent <Text>().text = Client.Instance.Friends.GetName(identity.identity);
        }

        /*
         * THIS IS A NEW PLAYER, UPDATE THE SPAWNED IDENTITIES FOR THE NEW PLAYER
         * */

        if (SNet_Network.instance.isHost())
        { // Host will update the spawneds
            Debug.Log("New player spawned, SpawnAll()");
            int sCount = SNet_Identity.list.Count;
            for (int i = 0; i < sCount; i++)
            {
                if (!SNet_Identity.list[i].controller)
                { // Refresh only non-player objects
                    SNet_Network.Spawn sp = new SNet_Network.Spawn
                                                (SNet_Identity.list[i].prefab,
                                                SNet_Identity.list[i].transform.position,
                                                SNet_Identity.list[i].transform.rotation,
                                                SNet_Identity.list[i].transform.localScale,
                                                0, true);

                    sp.i = SNet_Identity.list[i].identity;
                    SNet_Network.instance.Send_Message(sp, identity.identity);

                    /*
                     * UPDATE SYNCERS (Transforms, rigidbodies), But DON'T MAKE ANGRY STEAM SERVERS, SO USE RANDOM VALUES
                     * */
                    if (SNet_Identity.list[i].tform != null)
                    {
                        SNet_Identity.list[i].tform.ReUpdate();
                    }

                    if (SNet_Identity.list[i].rbody != null)
                    {
                        SNet_Identity.list[i].rbody.ReUpdate();
                    }

                    if (SNet_Identity.list[i].vehicle != null)
                    {
                        MonoBehaviourExtensions.Invoke(SNet_Identity.list[i].vehicle, SNet_Identity.list[i].vehicle.VehicleUpdate, 3f);
                    }
                }
            }
        }
    }
Exemplo n.º 4
0
 public void Invoke(Action theDelegate, float time)
 {
     MonoBehaviourExtensions.Invoke(this, theDelegate, time);
 }