//Instance object of ObstacleContainer class
 public static ObstacleContainer Instance()
 {
     if (!obsContainer)
     {
         obsContainer = FindObjectOfType(typeof(ObstacleContainer)) as ObstacleContainer;
     }
     return(obsContainer);
 }
 /*FUNCTION: OnTriggerEnter2D(Collider2D collider)
  * CALLED BY: Trigger event from the collider added on bird object
  * */
 void OnTriggerEnter2D(Collider2D collider)
 {
     if (collider.tag == "Wheel")
     {
         BumpWithWheel();
     }
     else if (collider.tag == "WheelCheckpoint")
     {
         ObstacleContainer.Instance().GenerateObstacle4Bird();
     }
 }
Exemple #3
0
    public void Spawn(string id)
    {
        ObstacleContainer c;

        if (ObstacleData.Data.ContainsKey(id))
        {
            c = ObstacleData.Data[id];
        }
        else
        {
            c = new ObstacleContainer("Basic");
        }

        if (c.IsAnimated)
        {
            SetAnimatedSprite(id);
        }
        else
        {
            SetBasicTexture(id);
        }

        if (_sceneCache.ContainsKey(c.Controller))
        {
            AddChild(_sceneCache[c.Controller].Instance());
        }
        else
        {
            PackedScene ps = LoadController(c.Controller);
            _sceneCache.Add(c.Controller, ps);
            Node n = ps.Instance();
            if (n != null && ps != null)
            {
                AddChild(n);
            }
            else
            {
                Global.Log("Could not find controller: " + c.Controller);
            }
        }

        Scale = new Vector2(2, 2) * c.Scale;
        AddToGroup("obstacles");
    }
    private void LoadData()
    {
        // Perhaps change later to persistentDataPath or additional folders etc.

        string path = Path.Combine(Application.dataPath, SaveFile);

        if (File.Exists(path))
        {
            Debug.Log("Loading saved data.");
            string loadedData = File.ReadAllText(path);
            ObstacleDataContainer = JsonUtility.FromJson <ObstacleContainer>(loadedData);
            InstantiateAllData();
        }
        else
        {
            Debug.Log("Saved data doesn't exist, creating a file for save data.");
            ObstacleDataContainer = new ObstacleContainer();

            string saveData = JsonUtility.ToJson(ObstacleDataContainer);
            File.WriteAllText(path, saveData);
        }
    }