示例#1
0
 // Use this for initialization
 void Start()
 {
     if (gameChild != null)
     {
         child = gameChild.GetComponent <IPersistantObject>();
     }
 }
示例#2
0
    private bool SearchForChild()
    {
        Optional <IIdentifiable> possibleChild = God.GetByID(childID);

        if (possibleChild.IsPresent())
        {
            child     = (IPersistantObject)(possibleChild.Get());
            gameChild = child.GetMono().gameObject;
            gameChild.SetActive(false);
            return(true);
        }
        return(false);
    }
示例#3
0
    public void LoadLevel(string name, bool keepCarried)
    {
        /* Do stats stuff */
        God.SetCurrentLevel(name);
        God.GetStats().initLevel(name);

        Dictionary <string, Dictionary <string, string> > toCarry = Unload();
        //Debug.Log("Carrying " + toCarry.Count + " objects to next scene");
        //foreach(string key in toCarry.Keys)
        //{
        //    Debug.Log("Carrying " + key);
        //}
        Dictionary <string, PersistanceType> typeLookup = new Dictionary <string, PersistanceType>();

        foreach (PersistanceType t in System.Enum.GetValues(typeof(PersistanceType)))
        {
            typeLookup.Add(t.ToString(), t);
        }
        Level lvl = new Level(name).LoadFromPlaythrough();
        Dictionary <string, Dictionary <string, string> > output = lvl.Contents;

        // Merge the dictionaries of the scene & file
        if (keepCarried)
        {
            // For each ID
            foreach (string key in toCarry.Keys)
            {
                if (output.ContainsKey(key))
                {
                    // If that ID is already in the file, go through each property
                    foreach (string innerKey in toCarry[key].Keys)
                    {
                        // And replace the file-property with the scene property
                        output[key][innerKey] = toCarry[key][innerKey];
                    }
                }
                else
                {
                    // If that ID is not in the file, add it from the scene
                    output.Add(key, toCarry[key]);
                }
            }
        }
        List <IPersistantObject> generatedObjects = new List <IPersistantObject>();
        bool usingCompatibility = false;

        foreach (string id in output.Keys)
        {
            Dictionary <string, string> dict = output[id];
            string     t = dict["type"];
            int        num;
            GameObject template;
            if (int.TryParse(t, out num))
            {
                // Allow numbers for backwards compatibility
                template           = _Templates[(PersistanceType)num];
                usingCompatibility = true;
            }
            else
            {
                template = _Templates[typeLookup[dict["type"]]];
            }
            GameObject        loaded      = GameObject.Instantiate(template);
            IPersistantObject persistance = loaded.GetComponent <IPersistantObject>();
            persistance.setID(id);
            if (dict.ContainsKey("transform"))
            {
                persistance.GetMono().transform.UpdateToSaved(dict["transform"]);
            }
            persistance.Load(dict);
            generatedObjects.Add(persistance);
        }
        List <IIdentifiable> identif = new List <IIdentifiable>();

        generatedObjects.ForEach(obj => identif.Add(obj));
        God.UpdateIDLookup(identif);
        generatedObjects.ForEach(obj => obj.PostLoad());
        if (usingCompatibility)
        {
            Debug.Log("WARNING: Using compatibility mode to load level...things may not load as expected");
        }
        lvl.SaveToPlaythrough();
        if (name == GameConstants.OPENING_NARRATIVE_LEVEL)
        {
            God.ShowTexts(HintsList.OPENING_NARRATIVE);
        }
        else if (name == GameConstants.FIRST_MIRROR_LEVEL)
        {
            God.ShowText(HintsList.MIRROR_HINT);
        }
        else if (name == GameConstants.FIRST_GUARD_LEVEL)
        {
            if (!HintsList.GUARDS_SAID)
            {
                God.ShowTexts(HintsList.GUARDS);
                HintsList.GUARDS_SAID = true;
            }
        }
        else if (name == GameConstants.TWO_DOORS_LEVEL)
        {
            God.ShowText(HintsList.TWO_DOORS_HINT);
        }
        else if (name == GameConstants.FINAL_LEVEL)
        {
            StartCoroutine(FinalNarrative());
        }
        else if (name == GameConstants.GAME_END)
        {
            God.ShowText(HintsList.GAME_END_YAY);
        }
    }