Exemple #1
0
    private string PreSaveData()
    {
        string skp    = XEditorLibrary.GetPath("Skill" + "/" + _directory) + _name + ".txt";
        string config = XEditorLibrary.GetEditorBasedPath("Skill" + "/" + _directory) + _name + ".config";

        XConfigData conf = new XConfigData();

        if (!_combined)
        {
            conf.SkillClip     = AssetDatabase.GetAssetPath(_skillClip);
            conf.SkillClipName = _skillClip.name;
        }
        conf.Player    = _id;
        conf.Directory = _directory;
        conf.SkillName = _name;

        XSkillData data = new XSkillData();

        data.Name = _name;
        if (!_combined)
        {
            data.ClipName = conf.SkillClip.Remove(conf.SkillClip.LastIndexOf('.'));
            data.ClipName = data.ClipName.Remove(0, 17);
        }
        data.TypeToken = _combined ? 2 : 0;
        XDataIO <XSkillData> .singleton.SerializeData(skp, data);

        using (FileStream writer = new FileStream(config, FileMode.Create))
        {
            XmlSerializer formatter = new XmlSerializer(typeof(XConfigData));
            formatter.Serialize(writer, conf);
        }
        AssetDatabase.Refresh();
        return(skp);
    }
Exemple #2
0
        public void Load(string pathwithname)
        {
            try
            {
                string      path = XEditorLibrary.GetCfgFromSkp(pathwithname);
                XConfigData conf = XDataIO <XConfigData> .singleton.DeserializeData(path);

                GameObject prefab = XEditorLibrary.GetDummy((uint)conf.Player);
                if (prefab == null)
                {
                    XDebug.LogError("Prefab not found by id: ", conf.Player); return;
                }
                ColdBuild(prefab, conf);
                prefixPath = pathwithname.Substring(0, pathwithname.IndexOf("/Skill"));
                Time       = File.GetLastWriteTime(pathwithname);
            }
            catch (Exception e)
            {
                XDebug.LogError("Error occurred during loading config file: ", pathwithname, " with error:\n", e.StackTrace);
            }
        }
Exemple #3
0
        public void ColdBuild(GameObject prefab, XConfigData conf)
        {
            if (hoster != null)
            {
                GameObject.DestroyImmediate(hoster);
            }
            hoster = UnityEngine.Object.Instantiate(prefab, Vector3.zero, Quaternion.identity) as GameObject;
            hoster.transform.localScale = Vector3.one * XTableMgr.GetTable <XEntityPresentation>().GetItemID((uint)conf.Player).Scale;
            hoster.AddComponent <XSkillHoster>();
            hoster.GetComponent <CharacterController>().enabled = false;
            UnityEngine.AI.NavMeshAgent agent = hoster.GetComponent <UnityEngine.AI.NavMeshAgent>();
            if (agent != null)
            {
                agent.enabled = false;
            }

            XSkillHoster component = hoster.GetComponent <XSkillHoster>();
            string       directory = conf.Directory[conf.Directory.Length - 1] == '/' ? conf.Directory.Substring(0, conf.Directory.Length - 1) : conf.Directory;
            string       path      = XEditorLibrary.GetPath("Skill" + "/" + directory);

            component.ConfigData = conf;
            component.SkillData  = XDataIO <XSkillData> .singleton.DeserializeData(path + conf.SkillName + ".txt");

            component.SkillDataExtra.ScriptPath = path;
            component.SkillDataExtra.ScriptFile = conf.SkillName;
            component.SkillDataExtra.SkillClip  = RestoreClip(conf.SkillClip, conf.SkillClipName);
            if (component.SkillData.TypeToken != 2)
            {
                if (component.SkillData.Time == 0)
                {
                    component.SkillData.Time = component.SkillDataExtra.SkillClip.length;
                }
            }
            HotBuildEx(component, conf);

            EditorGUIUtility.PingObject(hoster);
            Selection.activeObject = hoster;
        }
Exemple #4
0
        public void HotBuildEx(XSkillHoster hoster, XConfigData conf)
        {
            XSkillDataExtra edata = hoster.SkillDataExtra;
            XSkillData      data  = hoster.SkillData;

            edata.ResultEx.Clear();
            edata.Fx.Clear();
            edata.HitEx.Clear();

            if (data.Result != null)
            {
                foreach (XResultData result in data.Result)
                {
                    XResultDataExtraEx rdee = new XResultDataExtraEx();
                    if (result.LongAttackEffect)
                    {
                        rdee.BulletPrefab      = Resources.Load(result.LongAttackData.Prefab) as GameObject;
                        rdee.BulletEndFx       = Resources.Load(result.LongAttackData.End_Fx) as GameObject;
                        rdee.BulletHitGroundFx = Resources.Load(result.LongAttackData.HitGround_Fx) as GameObject;
                    }
                    edata.ResultEx.Add(rdee);
                }
            }
            if (data.Hit != null)
            {
                foreach (XHitData hit in data.Hit)
                {
                    XHitDataExtraEx hee = new XHitDataExtraEx();
                    hee.Fx = Resources.Load(hit.Fx) as GameObject;
                    edata.HitEx.Add(hee);
                }
            }
            if (data.Fx != null)
            {
                foreach (XFxData fx in data.Fx)
                {
                    XFxDataExtra fxe = new XFxDataExtra();
                    fxe.Fx = Resources.Load(fx.Fx) as GameObject;
                    if (fx.Bone != null && fx.Bone.Length > 0)
                    {
                        Transform attachPoint = hoster.gameObject.transform.Find(fx.Bone);
                        if (attachPoint != null)
                        {
                            fxe.BindTo = attachPoint.gameObject;
                        }
                        else
                        {
                            int index = fx.Bone.LastIndexOf("/");
                            if (index >= 0)
                            {
                                string bone = fx.Bone.Substring(index + 1);
                                attachPoint = hoster.gameObject.transform.Find(bone);
                                if (attachPoint != null)
                                {
                                    fxe.BindTo = attachPoint.gameObject;
                                }
                            }
                        }
                    }
                    fxe.Ratio = fx.At / data.Time;
                    edata.Fx.Add(fxe);
                }
            }
            if (data.Manipulation != null)
            {
                foreach (XManipulationData manipulation in data.Manipulation)
                {
                    XManipulationDataExtra me = new XManipulationDataExtra();
                    edata.ManipulationEx.Add(me);
                }
            }
            if (data.Warning != null)
            {
                foreach (XWarningData warning in data.Warning)
                {
                    XWarningDataExtra we = new XWarningDataExtra();
                    we.Fx    = Resources.Load(warning.Fx) as GameObject;
                    we.Ratio = warning.At / data.Time;
                    edata.WarningEx.Add(we);
                }
            }
            if (data.Mob != null)
            {
                foreach (XMobUnitData mob in data.Mob)
                {
                    XMobUnitDataExtra me = new XMobUnitDataExtra();
                    me.Ratio = mob.At / data.Time;
                    edata.MobEx.Add(me);
                }
            }
        }