using TableConfig; 
 | 
using UnityEngine; 
 | 
using UnityEditor; 
 | 
  
 | 
public class ModelResourcesBuilder : ResourcesBuilder 
 | 
{ 
 | 
    public void BuildModelRes(int id) 
 | 
    { 
 | 
        ModelResConfig _modelRes = Config.Instance.Get<ModelResConfig>(id); 
 | 
        if (_modelRes == null) 
 | 
        { 
 | 
            Debug.LogWarningFormat("要生成的ModelRes资源id: {0} 并不存在于配置表中, 请确认是否填写有错.", id); 
 | 
            return; 
 | 
        } 
 | 
        switch ((E_ModelResType)_modelRes.Type) 
 | 
        { 
 | 
            case E_ModelResType.Suit: 
 | 
                BuildClothes(id); 
 | 
                break; 
 | 
            case E_ModelResType.Wing: 
 | 
                BuildWing(id); 
 | 
                break; 
 | 
            case E_ModelResType.Weapon: 
 | 
                BuildWeapon(id); 
 | 
                break; 
 | 
            case E_ModelResType.Horse: 
 | 
                BuildHorse(id); 
 | 
                break; 
 | 
            case E_ModelResType.Secondary: 
 | 
                BuildSecondary(id); 
 | 
                break; 
 | 
        } 
 | 
    } 
 | 
  
 | 
    public void BuildClothes(int id) 
 | 
    { 
 | 
        BuildAnimationClip(id); 
 | 
        BuildAnimatorController(id, "Temple_AnimatorController_Hero", "animatorBuildConfig"); 
 | 
        BuildPrefab(id, InstanceResourcesLoader.raceSuffix); 
 | 
    } 
 | 
  
 | 
    public void BuildWeapon(int id) 
 | 
    { 
 | 
        BuildPrefab(id, InstanceResourcesLoader.weaponSuffix); 
 | 
    } 
 | 
  
 | 
    public void BuildSecondary(int id) 
 | 
    { 
 | 
        BuildPrefab(id, InstanceResourcesLoader.secondarySuffix); 
 | 
    } 
 | 
  
 | 
    public void BuildHorse(int id) 
 | 
    { 
 | 
        BuildAnimationClip(id); 
 | 
        BuildAnimatorController(id, "Temple_AnimatorController_Horse", "animatorBuildConfig"); 
 | 
        BuildPrefab(id, InstanceResourcesLoader.horseSuffix); 
 | 
    } 
 | 
  
 | 
    public void BuildWing(int id) 
 | 
    { 
 | 
        BuildAnimationClip(id); 
 | 
        BuildAnimatorController(id, "Temple_AnimatorController_Wing", "animatorBuildConfig_Wing"); 
 | 
        BuildPrefab(id, InstanceResourcesLoader.wingSuffix); 
 | 
    } 
 | 
  
 | 
    private void BuildPrefab(int id, string suffix) 
 | 
    { 
 | 
        if (!IsBuildPrefab) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        ModelResConfig _modelRes = Config.Instance.Get<ModelResConfig>(id); 
 | 
        string _path = _modelRes.ResourcesName; 
 | 
        string _resName = _modelRes.ResourcesName; 
 | 
        if (_path.IndexOf('/') != -1) 
 | 
        { 
 | 
            _resName = _path.Substring(_path.IndexOf("/") + 1); 
 | 
            _path = _path.Substring(0, _modelRes.ResourcesName.IndexOf('/')); 
 | 
        } 
 | 
  
 | 
        BuildPrefab(_path, _resName, suffix); 
 | 
    } 
 | 
  
 | 
    public static void BuildAnimationClip(int id) 
 | 
    { 
 | 
        if (!IsBuildAnimationClip) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        ModelResConfig _modelRes = Config.Instance.Get<ModelResConfig>(id); 
 | 
        string _path = _modelRes.ResourcesName; 
 | 
        if (_path.IndexOf('/') != -1) 
 | 
        { 
 | 
            _path = _path.Substring(0, _modelRes.ResourcesName.IndexOf('/')); 
 | 
        } 
 | 
  
 | 
        BuildAnimationClip(_path); 
 | 
    } 
 | 
  
 | 
    public static void BuildAnimatorController(int id, string templeName, string configName) 
 | 
    { 
 | 
        if (!IsBuildAnimatorController) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        ModelResConfig _modelRes = Config.Instance.Get<ModelResConfig>(id); 
 | 
        string _path = _modelRes.ResourcesName; 
 | 
        if (_path.IndexOf('/') != -1) 
 | 
        { 
 | 
            _path = _path.Substring(0, _modelRes.ResourcesName.IndexOf('/')); 
 | 
        } 
 | 
  
 | 
        BuildAnimatorController(_path, templeName, configName); 
 | 
    } 
 | 
  
 | 
    protected override void OnSetupRenderer(string path, string resName, ref Renderer renderer) 
 | 
    { 
 | 
        string _materialPath = string.Format("Assets/ART/Role/{0}/Materials/{1}.mat", path, resName); 
 | 
  
 | 
        Material _material = AssetDatabase.LoadAssetAtPath<Material>(_materialPath); 
 | 
        if (!_material) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        // 设置为不接受阴影 
 | 
        renderer.receiveShadows = false; 
 | 
  
 | 
        renderer.materials = new Material[0]; 
 | 
        renderer.sharedMaterial = AssetDatabase.LoadAssetAtPath<Material>(_materialPath); 
 | 
  
 | 
        // 这里是对翅膀的特殊处理 
 | 
        Transform _parent = renderer.transform.parent; 
 | 
        if (_parent == null) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        // 翅膀的第二个节点 
 | 
        Transform _node = _parent.Find(resName + "b"); 
 | 
  
 | 
        if (_node == null) 
 | 
        { 
 | 
            return; 
 | 
        } 
 | 
  
 | 
        _materialPath = string.Format("Assets/ART/Role/{0}/Materials/{1}_glow.mat", path, resName); 
 | 
  
 | 
        Renderer _renderer = _node.GetComponent<Renderer>(); 
 | 
        _renderer.receiveShadows = false; 
 | 
  
 | 
        _renderer.materials = new Material[0]; 
 | 
        _renderer.sharedMaterial = AssetDatabase.LoadAssetAtPath<Material>(_materialPath); 
 | 
    } 
 | 
} 
 |