void Start() { BUTTON1.enabled = false; BUTTON2.enabled = false; BUTTON3.enabled = false; BUTTON4.enabled = false; BUTTON5.enabled = false; BUTTON6.enabled = false; index = Random.Range(0, 3); grow = false; start = true; wait = 0.5f; count = 0f; sound = GetComponent <AudioSource>(); image = GetComponent <Image>(); AS = GameObject.Find("Info").GetComponent <AddScript>(); RS = GameObject.Find("Buttons").GetComponent <RandomScript>(); BG1 = GameObject.Find("BG1").GetComponent <BackgroundScript>(); BG2 = GameObject.Find("BG2").GetComponent <BackgroundScript>(); BG3 = GameObject.Find("BG3").GetComponent <BackgroundScript>(); BG4 = GameObject.Find("BG4").GetComponent <BackgroundScript>(); image1 = GameObject.Find("Button1").GetComponent <Image>(); image2 = GameObject.Find("Button2").GetComponent <Image>(); image3 = GameObject.Find("Button3").GetComponent <Image>(); image4 = GameObject.Find("Button4").GetComponent <Image>(); image5 = GameObject.Find("Button5").GetComponent <Image>(); image6 = GameObject.Find("Button6").GetComponent <Image>(); image7 = GameObject.Find("Button7").GetComponent <Image>(); monster = GameObject.Find("MonsterHB").GetComponent <MonsterScript>(); HS = GameObject.Find("Score").GetComponent <HighscoreScript>(); playerMoveRend = GameObject.Find("Player").GetComponent <SpriteRenderer>(); playerMoveAnim = GameObject.Find("Player").GetComponent <Animator>(); playerFallRend = GameObject.Find("player").GetComponent <SpriteRenderer>(); PlayerFallAnim = GameObject.Find("player").GetComponent <Animator>(); }
private static void FixGoAtt(GameObject _go, MonoBehaviour _mono, AddScript _script, Dictionary <int, MonoBehaviour> _dic) { List <AddAtt> list = new List <AddAtt>(); FieldInfo[] ff = _mono.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo fff in ff) { object[] yu = fff.GetCustomAttributes(false); foreach (object ob in yu) { if (ob is SerializeField) { object vv = fff.GetValue(_mono); if (vv != null) { AddAtt att = null; try{ att = new AddAtt(fff.Name, vv, _dic); }catch (Exception e) { throw new Exception("error:" + e.ToString() + " go:" + _go.name); } list.Add(att); } } } } _script.atts = list.ToArray(); AddButtonListener[] buttonListeners = _go.GetComponents <AddButtonListener>(); List <AddButtonListener> list2 = new List <AddButtonListener>(); for (int i = 0; i < buttonListeners.Length; i++) { if (buttonListeners[i].scriptName == _mono.name) { list2.Add(buttonListeners[i]); } } _script.buttons = new Button[list2.Count]; _script.buttonMethodNames = new string[list2.Count]; for (int i = 0; i < list2.Count; i++) { _script.buttons[i] = list2[i].button; _script.buttonMethodNames[i] = list2[i].methodName; GameObject.DestroyImmediate(list2[i], true); } if (_mono is SuperScrollRect) { SuperScrollRect scroll = _mono as SuperScrollRect; _script.superScrollRectContent = scroll.content; _script.superScrollRectIsHorizontal = scroll.horizontal; _script.superScrollRectIsVertical = scroll.vertical; _script.superScrollRectMovementType = scroll.movementType; } GameObject.DestroyImmediate(_mono, true); }
private static void FixGo(GameObject _go, ref bool _hasChange, bool _isRoot) { MonoBehaviour[] b = _go.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour bb in b) { if (bb is AddScript || bb is AddButtonListener) { continue; } string typeName = bb.GetType().FullName; if (typeName.IndexOf("UnityEngine") == -1) { AddScript ss = _go.AddComponent <AddScript>(); ss.scriptName = typeName; List <AddAtt> list = new List <AddAtt>(); FieldInfo[] ff = bb.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo fff in ff) { object[] yu = fff.GetCustomAttributes(false); foreach (object ob in yu) { if (ob is SerializeField) { object vv = fff.GetValue(bb); if (vv != null) { if (vv.GetType().BaseType == typeof(MonoBehaviour)) { Debug.LogError("SerializeField is a MonoBehaviour! go.name:" + _go.name + " root.name:" + _go.transform.root.gameObject.name + " FieldInfo.name:" + fff.Name); } AddAtt att = null; try{ att = new AddAtt(fff.Name, vv); }catch (Exception e) { throw new Exception("error:" + e.ToString() + " go:" + _go.name); } list.Add(att); } } } } ss.atts = list.ToArray(); AddButtonListener[] buttonListeners = _go.GetComponents <AddButtonListener>(); List <AddButtonListener> list2 = new List <AddButtonListener>(); for (int i = 0; i < buttonListeners.Length; i++) { if (buttonListeners[i].scriptName == bb.name) { list2.Add(buttonListeners[i]); } } ss.buttons = new Button[list2.Count]; ss.buttonMethodNames = new string[list2.Count]; for (int i = 0; i < list2.Count; i++) { ss.buttons[i] = list2[i].button; ss.buttonMethodNames[i] = list2[i].methodName; GameObject.DestroyImmediate(list2[i], true); } GameObject.DestroyImmediate(bb, true); _hasChange = true; } } for (int i = 0; i < _go.transform.childCount; i++) { FixGo(_go.transform.GetChild(i).gameObject, ref _hasChange, false); } if (_isRoot && _hasChange) { _go.AddComponent <AddScriptRoot>(); } }
private static void FixGo(GameObject _go, ref bool _hasChange, bool _isRoot, Dictionary <int, GameObject> _dic0, Dictionary <int, MonoBehaviour> _dic1, Dictionary <int, AddScript> _dic2) { MonoBehaviour[] b = _go.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour bb in b) { if (bb is AddScript || bb is AddButtonListener) { continue; } string typeName = bb.GetType().FullName; if (typeName.IndexOf("UnityEngine") == -1) { AddScript ss = _go.AddComponent <AddScript>(); ss.scriptName = typeName; int id = bb.GetInstanceID(); ss.monoBehaviourInstanceID = id; _dic0.Add(id, _go); _dic1.Add(id, bb); _dic2.Add(id, ss); _hasChange = true; // FixGoAtt(_go,bb,ss, // List<AddAtt> list = new List<AddAtt>(); // // FieldInfo[] ff = bb.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); // // foreach(FieldInfo fff in ff){ // // object[] yu = fff.GetCustomAttributes(false); // // foreach(object ob in yu){ // // if(ob is SerializeField){ // // object vv = fff.GetValue(bb); // // if(vv != null){ // // if(vv.GetType().BaseType == typeof(MonoBehaviour)){ // // Debug.LogError("SerializeField is a MonoBehaviour! go.name:" + _go.name + " root.name:" + _go.transform.root.gameObject.name + " FieldInfo.name:" + fff.Name); // } // // AddAtt att = null; // // try{ // // att = new AddAtt(fff.Name,vv); // // }catch(Exception e){ // // throw new Exception("error:" + e.ToString() + " go:" + _go.name); // } // // list.Add(att); // } // } // } // } // // ss.atts = list.ToArray(); // // AddButtonListener[] buttonListeners = _go.GetComponents<AddButtonListener>(); // // List<AddButtonListener> list2 = new List<AddButtonListener>(); // // for(int i = 0 ; i < buttonListeners.Length ; i++){ // // if(buttonListeners[i].scriptName == bb.name){ // // list2.Add(buttonListeners[i]); // } // } // // ss.buttons = new Button[list2.Count]; // // ss.buttonMethodNames = new string[list2.Count]; // // for(int i = 0 ; i < list2.Count ; i++){ // // ss.buttons[i] = list2[i].button; // // ss.buttonMethodNames[i] = list2[i].methodName; // // GameObject.DestroyImmediate(list2[i],true); // } // // if(bb is SuperScrollRect){ // // SuperScrollRect scroll = bb as SuperScrollRect; // // ss.superScrollRectContent = scroll.content; // // ss.superScrollRectIsHorizontal = scroll.horizontal; // // ss.superScrollRectIsVertical = scroll.vertical; // // ss.superScrollRectMovementType = scroll.movementType; // } // // GameObject.DestroyImmediate(bb,true); // _hasChange = true; } } for (int i = 0; i < _go.transform.childCount; i++) { FixGo(_go.transform.GetChild(i).gameObject, ref _hasChange, false, _dic0, _dic1, _dic2); } if (_isRoot && _hasChange) { foreach (int id in _dic0.Keys) { FixGoAtt(_dic0[id], _dic1[id], _dic2[id], _dic1); } _go.AddComponent <AddScriptRoot>(); } }
private static void FixGo(GameObject _go, ref bool _hasChange) { MonoBehaviour[] b = _go.GetComponents <MonoBehaviour>(); foreach (MonoBehaviour bb in b) { if (bb is AddScript || bb is AddButtonListener) { continue; } string typeName = bb.GetType().FullName; if (typeName.IndexOf("UnityEngine") == -1) { AddScript ss = _go.AddComponent <AddScript>(); ss.scriptName = typeName; List <AddAtt> list = new List <AddAtt>(); FieldInfo[] ff = bb.GetType().GetFields(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance); foreach (FieldInfo fff in ff) { object[] yu = fff.GetCustomAttributes(false); foreach (object ob in yu) { if (ob is SerializeField) { object vv = fff.GetValue(bb); AddAtt att = new AddAtt(fff.Name, vv); list.Add(att); } } } ss.atts = list.ToArray(); AddButtonListener[] buttonListeners = _go.GetComponents <AddButtonListener>(); List <AddButtonListener> list2 = new List <AddButtonListener>(); for (int i = 0; i < buttonListeners.Length; i++) { if (buttonListeners[i].scriptName == bb.name) { list2.Add(buttonListeners[i]); } } ss.buttons = new Button[list2.Count]; ss.buttonMethodNames = new string[list2.Count]; for (int i = 0; i < list2.Count; i++) { ss.buttons[i] = list2[i].button; ss.buttonMethodNames[i] = list2[i].methodName; GameObject.DestroyImmediate(list2[i], true); } GameObject.DestroyImmediate(bb, true); _hasChange = true; } } for (int i = 0; i < _go.transform.childCount; i++) { FixGo(_go.transform.GetChild(i).gameObject, ref _hasChange); } }