コード例 #1
0
ファイル: ViewBase.cs プロジェクト: Hengle/Hermit
        /// <summary>
        /// Should be call manually.
        /// </summary>
        public virtual void SetUpViewInfo()
        {
            ViewManager = Her.Resolve <IViewManager>();

            DataBindings = GetComponentsInChildren <DataBindingBase>();
            ViewId       = ViewManager.Register(this);
        }
コード例 #2
0
ファイル: DataBindingBase.cs プロジェクト: Hengle/Hermit
        protected (Component component, MemberInfo memberInfo) ParseViewEntry(Component viewProvider,
                                                                              string entry)
        {
            var(typeName, memberName) = ParseEntry2TypeMember(entry);

            var component = viewProvider.GetComponent(typeName);

            if (component == null)
            {
                Her.Error($"Can't find component of type: {typeName} on {viewProvider}.");
                return(null, null);
            }

            var viewMemberInfos = component.GetType().GetMember(memberName);

            if (viewMemberInfos.Length <= 0)
            {
                Her.Error($"Can't find member of name: {memberName} on {component}.");
                return(null, null);
            }

            var memberInfo = viewMemberInfos[0];

            return(component, memberInfo);
        }
コード例 #3
0
ファイル: DataBindingBase.cs プロジェクト: Hengle/Hermit
        protected (string typeName, string memberName) ParseEntry2TypeMember(string entry)
        {
            var lastPeriodIndex = entry.LastIndexOf('.');

            if (lastPeriodIndex == -1)
            {
                throw new Exception($"No period was found[{entry}] on {name}");
            }

            var typeName   = entry.Substring(0, lastPeriodIndex);
            var memberName = entry.Substring(lastPeriodIndex + 1);

            //Due to (undocumented) unity behaviour, some of their components do not work with the namespace when using GetComponent(""), and all of them work without the namespace
            //So to be safe, we remove all namespaces from any component that starts with UnityEngine
            if (typeName.StartsWith("UnityEngine."))
            {
                typeName = typeName.Substring(typeName.LastIndexOf('.') + 1);
            }

            if (typeName.Length == 0 || memberName.Length == 0)
            {
                Her.Error($"Bad formatting! Expected [<type-name>.<member-name>]: {entry} ");
                return(null, null);
            }

            return(typeName, memberName);
        }
コード例 #4
0
ファイル: ViewBase.cs プロジェクト: Hengle/Hermit
        public void SetViewModel(object context)
        {
            if (context is TViewModel viewModel)
            {
                DataContext = viewModel;
            }
            else
            {
                Her.Warn($"{context} is not matching {typeof(TViewModel)}");
            }

            DataReadyEvent?.Invoke();
        }
コード例 #5
0
ファイル: DataBindingBase.cs プロジェクト: Hengle/Hermit
        protected MemberInfo ParseViewModelEntry(ViewModel viewModel, string entry)
        {
            var(_, memberName) = ParseEntry2TypeMember(entry);

            var viewMemberInfos = viewModel.GetType().GetMember(memberName);

            if (viewMemberInfos.Length <= 0)
            {
                Her.Error($"Can't find member of name: {memberName} on {viewModel}.");
                return(null);
            }

            var memberInfo = viewMemberInfos[0];

            return(memberInfo);
        }
コード例 #6
0
 public DefaultCollectionChangedHandler()
 {
     ViewManager = Her.Resolve <IViewManager>();
 }