Exemplo n.º 1
0
    public static string SystemTypeToType(Type type)
    {
        string ret = DataType.BOOLEAN;

        if (type == typeof(bool))
        {
            ret = DataType.BOOLEAN;
        }
        else if (type == typeof(string))
        {
            ret = DataType.STRING;
        }
        else if (type == typeof(int) || type == typeof(float))
        {
            ret = DataType.RANGE;
        }
        else if (type == typeof(void))
        {
            ret = DataType.BANG;
        }
        else if (type == typeof(Color))
        {
            ret = DataType.COLOR;
        }
        else if (CustomAttributeBase.IsEnum(type))
        {
            ret = DataType.ENUM;

            // Could make another map to search this way
            foreach (KeyValuePair <string, Type> i in cachedEnumTypes)
            {
                if (i.Value == type)
                {
                    return(i.Key);
                }
            }
        }
        else
        {
            ret = type.ToString();
        }
        return(ret);
    }
Exemplo n.º 2
0
    public void AddTunable(DebugTunable attTunable, UnityEngine.Object inst)
    {
        if (attTunable == null)
        {
            Debug.Log("AddTunable:  null attTunable, what?");
            return;
        }

        int urid = -1;

        if (attTunable.IsField())
        {
            // Initial value
            object value     = attTunable.fieldInfo.GetValue(inst);
            string debugName = string.IsNullOrEmpty(attTunable.ItemName) ? attTunable.fieldInfo.Name : attTunable.ItemName;

            // Add the item
            if (attTunable is DebugBoolTunable)
            {
                urid = DebugMenu.Instance.AddBoolItem(debugName, (bool newVal) => { attTunable.fieldInfo.SetValue(inst, newVal); }, () => { return((bool)attTunable.fieldInfo.GetValue(inst)); }, (bool)value, this.gameObject);
            }
            else if (attTunable is DebugNumberTunable)
            {
                DebugNumberTunable numTuneable = attTunable as DebugNumberTunable;
                if (attTunable.fieldInfo.FieldType == typeof(float))
                {
                    urid = DebugMenu.Instance.AddFloatItem(debugName, (float newVal) => { attTunable.fieldInfo.SetValue(inst, newVal); }, () => { return((float)attTunable.fieldInfo.GetValue(inst)); }, (float)value, numTuneable.Fmin, numTuneable.Fmax, this.gameObject, (int)numTuneable.FStep);
                }
                else if (attTunable.fieldInfo.FieldType == typeof(int))
                {
                    urid = DebugMenu.Instance.AddIntItem(debugName, (int newVal) => { attTunable.fieldInfo.SetValue(inst, newVal); }, () => { return((int)attTunable.fieldInfo.GetValue(inst)); }, (int)value, (int)numTuneable.Fmin, (int)numTuneable.Fmax, this.gameObject, (int)Mathf.Max(1, (int)numTuneable.FStep));
                }
            }
            else if (attTunable is DebugVector3Tunable)
            {
                DebugVector3Tunable vec3Tuneable = attTunable as DebugVector3Tunable;
                urid = DebugMenu.Instance.AddVector3Item(debugName, (Vector3 newVal) => { attTunable.fieldInfo.SetValue(inst, newVal); }, () => { return((Vector3)attTunable.fieldInfo.GetValue(inst)); }, (Vector3)value, vec3Tuneable.VecStep, this.gameObject);
            }
            else if (CustomAttributeBase.IsEnum(attTunable.fieldInfo.FieldType) && attTunable is DebugEnumTunable)
            {
                DebugEnumTunable enumTunable = attTunable as DebugEnumTunable;
                // Get range from enum values
                Type fieldType = attTunable.fieldInfo.FieldType;

                int minv = enumTunable.MinEnumVal;
                int maxv = enumTunable.MaxEnumVal;

                if (minv == -1 && maxv == -1)
                {
                    Array arr = Enum.GetValues(fieldType);
                    if (arr != null && arr.Length > 0)
                    {
                        minv = (int)arr.GetValue(0);
                        maxv = (int)arr.GetValue(arr.Length - 1);
                    }
                }

                urid = DebugMenu.Instance.AddEnumItem(debugName, attTunable.fieldInfo.FieldType, (int newVal) => { attTunable.fieldInfo.SetValue(inst, newVal); }, () => { return((int)attTunable.fieldInfo.GetValue(inst)); }, (int)value, minv, maxv, this.gameObject);
            }
        }
        else if (attTunable.IsMethod())
        {
            string debugName = string.IsNullOrEmpty(attTunable.ItemName) ? attTunable.methodInfo.Name : attTunable.ItemName;

            if (attTunable is DebugButtonAttribute)
            {
                DebugButtonAttribute buttonTunable = attTunable as DebugButtonAttribute;

                urid = DebugMenu.Instance.AddButtonItem(debugName, buttonTunable.ButtonName, () => { buttonTunable.methodInfo.Invoke(inst, null); }, this.gameObject);
            }
        }

        // Add the item urid to the list of items associated with the object instance
        if (urid != -1)
        {
            if (!m_urids.ContainsKey(inst))
            {
                m_urids[inst] = new List <int>();
            }
            m_urids[inst].Add(urid);
        }
    }