Exemplo n.º 1
0
        // Generates the landmarks, pretty similar to the data in pickup.
        private void GenerateLandmarks()
        {
            foreach (var p in E.Get().CurrTrial.trialData.LandMarks)
            {
                var        d = DS.GetData().Landmarks[p - 1];
                GameObject prefab;
                GameObject landmark;
                if (d.Type.ToLower().Equals("3d"))
                {
                    prefab   = (GameObject)Resources.Load("3D_Objects/" + d.Object, typeof(GameObject));
                    landmark = Instantiate(prefab);
                    landmark.AddComponent <RotateBlock>();
                    landmark.GetComponent <Renderer>().material.color = Data.GetColour(d.Color);
                }
                else
                {
                    // Load the "2D" prefab here, so we have the required components
                    prefab   = (GameObject)Resources.Load("3D_Objects/2D", typeof(GameObject));
                    landmark = Instantiate(prefab);
                    var spriteName = d.Object;
                    var pic        = Img2Sprite.LoadNewSprite(DataSingleton.GetData().SpritesPath + spriteName);
                    landmark.GetComponent <SpriteRenderer>().sprite = pic;
                }

                landmark.transform.localScale = d.ScaleVector;
                try
                {
                    landmark.transform.position = d.PositionVector;
                }
                catch (Exception _)
                {
                    landmark.transform.position = new Vector3(d.PositionVector.x, 0.5f, d.PositionVector.z);
                }

                //landmark.transform.Rotate(new Vector3(0, 1, 0), d.InitialRotation);
                landmark.transform.Rotate(d.RotationVector);


                landmark.GetComponent <Renderer>().material.color = Data.GetColour(d.Color);
                var sprite = d.ImageLoc;
                if (sprite != null)
                {
                    var pic = Img2Sprite.LoadNewSprite(DataSingleton.GetData().SpritesPath + sprite);
                    landmark.GetComponent <SpriteRenderer>().sprite = pic;
                }

                _created.Add(landmark);
            }
        }
Exemplo n.º 2
0
        // Use this for initialization
        private void Start()
        {
            var gen = GameObject.Find("WallCreator").GetComponent <GenerateGenerateWall>();

            _destroy = new List <GameObject>(); //This initializes the food object destroy list

            var activeGoals    = E.Get().CurrTrial.trialData.ActiveGoals;
            var inactiveGoals  = E.Get().CurrTrial.trialData.InactiveGoals;
            var invisibleGoals = E.Get().CurrTrial.trialData.InvisibleGoals;
            var inactiveSet    = new HashSet <int>(inactiveGoals);
            var invisibleSet   = new HashSet <int>(invisibleGoals);
            var activeSet      = new HashSet <int>(activeGoals);

            var merged = new List <int>();

            merged.AddRange(activeGoals);
            merged.AddRange(inactiveGoals);
            merged.AddRange(invisibleGoals);

            Data.Point p = new Data.Point {
                X = 0, Y = 0, Z = 0
            };
            foreach (var val in merged)
            {
                var goalItem = DS.GetData().Goals[Mathf.Abs(val) - 1];
                UnityEngine.Debug.Log(goalItem);

                // Position is not set in the config file
                if (goalItem.Position.Count == 0)
                {
                    p = ReadFromExternal(goalItem.PythonFile);
                }
                else
                {
                    try
                    {
                        p = new Data.Point {
                            X = goalItem.PositionVector.x, Y = goalItem.PositionVector.y, Z = goalItem.PositionVector.z
                        };
                    }
                    catch (Exception _)
                    {
                        p = new Data.Point {
                            X = goalItem.PositionVector.x, Y = 0.5f, Z = goalItem.PositionVector.z
                        };
                    }
                }

                GameObject prefab;
                GameObject obj;
                var        spriteName = "";

                if (goalItem.Type.ToLower().Equals("3d"))
                {
                    prefab = (GameObject)Resources.Load("3D_Objects/" + goalItem.Object, typeof(GameObject));
                    obj    = Instantiate(prefab);
                    obj.AddComponent <RotateBlock>();
                }
                else
                {
                    // Load the "2D" prefab here, so we have the required components
                    prefab     = (GameObject)Resources.Load("3D_Objects/" + goalItem.Type.ToUpper(), typeof(GameObject));
                    obj        = Instantiate(prefab);
                    spriteName = goalItem.Object;
                }

                obj.transform.Rotate(goalItem.RotationVector);
                obj.transform.localScale = goalItem.ScaleVector;
                obj.transform.position   = new Vector3(p.X, p.Y, p.Z);

                obj.AddComponent <PickupSound>();
                obj.GetComponent <PickupSound>().Sound = Resources.Load <AudioClip>("Sounds/" + goalItem.Sound);

                if (!string.IsNullOrEmpty(spriteName))
                {
                    var pic = Img2Sprite.LoadNewSprite(DataSingleton.GetData().SpritesPath + spriteName);
                    obj.GetComponent <SpriteRenderer>().sprite = pic;
                }

                var color = Data.GetColour(goalItem.Color);

                try
                {
                    obj.GetComponent <Renderer>().material.color = color;
                    obj.GetComponent <Renderer>().enabled        = !invisibleSet.Contains(val);
                    obj.GetComponent <Collider>().enabled        = !inactiveSet.Contains(val);

                    if (activeSet.Contains(val) || invisibleSet.Contains(val))
                    {
                        obj.tag = "Pickup";
                        obj.GetComponent <Collider>().isTrigger = true;
                    }
                }
                catch (Exception _)
                {
                    print("Visibility not working");
                }

                _destroy.Add(obj);
            }

            GameObject.Find("Participant").GetComponent <PlayerController>().ExternalStart(p.X, p.Z);
        }
    // Use this for initialization
    private void Start()
    {
        var m = L.Get().CurrTrial.trialData.Map;
        var y = m.TopLeft[1];

        // Goes through each map and initializes it based on stuff.
        foreach (var row in m.Map)
        {
            var x = m.TopLeft[0];

            foreach (var col in row.ToCharArray())
            {
                if (col == 'w')
                {
                    var obj = GameObject.CreatePrimitive(PrimitiveType.Cube);
                    obj.GetComponent <Renderer>().sharedMaterial.color = Data.GetColour(m.Color);
                    obj.transform.localScale = new Vector3(m.TileWidth, L.Get().CurrTrial.enclosure.WallHeight, m.TileWidth);
                    obj.transform.position   = new Vector3(x, L.Get().CurrTrial.enclosure.WallHeight * 0.5f, y);
                }
                else if (col == 's')
                {
                    Debug.Log(x + " " + y);
                    GameObject.Find("Participant").GetComponent <PlayerController>().ExternalStart(x, y, true);
                }
                else if (col != '0')
                {
                    // TODO: This code should be shared with PickupGenerator.cs - this class might also just be deadcode.
                    var val      = col - '0';
                    var goalItem = DS.GetData().Goals[val - 1];

                    GameObject prefab;
                    GameObject obj;
                    var        spriteName = "";

                    if (goalItem.Type.ToLower().Equals("3d"))
                    {
                        prefab = (GameObject)Resources.Load("3D_Objects/" + goalItem.Object, typeof(GameObject));
                        obj    = Instantiate(prefab);
                        obj.AddComponent <RotateBlock>();
                        obj.GetComponent <Renderer>().material.color = Data.GetColour(goalItem.Color);
                    }
                    else
                    {
                        // Load the "2D" prefab here, so we have the required components
                        prefab     = (GameObject)Resources.Load("3D_Objects/" + goalItem.Type.ToUpper(), typeof(GameObject));
                        obj        = Instantiate(prefab);
                        spriteName = goalItem.Object;
                    }

                    obj.transform.localScale = goalItem.ScaleVector;
                    obj.transform.position   = new Vector3(x, 0.5f, y);

                    if (!string.IsNullOrEmpty(spriteName))
                    {
                        var pic = Img2Sprite.LoadNewSprite(DataSingleton.GetData().SpritesPath + spriteName);
                        obj.GetComponent <SpriteRenderer>().sprite = pic;
                    }
                }

                x += m.TileWidth;
            }

            y -= m.TileWidth;
        }
    }