void Start()
 {
     character = this.GetComponent <CharacterSystem>();
     ai        = character.GetComponent <AICharacterShooterNav>();
     timeTmp   = Time.time;
     TimeWait  = Random.Range(TimeWait / 2, TimeWait);
 }
Exemple #2
0
    //存储玩家
    public void SavePlayer(CharacterSystem character)
    {
        if (UnitZ.gameManager == null || character == null)
        {
            return;
        }

        PlayersRegister(UnitZ.gameManager.UserID);
        PlayerSaveData playersave = new PlayerSaveData();

        playersave.UID          = UnitZ.gameManager.UserID;
        playersave.PlayerName   = UnitZ.gameManager.UserName;
        playersave.CharacterKey = character.CharacterKey;
        playersave.ItemData     = character.inventory.GetItemDataText();
        playersave.EquipData    = character.inventory.GenStickerTextData();
        playersave.FPSItemIndex = character.inventory.GetCollectorFPSindex();
        playersave.Position     = character.transform.position.x + "," + character.transform.position.y + "," + character.transform.position.z;
        playersave.LevelName    = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
        playersave.Health       = character.HP;

        CharacterLiving living = character.GetComponent <CharacterLiving> ();

        if (living)
        {
            playersave.Food  = living.Hungry;
            playersave.Water = living.Water;
        }
        WriteData(playersave);
    }
Exemple #3
0
 public virtual void Pickup(CharacterSystem character)
 {
     if (character && (character.IsMine || (!Network.isClient && !Network.isServer))) {
         CharacterDriver driver = character.GetComponent<CharacterDriver> ();
         if (driver) {
             for (int i=0; i<Seats.Length; i++) {
                 if (Seats [i].passenger == null) {
                     Debug.Log ("Pick up " + character.name);
                     Seats [i].GetIn (driver);
                     break;
                 }
             }
         }
     }
 }
Exemple #4
0
    void ApplyPlayerData(PlayerSaveData playersave, CharacterSystem character)
    {
        if (character && character.inventory)
        {
            string[] positionraw = playersave.Position.Split("," [0]);
            if (positionraw.Length > 2)
            {
                Vector3 position = Vector3.zero;
                float.TryParse(positionraw [0], out position.x);
                float.TryParse(positionraw [1], out position.y);
                float.TryParse(positionraw [2], out position.z);
                character.transform.position = position;
            }

            character.HP = playersave.Health;
            CharacterLiving living = character.GetComponent <CharacterLiving> ();
            if (living)
            {
                living.Hungry = playersave.Food;
                living.Water  = playersave.Water;
            }
            //如果有新存储,参数都使用默认
            if (playersave.Food <= 0 && playersave.Water <= 0 && playersave.Health <= 0)
            {
                character.HP = character.HPmax;
                if (living)
                {
                    living.Hungry = living.HungryMax;
                    living.Water  = living.WaterMax;
                }
            }

            //Debug.Log ("Applying "+playersave.ItemData+" |  "+playersave.EquipData+" | "+playersave.FPSItemIndex);
            //Debug.Log ("with " + PlayerSaveDataText (playersave));
            character.inventory.SetupStarterItem();
            character.inventory.SetItemsFromText(playersave.ItemData);
            character.inventory.UpdateSticker(playersave.EquipData);

            if (character.inventory.Items.Count > playersave.FPSItemIndex)
            {
                character.inventory.EquipItemByCollector(character.inventory.Items [playersave.FPSItemIndex]);
            }
        }
    }
 private void Update()
 {
     if (!GameCore.gameManager.isGameEnd)
     {
         FacingCheck();
         Vector3      rayDirection = transform.TransformDirection(direction) * EnemyCheckerRayDistance;
         RaycastHit2D EnemyHit     = Physics2D.Raycast(transform.position, rayDirection, EnemyCheckerRayDistance, EnemyLayer);
         if (character.GetComponent <Prince>())
         {
             if (EnemyHit)
             {
                 GameCore.combatController.currentEnemy = EnemyHit.collider.gameObject;
             }
             else
             {
                 GameCore.combatController.currentEnemy = null;
             }
         }
         Debug.DrawRay(transform.position, direction * EnemyCheckerRayDistance, Color.green);
     }
 }
Exemple #6
0
    void ApplyPlayerData(PlayerSaveData playersave, CharacterSystem character)
    {
        if (character && character.inventory) {
            //Debug.Log ("Applying ");
            //Debug.Log ("with " + PlayerSaveDataText (playersave));

            character.inventory.SetItemsFromText (playersave.ItemData);
            character.inventory.UpdateOtherInventory (playersave.EquipData);
            if (character.inventory.Items.Count > playersave.FPSItemIndex)
                character.inventory.EquipItemByCollector (character.inventory.Items [playersave.FPSItemIndex]);
            string[] positionraw = playersave.Position.Split ("," [0]);
            if (positionraw.Length > 2) {
                Vector3 position = Vector3.zero;
                float.TryParse (positionraw [0], out position.x);
                float.TryParse (positionraw [1], out position.y);
                float.TryParse (positionraw [2], out position.z);
                character.transform.position = position;
            }

            character.HP = playersave.Health;
            CharacterLiving living = character.GetComponent<CharacterLiving> ();
            if (living) {
                living.Hungry = playersave.Food;
                living.Water = playersave.Water;
            }
            // if new save, all parameter must be set by default.
            if (playersave.Food <= 0 && playersave.Water <= 0 && playersave.Health <= 0) {
                character.HP = character.HPmax;
                if (living) {
                    living.Hungry = living.HungryMax;
                    living.Water = living.WaterMax;
                }
            }

            character.InitializeData ();
        }
    }
Exemple #7
0
    public void SavePlayer(CharacterSystem character)
    {
        if (UnitZ.gameManager == null || character == null)
            return;

        PlayersRegister (UnitZ.gameManager.UserID);
        string hasKey = UnitZ.gameManager.UserID;
        PlayerSaveData playersave = new PlayerSaveData ();

        playersave.UID = hasKey;
        playersave.PlayerName = UnitZ.gameManager.UserName;
        playersave.ItemData = character.inventory.GetItemDataText ();
        playersave.EquipData = character.inventory.GenStickerTextData ();
        playersave.FPSItemIndex = character.inventory.GetCollectorFPSindex ();
        playersave.Position = character.transform.position.x + "," + character.transform.position.y + "," + character.transform.position.z;
        playersave.LevelName = Application.loadedLevelName;
        playersave.Health = character.HP;

        CharacterLiving living = character.GetComponent<CharacterLiving> ();
        if (living) {
            playersave.Food = living.Hungry;
            playersave.Water = living.Water;
        }

        if ((!Network.isServer && !Network.isClient) || Network.isServer) {
            WriteData (playersave);
        } else {
            if (networkViewer)
                networkViewer.RPC ("SaveToServer", RPCMode.Server, PlayerSaveDataText (playersave));
        }
    }
    void Update()
    {
        if (PlayerManage == null || Canvas == null)
            return;

        mainCharacter = PlayerManage.playingCharacter;

        if (PlayerManage.playingCharacter != null) {
            Canvas.gameObject.SetActive (true);
        } else {
            Canvas.gameObject.SetActive (false);
        }

        if (mainCharacter) {

            InputController ();

            if (HPbar) {
                HPbar.Value = mainCharacter.HP;
                HPbar.ValueMax = mainCharacter.HPmax;
            }
            if (FoodBar && living) {
                FoodBar.Value = living.Hungry;
                FoodBar.ValueMax = living.HungryMax;
            }
            if (WaterBar && living) {
                WaterBar.Value = living.Water;
                WaterBar.ValueMax = living.WaterMax;
            }

            if (living == null)
                living = mainCharacter.GetComponent<CharacterLiving> ();

        } else {
            living = null;
        }
    }