Exemplo n.º 1
0
        public override object GetValue(object component)
        {
            UrhoBackend.Serializable wrapper = component as UrhoBackend.Serializable;
            PropertyGridTypeHandler  handler = component as PropertyGridTypeHandler;

            if (handler != null && wrapper == null)
            {
                wrapper = handler.wrapper;
            }

            if (wrapper != null)
            {
                UrhoBackend.Variant var = wrapper.GetAttribute(attrName_);

                /*if (type_ == typeof(UrhoBackend.ResourceRefList))
                 *  return var.GetResourceRefList().ToList();
                 * else */if (attrInfo_.EnumNames != null && attrInfo_.EnumNames.Count > 0)
                {
                    return(attrInfo_.EnumNames[var.GetInt()]);
                }
                else if (type_ == typeof(UrhoBackend.Quaternion))
                {
                    return(var.GetQuaternion().ToEulerAngles());
                }
                else if (type_ == typeof(UrhoBackend.VariantMap))
                {
                    if (!source_.Equals(wrapper) || lastReturn_ == null)
                    {
                        source_     = wrapper;
                        lastReturn_ = VariantMapRecord.Get(wrapper, this, var.GetVariantMap());;
                        return(lastReturn_);
                    }
                    return(lastReturn_);
                }
                else if (type_ == typeof(UrhoBackend.VariantVector))
                {
                    return(VariantVectorRecord.From(var.GetVariantVector()));
                }
                return(VariantTranslate.ExtractFromVariant(var));
            }
            return(null);
        }
Exemplo n.º 2
0
        public override void SetValue(object component, object value)
        {
            UrhoBackend.Serializable wrapper = component as UrhoBackend.Serializable;
            PropertyGridTypeHandler  handler = component as PropertyGridTypeHandler;

            if (handler != null && wrapper == null)
            {
                wrapper = handler.wrapper;
            }

            if (wrapper != null)
            {
                if (type_ == typeof(UrhoBackend.ResourceRef))
                {
                    UrhoBackend.ResourceRef newRef  = value as UrhoBackend.ResourceRef;
                    UrhoBackend.ResourceRef baseRef = wrapper.GetAttributeDefault(attrName_).GetResourceRef();
                    baseRef.SetResourceName(newRef.GetName());
                    wrapper.SetAttribute(attrName_, VariantTranslate.VariantFromObject(baseRef));
                }
                //else if (type_ == typeof(UrhoBackend.ResourceRefList))
                //{
                //    List<string> list = value as List<string>;
                //    if (list != null)
                //    {
                //        UrhoBackend.ResourceRefList baseList = wrapper.GetAttributeDefault(attrName_).GetResourceRefList();
                //        baseList.FromList(list);
                //        wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(baseList));
                //    }
                //}
                else if (attrInfo_.EnumNames != null && attrInfo_.EnumNames.Count > 0)
                {
                    int index = attrInfo_.EnumNames.IndexOf(value.ToString());
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(index));
                }
                else if (type_ == typeof(UrhoBackend.Quaternion))
                {
                    UrhoBackend.Vector3    vec3 = value as UrhoBackend.Vector3;
                    UrhoBackend.Quaternion quat = new UrhoBackend.Quaternion();
                    quat.FromEulerAngles(vec3.x, vec3.y, vec3.z);
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(quat));
                }
                else if (type_ == typeof(UrhoBackend.VariantMap))
                {
                    VariantMapList         records = lastReturn_ as VariantMapList; // value as VariantMapList;
                    UrhoBackend.VariantMap newMap  = new UrhoBackend.VariantMap();
                    VariantMapRecord.Fill(newMap, records);
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(newMap));
                    VariableUtils.SetVariableNames(wrapper, records);
                }
                else if (type_ == typeof(UrhoBackend.VariantVector))
                {
                    List <VariantVectorRecord> records = value as List <VariantVectorRecord>;
                    UrhoBackend.VariantVector  newVec  = new UrhoBackend.VariantVector();
                    VariantVectorRecord.To(newVec, records);
                    wrapper.SetAttribute(attrName_, new UrhoBackend.Variant(newVec));
                }
                else
                {
                    wrapper.SetAttribute(attrName_, VariantTranslate.VariantFromObject(value));
                }
            }
            //\todo
        }