/// <summary> /// Add a new value (or values) to this JsonSchema's enum list. This JsonSchema (with the /// new value(s)) is then returned so that additional changes can be chained together. /// </summary> /// <param name="enumValue"></param> /// <param name="extraEnumValues"></param> /// <returns></returns> public JsonSchema AddEnum(string enumValue, params string[] extraEnumValues) { if (Enum == null) { Enum = new List <string>(); } if (Enum.Contains(enumValue)) { throw new ArgumentException("enumValue (" + enumValue + ") already exists in the list of allowed values.", "enumValue"); } Enum.Add(enumValue); if (extraEnumValues != null && extraEnumValues.Length > 0) { foreach (string extraEnumValue in extraEnumValues) { if (Enum.Contains(extraEnumValue)) { throw new ArgumentException("extraEnumValue (" + extraEnumValue + ") already exists in the list of allowed values.", "extraEnumValues"); } Enum.Add(extraEnumValue); } } return(this); }
public static string ToName(this Enum current) { Type type = current.GetType(); var cache = EnumExtension.nameCache; if (cache.ContainsKey(type) && cache[type].ContainsKey(current)) { return(cache[type][current]); } if (current.ToInt() == -1) { string[] allNames = Enum.GetNames(type); return(string.Join(" ", allNames)); } string name = Enum.GetName(type, current); if (name.IsEmpty() || name.IsNull()) { string[] allNames = Enum.GetNames(type); StringBuilder names = new StringBuilder(); for (int index = 0; index < allNames.Length; ++index) { string currentName = allNames[index]; Enum value = current.ParseEnum(currentName); if (current.Contains(value)) { names.Append(currentName + " "); } } name = names.ToString(); } cache.AddNew(type)[current] = name; return(name); }
public static bool Within(this Enum current, params string[] values) { for (int index = 0; index < values.Length; ++index) { Enum value = current.ParseEnum(values[index]); if (current.Contains(value)) { return(true); } } return(false); }
public static bool Has(this Enum current, Enum mask) { return(current.Contains(mask)); }
public Texture2D CreateLevelScreenshot() { // Hide unused links and show gendoors foreach (var e in Objects) { // Update the event to make sure it has rendered e.ForceUpdate(); if (e.ObjData is Unity_Object_R1 r1Obj) { Enum[] exceptions = new Enum[] { R1_EventType.TYPE_GENERATING_DOOR, R1_EventType.TYPE_DESTROYING_DOOR, R1_EventType.MS_scintillement, R1_EventType.MS_super_gendoor, R1_EventType.MS_super_kildoor, R1_EventType.MS_compteur, R1_EventType.TYPE_RAY_POS, R1_EventType.TYPE_INDICATOR, }; if (exceptions.Contains(r1Obj.EventData.Type)) { e.gameObject.SetActive(true); } } else if (e.ObjData is Unity_Object_GBA gbaObj) { if (gbaObj.Actor.ActorID == 0) { e.gameObject.SetActive(true); } } // Always hide events with no graphics if (e.defautRenderer.enabled) { e.gameObject.SetActive(false); } // TODO: Change this option // Helper method bool showLinksForObj(Unity_ObjBehaviour ee) { if (ee.ObjData is Unity_Object_R1 r1Object) { return(r1Object.EventData.Type == R1_EventType.TYPE_GENERATING_DOOR || r1Object.EventData.Type == R1_EventType.TYPE_DESTROYING_DOOR || r1Object.EventData.Type == R1_EventType.MS_scintillement || r1Object.EventData.Type == R1_EventType.MS_super_gendoor || r1Object.EventData.Type == R1_EventType.MS_super_kildoor || r1Object.EventData.Type == R1_EventType.MS_compteur); } return(ee.ObjData.EditorLinkGroup != 0); } if (e.ObjData.EditorLinkGroup == 0) { e.lineRend.enabled = false; e.linkCube.gameObject.SetActive(false); } else { // Hide link if not linked to gendoor bool gendoorFound = showLinksForObj(e); var allofSame = new List <Unity_ObjBehaviour> { e }; foreach (Unity_ObjBehaviour f in Objects.Where(f => f.ObjData.EditorLinkGroup == e.ObjData.EditorLinkGroup)) { allofSame.Add(f); if (showLinksForObj(f)) { gendoorFound = true; } } if (!gendoorFound) { foreach (var a in allofSame) { a.lineRend.enabled = false; a.linkCube.gameObject.SetActive(false); } } } } RenderTexture renderTex = new RenderTexture(LevelEditorData.MaxWidth * LevelEditorData.Level.CellSize / 1, LevelEditorData.MaxHeight * LevelEditorData.Level.CellSize / 1, 24); renderCamera.targetTexture = renderTex; var cellSizeInUnits = LevelEditorData.Level.CellSize / (float)LevelEditorData.Level.PixelsPerUnit; renderCamera.transform.position = new Vector3((LevelEditorData.MaxWidth) * cellSizeInUnits / 2f, -(LevelEditorData.MaxHeight) * cellSizeInUnits / 2f, renderCamera.transform.position.z); renderCamera.orthographicSize = (LevelEditorData.MaxHeight * cellSizeInUnits / 2f); renderCamera.rect = new Rect(0, 0, 1, 1); renderCamera.Render(); // Save to picture RenderTexture.active = renderTex; tex = TextureHelpers.CreateTexture2D(renderTex.width, renderTex.height); tex.ReadPixels(new Rect(0, 0, tex.width, tex.height), 0, 0); tex.Apply(); RenderTexture.active = null; renderCamera.rect = new Rect(0, 0, 0, 0); return(tex); }