예제 #1
0
        public override void PageInit()
        {
            base.PageInit();

            if (m_clearObjectControl == null)
            {
                m_clearObjectControl = AddObjectControl(new Vector2(20, 16), 0, this, "ClearObjectControlsOnRelease", "Clear object controls on release? Currently {3}");
            }
        }
예제 #2
0
        public ModPanelV2ObjectControl AddObjectControl(Vector2 startOffset, int startIndex, object instance, string memberName, string message = null, bool updateOnTick = false, bool isMethod = false, object[] methodParameters = null)
        {
            if (Panel != null)
            {
                FieldInfo  Field  = null;
                MethodInfo Method = null;
                ModPanelV2ObjectControl.ObjectType ObjectType = ModPanelV2ObjectControl.ObjectType.Message;

                if (!string.IsNullOrEmpty(memberName))
                {
                    if (instance != null)
                    {
                        Field = AccessTools.Field(instance.GetType(), memberName);

                        if (Field == null || isMethod)
                        {
                            Type[] paramTypes;
                            if (methodParameters != null)
                            {
                                paramTypes = new Type[methodParameters.Length];
                                for (int i = 0; i < methodParameters.Length; i++)
                                {
                                    paramTypes[i] = methodParameters[i].GetType();
                                }
                            }

                            Method = AccessTools.Method(instance.GetType(), memberName);
                        }
                    }

                    if (Field != null)
                    {
                        if (Field.FieldType.IsEnum)
                        {
                            ObjectType = ModPanelV2ObjectControl.ObjectType.Enum;
                        }
                        else if (Field.FieldType == typeof(Vector2) || Field.FieldType == typeof(Vector3))
                        {
                            ObjectType = ModPanelV2ObjectControl.ObjectType.Vectors;
                        }
                        else
                        {
                            ObjectType = (ModPanelV2ObjectControl.ObjectType)Enum.Parse(typeof(ModPanelV2ObjectControl.ObjectType), Field.FieldType.Name);
                        }
                    }
                    else if (Method != null)
                    {
                        ObjectType = ModPanelV2ObjectControl.ObjectType.Method;
                    }
                    else
                    {
                        //Debug.Log("uh oh worm?");
                        ObjectType = ModPanelV2ObjectControl.ObjectType.Message;
                        message    = "No member of the instance was found with the name\n" + memberName;
                        message   += isMethod ? "\nIt was said to be a method." : "\nIt was said to be a field.";
                    }
                }
                //else if (string.IsNullOrEmpty(memberName))
                //	ObjectType = ModPanelV2ObjectControl.ObjectType.Message;


                ModPanelV2ObjectControl oc = Instantiate(Panel.ControlPrefabs[(int)ObjectType], this.transform).GetComponent <ModPanelV2ObjectControl>();
                oc.transform.localPosition = startOffset + new Vector2(0f, ObjectControlSpacing * startIndex);
                oc.gameObject.name        += memberName;

                oc.InitObjectControl(instance, Field, Method, message, updateOnTick, methodParameters);
                ObjectControls.Add(oc);
                if (updateOnTick)
                {
                    UpdatingObjectControls.Add(oc);
                }
                return(oc);
            }
            return(null);
        }