Advertisement
Guest User

ChildXmlLayoutController

a guest
Mar 3rd, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.21 KB | None | 0 0
  1. using UnityEngine;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine.UI;
  6.  
  7. namespace UI.Xml.Tags
  8. {
  9.     public class ChildXmlLayoutTagHandler : ElementTagHandler
  10.     {
  11.         public override MonoBehaviour primaryComponent
  12.         {
  13.             get { return currentInstanceTransform.GetComponentInChildren<XmlLayout>(); }
  14.         }
  15.  
  16.         // don't use a prefab
  17.         public override string prefabPath
  18.         {
  19.             get { return null; }
  20.         }
  21.  
  22.         // Generate xsd documentation for this
  23.         public override bool isCustomElement
  24.         {
  25.             get { return true; }
  26.         }
  27.                
  28.         // No children permitted
  29.         public override string elementChildType
  30.         {
  31.             get { return null; }
  32.         }                
  33.  
  34.         public override Dictionary<string, string> attributes
  35.         {
  36.             get
  37.             {
  38.                 return new Dictionary<string, string>()
  39.                 {
  40.                     {"viewPath", "xs:string"},
  41.                     {"controller", "xs:string"}
  42.                 };
  43.             }
  44.         }
  45.  
  46.         public override void ApplyAttributes(AttributeDictionary attributesToApply)
  47.         {
  48.             // necessary for elements which don't use a prefab
  49.             MatchParentDimensions();
  50.  
  51.             currentXmlElement.name = "ChildXmlLayout";
  52.  
  53.             base.ApplyAttributes(attributesToApply);
  54.  
  55.             var viewPath = attributesToApply.GetValue<string>("viewPath");            
  56.  
  57.             if (String.IsNullOrEmpty(viewPath))
  58.             {
  59.                 Debug.LogWarning("[XmlLayout][Warning][ChildXmlLayout]:: The 'viewPath' attribute is required.");
  60.                 return;
  61.             }
  62.                              
  63.             Type controllerType = null;
  64.             var controllerTypeName = attributesToApply.GetValue<string>("controller");
  65.  
  66.             if (!String.IsNullOrEmpty(controllerTypeName))
  67.             {
  68.                 controllerType = Type.GetType(controllerTypeName, false, true);
  69.             }
  70.  
  71.             XmlLayoutFactory.Instantiate(currentInstanceTransform, viewPath, controllerType);                        
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement