protected override void OnReset() { Type type = this.GetType(); LayoutViewDisplayAttributeAttribute settings = AttributeUtility.FindAttribute <LayoutViewDisplayAttributeAttribute>(type); if (settings == null) { throw new MissingReferenceException("Missing [LayoutSceneViewDisplay] attribute declaration for the class '" + type.Name + "'"); } SceneView sceneView = SceneView.currentDrawingSceneView; if (sceneView == null) { StratusDebug.Log("No scene view?"); return; } // Read and set the properties fron the attribute this.title = settings.GetProperty <string>("title"); this.size = new Vector2(settings.GetProperty <float>("width"), settings.GetProperty <float>("height")); this.anchor = settings.GetProperty <StratusGUI.Anchor>("anchor"); this.dimensions = settings.GetProperty <StratusGUI.Dimensions>("dimensions"); // If the size is relative... if (this.dimensions == StratusGUI.Dimensions.Relative) { this.scale = this.size; } // Calcualte the rect this.currentSize = this.CalculateSize(sceneView); this.rect = StratusGUI.CalculateAnchoredPositionOnScreen(this.anchor, this.currentSize, sceneView.position.size); }
//------------------------------------------------------------------------/ // Methods: Private //------------------------------------------------------------------------/ protected override void OnReset() { Type type = GetType(); var settings = AttributeUtility.FindAttribute <LayoutViewDisplayAttributeAttribute>(type); if (settings == null) { throw new MissingReferenceException("Missing [LayoutSceneViewDisplay] attribute declaration for the class '" + type.Name + "'"); } // Read and set the properties fron the attribute this.title = settings.GetProperty <string>("title"); this.size = new Vector2(settings.GetProperty <float>("width"), settings.GetProperty <float>("height")); this.anchor = settings.GetProperty <StratusGUI.Anchor>("anchor"); this.dimensions = settings.GetProperty <StratusGUI.Dimensions>("dimensions"); // If the size is relative... if (this.dimensions == StratusGUI.Dimensions.Relative) { scale = size; } }
/// <summary> /// Retrieves a specific attribute from the given type, if it is present /// </summary> /// <typeparam name="T"></typeparam> /// <param name="type"></param> /// <returns></returns> public static T GetAttribute <T>(this Type type) where T : Attribute { return(AttributeUtility.FindAttribute <T>(type)); }