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 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!"); } }
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)); } }
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); }
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); }
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!"); } }
/// <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); } }