Ejemplo n.º 1
0
 private void Awake()
 {
     // hit = new RaycastHit2D();
     // PlayerPrefs.DeleteAll();
     Instance     = this;
     _wordKeepers = new List <GameObject>();
     turnText     = GameObject.FindWithTag("Turn").GetComponent <TextMeshProUGUI>();
     if (PlayerPrefs.HasKey("year"))
     {
         turns = PlayerPrefs.GetInt("year");
     }
     if (PlayerPrefs.HasKey("debug"))
     {
         debug = bool.Parse(PlayerPrefs.GetString("debug"));
     }
     if (File.Exists(Application.persistentDataPath + "/" + gameObject.name + ".save"))
     {
         data = JsonUtility.FromJson <JsonParser.Data>(File.ReadAllText(Application.persistentDataPath + "/" + gameObject.name + ".save"));
     }
     else
     {
         data = JsonParser.Instance.GetData();
         for (int i = 0; i < data.TechnologyTree.Count; i++)
         {
             if (data.TechnologyTree[i].dependances.Count == 0)
             {
                 var tmpStruct = data.TechnologyTree[i];
                 tmpStruct.useable = true;
                 tmpStruct.learned = true;
                 for (int j = 0; j < tmpStruct.words.objects.Count; j++)
                 {
                     var tmpStructDescends = tmpStruct.words.objects[j];
                     tmpStructDescends.useable  = true;
                     tmpStruct.words.objects[j] = tmpStructDescends;
                 }
                 for (int j = 0; j < tmpStruct.words.subjects.Count; j++)
                 {
                     var tmpStructDescends = tmpStruct.words.subjects[j];
                     tmpStructDescends.useable   = true;
                     tmpStruct.words.subjects[j] = tmpStructDescends;
                 }
                 for (int j = 0; j < tmpStruct.words.verbs.Count; j++)
                 {
                     var tmpStructDescends = tmpStruct.words.verbs[j];
                     tmpStructDescends.useable = true;
                     tmpStruct.words.verbs[j]  = tmpStructDescends;
                 }
                 data.TechnologyTree[i] = tmpStruct;
             }
         }
     }
     _turnPast = Random.Range(20, 30);
 }
Ejemplo n.º 2
0
    void Awake()
    {
        // if (Player.Instance.debug)
        // PlayerPrefs.DeleteAll();

        if (PlayerPrefs.HasKey("religion" + gameObject.name))
        {
            Debug.Log("_religion");
            _religion.value = PlayerPrefs.GetFloat("religion" + gameObject.name);
            Debug.Log(_religion.value);
        }

        if (PlayerPrefs.HasKey("science" + gameObject.name))
        {
            _science.value = PlayerPrefs.GetFloat("science" + gameObject.name);
        }
        if (PlayerPrefs.HasKey("social" + gameObject.name))
        {
            _social.value = PlayerPrefs.GetFloat("social" + gameObject.name);
        }
        if (PlayerPrefs.HasKey("conquest" + gameObject.name))
        {
            _conquest.value = PlayerPrefs.GetFloat("conquest" + gameObject.name);
        }
        if (File.Exists(Application.persistentDataPath + "/" + gameObject.name + ".save"))
        {
            data = JsonUtility.FromJson <JsonParser.Data>(File.ReadAllText(Application.persistentDataPath + "/" + gameObject.name + ".save"));
        }
        else
        {
            _religion.value = Random.Range(30f, 50f);
            _social.value   = Random.Range(30f, 50f);
            _science.value  = Random.Range(30f, 50f);
            _conquest.value = Random.Range(30f, 50f);
            data            = JsonParser.Instance.GetData();
            for (int i = 0; i < data.TechnologyTree.Count; i++)
            {
                if (data.TechnologyTree[i].dependances.Count == 0)
                {
                    var tmpStruct = data.TechnologyTree[i];
                    tmpStruct.useable = true;
                    tmpStruct.learned = true;
                    for (int j = 0; j < tmpStruct.words.objects.Count; j++)
                    {
                        var tmpStructDescends = tmpStruct.words.objects[j];

                        tmpStructDescends.useable  = true;
                        tmpStruct.words.objects[j] = tmpStructDescends;
                    }
                    for (int j = 0; j < tmpStruct.words.subjects.Count; j++)
                    {
                        var tmpStructDescends = tmpStruct.words.subjects[j];

                        tmpStructDescends.useable   = true;
                        tmpStruct.words.subjects[j] = tmpStructDescends;
                    }
                    for (int j = 0; j < tmpStruct.words.verbs.Count; j++)
                    {
                        var tmpStructDescends = tmpStruct.words.verbs[j];

                        tmpStructDescends.useable = true;
                        tmpStruct.words.verbs[j]  = tmpStructDescends;
                    }
                    data.TechnologyTree[i] = tmpStruct;
                }
            }
        }
        _currentValues     = new Vector4(_religion.value, _social.value, _science.value, _conquest.value);
        _trustIndice.value = 100f - (Mathf.Max(Mathf.Max(_religion.value, _social.value),
                                               Mathf.Max(_science.value, _conquest.value)) -
                                     Mathf.Min(Mathf.Min(_religion.value, _social.value), Mathf.Min(_science.value, _conquest.value)));

        _subjects   = GetComponentInChildren <Subjects>();
        _objects    = GetComponentInChildren <Objects>();
        _verbs      = GetComponentInChildren <Verbs>();
        _notifPanel = GameObject.FindWithTag("Notifications");
        _panelAbstract.SetActive(false);
        _open.SetActive(false);
    }
Ejemplo n.º 3
0
    private void Start()
    {
        _data = Player.Instance.data;
        var technos = _data.TechnologyTree.FindAll(x => x.useable && x.dependances.Count > 0);
        var general = _data.TechnologyTree.Find(x => x.name == "general");

        _currentSubject = general.words.subjects[Random.Range(0, general.words.subjects.Count)];
        if (technos.Count <= 0)
        {
            Player.Instance.wordKeep = true;
            Player.Instance.lastTurn = Player.Instance.turn;
            Player.Instance.DeleteWordKeeper(this.gameObject);
            Destroy(gameObject);
            return;
        }

        int index = Random.Range(0, technos.Count);
        var tech1 = _data.TechnologyTree.Find(x => x.name == technos[index].dependances[0]);
        var tech2 = _data.TechnologyTree.Find(x => x.name == technos[index].dependances[1]);

        if (tech1.words.verbs.Count > 0)
        {
            _currentObject = tech2.words.objects.Find(x => x.useable);
            _currentVerb   = tech1.words.verbs.Find(x => x.useable);
            _wordsSets     = true;
            _result        = technos[index];
        }
        if (tech2.words.verbs.Count > 0)
        {
            _currentObject = tech1.words.objects.Find(x => x.useable);
            _currentVerb   = tech2.words.verbs.Find(x => x.useable);
            _wordsSets     = true;
            _result        = technos[index];
        }
        if (technos[index].words.verbs.Count > 0)
        {
            _currentWord = technos[index].words.verbs.Find(x => x.useable == false);
        }
        else
        {
            _currentWord = technos[index].words.objects.Find(x => x.useable == false);
        }

        if (!_wordsSets)
        {
            Player.Instance.wordKeep = true;
            Player.Instance.lastTurn = Player.Instance.turn;
            Player.Instance.DeleteWordKeeper(this.gameObject);
            Destroy(gameObject);
        }

        GameObject subject = Instantiate(_prefabTechno, Vector3.zero, Quaternion.identity, _posSubject);

        subject.transform.localPosition = Vector3.zero;
        subject.transform.localScale    = Vector3.one;

        subject.GetComponentInChildren <TextMeshProUGUI>().text = _currentSubject.name;
        if (Resources.Load <Sprite>(_currentSubject.name))
        {
            subject.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>(_currentSubject.name);
        }
        GameObject verb = Instantiate(_prefabTechno, Vector3.zero, Quaternion.identity, _posVerb);

        verb.GetComponentInChildren <TextMeshProUGUI>().text = _currentVerb.name;
        verb.transform.localPosition = Vector3.zero;
        verb.transform.localScale    = Vector3.one;

        if (Resources.Load <Sprite>(_currentVerb.name))
        {
            verb.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>(_currentVerb.name);
        }
        GameObject obj = Instantiate(_prefabTechno, Vector3.zero, Quaternion.identity, _posObject);

        obj.GetComponentInChildren <TextMeshProUGUI>().text = _currentObject.name;
        obj.transform.localPosition = Vector3.zero;
        obj.transform.localScale    = Vector3.one;

        if (Resources.Load <Sprite>(_currentObject.name))
        {
            obj.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>(_currentObject.name);
        }
        for (int i = 0; i < _data.TechnologyTree.Count; i++)
        {
            if (!_data.TechnologyTree[i].learned)
            {
                continue;
            }
            GameObject go = Instantiate(_prefabConcept, Vector3.zero, Quaternion.identity, _panelConcept.transform);
            go.transform.localScale = Vector3.one;

            if (_data.TechnologyTree[i].name == _result.name)
            {
                go.GetComponent <Button>().onClick.AddListener(delegate
                {
                    bool foundWord       = false;
                    _currentWord.useable = true;
                    for (int j = 0; j < _result.words.verbs.Count; j++)
                    {
                        if (_result.words.verbs[j].name == _currentWord.name)
                        {
                            _result.words.verbs[j] = _currentWord;
                            foundWord = true;
                            break;
                        }
                    }

                    if (!foundWord)
                    {
                        for (int j = 0; j < _result.words.objects.Count; j++)
                        {
                            if (_result.words.objects[j].name == _currentWord.name)
                            {
                                _result.words.objects[j] = _currentWord;
                                break;
                            }
                        }
                    }

                    for (int j = 0; j < _data.TechnologyTree.Count; j++)
                    {
                        if (_data.TechnologyTree[j].name == _result.name)
                        {
                            _data.TechnologyTree[j] = _result;
                        }
                    }

                    Notifications.Instance.gameObject.SetActive(true);
                    Notifications.Instance.TimeVisible += 2.5f;
                    Notifications.Instance.AddText("You found a new word : " + _currentWord.name);
                    Player.Instance.data     = _data;
                    Player.Instance.wordKeep = true;
                    Player.Instance.lastTurn = Player.Instance.turn;
                    Player.Instance.DeleteWordKeeper(this.gameObject);
                    Player.Instance.Close();
                    Destroy(gameObject);
                });
            }
            else
            {
                go.GetComponent <Button>().onClick.AddListener(delegate
                {
                    Notifications.Instance.gameObject.SetActive(true);
                    Notifications.Instance.TimeVisible += 2.5f;
                    Notifications.Instance.AddText("You didn't understand!");
                    Player.Instance.wordKeep = true;
                    Player.Instance.lastTurn = Player.Instance.turn;
                    Player.Instance.DeleteWordKeeper(this.gameObject);
                    Player.Instance.Close();
                    Destroy(gameObject);
                });
            }
            buttonOpen.GetComponent <Button>().onClick.AddListener(delegate
            {
                Player.Instance.Open(this.gameObject);
            });
            buttonClose.GetComponent <Button>().onClick.AddListener(delegate
            {
                Player.Instance.Close();
            });
            go.GetComponentInChildren <TextMeshProUGUI>().text = _data.TechnologyTree[i].name;
            if (Resources.Load <Sprite>(_data.TechnologyTree[i].name))
            {
                go.GetComponentInChildren <Image>().sprite = Resources.Load <Sprite>(_data.TechnologyTree[i].name);
            }
        }
    }