/// <summary> /// 讀取資料夾結構內的設定值 /// </summary> /// <param name="textTreeNodeObject">要讀取的OCIFolder.treeNodeObject</param> /// <param name="config">要讀取的項目</param> /// <returns></returns> public static string GetConfig(TreeNodeObject textTreeNodeObject, Config config) { if (null == textTreeNodeObject) { textTreeNodeObject = (from v in Singleton <GuideObjectManager> .Instance.selectObjectKey select Studio.Studio.GetCtrlInfo(v) as OCIFolder into v where v != null select v.treeNodeObject).FirstOrDefault(); } OCIFolder textOCIFolder = Studio.Studio.GetCtrlInfo(textTreeNodeObject) as OCIFolder; TextMesh t = textOCIFolder.objectItem.GetComponentInChildren <TextMesh>(true); MeshRenderer m = textOCIFolder.objectItem.GetComponentInChildren <MeshRenderer>(true); TreeNodeObject GetChildNode(string prefix, TreeNodeObject nRoot) { return(nRoot?.child?.Where((x) => Studio.Studio.GetCtrlInfo(x).objectInfo.kind == 3 && (Studio.Studio.GetCtrlInfo(x) is OCIFolder y) && y.name.Contains(prefix) ).FirstOrDefault()); } TreeNodeObject nConfig = GetChildNode(Patches.TextConfigPrefix, textTreeNodeObject); string GetValue(string prefix) { if (Studio.Studio.GetCtrlInfo(GetChildNode(prefix, nConfig)) is OCIFolder f) { return(f.name.Replace(prefix, "")); } else { return(null); } } switch (config) { case Config.Font: return(GetValue(Patches.TextConfigFontPrefix)); case Config.FontSize: return(GetValue(Patches.TextConfigFontSizePrefix)); case Config.FontStyle: return(GetValue(Patches.TextConfigFontStylePrefix)); case Config.Color: return(GetValue(Patches.TextConfigColorPrefix)); case Config.Anchor: return(GetValue(Patches.TextConfigAnchorPrefix)); case Config.Align: return(GetValue(Patches.TextConfigAlignPrefix)); default: return(null); } }
/// <summary> /// 在給定的OCIFolder GameObject下添加TextMesh /// </summary> /// <param name="folder">要添加TextMesh的OCIFolder</param> /// <param name="text">預設文字</param> /// <returns>新建立的TextMesh</returns> public static TextMesh MakeTextObj(OCIFolder folder, string text) { Patches.DrawConfigPanel(); folder.objectItem.layer = 10; GameObject go = new GameObject(); go.transform.SetParent(folder.objectItem.transform); go.layer = 10; go.transform.localPosition = Vector3.zero; TextMesh t = go.AddComponent <TextMesh>(); t.fontSize = 500; t.text = text; t.transform.localScale = Vector3.one; t.name = "TextObj"; t.gameObject.SetActive(true); go.transform.localRotation = Quaternion.Euler(0f, 180f, 0f); SetColor(folder, KK_StudioTextPlugin.Default_Color.Value); SetFont(folder, KK_StudioTextPlugin.Default_FontName.Value); SetCharacterSize(folder, KK_StudioTextPlugin.Default_FontSize.Value); SetFontStyle(folder, KK_StudioTextPlugin.Default_FontStyle.Value); SetAlignment(folder, KK_StudioTextPlugin.Default_Alignment.Value); SetAnchor(folder, KK_StudioTextPlugin.Default_Anchor.Value); Logger.LogDebug("Create Text"); return(t); }
/// <summary> /// Create a new folder and add a collider to it /// </summary> public void CreateMaskingFolder() { TreeNodeObject selectedNode = null; if (StudioCustomMasking.AddNewMaskToSelected.Value) { selectedNode = GetNonMaskingTreeNodeObject(); } OCIFolder ociFolder = AddObjectFolder.Add(); Singleton <UndoRedoManager> .Instance.Clear(); AddColliderToFolder(ociFolder); if (selectedNode != null) { Studio.Studio.Instance.treeNodeCtrl.SetParent(ociFolder.treeNodeObject, selectedNode); selectedNode.SetTreeState(TreeNodeObject.TreeState.Open); var workspaceCtrl = (WorkspaceCtrl)Traverse.Create(Studio.Studio.Instance).Field("m_WorkspaceCtrl").GetValue(); workspaceCtrl.UpdateUI(); } if (Studio.Studio.optionSystem.autoSelect && ociFolder != null) { Studio.Studio.Instance.treeNodeCtrl.SelectSingle(ociFolder.treeNodeObject); } }
/// <summary> /// 設定字型顏色 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="color">字型顏色</param> public static void SetColor(OCIFolder folder, Color color = default) { folder.objectItem.GetComponentInChildren <MeshRenderer>(true).material.color = color; if (KK_StudioTextPlugin.Auto_change_default.Value) { KK_StudioTextPlugin.Default_Color.Value = color; } }
/// <summary> /// 設定字型顏色 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="color">字型顏色</param> public static void SetColor(OCIFolder folder, string color) { if (!ColorUtility.TryParseHtmlString(color, out var c)) { c = default; } SetColor(folder, c); }
/// <summary> /// 設定字體對齊 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="alignment">字體對齊(Left, Right, Center)</param> public static void SetAlignment(OCIFolder folder, TextAlignment alignment = TextAlignment.Center) { folder.objectItem.GetComponentInChildren <TextMesh>(true).alignment = alignment; if (KK_StudioTextPlugin.Auto_change_default.Value) { KK_StudioTextPlugin.Default_Alignment.Value = alignment; } }
/// <summary> /// 設定字體錨點 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="anchor">字體錨點</param> public static void SetAnchor(OCIFolder folder, TextAnchor anchor = TextAnchor.MiddleCenter) { folder.objectItem.GetComponentInChildren <TextMesh>(true).anchor = anchor; if (KK_StudioTextPlugin.Auto_change_default.Value) { KK_StudioTextPlugin.Default_Anchor.Value = anchor; } }
/// <summary> /// 設定字體大小,單位放大五百倍 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="size">字體大小</param> public static void SetCharacterSize(OCIFolder folder, float size = 1f) { folder.objectItem.GetComponentInChildren <TextMesh>(true).characterSize = 0.002f * size; if (KK_StudioTextPlugin.Auto_change_default.Value) { KK_StudioTextPlugin.Default_FontSize.Value = size; } }
/// <summary> /// 設定字體大小,單位放大五百倍 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="size">字體大小</param> public static void SetCharacterSize(OCIFolder folder, string size) { if (!float.TryParse(size, out float f)) { f = 1f; } SetCharacterSize(folder, f); }
/// <summary> /// 設定字體樣式 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="style">字體樣式</param> public static void SetFontStyle(OCIFolder folder, FontStyle style = FontStyle.Normal) { folder.objectItem.GetComponentInChildren <TextMesh>(true).fontStyle = style; if (KK_StudioTextPlugin.Auto_change_default.Value) { KK_StudioTextPlugin.Default_FontStyle.Value = style; } }
public static void AddToTrack(OCIFolder objctrl) { var newid = ResolveID("folder", new Folder(objctrl), AllProps); if (newid != null) { var tagfld = Folder.add(SceneFolders.prop_folder_prefix + newid); tagfld.set_parent_treenodeobject(objctrl.treeNodeObject); } }
public static Folder add(string name) { OCIFolder fold = AddObjectFolder.Add(); Folder obj = new Folder(fold); if (name != null) { obj.name = name; } return(obj); }
/// <summary> /// 設定字體對齊 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="alignment">字體對齊(Left, Right, Center)</param> public static void SetAlignment(OCIFolder folder, string alignment = "Center") { try { if (alignment == "") { alignment = "Center"; } SetAlignment(folder, (TextAlignment)Enum.Parse(typeof(TextAlignment), alignment)); } catch (OverflowException) { Logger.LogError("OverflowException: Please use a correct Alignment (Left, Right, Center)."); Logger.LogError("Fallback to TextAlignment.Center"); SetAlignment(folder, TextAlignment.Center); } }
/// <summary> /// 設定字體錨點 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="anchor">字體錨點</param> public static void SetAnchor(OCIFolder folder, string anchor = "MiddleCenter") { try { if (anchor == "") { anchor = "MiddleCenter"; } SetAnchor(folder, (TextAnchor)Enum.Parse(typeof(TextAnchor), anchor)); } catch (OverflowException) { Logger.LogError("OverflowException: Please use a correct Anchor(Upper/Lower/Middle + Left/Right/Center)."); Logger.LogError("Fallback to TextAnchor.MiddleCenter"); SetAnchor(folder, TextAnchor.MiddleCenter); } }
/// <summary> /// 設定字體樣式 /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="style">字體樣式</param> public static void SetFontStyle(OCIFolder folder, string style = "Normal") { try { if (style == "") { style = "Normal"; } SetFontStyle(folder, (FontStyle)Enum.Parse(typeof(FontStyle), style)); } catch (OverflowException) { Logger.LogError("OverflowException: Please use a correct FontStyle."); Logger.LogError("Fallback to FontStyle.Normal"); SetFontStyle(folder, FontStyle.Normal); } }
/// <summary> /// 設定字型,預設為MS Gothic /// </summary> /// <param name="folder">對象OCIFolder</param> /// <param name="fontName">字型名稱</param> public static void SetFont(OCIFolder folder, string fontName = "MS Gothic") { Color colorBackup = folder.objectItem.GetComponentInChildren <MeshRenderer>(true).material.color; TextMesh textMesh = folder.objectItem.GetComponentInChildren <TextMesh>(true); textMesh.font = GetFont(fontName); textMesh.font.RequestCharactersInTexture(textMesh.text); folder.objectItem.GetComponentInChildren <MeshRenderer>(true).material = Font3DMaterial; folder.objectItem.GetComponentInChildren <MeshRenderer>(true).material.SetTexture("_MainTex", textMesh.font.material.mainTexture); folder.objectItem.GetComponentInChildren <MeshRenderer>(true).material.EnableKeyword("_NORMALMAP"); SetColor(folder, colorBackup); if (KK_StudioTextPlugin.Auto_change_default.Value) { KK_StudioTextPlugin.Default_FontName.Value = fontName; } }
/// <summary> /// Add a collider to the folder. Also registers it in the list of masking folders. /// </summary> /// <param name="ociFolder"></param> private void AddColliderToFolder(OCIFolder ociFolder) { ociFolder.objectItem.name = "FolderCollider"; var collider = ociFolder.objectItem.AddComponent<BoxCollider>(); #if KK || KKS collider.size = new Vector3(1f, 1f, 1f); #elif AI || HS2 collider.size = new Vector3(10f, 10f, 10f); #else this ain't right #endif ociFolder.objectItem.layer = StudioCustomMasking.ColliderLayer; ociFolder.objectItem.transform.parent = ociFolder.objectItem.transform; ociFolder.name = "Mask (hides parent)"; //Enable scale ociFolder.guideObject.enableScale = true; //Set scale inactive ociFolder.guideObject.roots[2].SetActive(false); MaskingFolders[ociFolder.objectInfo.dicKey] = ociFolder; }
/// <summary> /// Add a collider to the folder. Also registers it in the list of masking folders. /// </summary> /// <param name="ociFolder"></param> private void AddColliderToFolder(OCIFolder ociFolder) { ociFolder.objectItem.name = "FolderCollider"; var collider = ociFolder.objectItem.AddComponent <BoxCollider>(); #if KK collider.size = new Vector3(1f, 1f, 1f); #elif AI || HS2 collider.size = new Vector3(10f, 10f, 10f); #endif ociFolder.objectItem.layer = StudioCustomMasking.ColliderLayer; ociFolder.objectItem.transform.parent = ociFolder.objectItem.transform; ociFolder.name = "Mask (hides parent)"; //Enable scale ociFolder.guideObject.enableScale = true; GameObject[] roots = (GameObject[])Traverse.Create(ociFolder.guideObject).Field("roots").GetValue(); //Set scale inactive roots[2].SetActive(false); MaskingFolders[ociFolder.objectInfo.dicKey] = ociFolder; }
public static Folder create_from(OCIFolder objctrl) { return(new Folder(objctrl)); }
public Folder(OCIFolder objctrl) : base(objctrl) { this.objctrl = objctrl; }
/// <summary> /// 創建設定資料夾結構,或是變更設定中的特定項目 /// </summary> /// <param name="textTreeNodeObject">要變更的OCIFolder.treeNodeObject</param> /// <param name="config">要設定的項目</param> public static void MakeAndSetConfigStructure(TreeNodeObject textTreeNodeObject, Config config = Config.All) { Patches.isCreatingTextStructure = true; OCIFolder textOCIFolder = Studio.Studio.GetCtrlInfo(textTreeNodeObject) as OCIFolder; TextMesh t = textOCIFolder.objectItem.GetComponentInChildren <TextMesh>(true); MeshRenderer m = textOCIFolder.objectItem.GetComponentInChildren <MeshRenderer>(true); TreeNodeCtrl treeNodeCtrl = Singleton <Studio.Studio> .Instance.treeNodeCtrl; TreeNodeObject nConfig = doMain(Patches.TextConfigPrefix, "", textTreeNodeObject); if (config == Config.Font || config == Config.All) { doMain(Patches.TextConfigFontPrefix, t.font.name, nConfig); } if (config == Config.FontSize || config == Config.All) { doMain(Patches.TextConfigFontSizePrefix, (t.characterSize * 500).ToString(), nConfig); } if (config == Config.FontStyle || config == Config.All) { doMain(Patches.TextConfigFontStylePrefix, t.fontStyle.ToString(), nConfig); } if (config == Config.Color || config == Config.All) { doMain(Patches.TextConfigColorPrefix, '#' + ColorUtility.ToHtmlStringRGBA(m.material.color), nConfig); } if (config == Config.Anchor || config == Config.All) { doMain(Patches.TextConfigAnchorPrefix, t.anchor.ToString(), nConfig); } if (config == Config.Align || config == Config.All) { doMain(Patches.TextConfigAlignPrefix, t.alignment.ToString(), nConfig); } Patches.isCreatingTextStructure = false; TreeNodeObject doMain(string prefix, string value, TreeNodeObject nRoot) { TreeNodeObject node = nRoot.child?.Where((x) => Studio.Studio.GetCtrlInfo(x).objectInfo.kind == 3 && (Studio.Studio.GetCtrlInfo(x) is OCIFolder y) && y.name.Contains(prefix) ).FirstOrDefault(); OCIFolder folder; if (null == node) { //沒有找到就創建 folder = AddObjectFolder.Add(); treeNodeCtrl.SetParent(folder.treeNodeObject, nRoot); folder.objectInfo.changeAmount.Reset(); node = folder.treeNodeObject; } else { folder = Studio.Studio.GetCtrlInfo(node) as OCIFolder; } folder.name = folder.objectItem.name = prefix + value; return(node); } }