纳金网

标题: Unity3D 玩家管理 [打印本页]

作者: 王者再临    时间: 2014-8-30 01:56
标题: Unity3D 玩家管理
  1. using UnityEngine;
  2. using System.Collections;

  3. /// <summary>
  4. /// 游戏管理员
  5. /// </summary>
  6. public class GameMaster : MonoBehaviour {
  7.     /// <summary>
  8.     /// 玩家的复活点
  9.     /// </summary>
  10.     private Vector3 _playerSpwanPointPos;

  11.         void Start () {
  12.         //初始化玩家的复活点
  13.         _playerSpwanPointPos = new Vector3(836f, 0, 790f);
  14.         GameObject go = GameObject.Find(GameSetting.PLAYER_SPWAN_POINT);
  15.         if (go == null)
  16.         {
  17.             Debug.LogWarning("没有找到玩家的复活点");
  18.             go = new GameObject(GameSetting.PLAYER_SPWAN_POINT);
  19.             go.transform.position = _playerSpwanPointPos;
  20.         }

  21.         //构建玩家游戏对象
  22.         GameObject obj = Resources.LoadAssetAtPath("Assets\\Prefabs\\Player\\Sample Hero\\Player-Swordman.prefab", typeof(GameObject)) as GameObject;
  23.         obj = Instantiate(obj) as GameObject;
  24.         obj.name = "Player";

  25.         //构建主相机
  26.         GameObject cam=Resources.LoadAssetAtPath("Assets\\Prefabs\\Player\\Camera\\main Camera.prefab", typeof(GameObject)) as GameObject;
  27.         cam = Instantiate(cam) as GameObject;
  28.         cam.name = "Main Camera";
  29.         cam.GetComponent<MouseOrbit>().m_target = obj;

  30.         LoadCharacter();
  31.         }

  32.     #region 加载角色的信息
  33.     /// <summary>
  34.     /// 加载角色的信息
  35.     /// </summary>
  36.     public void LoadCharacter()
  37.     {
  38.         GameObject go = GameObject.Find("GameSetting");
  39.         if (go == null)
  40.         {
  41.             go = Resources.LoadAssetAtPath("Assets\\Prefabs\\Global\\GameSetting.prefab", typeof(GameObject)) as GameObject;
  42.             go = Instantiate(go) as GameObject;
  43.             go.name = "GameSetting";
  44.         }
  45.         GameSetting setting = GameObject.Find("GameSetting").GetComponent<GameSetting>();
  46.         //加载角色保存的信息
  47.         setting.LoadCharacterData();
  48.     }
  49.     #endregion
  50. }
复制代码

作者: heise    时间: 2014-8-30 02:16
谢谢分享
作者: hyui    时间: 2014-8-30 03:16
Great stuff !         




欢迎光临 纳金网 (http://course.narkii.com/club/) Powered by Discuz! X2.5