private static void CreatePrefab(string filePath) { string path = PathManager.CombinePath(filePath, CreatePrefabs.m_ModeName + ".fbx"); GameObject go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; //关联材质 for (int i = 0; i < go.transform.childCount; i++) { Transform tf = go.transform.GetChild(i); SkinnedMeshRenderer sr = tf.GetComponent <SkinnedMeshRenderer>(); if (null != sr) { string partName = tf.name; string matPath = PathManager.CombinePath(filePath + "Materials/", m_materialList[partName]); sr.material = AssetDatabase.LoadAssetAtPath(matPath, typeof(UnityEngine.Material)) as UnityEngine.Material; } } //创建状态机 AnimatorController ac = AutoCreateControl.CreateControl(filePath); go.GetComponent <Animator>().runtimeAnimatorController = ac; //GlobalDefine.SetLayer(go, GlobalDefine.Layer_character); string foldPath = filePath + "Prefabs/"; if (!Directory.Exists(foldPath)) { Directory.CreateDirectory(foldPath); } string prefabPath = PathManager.CombinePath(foldPath, "model.prefab"); PrefabUtility.CreatePrefab(prefabPath, go); // GameObject.DestroyImmediate(go); }
private static void CreatePrefab(string filePath) { string path = PathManager.CombinePath(filePath, CreatePrefabs.m_ModeName + ".fbx"); GameObject go = AssetDatabase.LoadAssetAtPath(path, typeof(GameObject)) as GameObject; string prefabPath = PathManager.CombinePath(filePath, "model.prefab"); PrefabUtility.CreatePrefab(prefabPath, go); // GameObject.DestroyImmediate(go); }
private void onClick1() { if (avatar != null) { return; } string path = PathManager.CombinePath(PathManager.resoucePath, "model/jianshi.prefab"); AssetManager.LoadAsset(path, loadCom); }
static void CreatePrefabSelect() { TextAsset target = Selection.activeObject as TextAsset; if (null == target) { return; } Debug.Log(target.name); //整体路径 string filePathWithName = AssetDatabase.GetAssetPath(target); //带后缀的文件名 string fileNameWithExtension = Path.GetFileName(filePathWithName); //不带后缀的文件名 string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePathWithName); //不带文件名的路径 string filePath = filePathWithName.Replace(fileNameWithExtension, ""); string foldPath = filePath + fileNameWithoutExtension + "_Action/"; Debug.Log(foldPath); if (!Directory.Exists(foldPath)) { Directory.CreateDirectory(foldPath); } string[] lines = target.text.Split("\n"[0]); for (int i = 0; i < lines.Length; i++) { string strLine = lines[i]; if (strLine != "" && strLine.Contains("import")) { string[] keyValue = strLine.Replace("_import", "").Split(' '); if (keyValue.Length >= 3) { Animation anim = new Animation(); anim.name = keyValue[0]; //anim.firstFrame = int.Parse(keyValue[1]); //anim.lastFrame = int.Parse(keyValue[2]); //anim.loop = true; anim.wrapMode = WrapMode.Loop; string assetPath = PathManager.CombinePath(foldPath, anim.name + ".anim"); Debug.Log(assetPath); AssetDatabase.CreateAsset(anim, assetPath); } } } AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); }
private void onClick3() { Renderer render = avatar.transform.Find("jianshi_skin").Find("jianshi").gameObject.GetComponent <Renderer>(); m_textureIndex++; if (m_textureIndex > 6) { m_textureIndex = 1; } string path = PathManager.CombinePath(PathManager.resoucePath, "model/mTexture/jianshi_0" + m_textureIndex + ".png"); render.sharedMaterial.mainTexture = AssetDatabase.LoadAssetAtPath(path, typeof(Texture2D)) as Texture; Debug.Log(path); }
//创建state (判断动作是否有混合动作 分别加载) public static AnimatorState CreateState(string name, Vector3 pos) { string fbxPath = PathManager.CombinePath(m_parentPath, CreatePrefabs.m_ModeName + "@" + name + ".fbx"); AnimatorState state = null; if (IsBlendTree(name)) { AnimationClip a1c = GetAnimationClip(fbxPath); if (a1c == null) { Debug.LogError("--------动作丢失---------name=" + (fbxPath)); return(null); } BlendTree bt; //创建混合树(名字为name) state = m_curAnimCtrl.CreateBlendTreeInController(name, out bt); bt.hideFlags = HideFlags.HideInHierarchy; string[] btMotion = { "_up", "_rightup", "_right", "_rightdown" }; for (int i = 0; i < btMotion.Length; i++) { string blendFbxPath = PathManager.CombinePath(m_parentPath, CreatePrefabs.m_ModeName + "@" + name + btMotion[i] + ".fbx"); a1c = GetAnimationClip(blendFbxPath); bt.AddChild(a1c); } bt.useAutomaticThresholds = true; bt.blendParameter = "rotation"; bt.name = "Blend Tree"; state.motion = bt; } else { AnimationClip anim = GetAnimationClip(fbxPath); if (anim == null) { Debug.LogError("--------动作丢失---------name=" + (fbxPath)); return(null); } state = m_stateMachine.AddState(name, pos); state.motion = anim; } m_allState[name] = state; return(state); }
public static AnimatorController CreateControl(string filePath) { m_parentPath = filePath; string foldPath = filePath + "Control/"; if (!Directory.Exists(foldPath)) { Directory.CreateDirectory(foldPath); } string ctrlPath = PathManager.CombinePath(foldPath, "animation.controller"); AnimatorController ac = AnimatorController.CreateAnimatorControllerAtPath(ctrlPath); m_curAnimCtrl = ac; AddParam(ac); var animLayer = ac.layers[0]; m_stateMachine = animLayer.stateMachine; CreateAllState(); CreateAllRelation(); return(ac); }