示例#1
0
        /// <summary>
        /// 类型转换。
        /// 注意:如果T非UMonoActorComponent子类,这个方法可能返回新对象。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static T Cast <T>(UObject obj) where T : UObject, new()
        {
            if (obj == null)
            {
                return(null);
            }

            var cast = obj as T;

            if (cast != null)
            {
                return(cast);
            }

            if (typeof(T).IsSubclassOf(typeof(UMonoActorComponent)))
            {
                return(GetManagedObject(obj) as T);
            }
            if (obj.IsChildOf <T>())
            {
                var newObj = new T {
                    _this = obj._this
                };
                return(newObj);
            }

            return(null);
        }
示例#2
0
文件: UObject.cs 项目: ycllz/UnrealCS
        /// <summary>
        /// 类型转换。
        /// 注意:如果T非UMonoActorComponent子类,这个方法可能返回新对象。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static T Cast <T>(UObject obj) where T : UObject, new()
        {
            if (obj == null)
            {
                return(null);
            }
            if (obj is T)
            {
                return(obj as T);
            }

            if (typeof(T).IsSubclassOf(typeof(UMonoActorComponent)))
            {
                return(GetManagedObject(obj) as T);
            }
            if (obj.IsChildOf <T>())
            {
                T newObj = new T();
                newObj._this = obj._this;
                return(newObj);
            }

            return(null);
        }