コード例 #1
0
 public static void Deserialize(string json, CurvySplineSegment insertAfter, CurvySerializationSpace space)
 {
     if (SerializedCurvyObjectHelper.GetJsonSerializedType(json) == typeof(SerializedCurvySplineSegmentCollection))
     {
         var sspl = SerializedCurvySplineSegmentCollection.FromJson(json);
         sspl.Deserialize(insertAfter, space, mOnDeserializedCP);
     }
     else
     {
         DTLog.LogWarning("[Curvy] CurvyImportExport.Deserialize: Data isn't of type 'SerializedCurvySplineSegmentCollection'!");
     }
 }
コード例 #2
0
ファイル: DTResource.cs プロジェクト: Fell/OnTrack
        /// <summary>
        /// Load an image either from a Resource DLL or the Editor/Resources folder
        /// </summary>
        /// <param name="assembly">the resource DLL assembly</param>
        /// <param name="resourcePath">the resource path(namespace)</param>
        /// <param name="resourceName">name of the resource file (without extension)</param>
        /// <param name="width">width of the image (can be omitted when loading from texture file)</param>
        /// <param name="height">height of the image (can be omitted when loading from texture file)</param>
        /// <returns>a Texture</returns>
        public virtual Texture2D Load(string resourceName, int width = 0, int height = 0, Assembly assembly = null, string resourcePath = "")
        {
            if (assembly == null)
            {
                assembly = ResourceDLL;
            }
            if (string.IsNullOrEmpty(resourcePath))
            {
                resourcePath = ResourceNamespace;
            }

            Texture2D texture = null;

            if (string.IsNullOrEmpty(System.IO.Path.GetExtension(resourceName)))
            {
                resourceName += ".png";
            }

            //if (!resourcePath.EndsWith("."))
            //    resourcePath += ".";

            if (assembly != null)
            {
                System.IO.Stream myStream = assembly.GetManifestResourceStream(resourcePath + resourceName);
                if (myStream != null)
                {
                    texture = new Texture2D(width, height, TextureFormat.ARGB32, false);
                    texture.LoadImage(ReadToEnd(myStream));
                    if (texture != null)
                    {
                        //texture.hideFlags = HideFlags.DontSave;
                        return(texture);
                    }
                }
            }
            // Try from file sys:
            texture = (Texture2D)Resources.Load(System.IO.Path.GetFileNameWithoutExtension(resourceName));

            if (texture == null)
            {
                DTLog.LogWarning("Missing resource: " + resourcePath + resourceName);
            }
            //else
            //    texture.hideFlags = HideFlags.DontSave;



            return(texture);
        }
コード例 #3
0
        void OnGUI()
        {
            DTInspectorNode.IsInsideInspector = false;
            if (Curves.Count == 0)
            {
                return;
            }


            Mode = GUILayout.SelectionGrid(Mode, new GUIContent[]
            {
                new GUIContent("Closed Shape", "Export a closed shape with triangles"),
                new GUIContent("Vertex Line", "Export a vertex line")
            }, 2);



            if (!string.IsNullOrEmpty(TriangulationMessage) && !TriangulationMessage.Contains("Angle must be >0"))
            {
                EditorGUILayout.HelpBox(TriangulationMessage, MessageType.Error);
            }

            scroll = EditorGUILayout.BeginScrollView(scroll);

            // OUTLINE
            GUIRenderer.RenderSectionHeader(nSplines);
            if (nSplines.ContentVisible)
            {
                Winding = (WindingRule)EditorGUILayout.EnumPopup("Winding", Winding, GUILayout.Width(285));
                GUILayout.BeginHorizontal();
                GUILayout.Label(new GUIContent("Spline", "Note: Curves from a SplineGroup needs to be connected!"), EditorStyles.boldLabel, GUILayout.Width(140));
                GUILayout.Label("Vertex Generation", EditorStyles.boldLabel, GUILayout.Width(160));
                GUILayout.Label("Orientation", EditorStyles.boldLabel);
                GUILayout.EndHorizontal();
                CurveGUI(Curves[0]);
                if (Mode == CLOSEDSHAPE)
                {
                    for (int i = 1; i < Curves.Count; i++)
                    {
                        CurveGUI(Curves[i]);
                    }
                    if (GUILayout.Button(CurvyStyles.AddSmallTexture, GUILayout.ExpandWidth(false)))
                    {
                        Curves.Add(new SplinePolyLine(null));
                    }
                }
            }

            mNeedRepaint = mNeedRepaint || nSplines.NeedRepaint;
            GUIRenderer.RenderSectionFooter(nSplines);

            // TEXTURING
            GUIRenderer.RenderSectionHeader(nTexture);
            if (nTexture.ContentVisible)
            {
                Mat      = (Material)EditorGUILayout.ObjectField("Material", Mat, typeof(Material), true, GUILayout.Width(285));
                UVTiling = EditorGUILayout.Vector2Field("Tiling", UVTiling, GUILayout.Width(285));
                UVOffset = EditorGUILayout.Vector2Field("Offset", UVOffset, GUILayout.Width(285));
            }
            GUIRenderer.RenderSectionFooter(nTexture);
            mNeedRepaint = mNeedRepaint || nTexture.NeedRepaint;
            // EXPORT
            GUIRenderer.RenderSectionHeader(nExport);
            if (nExport.ContentVisible)
            {
                EditorGUILayout.HelpBox("Export is 2D (x/y) only!", MessageType.Info);
                MeshName = EditorGUILayout.TextField("Mesh Name", MeshName, GUILayout.Width(285));
                UV2      = EditorGUILayout.Toggle("Add UV2", UV2);

                GUILayout.BeginHorizontal();

                if (GUILayout.Button("Save as Asset"))
                {
                    string path = EditorUtility.SaveFilePanelInProject("Save Mesh", MeshName + ".asset", "asset", "Choose a file location");
                    if (!string.IsNullOrEmpty(path))
                    {
                        Mesh msh = clonePreviewMesh();
                        if (msh)
                        {
                            msh.name = MeshName;
                            AssetDatabase.DeleteAsset(path);
                            AssetDatabase.CreateAsset(msh, path);
                            AssetDatabase.SaveAssets();
                            AssetDatabase.Refresh();
                            DTLog.Log("[Curvy] Export: Mesh Asset saved!");
                        }
                    }
                }

                if (GUILayout.Button("Create GameObject"))
                {
                    Mesh msh = clonePreviewMesh();
                    if (msh)
                    {
                        msh.name = MeshName;
                        var go = new GameObject(MeshName, typeof(MeshRenderer), typeof(MeshFilter));
                        go.GetComponent <MeshFilter>().sharedMesh       = msh;
                        go.GetComponent <MeshRenderer>().sharedMaterial = Mat;
                        Selection.activeGameObject = go;
                        DTLog.Log("[Curvy] Export: GameObject created!");
                    }
                    else
                    {
                        DTLog.LogWarning("[Curvy] Export: Unable to triangulate spline!");
                    }
                }
                GUILayout.EndHorizontal();
            }
            GUIRenderer.RenderSectionFooter(nExport);
            mNeedRepaint = mNeedRepaint || nExport.NeedRepaint;
            EditorGUILayout.EndScrollView();
            refreshNow = refreshNow || GUI.changed;
            if (mNeedRepaint)
            {
                Repaint();
                mNeedRepaint = false;
            }
        }