private void InitializedMenu(string filename) { //StreamReader streamreader = new StreamReader(Application.dataPath + filename); //JsonReader jr = new JsonReader(streamreader); //JsonData jd = JsonMapper.ToObject(jr); JsonData jd = JsonMapper.ToObject(Resources.Load <TextAsset>(filename).text); gameController.dishinfo = (string)jd["简介"]; gameController.dishinst = (string)jd["详介"]; foreach (JsonData i in jd["步骤"]) { CookingStep cs = Instantiate(stepPrefab, transform); cs.Init((string)i["名字"], (int)i["持续时间"], (bool)i["能否同时"], (string)i["图片"], (int)i["台子"]); var drag = cs.GetComponent <Dragable>(); gameController.stepCollection.CookingSteps.Add(cs); } for (int i = 0; i < jd["步骤"].Count; i++) { CookingStep cs = gameController.stepCollection.CookingSteps[i]; string path = "Images/步骤/" + cs.spritePath; Sprite sprite = Resources.Load <Sprite>(path); Image t = cs.GetComponentsInChildren <Image>()[2]; t.sprite = sprite; t.preserveAspect = true; Text timeText = cs.GetComponentsInChildren <Text>().Where(x => x.name == "Time").First(); timeText.text = cs.Time.ToString() + " min"; Text nameText = cs.GetComponentsInChildren <Text>().Where(x => x.name == "Name").First(); nameText.text = cs.Name; JsonData depend = jd["步骤"][i]["前置条件"]; foreach (JsonData j in depend) { cs.DirectDepend.Add(gameController.stepCollection.FindByName((string)j)); } } gameController.stepCollection.CalcDepend(); gameController.stepCollection.CookingSteps.ForEach((x) => x.Depend.ForEach((y) => x.DependNotSatisfied.Add(y) ) ); /* foreach(var step in gameController.stepCollection.CookingSteps) * { * if (step.DependNotSatisfied.Count > 0) * { * step.canDrag = false; * } * } */ }
private Vector2 unitSize; // 在菜单栏里的步骤的大小 void Start() { gameController = FindObjectOfType <GameController>(); InitializedMenu("Jsons/test"); // Resources文件夹下读取文件不用后缀名 unitSize = stepPrefab.GetComponent <RectTransform>().sizeDelta; }