public static T CreateChild <T>(Transform parent, string name, bool disabled = false) where T : Component { GameObject go; if (parent is RectTransform) { go = new GameObject(name, typeof(RectTransform)); } else { go = new GameObject(name); } if (disabled) { MadGameObject.SetActive(go, false); } go.transform.SetParent(parent); go.transform.localRotation = Quaternion.identity; go.transform.localScale = Vector3.one; go.transform.localPosition = Vector3.zero; T obj = go.GetComponent <T>(); if (obj == null) { obj = go.AddComponent <T>(); } if (MadTransform.registerUndo) { MadUndo.RegisterCreatedObjectUndo(go, "Created " + name); } return(obj); }
protected void FieldSetNativeSize() { if (MadGUI.Button("Set Native Size")) { var b = (EnergyBarUGUIBase)target; MadUndo.RecordObject2(b.gameObject, "Set Native Size"); b.SetNativeSize(); } }
void FieldSequenceTextures() { if (UseAtlas()) { int size = script.sequenceAtlasTexturesGUID.Length; int nSize = FieldTextureCount(); EditorGUILayout.Space(); FieldBatchTextureSet(); EditorGUILayout.Space(); MadGUI.Indent(() => { if (size != nSize) { MadUndo.RecordObject2(script, "Texture Count Resize"); System.Array.Resize(ref script.sequenceAtlasTexturesGUID, nSize); EditorUtility.SetDirty(script); } if (sequenceAtlasTexturesGUID.arraySize == 0) { ZeroTexturesWarning(); } for (int i = 0; i < sequenceAtlasTexturesGUID.arraySize; ++i) { var element = sequenceAtlasTexturesGUID.GetArrayElementAtIndex(i); FieldAtlasSprite(element, "Texture " + i); } }); } else { int size = script.sequenceTextures.Length; int nSize = FieldTextureCount(); EditorGUILayout.Space(); MadGUI.Indent(() => { if (size != nSize) { MadUndo.RecordObject2(script, "Texture Count Resize"); System.Array.Resize(ref script.sequenceTextures, nSize); EditorUtility.SetDirty(script); } if (sequenceTextures.arraySize == 0) { ZeroTexturesWarning(); } for (int i = 0; i < sequenceTextures.arraySize; ++i) { var element = sequenceTextures.GetArrayElementAtIndex(i); MadGUI.PropertyField(element, "Texture " + i); } }); } }
protected void CreateAnchor() { MadUndo.LegacyRegisterSceneUndo("Create Anchor"); if (IsAnchored()) { EditorUtility.DisplayDialog("Anchor already exists", "Your bar object is already under the anchor", "Fine"); return; } var anchor = MadTransform.CreateChild <MadAnchor>(energyBarBase.transform.parent, "Anchor"); energyBarBase.transform.parent = anchor.transform; Selection.activeObject = energyBarBase.gameObject; }
private void FieldBatchTextureSet() { MadGUI.Info("If your atlas textures have regular names (like part_01, part_02) then you can add them all at once. " + "Just enter here something like 'part_??' where ?? are placeholders for digits, and then press the button below."); nameTemplate = EditorGUILayout.TextField("Name Template", nameTemplate); if (MadGUI.Button("Batch Texture Set", Color.yellow)) { if (EditorUtility.DisplayDialog("Batch Texture Set", "Are you sure that you want to overwrite your texture settings?", "Yes", "No")) { MadUndo.RecordObject2(script, "Batch Texture Set"); var regex = "^" + nameTemplate.Replace("?", "[0-9]") + "$"; var filtered = from i in script.atlas.items where Regex.Match(i.name, regex).Success orderby i.name select i; var filteredArr = filtered.ToArray(); for (int i = 0; i < script.sequenceAtlasTexturesGUID.Length && i < filteredArr.Length; ++i) { script.sequenceAtlasTexturesGUID[i] = filteredArr[i].textureGUID; } } } }
public static void Convert() { MadUndo.LegacyRegisterSceneUndo("Convert to Atlas"); var allSprites = GameObject.FindObjectsOfType(typeof(MadSprite)) as MadSprite[]; var texturedSprites = from sprite in allSprites where sprite.inputType == MadSprite.InputType.SingleTexture && sprite.texture != null select sprite; var textures = from sprite in texturedSprites select sprite.texture; textures = textures.Distinct(); var atlas = MadAtlasBuilder.CreateAtlas(textures.ToArray()); if (atlas == null) { EditorUtility.DisplayDialog("Convert", "Conversion cancelled!", "OK"); return; } foreach (var sprite in texturedSprites) { sprite.inputType = MadSprite.InputType.TextureAtlas; sprite.textureAtlas = atlas; string guid = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(sprite.texture)); sprite.textureAtlasSpriteGUID = guid; EditorUtility.SetDirty(sprite); } EditorUtility.DisplayDialog("Convert", "Conversion done! Please save your scene!", "OK"); }