protected override void Reset() { Clear(); _vectorGraphics = null; UpdateMaterial(); base.Reset(); }
// Call this function during Start or Awake only once public static RenderTexture RenderSVG(SVGAsset svgAsset, Rect textureSize) { Bounds bounds = svgAsset.bounds; // Initialize renderer.transform.position = camera.transform.forward * (camera.nearClipPlane + svgAsset.bounds.size.z + 1f) - svgAsset.bounds.center; renderer.vectorGraphics = svgAsset; if (bounds.size.x > bounds.size.y) { camera.orthographicSize = Mathf.Min(bounds.size.x, bounds.size.y) * 0.5f; } else { camera.orthographicSize = Mathf.Max(bounds.size.x, bounds.size.y) * 0.5f; } RenderTexture rt = GetRenderTexture(svgAsset, textureSize); camera.targetTexture = rt; camera.Render(); camera.targetTexture = null; RemoveSVGRenderer(); RemoveCamera(); return rt; }
// Use this for initialization void Start() { animalSVGImage = gameObject.GetComponent(typeof(SVGImage)) as SVGImage; animalOpenEye = animalSVGImage.vectorGraphics; isClosed = false; open = firstBlink; close = 0.2f; timer = open; }
public void Load() { if(svgInput == null || string.IsNullOrEmpty(svgInput.text)) return; if(svgAsset != null) { Destroy(svgAsset); } svgAsset = SVGAsset.Load(svgInput.text); preview.vectorGraphics = svgAsset; }
public static void Postfix(WeaponCategoryValue __instance, ref SVGAsset __result) { if (DataManager_PrewarmComplete.dataManager == null) { return; } SVGAsset result = DataManager_PrewarmComplete.dataManager.GetObjectOfType <SVGAsset>(__instance.Icon, BattleTechResourceType.SVGAsset); if (result != null) { __result = result; } }
public void Load() { if (svgInput == null || string.IsNullOrEmpty(svgInput.text)) { return; } if (svgAsset != null) { Destroy(svgAsset); } svgAsset = SVGAsset.Load(svgInput.text); //preview.vectorGraphics = svgAsset; }
void Start() { svgAssetsMap = new Dictionary <string, SVGAsset>(); for (int i = 0; i < svgAssets.Length; i++) { SVGAsset currentAsset = svgAssets[i]; svgAssetsMap.Add(currentAsset.name, currentAsset); } foreach (KeyValuePair <string, SVGAsset> kvp in svgAssetsMap) { //textBox3.Text += ("Key = {0}, Value = {1}", kvp.Key, kvp.Value); Debug.Log(string.Format("Key = {0}, Value = {1}", kvp.Key, kvp.Value)); } }
protected static RenderTexture GetRenderTexture(SVGAsset svgAsset, Rect textureSize) { float aspect = 1f; if (svgAsset != null) aspect = svgAsset.bounds.size.x / svgAsset.bounds.size.y; int _previewResolution = Mathf.CeilToInt(textureSize.width); RenderTexture rt = new RenderTexture(_previewResolution, Mathf.CeilToInt(_previewResolution / aspect), 24, RenderTextureFormat.Default, RenderTextureReadWrite.Default); rt.antiAliasing = 8; rt.Create(); return rt; }
public static bool Prefix(ResourceLoadRequest <SVGAsset> __instance) { //RLog.M.TWL(0, "SVGAssetLoadRequest.Load "+__instance.ManifestEntry.Name); //return true; ResourceLoadRequest_Load(__instance);//base.Load(); if (__instance.State != DataManager.FileLoadRequest.RequestState.Requested) { return(false); } __instance.State(DataManager.FileLoadRequest.RequestState.Processing); __instance.StartTimeoutTracking(0.0f); if (__instance.ManifestEntry.IsAssetBundled) { __instance.dataManager().AssetBundleManager().RequestAsset <SVGAsset>(BattleTechResourceType.SVGAsset, __instance.ResourceId, new Action <SVGAsset>( (SVGAsset resource) => { SVGAssetLoadRequest.GetMethod("AssetLoaded", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[] { resource }); } )); } else { if (!__instance.ManifestEntry.IsResourcesAsset) { try { SVGAsset resource = SVGAsset.Load(File.ReadAllText(__instance.ManifestEntry.FilePath)); if (resource == null) { throw new NullReferenceException("Fail to load SVG file"); } SVGAssetLoadRequest.GetMethod("AssetLoaded", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[] { resource }); RLog.M.WL(1, "Loaded from external file:" + __instance.ManifestEntry.FilePath); }catch (Exception e) { RLog.M.TWL(0, "Fail to load external file:" + __instance.ManifestEntry.FilePath); RLog.M.WL(0, e.ToString()); throw new ArgumentNullException("THIS IS !NOT! I REPEAT, !NOT! MODTEK ERROR. YOUR SVG FILE FAIL TO LOAD! More info in ModTek_runtime_log.txt"); } return(false); } __instance.dataManager().RequestResourcesLoad_SVGAsset(__instance.ManifestEntry.ResourcesLoadPath, new Action <SVGAsset>( (SVGAsset resource) => { SVGAssetLoadRequest.GetMethod("AssetLoaded", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, new object[] { resource }); } )); } return(false); }
public void Load() { // if(svgInput == null || string.IsNullOrEmpty(svgInput.text)) return; // if(svgAsset != null) // { // Destroy(svgAsset[0]); // } svgAsset = new List <SVGAsset>(); StartCoroutine(SVGAsset.Load(TxtFile.text, svgAsset, null, 100)); Debug.Log("load svg asset count: " + svgAsset.Count); for (int i = 1; i < svgAsset.Count; i++) { SVGImage newSVGImage = Instantiate(preview, preview.transform.position, preview.transform.rotation, preview.transform.parent); newSVGImage.vectorGraphics = svgAsset[i]; } preview.vectorGraphics = svgAsset[0]; }
public static void Postfix(SimGameState __instance, Pilot p, ref SVGAsset __result, Pilot ___commander) { try { BattleTech.Data.SVGCache cache = (BattleTech.Data.SVGCache)Traverse.Create(__instance.DataManager).Method("get_SVGCache").GetValue(); if (p.Description.Id == ___commander.Description.Id) { __result = cache.GetAsset("uixSvgIcon_mwrank_Commander"); } if (p.pilotDef.IsVanguard || p.pilotDef.IsRonin) { __result = cache.GetAsset("uixSvgIcon_mwrank_Ronin"); } } catch (Exception e) { Logger.LogError(e); } }
static GameObject CreateMark(GameObject parent, string iconId, string objectId) { Mod.Log.Debug?.Write($"Creating mark for iconId: {iconId}"); try { SVGAsset icon = ModState.Combat.DataManager.GetObjectOfType <SVGAsset>(iconId, BattleTechResourceType.SVGAsset); if (icon == null) { Mod.Log.Warn?.Write($"Icon: {iconId} was not loaded! Check the manifest load"); } GameObject imageGO = new GameObject(); imageGO.name = objectId; imageGO.transform.parent = parent.transform; imageGO.transform.localScale = new Vector3(0.7f, 1f, 1f); SVGImage image = imageGO.AddComponent <SVGImage>(); if (image == null) { Mod.Log.Warn?.Write("Failed to create image for icon, load will fail!"); } image.vectorGraphics = icon; image.color = Color.white; image.enabled = true; LayoutElement le = imageGO.AddComponent <LayoutElement>(); le.preferredHeight = 32f; le.preferredWidth = 32f; RectTransform rectTransform = imageGO.GetComponent <RectTransform>(); rectTransform.sizeDelta = new Vector2(50f, 0f); return(imageGO); } catch (Exception e) { Mod.Log.Error?.Write(e, $"Failed to create mark image: {iconId}"); return(null); } }
public override void OnInspectorGUI() { SVGDebugLayers go = target as SVGDebugLayers; SVGRenderer svgrenderer = go.GetComponent <SVGRenderer>(); if (svgrenderer == null || svgrenderer.vectorGraphics == null) { return; } currentAsset = svgrenderer.vectorGraphics; SVGLayer[] svgLayers = currentAsset.layers; if (svgLayers == null) { return; } for (int i = 0; i < svgLayers.Length; i++) { string layerName = svgLayers[i].name; GUILayout.Label(layerName, SVGGUI.helpBox); Rect lastRect = GUILayoutUtility.GetLastRect(); if (lastRect.Contains(Event.current.mousePosition)) { hilightedLayer = svgLayers[i]; SceneView.RepaintAll(); } if (svgLayers[i].shapes != null) { for (int j = 0; j < svgLayers[i].shapes.Length; j++) { GUILayout.Label(" "+ layerName + " " + svgLayers[i].shapes[j].type.ToString(), SVGGUI.helpBox); lastRect = GUILayoutUtility.GetLastRect(); if (lastRect.Contains(Event.current.mousePosition)) { hilightedShape = svgLayers[i].shapes[j]; SceneView.RepaintAll(); } } } } }
internal static void LoadIcons(Dictionary <string, VersionManifestEntry> icons_ressourses) { Control.LogDebug(DType.Icons, $"Get data:"); foreach (var pair in icons_ressourses) { Control.LogDebug(DType.Icons, $"- {pair.Key}: {pair.Value.FileName} {pair.Value.FilePath} {pair.Value.Name}"); try { using (var reader = new StreamReader(pair.Value.FilePath)) { var txt = reader.ReadToEnd(); var icon = SVGAsset.Load(txt); icons["@" + pair.Key] = icon; } } catch (Exception e) { Control.LogError(e); } } }
public static bool GetAsset(string id, ref SVGAsset __result) { try { if (string.IsNullOrEmpty(id) || id[0] != '@') { return(true); } __result = IconController.Get(id); if (__result == null) { Control.LogError($"Custom icon {id} not found!"); } return(false); } catch (Exception e) { Control.LogError(e); } return(true); }
public void spawnPlayer(string id, string name) { Vector2 position = createRandomPosition(minSpawnX, maxSpawnX, minSpawnY, maxSpawnY); // int random = Random.Range(0, 1); Transform player = (Transform)Instantiate(playerPrefab, position, Quaternion.identity); player.GetComponent <PlayerCharacter>().setName(name); string svgName = "skate-guy"; if (Random.Range(0, 2) == 1) { svgName = "skate-girl"; } SVGAsset playerSvg = GameObject.FindObjectOfType <SVGContainer>().getSvg(svgName); player.GetComponent <SVGRenderer>().vectorGraphics = playerSvg; player.GetChild(0).GetComponent <SVGRenderer>().color = GameObject.FindObjectOfType <ColorHelper>().RandomColor(); player.parent = GameObject.FindGameObjectWithTag("Board").transform; playerMap.Add(id, player); }
public void Apply(SVGAsset svgAsset) { this.format = svgAsset.format; this.useGradients = svgAsset.useGradients; this.antialiasing = svgAsset.antialiasing; this.antialiasingWidth = svgAsset.antialiasingWidth; this.meshCompression = svgAsset.meshCompression; this.scale = svgAsset.scale; this.vpm = svgAsset.vpm; this.depthOffset = svgAsset.depthOffset; this.compressDepth = svgAsset.compressDepth; this.customPivotPoint = svgAsset.customPivotPoint; this.pivotPoint = svgAsset.pivotPoint; this.border = svgAsset.border; this.sliceMesh = svgAsset.sliceMesh; this.generateCollider = svgAsset.generateCollider; this.keepSVGFile = svgAsset.keepSVGFile; this.ignoreSVGCanvas = svgAsset.ignoreSVGCanvas; this.optimizeMesh = svgAsset.optimizeMesh; this.generateNormals = svgAsset.generateNormals; this.generateTangents = svgAsset.generateTangents; }
void DebugPoints(SVGShape svgShape, SVGAsset svgAsset) { if (svgShape.vertexCount == 0) { return; } if (Event.current.type == EventType.Repaint) { SVGDebugLayers go = target as SVGDebugLayers; Matrix4x4 handlesMatrix = Handles.matrix; Handles.matrix = go.transform.localToWorldMatrix; Vector3 lastPosition = svgShape.vertices[0]; Vector3 currentPosition; for (int j = 1; j < svgShape.vertexCount; j++) { currentPosition = svgShape.vertices[j]; Handles.DrawLine(lastPosition, currentPosition); lastPosition = currentPosition; } Handles.matrix = handlesMatrix; } }
protected override void Start() { model = piece.gameObject.transform.FindChild("Model").gameObject; faceCameraContainer = piece.gameObject.transform.FindChild("FaceCameraContainer").gameObject; hpBarContainer = faceCameraContainer.transform.FindChild("HpBarContainer").gameObject; hpBar = hpBarContainer.transform.FindChild("hpbar").gameObject; hpBarfill = hpBarContainer.transform.FindChild("HpBarFill").gameObject; hpBarFillRenderer = hpBarfill.GetComponent<MeshRenderer>(); hpBarSvgRenderer = hpBar.GetComponent<SVGRenderer>(); hpBarSvgEnemy = loader.Load<SVGAsset>("UI/hpbar enemy"); hpBarSvg = loader.Load<SVGAsset>("UI/hpbar"); textContainer = hpBarContainer.transform.FindChild("TextContainer").gameObject; attackGO = textContainer.transform.FindChild("Attack").gameObject; healthGO = textContainer.transform.FindChild("Health").gameObject; armorGO = textContainer.transform.FindChild("Armor").gameObject; attackText = attackGO.GetComponent<TextMeshPro>(); healthText = healthGO.GetComponent<TextMeshPro>(); armorText = armorGO.GetComponent<TextMeshPro>(); shield = faceCameraContainer.transform.FindChild("Shield").gameObject; cloak = faceCameraContainer.transform.FindChild("Cloak").gameObject; paralyze = faceCameraContainer.transform.FindChild("Paralyze").gameObject; root = faceCameraContainer.transform.FindChild("Root").gameObject; armorBG = faceCameraContainer.transform.FindChild("Armor").gameObject; eventIconContainer = faceCameraContainer.transform.FindChild("EventIconContainer").gameObject; circleBg = eventIconContainer.transform.FindChild("CircleBg").gameObject; eventIcon = eventIconContainer.transform.FindChild("Event").gameObject; deathIcon = eventIconContainer.transform.FindChild("Death").gameObject; rangeIcon = eventIconContainer.transform.FindChild("Range").gameObject; meshRenderer = model.GetComponentInChildren<MeshRenderer>(); highlight = model.GetComponentInChildren<Highlighter>(); attackText.text = piece.attack.ToString(); healthText.text = piece.health.ToString(); circleBg.SetActive(false); deathIcon.SetActive(false); eventIcon.SetActive(false); rangeIcon.SetActive(false); //rotate to model direction model.gameObject.transform.rotation = Quaternion.Euler(DirectionAngle.angle[piece.direction]); //find top of the mesh and adjust the hpbar to be just above it Vector3[] verts = model.GetComponentInChildren<MeshFilter>().sharedMesh.vertices; Vector3 topVertex = new Vector3(0, float.NegativeInfinity, 0); for (int i = 0; i < verts.Length; i++) { //Vector3 vert = transform.TransformPoint(verts[i]); Vector3 vert = verts[i]; if (vert.y > topVertex.y) { topVertex = vert; } } hpBarContainer.transform.localPosition = hpBarContainer.transform.localPosition.SetY( topVertex.y * 1.5f + 0.9f ); UpdateHpBar(); }
public static void Postfix(CombatHUDStatusPanel __instance) { Mod.Log.Trace?.Write("CHUDSP:SAS - entered."); if (__instance.DisplayedCombatant != null) { Type[] iconMethodParams = new Type[] { typeof(SVGAsset), typeof(Text), typeof(Text), typeof(Vector3), typeof(bool) }; Traverse showDebuffIconMethod = Traverse.Create(__instance).Method("ShowDebuff", iconMethodParams); Traverse showBuffIconMethod = Traverse.Create(__instance).Method("ShowBuff", iconMethodParams); AbstractActor actor = __instance.DisplayedCombatant as AbstractActor; EWState actorState = new EWState(actor); DataManager dm = __instance.DisplayedCombatant.Combat.DataManager; bool isPlayer = actor.team == actor.Combat.LocalPlayerTeam; if (isPlayer) { SVGAsset icon = dm.GetObjectOfType <SVGAsset>(Mod.Config.Icons.VisionAndSensors, BattleTechResourceType.SVGAsset); Text title = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TITLE_VISION_AND_SENSORS]); showBuffIconMethod.GetValue(new object[] { icon, title, new Text(BuildToolTip(actor)), __instance.effectIconScale, false }); // Disable the sensors if (actor.Combat.TurnDirector.CurrentRound == 1) { SVGAsset sensorsDisabledIcon = dm.GetObjectOfType <SVGAsset>(Mod.Config.Icons.SensorsDisabled, BattleTechResourceType.SVGAsset); Text sensorsDisabledTitle = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TITLE_SENSORS_DISABLED]); Text sensorsDisabledText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_SENSORS_DISABLED]); showDebuffIconMethod.GetValue(new object[] { sensorsDisabledIcon, sensorsDisabledTitle, sensorsDisabledText, __instance.effectIconScale, false }); } } if (actorState.GetRawECMShield() != 0 || actorState.GetRawECMJammed() != 0 || actorState.ProbeCarrierMod() != 0 || actorState.PingedByProbeMod() != 0 || actorState.GetRawStealth() != null || actorState.GetRawMimetic() != null || actorState.GetRawNarcEffect() != null || actorState.GetRawTagEffect() != null) { // Build out the detailed string StringBuilder sb = new StringBuilder(); if (actorState.GetRawECMShield() != 0) { // A positive is good, a negative is bad string color = actorState.GetRawECMShield() >= 0 ? "00FF00" : "FF0000"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_ECM_SHIELD], new object[] { color, actorState.GetRawECMShield() } ).ToString(); sb.Append(localText); } if (actorState.GetRawECMJammed() != 0) { // A positive (after normalization) is good, a negative is bad string color = -1 * actorState.GetRawECMJammed() >= 0 ? "00FF00" : "FF0000"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_ECM_JAMMING], new object[] { color, -1 * actorState.GetRawECMJammed() } ).ToString(); sb.Append(localText); } if (actorState.ProbeCarrierMod() != 0) { // A positive is good, a negative is bad string color = actorState.ProbeCarrierMod() >= 0 ? "00FF00" : "FF0000"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_PROBE_CARRIER], new object[] { color, -1 * actorState.ProbeCarrierMod() } ).ToString(); sb.Append(localText); } // Armor if (actorState.GetRawStealth() != null) { string color = "00FF00"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_STEALTH], new object[] { color, actorState.GetRawStealth().MediumRangeAttackMod, actorState.GetRawStealth().LongRangeAttackMod, actorState.GetRawStealth().ExtremeRangeAttackMod, } ).ToString(); sb.Append(localText); } if (actorState.GetRawMimetic() != null) { // A positive is good (harder to hit), should be no negative? string color = "00FF00"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_MIMETIC], new object[] { color, actorState.CurrentMimeticPips() } ).ToString(); sb.Append(localText); } // Transient effects if (actorState.PingedByProbeMod() != 0) { // A positive (after normalization) is good, a negative is bad string color = -1 * actorState.PingedByProbeMod() >= 0 ? "00FF00" : "FF0000"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_PROBE_EFFECT], new object[] { color, -1 * actorState.PingedByProbeMod() } ).ToString(); sb.Append(localText); } if (actorState.GetRawNarcEffect() != null) { // A positive (after normalization) is good, a negative is bad string color = -1 * actorState.GetRawNarcEffect().AttackMod >= 0 ? "00FF00" : "FF0000"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_NARC_EFFECT], new object[] { color, -1 * actorState.GetRawNarcEffect().AttackMod } ).ToString(); sb.Append(localText); } if (actorState.GetRawTagEffect() != null) { // A positive (after normalization) is good, a negative is bad string color = -1 * actorState.GetRawTagEffect().AttackMod >= 0 ? "00FF00" : "FF0000"; string localText = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TEXT_EW_TAG_EFFECT], new object[] { color, -1 * actorState.GetRawTagEffect().AttackMod } ).ToString(); sb.Append(localText); } SVGAsset icon = dm.GetObjectOfType <SVGAsset>(Mod.Config.Icons.ElectronicWarfare, BattleTechResourceType.SVGAsset); Text title = new Text(Mod.LocalizedText.Tooltips[ModText.LT_TT_TITLE_EW]); showBuffIconMethod.GetValue(new object[] { icon, title, new Text(sb.ToString()), __instance.effectIconScale, false }); } } }
static void ReimportSVGAsset(SVGAsset svgAsset, string asset) { MethodInfo _editor_ApplyChanges = typeof(SVGAsset).GetMethod("_editor_ApplyChanges", BindingFlags.NonPublic | BindingFlags.Instance); _editor_ApplyChanges.Invoke(svgAsset, new object[]{true}); }
protected static void InitDefaultValues(SVGAsset asset) { FieldInfo _editor_format = typeof(SVGAsset).GetField("_format", BindingFlags.NonPublic | BindingFlags.Instance); _editor_format.SetValue(asset, SVGImporterEditor.settings.defaultSVGFormat); FieldInfo _editor_useGradients = typeof(SVGAsset).GetField("_useGradients", BindingFlags.NonPublic | BindingFlags.Instance); _editor_useGradients.SetValue(asset, SVGImporterEditor.settings.defaultUseGradients); FieldInfo _editor_antialiasing = typeof(SVGAsset).GetField("_antialiasing", BindingFlags.NonPublic | BindingFlags.Instance); _editor_antialiasing.SetValue(asset, SVGImporterEditor.settings.defaultAntialiasing); FieldInfo _editor_antialiasingWidth = typeof(SVGAsset).GetField("_antialiasingWidth", BindingFlags.NonPublic | BindingFlags.Instance); _editor_antialiasingWidth.SetValue(asset, SVGImporterEditor.settings.defaultAntialiasingWidth); FieldInfo _editor_meshCompression = typeof(SVGAsset).GetField("_meshCompression", BindingFlags.NonPublic | BindingFlags.Instance); _editor_meshCompression.SetValue(asset, SVGImporterEditor.settings.defaultMeshCompression); FieldInfo _editor_vpm = typeof(SVGAsset).GetField("_vpm", BindingFlags.NonPublic | BindingFlags.Instance); _editor_vpm.SetValue(asset, SVGImporterEditor.settings.defaultVerticesPerMeter); FieldInfo _editor_scale = typeof(SVGAsset).GetField("_scale", BindingFlags.NonPublic | BindingFlags.Instance); _editor_scale.SetValue(asset, SVGImporterEditor.settings.defaultScale); FieldInfo _editor_depthOffset = typeof(SVGAsset).GetField("_depthOffset", BindingFlags.NonPublic | BindingFlags.Instance); _editor_depthOffset.SetValue(asset, SVGImporterEditor.settings.defaultScale); FieldInfo _editor_compressDepth = typeof(SVGAsset).GetField("_compressDepth", BindingFlags.NonPublic | BindingFlags.Instance); _editor_compressDepth.SetValue(asset, SVGImporterEditor.settings.defaultCompressDepth); FieldInfo _editor_customPivotPoint = typeof(SVGAsset).GetField("_customPivotPoint", BindingFlags.NonPublic | BindingFlags.Instance); _editor_customPivotPoint.SetValue(asset, SVGImporterEditor.settings.defaultCustomPivotPoint); FieldInfo _editor_pivotPoint = typeof(SVGAsset).GetField("_pivotPoint", BindingFlags.NonPublic | BindingFlags.Instance); _editor_pivotPoint.SetValue(asset, SVGImporterEditor.settings.defaultPivotPoint); FieldInfo _editor_generateCollider = typeof(SVGAsset).GetField("_generateCollider", BindingFlags.NonPublic | BindingFlags.Instance); _editor_generateCollider.SetValue(asset, SVGImporterEditor.settings.defaultGenerateCollider); FieldInfo _editor_keepSVGFile = typeof(SVGAsset).GetField("_keepSVGFile", BindingFlags.NonPublic | BindingFlags.Instance); _editor_keepSVGFile.SetValue(asset, SVGImporterEditor.settings.defaultKeepSVGFile); FieldInfo _editor_ignoreSVGCanvas = typeof(SVGAsset).GetField("_ignoreSVGCanvas", BindingFlags.NonPublic | BindingFlags.Instance); _editor_ignoreSVGCanvas.SetValue(asset, SVGImporterEditor.settings.defaultIgnoreSVGCanvas); FieldInfo _editor_optimizeMesh = typeof(SVGAsset).GetField("_optimizeMesh", BindingFlags.NonPublic | BindingFlags.Instance); _editor_optimizeMesh.SetValue(asset, SVGImporterEditor.settings.defaultOptimizeMesh); FieldInfo _editor_generateNormals = typeof(SVGAsset).GetField("_generateNormals", BindingFlags.NonPublic | BindingFlags.Instance); _editor_generateNormals.SetValue(asset, SVGImporterEditor.settings.defaultGenerateNormals); FieldInfo _editor_generateTangents = typeof(SVGAsset).GetField("_generateTangents", BindingFlags.NonPublic | BindingFlags.Instance); _editor_generateTangents.SetValue(asset, SVGImporterEditor.settings.defaultGenerateTangents); }
protected string GetEditorInfo(SVGAsset asset) { PropertyInfo _editor_Info = typeof(SVGAsset).GetProperty("_editor_Info", BindingFlags.NonPublic | BindingFlags.Instance); return (string)_editor_Info.GetValue(asset, new object[0]); }
protected void SaveMeshFile(SVGAsset meshAsset) { string assetPath = AssetDatabase.GetAssetPath(meshAsset); string lastPath = lastMeshSavePath; if(string.IsNullOrEmpty(lastPath)) { lastPath = assetPath; } else { lastPath += "/"; } string path = EditorUtility.SaveFilePanel("Save Mesh File", Path.GetDirectoryName(lastPath), Path.GetFileNameWithoutExtension(assetPath)+"-mesh", "asset" ); if(!string.IsNullOrEmpty(path)) { System.Uri assetFolderPath = new Uri(Application.dataPath); System.Uri outputPath = new Uri(path); path = assetFolderPath.MakeRelativeUri(outputPath).ToString(); lastSVGRecoveryPath = Path.GetDirectoryName(path); Mesh sharedMesh = meshAsset.sharedMesh; Mesh mesh = new Mesh(); mesh.name = sharedMesh.name; mesh.vertices = (Vector3[])sharedMesh.vertices.Clone(); mesh.triangles = (int[])sharedMesh.triangles.Clone(); if(sharedMesh.uv != null || sharedMesh.uv.Length > 0) mesh.uv = (Vector2[])sharedMesh.uv.Clone(); if(sharedMesh.colors32 != null || sharedMesh.colors32.Length > 0) mesh.colors32 = (Color32[])sharedMesh.colors32.Clone(); AssetDatabase.CreateAsset(mesh, path); EditorUtility.RevealInFinder(path); } }
void GetSVGAsset() { svgAsset = Selection.activeObject as SVGAsset; }
static void Postfix(SGBarracksRosterSlot __instance, Pilot ___pilot, GameObject ___AbilitiesObject, LocalizableText ___callsign, Image ___portrait, SVGImage ___roninIcon, SVGImage ___veteranIcon, LocalizableText ___expertise, HBSTooltip ___ExpertiseTooltip) { if (ModState.SimGameState == null) { return; // Only patch if we're in SimGame } if (___pilot == null) { return; } Mod.Log.Debug?.Write($"POST Calling refresh for pilot: {___pilot.Name}"); CrewDetails details = ModState.GetCrewDetails(___pilot.pilotDef); // Find the common GameObjects we need to manipulate GameObject portraitOverride = GetOrCreateProfileOverride(___portrait); if (details.IsAerospaceCrew || details.IsMechTechCrew || details.IsMedTechCrew || details.IsVehicleCrew) { portraitOverride.SetActive(true); } else { portraitOverride.SetActive(false); } GameObject crewBlock = GetOrCreateCrewBlock(___portrait.gameObject); if (details.IsAerospaceCrew || details.IsMechTechCrew || details.IsMedTechCrew) { crewBlock.SetActive(true); } else { crewBlock.SetActive(false); } GameObject mwStats = ___portrait.transform.parent.parent.gameObject.FindFirstChildNamed(ModConsts.GO_HBS_Profile_Stats_Block); if (details.IsAerospaceCrew || details.IsMechTechCrew || details.IsMedTechCrew) { mwStats.SetActive(false); } else { mwStats.SetActive(true); } GameObject layoutTitleGO = __instance.GameObject.FindFirstChildNamed(ModConsts.GO_HBS_Profile_Layout_Title); Image layoutTitleImg = layoutTitleGO.GetComponent <Image>(); if (details.IsAerospaceCrew) { Mod.Log.Debug?.Write($" -- pilot is Aerospace crew"); layoutTitleImg.color = Mod.Config.Crew.AerospaceColor; ___portrait.gameObject.SetActive(false); ___AbilitiesObject.SetActive(false); ___roninIcon.gameObject.SetActive(false); ___veteranIcon.gameObject.SetActive(false); // Set the portrait icon SVGAsset icon = ModState.SimGameState.DataManager.GetObjectOfType <SVGAsset>(Mod.Config.Icons.CrewPortrait_Aerospace, BattleTechResourceType.SVGAsset); if (icon == null) { Mod.Log.Warn?.Write($"ERROR READING ICON: {Mod.Config.Icons.CrewPortrait_Aerospace}"); } SVGImage image = portraitOverride.GetComponentInChildren <SVGImage>(); image.vectorGraphics = icon; // Set the crew size LocalizableText[] texts = crewBlock.GetComponentsInChildren <LocalizableText>(); LocalizableText lt1 = texts[0]; string sizeText = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Size], new object[] { details.SizeLabel, details.Size }).ToString(); lt1.SetText(sizeText); // Force the font size here, otherwise the right hand panel isn't correct lt1.fontSize = 16f; lt1.fontSizeMin = 16f; lt1.fontSizeMax = 16f; LocalizableText lt2 = texts[1]; string skillText = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Skill_Aerospace_Points], new object[] { details.Value }).ToString(); lt2.SetText(skillText); // Force the font size here, otherwise the right hand panel isn't correct lt2.fontSize = 16f; lt2.fontSizeMin = 16f; lt2.fontSizeMax = 16f; // Set the expertise of the crew ___expertise.color = Color.white; ___expertise.SetText(details.ExpertiseLabel); } else if (details.IsMechTechCrew) { Mod.Log.Debug?.Write($" -- pilot is Mechtech crew"); layoutTitleImg.color = Mod.Config.Crew.MechTechCrewColor; ___portrait.gameObject.SetActive(false); ___AbilitiesObject.SetActive(false); ___roninIcon.gameObject.SetActive(false); ___veteranIcon.gameObject.SetActive(false); // Set the portrait icon SVGAsset icon = ModState.SimGameState.DataManager.GetObjectOfType <SVGAsset>(Mod.Config.Icons.CrewPortrait_MechTech, BattleTechResourceType.SVGAsset); if (icon == null) { Mod.Log.Warn?.Write($"ERROR READING ICON: {Mod.Config.Icons.CrewPortrait_MechTech}"); } SVGImage image = portraitOverride.GetComponentInChildren <SVGImage>(); image.vectorGraphics = icon; // Set the crew size LocalizableText[] texts = crewBlock.GetComponentsInChildren <LocalizableText>(); LocalizableText lt1 = texts[0]; string sizeText = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Size], new object[] { details.SizeLabel, details.Size }).ToString(); lt1.SetText(sizeText); // Force the font size here, otherwise the right hand panel isn't correct lt1.fontSize = 16f; lt1.fontSizeMin = 16f; lt1.fontSizeMax = 16f; LocalizableText lt2 = texts[1]; string skillText = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Skill_MechTech_Points], new object[] { details.Value }).ToString(); lt2.SetText(skillText); // Force the font size here, otherwise the right hand panel isn't correct lt2.fontSize = 16f; lt2.fontSizeMin = 16f; lt2.fontSizeMax = 16f; // Set the expertise of the crew ___expertise.color = Color.white; ___expertise.SetText(details.ExpertiseLabel); } else if (details.IsMedTechCrew) { Mod.Log.Debug?.Write($" -- pilot is Medtech crew"); layoutTitleImg.color = Mod.Config.Crew.MedTechCrewColor; ___portrait.gameObject.SetActive(false); ___AbilitiesObject.SetActive(false); ___roninIcon.gameObject.SetActive(false); ___veteranIcon.gameObject.SetActive(false); // Set the portrait icon SVGAsset icon = ModState.SimGameState.DataManager.GetObjectOfType <SVGAsset>(Mod.Config.Icons.CrewPortrait_MedTech, BattleTechResourceType.SVGAsset); if (icon == null) { Mod.Log.Warn?.Write($"ERROR READING ICON: {Mod.Config.Icons.CrewPortrait_MedTech}"); } SVGImage image = portraitOverride.GetComponentInChildren <SVGImage>(); image.vectorGraphics = icon; // Set the crew size LocalizableText[] texts = crewBlock.GetComponentsInChildren <LocalizableText>(); LocalizableText lt1 = texts[0]; string sizeText = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Crew_Size], new object[] { details.SizeLabel, details.Size }).ToString(); lt1.SetText(sizeText); // Force the font size here, otherwise the right hand panel isn't correct lt1.fontSize = 16f; lt1.fontSizeMin = 16f; lt1.fontSizeMax = 16f; LocalizableText lt2 = texts[1]; string skillText = new Localize.Text(Mod.LocalizedText.Labels[ModText.LT_Skill_MedTech_Points], new object[] { details.Value }).ToString(); lt2.SetText(skillText); // Force the font size here, otherwise the right hand panel isn't correct lt2.fontSize = 16f; lt2.fontSizeMin = 16f; lt2.fontSizeMax = 16f; // Set the expertise of the crew ___expertise.color = Color.white; ___expertise.SetText(details.ExpertiseLabel); } else if (details.IsVehicleCrew) { Mod.Log.Debug?.Write($" -- pilot is Vehicle crew"); layoutTitleImg.color = Mod.Config.Crew.VehicleCrewColor; ___portrait.gameObject.SetActive(false); ___roninIcon.gameObject.SetActive(false); ___callsign.SetText("VCREW: " + ___pilot.Callsign); // Set the portrait icon SVGAsset icon = ModState.SimGameState.DataManager.GetObjectOfType <SVGAsset>(Mod.Config.Icons.CrewPortrait_Vehicle, BattleTechResourceType.SVGAsset); if (icon == null) { Mod.Log.Warn?.Write($"ERROR READING ICON: {Mod.Config.Icons.CrewPortrait_Vehicle}"); } SVGImage image = portraitOverride.GetComponentInChildren <SVGImage>(); image.vectorGraphics = icon; ___expertise.color = Color.white; } else { Mod.Log.Debug?.Write($" -- pilot is Mechwarrior"); ___portrait.gameObject.SetActive(true); } Mod.Log.Debug?.Write($"LayoutTitleImg color set to: {layoutTitleImg.color}"); }
public static GameObject DropSVGAssetToSceneToCreateGO(SVGAsset asset, Vector3 position) { GameObject go = new GameObject(asset.name); Undo.RegisterCreatedObjectUndo(go, "Create SVG Renderer"); //Vector3 destination = Camera.current.ScreenToWorldPoint(new Vector3(mousePosition.x, scenePosition.height - mousePosition.y, 0f)); //destination.z = 0f; go.transform.position = position; SVGRenderer renderer = go.AddComponent<SVGRenderer>(); renderer.vectorGraphics = asset; if(asset.generateCollider) go.AddComponent<SVGCollider2D>(); Selection.activeGameObject = go; return go; }
void OnEnable() { Instance = this; asset = (SVGAsset)serializedObject.targetObject; anchorPositionContent = new GUIContent[anchorPosition.Length]; for(int i = 0; i < anchorPosition.Length; i++) { anchorPositionContent[i] = new GUIContent(anchorPosition[i]); } if(serializedObject.isEditingMultipleObjects) { assets = new SVGAsset[serializedObject.targetObjects.Length]; for(int i = 0; i < serializedObject.targetObjects.Length; i++) { assets[i] = (SVGAsset)serializedObject.targetObjects[i]; } } filesValid = true; if(serializedObject.isEditingMultipleObjects) { for(int i = 0; i < assets.Length; i++) { if(string.IsNullOrEmpty(assets[i].svgFile)) filesValid = false; } } else { if(string.IsNullOrEmpty(asset.svgFile)) filesValid = false; } format = serializedObject.FindProperty("_format"); useGradients = serializedObject.FindProperty("_useGradients"); antialiasing = serializedObject.FindProperty("_antialiasing"); antialiasingWidth = serializedObject.FindProperty("_antialiasingWidth"); meshCompression = serializedObject.FindProperty("_meshCompression"); scale = serializedObject.FindProperty("_scale"); vpm = serializedObject.FindProperty("_vpm"); depthOffset = serializedObject.FindProperty("_depthOffset"); compressDepth = serializedObject.FindProperty("_compressDepth"); customPivotPoint = serializedObject.FindProperty("_customPivotPoint"); pivotPoint = serializedObject.FindProperty("_pivotPoint"); //border = serializedObject.FindProperty("_border"); generateCollider = serializedObject.FindProperty("_generateCollider"); keepSVGFile = serializedObject.FindProperty("_keepSVGFile"); ignoreSVGCanvas = serializedObject.FindProperty("_ignoreSVGCanvas"); optimizeMesh = serializedObject.FindProperty("_optimizeMesh"); generateNormals = serializedObject.FindProperty("_generateNormals"); generateTangents = serializedObject.FindProperty("_generateTangents"); CreateSnapshot(); unappliedChanges = false; }
public static GameObject DropFramesToSceneToCreateGO(string name, SVGAsset[] frames, Vector3 position) { if (frames.Length > 0) { SVGAsset asset = frames[0]; GameObject gameObject = DropSVGAssetToSceneToCreateGO(asset, position); if (frames.Length > 1) { SVGFrameAnimator svgFrameAnimator = gameObject.AddComponent<SVGFrameAnimator>(); svgFrameAnimator.frames = frames.Clone() as SVGAsset[]; } return gameObject; } return null; }
public SVGAssetSnapshot(SVGAsset svgAsset) { Apply(svgAsset); }
protected void RecoverSVGFile(SVGAsset recoverAsset) { string assetPath = AssetDatabase.GetAssetPath(recoverAsset); string lastPath = lastSVGRecoveryPath; if(string.IsNullOrEmpty(lastPath)) { lastPath = assetPath; } else { lastPath += "/"; } string path = EditorUtility.SaveFilePanel("Recover SVG File", Path.GetDirectoryName(lastPath), Path.GetFileNameWithoutExtension(assetPath), "svg" ); if(!string.IsNullOrEmpty(path)) { lastSVGRecoveryPath = Path.GetDirectoryName(path); File.WriteAllText(path, recoverAsset.svgFile); EditorUtility.RevealInFinder(path); } }
protected virtual void OnVectorGraphicsChanged(SVGAsset svgAsset) { UpdateCollider(); }
protected static Mesh GetMesh(SVGAsset targetObject) { try { PropertyInfo _editor_sharedMesh = typeof(SVGAsset).GetProperty("_editor_sharedMesh", BindingFlags.NonPublic | BindingFlags.Instance); return (Mesh)_editor_sharedMesh.GetValue(targetObject, new object[0]); } catch { return null; } }
public static void CorrectSVGLayers(List <SVGLayer> layers, Rect viewport, SVGAsset asset, out Vector2 offset) { offset = Vector2.zero; if (layers == null) { return; } int layersCount = layers.Count, layersShapesLength = 0, layersShapesVerticesLength = 0; for (int i = 0; i < layersCount; i++) { CorrectSVGLayerShape(layers[i].shapes); } float minX = float.MaxValue; float maxX = float.MinValue; float minY = float.MaxValue; float maxY = float.MinValue; // calculate bounds for (int i = 0; i < layersCount; i++) { if (layers[i].shapes == null) { continue; } layersShapesLength = layers[i].shapes.Length; for (int j = 0; j < layersShapesLength; j++) { Vector2 min = layers[i].shapes[j].bounds.min; Vector2 max = layers[i].shapes[j].bounds.max; if (min.x < minX) { minX = min.x; } if (max.x > maxX) { maxX = max.x; } if (min.y < minY) { minY = min.y; } if (max.y > maxY) { maxY = max.y; } } } Rect bounds = new Rect(minX, minY, maxX - minX, maxY - minY); if (asset.ignoreSVGCanvas) { offset = new Vector2(bounds.min.x + bounds.size.x * asset.pivotPoint.x, (bounds.max.y - bounds.size.y * asset.pivotPoint.y)); } else { offset = new Vector2(viewport.min.x + viewport.size.x * asset.pivotPoint.x, (viewport.max.y - viewport.size.y * asset.pivotPoint.y)); } // update vertices for (int i = 0; i < layersCount; i++) { if (layers[i].shapes == null) { continue; } layersShapesLength = layers[i].shapes.Length; for (int j = 0; j < layersShapesLength; j++) { if (layers[i].shapes[j].vertices == null) { continue; } layersShapesVerticesLength = layers[i].shapes[j].vertices.Length; for (int k = 0; k < layersShapesVerticesLength; k++) { layers[i].shapes[j].vertices[k] -= offset; } layers[i].shapes[j].bounds.center -= offset; if (layers[i].shapes[j].fill != null) { layers[i].shapes[j].fill.transform = layers[i].shapes[j].fill.transform.Translate(offset); } } } }
protected static Material[] GetMaterial(SVGAsset targetObject) { try { PropertyInfo _editor_sharedMaterials = typeof(SVGAsset).GetProperty("_editor_sharedMaterials", BindingFlags.NonPublic | BindingFlags.Instance); return (Material[])_editor_sharedMaterials.GetValue(targetObject, new object[0]); } catch { return null; } }
// Completeley overriding original method public static bool Prefix(CombatHUDMWStatus __instance, Pilot pilot) { try { if (!(pilot.ParentActor is Mech mech)) { return(true); } Logger.Info($"[CombatHUDMWStatus_RefreshPilot_PREFIX] Pilot: {pilot.Callsign}"); Color inspired = LazySingletonBehavior <UIManager> .Instance.UIColorRefs.blue; Color good = LazySingletonBehavior <UIManager> .Instance.UIColorRefs.white; Color medium = LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.StabilityPipsShown.color; Color bad = LazySingletonBehavior <UIManager> .Instance.UIColorRefs.orange; Color critical = LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.FloatiePilotDamage.color; // Utilize the former injuries item as a general state description CombatHUDStatusStackItem pilotStateHeader = __instance.InjuriesItem; int stressLevel = pilot.GetStressLevel(); Localize.Text stressLevelDescriptor = new Localize.Text(Miscellaneous.GetStressLevelString(stressLevel), Array.Empty <object>()); Localize.Text unknownDescriptor = new Localize.Text("UNKNOWN", Array.Empty <object>()); Localize.Text stateDescriptor = pilot.IsIncapacitated || pilot.HasEjected ? unknownDescriptor : stressLevelDescriptor; SVGAsset stateIcon = __instance.InjuriesItem.Icon.vectorGraphics; //SVGAsset stateIcon = LazySingletonBehavior<UIManager>.Instance.UILookAndColorConstants.FloatieIconPilotInjury; Color stateColor = Miscellaneous.GetStressLevelColor(stressLevel); //pilotStateHeader.ShowIcon(stateIcon, stateDescription, stateColor); pilotStateHeader.ShowExistingIcon(stateDescriptor, stateColor); pilotStateHeader.AddTooltipString(new Localize.Text("???WILL THIS BE VISIBLE ANYWHERE AT ALL???", new object[] { }), EffectNature.Buff); __instance.InspiredItem.Free(); /* TRY: Put pilots personal morale (high|low spirits) in InspiredItem? * if (pilot.HasHighMorale) * { * Localize.Text highSpiritsDescriptor = new Localize.Text("HIGH SPIRITS", Array.Empty<object>()); * Color highSpiritsColor = LazySingletonBehavior<UIManager>.Instance.UIColorRefs.blue; * __instance.InspiredItem.ShowExistingIcon(highSpiritsDescriptor, highSpiritsColor); * } * else if (pilot.HasLowMorale) * { * Localize.Text lowSpiritsDescriptor = new Localize.Text("LOW SPIRITS", Array.Empty<object>()); * Color lowSpiritsColor = LazySingletonBehavior<UIManager>.Instance.UIColorRefs.orange; * __instance.InspiredItem.ShowExistingIcon(lowSpiritsDescriptor, lowSpiritsColor); * } */ // Passives // BEWARE: This needs to be cleared everytime as there's a limited number of stackslots available and there are no control mechanisms or safeguards available! __instance.PassivesList.ClearAllStatuses(); // Injuries SVGAsset injuriesIcon = LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.FloatieIconPilotInjury; Localize.Text injuriesText; Color injuriesColor; if (pilot.IsIncapacitated) { injuriesText = new Localize.Text("INCAPACITATED", new object[] { }); injuriesColor = critical; } else { injuriesText = new Localize.Text("INJURIES: {0}/{1}", new object[] { pilot.Injuries, pilot.Health }); float pilotRemainingHealth = pilot.Health - pilot.Injuries; injuriesColor = (pilotRemainingHealth == 1) ? critical : (pilotRemainingHealth == 2) ? bad : (pilotRemainingHealth < pilot.Health) ? medium : good; } __instance.PassivesList.ShowItem(injuriesIcon, injuriesText, new List <Localize.Text>(), new List <Localize.Text>()).Icon.color = injuriesColor; // StressLevel SVGAsset stressLevelIcon = LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.FloatieIconPilotInjury; Localize.Text stressLevelText = new Localize.Text("STRESS: {0}/{1}", new object[] { stressLevel, 4 }); Color stressLevelColor = Miscellaneous.GetStressLevelColor(stressLevel); __instance.PassivesList.ShowItem(stressLevelIcon, stressLevelText, new List <Localize.Text>(), new List <Localize.Text>()).Icon.color = stressLevelColor; // Fortitude (Derived from resists, morale and combat experience) int fortitudeValue = (int)Math.Round(Assess.GetResistanceModifiers(mech, true, false)); SVGAsset fortitudeIcon = LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.MoraleDefendButtonIcon; Localize.Text fortitudeText = new Localize.Text("FORTITUDE: {0}{1}", new object[] { fortitudeValue, "" }); Color fortitudeColor = pilot.HasMoraleInspiredEffect ? inspired : good; __instance.PassivesList.ShowItem(fortitudeIcon, fortitudeText, new List <Localize.Text>(), new List <Localize.Text>()).Icon.color = fortitudeColor; /* High|Low spirits * if (pilot.HasHighMorale) * { * SVGAsset highSpiritsIcon = LazySingletonBehavior<UIManager>.Instance.UILookAndColorConstants.StatusInspiredIcon; * Localize.Text highSpiritsDescriptor = new Localize.Text("HIGH SPIRITS", Array.Empty<object>()); * Color highSpiritsColor = LazySingletonBehavior<UIManager>.Instance.UIColorRefs.blue; * __instance.PassivesList.ShowItem(highSpiritsIcon, highSpiritsDescriptor, new List<Localize.Text>(), new List<Localize.Text>()).Icon.color = highSpiritsColor; * * // REF: This variant doesn't change anything regarding color updates * //CombatHUDStatusStackItem passiveStackItemHighSpirits = __instance.PassivesList.ShowItem(highSpiritsIcon, new Text("DUMMY", Array.Empty<object>()), new List<Localize.Text>(), new List<Localize.Text>()); * //passiveStackItemHighSpirits.ShowExistingIcon(highSpiritsDescriptor, highSpiritsColor); * } * else if (pilot.HasLowMorale) * { * SVGAsset lowSpiritsIcon = LazySingletonBehavior<UIManager>.Instance.UILookAndColorConstants.StatusInspiredIcon; * Localize.Text lowSpiritsDescriptor = new Localize.Text("LOW SPIRITS", Array.Empty<object>()); * Color lowSpiritsColor = LazySingletonBehavior<UIManager>.Instance.UIColorRefs.orange; * __instance.PassivesList.ShowItem(lowSpiritsIcon, lowSpiritsDescriptor, new List<Localize.Text>(), new List<Localize.Text>()).Icon.color = lowSpiritsColor; * } */ // Weapons int functionalWeapons = mech.Weapons.FindAll(w => w.DamageLevel == ComponentDamageLevel.Functional).Count; int penalizedWeapons = mech.Weapons.FindAll(w => w.DamageLevel == ComponentDamageLevel.Penalized).Count; float weaponHealthRatio = (float)(functionalWeapons - penalizedWeapons / 2) / (float)mech.Weapons.Count; int weaponHealthPercent = (int)Math.Round(weaponHealthRatio * 100); SVGAsset weaponHealthIcon = LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.SmallHardpointIcon; Localize.Text weaponHealthText = new Localize.Text("WEAPONS: {0}{1}", new object[] { weaponHealthPercent, "%" }); Color weaponHealthColor = (weaponHealthPercent <= 25) ? critical : (weaponHealthPercent <= 50) ? bad : (weaponHealthPercent <= 75) ? medium : good; __instance.PassivesList.ShowItem(weaponHealthIcon, weaponHealthText, new List <Localize.Text>(), new List <Localize.Text>()).Icon.color = weaponHealthColor; // Mech Health float mechHealthRatio = (mech.SummaryStructureCurrent + mech.SummaryArmorCurrent) / (mech.SummaryStructureMax + mech.SummaryArmorMax); int mechHealthPercent = (int)Math.Round(mechHealthRatio * 100); SVGAsset mechHealthIcon = LazySingletonBehavior <UIManager> .Instance.UILookAndColorConstants.StatusCoverIcon; Localize.Text mechHealthDescriptor = new Localize.Text("MECH: {0}{1}", new object[] { mechHealthPercent, "%" }); Color mechHealthColor = (mechHealthPercent <= 25) ? critical : (mechHealthPercent <= 55) ? bad : (mechHealthPercent <= 85) ? medium : good; __instance.PassivesList.ShowItem(mechHealthIcon, mechHealthDescriptor, new List <Localize.Text>(), new List <Localize.Text>()).Icon.color = mechHealthColor; // Skipping original method return(false); } catch (Exception e) { Logger.Error(e); return(true); } }
public static void DoRenderPreview(SVGAsset targetObject, PreviewRenderUtility previewUtility) { if(targetObject == null) return; Mesh tempMesh = GetMesh(targetObject); if(tempMesh == null) return; Material[] sharedMaterials = GetMaterial(targetObject); if(tempMesh == null || sharedMaterials == null || sharedMaterials.Length == 0) return; RenderMeshPreviewSkipCameraAndLighting(tempMesh, previewUtility, sharedMaterials); }
public static void UpdateInstances(SerializedObject serializedObject) { if(serializedObject == null) return; if(serializedObject.targetObjects != null && serializedObject.targetObjects.Length > 0) { SVGAsset[] svgAssets = new SVGAsset[serializedObject.targetObjects.Length]; for(int i = 0; i < svgAssets.Length; i++) { svgAssets[i] = serializedObject.targetObjects[i] as SVGAsset; } UpdateInstances(svgAssets); } }
protected SVGError[] GetEditorErrors(SVGAsset asset) { PropertyInfo _editor_errors = typeof(SVGAsset).GetProperty("_editor_errors", BindingFlags.NonPublic | BindingFlags.Instance); return (SVGError[])_editor_errors.GetValue(asset, new object[0]); }
public static void UpdateInstances(SVGAsset[] svgAssets) { if(svgAssets == null || svgAssets.Length == 0) return; SVGImage[] svgImages = Resources.FindObjectsOfTypeAll<SVGImage>(); if(svgImages != null && svgImages.Length > 0) { for(int i = 0; i < svgImages.Length; i++) { if(AssetDatabase.Contains(svgImages[i])) continue; for(int j = 0; j < svgAssets.Length; j++) { if(svgAssets[j] == null) continue; if(svgImages[i] == null || svgImages[i].vectorGraphics != svgAssets[j]) continue; typeof(SVGImage).GetMethod("Clear", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(svgImages[i], null); typeof(SVGImage).GetMethod("UpdateMaterial", BindingFlags.NonPublic | BindingFlags.Instance).Invoke(svgImages[i], null); svgImages[i].SetAllDirty(); } } } }
public void AddFrames(SVGAsset[] assets) { Undo.RecordObject(target, "Add Frames"); SVGFrameAnimator frameAnimator = target as SVGFrameAnimator; if(frameAnimator == null) return; if(frameAnimator.frames == null || frameAnimator.frames.Length == 0) { frameAnimator.frames = (SVGAsset[])assets.Clone(); } else { int start = frameAnimator.frames.Length; int end = frameAnimator.frames.Length + assets.Length; System.Array.Resize<SVGAsset>(ref frameAnimator.frames, frameAnimator.frames.Length + assets.Length); for(int i = start; i < end; i++) { frameAnimator.frames[i] = assets[i - start]; } } EditorUtility.SetDirty(target); }