public override BaseResponse GenerateResponse()
        {
            object          targetObject     = ObjectMap.GetObjectFromGUID(guid);
            WrappedVariable returnedVariable = null;

            if (targetObject != null)
            {
                Type[] parameterTypes = new Type[wrappedParameters.Length];
                for (int i = 0; i < wrappedParameters.Length; i++)
                {
                    parameterTypes[i] = DataTypeHelper.GetSystemTypeFromWrappedDataType(wrappedParameters[i].DataType, wrappedParameters[i].MetaData, wrappedParameters[i].Attributes);
                }
                MethodInfo methodInfo = targetObject.GetType().GetMethod(methodName, GetGameObjectRequest.BINDING_FLAGS, null, parameterTypes, null);
                Debug.Assert(methodInfo != null, "Couldn't find a matching method for signature");
                object[] parameters = new object[wrappedParameters.Length];
                for (int i = 0; i < wrappedParameters.Length; i++)
                {
                    parameters[i] = wrappedParameters[i].ValueNative;
                }
                object returnedValue = methodInfo.Invoke(targetObject, parameters);
                if (methodInfo.ReturnType == typeof(IEnumerator) && targetObject is MonoBehaviour)
                {
                    // Run it as a coroutine
                    MonoBehaviour monoBehaviour = (MonoBehaviour)targetObject;
                    monoBehaviour.StartCoroutine((IEnumerator)returnedValue);
                }
                returnedVariable = new WrappedVariable("", returnedValue, methodInfo.ReturnType, false);

                //Debug.Log(returnedValue);
            }

            return(new InvokeMethodResponse(methodName, returnedVariable));
        }
Example #2
0
        public void TestOperator()
        {
            var term1 = new WrappedFunction(CNTKLib.Log(new WrappedVariable(Constant.Scalar(DataType.Float, 3.0))));
            var term2 = new WrappedVariable(Variable.InputVariable(new int[] { 2, 2 }, DataType.Float));
            var exp   = term1 + term2;

            Assert.IsTrue(exp is WrappedFunction);
            Assert.AreEqual(((Function)exp).RootFunction.OpName, "Plus");
        }
Example #3
0
 public FindUnityObjectsResponse(WrappedVariable variable, ObjectPickerContext context, Object[] sourceObjects)
 {
     this.variable      = variable;
     this.context       = context;
     objectDescriptions = new UnityObjectDescription[sourceObjects.Length];
     for (int i = 0; i < sourceObjects.Length; i++)
     {
         objectDescriptions[i] = new UnityObjectDescription(sourceObjects[i]);
     }
 }
 public GetUnityObjectsResponse(WrappedVariable variable, Guid componentGuid, Object[] sourceObjects)
 {
     this.variable      = variable;
     this.componentGuid = componentGuid;
     objectDescriptions = new UnityObjectDescription[sourceObjects.Length];
     for (int i = 0; i < sourceObjects.Length; i++)
     {
         objectDescriptions[i] = new UnityObjectDescription(sourceObjects[i]);
     }
 }
Example #5
0
        public FindUnityObjectsResponse(BinaryReader br, int requestID)
            : base(br, requestID)
        {
            variable = new WrappedVariable(br);
            context  = new ObjectPickerContext(br);
            int count = br.ReadInt32();

            objectDescriptions = new UnityObjectDescription[count];
            for (int i = 0; i < count; i++)
            {
                objectDescriptions[i] = new UnityObjectDescription(br);
            }
        }
        public GetUnityObjectsResponse(BinaryReader br, int requestID)
            : base(br, requestID)
        {
            variable      = new WrappedVariable(br);
            componentGuid = new Guid(br.ReadString());
            int count = br.ReadInt32();

            objectDescriptions = new UnityObjectDescription[count];
            for (int i = 0; i < count; i++)
            {
                objectDescriptions[i] = new UnityObjectDescription(br);
            }
        }
 public SetVariableRequest(BinaryReader br)
 {
     this.guid            = new Guid(br.ReadString());
     this.wrappedVariable = new WrappedVariable(br);
 }
Example #8
0
 public GetUnityObjectsRequest(BinaryReader br)
 {
     this.variable      = new WrappedVariable(br);
     this.componentGuid = new Guid(br.ReadString());
 }
Example #9
0
 public GetUnityObjectsRequest(WrappedVariable variable, Guid componentGuid)
 {
     this.variable      = variable;
     this.componentGuid = componentGuid;
 }
Example #10
0
    public static object DrawIndividualVariable(ObjectPickerContext objectPickerContext, WrappedVariable variable, string fieldName, object fieldValue, OpenPickerCallback onObjectPicker, int index = 0)
    {
        object newValue;

        if (variable.DataType == DataType.Enum)
        {
            //Type underlyingType = variable.MetaData.GetTypeFromMetaData();
            int enumValueIndex = Array.IndexOf(variable.MetaData.EnumValues, fieldValue);
            enumValueIndex = EditorGUILayout.Popup(fieldName, enumValueIndex, variable.MetaData.EnumNames);

            newValue = variable.MetaData.EnumValues[enumValueIndex];
        }
        else if (variable.DataType == DataType.UnityObjectReference)
        {
            if (fieldValue is Guid)
            {
                EditorGUILayout.BeginHorizontal();
                Guid fieldValueGuid = (Guid)fieldValue;

                if (fieldValueGuid != Guid.Empty && variable.ValueDisplayNames.Length > index)
                {
                    EditorGUILayout.TextField(fieldName, variable.ValueDisplayNames[index]);
                }
                else
                {
                    EditorGUILayout.TextField(fieldName, "None (" + variable.MetaData.TypeFullName + ")");
                }

                if (objectPickerContext != null)
                {
                    if (GUILayout.Button("...", GUILayout.Width(30)))
                    {
                        onObjectPicker(objectPickerContext, variable);
                    }
                }

                bool guiEnabled = GUI.enabled;
                // Force GUI enabled on for this control
                GUI.enabled = (fieldValueGuid != Guid.Empty);
                if (GUILayout.Button("-->", GUILayout.Width(30)))
                {
                    APIManager       apiManager = BridgingContext.Instance.container.APIManager;
                    SidekickSettings settings   = BridgingContext.Instance.container.Settings;
                    apiManager.SendToPlayers(new GetObjectRequest((Guid)fieldValue, (InfoFlags)settings.GetGameObjectFlags));
                    Debug.Log(fieldValue);
                }

                GUI.enabled = guiEnabled;
                EditorGUILayout.EndHorizontal();

                newValue = fieldValue;
            }
            else
            {
                newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, variable.MetaData.GetTypeFromMetaData(), true);
            }
        }
        else if (variable.DataType == DataType.Integer)
        {
            newValue = EditorGUILayout.IntField(fieldName, (int)fieldValue);
        }
        else if (variable.DataType == DataType.Long)
        {
            newValue = EditorGUILayout.LongField(fieldName, (long)fieldValue);
        }
        else if (variable.DataType == DataType.String)
        {
            newValue = EditorGUILayout.TextField(fieldName, (string)fieldValue);
        }
        else if (variable.DataType == DataType.Char)
        {
            string newString = EditorGUILayout.TextField(fieldName, new string((char)fieldValue, 1));
            if (newString.Length == 1)
            {
                newValue = newString[0];
            }
            else
            {
                newValue = fieldValue;
            }
        }
        else if (variable.DataType == DataType.Float)
        {
            newValue = EditorGUILayout.FloatField(fieldName, (float)fieldValue);
        }
        else if (variable.DataType == DataType.Double)
        {
            newValue = EditorGUILayout.DoubleField(fieldName, (double)fieldValue);
        }
        else if (variable.DataType == DataType.Boolean)
        {
            newValue = EditorGUILayout.Toggle(fieldName, (bool)fieldValue);
        }
        else if (variable.DataType == DataType.Vector2)
        {
            newValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3)
        {
            newValue = EditorGUILayout.Vector3Field(fieldName, (Vector3)fieldValue);
        }
        else if (variable.DataType == DataType.Vector4)
        {
            newValue = EditorGUILayout.Vector4Field(fieldName, (Vector4)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.Vector2Int)
        {
            newValue = EditorGUILayout.Vector2IntField(fieldName, (Vector2Int)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3Int)
        {
            newValue = EditorGUILayout.Vector3IntField(fieldName, (Vector3Int)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Quaternion)
        {
            //if(InspectorSidekick.Current.Settings.RotationsAsEuler)
            //{
            //  Quaternion quaternion = (Quaternion)fieldValue;
            //  Vector3 eulerAngles = quaternion.eulerAngles;
            //  eulerAngles = EditorGUILayout.Vector3Field(fieldName, eulerAngles);
            //  newValue = Quaternion.Euler(eulerAngles);
            //}
            //else
            {
                Quaternion quaternion = (Quaternion)fieldValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector   = EditorGUILayout.Vector4Field(fieldName, vector);
                newValue = new Quaternion(vector.x, vector.y, vector.z, vector.z);
            }
        }
        else if (variable.DataType == DataType.Bounds)
        {
            newValue = EditorGUILayout.BoundsField(fieldName, (Bounds)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.BoundsInt)
        {
            newValue = EditorGUILayout.BoundsIntField(fieldName, (BoundsInt)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Color)
        {
            newValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
        }
        else if (variable.DataType == DataType.Color32)
        {
            newValue = (Color32)EditorGUILayout.ColorField(fieldName, (Color32)fieldValue);
        }
        else if (variable.DataType == DataType.Gradient)
        {
            newValue = InternalEditorGUILayout.GradientField(new GUIContent(fieldName), (Gradient)fieldValue);
        }
        else if (variable.DataType == DataType.AnimationCurve)
        {
            newValue = EditorGUILayout.CurveField(fieldName, (AnimationCurve)fieldValue);
        }
        else if (variable.DataType == DataType.Rect)
        {
            newValue = EditorGUILayout.RectField(fieldName, (Rect)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.RectInt)
        {
            newValue = EditorGUILayout.RectIntField(fieldName, (RectInt)fieldValue);
        }
#endif
        else
        {
            GUILayout.Label(fieldName);
            newValue = fieldValue;
        }

        return(newValue);
    }
        public override BaseResponse GenerateResponse()
        {
            GetGameObjectResponse getGOResponse = new GetGameObjectResponse();

            Transform foundTransform = TransformHelper.GetFromPath(gameObjectPath);

            getGOResponse.GameObjectName = foundTransform.name;

            List <Object> components = new List <Object>(foundTransform.GetComponents <Component>());

            // Not technically a component, but include the GameObject
            components.Insert(0, foundTransform.gameObject);
            getGOResponse.Components = new List <ComponentDescription>(components.Count);
            foreach (Object component in components)
            {
                //Guid guid = ObjectMap.AddOrGetObject(component);
                ObjectMap.AddOrGetObject(component);

                ComponentDescription description = new ComponentDescription(component);
                Type componentType = component.GetType();

                while (componentType != null &&
                       componentType != typeof(System.Object) &&
                       componentType != typeof(UnityEngine.Object) &&
                       componentType != typeof(UnityEngine.Component))
                {
                    ComponentScope componentScope = new ComponentScope(componentType);
                    if ((flags & InfoFlags.Fields) == InfoFlags.Fields)
                    {
                        FieldInfo[] fieldInfos = componentType.GetFields(BINDING_FLAGS);
                        foreach (FieldInfo fieldInfo in fieldInfos)
                        {
                            if (TypeUtility.IsBackingField(fieldInfo, componentType))
                            {
                                // Skip backing fields for auto-implemented properties
                                continue;
                            }

                            object objectValue = fieldInfo.GetValue(component);

                            WrappedVariable wrappedVariable = new WrappedVariable(fieldInfo, objectValue);
                            componentScope.Fields.Add(wrappedVariable);
                        }
                    }

                    if (componentType == typeof(GameObject)) // Special handling for GameObject.name to always be included
                    {
                        PropertyInfo    nameProperty = componentType.GetProperty("name", BindingFlags.Public | BindingFlags.Instance);
                        WrappedVariable wrappedName  = new WrappedVariable(nameProperty, nameProperty.GetValue(component, null));
                        componentScope.Properties.Add(wrappedName);
                    }

                    if ((flags & InfoFlags.Properties) == InfoFlags.Properties)
                    {
                        PropertyInfo[] properties = componentType.GetProperties(BINDING_FLAGS);
                        foreach (PropertyInfo property in properties)
                        {
                            Type declaringType = property.DeclaringType;
                            if (declaringType == typeof(Component) ||
                                declaringType == typeof(UnityEngine.Object))
                            {
                                continue;
                            }

                            object[] attributes          = property.GetCustomAttributes(false);
                            bool     isObsoleteWithError = AttributeHelper.IsObsoleteWithError(attributes);
                            if (isObsoleteWithError)
                            {
                                continue;
                            }

                            // Skip properties that cause exceptions at edit time
                            if (Application.isPlaying == false)
                            {
                                if (typeof(MeshFilter).IsAssignableFrom(declaringType))
                                {
                                    if (property.Name == "mesh")
                                    {
                                        continue;
                                    }
                                }

                                if (typeof(Renderer).IsAssignableFrom(declaringType))
                                {
                                    if (property.Name == "material" || property.Name == "materials")
                                    {
                                        continue;
                                    }
                                }
                            }



                            string propertyName = property.Name;

                            MethodInfo getMethod = property.GetGetMethod(true);
                            if (getMethod != null)
                            {
                                //MethodImplAttributes methodImplAttributes = getMethod.GetMethodImplementationFlags();
                                //if ((methodImplAttributes & MethodImplAttributes.InternalCall) != 0)
                                //{
                                //    continue;
                                //}


                                object objectValue = getMethod.Invoke(component, null);

                                WrappedVariable wrappedVariable = new WrappedVariable(property, objectValue);
                                componentScope.Properties.Add(wrappedVariable);
                            }
                        }
                    }

                    if ((flags & InfoFlags.Methods) == InfoFlags.Methods)
                    {
                        MethodInfo[] methodInfos = componentType.GetMethods(BINDING_FLAGS);
                        foreach (var methodInfo in methodInfos)
                        {
                            if (TypeUtility.IsPropertyMethod(methodInfo, componentType))
                            {
                                // Skip automatically generated getter/setter methods
                                continue;
                            }

                            MethodImplAttributes methodImplAttributes = methodInfo.GetMethodImplementationFlags();
                            if ((methodImplAttributes & MethodImplAttributes.InternalCall) != 0 && methodInfo.Name.StartsWith("INTERNAL_"))
                            {
                                // Skip any internal method if it also begins with INTERNAL_
                                continue;
                            }
                            WrappedMethod wrappedMethod = new WrappedMethod(methodInfo);
                            componentScope.Methods.Add(wrappedMethod);
                        }
                    }

                    description.Scopes.Add(componentScope);

                    componentType = componentType.BaseType;
                }

                getGOResponse.Components.Add(description);
            }
            return(getGOResponse);
        }
 public GetUnityObjectsRequest(BinaryReader br)
 {
     this.variable = new WrappedVariable(br);
     this.context  = new ObjectPickerContext(br);
 }
Example #13
0
    public static object DrawIndividualVariable(ComponentDescription componentDescription, WrappedVariable variable, string fieldName, Type fieldType, object fieldValue, Action <Guid, WrappedVariable> onObjectPicker)
    {
        object newValue;

        if (variable.DataType == DataType.Enum)
        {
            newValue = EditorGUILayout.IntPopup(fieldName, (int)fieldValue, variable.MetaData.EnumNames, variable.MetaData.EnumValues);
        }
        else if (variable.DataType == DataType.UnityObjectReference)
        {
            if (fieldValue is Guid)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUILayout.PrefixLabel(fieldName);
                if ((Guid)fieldValue != Guid.Empty)
                {
                    EditorGUILayout.TextField(variable.MetaData.ValueDisplayName);
                }
                else
                {
                    EditorGUILayout.TextField("None (" + variable.MetaData.TypeFullName + ")");
                }
                if (componentDescription != null)
                {
                    if (GUILayout.Button("...", GUILayout.Width(30)))
                    {
                        onObjectPicker(componentDescription.Guid, variable);
                    }
                }
                EditorGUILayout.EndHorizontal();

                newValue = fieldValue;
            }
            else if (typeof(UnityEngine.Object).IsAssignableFrom(fieldType))
            {
                newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, variable.MetaData.GetTypeFromMetaData(), true);
            }
            else
            {
                throw new NotSupportedException();
            }
        }
        else if (fieldType == typeof(int) ||
                 (fieldType.IsSubclassOf(typeof(Enum)) && OldInspectorSidekick.Current.Settings.TreatEnumsAsInts))
        {
            newValue = EditorGUILayout.IntField(fieldName, (int)fieldValue);
        }
        else if (fieldType == typeof(long))
        {
            newValue = EditorGUILayout.LongField(fieldName, (long)fieldValue);
        }
        else if (fieldType == typeof(string))
        {
            newValue = EditorGUILayout.TextField(fieldName, (string)fieldValue);
        }
        else if (fieldType == typeof(char))
        {
            string newString = EditorGUILayout.TextField(fieldName, new string((char)fieldValue, 1));
            if (newString.Length == 1)
            {
                newValue = newString[0];
            }
            else
            {
                newValue = fieldValue;
            }
        }
        else if (fieldType == typeof(float))
        {
            newValue = EditorGUILayout.FloatField(fieldName, (float)fieldValue);
        }
        else if (fieldType == typeof(double))
        {
            newValue = EditorGUILayout.DoubleField(fieldName, (double)fieldValue);
        }
        else if (fieldType == typeof(bool))
        {
            newValue = EditorGUILayout.Toggle(fieldName, (bool)fieldValue);
        }
        else if (fieldType == typeof(Vector2))
        {
            newValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
        }
        else if (fieldType == typeof(Vector3))
        {
            newValue = EditorGUILayout.Vector3Field(fieldName, (Vector3)fieldValue);
        }
        else if (fieldType == typeof(Vector4))
        {
            newValue = EditorGUILayout.Vector4Field(fieldName, (Vector4)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (fieldType == typeof(Vector2Int))
        {
            newValue = EditorGUILayout.Vector2IntField(fieldName, (Vector2Int)fieldValue);
        }
        else if (fieldType == typeof(Vector3Int))
        {
            newValue = EditorGUILayout.Vector3IntField(fieldName, (Vector3Int)fieldValue);
        }
#endif
        else if (fieldType == typeof(Quaternion))
        {
            //if(InspectorSidekick.Current.Settings.RotationsAsEuler)
            //{
            //  Quaternion quaternion = (Quaternion)fieldValue;
            //  Vector3 eulerAngles = quaternion.eulerAngles;
            //  eulerAngles = EditorGUILayout.Vector3Field(fieldName, eulerAngles);
            //  newValue = Quaternion.Euler(eulerAngles);
            //}
            //else
            {
                Quaternion quaternion = (Quaternion)fieldValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector   = EditorGUILayout.Vector4Field(fieldName, vector);
                newValue = new Quaternion(vector.x, vector.y, vector.z, vector.z);
            }
        }
        else if (fieldType == typeof(Bounds))
        {
            newValue = EditorGUILayout.BoundsField(fieldName, (Bounds)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (fieldType == typeof(BoundsInt))
        {
            newValue = EditorGUILayout.BoundsIntField(fieldName, (BoundsInt)fieldValue);
        }
#endif
        else if (fieldType == typeof(Color))
        {
            newValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
        }
        else if (fieldType == typeof(Color32))
        {
            newValue = (Color32)EditorGUILayout.ColorField(fieldName, (Color32)fieldValue);
        }
        else if (fieldType == typeof(Gradient))
        {
            newValue = InternalEditorGUILayout.GradientField(new GUIContent(fieldName), (Gradient)fieldValue);
        }
        else if (fieldType == typeof(AnimationCurve))
        {
            newValue = EditorGUILayout.CurveField(fieldName, (AnimationCurve)fieldValue);
        }
        else if (fieldType.IsSubclassOf(typeof(Enum)))
        {
            newValue = EditorGUILayout.EnumPopup(fieldName, (Enum)fieldValue);
        }
        else if (fieldType == typeof(Rect))
        {
            newValue = EditorGUILayout.RectField(fieldName, (Rect)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (fieldType == typeof(RectInt))
        {
            newValue = EditorGUILayout.RectIntField(fieldName, (RectInt)fieldValue);
        }
#endif
        else if (fieldType.IsSubclassOf(typeof(UnityEngine.Object)))
        {
            newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, fieldType, true);
        }
        else
        {
            GUILayout.Label(fieldType + " " + fieldName);
            newValue = fieldValue;
        }



        //          EditorGUILayout.BoundsField()
        //          EditorGUILayout.ColorField
        //          EditorGUILayout.CurveField
        //          EditorGUILayout.EnumPopup
        //          EditorGUILayout.EnumMaskField
        //          EditorGUILayout.IntSlider // If there's a range attribute maybe?
        //          EditorGUILayout.LabelField // what's this?
        //          EditorGUILayout.ObjectField
        //          EditorGUILayout.RectField
        //          EditorGUILayout.TextArea
        //          EditorGUILayout.TextField

        // What's this? public static void HelpBox (string message, MessageType type, bool wide)
        // What's this?         public static bool InspectorTitlebar (bool foldout, Object targetObj)

        return(newValue);
    }
 public SetVariableRequest(Guid guid, WrappedVariable wrappedVariable)
 {
     this.guid            = guid;
     this.wrappedVariable = wrappedVariable;
 }
Example #15
0
 public InvokeMethodResponse(BinaryReader br, int requestID)
     : base(br, requestID)
 {
     methodName       = br.ReadString();
     returnedVariable = new WrappedVariable(br);
 }
Example #16
0
 public InvokeMethodResponse(string methodName, WrappedVariable returnedVariable)
 {
     this.methodName       = methodName;
     this.returnedVariable = returnedVariable;
 }
Example #17
0
        public override BaseResponse GenerateResponse()
        {
            GetGameObjectResponse getGOResponse = new GetGameObjectResponse();

            Transform foundTransform = TransformHelper.GetFromPath(gameObjectPath);

            getGOResponse.GameObjectName = foundTransform.name;

            List <Object> components = new List <Object>(foundTransform.GetComponents <Component>());

            // Not technically a component, but include the GameObject
            components.Insert(0, foundTransform.gameObject);
            getGOResponse.Components = new List <ComponentDescription>(components.Count);
            foreach (Object component in components)
            {
                //Guid guid = ObjectMap.AddOrGetObject(component);
                ObjectMap.AddOrGetObject(component);

                ComponentDescription description = new ComponentDescription(component);
                Type componentType = component.GetType();

                if ((flags & InfoFlags.Fields) == InfoFlags.Fields)
                {
                    FieldInfo[] fieldInfos = componentType.GetFields(GetGameObjectRequest.BINDING_FLAGS);
                    foreach (FieldInfo fieldInfo in fieldInfos)
                    {
                        if (TypeUtility.IsBackingField(fieldInfo, componentType))
                        {
                            // Skip backing fields for auto-implemented properties
                            continue;
                        }

                        object objectValue = fieldInfo.GetValue(component);

                        WrappedVariable wrappedVariable = new WrappedVariable(fieldInfo, objectValue);
                        description.Fields.Add(wrappedVariable);
                    }
                }

                if ((flags & InfoFlags.Properties) == InfoFlags.Properties)
                {
                    PropertyInfo[] properties = componentType.GetProperties(GetGameObjectRequest.BINDING_FLAGS);
                    foreach (PropertyInfo property in properties)
                    {
                        Type declaringType = property.DeclaringType;
                        if (declaringType == typeof(Component) ||
                            declaringType == typeof(UnityEngine.Object))
                        {
                            continue;
                        }

                        object[] attributes          = property.GetCustomAttributes(false);
                        bool     isObsoleteWithError = AttributeHelper.IsObsoleteWithError(attributes);
                        if (isObsoleteWithError)
                        {
                            continue;
                        }

                        // Skip properties that cause exceptions at edit time
                        if (Application.isPlaying == false)
                        {
                            if (typeof(MeshFilter).IsAssignableFrom(declaringType))
                            {
                                if (property.Name == "mesh")
                                {
                                    continue;
                                }
                            }

                            if (typeof(Renderer).IsAssignableFrom(declaringType))
                            {
                                if (property.Name == "material" || property.Name == "materials")
                                {
                                    continue;
                                }
                            }
                        }



                        string propertyName = property.Name;

                        MethodInfo getMethod = property.GetGetMethod(true);
                        if (getMethod != null)
                        {
                            object objectValue = getMethod.Invoke(component, null);

                            WrappedVariable wrappedVariable = new WrappedVariable(property, objectValue);
                            description.Properties.Add(wrappedVariable);
                        }
                    }
                }

                if ((flags & InfoFlags.Methods) == InfoFlags.Methods)
                {
                    MethodInfo[] methodInfos = componentType.GetMethods(GetGameObjectRequest.BINDING_FLAGS);
                    foreach (var methodInfo in methodInfos)
                    {
                        if (TypeUtility.IsPropertyMethod(methodInfo, componentType))
                        {
                            // Skip automatically generated getter/setter methods
                            continue;
                        }

                        WrappedMethod wrappedMethod = new WrappedMethod(methodInfo);
                        description.Methods.Add(wrappedMethod);
                    }
                }

                getGOResponse.Components.Add(description);
            }
            return(getGOResponse);
        }
    public static object Draw(ObjectPickerContext objectPickerContext, WrappedVariable variable, OpenPickerCallback onObjectPicker)
    {
        string name = variable.VariableName;

        if ((variable.Attributes.HasFlagByte(VariableAttributes.IsLiteral)))
        {
            name += " [Const]";
        }
        if ((variable.Attributes.HasFlagByte(VariableAttributes.IsStatic)))
        {
            name += " [Static]";
        }

        GUI.enabled = (variable.Attributes.HasFlagByte(VariableAttributes.ReadOnly) == false &&
                       variable.Attributes.HasFlagByte(VariableAttributes.IsLiteral) == false);

        object objectValue = variable.Value;
        object newValue    = null;

        if (variable.DataType != DataType.Unknown)
        {
            if (variable.Attributes.HasFlagByte(VariableAttributes.IsArray) ||
                variable.Attributes.HasFlagByte(VariableAttributes.IsList))
            {
                GUILayout.Label(name);
                EditorGUI.indentLevel++;
                IList list = null;
                int   size = 0;
                if (variable.Value != null)
                {
                    list = (IList)variable.Value;
                    size = list.Count;
                }

                int newSize = Mathf.Max(0, EditorGUILayout.DelayedIntField("Size", size));
                if (newSize != size)
                {
                    if (list == null)
                    {
                        list = new ArrayList();
                    }
                    CollectionUtility.Resize(ref list, variable.DefaultElementValue, newSize);
                }
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        list[i] = DrawIndividualVariable(objectPickerContext, variable, "Element " + i, list[i], onObjectPicker, i);
                    }
                }
                newValue = list;
                EditorGUI.indentLevel--;
            }
            else
            {
                newValue = DrawIndividualVariable(objectPickerContext, variable, name, variable.Value, onObjectPicker);
            }
        }
        else
        {
            EditorGUILayout.LabelField(name, "Unknown <" + variable.Value.ToString() + "> ");
        }
        GUI.enabled = true;

        return(newValue);
    }
 public GetUnityObjectsRequest(WrappedVariable variable, ObjectPickerContext context)
 {
     this.variable = variable;
     this.context  = context;
 }
    public static object DrawIndividualVariable(ObjectPickerContext objectPickerContext, WrappedVariable variable, string fieldName, object fieldValue, OpenPickerCallback onObjectPicker, int index = 0)
    {
        object newValue;

        if (variable.DataType == DataType.Enum)
        {
            newValue = EditorGUILayout.IntPopup(fieldName, (int)fieldValue, variable.MetaData.EnumNames, variable.MetaData.EnumValues);
        }
        else if (variable.DataType == DataType.UnityObjectReference)
        {
            if (fieldValue is Guid)
            {
                EditorGUILayout.BeginHorizontal();
                if ((Guid)fieldValue != Guid.Empty && variable.ValueDisplayNames.Length > index)
                {
                    EditorGUILayout.TextField(fieldName, variable.ValueDisplayNames[index]);
                }
                else
                {
                    EditorGUILayout.TextField(fieldName, "None (" + variable.MetaData.TypeFullName + ")");
                }
                if (objectPickerContext != null)
                {
                    if (GUILayout.Button("...", GUILayout.Width(30)))
                    {
                        onObjectPicker(objectPickerContext, variable);
                    }
                }
                EditorGUILayout.EndHorizontal();

                newValue = fieldValue;
            }
            else
            {
                newValue = EditorGUILayout.ObjectField(fieldName, (UnityEngine.Object)fieldValue, variable.MetaData.GetTypeFromMetaData(), true);
            }
        }
        else if (variable.DataType == DataType.Integer)
        {
            newValue = EditorGUILayout.IntField(fieldName, (int)fieldValue);
        }
        else if (variable.DataType == DataType.Long)
        {
            newValue = EditorGUILayout.LongField(fieldName, (long)fieldValue);
        }
        else if (variable.DataType == DataType.String)
        {
            newValue = EditorGUILayout.TextField(fieldName, (string)fieldValue);
        }
        else if (variable.DataType == DataType.Char)
        {
            string newString = EditorGUILayout.TextField(fieldName, new string((char)fieldValue, 1));
            if (newString.Length == 1)
            {
                newValue = newString[0];
            }
            else
            {
                newValue = fieldValue;
            }
        }
        else if (variable.DataType == DataType.Float)
        {
            newValue = EditorGUILayout.FloatField(fieldName, (float)fieldValue);
        }
        else if (variable.DataType == DataType.Double)
        {
            newValue = EditorGUILayout.DoubleField(fieldName, (double)fieldValue);
        }
        else if (variable.DataType == DataType.Boolean)
        {
            newValue = EditorGUILayout.Toggle(fieldName, (bool)fieldValue);
        }
        else if (variable.DataType == DataType.Vector2)
        {
            newValue = EditorGUILayout.Vector2Field(fieldName, (Vector2)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3)
        {
            newValue = EditorGUILayout.Vector3Field(fieldName, (Vector3)fieldValue);
        }
        else if (variable.DataType == DataType.Vector4)
        {
            newValue = EditorGUILayout.Vector4Field(fieldName, (Vector4)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.Vector2Int)
        {
            newValue = EditorGUILayout.Vector2IntField(fieldName, (Vector2Int)fieldValue);
        }
        else if (variable.DataType == DataType.Vector3Int)
        {
            newValue = EditorGUILayout.Vector3IntField(fieldName, (Vector3Int)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Quaternion)
        {
            //if(InspectorSidekick.Current.Settings.RotationsAsEuler)
            //{
            //  Quaternion quaternion = (Quaternion)fieldValue;
            //  Vector3 eulerAngles = quaternion.eulerAngles;
            //  eulerAngles = EditorGUILayout.Vector3Field(fieldName, eulerAngles);
            //  newValue = Quaternion.Euler(eulerAngles);
            //}
            //else
            {
                Quaternion quaternion = (Quaternion)fieldValue;
                Vector4    vector     = new Vector4(quaternion.x, quaternion.y, quaternion.z, quaternion.w);
                vector   = EditorGUILayout.Vector4Field(fieldName, vector);
                newValue = new Quaternion(vector.x, vector.y, vector.z, vector.z);
            }
        }
        else if (variable.DataType == DataType.Bounds)
        {
            newValue = EditorGUILayout.BoundsField(fieldName, (Bounds)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.BoundsInt)
        {
            newValue = EditorGUILayout.BoundsIntField(fieldName, (BoundsInt)fieldValue);
        }
#endif
        else if (variable.DataType == DataType.Color)
        {
            newValue = EditorGUILayout.ColorField(fieldName, (Color)fieldValue);
        }
        else if (variable.DataType == DataType.Color32)
        {
            newValue = (Color32)EditorGUILayout.ColorField(fieldName, (Color32)fieldValue);
        }
        else if (variable.DataType == DataType.Gradient)
        {
            newValue = InternalEditorGUILayout.GradientField(new GUIContent(fieldName), (Gradient)fieldValue);
        }
        else if (variable.DataType == DataType.AnimationCurve)
        {
            newValue = EditorGUILayout.CurveField(fieldName, (AnimationCurve)fieldValue);
        }
        else if (variable.DataType == DataType.Rect)
        {
            newValue = EditorGUILayout.RectField(fieldName, (Rect)fieldValue);
        }
#if UNITY_2017_2_OR_NEWER
        else if (variable.DataType == DataType.RectInt)
        {
            newValue = EditorGUILayout.RectIntField(fieldName, (RectInt)fieldValue);
        }
#endif
        else
        {
            GUILayout.Label(fieldName);
            newValue = fieldValue;
        }

        return(newValue);
    }
Example #21
0
    public static object Draw(ComponentDescription componentDescription, WrappedVariable variable, Action <Guid, WrappedVariable> onObjectPicker)
    {
        string name = variable.VariableName;

        if ((variable.Attributes.HasFlagByte(VariableAttributes.IsLiteral)))
        {
            name += " [Const]";
        }
        if ((variable.Attributes.HasFlagByte(VariableAttributes.IsStatic)))
        {
            name += " [Static]";
        }

        GUI.enabled = (variable.Attributes.HasFlagByte(VariableAttributes.ReadOnly) == false &&
                       variable.Attributes.HasFlagByte(VariableAttributes.IsLiteral) == false);

        object objectValue = variable.Value;
        object newValue    = null;

        if (variable.DataType != DataType.Unknown)
        {
            if (variable.Attributes.HasFlagByte(VariableAttributes.IsArray) ||
                variable.Attributes.HasFlagByte(VariableAttributes.IsList))
            {
                GUILayout.Label(name);
                EditorGUI.indentLevel++;
                IList list = null;
                int   size = 0;
                if (variable.Value != null)
                {
                    list = (IList)variable.Value;
                    size = list.Count;
                }

                Type type = DataTypeHelper.GetSystemTypeFromWrappedDataType(variable.DataType, variable.MetaData);

                int newSize = Mathf.Max(0, EditorGUILayout.DelayedIntField("Size", size));
                if (newSize != size)
                {
                    if (list == null)
                    {
                        list = new ArrayList();
                        //list = (IList)Activator.CreateInstance(type);
                    }
                    CollectionUtility.Resize(ref list, type, newSize);
                }
                if (list != null)
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        list[i] = DrawIndividualVariable(componentDescription, variable, "Element " + i, type, list[i], onObjectPicker);
                    }
                }
                newValue = list;
                EditorGUI.indentLevel--;
            }
            else
            {
                Type type;
                if (variable.Value != null)
                {
                    type = variable.Value.GetType();
                }
                else
                {
                    type = variable.MetaData.GetTypeFromMetaData();
                }
                newValue = DrawIndividualVariable(componentDescription, variable, name, type, variable.Value, onObjectPicker);
            }
        }
        else
        {
            if (objectValue == null)
            {
                EditorGUILayout.TextField(name, "{null}");
            }
            else
            {
                EditorGUILayout.TextField(name, "Unknown <" + variable.Value.ToString() + ">");
            }
        }
        GUI.enabled = true;

        return(newValue);
    }