static void CreateNewBehaviorTree(MenuCommand menuCommand) { // string path = AssetDatabase.GetAssetPath(Selection.activeObject); // if (path == "") // path = "Assets"; // else if (Path.GetExtension(path) != "") // path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), ""); string basePath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/xRes/carbonEvent/").e(); string fullPath = EditorUtility.SaveFilePanel("Save Carbon Event", basePath, "New Behavior Tree", "asset"); if (string.IsNullOrEmpty(fullPath)) { return; } // fullPath = AssetDatabase.GenerateUniqueAssetPath (fullPath); fullPath = fullPath.Substring(fullPath.IndexOf("/Assets/") + 1); BehaviorTree bt = ScriptableObject.CreateInstance <BehaviorTree> (); Root root = ScriptableObject.CreateInstance <Root> (); root.editorPosition = new Vector2(0, 0); bt.SetRoot(root); BTAsset btAsset = ScriptableObject.CreateInstance <BTAsset> (); btAsset.Serialize(bt); AssetDatabase.CreateAsset(btAsset, fullPath); AssetDatabase.Refresh(); EditorUtility.FocusProjectWindow(); Selection.activeObject = btAsset; }
void addVal(string key, string val, bool isForce = false) { if (!string.IsNullOrEmpty(key) && !string.IsNullOrEmpty(val)) { if (dictOrgs.ContainsKey(key) && !isForce) { EditorUtility.DisplayDialog("error", "The key is allready exist!", "Okay"); } else { string fileName = Application.dataPath + "/" + CLPathCfg.self.localizationPath + "Chinese.txt"; fileName = fileName.Replace("/upgradeRes/", "/upgradeRes4Dev/"); if (isForce) { Dictionary <string, string> tempDic = null; byte[] buff = File.ReadAllBytes(fileName); ByteReader reader = new ByteReader(buff); tempDic = reader.ReadDictionary(); tempDic [key] = val; PStr pstr = PStr.b(); foreach (KeyValuePair <string, string> cell in tempDic) { pstr.a(cell.Key).a("=").a(cell.Value.Replace("\n", "\\n")).a("\n"); } File.WriteAllText(fileName, pstr.e()); } else { File.AppendAllText(fileName, "\n" + key + "=" + val); } refreshContent(); } } }
public static void cleanModleMaterials(string modelName) { string matPath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/model/").a(modelName.Replace(".", "/")).a(".FBX").e(); doCleanModelMaterials(matPath); }
void cutVal(string key) { string fileName = Application.dataPath + "/" + CLPathCfg.self.localizationPath + "Chinese.txt"; fileName = fileName.Replace("/upgradeRes/", "/upgradeRes4Dev/"); Dictionary <string, string> tempDic = null; byte[] buff = File.ReadAllBytes(fileName); ByteReader reader = new ByteReader(buff); tempDic = reader.ReadDictionary(); if (!tempDic.ContainsKey(key)) { return; } tempDic.Remove(key); PStr pstr = PStr.b(); foreach (KeyValuePair <string, string> cell in tempDic) { pstr.a(cell.Key).a("=").a(cell.Value.Replace("\n", "\\n")).a("\n"); } File.WriteAllText(fileName, pstr.e()); refreshContent(); }
void init() { if (isFinishInited) { return; } isFinishInited = true; instance = target as MyUIPanel; string language = "Chinese"; if (!Localization.language.Equals(language)) { byte[] buff = null; string languageFile = PStr.b( CLPathCfg.self.localizationPath, language, ".txt").e(); #if UNITY_EDITOR if (CLCfgBase.self.isEditMode) { languageFile = PStr.b().a(CLPathCfg.persistentDataPath).a("/").a(languageFile).e(); languageFile = languageFile.Replace("/upgradeRes/", "/upgradeRes4Dev/"); buff = File.ReadAllBytes(languageFile); } else { buff = FileEx.readNewAllBytes(languageFile); } #else buff = FileEx.readNewAllBytes(languageFile); #endif Localization.Load(language, buff); } title = Localization.Get(instance.titleKeyName); }
public string _checkValid() { string v = value.ToString(); if (!canNull && string.IsNullOrEmpty(v)) { return(PStr.b().a(name).a("不能为空\n").e()); } if (minLen > 0 && v.Length < minLen) { return(PStr.b().a(name).a("长度至少有").a(minLen).a("位\n").e()); } if (maxLen > 0 && v.Length > maxLen) { return(PStr.b().a(name).a("长度最长").a(maxLen).a("位\n").e()); } if (checkIDCard) { string str = CLUIFormUtl.IdentityCodeValid(v); if (!string.IsNullOrEmpty(str)) { return(str); } } return(""); }
public static void setModelProp(string modelName, bool isReadable, ModelImporterNormals modelNormals, ModelImporterTangents modelTangents) { string matPath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/model/").a(modelName.Replace(".", "/")).a(".FBX").e(); ModelImporter mi = ModelImporter.GetAtPath(matPath) as ModelImporter; setModelProp(mi, isReadable, modelNormals, modelTangents); doCleanModelMaterials(matPath); }
/// <summary> /// Gets the object by path. /// </summary> /// <returns>The object by path.</returns> /// <param name="path">Path.</param> public static Object getObjectByPath(string path) { string tmpPath = path; if (!tmpPath.StartsWith("Assets/")) { tmpPath = PStr.b().a("Assets/").a(tmpPath).e(); } return(AssetDatabase.LoadAssetAtPath( tmpPath, typeof(UnityEngine.Object))); }
public bool putDir(string localDir, string remoteDir, Callback onProgressCallback, Callback onFinishCallback) { bool ret = false; if (!Directory.Exists(localDir)) { Debug.LogError("There is no directory exist!"); Utl.doCallback(onFinishCallback, false); return(false); } mkdir(remoteDir); string[] files = Directory.GetFiles(localDir); string file = ""; string[] dirs = Directory.GetDirectories(localDir); if (files != null) { int finishCount = 0; for (int i = 0; i < files.Length; i++) { file = files[i]; Debug.Log(file); string remoteFile = Path.Combine(remoteDir, Path.GetFileName(file)); ret = put(file, remoteFile, (Callback)((objs) => { finishCount++; Utl.doCallback(onProgressCallback, (float)finishCount / files.Length); }) ); if (!ret) { Utl.doCallback(onFinishCallback, false); return(false); } } } if (dirs != null) { for (int i = 0; i < dirs.Length; i++) { // Debug.Log (PStr.b ().a (remotePath).a ("/").a (Path.GetFileName (dirs [i])).e ()); ret = putDir(dirs[i], PStr.b().a(remoteDir).a("/").a(Path.GetFileName(dirs[i])).e(), onProgressCallback, null); if (!ret) { Utl.doCallback(onFinishCallback, false); return(false); } } } Utl.doCallback(onFinishCallback, true); return(ret); }
void init() { if (!_isFinishInit || frameObj == null) { _isFinishInit = true; if (!string.IsNullOrEmpty(panel.frameName)) { string tmpPath = PStr.b().a("Assets/").a(CLPathCfg.self.basePath).a("/upgradeRes4Dev/priority/ui/other/").a(panel.frameName).a(".prefab").e(); frameObj = AssetDatabase.LoadMainAssetAtPath(tmpPath); } } }
static string arrayList2Str(ArrayList list) { if (list == null) { return(""); } string str = ""; for (int i = 0; i < list.Count; i++) { str = PStr.b().a(str).a(list[i].ToString()).a("_").e(); } return(str); }
public Object getMaterial(string path) { if (MaterialMap [path] == null) { string matPath = PStr.b().a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/Materials/").a(path.Replace(".", "/")).a(".mat").e(); // Debug.Log (matPath); Object obj = ECLEditorUtl.getObjectByPath(matPath); MaterialMap [path] = obj; return(obj); } else { return((Object)(MaterialMap [path])); } }
string getCodeLua() { PStr p = PStr.b().a("local curve = AnimationCurve ();\n"); if (curve == null) { return(""); } Keyframe kf = new Keyframe(); for (int i = 0; i < curve.length; i++) { kf = curve [i]; p.a("curve:AddKey(Keyframe(").a(kf.time).a(", ").a(kf.value).a(", ").a(kf.inTangent).a(", ").a(kf.outTangent).a("));\n"); } return(p.e()); }
public Mesh getMesh(string path, string meshName) { if (MeshMap [path] == null) { string matPath = PStr.b().a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/model/").a(path.Replace(".", "/")).a(".FBX").e(); Debug.Log(matPath); MeshMap [path] = ECLEditorUtl.getObjectByPath(matPath); } GameObject mi = MeshMap [path] as GameObject; if (mi != null) { MeshFilter[] mfs = mi.GetComponentsInChildren <MeshFilter>(); if (mfs != null && mfs.Length > 0) { for (int i = 0; i < mfs.Length; i++) { if (mfs [i].sharedMesh.name == meshName) { return(mfs[i].sharedMesh); } } } else { SkinnedMeshRenderer[] smrs = mi.GetComponentsInChildren <SkinnedMeshRenderer>(); if (smrs != null) { for (int i = 0; i < smrs.Length; i++) { if (smrs [i].sharedMesh.name == meshName) { return(smrs[i].sharedMesh); } } } } } return(null); }
public string getUpgradePackageMd5(string name) { string p = getUpgradePackagePath(name); p = PStr.b().a(p).a("/").a(CLPathCfg.self.basePath).a("/resVer/").a(CLPathCfg.self.platform).e(); if (Directory.Exists(p)) { string[] files = Directory.GetFiles(p); string fileName = ""; for (int i = 0; i < files.Length; i++) { fileName = Path.GetFileName(files [i]); if (fileName.StartsWith("VerCtl.ver")) { return(Utl.MD5Encrypt(File.ReadAllBytes(files [i]))); } } } return(""); }
public Avatar getAvatar(string path) { if (MeshMap [path] == null) { string matPath = PStr.b().a(CLPathCfg.self.basePath).a("/") .a("upgradeRes4Dev").a("/other/model/").a(path.Replace(".", "/")).a(".FBX").e(); Debug.Log(matPath); MeshMap [path] = ECLEditorUtl.getObjectByPath(matPath); } GameObject mi = MeshMap [path] as GameObject; Animator animator = mi.GetComponent <Animator>(); if (animator == null) { animator = mi.GetComponentInChildren <Animator>(); } if (animator != null) { return(animator.avatar); } return(null); }
public static string checkModleSetting(string path) { string ret = ""; ModelImporter mi = ModelImporter.GetAtPath(path) as ModelImporter; if (mi != null) { if (mi.isReadable) { ret = PStr.b().a(ret).a("can reade write! ").e(); } if (mi.importMaterials) { ret = PStr.b().a(ret).a("import Materials! ").e(); } if (mi.importNormals != ModelImporterNormals.None) { ret = PStr.b().a(ret).a("import Normals! ").e(); } } Debug.LogError(ret); return(ret); }
public static void exportEventCfg(List <Node> nodes) { ArrayList list = new ArrayList(); ArrayList cell = new ArrayList(); Node node = null; PStr pstr = PStr.b(); for (int i = 0; i < nodes.Count; i++) { node = nodes [i]; if (node is Root) { continue; } pstr.a(node.index); pstr.a("\t"); if (node.behaviorTree.rootNode.attr != null) { pstr.a(((MyRoot)(node.behaviorTree.rootNode.attr)).fubenID); } else { pstr.a(0); } pstr.a("\t"); pstr.a(node.condition); pstr.a("\t"); if (node is NodeAction) { if (((NodeAction)node).action != null) { MyAction action = ((NodeAction)node).action as MyAction; pstr.a(action.triggerType); pstr.a("\t"); pstr.a(action.hideSelf.ToString().ToLower()); pstr.a("\t"); pstr.a(action.talkId); pstr.a("\t"); pstr.a(action.npcCfg); pstr.a("\t"); pstr.a(action.boxCfg); pstr.a("\t"); } else { pstr.a(0); pstr.a("\t"); pstr.a("false"); pstr.a("\t"); pstr.a(0); pstr.a("\t"); pstr.a(""); pstr.a("\t"); pstr.a(0); pstr.a("\t"); } } else { pstr.a(0); pstr.a("\t"); pstr.a("false"); pstr.a("\t"); pstr.a(0); pstr.a("\t"); pstr.a(""); pstr.a("\t"); pstr.a(0); pstr.a("\t"); } pstr.a(node.result2); pstr.a("\t"); pstr.a(node.result1); pstr.a("\t"); pstr.a(""); pstr.a("\n"); } Debug.Log(pstr.e()); }
void showSpriteInfor() { if (currSelectSprite == null) { return; } Hashtable d = MapEx.getMap(currSelectSprite, "data"); int times = MapEx.getInt(currSelectSprite, "times"); string name = MapEx.getString(d, "name"); string path = MapEx.getString(d, "path"); int x = MapEx.getInt(d, "x"); int y = MapEx.getInt(d, "y"); int width = MapEx.getInt(d, "width"); int height = MapEx.getInt(d, "height"); int borderLeft = MapEx.getInt(d, "borderLeft"); int borderRight = MapEx.getInt(d, "borderRight"); int borderTop = MapEx.getInt(d, "borderTop"); int borderBottom = MapEx.getInt(d, "borderBottom"); int paddingLeft = MapEx.getInt(d, "paddingLeft"); int paddingRight = MapEx.getInt(d, "paddingRight"); int paddingTop = MapEx.getInt(d, "paddingTop"); int paddingBottom = MapEx.getInt(d, "paddingBottom"); Hashtable atlas = MapEx.getMap(currSelectSprite, "atlas"); string atlasStr = ""; foreach (DictionaryEntry item in atlas) { atlasStr = PStr.b().a(atlasStr).a(",").a(item.Key.ToString()).e(); } Texture tex = ECLEditorUtl.getObjectByPath(path) as Texture; Rect r = Rect.zero; if (tex != null) { float h = 0; float w = position.width - 160; float rate = w / tex.width; if (rate < 1) { h = tex.height * rate; } else { h = tex.height; } h = h > 200 ? h : 200; r = new Rect(0, 0, NumEx.getIntPart(w), NumEx.getIntPart(h)); GUI.DrawTexture(r, tex, ScaleMode.ScaleToFit); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } else { r = new Rect(0, 0, position.width - 160, 100); GUILayout.Space(r.height + r.y); //这句主要目的是为了可以滑动 } GUILayout.Space(10); ECLEditorUtl.BeginContents(); { EditorGUILayout.BeginHorizontal(); { EditorGUILayout.TextField("name", name); EditorGUILayout.IntField("times", times); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("x", x); EditorGUILayout.IntField("y", y); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("width", width); EditorGUILayout.IntField("height", height); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderLeft", borderLeft); EditorGUILayout.IntField("borderRight", borderRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("borderTop", borderTop); EditorGUILayout.IntField("borderBottom", borderBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingLeft", paddingLeft); EditorGUILayout.IntField("paddingRight", paddingRight); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.IntField("paddingTop", paddingTop); EditorGUILayout.IntField("paddingBottom", paddingBottom); } EditorGUILayout.EndHorizontal(); EditorGUILayout.TextField("path", path); EditorGUILayout.TextField("Atlas", atlasStr); } ECLEditorUtl.EndContents(); }
void OnGUI() { GUILayout.Space(5); ECLEditorUtl.BeginContents(); { EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("Sprites Borrow Infor File", ECLEditorUtl.width150)) { string _mSpritesBorrowInforFile = EditorUtility.OpenFilePanel("Select Infor File", Application.dataPath + "/KOK/xRes/spriteBorrow", "json"); if (!mSpritesBorrowInforFile.Equals(_mSpritesBorrowInforFile)) { mSpritesBorrowInforFile = _mSpritesBorrowInforFile; initData(); } } if (GUILayout.Button("Refresh", ECLEditorUtl.width80)) { initData(); } GUILayout.TextField(mSpritesBorrowInforFile); } EditorGUILayout.EndHorizontal(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); { packerSize = (PackerSize)EditorGUILayout.EnumPopup("", packerSize); GUI.color = Color.yellow; if (GUILayout.Button("Packer View")) { isShowParckerView = true; currSelectSprite = null; } GUI.color = Color.white; } EditorGUILayout.EndHorizontal(); } ECLEditorUtl.EndContents(); GUILayout.Space(5); EditorGUILayout.BeginHorizontal(); { EditorGUILayout.BeginVertical(); { bool _isSelectedAll = EditorGUILayout.ToggleLeft("All", isSelectedAll, ECLEditorUtl.width150); if (isSelectedAll != _isSelectedAll) { isSelectedAll = _isSelectedAll; for (int i = 0; i < mSpriteList.Count && i < (int)packerSize; i++) { item = mSpriteList [i] as Hashtable; item ["selected"] = isSelectedAll; } refreshSelectedCount(); } scrollPos = EditorGUILayout.BeginScrollView(scrollPos, ECLEditorUtl.width150); { rect.y = 0; ECLEditorUtl.BeginContents(); { // GUILayout.Space (10); for (int i = 0; i < mSpriteList.Count && i < (int)packerSize; i++) { item = mSpriteList [i] as Hashtable; bool selected = GUI.Toggle(new Rect(5, rect.y, 50, cellSize + 30), MapEx.getBool(item, "selected"), (i + 1).ToString()); if (selected != MapEx.getBool(item, "selected")) { item ["selected"] = selected; refreshSelectedCount(); } showCellSprite(item); } } ECLEditorUtl.EndContents(); } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); //========================================= //========================================= EditorGUILayout.BeginVertical(); { GUILayout.Label(PStr.b().a("Selected: ").a(selectedCount).a("/").a(allSpriteCount).e()); scrollPos2 = EditorGUILayout.BeginScrollView(scrollPos2, GUILayout.Width(position.width - 150)); { ECLEditorUtl.BeginContents(); { if (isShowParckerView) { showPackerView(); } else { showSpriteInfor(); } } ECLEditorUtl.EndContents(); } EditorGUILayout.EndScrollView(); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndHorizontal(); }