Skip to content

Instantly share code, notes, and snippets.

@whaison
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save whaison/ee2dead475d723896c92 to your computer and use it in GitHub Desktop.
Save whaison/ee2dead475d723896c92 to your computer and use it in GitHub Desktop.
Prefab Particle System YAML EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System;
using System.Runtime.CompilerServices;
public class PassObject :object
{
public string tilesX="2";
public string tilesY="2";
public string frameOverTime="0.25";
}
public class FindAllPropatiesAndWrite : Editor
{
public
//static List<string> txtLineListRef = new List<string>();
static string AssetPathStr;
static string SavePathStr;
[MenuItem("Assets/Find All Object Properties And Write")]
public static void Init ()
{
List<string> mytxtLineListRef = new List<string>();
AssetPathStr=AssetDatabase.GetAssetPath(Selection.activeGameObject);
Debug.Log("AssetPathStr="+AssetPathStr);
//SavePathStr=Application.dataPath + "FileName.prefab";
SavePathStr=AssetPathStr;
Debug.Log("SavePathStr="+SavePathStr);
PassObject Obj=new PassObject();
Obj.tilesX="2";
Obj.tilesY="2";
Obj.frameOverTime="0.25";
StreamReader(mytxtLineListRef, Obj);
Save(mytxtLineListRef);
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}
public static void InitSaveOption (PassObject Obj,GameObject gameObjectRef){
List<string> mytxtLineListRef = new List<string>();
AssetPathStr=AssetDatabase.GetAssetPath(gameObjectRef);
Debug.Log("##############################AssetPathStr="+AssetPathStr);
//SavePathStr=Application.dataPath + "FileName.prefab";
SavePathStr=AssetPathStr;
Debug.Log("SavePathStr="+SavePathStr);
StreamReader(mytxtLineListRef, Obj);
//Init1 ();
//for(int i = 0; i < txtLineList.Count; i++)
//{
//Debug.Log("Creating enemy number: " + i);
Save(mytxtLineListRef);
//}
//Assetをリロードする。
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}
public static void StreamReader(List<string> mytxtLineListRef,PassObject Obj)
{
try
{
// Create an instance of StreamReader to read from a file.
// The using statement also closes the StreamReader.
using (StreamReader sr = new StreamReader(AssetPathStr))
{
string line;
// Read and display lines from the file until the end of
// the file is reached.
bool bool_Start_UVModule=false;
bool bool_m_Curve=false;
bool bool_maxCurve=false;
bool bool_minCurve=false;
int linenum=0;
while ((line = sr.ReadLine()) != null)
{
if (line.IndexOf("UVModule") == -1) {
//文字列が無かった
} else {
//文字列があった
Debug.Log("-###################-UVModule--########################### START");
bool_Start_UVModule=true;
}
if (line.IndexOf("VelocityModule") == -1) {
//文字列が無かった
} else {
//文字列があった
Debug.Log("####################---UVModule end--#######################-E N D");
bool_Start_UVModule=false;
}
//m_Curve
if (line.IndexOf("m_Curve") == -1) {
//文字列が無かった
} else {
//文字列があった
//Debug.Log("####################---UVModule end--#######################-E N D");
bool_m_Curve=true;
}
//maxCurve:
if (line.IndexOf("maxCurve:") == -1) {
//文字列が無かった
} else {
//文字列があった
//Debug.Log("####################---UVModule end--#######################-E N D");
bool_maxCurve=true;
}
//minCurve:
if (line.IndexOf("minCurve:") == -1) {
//文字列が無かった
} else {
//文字列があった
//Debug.Log("####################---UVModule end--#######################-E N D");
bool_maxCurve=false;
bool_minCurve=true;
}
//minMaxState:
if (line.IndexOf("minMaxState:") == -1) {
//文字列が無かった
} else {
//文字列があった
//Debug.Log("####################---UVModule end--#######################-E N D");
bool_minCurve=false;
}
//m_Curve-------end:
if (line.IndexOf("m_PreInfinity") == -1) {
//文字列が無かった
} else {
//文字列があった
//Debug.Log("####################---UVModule end--#######################-E N D");
bool_m_Curve=false;
}
//Debug.Log(line);
linenum++;
//Debug.Log(linenum+":"+line);
if(bool_Start_UVModule==true){
//--------------enabled: 0"
line=LineChenger(linenum,line,"enabled: 0","0","1");
//---------------scalar: 1
line=LineChenger(linenum,line,"scalar: 1","1",Obj.frameOverTime);
if(bool_m_Curve==true){
///value: 0
line=LineChenger(linenum,line,"value: 0","0","1");
}
//-------------minMaxState: 1
line=LineChenger(linenum,line,"minMaxState: 1","1","0");
//---------tilesX: 1
line=LineChenger(linenum,line,"tilesX: 1","1",Obj.tilesX);
//---------tilesY: 1
line=LineChenger(linenum,line,"tilesY: 1","1",Obj.tilesY);
}
//txtLineList.Add(line);
mytxtLineListRef.Add(line);
}
}
}
catch (Exception e)
{
// Let the user know what went wrong.
Debug.Log("The file could not be read:");
Debug.Log(e.Message);
}
}
public static string LineChenger(int linenum, string line,string searchString,string defaultValue,string chengeValue){
if (line.IndexOf(searchString) == -1) {
//文字列が無かった
} else {
//文字列があった
Debug.Log(linenum+":"+line);
int startint=line.IndexOf(defaultValue);
string str_0 = line.Substring(0,startint);
string str_1 = line.Substring(startint);
string str_2 = line.Substring(startint+1);
line=str_0+chengeValue+str_2;
Debug.Log(linenum+":"+line);
}
return line;
}
public static void Save(List<string> mytxtLineListRef){
StreamWriter sw;
FileInfo fi;
fi = new FileInfo(SavePathStr);
//sw = fi.AppendText();
sw = fi.CreateText();
for(int i = 0; i < mytxtLineListRef.Count; i++)
{
//Debug.Log("Creating enemy number: " + i);
sw.WriteLine(mytxtLineListRef[i]);
}
//sw.WriteLine(txt);
//sw.Fluse();
sw.Close();
}
static void Init1 ()
{
//= Selection.activeGameObject
}
static void Init2 ()
{
Component[] allComponent;
allComponent = Selection.activeGameObject.GetComponents<Component>();
//ParticleSystem newPS = activeGameObject.GetComponent<ParticleSystem>();
bool bool_UVModule=false;
bool bool_frameOverTime=false;
foreach(Component go in allComponent)
{
SerializedObject m_Object = new SerializedObject(go);
//SerializedObject psSerial = new SerializedObject (newPS);
Debug.Log ("--------"+ go.GetType() +"-------");
try
{
SerializedProperty obj = m_Object.GetIterator();
foreach(SerializedProperty property in obj)
{
Debug.Log(property.name + " : " + property.propertyType);
if(property.name=="UVModule"){
Debug.Log("//#######UVModule を見つけました#############");
bool_UVModule=true;
}
if(bool_UVModule==true){
if(property.name=="enabled"){
//Debug.Log("//##### 01 ##UVModule enabled property.boolValue~"+property.boolValue.ToString()+"#############");
property.boolValue=true;
//Debug.Log("//###### 02 #UVModule enabled property.boolValue~"+property.boolValue.ToString()+"#############");
//SerializedProperty objset = m_Object.FindProperty("UVModule.enabled").boolValue=true;
property.FindPropertyRelative("enabled").boolValue = true;
//Debug.Log("//##### 03 ##UVModule enabled property.boolValue~"+property.boolValue.ToString()+"#############");
//property.FindProperty("UVModule.enabled").boolValue = true;
//psSerial.FindProperty("UVModule.tilesX").intValue = pr.uvAnimationXTile;
//psSerial.FindProperty("UVModule.tilesY").intValue = pr.uvAnimationYTile;
//psSerial.FindProperty("UVModule.cycles").floatValue = (int)pr.uvAnimationCycles;
}
if(property.name=="frameOverTime"){
bool_frameOverTime=true;
}
if(property.name=="scalar"){
property.floatValue=0.0f;
bool_frameOverTime=false;
}
if(property.name=="tilesX"){
property.intValue=2;
}
if(property.name=="tilesY"){
property.intValue=2;
}
if(property.name=="animationType"){
property.intValue=0;//whole sheet
}
if(property.name=="UVModule"){}
}
if(property.name=="VelocityModule"){
Debug.Log("//#######VelocityModule を見つけました#############");
//bool_UVModule=false;
}
}
}
catch(System.Exception e)
{
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment