public void OnEnable() { tex = Resources.Load("TT_SideHelp") as Texture; TileToolTile target_cs = (TileToolTile)target; target_cs.FindAndSetTileValues(); TileToolStyle TTS = target_cs.gameObject.GetComponent <TileToolStyle>(); if (!TTS) { target_cs.gameObject.AddComponent <TileToolStyle>(); } if (GUI.changed) { EditorUtility.SetDirty(target_cs); } }
public void ReplaceStyles(string type) { if (Selection.transforms.Length > 0 && (_style != null)) //Check if style is assigned { GameObject[] styleObjects = null; if (type == "Tile") { styleObjects = _style._tiles; //CombineVector3Arrays(_style._tiles, _style._objects); } else if (type == "Object") { styleObjects = _style._objects; } else if (type == "All") { styleObjects = CombineVector3Arrays(_style._tiles, _style._objects); } if (Selection.activeTransform.GetComponent(typeof(TileToolGroup)) != null) { Transform[] glist = null; glist = new Transform[Selection.activeTransform.childCount]; Transform o = Selection.activeTransform; for (int i = 0; i < Selection.activeTransform.childCount; i++) { glist[i] = o.GetChild(i); } _selection = glist; } else { _selection = Selection.transforms; //Add selection to array } // var olist:GameObject[]; // olist = new GameObject[_selection.length]; for (int i = 0; i < _selection.Length; i++) { float p = (float)i; EditorUtility.DisplayProgressBar("TileTool: Replacing GameObjects", "Any removed sides will be reset", p / _selection.Length); //olist[i] = _selection[i].gameObject; TileToolStyle TTO = (TileToolStyle)_selection[i].GetComponent(typeof(TileToolStyle)); if ((TTO != null) && TTO.objectName != "") { string s = TTO.objectName; for (int j = 0; j < styleObjects.Length; j++) { TileToolStyle newTTO = styleObjects[j].GetComponent <TileToolStyle>(); if (newTTO != null) { string newObjectTile = newTTO.objectName; if (s == newObjectTile) { GameObject newObject = null; newObject = (GameObject)PrefabUtility.InstantiatePrefab(styleObjects[j]); Transform newT = newObject.transform; newT.position = _selection[i].position; newT.rotation = _selection[i].rotation; newT.localScale = _selection[i].localScale; // olist[i] = newObject; newT.parent = _selection[i].transform.parent; Undo.RegisterCreatedObjectUndo(newObject, "TileTool: Replace Styles"); Undo.DestroyObjectImmediate(_selection[i].gameObject); break; } } } } } //if(!Selection.activeTransform.GetComponent(TileToolGroup)){ // Selection.objects = olist; //} } }