Ejemplo n.º 1
0
        void RenderFieldMap(int chapterId)
        {
            this.ChapterId = chapterId;

            // Draw map on UI
            GameField field           = gameManager.GetField();
            Material  defaultMaterial = Resources.Load <Material>(@"common-mat");

            fieldMapRoot = this.transform.Find("FieldMap");
            string        mappingData = File.ReadAllText(@"D:\GitRoot\toneyisnow\windingtale\Resources\Remastered\Shapes\ShapePanel1\shape-mapping-1.json");
            ShapeMappings mappings    = JsonConvert.DeserializeObject <ShapeMappings>(mappingData);

            HashSet <int> missingShapes = new HashSet <int>();

            for (int x = 0; x < field.Width; x++)
            {
                for (int y = 0; y < field.Height; y++)
                {
                    int    shapeIndex  = field.Map[x, y];
                    string voxIndexStr = shapeIndex.ToString();
                    foreach (string key in mappings.mappings.Keys)
                    {
                        if (mappings.mappings[key].Contains(shapeIndex))
                        {
                            voxIndexStr = key;
                            break;
                        }
                    }

                    Int32.TryParse(voxIndexStr, out int voxIndex);

                    GameObject shapeObject = new GameObject();
                    shapeObject.name = string.Format(@"shape_{0}_{1}", x + 1, y + 1);
                    UIShape shapeCom = shapeObject.AddComponent <UIShape>();
                    shapeCom.Initialize(this, fieldMapRoot, chapterId, voxIndex, FDPosition.At(x + 1, y + 1));

                    /*
                     * GameObject shapeGO = AssetManager.Instance().InstantiateShapeGO(this.transform, chapterId, voxIndex);
                     * if (shapeGO == null)
                     * {
                     *  missingShapes.Add(shapeIndex);
                     *  continue;
                     * }
                     *
                     * shapeGO.transform.parent = fieldMapRoot;
                     * shapeGO.transform.localPosition = FieldTransform.GetShapePixelPosition(x + 1, y + 1);
                     *
                     * var box = shapeGO.AddComponent<BoxCollider>();
                     * box.size = new Vector3(2.0f, 0.5f, 2.0f);
                     * box.center = new Vector3(0f, 1f, 0f);
                     */

                    //var renderer = shapePrefab.GetComponentInChildren<MeshRenderer>();
                    //renderer.sharedMaterial = defaultMaterial;

                    // Note the the FlameDragon is counting matrix from 1, not 0
                    // GameObject go = FieldTransform.CreateShapeObject(shapePrefab, fieldMapRoot, x + 1, y + 1);
                }
            }
        }