Example #1
0
        public GameObject CreatePrefab(Xda xda)
        {
            IXdArtboardTranslater  artboardTranslater  = new DefaultXdArtboardTranslater();
            IXdRectangleTranslater rectangleTranslater = new DefaultXdRectangleTranslater();
            IXdTextTranslater      textTranslater      = new DefaultXdTextTranslater();
            IXdGroupTranslater     groupTranslater     = new DefaultXdGroupTranslater();

            // アートボード
            GameObject artboard = artboardTranslater.CreateGameObjectByArtboard(xda.artboard);

            var nodeTree        = new Dictionary <Node, string> ();
            var siblingIndexMap = new Dictionary <Node, int>();
            var goMap           = new Dictionary <string, GameObject> ();

            goMap.Add(xda.artboard.guid, artboard);
            // イメージ
            for (int i = 0; i < xda.rectangleList.Count; i++)
            {
                var node = xda.rectangleList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = rectangleTranslater.CreateGameObjectByRectangle(node, artboard);
                goMap.Add(node.guid, go);
            }

            // テキスト
            for (int i = 0; i < xda.textList.Count; i++)
            {
                var node = xda.textList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = textTranslater.CreateGameObjectByText(node, artboard);
                goMap.Add(node.guid, go);
            }

            // グループ
            for (int i = 0; i < xda.groupList.Count; i++)
            {
                var node = xda.groupList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = groupTranslater.CreateGameObjectByGroup(xda.groupList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // 親子関係構築
            foreach (var kvp in nodeTree)
            {
                goMap[kvp.Key.guid].transform.SetParent(goMap[kvp.Value].transform);
            }

            // SiblingIndex設定
            foreach (var kvp in siblingIndexMap)
            {
                goMap[kvp.Key.guid].transform.SetSiblingIndex(kvp.Value);
            }
            return(artboard);
        }
Example #2
0
        GameObject CreateCanvas(Xda xda)
        {
            // アートボード
            GameObject artboard = new GameObject(xda.artboard.name);
            var        canvas   = artboard.AddComponent <Canvas> ();

            canvas.renderMode = RenderMode.ScreenSpaceOverlay;
            var xdRect   = xda.rectangleList[0];
            var nodeTree = new Dictionary <Node, string> ();
            var goMap    = new Dictionary <string, GameObject> ();

            goMap.Add(xda.artboard.guid, artboard);
            // イメージ
            for (int i = 0; i < xda.rectangleList.Count; i++)
            {
                var node = xda.rectangleList[i];
                nodeTree.Add(node, node.parentGuid);
                var go = CreateImage(node, artboard);
                goMap.Add(node.guid, go);
            }

            // テキスト
            for (int i = 0; i < xda.textList.Count; i++)
            {
                var node = xda.textList[i];
                nodeTree.Add(node, node.parentGuid);
                var go = CreateText(node, artboard);
                goMap.Add(node.guid, go);
            }

            // グループ
            for (int i = 0; i < xda.groupList.Count; i++)
            {
                var node = xda.groupList[i];
                nodeTree.Add(node, node.parentGuid);
                var go = CreateGroup(xda.groupList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // 親子関係構築
            foreach (var kvp in nodeTree)
            {
                goMap[kvp.Key.guid].transform.SetParent(goMap[kvp.Value].transform);
            }
            return(artboard);
        }
Example #3
0
        public override void OnImportAsset(AssetImportContext ctx)
        {
            string text = File.ReadAllText(ctx.assetPath);
            Xda    xda  = null;

            try {
                xda = JsonUtility.FromJson <Xda> (text);
            } catch (System.Exception ex) {
                throw ex;
            }

            // 以下だとプレハブがソートされてしまうバグがあるため新しいプレハブとして生成
            // ctx.AddObjectToAsset (xda.artboard.guid, artboard);
            // ctx.SetMainObject (artboard);

            var artboard = new XdaTranslater().CreatePrefab(xda);

            PrefabUtility.SaveAsPrefabAsset(artboard, ctx.assetPath.Replace("xda", "prefab"));
            GameObject.DestroyImmediate(artboard);
        }
Example #4
0
        public GameObject CreatePrefab(Xda xda)
        {
            IXdArtboardTranslater       artboardTranslater       = new DefaultXdArtboardTranslater();
            IXdRectangleTranslater      rectangleTranslater      = new DefaultXdRectangleTranslater();
            IXdTextTranslater           textTranslater           = new DefaultXdTextTranslater();
            IXdGroupTranslater          groupTranslater          = new DefaultXdGroupTranslater();
            IXdEllipseTranslater        ellipseTranslater        = new DefaultXdEllipseTranslater();
            IXdLineTranslater           lineTranslater           = new DefaultXdLineTranslater();
            IXdPathTranslater           pathTranslater           = new DefaultXdPathTranslater();
            IXdSymbolInstanceTranslater symbolInstanceTranslater = new DefaultXdSymbolInstanceTranslater();
            IXdLinkedGraphicTranslater  linkedGraphicTranslater  = new DefaultXdLinkedGraphicTranslater();

            // アートボード
            GameObject artboard = artboardTranslater.CreateGameObjectByArtboard(xda.artboard);

            var nodeTree        = new Dictionary <Node, string> ();
            var siblingIndexMap = new Dictionary <Node, int>();
            var goMap           = new Dictionary <string, GameObject> ();

            goMap.Add(xda.artboard.guid, artboard);
            // イメージ
            for (int i = 0; i < xda.rectangleList.Count; i++)
            {
                var node = xda.rectangleList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = rectangleTranslater.CreateGameObjectByRectangle(node, artboard);
                goMap.Add(node.guid, go);
            }

            // テキスト
            for (int i = 0; i < xda.textList.Count; i++)
            {
                var node = xda.textList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = textTranslater.CreateGameObjectByText(node, artboard);
                goMap.Add(node.guid, go);
            }

            // グループ
            for (int i = 0; i < xda.groupList.Count; i++)
            {
                var node = xda.groupList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = groupTranslater.CreateGameObjectByGroup(xda.groupList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // Ellipse
            for (int i = 0; i < xda.ellipseList.Count; i++)
            {
                var node = xda.ellipseList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = ellipseTranslater.CreateGameObjectByEllipse(xda.ellipseList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // Line
            for (int i = 0; i < xda.lineList.Count; i++)
            {
                var node = xda.lineList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = lineTranslater.CreateGameObjectByLine(xda.lineList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // Path
            for (int i = 0; i < xda.pathList.Count; i++)
            {
                var node = xda.pathList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = pathTranslater.CreateGameObjectByPath(xda.pathList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // SymbolInstance
            for (int i = 0; i < xda.symbolInstanceList.Count; i++)
            {
                var node = xda.symbolInstanceList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = symbolInstanceTranslater.CreateGameObjectBySymbolInstance(xda.symbolInstanceList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // LinkedGraphic
            for (int i = 0; i < xda.linkedGraphicList.Count; i++)
            {
                var node = xda.linkedGraphicList[i];
                nodeTree.Add(node, node.parentGuid);
                siblingIndexMap.Add(node, node.siblingIndex);
                var go = linkedGraphicTranslater.CreateGameObjectByLinkedGraphic(xda.linkedGraphicList[i], artboard);
                goMap.Add(node.guid, go);
            }

            // 親子関係構築
            foreach (var kvp in nodeTree)
            {
                goMap[kvp.Key.guid].transform.SetParent(goMap[kvp.Value].transform);
            }

            // SiblingIndex設定
            foreach (var kvp in siblingIndexMap)
            {
                goMap[kvp.Key.guid].transform.SetSiblingIndex(kvp.Value);
            }
            return(artboard);
        }