コード例 #1
0
        public Player PlayerConstructor(Vector3 pos, Vector2 scale, PlayerState iniState)
        {
            if (_prefabManager == null)
            {
                var pIns = PrefabManager.GetInstance();
                if (pIns == null)
                {
                    throw new Exception("get null prefab manager");
                }
                _prefabManager = pIns;
            }

            var playerPrefab = _prefabManager.GetGameObject("Player");

            if (playerPrefab == null)
            {
                throw new Exception("get null player prefab");
            }

            var playerObject = Object.Instantiate(playerPrefab);

            playerObject.transform.position   = pos;
            playerObject.transform.localScale = scale;
            var controller = playerObject.AddComponent <OperationEventListener>();
            var player     = playerObject.GetComponent <Player>();

            player.InitPlayer(controller, iniState);
            player.ModifySelfId(Guid.NewGuid());
            _sendInit(playerObject, "Player");

            return(player);
        }
コード例 #2
0
    public void LoadLevel(string path)
    {
        //string path = Application.persistentDataPath + "/Saves/";

        //if (File.Exists(path + level.name + ".json"))
        if (File.Exists(path))
        {
            Clear();

            string str = File.ReadAllText(path);

            var sqrObjects = JsonHelper.FromJson <SquareObject>(str);

            foreach (var obj in sqrObjects)
            {
                Square square = new Square(obj.pos);
                square.objects.Add(obj);

                var selectedOriginal = prefabManager.GetGameObject(obj.pid);
                if (level.AddSquareObject(obj.pos, obj.rotation, selectedOriginal) != null)
                {
                    CreateNewObject(obj.pid, obj.pos, obj.rotation);
                }

                //level.map.Add(square.position, square);
            }

            level.name          = Path.GetFileNameWithoutExtension(path);
            levelNameInput.text = level.name;

            //level.LoadLevel(str);
        }
    }
コード例 #3
0
    GameObject CreateNewObject(int pid, IPosition pos, Vector3 rotation)
    {
        var selectedOriginal = prefabManager.GetGameObject(pid);

        if (selectedOriginal.tag == "Start")
        {
            selectedOriginal = playerPrefab;
        }

        var newObject = Instantiate(selectedOriginal, new Vector3(pos.x, pos.y / 2.0f, pos.z), Quaternion.Euler(rotation), levelHolder.transform);

        if (newObject.tag == "Player")
        {
            player = newObject.GetComponent <PlayerMovement>();
        }

        return(newObject);
    }
コード例 #4
0
        public Player PlayerConstructor(Vector3 pos, Vector2 scale, PlayerState iniState)
        {
            if (_prefabManager == null)
            {
                var pIns = PrefabManager.GetInstance();
                if (pIns == null)
                {
                    throw new Exception("get null prefab manager");
                }
                _prefabManager = pIns;
            }

            var playerPrefab = _prefabManager.GetGameObject("Player");

            if (playerPrefab == null)
            {
                throw new Exception("get null player prefab");
            }

            var playerObject = Object.Instantiate(playerPrefab);

            playerObject.transform.position   = pos;
            playerObject.transform.localScale = scale;
            var player = playerObject.GetComponent <Player>();

            player.jumpScale = 8;

            var     controllerPrefab     = PrefabManager.GetInstance().GetGameObject("AppController");
            Vector3 controllerPosition   = _isUpperPlayer ? new Vector3(0, 10.5f) : new Vector3(0, -10.5f);
            var     controllerGameObject = Object.Instantiate(controllerPrefab, controllerPosition, quaternion.identity);
            var     controller           = controllerGameObject.GetComponent <IPlayerController>();

            if (controller == null)
            {
                Debug.Log("player controller is null");
            }
            player.InitPlayer(controller, iniState);
            _isUpperPlayer = !_isUpperPlayer;
            return(player);
        }