public static void loadNodeIcons()
    {
        if (ArchimatixEngine.nodeIcons != null)
        {
            return;
        }

        ArchimatixEngine.nodeIcons = new Dictionary <string, Texture2D>();


        // The ? wildcard is used here to make sure that .jpg.meta files are not being returned
        String[] nodeIconPaths = Directory.GetFiles(ArchimatixEngine.ArchimatixAssetPath + "/ui/NodeIcons/", "*.jp?");

        string filename;
        string nodeIconName;

        for (int i = 0; i < nodeIconPaths.Length; i++)
        {
            //Debug.Log(nodeIconPaths[i]);
            filename = System.IO.Path.GetFileName(nodeIconPaths[i]);

            if (!string.IsNullOrEmpty(filename) && filename.Length > 10)
            {
                // strip extension
                nodeIconName = System.IO.Path.GetFileNameWithoutExtension(nodeIconPaths[i]);

                if (!string.IsNullOrEmpty(filename) && nodeIconName.Length > 10)
                {
                    //strip prefix of "zz-AXNode-"
                    nodeIconName = nodeIconName.Substring(10);

                    ArchimatixEngine.nodeIcons.Add(nodeIconName, (Texture2D)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/ui/NodeIcons/" + filename, typeof(Texture2D)));
                }
            }
        }

        // custom nodes with name of form zz_AXNode-typename
        Archimatix.discoverThirdPartyNodes();

        foreach (String name in Archimatix.customNodeNames)
        {
            string typeName = name;

            DirectoryInfo info = new DirectoryInfo(Application.dataPath);

            FileInfo[] files = info.GetFiles("zz_AXNode-" + typeName + ".jpg", SearchOption.AllDirectories);

            if (files != null && files.Length > 0)
            {
                string iconRelPath = ArchimatixUtils.getRelativeFilePath(files[0].ToString());
                //Debug.Log("path: " + typeName + " --- " + iconRelPath);

                if (!ArchimatixEngine.nodeIcons.ContainsKey(typeName))
                {
                    ArchimatixEngine.nodeIcons.Add(typeName, (Texture2D)AssetDatabase.LoadAssetAtPath(iconRelPath, typeof(Texture2D)));
                }
            }
        }
    }
示例#2
0
    public static void makePrefab(AXModel model, string prefabPath, AXNodeGraphEditorWindow _editor)
    {
        //if (model == null)
        //	return null;

        if (model.generatedGameObjects != null)
        {
            // extrat folder path from path

            //string filename = System.IO.Path.GetFileName (filepath);
            string prefabName = System.IO.Path.GetFileNameWithoutExtension(prefabPath);

            string relativePrefabPath = ArchimatixUtils.getRelativeFilePath(prefabPath);

            string folderPath         = System.IO.Path.GetDirectoryName(prefabPath);
            string relativeFolderPath = ArchimatixUtils.getRelativeFilePath(folderPath);

            // if no directory selected in dialog, then relativeFolderPath is empty
            if (String.IsNullOrEmpty(relativeFolderPath))
            {
                relativeFolderPath = "Assets";
            }

            Debug.Log(folderPath + " :: " + relativeFolderPath + " :: " + prefabName);

            model.build();

            GameObject stampedGO = model.stamp();

            // Only save unique, sharedMeshes to the AssetsDatabase
            List <Mesh> meshesToSave = new List <Mesh> ();
            int         meshCount    = 0;

            Transform[] transforms = stampedGO.GetComponentsInChildren <Transform> ();
            foreach (Transform transform in transforms)
            {
                MeshFilter meshFilter = transform.gameObject.GetComponent <MeshFilter> ();

                if (meshFilter != null)
                {
                    Mesh mesh = meshFilter.sharedMesh;
                    if (mesh != null && !meshesToSave.Contains(mesh))
                    {
                        ;
                        meshesToSave.Add(mesh);

                        meshCount++;
                    }
                    GameObjectUtility.SetStaticEditorFlags(transform.gameObject, StaticEditorFlags.LightmapStatic);
                }
            }

            AssetDatabase.DeleteAsset(relativePrefabPath);


            // [not sure why this is needed here to correct the filepath, but not in the Library Save dalog...]
            relativePrefabPath = relativePrefabPath.Replace('\\', '/');



            var prefab = PrefabUtility.CreateEmptyPrefab(relativePrefabPath);

            int i = 0;
            foreach (Mesh mesh in meshesToSave)

            /*
             * {
             *      if (string.IsNullOrEmpty(mesh.name))
             *              mesh.name = prefabName+"_"+(i++);
             *      AssetDatabase.DeleteAsset (relativePrefabPath+"/"+mesh.name);
             *      AssetDatabase.AddObjectToAsset(mesh, relativePrefabPath);
             * }
             */
            {             // Compliments of Enoch
                if (string.IsNullOrEmpty(mesh.name))
                {
                    mesh.name = prefabName + "_" + (i++);
                }
                var path = AssetDatabase.GetAssetPath(mesh);

                if (string.IsNullOrEmpty(path))
                {
                    AssetDatabase.AddObjectToAsset(mesh, relativePrefabPath);
                }
            }



            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();

            PrefabUtility.ReplacePrefab(stampedGO, prefab, ReplacePrefabOptions.ConnectToPrefab);

            stampedGO.name = prefabName;
            //Selection.activeGameObject = stampedGO;

            //buildStatus = BuildStatus.Generated;



            //Close();
        }
    }
        // DETAIL VIEW

        public void doDetailView()
        {
            GUIStyle  shadowDown = new GUIStyle();
            Texture2D bgTex      = (Texture2D)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/ui/Shadow.png", typeof(Texture2D));

            shadowDown.normal.background = bgTex;



            if (EditorGUILayout.BeginFadeGroup(showDetailItem.faded))
            {
                // DETAIL VIEW

                GUILayout.Space(15);


                GUILayout.BeginHorizontal(shadowDown, GUILayout.Height(18));
                GUILayout.Label(" ");
                GUILayout.EndHorizontal();

                GUILayout.BeginHorizontal();

                // LARGE THUMBNAIL


                string thumbnailPath = Path.ChangeExtension(detailItem.readIntoLibraryFromRelativeAXOBJPath, ".jpg");

                string thumbnailRelativePath = ArchimatixUtils.getRelativeFilePath(thumbnailPath);;

                Texture2D tex = (Texture2D)AssetDatabase.LoadAssetAtPath(thumbnailRelativePath, typeof(Texture2D));
                GUILayout.Label(tex, GUILayout.Width(256));

                GUIStyle labelstyle  = GUI.skin.GetStyle("Label");
                GUIStyle buttonstyle = GUI.skin.GetStyle("Button");

                GUILayout.Space(30);

                // DATA SHEET


                GUILayout.BeginVertical();



                // NAME
                labelstyle.fontSize = 24;
                GUILayout.Label(detailItem.Name);
                labelstyle.fontSize = 10;


                if (editingDetailItem)
                {
                    detailItem.author = GUILayout.TextField(detailItem.author);

                    EditorGUILayout.LabelField("Tags");
                    detailItem.tags = GUILayout.TextField(detailItem.tags);

                    // TAG CATEGORIES
                    GUILayout.BeginHorizontal();

                    string tags = "," + detailItem.tags + ",";

                    foreach (KeyValuePair <string, List <string> > kv in ArchimatixEngine.library.categories)
                    {
                        GUILayout.BeginVertical();

                        GUILayout.Label(kv.Key);

                        foreach (string tag in kv.Value)
                        {
                            tags = "," + detailItem.tags + ",";
                            //GUILayout.Label ("- "+tag);
                            EditorGUI.BeginChangeCheck();
                            EditorGUILayout.ToggleLeft(tag, tags.Contains("," + tag + ","), GUILayout.Width(150));
                            if (EditorGUI.EndChangeCheck())
                            {
                                if (tags.Contains(tag))
                                {
                                    tags = tags.Replace(("," + tag + ","), ",");
                                }
                                else
                                {
                                    tags += tag;
                                }

                                detailItem.tags = tags.Trim(new Char[] { ' ', ',' });
                            }
                        }
                        GUILayout.EndVertical();
                    }
                    GUILayout.EndHorizontal();
                    // TAG CATEGORIES



                    GUILayout.FlexibleSpace();
                    buttonstyle.alignment = TextAnchor.MiddleCenter;
                    GUILayout.BeginHorizontal();
                    if (GUILayout.Button("Cancel", GUILayout.Width(50)))
                    {
                        editingDetailItem = false;
                    }
                    if (GUILayout.Button("Save", GUILayout.Width(50)))
                    {
                        Debug.Log("Saving author as: " + detailItem.author);
                        editingDetailItem = false;


                        //library.saveParametricObjectMetadata(detailItem);
                    }

                    GUILayout.EndHorizontal();
                    buttonstyle.alignment = TextAnchor.UpperLeft;
                }
                else
                {
                    // AUTHOR
                    string author = (string.IsNullOrEmpty(detailItem.author)) ? "anonymous" : detailItem.author;

                    GUILayout.BeginHorizontal();
                    labelstyle.alignment = TextAnchor.MiddleRight;
                    GUILayout.Label("By: ", GUILayout.Width(50));
                    labelstyle.alignment = TextAnchor.MiddleLeft;
                    GUILayout.Label(author);
                    GUILayout.EndHorizontal();

                    if (string.IsNullOrEmpty(detailItem.tags))
                    {
                        detailItem.tags = "";
                    }

                    string tmpTags = detailItem.tags.Replace(",", ", ");

                    GUILayout.BeginHorizontal();
                    labelstyle.alignment = TextAnchor.MiddleRight;
                    GUILayout.Label("Tags: ", GUILayout.Width(50));
                    labelstyle.alignment = TextAnchor.MiddleLeft;
                    if (tmpTags == null || tmpTags == "")
                    {
                        tmpTags = "none";
                    }
                    GUILayout.Label(tmpTags);
                    GUILayout.EndHorizontal();

                    GUILayout.FlexibleSpace();
                    buttonstyle.alignment = TextAnchor.MiddleCenter;
                    if (GUILayout.Button("Edit", GUILayout.Width(50)))
                    {
                        editingDetailItem = true;
                    }
                    buttonstyle.alignment = TextAnchor.UpperLeft;
                }


                GUILayout.EndVertical();

                GUILayout.EndHorizontal();



                // bottom shadow
                Texture2D bgTexUp = (Texture2D)AssetDatabase.LoadAssetAtPath(ArchimatixEngine.ArchimatixAssetPath + "/ui/ShadowUp.png", typeof(Texture2D));

                shadowDown.normal.background = bgTexUp;



                GUILayout.BeginHorizontal(shadowDown, GUILayout.Height(18));
                GUILayout.Label(" ");
                GUILayout.EndHorizontal();



                GUILayout.Space(15);
            }
            EditorGUILayout.EndFadeGroup();
        }