private void CreateCanvas(GameObject g, WindowContent conotent) { g.AddComponent <Canvas>().renderMode = RenderMode.ScreenSpaceCamera; var scaler = g.AddComponent <CanvasScaler>(); scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; scaler.referenceResolution = conotent.screenSize; g.AddComponent <GraphicRaycaster>(); var t = Assembly.Load("Assembly-CSharp").GetType(conotent.cs_name + conotent.content_type); g.AddComponent(t); g.layer = LayerMask.NameToLayer("UI"); }
private bool CanCreate(WindowContent content) { if (File.Exists($"{Application.dataPath}/{content.cs_path}/{content.cs_name}{content.content_type}.cs")) { return(false); } if (File.Exists( $"{Application.dataPath}/{content.prefab_res_path}/{content.content_type}/{content.cs_name}{content.content_type}.prefab") ) { return(false); } return(true); }
private void CreatePrefabs(WindowContent content) { string name = $"{content.cs_name}{content.content_type}"; var g = new GameObject(name); CreateCanvas(g, _content); RectTransform rect = new GameObject("Root", typeof(Image)).transform as RectTransform; rect.transform.SetParent(g.transform); rect.anchorMin = Vector2.zero; rect.anchorMax = Vector2.one; rect.sizeDelta = Vector2.zero; rect.anchoredPosition = Vector2.zero; rect.GetComponent <Image>().color = new Color(1, 1, 1, 0.4f); rect.gameObject.layer = LayerMask.NameToLayer("UI"); // CreatePath($"{Application.dataPath}/{content.prefab_res_path}/{content.content_type}"); // PrefabUtility.SaveAsPrefabAsset(g, $"Assets/{content.prefab_res_path}/{content.content_type}/{name}.prefab"); DestroyImmediate(g); }
private void OnEnable() { _content = GetContent(); }
private void SaveContent(WindowContent content) { string fileName = Application.dataPath + "/../" + "UIFrameworkConfig.txt"; File.WriteAllText(fileName, JsonUtility.ToJson(content)); }