public static void CreateNGSettings(string path) { try { NGSettings asset = ScriptableObject.CreateInstance <NGSettings>(); AssetDatabase.CreateAsset(asset, path); AssetDatabase.SaveAssets(); NGEditorPrefs.SetString(Constants.ConfigPathKeyPref, path, true); HQ.SetSettings(asset); // Need to skip many frames before really writing the data. Don't know why it requires 2 frames. EditorApplication.delayCall += () => { EditorApplication.delayCall += () => { HQ.InvalidateSettings(); AssetDatabase.SaveAssets(); }; }; } catch (Exception ex) { InternalNGDebug.LogException(ex); HQ.SetSettings(null); } }
protected virtual void OnGUI() { if (this.richTextField == null) { this.richTextField = new GUIStyle(GUI.skin.textField); this.richTextField.richText = true; } this.DrawWizardGUI(); using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton)) { if (GUILayout.Button(LC.G("ExportSettings_Export")) == true) { if (SettingsExporter.Export(this.instances, this.root, exportFile) == true) { InternalNGDebug.Log(LC.G("ExportSettings_ExportSuccess")); } else { InternalNGDebug.LogError(LC.G("ExportSettings_ExportFailed")); } } } this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition); this.DrawNode(this.root); EditorGUILayout.EndScrollView(); }
protected virtual void OnGUI() { if (this.richTextField == null) { this.richTextField = new GUIStyle(GUI.skin.textField); this.richTextField.richText = true; } using (BgColorContentRestorer.Get(GeneralStyles.HighlightActionButton)) { if (GUILayout.Button(LC.G("ImportSettings_Import")) == true) { ImportSettingsWizard.trackObjects.Clear(); try { this.Import(this.root); InternalNGDebug.Log(LC.G("ImportSettings_ImportCompleted")); } catch (Exception ex) { InternalNGDebug.LogException(LC.G("ImportSettings_ImportFailed"), ex); } } } ImportSettingsWizard.trackObjects.Clear(); this.scrollPosition = EditorGUILayout.BeginScrollView(this.scrollPosition); { this.DrawNode(this.root); } EditorGUILayout.EndScrollView(); }
public static void RequestAddLanguage(this Version version, IPublisherAPI api, string languageCode, Action <RequestResponse <bool> > onCompleted = null) { api.AddLanguage(version.id, languageCode, version.name, (r, result) => { RequestResponse <bool> requestResponse = new RequestResponse <bool>() { context = version, ok = false, error = null, result = false }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { Response response = DataStructureExtension.CheckResponse(result, requestResponse); if (Conf.DebugMode == Conf.DebugState.Verbose) { InternalNGDebug.Snapshot(response); } if (response != null && response.Succeeded == true) { requestResponse.ok = true; requestResponse.result = true; } } if (onCompleted != null) { onCompleted(requestResponse); } }); }
public static void RequestSubmit(this Version version, IPublisherAPI api, bool autoPublish, string comments, Action <RequestResponse <string> > onCompleted = null) { api.Submit(version.id, autoPublish, comments, (r, result) => { RequestResponse <string> requestResponse = new RequestResponse <string>() { context = version, ok = false, error = null, result = null }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { Response response = DataStructureExtension.CheckResponse(result, requestResponse); if (Conf.DebugMode == Conf.DebugState.Verbose) { InternalNGDebug.Snapshot(response); } if (response != null && response.Succeeded == true) { requestResponse.ok = true; requestResponse.result = response.url; } } if (onCompleted != null) { onCompleted(requestResponse); } }); }
private NetGameObjectData(ByteBuffer buffer) { using (SafeUnwrapByteBuffer.Get(buffer, this.GetError)) { this.gameObjectInstanceID = buffer.ReadInt32(); this.tag = buffer.ReadUnicodeString(); this.layer = buffer.ReadInt32(); this.isStatic = buffer.ReadBoolean(); int length = buffer.ReadInt32(); this.components = new NetComponent[length]; for (int i = 0; i < length; i++) { try { this.components[i] = NetComponent.Deserialize(buffer); } catch (Exception ex) { InternalNGDebug.LogException("GameObject failed on Component " + (i + 1) + "/" + length + ".", ex); throw; } } } }
public static void RequestPeriods(this PublisherDatabase database, IPublisherAPI api, Action <RequestResponse <Period[]> > onCompleted = null) { api.GetPeriods(api.Session.publisher, (r, result) => { RequestResponse <Period[]> requestResponse = new RequestResponse <Period[]>() { context = database, ok = false, error = null, result = null }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { PeriodsContainer container = JsonUtility.FromJson <PeriodsContainer>(result); if (Conf.DebugMode == Conf.DebugState.Verbose) { InternalNGDebug.Snapshot(container); } requestResponse.ok = true; requestResponse.result = container.periods; database.Periods = requestResponse.result; } if (onCompleted != null) { onCompleted(requestResponse); } }); }
/// <summary> /// Prepares the row by parsing its log. /// </summary> private void ParseLog() { InternalNGDebug.AssertFile(this.isParsed == false, "Parsed Row is being parsed again."); this.isParsed = true; int end = this.log.condition.IndexOf(InternalNGDebug.DataEndChar); string raw = this.log.condition.Substring(1, end - 1); int n = raw.IndexOf(InternalNGDebug.DataSeparator); if (n != -1) { this.firstLine = raw.Substring(0, n).Replace(InternalNGDebug.DataSeparatorReplace, InternalNGDebug.DataSeparator); this.fields = raw.Substring(n + 1).Replace(InternalNGDebug.DataSeparatorReplace, InternalNGDebug.DataSeparator); Utility.content.text = this.fields; this.fieldsHeight = GeneralStyles.RichTextArea.CalcHeight(Utility.content, 0F); } else { this.firstLine = raw.Replace(InternalNGDebug.DataSeparatorReplace, InternalNGDebug.DataSeparator); this.fields = string.Empty; this.fieldsHeight = 0F; } }
public static void PreviewStackFrame(RowsDrawer rowsDrawer, Rect r, Frame frame) { if (frame.fileExist == true && RowUtility.previewFrame != frame) { try { RowUtility.previewLines = ConsoleUtility.files.GetFile(frame.fileName); RowUtility.rowsDrawer = rowsDrawer; RowUtility.previewFrame = frame; RowUtility.previewRect = r; FilesWatcher.Watch(frame.fileName); RowUtility.previewEditorWindow = RowUtility.drawingWindow; RowUtility.rowsDrawer.AfterAllRows -= RowUtility.DrawPreview; RowUtility.rowsDrawer.AfterAllRows += RowUtility.DrawPreview; } catch (Exception ex) { InternalNGDebug.LogException(ex); RowUtility.ClearPreview(); } } }
private static void LaunchAllTests() { foreach (Type type in Utility.EachNGTSubClassesOf(typeof(NGUnitTest))) { NGUnitTest test = Activator.CreateInstance(type) as NGUnitTest; MethodInfo[] methods = type.GetMethods(); InternalNGDebug.Log("Testing " + type.Name); for (int i = 0; i < methods.Length; i++) { if (methods[i].IsDefined(typeof(TestMethodAttribute), false) == true) { try { methods[i].Invoke(test, null); } catch (Exception ex) { InternalNGDebug.LogException(ex); } } } } }
public static bool Initialize() { if (MetadataDatabase.database == null) { try { MetadataDatabase.database = new Dictionary <Type, TypeIdentifiers>(1024); string[] files = Directory.GetFiles(Application.dataPath + "/../Library/metadata", "*.info", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { MetadataDatabase.Extract(files[i]); } return(true); } catch (Exception ex) { InternalNGDebug.LogException(ex); } return(false); } return(true); }
void IHasCustomMenu.AddItemsToMenu(GenericMenu menu) { if (this.Hierarchy != null) { this.Hierarchy.AddTabMenus(menu, this); } Utility.AddNGMenuItems(menu, this, NGRemoteInspectorWindow.NormalTitle, Constants.WikiBaseURL + "#markdown-header-132-ng-remote-inspector"); if (Conf.DebugMode != Conf.DebugState.None) { menu.AddItem(new GUIContent("Output static types"), false, () => { if (this.Hierarchy.inspectableTypes != null) { for (int i = 0; i < this.Hierarchy.inspectableTypes.Length; i++) { if (this.Hierarchy.inspectableTypes[i].@namespace != null) { Debug.Log(this.Hierarchy.inspectableTypes[i].typeIndex + " " + this.Hierarchy.inspectableTypes[i].@namespace + '.' + this.Hierarchy.inspectableTypes[i].name); } else { Debug.Log(this.Hierarchy.inspectableTypes[i].typeIndex + " " + this.Hierarchy.inspectableTypes[i].name); } } } else { InternalNGDebug.Log("Static types not available, load them first."); } }); } }
private void FindReferences() { this.ClearResults(); this.isSearching = true; string[] files = Directory.GetFiles("Assets/", "*.mat", SearchOption.AllDirectories); int max = files.Length; for (int i = 0; i < max; i++) { try { Material mat = AssetDatabase.LoadAssetAtPath(files[i], typeof(Material)) as Material; if (mat.shader == this.targetShader) { this.results.Add(mat); } } catch (Exception ex) { InternalNGDebug.LogException("Exception thrown on file \"" + files[i] + "\".", ex); } EditorUtility.DisplayProgressBar(NGShaderFinderWindow.Title + " - Project (" + (i + 1) + " / " + max + ")", files[i], (float)(i + 1) / (float)max); } EditorUtility.ClearProgressBar(); this.PrepareResults(); }
public static void Invoke(string name, Type type, string staticMethod) { if (type != null) { MethodInfo method = type.GetMethod(staticMethod, BindingFlags.Public | BindingFlags.Static); if (method != null) { method.Invoke(null, null); return; } } if (HQ.nestedMenuFailedOnce == name) { Utility.ShowPreferencesWindowAt(Constants.PreferenceTitle); Preferences.tab = Preferences.Tab.Preferences; XGUIHighlightManager.Highlight(Preferences.Title + ".RootedMenu"); } else { HQ.nestedMenuFailedOnce = name; InternalNGDebug.LogWarning("Calling MenuItem \"" + name + "\" has failed. Please regenerate rooted menu. (Go to Edit/Preferences/NG Tools or recall this menu)"); } }
static TypeHandlersManager() { List <TypeHandler> handlers = new List <TypeHandler>(); foreach (Type t in Utility.EachAllSubClassesOf(typeof(TypeHandler))) { if (t == typeof(ClassHandler)) { TypeHandlersManager.classHandler = new ClassHandler(); handlers.Add(TypeHandlersManager.classHandler); } else if (t == typeof(ArrayHandler)) { TypeHandlersManager.arrayHandler = new ArrayHandler(); handlers.Add(TypeHandlersManager.arrayHandler); } else { handlers.Add((TypeHandler)Activator.CreateInstance(t)); } } handlers.Sort((a, b) => (a.GetType().GetCustomAttributes(typeof(PriorityAttribute), false) as PriorityAttribute[])[0].priority - (b.GetType().GetCustomAttributes(typeof(PriorityAttribute), false) as PriorityAttribute[])[0].priority); TypeHandlersManager.typeHandlers = handlers.ToArray(); InternalNGDebug.Assert(TypeHandlersManager.classHandler != null, "Ref-type handler does not exist."); InternalNGDebug.Assert(TypeHandlersManager.arrayHandler != null, "Array-type handler does not exist."); }
private string RequestSupportedTextureFormat() { StringBuilder buffer = Utility.GetBuffer(); foreach (TextureFormat item in Enum.GetValues(typeof(TextureFormat))) { if ((int)item <= 0) { continue; } try { bool supported = SystemInfo.SupportsTextureFormat(item); if (buffer.Length > 0) { buffer.AppendLine(); } buffer.Append(item.ToString() + " : " + supported); } catch (Exception ex) { InternalNGDebug.VerboseLogException(ex); } } return(Utility.ReturnBuffer(buffer)); }
public static void Serialize(ByteBuffer buffer, ServerGameObject NGGameObject) { using (SafeWrapByteBuffer.Get(buffer)) { NGGameObject.ProcessComponents(); buffer.Append(NGGameObject.instanceID); buffer.AppendUnicodeString(NGGameObject.gameObject.tag); buffer.Append(NGGameObject.gameObject.layer); buffer.Append(NGGameObject.gameObject.isStatic); buffer.Append(NGGameObject.components.Count); for (int i = NGGameObject.components.Count - 1; i >= 0; --i) { try { NetComponent.Serialize(buffer, NGGameObject.components[i]); } catch (Exception ex) { InternalNGDebug.LogException("GameObject \"" + NGGameObject.gameObject.name + "\" failed on Component \"" + NGGameObject.components[i].component.name + "\" (" + (i + 1) + "/" + NGGameObject.components.Count + ").", ex); throw; } } } }
protected virtual void OnDisable() { InternalNGDebug.VerboseLog("NGHub.OnDisable," + this.initialized + "," + this.dockedAsMenu); if (this.initialized == false) { return; } if (this.dockedAsMenu == true) { NGEditorPrefs.SetInt(NGHubWindow.ForceRecreateKeyPref + "_" + Application.dataPath, (int)DockState.ProperlyDisabled); } HQ.SettingsChanged -= this.OnSettingsChanged; Undo.undoRedoPerformed -= this.RestoreComponents; Utility.DirectSaveEditorPref(this.backgroundColor, typeof(Color), NGHubWindow.BackgroundColorKeyPref); this.initialized = false; for (int i = 0; i < this.components.Count; i++) { this.components[i].Uninit(); } }
public static void RequestLanguages(this PublisherDatabase database, IPublisherAPI api, Action <RequestResponse <Language[]> > onCompleted = null) { api.GetLanguages((r, result) => { RequestResponse <Language[]> requestResponse = new RequestResponse <Language[]>() { context = database, ok = false, error = null, result = null }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { LanguagesContainer languages = JsonUtility.FromJson <LanguagesContainer>("{\"languages\":" + result + '}'); if (Conf.DebugMode == Conf.DebugState.Verbose) { InternalNGDebug.Snapshot(languages.languages); } requestResponse.ok = true; requestResponse.result = languages.languages; database.Languages = requestResponse.result; } if (onCompleted != null) { onCompleted(requestResponse); } }); }
private static void LoadHashesCache() { if (System.IO.File.Exists(NGSyncFoldersWindow.cachePath) == true) { try { if (NGSyncFoldersWindow.cachedHashes == null) { NGSyncFoldersWindow.cachedHashes = new Dictionary <string, string[]>(64); } using (FileStream fs = System.IO.File.Open(NGSyncFoldersWindow.cachePath, FileMode.Open, FileAccess.Read, FileShare.Read)) using (BufferedStream bs = new BufferedStream(fs)) using (StreamReader sr = new StreamReader(bs)) { string line; while ((line = sr.ReadLine()) != null) { NGSyncFoldersWindow.cachedHashes.Add(line, new string[] { sr.ReadLine(), sr.ReadLine() }); } } } catch (Exception ex) { InternalNGDebug.LogException(ex); NGSyncFoldersWindow.cachedHashes.Clear(); } } else if (NGSyncFoldersWindow.cachedHashes == null) { NGSyncFoldersWindow.cachedHashes = new Dictionary <string, string[]>(); } }
public static void RequestCategories(this Version version, IPublisherAPI api, Action <RequestResponse <Category[]> > onCompleted = null) { api.GetCategories(version.id, (r, result) => { RequestResponse <Category[]> requestResponse = new RequestResponse <Category[]>() { context = version, ok = false, error = null, result = null }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { CategoriesContainer categories = JsonUtility.FromJson <CategoriesContainer>("{\"categories\":" + result + "}"); if (Conf.DebugMode == Conf.DebugState.Verbose) { InternalNGDebug.Snapshot(categories.categories); } requestResponse.ok = true; requestResponse.result = categories.categories; version.Categories = requestResponse.result; } if (onCompleted != null) { onCompleted(requestResponse); } }); }
private static void Create(Type type) { try { string path = string.Empty; if (ScriptableObjectCreator.contextObject != null) { path = AssetDatabase.GetAssetPath(ScriptableObjectCreator.contextObject); if (string.IsNullOrEmpty(path) == false && Directory.Exists(path) == false) { path = Directory.GetParent(path).FullName; } } path = EditorUtility.SaveFilePanelInProject(LC.G("Create") + " " + type.Name, type.Name + ".asset", "asset", LC.G("ScriptableObjectCreator_EnterAssetName"), path); if (string.IsNullOrEmpty(path) == false) { ScriptableObject instance = ScriptableObject.CreateInstance(type); AssetDatabase.CreateAsset(instance, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); Selection.activeObject = instance; } } catch (Exception ex) { InternalNGDebug.LogException(ex); } }
public static void RequestSetKeyImage(this Version version, IPublisherAPI api, VersionDetailed.Package.Version.Language language, string path, string type, Action <RequestResponse <string> > onCompleted = null) { api.SetKeyImage(version.id, language.languageCode, path, type, (r, result) => { RequestResponse <string> requestResponse = new RequestResponse <string>() { context = version, ok = false, error = null, result = null }; if (DataStructureExtension.CheckRequest(r, result, requestResponse) == true) { Response response = DataStructureExtension.CheckResponse(result, requestResponse); if (Conf.DebugMode == Conf.DebugState.Verbose) { InternalNGDebug.Snapshot(response); } if (response != null && response.Succeeded == true) { requestResponse.ok = true; requestResponse.result = response.url; } } if (onCompleted != null) { onCompleted(requestResponse); } }); }
private void UpdateGroupedData() { this.groupedData.Clear(); for (int i = 0; i < this.dataConsole.Length; i++) { if (this.dataConsole[i] == null) { InternalNGDebug.LogWarning(Errors.GameConsole_NullDataConsole, "DataConsole #" + i + " is null.", this); continue; } this.dataConsole[i].shortStyle = this.dataConsoleShortStyle; this.dataConsole[i].fullStyle = this.dataConsoleFullStyle; this.dataConsole[i].subTitleStyle = this.dataConsoleSubTitleStyle; this.dataConsole[i].InitOnGUI(); if (this.groupedData.ContainsKey(this.dataConsole[i].group) == false) { this.groupedData.Add(this.dataConsole[i].group, new GroupDataConsole()); } this.groupedData[this.dataConsole[i].group].Add(this.dataConsole[i]); } foreach (GroupDataConsole group in this.groupedData.Values) { group.Init(); } }
private static void OnGUIPresets() { if (ConsoleSettingsEditor.presetTypes == null) { List <Type> types = new List <Type>(4); List <string> names = new List <string>(4); foreach (Type c in Utility.EachNGTSubClassesOf(typeof(Preset))) { types.Add(c); names.Add(Utility.NicifyVariableName(c.Name)); } ConsoleSettingsEditor.presetTypes = types.ToArray(); ConsoleSettingsEditor.presetNames = names.ToArray(); } for (int i = 0; i < ConsoleSettingsEditor.presetTypes.Length; i++) { if (GUILayout.Button(ConsoleSettingsEditor.presetNames[i]) == true && ((Event.current.modifiers & Constants.ByPassPromptModifier) != 0 || EditorUtility.DisplayDialog(ConsoleSettingsEditor.presetNames[i], LC.G("NGSettings_ConfirmApply"), LC.G("Yes"), LC.G("No")) == true)) { Preset preset = Activator.CreateInstance(ConsoleSettingsEditor.presetTypes[i]) as Preset; preset.SetSettings(HQ.Settings); EditorUtility.UnloadUnusedAssetsImmediate(); HQ.InvalidateSettings(); InternalNGDebug.Log("Preset \"" + ConsoleSettingsEditor.presetNames[i] + "\" applied on " + HQ.Settings + "."); } } }
public override void StartServer() { if (this.tcpListener != null) { return; } try { #if NETFX_CORE this.tcpListener = new Windows.Networking.Sockets.StreamSocketListener(); this.tcpListener.ConnectionReceived += OnConnection; this.BindEndPointAsync(); #else this.tcpListener = new TcpListener(IPAddress.Any, this.port); this.tcpListener.Start(this.backLog); this.tcpListener.BeginAcceptTcpClient(new AsyncCallback(this.AcceptClient), null); #endif InternalNGDebug.LogFile("Started TCPListener IPAddress.Any:" + this.port); } catch (Exception ex) { InternalNGDebug.LogException(ex); } }
public AutoDetectUDPListener(int portMin, int portMax) { this.callback = new AsyncCallback(this.OnUDPBroadcastPacketReceived); if (this.UDPBroadcastServer != null && this.UDPBroadcastServer.Client.Connected == true) { this.UDPBroadcastServer.Close(); } for (int port = portMin; port <= portMax; port++) { try { this.UDPBroadcastServer = new UdpClient(port); this.UDPBroadcastServer.BeginReceive(this.callback, null); break; } catch (SocketException) { } catch (Exception ex) { InternalNGDebug.LogException(ex); this.UDPBroadcastServer = null; } } Utility.RegisterIntervalCallback(this.CheckNGServersAlive, 200); }
private void AcceptClient(IAsyncResult ar) { // TcpListener is null when the server stops. if (this.tcpListener == null) { return; } try { Client client = new Client(this.tcpListener.EndAcceptTcpClient(ar), Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.OSXEditor) { debugPrefix = "S:" }; this.clients.Add(client); InternalNGDebug.LogFile("Accepted Client " + client.tcpClient.Client.RemoteEndPoint); } catch (Exception ex) { InternalNGDebug.LogFileException(ex); } finally { this.tcpListener.BeginAcceptTcpClient(new AsyncCallback(this.AcceptClient), null); } }
/// <summary> /// Prepares the row by parsing its log. /// </summary> private void ParseLog() { InternalNGDebug.AssertFile(this.isParsed == false, "Parsed Row is being parsed again."); this.isParsed = true; int n = this.log.condition.IndexOf(InternalNGDebug.JSONStartChar); int m = this.log.condition.IndexOf(InternalNGDebug.JSONSeparator); int o = this.log.condition.IndexOf(InternalNGDebug.JSONEndChar); if (n != -1 && m != -1) { this.firstLine = this.log.condition.Substring(n + 1, m - n - 1); } if (m != -1) { if (o != -1) { this.json = this.log.condition.Substring(m + 1, o - m - 1); } else { this.json = this.log.condition.Substring(m + 1); } } else { this.json = string.Empty; } if (string.IsNullOrEmpty(this.firstLine) == true) { this.firstLine = this.json; } }
public static bool Export(IEnumerable <object> instances, Node node, string file) { foreach (object instance in instances) { if (instance is ISettingExportable) { (instance as ISettingExportable).PreExport(); } } try { using (StreamWriter sr = new StreamWriter(file)) using (BinaryWriter sw = new BinaryWriter(sr.BaseStream)) { node.Serialize(sw); } } catch (Exception ex) { InternalNGDebug.LogException(ex); return(false); } return(true); }