Exemplo n.º 1
0
    protected override void Awake()
    {
        base.Awake();

        root = transform.parent.GetComponentInParent <BindRoot>();
        root.Subscribe(this);
    }
Exemplo n.º 2
0
        public static void Check(BindRoot bindRoot)
        {
            var root       = bindRoot.gameObject;
            var scriptName = bindRoot.ScriptName;

            if (!VeeUtils.CheckStringValid(scriptName))
            {
                Debug.LogWarning("Bind Root Name is NOT valid on gameobject " + root.name);
                return;
            }

            var fullClassName = scriptName;

            if (VeeUtils.CheckStringValid(bindRoot.NameSpace))
            {
                fullClassName = bindRoot.NameSpace + "." + scriptName;
            }
            var types = ReflectionHelper.GetTypesInAllLoadedAssemblies(t => t.FullName == fullClassName).ToList();

            if (types.Count <= 0)
            {
                Debug.LogWarning($"Not Found class [{fullClassName}] in Assemblies");
                return;
            }

            if (types.Count > 1)
            {
                Debug.LogWarning($"Multy Type found for class [{scriptName}], please fill nameSpace ");
                return;
            }

            var comType = types[0];
            var com     = bindRoot.gameObject.GetComponent(comType);

            if (com == null)
            {
                Debug.LogWarning($"Not Found {fullClassName} Component on {root.name}");
                return;
            }

            var eles     = root.GetComponentsInChildren <BindElement>(true);
            var oldNames = new List <string>();

            foreach (var ele in eles)
            {
                if (ele.RootName != scriptName)
                {
                    continue;
                }

                var eleBindName = ele.BindName;
                if (oldNames.Contains(eleBindName))
                {
                    Debug.LogWarning($"Checking bindname [{eleBindName}] on [{ele.gameObject.name}], name Repeated !!!");
                }
                else
                {
                    oldNames.Add(eleBindName);
                    Debug.Log($"Checking bindname [{eleBindName}] on [{ele.gameObject.name}]");
                }

                var bindField = comType.GetField(eleBindName);
                if (bindField == null)
                {
                    Debug.LogWarning($"BindElement [{eleBindName}] is not a field of {scriptName}");
                    continue;
                }

                var fieldType = bindField.FieldType;
                var eleType   = ele.EleType;

                if (fieldType != eleType)
                {
                    Debug.LogWarning($"BindElement [{eleBindName}] Type [{ele.Type}] not matching field type [{bindField.FieldType}] in {scriptName}");
                    continue;
                }

                UnityEngine.Object eleClass = null;
                if (fieldType.FullName == "UnityEngine.GameObject")
                {
                    eleClass = ele.gameObject;
                }
                else
                {
                    eleClass = ele.gameObject.GetComponent(fieldType);
                }

                if (eleClass == null)
                {
                    Debug.LogWarning($"Not Found [{fieldType}] Class on [{ele.gameObject}], bind name [{eleBindName}]");
                    continue;
                }

                if (bindField.GetValue(com) != (object)eleClass)
                {
                    Debug.Log($"[{eleBindName}] is filled");
                    bindField.SetValue(com, eleClass);
                }
            }

            Debug.Log($"Check finished on [{bindRoot.ScriptName}]");
        }
Exemplo n.º 3
0
 protected virtual void Awake()
 {
     root = GetComponentInParent <BindRoot>();
     root.Subscribe(this);
 }