private void Start()
    {
        if (!SNet_Network.instance.isHost())
        {
            Destroy(gameObject);
        }

        if (GetComponent <SNet_Identity>().set)
        {
            return;
        }

        if (Application.isEditor && string.IsNullOrEmpty(prefab))
        {
            /*
             * SET PREFAB NAME
             * */
            prefab = gameObject.name;
        }

        if (Application.isPlaying && !string.IsNullOrEmpty(prefab))
        {
            WheelCollider[] wheels = GetComponentsInChildren <WheelCollider>();
            foreach (WheelCollider wc in wheels)
            {
                wc.enabled = false;
            }
            Destroy(GetComponent <SNet_Vehicle>());
            Destroy(GetComponent <Collider>());
            Destroy(GetComponent <Rigidbody>());

            MonoBehaviourExtensions.Invoke(this, Respawn, 0.5f);
        }
    }
    /// <summary>
    /// Syncs vehicle data and update the toucheds
    /// </summary>
    public void VehicleUpdate()
    {
        if (!SNet_Network.instance.isHost())
        {
            return; // Only host can sync vehicle data.
        }
        for (int i = 0; i < vehicle.p.Count; i++)
        {
            if (vehicle.p[i] == 0)
            {
                continue;
            }

            if (SNet_Identity.list.Find(x => x.identity == vehicle.p[i]) == null)
            {
                // Missing passenger
                vehicle.p[i] = 0;
            }
        }

        if (vehicle != null && vehicle.p.Count > 0)
        {
            SNet_Network.instance.Send_Message(vehicle);
        }

        if (vehicle != null)
        {
            SNet_Network.instance.Send_Message(health);
        }

        MonoBehaviourExtensions.Invoke(this, VehicleUpdate, 3f);
    }
Пример #3
0
    private void Start()
    {
        tag = "Explosive";

        startTime = Time.time;

        if (explodeInTime > 0)
        {
            MonoBehaviourExtensions.Invoke(this, Explode_Request, explodeInTime);
        }
    }
    private void Start()
    {
        identity = GetComponent <SNet_Identity>();
        info     = new VI(identity.identity);
        vehicle  = new V(identity.identity);
        health   = new VH(identity.identity, maxHealth);

        vehicle.p = new List <ulong>();
        for (int i = 0; i < seatPoints.Count; i++)
        {
            vehicle.p.Add(0);
        }

        MonoBehaviourExtensions.Invoke(this, VehicleUpdate, 3f);
    }
Пример #5
0
    public void Open(bool show = true)
    {
        if (activeSelf && !gameObject.activeSelf)
        {
            activeSelf = false;
            return;
        }

        if (!myCanvas)
        {
            AddCanvas();
            myCanvas.alpha = (showOnStart) ? 1 : 0;
        }

        activeSelf = show;

        if (show)
        {
            if (hideIn != 0)
            {
                CancelInvoke();
                MonoBehaviourExtensions.Invoke(this, Close, hideIn);
            }

            gameObject.SetActive(true);
            alphaDown = 1;
        }
        else
        {
            if (!gameObject.activeSelf)
            {
                return;
            }

            alphaDown = -1;
        }
    }
Пример #6
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);
 }
Пример #7
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);
                    }
                }
            }
        }
    }
Пример #8
0
 public void Invoke(Action theDelegate, float time)
 {
     MonoBehaviourExtensions.Invoke(this, theDelegate, time);
 }