TP:FCEE652B

cause

在游戏开发的过程中,很多时候需要策划填的一些静态数据表(比如英雄表,技能表等等),而策划一般都习惯使用excel。

excel在unity里面是不能直接读取的,所以我们一般要另存为txt读取,然后一行一行解析进行读取。

***.txt

id	name	price
1 张三 3.0
2 李四 4.0

但是有一点问题,策划改表是很频繁的,总不能每次策划改动我们另存为一次吧。

这个时候我们可以采用python写一个脚本动态批处理即可

how

1.安装mysql并且安装MySQLdb模块

测试环境win7 推荐python 编辑器pycharm

MySql_Win_Install

安装MySQL-Python(MySQLdb)

2.安装Navicat Premium导入excel表

3.配置读取参数

{
"db":{
"host":"127.0.0.1",
"user":"root",
"passwd":"",
"port":3306,
"db":"testdb"
},
"exp_sep":"\t",
"exp_suffix":".txt",
"tables":[
"test_table"
],
"vos":[
"test_table"
]
}

4.动态生成txt和静态配置类

#! /usr/bin/env python
#coding:utf8 import sys
import MySQLdb
import json reload(sys)
sys.setdefaultencoding('utf-8') # tables = ('test_table',)
# vo = ('test_table',)
# ('test_table') is interpreted as using algebraic grouping and simply as max_price and not a tuple.
# Adding a comma, i.e. ('test_table',) forces it to make a tuple. head = '''using UnityEngine;
using System;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
'''
class_part1 = '''public class %s
{
'''
field = ''' public %s %s;
'''
ctor_par1 = ''' public %s(string[] args)
{
'''
ctor_field = ''' this.%s=%s(arr[%s]);
'''
ctor_par2 = ''' }
'''
class_part2 = '}' def ConvetType(typeid):
if typeid == 3:
return 'int'
elif typeid == 4:
return 'float'
else:
return 'string' def ConvertCtorType(typeid):
if typeid == 3:
return 'int.Parse'
elif typeid == 4:
return 'float.Parse'
else:
return '' # description (('id', 3, 1, 11, 11, 0, 0), ('name', 253, 6, 765, 765, 0, 0), ('price', 4, 1, 12, 12, 31, 0))
def CreateCS(index, description):
vo = curconifg['vos']
with open('%s.cs'% vo[index],"w+") as my_cs:
my_cs.write(head)
my_cs.write(class_part1 % vo[index])
for colIndex in range(len(description)):
curCol = description[colIndex]
my_cs.write(field % (ConvetType(curCol[1]),curCol[0]))
my_cs.write(ctor_par1 % vo[index])
for colIndex in range(len(description)):
curCol = description[colIndex]
my_cs.write(ctor_field % (curCol[0],ConvertCtorType(curCol[1]),colIndex))
my_cs.write(ctor_par2)
my_cs.write(class_part2) def CreateConfig():
con = MySQLdb.connect(curconifg['db']['host'],curconifg['db']['user'],curconifg['db']['passwd'],curconifg['db']['db'],charset='utf8');
# notice ,charset='utf8'
with con:
cur = con.cursor()
tables = curconifg['tables']
for index in range(len(tables)):
table = tables[index]
# cur.execute("select * from %s where id = %s",('test_table',1))
# DB API requires you to pass in any parameters as a sequence
# but sql query is select * from \\'test_table\\' where id = 1
# like below error
# http://blog.xupeng.me/2013/09/25/mysqldb-args-processing
# so you can do it below,but not safe
query = 'select * from %s '%(table);
cur.execute(query)
with open('%s.txt'%(table),'w+') as my_txt:
# create file if not exits
description = cur.description
CreateCS(index,description)
# description (('id', 3, 1, 11, 11, 0, 0), ('name', 253, 6, 765, 765, 0, 0), ('price', 4, 1, 12, 12, 31, 0))
# create txt
line = curconifg['exp_sep'].join(str(curCol[0]) for curCol in description)
# id name price
my_txt.write(line+'\n')
for i in range(cur.rowcount):
row = cur.fetchone()
line = curconifg['exp_sep'].join(str(col) for col in row)
# 1 张三 3.0
if(i <= (cur.rowcount - 1)):
my_txt.write(line+'\n')
else:
my_txt.write(line) with open("config.json","r") as jsonFile:
curconifg = json.load(jsonFile)
CreateConfig()

结果如图:

improvement

向上面那样考虑生成txt然后一行一行解析其实还是有点麻烦的,因为这个解析规则还是依赖于我们

其实我们可以考虑在生成的时候转换一下

***.txt

id	name	price
1 张三 3.0 {"id":1,"name":"张三","price":3.0}

是不是有很多想法啦,骚年!

参考工程 Pratices1

Unity 配置静态excel 工作流程的更多相关文章

  1. Sitecore 8.2 工作流程

    假设您的新Sitecore项目的所有开发都已完成.现在的下一步是在网站上填写内容并准备上线.客户通知您他们希望使用专门的网站管理员团队负责整个内容管理流程,并要求您为他们准备实例以便能够执行此操作. ...

  2. ecshop 工作流程加载配置介绍

    ecshop 工作流程加载配置介绍 分类: ecshop2014-09-14 09:36 729人阅读 评论(2) 收藏 举报 模板引擎工作流 这里简单介绍下echsop工作流程: 首先,你会发现一般 ...

  3. 工作流程,编程,调试,性能:Unity游戏开发者应该学习的20个改进技巧

    Unity 是一个备受欢迎的游戏开发平台.它的功能令人印象深刻,同时也迎合了不同的游戏开发需求.游戏开发者可以使用 Unity 创建任何类型的游戏,从世界级的 RPG 游戏到最流行的增强现实游戏 Po ...

  4. KaliLinux常用服务配置教程DHCP服务工作流程

    KaliLinux常用服务配置教程DHCP服务工作流程 DHCP服务工作流程如图1.1所示. 具体的工作流程如下所示: (1)DHCP客户端以广播的方式发出DHCP Discover报文. (2)所有 ...

  5. SpringMVC-DispatcherServlet工作流程及web.xml配置

    工作流程: Web中,无非是请求和响应: 在SpringMVC中,请求的第一站是DispatcherServlet,充当前端控制器角色: DispatcherServlet会查询一个或多个处理器映射( ...

  6. GIT使用—安装配置及工作流程

    一.Git 与 SVN 区别 GIT不仅仅是个版本控制系统,它也是个内容管理系统(CMS),工作管理系统等. 1.GIT是分布式的,SVN不是:这是GIT和其它非分布式的版本控制系统,例如SVN,CV ...

  7. Excel催化剂开源第10波-VSTO开发之用户配置数据与工作薄文件一同存储

    在传统的VBA开发中,若是用的是普通加载项方法,是可以存储数据在xlam上的,若用的是Com加载项方法同时是Addins程序级别的项目开发的,配置文件没法保存到工作薄中,一般另外用配置文件来存放供调用 ...

  8. Git 安装配置及工作流程

    在使用Git前我们需要先安装 Git.Git 目前支持 Linux/Unix.Solaris.Mac和 Windows 平台上运行. Git 各平台安装包下载地址为:http://git-scm.co ...

  9. 03.AOF持久化机制配置与工作流程

    一.AOF持久化的配置 配置文件redis.conf,AOF持久化默认是关闭的,默认是打开RDB持久化 appendonly yes     二.工作流程: 打开AOF持久化机制之后,redis每次接 ...

随机推荐

  1. mysql 使用set names 解决乱码问题

    引子: 最近查询公司线上表数据,返现在Xshell控制台打印的数据都是乱码,记得之前瞄过同事都是执行set names UTF8 , 解决的,特记录如下.

  2. 《锋利的JQuery》读书要点笔记5——jQuery与Ajax的应用

    第6章 jQuery与Ajax的应用 Ajax的全称:Asynchronous JavaScript and XML (异步Javascript和XML) 传统模式中,数据提交通过表单方式实现,数据的 ...

  3. 前端读者 | 别人写的css,你敢用吗?

    本文来自@yeaseonzhang:链接:http://yeaseonzhang.github.io/2018/04/10/%E5%88%AB%E4%BA%BA%E5%86%99%E7%9A%84cs ...

  4. OSSIM 4 组件目录

    在查找openvas问题的时候,发现: 主要组件的配置文件目录:/etc/default主要组件的安装目录:/usr/share 感觉和kali linux的的结构类似.

  5. Appium +Python 连接真机测试

    1.数据线连接电脑和手机: 2.用adb获取手机的UUID:cmd-> adb devices 前面的就是你手机的UUID 3.打开appium,选择手机的安卓版本(关于手机中查看),填写手机的 ...

  6. HDU 1391 number steps(找规律,数学)

    Starting from point (0,0) on a plane, we have written all non-negative integers 0, 1, 2,... as shown ...

  7. HDU 6313: Hack it

    Hack It Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  8. Linux CentOS下Python+robot framework环境搭建

    转载自:http://blog.sina.com.cn/s/blog_13cc013b50102vof1.html 操作系统环境:CentOS 6.5-x86_64 下载地址:http://www.c ...

  9. [Contest20180122]超级绵羊异或

    题意:求$a\ xor\left(a+b\right)xor\cdots xor\left(a+b\left(n-1\right)\right)$ 对每一位求答案,第$k$的答案是$\sum\limi ...

  10. 【容斥原理】CDOJ - 1544 - 当咸鱼也要按照基本法

    众所周知zhu是一个大厨,zhu一直有自己独特的咸鱼制作技巧. tang是一个咸鱼供应商,他告诉zhu在他那里面有NN条咸鱼(标号从1到N)可以被用来制作. 每条咸鱼都有一个咸鱼值KiKi,初始时所有 ...