public void FreePetView()
        {
            focused = false;
            DOTween.KillAll();

            /* Closing the pet information */
            InformationUI.SetActive(false);

            current_focus_pet = null;
            GameObject.FindWithTag("MainCamera").GetComponent <CameraController>().DefaultView();
            CameraTargetPosition = Vector3.zero;
        }
        public void UpdatePetView()
        {
            string[] _petids = PlayerData.instance.GetPetsId();
            current_view_index = PlayerData.instance.GetPlayerFocusPetId();

            /* Destroy a old pet view */
            if (pets_view_data.Count > 0)
            {
                for (int i = 0; i < pets_view_data.Count; i++)
                {
                    Destroy(pets_view_data[i].gameObject);
                }
            }
            pets_view_data.Clear();


            /* Add a new pet view */
            int current_focus_id = PlayerData.instance.GetPlayerFocusPetId();

            if ((_petids != null) && (PetViewPrefab != null))
            {
                for (int i = 0; i < _petids.Length; i++)
                {
                    int id;
                    int.TryParse(_petids[i], out id);
                    Debug.Log(id);

                    /* A insatnced position in background*/
                    Vector2 new_view_pos = Vector2.zero + new Vector2(Random.Range(-ContainerWidth * PET_VIEWS_POS_RANGE, ContainerWidth * PET_VIEWS_POS_RANGE), Random.Range(0, ContainerHeight * PET_VIEWS_POS_RANGE));

                    /* Instantiate PetView prefab and load it data by it's id */
                    GameObject _new_pet_view = Instantiate(PetViewPrefab, new_view_pos, Quaternion.identity, transform);
                    PetView    _pet_view     = _new_pet_view.GetComponent <PetView>();
                    _pet_view.LoadPet(id);
                    if (id == current_focus_id)
                    {
                        current_focus_pet = _pet_view;
                    }

                    Animator _pet_animator = _new_pet_view.GetComponent <Animator>();


                    pets_view_data.Add(_pet_view);
                }
            }

            /* Set back the PlayerData, waitting next time to save */
            PlayerData.instance.SetPetViews(pets_view_data);

            Debug.LogFormat("now pet count: {0}, current focus pet: {1}", pets_view_data.Count, PlayerData.instance.GetPlayerFocusPetId());
        }
        public void FocusPetView()
        {
            focused = true;
            GameObject.FindWithTag("MainCamera").GetComponent <CameraController>().FocusView();

            if (current_focus_pet == null)
            {
                int current_focus_id = PlayerData.instance.GetPlayerFocusPetId();
                // Debug.LogFormat("focus : {0}", current_focus_id);
                string[] _petids = PlayerData.instance.GetPetsId();
                // Debug.LogFormat("ids length : {0}", _petids.Length);

                if (_petids.Length > 0)
                {
                    // Debug.LogFormat("ids[0] : {0}", _petids[0]);
                    int.TryParse(_petids[0], out current_focus_id);
                    PlayerData.instance.SavePlayerFocusPetId(current_focus_id);
                    foreach (PetView pv in pets_view_data)
                    {
                        Debug.LogFormat("PV_id : {0}", pv.ID);
                        if (pv.ID == current_focus_id)
                        {
                            current_focus_pet = pv;
                        }
                    }
                }

                if (current_focus_pet == null)
                {
                    return;
                }
            }

            /* Moveing camera */
            Vector3 pos = current_focus_pet.transform.position;

            pos.z = Camera.main.transform.position.z;
            //if (pos.y < 0) pos.y = 0;
            if (camera_transform.position != pos)
            {
                CameraDomovePosition = pos;
            }

            /* Showing the pet information */
            InformationUI.SetActive(true);
            PetInformation.instance.AssignPet(current_focus_pet);
            //Debug.LogFormat("{0}: {1}", current_focus_pet, pet);

            /* keep the current pet id */
            PlayerData.instance.SavePlayerFocusPetId(current_focus_pet.ID);
        }
Example #4
0
        public void AddNewPetForStage()
        {
            int id;

            do
            {
                id = Random.Range(0, PetViewController.PET_ID_RANGER);
            } while (PlayerData.instance.CheckIDExisted(id));
            GameObject _new_pet_view = Instantiate(PetViewPrefab, Vector3.zero, Quaternion.identity, transform);
            PetView    _pet_view     = _new_pet_view.GetComponent <PetView>();

            _pet_view.NewPet(id, PetKind, GetNewPetName());
            _new_pet_view.GetComponent <SpriteRenderer>().enabled = false;

            PlayerData.instance.SavePlayerData();
        }
Example #5
0
        void OnTriggerEnter2D(Collider2D collider)
        {
            if (collider.CompareTag(PetTag) && collider.gameObject.GetComponent <PetView>().ID == PlayerData.instance.GetPlayerFocusPetId())
            {
                PetView pet = collider.GetComponent <PetView>();

                pet.IncreateHunger(AddHunger);
                pet.EatFood(this);


                if (sound != null)
                {
                    sound.Play();
                }

                Destroy(gameObject);
            }
        }
Example #6
0
        void OpenPanel(PetView _pet)
        {
            if (_pet != null)
            {
                pet = _pet;

                var sprite = Resources.Load(pet.PetSpriteName, typeof(Sprite));
                if (sprite != null)
                {
                    petImage.sprite = (Sprite)sprite;
                }
                LevelValue.text = pet.Level.ToString();
                Exp.maxValue    = pet.maxExp;
                Exp.value       = pet.Exp;
                ExpValue.text   = pet.Exp.ToString() + " / " + pet.maxExp.ToString();

                float temp       = (pet.UpgradeMaxHP - Pet.UpgradeMin) / (Pet.UpgradeMax - Pet.UpgradeMin);
                float scaleValue = minScale + (maxScale - minScale) * temp;
                ArrowMaxHP.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);

                temp       = (pet.UpgradeHPRecover - Pet.UpgradeMin) / (Pet.UpgradeMax - Pet.UpgradeMin);
                scaleValue = minScale + (maxScale - minScale) * temp;
                ArrowHPRecover.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);

                temp       = (pet.UpgradeMaxMP - Pet.UpgradeMin) / (Pet.UpgradeMax - Pet.UpgradeMin);
                scaleValue = minScale + (maxScale - minScale) * temp;
                ArrowMaxMP.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);

                temp       = (pet.UpgradeMPRecover - Pet.UpgradeMin) / (Pet.UpgradeMax - Pet.UpgradeMin);
                scaleValue = minScale + (maxScale - minScale) * temp;
                ArrowMPRecover.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);

                temp       = (pet.UpgradeAttack - Pet.UpgradeMin) / (Pet.UpgradeMax - Pet.UpgradeMin);
                scaleValue = minScale + (maxScale - minScale) * temp;
                ArrowAttack.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);

                temp       = (pet.UpgradeDefence - Pet.UpgradeMin) / (Pet.UpgradeMax - Pet.UpgradeMin);
                scaleValue = minScale + (maxScale - minScale) * temp;
                ArrowDefence.transform.localScale = new Vector3(scaleValue, scaleValue, scaleValue);

                gameObject.SetActive(true);
            }
        }
        public void TouchPetView(PetView _touched_pet)
        {
            /* Player want to focus a pet */
            if (!focused && current_focus_pet == null)
            {
                FocusPetView(_touched_pet);
                FocusPetEvents.Invoke();
            }

            /* Player is interactive with the touched pet */
            if (focused && current_focus_pet == _touched_pet)
            {
                _touched_pet.IncreateMood();
                TouchPetEvents.Invoke();
            }

            /* Player is clicking other pet*/
            if (current_focus_pet != _touched_pet)
            {
                FreePetView();
            }
        }
        public void NewPetView(string _kind, string _name)
        {
            /* Random a id */
            int id;

            do
            {
                id = Random.Range(0, PET_ID_RANGER);
            } while(PlayerData.instance.CheckIDExisted(id)); //while (!CheckID(id));

            /* A insatnced position in background*/
            Vector3 new_view_pos = Vector3.zero + new Vector3(Random.Range(-ContainerWidth * PET_VIEWS_POS_RANGE, ContainerWidth * PET_VIEWS_POS_RANGE), Random.Range(0, ContainerHeight * PET_VIEWS_POS_RANGE), 0);

            /* Instantiate PetView prefab and load it data by it's id */
            GameObject _new_pet_view = Instantiate(PetViewPrefab, new_view_pos, Quaternion.identity, transform);
            PetView    _pet_view     = _new_pet_view.GetComponent <PetView>();

            _pet_view.NewPet(id, _kind, _name);

            pets_view_data.Add(_pet_view);

            PlayerData.instance.SavePlayerData();
        }
 public void FocusPetView(PetView _focus_pet)
 {
     current_focus_pet = _focus_pet;
     FocusPetView();
 }
Example #10
0
 void OpenStatus(PetView pet_)
 {
     pet    = pet_;
     points = pet.Points;
     updateImage();
 }