public static T CreateEffect <T>(string path, params object[] args) where T : CActionEffect { T result = null; if (args == null) { result = Activator.CreateInstance(typeof(T)) as T; } else { result = Activator.CreateInstance(typeof(T), args) as T; } result.asset = EditorWww.Create(path); result.OnCreate(); return(result); }
private static void AsyncCreateRole(RoleObject ro, Role config, bool high) { foreach (var equip in ro.Config.Equips) { Equip equipConfig = EditorWww.Create(equip.Equip) as Equip; if (!equipConfig) { Debug.Log("Error, Load Equip Failed: " + equip); } else { AddEquip(ro.gameObject, equipConfig, high, false); } } if (!string.IsNullOrEmpty(config.Mesh)) { if (config.Skin) { config.Skin.sharedMesh = EditorWww.Create(config.Mesh) as Mesh; config.Skin.enabled = true; config.Skin.sharedMaterial.shader = Shader.Find(config.Skin.sharedMaterial.shader.name); } else if (config.Filter) { config.Filter.sharedMesh = EditorWww.Create(config.Mesh) as Mesh; } } if (!string.IsNullOrEmpty(config.MainTex)) { if (config.Skin) { config.Skin.sharedMaterial.mainTexture = EditorWww.Create(config.MainTex) as Texture; } else if (config.Filter) { config.Filter.GetComponent <MeshRenderer>().sharedMaterial.mainTexture = EditorWww.Create(config.MainTex) as Texture; } } if (config.Skin) { config.Skin.enabled = true; } }
private static void AsyncCreateEquip(GameObject root, Equip equip, bool high, bool load = true) { string model = equip.ModelPath; string[] bones = equip.Bones; if (high && !string.IsNullOrEmpty(equip.HighModelPath)) { model = equip.HighModelPath; bones = equip.HighBones; } GameObject modelObject = UnityEngine.Object.Instantiate(EditorWww.Create(model)) as GameObject; Renderer Renderer = modelObject.GetComponentInChildren <Renderer>(); Renderer.enabled = true; Renderer.sharedMaterial.shader = Shader.Find(Renderer.sharedMaterial.shader.name); RoleObject ro = root.GetComponent <RoleObject>(); foreach (EffectConfig effectInfo in equip.Effects) { string path = effectInfo.EffectAssetPath; if (!high && !string.IsNullOrEmpty(effectInfo.LowEffectAssetPath)) { path = effectInfo.LowEffectAssetPath; } if (string.IsNullOrEmpty(path)) { continue; } GameObject effect = UnityEngine.Object.Instantiate(EditorWww.Create(effectInfo.EffectAssetPath)) as GameObject; if (effect) { Transform tf = RoleObject.FindChildTransformWithName(root, effectInfo.BindBone); if (!tf) { tf = modelObject.transform; } effect.transform.parent = tf; effect.transform.localPosition = effectInfo.Position; effect.transform.localEulerAngles = effectInfo.Rotation; effect.transform.localScale = effectInfo.Scale; } } Role config = root.gameObject.GetComponent <Role>(); if (!config) { modelObject.transform.SetParent(root.transform); modelObject.transform.localPosition = Vector3.zero; modelObject.transform.localEulerAngles = Vector3.zero; modelObject.transform.localScale = Vector3.one; return; } SwingBone[] swingBones = config.GetComponentsInChildren <SwingBone>(true); for (int i = 0; i < swingBones.Length; i++) { swingBones[i].enabled = true; swingBones[i].gameObject.SetActive(true); } SkinnedMeshRenderer skinrender = modelObject.GetComponentInChildren <SkinnedMeshRenderer>(); if (skinrender) { if (bones != null && bones.Length > 0) { Transform[] bonetfs = new Transform[bones.Length]; for (int i = 0; i < bones.Length; i++) { bonetfs[i] = ModelLoader.FindChildByName(root.transform, bones[i]); } skinrender.bones = bonetfs; skinrender.rootBone = FindChildByName(config.transform, equip.RootBone); } skinrender.enabled = true; } Transform bindTF = FindChildByName(config.transform, equip.ParentBone); if (!bindTF) { bindTF = config.transform; } if (ro) { ro.Skins.Add(modelObject); } Animation ani = modelObject.GetComponent <Animation>(); if (ani) { ro.Animations.Add(ani); } modelObject.transform.SetParent(bindTF); modelObject.transform.localPosition = Vector3.zero; modelObject.transform.localEulerAngles = Vector3.zero; modelObject.transform.localScale = Vector3.one; modelObject.layer = ro.modelLayer; }