Exemple #1
0
 public void GetParam(string congfig, Action <EntityParamModel> callback)
 {
     if (mParams.ContainsKey(congfig))
     {
         if (callback != null)
         {
             callback(mParams[congfig]);
         }
     }
     else
     {
         AssetLoader.LoadAsset <TextAsset>(congfig, (asset) => {
             if (asset != null && mParams.ContainsKey(congfig) == false)
             {
                 var xml = asset.assetObject;
                 if (xml)
                 {
                     var param = EntityParam.Create(xml.text) as EntityParamModel;
                     if (param != null)
                     {
                         mParams.Add(congfig, param);
                     }
                 }
                 asset.Destroy();
             }
             if (callback != null)
             {
                 callback(mParams.ContainsKey(congfig) ? mParams[congfig] : null);
             }
         });
     }
 }
Exemple #2
0
    private static bool OnOpeEntityParam(int instanceID, int line)
    {
        var asset = EditorUtility.InstanceIDToObject(instanceID) as TextAsset;

        if (asset != null)
        {
            EntityParam param = EntityParam.Create(asset.text);
            if (param != null)
            {
                TreeNodeGraph graph = TreeNodeGraph.CreateGraph(param);
                if (graph != null)
                {
                    Open <EntityParamWindow>(graph);
                    return(true);
                }
            }
        }
        return(false);
    }
Exemple #3
0
    protected override TreeNodeGraph OnLoad()
    {
        string path = EditorUtility.OpenFilePanel("Select a config", Application.dataPath + "/Resources/r/config/", "txt");

        if (string.IsNullOrEmpty(path))
        {
            return(null);
        }

        Debug.Log(path);


        string text = File.ReadAllText(path);

        EntityParam param = EntityParam.Create(text);

        if (param != null)
        {
            return(TreeNodeGraph.CreateGraph(param));
        }

        return(base.OnLoad());
    }
Exemple #4
0
    static void CreateAnimationPrefab(GameObject obj)
    {
        if (obj == null)
        {
            return;
        }

        string path = AssetDatabase.GetAssetPath(Selection.activeGameObject);

        string dirName = Application.dataPath.Substring(0, Application.dataPath.LastIndexOf('/') + 1) + path.Substring(0, path.LastIndexOf('/') + 1);

        DirectoryInfo dir = new DirectoryInfo(dirName);

        FileInfo[] files = dir.GetFiles("*.fbx");

        EntityParamModel modelParam     = null;
        string           configFullPath = string.Format("{0}/Resources/r/config/{1}.txt", Application.dataPath, obj.name.ToLower());

        Debug.Log(configFullPath);
        if (File.Exists(configFullPath) == false)
        {
            modelParam      = new EntityParamModel();
            modelParam.rect = new Rect(20, 20, TreeNode.WIDTH, TreeNode.HEIGHT);
        }
        else
        {
            modelParam = EntityParam.Create(File.ReadAllText(configFullPath)) as EntityParamModel;
        }

        modelParam.asset = obj.name.ToLower() + ".prefab";

        AnimatorController animatorController = AnimatorController.CreateAnimatorControllerAtPath(path.ToLower().Replace(".fbx", ".controller"));

        AnimatorStateMachine sm = animatorController.layers[0].stateMachine;

        int leftIndex  = 0;
        int rightIndex = 0;

        for (int i = 0; i < files.Length; ++i)
        {
            if (files[i].Name.Contains("@") == false)     // 跳过不是动作的文件
            {
                //Debug.Log("跳过无效文件:" + fileInfos[i].Name + "   "  + obj.name + "@");
                continue;
            }

            string animName = Path.GetFileNameWithoutExtension(files[i].Name).Split('@')[1];

            AnimatorState state = null;

            if (leftIndex < 5)
            {
                state = sm.AddState(animName, new Vector3(-140, 25 + 50 * leftIndex++, 0));
            }
            else
            {
                state = sm.AddState(animName, new Vector3(180, 25 + 50 * rightIndex++, 0));
            }
            string animationClip = files[i].FullName.Replace("\\", "/");
            animationClip = animationClip.Substring(animationClip.LastIndexOf("Assets/"));
            var clip = AssetDatabase.LoadAssetAtPath <AnimationClip>(animationClip);
            state.motion = clip;
            if (animName.Equals("idle"))
            {
                sm.defaultState = state;
            }

            if (modelParam != null)
            {
                ActionType        type        = EntityParamModel.GetActionType(animName);
                EntityParamAction actionParam = null;
                for (int j = 0; j < modelParam.children.Count; ++j)
                {
                    var child = modelParam.children[j] as EntityParamAction;
                    if (child != null && type == child.action)
                    {
                        actionParam = child; break;
                    }
                }
                if (actionParam == null)
                {
                    actionParam      = new EntityParamAction();
                    actionParam.rect = new Rect(300, 20, TreeNode.WIDTH, TreeNode.HEIGHT);
                    modelParam.AddChild(actionParam);
                }
                actionParam.action = type;
                actionParam.weight = EntityParamAction.ActionWeights[type];

                EntityParamAnimation animationParam = null;
                for (int j = 0; j < actionParam.children.Count; ++j)
                {
                    var child = actionParam.children[j] as EntityParamAnimation;
                    if (child != null && child.animationClip == animationClip)
                    {
                        animationParam = child; break;
                    }
                }
                if (animationParam == null)
                {
                    animationParam      = new EntityParamAnimation();
                    animationParam.rect = new Rect(600, 20, TreeNode.WIDTH, TreeNode.HEIGHT);
                    modelParam.AddChild(animationParam);
                }
                animationParam.animationClip = animName;
                animationParam.length        = clip.length;
                animationParam.mode          = EntityParamModel.GetWrapMode(animName);
            }
        }
        var empty = sm.AddState("empty", new Vector3(180, 25 + 50 * rightIndex, 0));

        empty.speed = 0;


        if (File.Exists(configFullPath))
        {
            File.Delete(configFullPath);
        }
        EntityParamWindow.Save(modelParam, configFullPath);

        // 如果目录下预制体不存在,则创建预制体
        string prefabPath = string.Format("Assets/Resources/r/model/{0}.prefab", obj.name.ToLower());

        string prefabFullPath = string.Format("{0}/Resources/r/model/{1}.prefab", Application.dataPath, obj.name.ToLower());

        if (File.Exists(prefabFullPath))
        {
            bool delete = EditorUtility.DisplayDialog("提示", string.Format("预设{0}.prefab已存在,是否替换?", obj.name), "确认", "取消");
            if (delete)
            {
                File.Delete(prefabFullPath);
            }
            else
            {
                AssetDatabase.SaveAssets();
                AssetDatabase.Refresh();
                return;
            }
        }

        obj.GetComponent <Animator>().runtimeAnimatorController = animatorController;
        GameObject go = PrefabUtility.SaveAsPrefabAsset(obj, prefabPath);

        go.transform.position   = Vector3.zero;
        go.transform.rotation   = Quaternion.identity;
        go.transform.localScale = Vector3.one;


        int layer = LayerMask.NameToLayer("Default");

        Transform[] transforms = go.GetComponentsInChildren <Transform>();
        for (int i = 0; i < transforms.Length; ++i)
        {
            transforms[i].gameObject.layer = layer;

            SetBonePoint(transforms[i]);
        }

        AssetDatabase.SaveAssets();
        AssetDatabase.Refresh();
    }