示例#1
0
        /// <summary> get parent Cc class</summary>
        public static Type GetParentClass(Type ccType)
        {
            //gather required
            var requiredList = BGReflectionAdapter.GetCustomAttributes(ccType, typeof(RequireComponent), true);

            if (requiredList.Length == 0)
            {
                return(null);
            }

            var result = new List <Type>();

            foreach (var item  in requiredList)
            {
                var requiredComponent = (RequireComponent)item;
                CheckRequired(requiredComponent.m_Type0, result);
                CheckRequired(requiredComponent.m_Type1, result);
                CheckRequired(requiredComponent.m_Type2, result);
            }

            if (result.Count == 0)
            {
                return(null);
            }
            if (result.Count > 1)
            {
                throw new CcException(ccType + " has more than one parent (extended from BGCc class), calculated by RequireComponent attribute");
            }
            return(result[0]);
        }
示例#2
0
        //add class if it's not abstract and a child of BGCc
        private static void CheckRequired(Type type, List <Type> result)
        {
            if (type == null || BGReflectionAdapter.IsAbstract(type) || !BGReflectionAdapter.IsClass(type) || !BGReflectionAdapter.IsSubclassOf(type, typeof(BGCc)))
            {
                return;
            }

            result.Add(type);
        }
示例#3
0
        // get Unity's HelpURLAttribute attrubute
        private static HelpURLAttribute GetHelpUrl(Type type)
        {
            var propertyInfos = BGReflectionAdapter.GetCustomAttributes(type, typeof(HelpURLAttribute), false);

            if (propertyInfos.Length > 0)
            {
                return((HelpURLAttribute)propertyInfos[0]);
            }
            return(null);
        }
示例#4
0
        /// <summary>Retrieves the descriptor from "type"</summary>
        public static CcDescriptor GetDescriptor(Type type)
        {
            var propertyInfos = BGReflectionAdapter.GetCustomAttributes(type, typeof(CcDescriptor), false);

            if (propertyInfos.Length > 0)
            {
                return((CcDescriptor)propertyInfos[0]);
            }
            return(null);
        }
示例#5
0
 /// <summary> Check standard Unity's DisallowMultipleComponent attribute </summary>
 public static bool IsSingle(Type ccType)
 {
     return(BGReflectionAdapter.GetCustomAttributes(ccType, typeof(DisallowMultipleComponent), true).Length > 0);
 }
示例#6
0
        /// <summary>all methods, prefixed with Private, are not meant to be called from outside of BGCurve package </summary>
        // field added callback
        public static void PrivateFieldAdded(BGCurvePointField field, FieldsValues fieldsValues)
        {
            var type = FieldTypes.GetType(field.Type);
            var item = BGReflectionAdapter.IsValueType(type) ? Activator.CreateInstance(type) : null;

            switch (field.Type)
            {
            case BGCurvePointField.TypeEnum.Bool:
                Ensure(ref fieldsValues.boolValues);
                fieldsValues.boolValues = BGCurve.Insert(fieldsValues.boolValues, fieldsValues.boolValues.Length, (bool)item);
                break;

            case BGCurvePointField.TypeEnum.Int:
                Ensure(ref fieldsValues.intValues);
                fieldsValues.intValues = BGCurve.Insert(fieldsValues.intValues, fieldsValues.intValues.Length, (int)item);
                break;

            case BGCurvePointField.TypeEnum.Float:
                Ensure(ref fieldsValues.floatValues);
                fieldsValues.floatValues = BGCurve.Insert(fieldsValues.floatValues, fieldsValues.floatValues.Length, (float)item);
                break;

            case BGCurvePointField.TypeEnum.Vector3:
                Ensure(ref fieldsValues.vector3Values);
                fieldsValues.vector3Values = BGCurve.Insert(fieldsValues.vector3Values, fieldsValues.vector3Values.Length, (Vector3)item);
                break;

            case BGCurvePointField.TypeEnum.Bounds:
                Ensure(ref fieldsValues.boundsValues);
                fieldsValues.boundsValues = BGCurve.Insert(fieldsValues.boundsValues, fieldsValues.boundsValues.Length, (Bounds)item);
                break;

            case BGCurvePointField.TypeEnum.Color:
                Ensure(ref fieldsValues.colorValues);
                fieldsValues.colorValues = BGCurve.Insert(fieldsValues.colorValues, fieldsValues.colorValues.Length, (Color)item);
                break;

            case BGCurvePointField.TypeEnum.String:
                Ensure(ref fieldsValues.stringValues);
                fieldsValues.stringValues = BGCurve.Insert(fieldsValues.stringValues, fieldsValues.stringValues.Length, (string)item);
                break;

            case BGCurvePointField.TypeEnum.Quaternion:
                Ensure(ref fieldsValues.quaternionValues);
                fieldsValues.quaternionValues = BGCurve.Insert(fieldsValues.quaternionValues, fieldsValues.quaternionValues.Length, (Quaternion)item);
                break;

            case BGCurvePointField.TypeEnum.AnimationCurve:
                Ensure(ref fieldsValues.animationCurveValues);
                fieldsValues.animationCurveValues = BGCurve.Insert(fieldsValues.animationCurveValues, fieldsValues.animationCurveValues.Length, (AnimationCurve)item);
                break;

            case BGCurvePointField.TypeEnum.GameObject:
                Ensure(ref fieldsValues.gameObjectValues);
                fieldsValues.gameObjectValues = BGCurve.Insert(fieldsValues.gameObjectValues, fieldsValues.gameObjectValues.Length, (GameObject)item);
                break;

            case BGCurvePointField.TypeEnum.Component:
                Ensure(ref fieldsValues.componentValues);
                fieldsValues.componentValues = BGCurve.Insert(fieldsValues.componentValues, fieldsValues.componentValues.Length, (Component)item);
                break;

            case BGCurvePointField.TypeEnum.BGCurve:
                Ensure(ref fieldsValues.bgCurveValues);
                fieldsValues.bgCurveValues = BGCurve.Insert(fieldsValues.bgCurveValues, fieldsValues.bgCurveValues.Length, (BGCurve)item);
                break;

            case BGCurvePointField.TypeEnum.BGCurvePointComponent:
                Ensure(ref fieldsValues.bgCurvePointComponentValues);
                fieldsValues.bgCurvePointComponentValues = BGCurve.Insert(fieldsValues.bgCurvePointComponentValues, fieldsValues.bgCurvePointComponentValues.Length, (BGCurvePointComponent)item);
                break;

            case BGCurvePointField.TypeEnum.BGCurvePointGO:
                Ensure(ref fieldsValues.bgCurvePointGOValues);
                fieldsValues.bgCurvePointGOValues = BGCurve.Insert(fieldsValues.bgCurvePointGOValues, fieldsValues.bgCurvePointGOValues.Length, (BGCurvePointGO)item);
                break;

            default:
                throw new ArgumentOutOfRangeException("field.Type", field.Type, "Unsupported type " + field.Type);
            }
        }