public override void OnInspectorGUI() { // get the target object SVGBackgroundBehaviour svgBackground = target as SVGBackgroundBehaviour; if (svgBackground != null) { this.DrawInspector(svgBackground); } }
// Reset is called when the user hits the Reset button in the Inspector's context menu or when adding the component the first time. // This function is only called in editor mode. Reset is most commonly used to give good default values in the inspector. void Reset() { this.Camera = null; this.Background = null; this.Atlas = null; this.Cards = null; this.m_SelectedCard0 = null; this.m_SelectedCard1 = null; this.m_Animating = false; }
void Start() { // start with the "idle" animation this.m_Animator = this.gameObject.GetComponent<Animator>(); this.IdleAnimation(); // move the background at world origin and get the reference to its monobehaviour script if (this.Background != null) { this.Background.transform.position = new Vector3(0, 0, 0); this.Background = this.Background.GetComponent<SVGBackgroundBehaviour>(); } // register handler for device orientation change this.Camera = (this.Camera != null) ? this.Camera.GetComponent<SVGCameraBehaviour>() : null; if (this.Camera != null) { // register ourself for receiving resize events this.Camera.OnResize += this.OnResize; // now fire a resize event by hand this.Camera.Resize(true); } }
private void DrawInspector(SVGBackgroundBehaviour svgBackground) { SVGBackgroundScaleType scaleAdaption = SVGBackgroundScaleType.Vertical; int size = 256; int slicedWidth = 256; int slicedHeight = 256; bool needUpdate = false; bool fullUpdate = false; TextAsset svgFile = EditorGUILayout.ObjectField("SVG file", svgBackground.SVGFile, typeof(TextAsset), true) as TextAsset; bool sliced = EditorGUILayout.Toggle(new GUIContent("Sliced", "Check if you want to slice the background in order to fit specified width/height"), svgBackground.Sliced); if (sliced) { slicedWidth = EditorGUILayout.IntField(new GUIContent("Width", "Sliced width, in pixels"), svgBackground.SlicedWidth); slicedHeight = EditorGUILayout.IntField(new GUIContent("Height", "Sliced height, in pixels"), svgBackground.SlicedHeight); } else { scaleAdaption = (SVGBackgroundScaleType)EditorGUILayout.EnumPopup("Scale adaption", svgBackground.ScaleAdaption); size = EditorGUILayout.IntField(new GUIContent("Size", "Size in pixels"), svgBackground.Size); } Color clearColor = EditorGUILayout.ColorField("Clear color", svgBackground.ClearColor); bool generateOnStart = EditorGUILayout.Toggle(new GUIContent("Generate on Start()", "Generate the background texture/sprite on Start()"), svgBackground.GenerateOnStart); // show dimensions in pixel and world units EditorGUILayout.LabelField("Width (pixel unit)", svgBackground.PixelWidth.ToString()); EditorGUILayout.LabelField("Height (pixel units)", svgBackground.PixelHeight.ToString()); EditorGUILayout.LabelField("Width (world units)", svgBackground.WorldWidth.ToString()); EditorGUILayout.LabelField("Height (world units)", svgBackground.WorldHeight.ToString()); // update svg file, if needed if (svgFile != svgBackground.SVGFile) { svgBackground.SVGFile = svgFile; EditorUtility.SetDirty(svgBackground); needUpdate = true; // in this case we must destroy the current document and load the new one fullUpdate = true; } if (sliced != svgBackground.Sliced) { svgBackground.Sliced = sliced; EditorUtility.SetDirty(svgBackground); needUpdate = true; } if (sliced) { // update sliced width (in pixels), if needed if (slicedWidth != svgBackground.SlicedWidth) { svgBackground.SlicedWidth = slicedWidth; EditorUtility.SetDirty(svgBackground); needUpdate = true; } // update sliced height (in pixels), if needed if (slicedHeight != svgBackground.SlicedHeight) { svgBackground.SlicedHeight = slicedHeight; EditorUtility.SetDirty(svgBackground); needUpdate = true; } } else { // update scale adaption, if needed if (scaleAdaption != svgBackground.ScaleAdaption) { svgBackground.ScaleAdaption = scaleAdaption; EditorUtility.SetDirty(svgBackground); needUpdate = true; } // update size (in pixels), if needed if (size != svgBackground.Size) { svgBackground.Size = size; EditorUtility.SetDirty(svgBackground); needUpdate = true; } } // update clear color, if needed if (clearColor != svgBackground.ClearColor) { svgBackground.ClearColor = clearColor; EditorUtility.SetDirty(svgBackground); needUpdate = true; } // update "update on start" flag, if needed if (generateOnStart != svgBackground.GenerateOnStart) { svgBackground.GenerateOnStart = generateOnStart; EditorUtility.SetDirty(svgBackground); } // update the background, if needed if (needUpdate) svgBackground.UpdateBackground(fullUpdate); }
private void DrawInspector(SVGBackgroundBehaviour svgBackground) { SVGBackgroundScaleType scaleAdaption = SVGBackgroundScaleType.Vertical; int size = 256; int slicedWidth = 256; int slicedHeight = 256; bool needUpdate = false; bool fullUpdate = false; TextAsset svgFile = EditorGUILayout.ObjectField("SVG file", svgBackground.SVGFile, typeof(TextAsset), true) as TextAsset; bool sliced = EditorGUILayout.Toggle(new GUIContent("Sliced", "Check if you want to slice the background in order to fit specified width/height"), svgBackground.Sliced); if (sliced) { slicedWidth = EditorGUILayout.IntField(new GUIContent("Width", "Sliced width, in pixels"), svgBackground.SlicedWidth); slicedHeight = EditorGUILayout.IntField(new GUIContent("Height", "Sliced height, in pixels"), svgBackground.SlicedHeight); } else { scaleAdaption = (SVGBackgroundScaleType)EditorGUILayout.EnumPopup("Scale adaption", svgBackground.ScaleAdaption); size = EditorGUILayout.IntField(new GUIContent("Size", "Size in pixels"), svgBackground.Size); } Color clearColor = EditorGUILayout.ColorField("Clear color", svgBackground.ClearColor); bool generateOnStart = EditorGUILayout.Toggle(new GUIContent("Generate on Start()", "Generate the background texture/sprite on Start()"), svgBackground.GenerateOnStart); bool fastUpload = EditorGUILayout.Toggle(new GUIContent("Fast upload", "Use the fast native method (OpenGL/DirectX) to upload the texture to the GPU"), svgBackground.FastUpload); // show dimensions in pixel and world units EditorGUILayout.LabelField("Width (pixel unit)", svgBackground.PixelWidth.ToString()); EditorGUILayout.LabelField("Height (pixel units)", svgBackground.PixelHeight.ToString()); EditorGUILayout.LabelField("Width (world units)", svgBackground.WorldWidth.ToString()); EditorGUILayout.LabelField("Height (world units)", svgBackground.WorldHeight.ToString()); // update svg file, if needed if (svgFile != svgBackground.SVGFile) { svgBackground.SVGFile = svgFile; SVGUtils.MarkSceneDirty(); needUpdate = true; // in this case we must destroy the current document and load the new one fullUpdate = true; } if (sliced != svgBackground.Sliced) { svgBackground.Sliced = sliced; SVGUtils.MarkSceneDirty(); needUpdate = true; } if (sliced) { // update sliced width (in pixels), if needed if (slicedWidth != svgBackground.SlicedWidth) { svgBackground.SlicedWidth = slicedWidth; SVGUtils.MarkSceneDirty(); needUpdate = true; } // update sliced height (in pixels), if needed if (slicedHeight != svgBackground.SlicedHeight) { svgBackground.SlicedHeight = slicedHeight; SVGUtils.MarkSceneDirty(); needUpdate = true; } } else { // update scale adaption, if needed if (scaleAdaption != svgBackground.ScaleAdaption) { svgBackground.ScaleAdaption = scaleAdaption; SVGUtils.MarkSceneDirty(); needUpdate = true; } // update size (in pixels), if needed if (size != svgBackground.Size) { svgBackground.Size = size; SVGUtils.MarkSceneDirty(); needUpdate = true; } } // update clear color, if needed if (clearColor != svgBackground.ClearColor) { svgBackground.ClearColor = clearColor; SVGUtils.MarkSceneDirty(); needUpdate = true; } // update "update on start" flag, if needed if (generateOnStart != svgBackground.GenerateOnStart) { svgBackground.GenerateOnStart = generateOnStart; SVGUtils.MarkSceneDirty(); } // update "fast upload" flag, if needed if (fastUpload != svgBackground.FastUpload) { svgBackground.FastUpload = fastUpload; SVGUtils.MarkSceneDirty(); } // update the background, if needed if (needUpdate) { svgBackground.UpdateBackground(fullUpdate); } }