/// <summary> /// Draws the snapping tool foldout. /// </summary> /// <param name="t"></param> public void DrawSnappingFoldout(Transform t) { EditorGUI.indentLevel = 0; //Add our toggle+foldout block for snapping. EditorGUILayout.BeginHorizontal(GUILayout.Width(15)); //we have to use a variable here, since we can't pass the EnableSnapping directly into a ref argument. var useSnapping = GlobalSnappingData.EnableSnapping; //if snapping is enabled, enable our advanced snapping options. GlobalSnappingData.SnappingFoldoutOpen = UnfinityGUIUtil.FoldoutToggle(GlobalSnappingData.SnappingFoldoutOpen, ref useSnapping, new GUIContent("Enable Snapping", "Enable or disable snapping on the selected object."));//, snappingStyle); GlobalSnappingData.EnableSnapping = useSnapping; //Check for closing everything down if the toggle button is clicked... if (GUI.changed) { if (!GlobalSnappingData.EnableSnapping && GlobalSnappingData.SnappingFoldoutOpen) { GlobalSnappingData.SnappingFoldoutOpen = false; } } //if the GUI changed, and the snapping foldout is open, enable snapping if (GUI.changed) { if (GlobalSnappingData.SnappingFoldoutOpen) { GlobalSnappingData.EnableSnapping = true; } } EditorGUILayout.EndHorizontal(); //if the GUI changed, and snapping was disabled, close the advanced foldout if (GUI.changed) { if (!GlobalSnappingData.EnableSnapping) { GlobalSnappingData.SnappingFoldoutOpen = false; } } //if the foldout is open, show our advanced options. if (GlobalSnappingData.SnappingFoldoutOpen) { //Indent the following line... EditorGUI.indentLevel = 1; AdvancedSnapping.DrawGUI(); } //Reset the indentation EditorGUI.indentLevel = 0; }
public void DrawInspector(Transform target) { Transform t = (Transform)target; //if we're only editing 1 object, otherwise we need to display an error message since multi-object //editing isn't currently supported by this extension. if (Selection.transforms.Length < 2) { // Replicate the standard transform inspector gui if the component isn't part of 2DToolkit if (t.gameObject.GetComponent("tk2dBaseSprite")) { var tk2dSpriteType = TransformInspectorUtility.GetType("tk2dBaseSprite"); var tk2dSprite = t.gameObject.GetComponent("tk2dBaseSprite"); //Get the sprite definition, so we can make sure it isn't null before preceding. MethodInfo tk2d_GetCurrentSpriteDef = tk2dSpriteType.GetMethod("GetCurrentSpriteDef", Type.EmptyTypes); object SpriteDef = tk2d_GetCurrentSpriteDef.Invoke(tk2dSprite, tk2d_GetCurrentSpriteDef.GetParameters()); //Try to check if the 2DToolkit sprite object is valid if (tk2dSprite != null && SpriteDef != null) { DrawSnappingFoldout(t); UnfinityGUIUtil.Unity4Space(); //We only need 2 vectors (X and Y) for 2DToolkit. No need to show the Z value. Vector3 position = EditorGUILayout.Vector2Field("Position", new Vector2(t.localPosition.x, t.localPosition.y)); UnfinityGUIUtil.Unity4Space(); //Again, we only need X and Y for scale. Vector2 scale = EditorGUILayout.Vector2Field("Size", new Vector2(TransformInspectorUtility.GetScaleFromClassName("tk2dBaseSprite", "scale", t).x, TransformInspectorUtility.GetScaleFromClassName("tk2dBaseSprite", "scale", t).y)); UnfinityGUIUtil.Unity4Space(); DrawRotationControls(t); //Leave some vertical space between areas! UnfinityGUIUtil.Unity4Space(); DrawLayerAndDepthControls(t); //allow the Z Depth to be set position.z = (float)EditorGUILayout.IntField("Z Depth", (int)t.localPosition.z); EditorGUI.indentLevel = 0; //Leave some vertical space between areas! EditorGUILayout.Space(); if (GUI.changed) { Undo.RecordObject(t, "Transform Change"); t.localPosition = this.FixIfNaN(position); t.localEulerAngles = this.FixIfNaN(EulerAngles); //Check if the scale is NaN var tk2DScale = new Vector3(scale.x, scale.y, 1); tk2DScale = this.FixIfNaN(tk2DScale); //Then copy it back //tk2dSprite.scale = new Vector2(tk2DScale.x, tk2DScale.y); TransformInspectorUtility.SetScaleFromClassName("tk2dBaseSprite", "scale", t, tk2DScale); //Retrieve the layer by name, and then set it. tk2dSprite.gameObject.layer = LayerMask.NameToLayer(GetSortedLayer()); //copy our changed sprite back to our target. EditorUtility.SetDirty(tk2dSprite); } } } } else { EditorGUILayout.LabelField("Multi-object editing is not supported at this time."); } }
public void DrawInspector(Transform target) { Transform t = (Transform)target; //if we're only editing 1 object, otherwise we need to display an error message since multi-object //editing isn't currently supported by this extension. if (Selection.transforms.Length < 2) { //Try to check if the generic object is valid if (target != null) { DrawSnappingFoldout(t); UnfinityGUIUtil.Unity4Space(); //We only need 2 vectors (X and Y) for 2DToolkit. No need to show the Z value. Vector3 position = EditorGUILayout.Vector2Field("Position", new Vector2(t.localPosition.x, t.localPosition.y)); UnfinityGUIUtil.Unity4Space(); //We can't show scale, since we don't know if this object even HAS scale... //Vector2 scale = EditorGUILayout.Vector2Field("Size", new Vector2(tk2dSprite.scale.x, tk2dSprite.scale.y)); DrawRotationControls(t); UnfinityGUIUtil.Unity4Space(); UnfinityGUIUtil.Unity4Space(); DrawLayerAndDepthControls(t); //allow the Z Depth to be set position.z = (float)EditorGUILayout.IntField("Z Depth", (int)t.localPosition.z); EditorGUI.indentLevel = 0; //Leave some vertical space between areas! EditorGUILayout.Space(); if (GUI.changed) { Undo.RecordObject(t, "Transform Change"); t.localPosition = this.FixIfNaN(position); t.localEulerAngles = this.FixIfNaN(EulerAngles); //Check if the scale is NaN //var tk2DScale = new Vector3(scale.x, scale.y, 0); //tk2DScale = this.FixIfNaN(tk2DScale); //Then copy it back //tk2dSprite.scale = new Vector2(tk2DScale.x, tk2DScale.y); //Retrieve the layer by name, and then set it. target.gameObject.layer = LayerMask.NameToLayer(GetSortedLayer()); //copy our changed sprite back to our target. EditorUtility.SetDirty(target); } } } else { EditorGUILayout.LabelField("Multi-object editing is not supported at this time."); } }
public void DrawInspector(Transform target) { Transform t = (Transform)target; //if we're only editing 1 object, otherwise we need to display an error message since multi-object //editing isn't currently supported by this extension. if (Selection.transforms.Length < 2) { // Replicate the standard transform inspector gui if the component isn't a Unity 4.3 sprite if (t.gameObject.GetComponent("SpriteRenderer")) { //var unitySpriteType = TransformInspectorUtility.GetType("SpriteRenderer"); var unitySprite = t.gameObject.GetComponent("SpriteRenderer"); //Try to check if the 2DToolkit sprite object is valid if (unitySprite != null) { DrawSnappingFoldout(t); UnfinityGUIUtil.Unity4Space(); //We only need 2 vectors (X and Y) for 2DToolkit. No need to show the Z value. Vector3 position = EditorGUILayout.Vector2Field("Position", new Vector2(t.localPosition.x, t.localPosition.y)); UnfinityGUIUtil.Unity4Space(); //Again, we only need X and Y for scale. //Vector2 scale = EditorGUILayout.Vector2Field("Size", //new Vector2(TransformInspectorUtility.GetScaleFromClassName("Sprite", "scale", t).x, //TransformInspectorUtility.GetScaleFromClassName("Sprite", "scale", t).y)); //Note: Do Unity sprite just use the Transform's scale? Vector2 scale = EditorGUILayout.Vector2Field("Size", new Vector2(t.localScale.x, t.localScale.y)); UnfinityGUIUtil.Unity4Space(); DrawRotationControls(t); //Leave some vertical space between areas! UnfinityGUIUtil.Unity4Space(); DrawLayerAndDepthControls(t); //allow the Z Depth to be set position.z = (float)EditorGUILayout.IntField("Z Depth", (int)t.localPosition.z); EditorGUI.indentLevel = 0; //Leave some vertical space between areas! EditorGUILayout.Space(); if (GUI.changed) { Undo.RecordObject(t, "Transform Change"); t.localPosition = this.FixIfNaN(position); t.localEulerAngles = this.FixIfNaN(EulerAngles); //Check if the scale is NaN var spriteScale = new Vector3(scale.x, scale.y, 1); spriteScale = this.FixIfNaN(spriteScale); t.localScale = spriteScale; //Then copy it back //tk2dSprite.scale = new Vector2(tk2DScale.x, tk2DScale.y); //TransformInspectorUtility.SetScaleFromClassName("SpriteRenderer", "scale", t, tk2DScale); //Retrieve the layer by name, and then set it. unitySprite.gameObject.layer = LayerMask.NameToLayer(GetSortedLayer()); //copy our changed sprite back to our target. EditorUtility.SetDirty(unitySprite); } } } } else { EditorGUILayout.LabelField("Multi-object editing is not supported at this time."); } }