void CreateShape() { if (!File.Exists(ScriptTemplate)) { DTLog.LogError("[Curvy] Missing Shape Template file '" + ScriptTemplate + "'!"); return; } mShapeParent = (mShapeIs2D) ? "CurvyShape2D" : "CurvyShape"; // Script string template = File.ReadAllText(ScriptTemplate); if (!string.IsNullOrEmpty(template)) { Directory.CreateDirectory(Path.GetDirectoryName(ShapeFileName)); var stream = File.CreateText(ShapeFileName); stream.Write(replaceVars(template)); stream.Close(); } else { DTLog.LogError("[Curvy] Unable to load template file"); return; } AssetDatabase.Refresh(); Close(); EditorUtility.DisplayDialog("Shape Script Wizard", "Script successfully created!", "OK"); Selection.activeObject = AssetDatabase.LoadMainAssetAtPath("Assets/" + mShapeScriptPath + "/" + mShapeClassName + ".cs"); }
void showSlots <T>(List <T> slots) where T : CGModuleSlot { foreach (CGModuleSlot slot in slots) { var linked = slot.GetLinkedModules(); if (linked.Count > 1) { for (int i = 0; i < linked.Count; i++) { var sel = EditorGUILayout.ObjectField((i == 0)?slot.Info.Name:" ", linked[i], typeof(CGModule), true); if (sel != linked[i]) { DTLog.Log("[Curvy] Linking modules from the inspector isn't supported yet! Use the Graph editor instead!"); } } } else { var lm = (linked.Count == 0) ? null : linked[0]; var sel = EditorGUILayout.ObjectField(slot.Info.Name, lm, typeof(CGModule), true); if (sel != lm) { DTLog.Log("[Curvy] Linking modules from the inspector isn't supported yet! Use the Graph editor instead!"); } } } }
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'!"); } }
void CreateModule() { if (!File.Exists(ScriptTemplate)) { DTLog.LogError("[Curvy] Missing Module Template file '" + ScriptTemplate + "'!"); return; } if (!File.Exists(EditorScriptTemplate)) { DTLog.LogError("[Curvy] Missing Module Template file '" + EditorScriptTemplate + "'!"); return; } // Script string template = File.ReadAllText(ScriptTemplate); if (!string.IsNullOrEmpty(template)) { Directory.CreateDirectory(Path.GetDirectoryName(ModuleFileName)); var stream = File.CreateText(ModuleFileName); stream.Write(replaceVars(template)); stream.Close(); } else { DTLog.LogError("[Curvy] Unable to load template file"); return; } // Editor Script template = File.ReadAllText(EditorScriptTemplate); if (!string.IsNullOrEmpty(template)) { Directory.CreateDirectory(Path.GetDirectoryName(ModuleEditorFileName)); var stream = File.CreateText(ModuleEditorFileName); stream.Write(replaceVars(template)); stream.Close(); } else { DTLog.LogError("[Curvy] Unable to load editor template file"); return; } AssetDatabase.Refresh(); Close(); EditorUtility.DisplayDialog("CG Module Wizard", "Scripts successfully created!", "OK"); Selection.objects = new Object[2] { AssetDatabase.LoadMainAssetAtPath(ModuleFileName.Replace(Application.dataPath, "Assets")), AssetDatabase.LoadMainAssetAtPath(ModuleEditorFileName.Replace(Application.dataPath, "Assets")) }; }
public virtual void SavePreferences() { if (!string.IsNullOrEmpty(Identifier)) { SetEditorPrefs <string>("Version", Version); SetEditorPrefs <DTToolbarMode>("ToolbarMode", ToolbarMode); SetEditorPrefs <DTToolbarOrientation>("ToolbarOrientation", ToolbarOrientation); } else { DTLog.LogError("[DevTools] Project " + this.GetType().Name + "missing identifier!"); } }
void DeletePreDTSettings() { DTLog.Log("[Curvy] Removing old preferences"); EditorPrefs.DeleteKey("Curvy_GizmoColor"); EditorPrefs.DeleteKey("Curvy_GizmoSelectionColor"); EditorPrefs.DeleteKey("Curvy_ControlPointSize"); EditorPrefs.DeleteKey("Curvy_OrientationLength"); EditorPrefs.DeleteKey("Curvy_Gizmos"); EditorPrefs.DeleteKey("Curvy_ToolbarLabels"); EditorPrefs.DeleteKey("Curvy_ToolbarOrientation"); EditorPrefs.DeleteKey("Curvy_ShowShapeWizardUndoWarning"); EditorPrefs.DeleteKey("Curvy_KeyBindings"); }
public static void ClipboardCopy(object data) { Type dataType = data.GetType(); IDTClipboardHandler handler; if (mClipboardHandlers.TryGetValue(dataType, out handler)) { handler.Copy(data); } else { DTLog.LogError("[DevTools] No ClipboardHandler for data type '" + data.GetType().Name + "' found!"); } }
public static Texture2D Load(string packedString) { Texture2D tex = Instance.LoadPacked(packedString); if (tex == null) { DTLog.LogError("Loading texture from packed string failed: " + packedString); return(Instance.LoadPacked(fallbackPackedString)); } else { return(Instance.LoadPacked(packedString)); } }
/// <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); }
public static DTProject Project(string identifier) { DTProject prj = null; if (!mProjects.TryGetValue(identifier, out prj)) { LoadProjects(); if (!mProjects.TryGetValue(identifier, out prj)) { DTLog.LogError("[DevTools] Unable to find project '" + identifier + "' !"); } } return(prj); }
public static T GetEditorPrefs <T>(string key, T defaultValue) { if (EditorPrefs.HasKey(key)) { Type tt = typeof(T); try { if (tt.IsEnum || tt.Matches(typeof(int), typeof(Int32))) { return((T)(object)EditorPrefs.GetInt(key, (int)(object)defaultValue)); } else if (tt.IsArray) { throw new System.NotImplementedException(); } else if (tt == typeof(string)) { return((T)(object)EditorPrefs.GetString(key, defaultValue.ToString())); } else if (tt == typeof(float)) { return((T)(object)EditorPrefs.GetFloat(key, (float)(object)defaultValue)); } else if (tt == typeof(bool)) { return((T)(object)EditorPrefs.GetBool(key, (bool)(object)defaultValue)); } else if (tt == typeof(Color)) { return((T)(object)EditorPrefs.GetString(key, ((Color)(object)defaultValue).ToHtml()).ColorFromHtml()); } else { DTLog.LogError("[DevTools] SetEditorPrefs: Unsupported datatype: " + tt.Name); } } catch { return(defaultValue); } } return(defaultValue); }
public virtual void LoadPreferences() { if (!string.IsNullOrEmpty(Identifier)) { // Upgrade? string ver = GetEditorPrefs <string>("Version", Version); if (string.Compare(ver, Version) == -1)// (ver != Version) { UpgradePreferences(ver); SetEditorPrefs <string>("Version", Version); } mTBMode = GetEditorPrefs <DTToolbarMode>("ToolbarMode", ToolbarMode); mTBOrientation = GetEditorPrefs <DTToolbarOrientation>("ToolbarOrientation", ToolbarOrientation); } else { DTLog.LogError("[DevTools] Project " + this.GetType().Name + "missing identifier!"); } }
internal CGModuleEditorBase GetModuleEditor(CGModule module) { CGModuleEditorBase ed; if (!ModuleEditors.TryGetValue(module, out ed)) { ed = Editor.CreateEditor(module) as CGModuleEditorBase; if (ed) { ed.Graph = this; ModuleEditors.Add(module, ed); } else { DTLog.LogError("[Curvy] Curvy Generator: Missing editor script for module '" + module.GetType().Name + "' !"); } } return(ed); }
/// <summary> /// Gets the Curvy folder relative path, e.g. "Packages/Curvy/" by default /// </summary> /// <returns></returns> public static string GetCurvyRootPath() { // Quick check for the regular path if (System.IO.File.Exists(Application.dataPath + "/Packages/Curvy/Base/CurvySplineBase.cs")) { return("Packages/Curvy/"); } // Still no luck? Do a project search var guid = AssetDatabase.FindAssets("curvysplinebase"); if (guid.Length == 0) { DTLog.LogError("[Curvy] Unable to locate CurvySplineBase.cs in the project! Is the Curvy package fully imported?"); return(null); } else { return(AssetDatabase.GUIDToAssetPath(guid[0]).TrimStart("Assets/").TrimEnd("Base/CurvySplineBase.cs")); } }
/// <summary> /// For all EditorKeyBindings registered to ToolbarItems of this project, check if Name is unique /// </summary> /// <returns></returns> internal bool CheckKeyBindingNamesAreUnique() { var dict = new Dictionary <string, object>(); object exist; foreach (var item in ToolbarItems) { foreach (var binding in item.KeyBindings) { if (dict.TryGetValue(binding.Name, out exist)) { DTLog.LogError(string.Format("[DevTools] KeyBindings need unique names! ({0} and {1}", item.GetType().Name, exist.GetType().Name)); return(false); } else { dict.Add(binding.Name, item); } } } return(true); }
public static void SetEditorPrefs <T>(string key, T value) { Type tt = typeof(T); if (tt.IsEnum) { EditorPrefs.SetInt(key, Convert.ToInt32(Enum.Parse(typeof(T), value.ToString()) as Enum)); } else if (tt.IsArray) { throw new System.NotImplementedException(); } else if (tt.Matches(typeof(int), typeof(Int32))) { EditorPrefs.SetInt(key, (value as int?).Value); } else if (tt == typeof(string)) { EditorPrefs.SetString(key, (value as string)); } else if (tt == typeof(float)) { EditorPrefs.SetFloat(key, (value as float?).Value); } else if (tt == typeof(bool)) { EditorPrefs.SetBool(key, (value as bool?).Value); } else if (tt == typeof(Color)) { EditorPrefs.SetString(key, (value as Color?).Value.ToHtml()); } else { DTLog.LogError("[DevTools] SetEditorPrefs: Unsupported datatype: " + tt.Name); } }
/// <summary> /// builds node tree and process parsing attributes /// </summary> public void ReadNodes() { DTGroupNode._serializedObject = serializedObject; SerializedProperty iterator = serializedObject.GetIterator(); mRootNode.Clear(); mEnterChildren = true; DTGroupNode baseNode = mRootNode; DTGroupNode parentNode = baseNode; Stack <string> propertyPathStack = new Stack <string>(); Stack <DTGroupNode> baseNodeStack = new Stack <DTGroupNode>(); bool resetParent = false; while (iterator.NextVisible(mEnterChildren)) { mEnterChildren = false; if (iterator.name != "m_Script" && iterator.name != "InspectorFoldout") { // handle baseNode resetting (AsGroup etc...) while (propertyPathStack.Count > 0 && !iterator.propertyPath.StartsWith(propertyPathStack.Peek())) { propertyPathStack.Pop(); baseNode = baseNodeStack.Pop(); parentNode = baseNode; } var fieldNode = new DTFieldNode(iterator); // get group parsing attributes var groupParseAttribs = iterator.GetAttributes(typeof(IDTGroupParsingAttribute)); groupParseAttribs.Sort(); // get field parsing attributes var parsingAttributes = iterator.GetAttributes(typeof(IDTFieldParsingAttribute)); foreach (IDTGroupParsingAttribute ga in groupParseAttribs) { if (ga is TabAttribute) { var tabA = (TabAttribute)ga; parentNode = baseNode.EnsurePath(tabA.Path, false); if (!string.IsNullOrEmpty(tabA.TabBarName) && !string.IsNullOrEmpty(tabA.TabName)) { if (!parentNode[tabA.TabBarName]) { parentNode = (DTGroupNode)parentNode.Add(new DTGroupNode(tabA.TabBarName, null, DTInspectorNode.RenderAsEnum.TabBar)); } else { parentNode = (DTGroupNode)parentNode[tabA.TabBarName]; } if (!parentNode[tabA.TabName]) { parentNode = (DTGroupNode)parentNode.Add(new DTGroupNode(tabA.TabName, iterator, DTInspectorNode.RenderAsEnum.Tab)); } else { parentNode = (DTGroupNode)parentNode[tabA.TabName]; } if (tabA.Sort != 100) { parentNode.SortOrder = tabA.Sort; } } else { DTLog.LogWarningFormat("[DevTools] Skipping [Tab] on '{0}' because Path is missing TabBar or Tab!", iterator.propertyPath); } } else if (ga is SectionAttribute) { var sectionA = (SectionAttribute)ga; parentNode = createGroup(baseNode, sectionA.Path, iterator); if (sectionA.Sort != 100) { parentNode.SortOrder = sectionA.Sort; } } else if (ga is AsGroupAttribute) { var asGroupA = (AsGroupAttribute)ga; propertyPathStack.Push(fieldNode.SerializedPropertyPath); baseNodeStack.Push(baseNode); parentNode = createGroup((asGroupA.PathIsAbsolute) ? baseNode : parentNode, (asGroupA.Path == null) ? fieldNode.Name : asGroupA.Path + "/" + fieldNode.Name, iterator); baseNode = parentNode; } else if (ga is GroupAttribute) { var groupA = (GroupAttribute)ga; parentNode = createGroup(baseNode, groupA.Path, iterator); if (groupA.Sort != 100) { parentNode.SortOrder = groupA.Sort; } resetParent = true; } } foreach (IDTFieldParsingAttribute pa in parsingAttributes) { if (pa is Hide) { fieldNode.Visible = false; fieldNode.ContentVisible = false; mEnterChildren = false; } else if (pa is AsGroupAttribute || pa is Inline) { fieldNode.Visible = false; fieldNode.ContentVisible = false; mEnterChildren = true; } else if (pa is ArrayExAttribute) { var arrayA = (ArrayExAttribute)pa; fieldNode.ArrayEx = new ReorderableList(serializedObject, iterator, arrayA.Draggable, arrayA.ShowHeader, arrayA.ShowAdd, arrayA.ShowDelete); SetupArrayEx(fieldNode, arrayA); } else if (pa is SortOrderAttribute) { fieldNode.SortOrder = ((SortOrderAttribute)pa).Sort; } } parentNode.Add(fieldNode); if (resetParent) { parentNode = parentNode.Parent as DTGroupNode; resetParent = false; } } } OnReadNodes(); Node.Sort(); }
/// <summary> /// Add code to handle upgrading (delete old pref-keys etc...) here /// </summary> /// <param name="oldVersion">the version stored in the EditorPrefs</param> static void UpgradeDevTools(string oldVersion) { DTLog.Log("[DevTools] Upgrading settings from " + oldVersion + " to " + VERSION); }
protected virtual void UpgradePreferences(string oldVersion) { DTLog.Log(string.Format("[{0}] Upgrading project settings from {1} to {2}", Identifier, oldVersion, Version)); }
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; } }