// Callback used by UNET
 public void OnConnect(ServerClient svrclnt)
 {
     if (svrclnt == ServerClient.Server)
     {
         MasterNetAdapter.Spawn(prefab, transform.position, transform.rotation, null);
     }
 }
 // Callback used by PUN
 public void OnJoinRoom()
 {
     if (MasterNetAdapter.ServerIsActive)
     {
         MasterNetAdapter.Spawn(prefab, transform.position, transform.rotation, null);
     }
 }
Beispiel #3
0
        /// <summary>
        /// Callback from the root NST when alive status changes.
        /// </summary>
        /// <param name="state"></param>
        public void OnNstState(State state)
        {
            bool isalive = state.IsAlive();

            // if this is a ressurection, move to a spawn point. Don't move if this is giving birth (first run) - the NM just assigned this location already.
            if (MasterNetAdapter.ServerIsActive && isalive && alreadyBorn)
            {
                nst.Teleport(MasterNetAdapter.GetPlayerSpawnPoint());
            }

            if (playerMesh != null)
            {
                playerMesh.SetActive(state.IsVisible());
            }

            if (na.IsLocalPlayer)
            {
                SetCamera(isalive);
            }

            // note time of death for respawn methods
            if (isalive == false)
            {
                deathTime = Time.time;
            }

            // note that this object now exists in the world, and will need to be moved to spawn points when it ressurects.
            if (isalive)
            {
                alreadyBorn = true;
            }
        }
        /// <summary>
        /// Callback from the root NST when alive status changes.
        /// </summary>
        /// <param name="newState"></param>
        public void OnNstState(State newState, State oldState)
        {
            bool isalive  = newState.IsAlive();
            bool wasalive = oldState.IsAlive();

            // if this is a ressurection, move to a spawn point. Don't move if this is giving birth (first run) - the NM just assigned this location already.
            if (isalive && !wasalive && alreadyBorn)
            {
                if (na.IAmActingAuthority)
                {
                    Transform tr = MasterNetAdapter.UNET_GetPlayerSpawnPoint();

                    // if no spawn returned from the engine, lets look for a sample spawn point.
                    if (!tr)
                    {
                        tr = NSTSamplePlayerSpawn.GetRandomSpawnPoint();
                    }

                    Vector3    pos = (tr) ? tr.position : Vector3.zero;
                    Quaternion rot = (tr) ? tr.rotation : Quaternion.identity;

                    nst.Teleport(pos, rot);
                }
            }
            ApplyState(newState);

            // note time of death for respawn methods
            if (!isalive && wasalive)
            {
                timeSinceDeath = 0;
            }
        }
Beispiel #5
0
 public void OnNstMasterStartServer()
 {
     if (MasterNetAdapter.ServerIsActive)
     {
         GameObject go = Instantiate(prefab, null);
         go.transform.position = transform.position;
         MasterNetAdapter.Spawn(go);
     }
 }
Beispiel #6
0
 // Update is called once per frame
 void Update()
 {
     if (Input.GetKeyDown(scene2Key))
     {
         MasterNetAdapter.ServerChangeScene("Scene2");
     }
     if (Input.GetKeyDown(scene3Key))
     {
         MasterNetAdapter.ServerChangeScene("Scene3");
     }
     if (Input.GetKeyDown(scene4Key))
     {
         MasterNetAdapter.ServerChangeScene("Scene4");
     }
 }
Beispiel #7
0
    // Teleport shortcuts
    private void Update()
    {
        if (Input.GetKeyDown("0"))
        {
            NSTTools.allNsts[0].Teleport(MasterNetAdapter.UNET_GetPlayerSpawnPoint());
        }

        if (Input.GetKeyDown("9"))
        {
            NSTTools.allNsts[1].Teleport(MasterNetAdapter.UNET_GetPlayerSpawnPoint());
        }

        if (Input.GetKeyDown("8"))
        {
            NSTTools.allNsts[2].Teleport(MasterNetAdapter.UNET_GetPlayerSpawnPoint());
        }
    }
Beispiel #8
0
    // Teleport shortcuts
    private void Update()
    {
        if (MasterNetAdapter.ServerIsActive)
        {
            if (Input.GetKeyDown("0"))
            {
                NetworkSyncTransform.allNsts[0].Teleport(MasterNetAdapter.GetPlayerSpawnPoint());
            }

            if (Input.GetKeyDown("9"))
            {
                NetworkSyncTransform.allNsts[1].Teleport(MasterNetAdapter.GetPlayerSpawnPoint());
            }

            if (Input.GetKeyDown("8"))
            {
                NetworkSyncTransform.allNsts[2].Teleport(MasterNetAdapter.GetPlayerSpawnPoint());
            }
        }
    }
Beispiel #9
0
        public override void OnInspectorGUI()
        {
            NSTSampleHealthUI _target = (NSTSampleHealthUI)target;
            IVitals           ivitals = null;

            base.OnInspectorGUI();

            EditorGUILayout.HelpBox("This component should be placed on a UI Text or UI Image (with Image Type set to Filled ideally). " +
                                    "It can monitor IVitals on the root of this object, or of the local player gameobject.", MessageType.None);

            string monitorTooltip = "Which IVital should be be monitoring? Auto will try to find an IVital interface on the root of this object first, and if it can't find one will subscribe to the local player IVital.";

            _target.monitor = (NSTSampleHealthUI.Monitor)EditorGUILayout.EnumPopup(new GUIContent("IVitals Source", monitorTooltip), _target.monitor);

            bool monitorSelf      = _target.monitor == NSTSampleHealthUI.Monitor.Self;
            bool monitorLclPlayer = _target.monitor == NSTSampleHealthUI.Monitor.LocalPlayer;

            // if monitoring self is an option, try to take it - see if we have vitals
            if (!monitorLclPlayer)
            {
                ivitals = _target.transform.root.GetComponent <IVitals>();
            }

            // failed to find vitals or we are only set to monitor the local player
            if (ivitals == null && !monitorSelf)
            {
                // make the GO selector available if no vitals were found on this object
                string gotooltip = "Used by the editor only. The IVitals on this gameobject is where vital names in the list below are pulled from.";
                _target.playerGO = (GameObject)EditorGUILayout.ObjectField(new GUIContent("Player GameObj", gotooltip), _target.playerGO, typeof(GameObject), true);

                //GameObject monitoredPrefab = _target.playerGO;

                if (_target.playerGO == null)
                {
                    _target.playerGO = MasterNetAdapter.GetRegisteredPlayerPrefab();


                    Debug.Log(
                        //DebugX.LogWarning(!DebugX.logWarnings ? "" : (
                        ("NSTSampleHealthUI on '" + _target.name + "' is using the NetworkManager registered playerPrefab '" + _target.playerGO.name + "' as its source."));
                }

                if (_target.playerGO != null)
                {
                    ivitals = _target.playerGO.GetComponent <IVitals>();
                }
            }


            int i = 0;

            // if we found an iVitals... scrape out the names
            if (ivitals != null)
            {
                for (i = 0; i < ivitals.Vitals.Count; i++)
                {
                    vitalnames[i] = (new GUIContent(i.ToString() + " " + ivitals.Vitals[i].name));
                }
            }

            // if not, just make a list of numbers
            for (int j = i; j < 16; j++)
            {
                vitalnames[j] = (new GUIContent(j.ToString()));
            }


            string     vitalIdTooltip = "Which vital to monitor.";
            GUIContent label          = new GUIContent("Monitored Vital", vitalIdTooltip);

            _target.monitoredVitalId = EditorGUILayout.Popup(label, _target.monitoredVitalId, vitalnames);
            //_target.monitoredVitalId = EditorGUILayout.Popup("Monitored Vital", _target.monitoredVitalId, vitalnames);

            serializedObject.ApplyModifiedProperties();
        }