本文整理汇总了C#中Movie.CreateObject方法的典型用法代码示例。如果您正苦于以下问题:C# Movie.CreateObject方法的具体用法?C# Movie.CreateObject怎么用?C# Movie.CreateObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Movie
的用法示例。
在下文中一共展示了Movie.CreateObject方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToASObject
public static Value ConvertToASObject(object obj, Movie mv)
{
// Step1: Get object type
System.Type tp = obj.GetType();
UnityEngine.Debug.Log(String.Format ("Type of CS object to convert: {0} \n", tp.Name));
// Step 2: Create AS object of the correct type using CreateObject (defined in SFMovie for now)
// The ActionScript class must have a default constructor that accepts no arguments, otherwise we will
// get error# 1063
Value result = mv.CreateObject(tp.Name);
if(null == result || !result.IsValid())
{
return null;
}
// Step 3: Iterate over the properties of obj and fill in the corresponding members of the ASObject, if
// the members exist
// Also think about nested objects etc.
foreach (var propInfo in tp.GetProperties())
{
UnityEngine.Debug.Log(propInfo.PropertyType);
Value propertyValue = result.GetMember(propInfo.Name);
if (propertyValue == null)
{
continue;
}
if (propInfo.PropertyType == typeof(System.Int32))
{
result.SetMember(propInfo.Name, (Int32)propInfo.GetValue(obj, null));
}
else if (propInfo.PropertyType == typeof(String))
{
result.SetMember(propInfo.Name, (String)propInfo.GetValue(obj, null));
}
else if (propInfo.PropertyType == typeof(System.UInt32))
{
result.SetMember(propInfo.Name, propertyValue);
}
else if (propInfo.PropertyType == typeof(Double))
{
result.SetMember(propInfo.Name, (Double)propInfo.GetValue(obj, null));
}
else if (propInfo.PropertyType == typeof(System.Single)) // float
{
result.SetMember(propInfo.Name, (Single)propInfo.GetValue(obj, null));
}
else if (propInfo.PropertyType == typeof(System.Boolean))
{
result.SetMember(propInfo.Name, (Boolean)propInfo.GetValue(obj, null));
}
else
{
if(!propInfo.PropertyType.IsPrimitive )
{
propertyValue = ConvertToASObject(propInfo.GetValue(obj, null), mv);
result.SetMember(propInfo.Name, propertyValue);
}
else
{
UnityEngine.Debug.Log(String.Format("Trying to convert a not handled managed type{0}!", propInfo.PropertyType.Name));
}
}
}
return result;
}