예제 #1
0
    int BoolField(SerializedProperty sp, InspectorPlusVar v)
    {
        if (v.toggleStart)
        {
            EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);

            EditorGUI.BeginChangeCheck();
            var newValue = EditorGUILayout.Toggle(m_dispName, sp.boolValue);

            if (EditorGUI.EndChangeCheck())
            {
                sp.boolValue = newValue;
            }

            EditorGUI.EndProperty();

            if (!sp.boolValue)
            {
                return(v.toggleSize);
            }
        }
        else
        {
            EditorGUILayout.PropertyField(sp, new GUIContent(m_dispName));
        }

        return(0);
    }
예제 #2
0
    private void FloatField(SerializedProperty sp, InspectorPlusVar v)
    {
        if (v.limitType == InspectorPlusVar.LimitType.Min && !sp.hasMultipleDifferentValues)
        {
            sp.floatValue = Mathf.Max(v.min, sp.floatValue);
        }
        else if (v.limitType == InspectorPlusVar.LimitType.Max && !sp.hasMultipleDifferentValues)
        {
            sp.floatValue = Mathf.Min(v.max, sp.floatValue);
        }

        if (v.limitType == InspectorPlusVar.LimitType.Range)
        {
            if (!v.progressBar)
            {
                EditorGUILayout.Slider(sp, v.min, v.max);
            }
            else
            {
                if (!sp.hasMultipleDifferentValues)
                {
                    sp.floatValue = Mathf.Clamp(sp.floatValue, v.min, v.max);
                    ProgressBar((sp.floatValue - v.min) / v.max, dispName);
                }
                else
                {
                    ProgressBar((sp.floatValue - v.min) / v.max, dispName);
                }
            }
        }
        else
        {
            EditorGUILayout.PropertyField(sp, new GUIContent(dispName));
        }
    }
예제 #3
0
    public override void OnInspectorGUI()
    {
        if (m_tracker == null)
        {
            DrawDefaultInspector();
            return;
        }

        m_tracker.UpdateFields();

        serializedObject.Update();
        RefreshVars();

        for (int i = 0; i < m_properties.Length; ++i)
        {
            InspectorPlusVar   v    = m_vars[i];
            SerializedProperty prop = m_properties[i];
            DrawProperty(v, prop, ref i);
        }

        if (!string.IsNullOrEmpty(GUI.tooltip))
        {
            GUI.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
            GUI.Box(m_tooltipRect, new GUIContent());
            EditorGUI.HelpBox(m_tooltipRect, GUI.tooltip, MessageType.Info);
            Repaint();
        }

        GUI.tooltip = "";

        serializedObject.ApplyModifiedProperties();
    }
예제 #4
0
    void TextureGUI(SerializedProperty sp, InspectorPlusVar v)
    {
        if (!v.largeTexture)
        {
            PropertyField(sp, m_curName);
        }
        else
        {
            EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);

            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(m_dispName);
            var newValue = EditorGUILayout.ObjectField(sp.objectReferenceValue, typeof(Texture2D), false,
                                                       GUILayout.Width(v.textureSize), GUILayout.Height(v.textureSize));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();

            if (EditorGUI.EndChangeCheck())
            {
                sp.objectReferenceValue = newValue;
            }

            EditorGUI.EndProperty();
        }
    }
    string BuildVar(InspectorPlusVar v)
    {

        return @"
        vars.Add(new InspectorPlusVar("+BuildArgs(v.limitType, v.min, v.max, v.progressBar, v.iMin, v.iMax, v.active, v.type, v.name, v.dispName, v.vectorDrawType, v.relative, v.scale,
                                       v.space, v.labelEnabled, v.label, v.labelBold, v.labelItalic, v.labelAlign, v.buttonEnabled, v.buttonText, v.buttonCallback, v.buttonCondense, v.numSpace, v.classType, 
                                       v.offset, v.QuaternionHandle, v.canWrite, v.tooltip, v.hasTooltip, v.toggleStart, v.toggleSize, v.toggleLevel, v.largeTexture, v.textureSize, v.textFieldDefault, v.textArea) + "));";
    }
예제 #6
0
 string BuildVar(InspectorPlusVar v)
 {
     return(@"
     vars.Add(new InspectorPlusVar(" + BuildArgs(v.limitType, v.min, v.max, v.progressBar, v.iMin, v.iMax, v.active,
                                                 v.type, v.name, v.dispName, v.vectorDrawType, v.relative, v.scale,
                                                 v.space, v.labelEnabled, v.label, v.labelBold, v.buttonEnabled, v.buttonText,
                                                 v.buttonCallback, v.buttonCondense, v.numSpace, v.classType,
                                                 v.offset, v.QuaternionHandle, v.canWrite, v.tooltip, v.hasTooltip, v.toggleStart, v.toggleSize, v.toggleLevel,
                                                 v.largeTexture, v.textureSize, v.textFieldDefault, v.textArea) + "));");
 }
예제 #7
0
    void RefreshVars()
    {
        m_vars = m_tracker.GetVars();
        int count = m_vars.Count;

        if (count != m_properties.Length)
        {
            m_properties = new SerializedProperty[count];
        }

        for (int i = 0; i < count; i += 1)
        {
            InspectorPlusVar v = m_vars[i];
            m_properties[i] = serializedObject.FindProperty(v.name);
        }
    }
예제 #8
0
    void RefreshVars()
    {
        vars = tracker.GetVars();
        int count = vars.Count;

        if (count != properties.Length)
        {
            properties = new SerializedProperty[count];
        }

        for (int i = 0; i < count; i += 1)
        {
            InspectorPlusVar v = vars[i];
            properties[i] = so.FindProperty(v.name);
        }
    }
예제 #9
0
    private void TextGUI(SerializedProperty sp, InspectorPlusVar v)
    {
        if (v.textFieldDefault == "")
        {
            PropertyField(sp, name);
            return;
        }

        string focusName = "_focusTextField" + v.name;

        GUI.SetNextControlName(focusName);

        EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);

        EditorGUI.BeginChangeCheck();

        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel(dispName);

        string newValue = "";

        if (!v.textArea)
        {
            newValue = EditorGUILayout.TextField("", sp.stringValue, GUILayout.Width(Screen.width));
        }
        else
        {
            newValue = EditorGUILayout.TextArea(sp.stringValue, GUILayout.Width(Screen.width));
        }

        if (GUI.GetNameOfFocusedControl() != focusName && !sp.hasMultipleDifferentValues && sp.stringValue == "")
        {
            GUI.color = new Color(0.7f, 0.7f, 0.7f);
            GUI.Label(GUILayoutUtility.GetLastRect(), v.textFieldDefault);
            GUI.color = Color.white;
        }

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (EditorGUI.EndChangeCheck())
        {
            sp.stringValue = newValue;
        }

        EditorGUI.EndProperty();
    }
예제 #10
0
    void IntField(SerializedProperty sp, InspectorPlusVar v)
    {
        if (v.limitType == InspectorPlusVar.LimitType.Min && !sp.hasMultipleDifferentValues)
        {
            sp.intValue = Mathf.Max(v.iMin, sp.intValue);
        }
        else if (v.limitType == InspectorPlusVar.LimitType.Max && !sp.hasMultipleDifferentValues)
        {
            sp.intValue = Mathf.Min(v.iMax, sp.intValue);
        }

        if (v.limitType == InspectorPlusVar.LimitType.Range)
        {
            if (!v.progressBar)
            {
                EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);
                EditorGUI.BeginChangeCheck();

                var newValue = EditorGUI.IntSlider(GUILayoutUtility.GetRect(18.0f, 18.0f), new GUIContent(m_dispName), sp.intValue,
                                                   v.iMin, v.iMax);

                if (EditorGUI.EndChangeCheck())
                {
                    sp.intValue = newValue;
                }

                EditorGUI.EndProperty();
            }
            else
            {
                if (!sp.hasMultipleDifferentValues)
                {
                    sp.intValue = Mathf.Clamp(sp.intValue, v.iMin, v.iMax);
                    ProgressBar((float)(sp.intValue - v.iMin) / v.iMax, m_dispName);
                }
                else
                {
                    ProgressBar((float)(sp.intValue - v.iMin) / v.iMax, m_dispName);
                }
            }
        }
        else
        {
            EditorGUILayout.PropertyField(sp, new GUIContent(m_dispName));
        }
    }
    void DrawElement(Rect rect, int i, bool isActive, bool isFocused)
    {
        InspectorPlusVar ipv = m_vars[i];

        currentRect        = rect;
        currentRect.height = EditorGUIUtility.singleLineHeight;

        GetRect(ipv.toggleLevel * 15.0f);

        ipv.active = GUI.Toggle(GetRect(15.0f), ipv.active, "");

        GUI.enabled  = ipv.active;
        ipv.dispName = GUI.TextField(GetRect(100.0f), ipv.dispName);

        GetRect(5.0f);

        GUI.enabled    = !ipv.fixedTip;
        ipv.hasTooltip = GUI.Toggle(GetRect(40.0f), ipv.hasTooltip, "");
        GUI.enabled    = ipv.hasTooltip && GUI.enabled;
        ipv.tooltip    = GUI.TextField(GetRect(100.0f), ipv.tooltip);

        GUI.enabled = true;


        GUI.enabled = i - 1 >= 0;

        GUI.enabled  = true;
        ipv.canWrite = GUI.Toggle(GetRect(15.0f), ipv.canWrite, new GUIContent(""));

        ipv.DrawFieldGUI(this);
        ipv.DrawDragBox(this);

        if (!ipv.active)
        {
            GUI.enabled = true;
        }

        if (GUI.changed)
        {
            UpdateTarget();
            dirty = true;
        }
    }
예제 #12
0
    int DrawProperty(InspectorPlusVar v, SerializedProperty prop, ref int i)
    {
        if (v.active && prop != null)
        {
            SerializedProperty sp = prop;
            string             s  = v.type;
            m_curName  = v.name;
            m_dispName = v.dispName;

            GUI.enabled = v.canWrite;

            GUILayout.BeginHorizontal();

            if (v.toggleLevel != 0)
            {
                GUILayout.Space(v.toggleLevel * 10.0f);
            }

            //TODO: This doesn't seem efficient?
            if (s == typeof(Vector2).Name)
            {
                Vector2Field(sp);
            }
            else if (s == typeof(float).Name)
            {
                FloatField(sp, v);
            }
            else if (s == typeof(int).Name)
            {
                IntField(sp, v);
            }
            else if (s == typeof(Quaternion).Name)
            {
                QuaternionField(sp);
            }
            else if (s == typeof(bool).Name)
            {
                i += BoolField(sp, v);
            }
            else if (s == typeof(Texture2D).Name || s == typeof(Texture).Name)
            {
                TextureGUI(sp, v);
            }
            else if (s == typeof(string).Name)
            {
                TextGUI(sp, v);
            }
            else if (sp.isArray)
            {
                ArrayGUI(sp, m_curName);
            }
            else
            {
                PropertyField(sp, m_curName);
            }

            GUILayout.EndHorizontal();
            GUI.enabled = true;

            if (v.hasTooltip)
            {
                Rect last = GUILayoutUtility.GetLastRect();
                GUI.Label(last, new GUIContent("", v.tooltip));

                Vector2 size = new GUIStyle().CalcSize(new GUIContent(GUI.tooltip));
                m_tooltipRect = new Rect(Event.current.mousePosition.x + 4.0f, Event.current.mousePosition.y + 12.0f, 28.0f + size.x,
                                         9.0f + size.y);

                if (m_tooltipRect.width > 250.0f)
                {
                    float delt = (m_tooltipRect.width - 250.0f);
                    m_tooltipRect.width  -= delt;
                    m_tooltipRect.height += size.y * Mathf.CeilToInt(delt / 250.0f);
                }
            }
        }

        if (v.space == 0.0f)
        {
            return(i);
        }

        float usedSpace = 0.0f;

        for (int j = 0; j < v.numSpace; j += 1)
        {
            bool buttonLine = false;
            for (int k = 0; k < 4; k += 1)
            {
                if (v.buttonEnabled[j * 4 + k])
                {
                    buttonLine = true;
                }
            }

            if (v.labelEnabled[j] || buttonLine)
            {
                usedSpace += 18.0f;
            }
        }

        if (v.space == 0.0f)
        {
            return(i);
        }

        float space = Mathf.Max(0.0f, (v.space - usedSpace) / 2.0f);

        for (int j = 0; j < v.numSpace; ++j)
        {
            bool buttonLine = false;
            for (int k = 0; k < 4; k += 1)
            {
                if (v.buttonEnabled[j * 4 + k])
                {
                    buttonLine = true;
                }
            }

            if (v.labelEnabled[j] || buttonLine)
            {
                GUILayout.BeginHorizontal();

                if (v.labelEnabled[j])
                {
                    GUILayout.Label(v.label[j], v.labelBold[j] ? EditorStyles.boldLabel : EditorStyles.label);
                }

                bool alignRight = v.labelEnabled[j] && buttonLine;

                if (!alignRight)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }

                GUILayout.FlexibleSpace();
                for (int k = 0; k < 4; k += 1)
                {
                    if (v.buttonEnabled[j * 4 + k])
                    {
                        if (!v.buttonCondense[j] && !alignRight)
                        {
                            GUILayout.FlexibleSpace();
                        }

                        string style = "Button";
                        if (v.buttonCondense[j])
                        {
                            bool hasLeft  = false;
                            bool hasRight = false;
                            for (int p = k - 1; p >= 0; p -= 1)
                            {
                                if (v.buttonEnabled[j * 4 + p])
                                {
                                    hasLeft = true;
                                }
                            }
                            for (int p = k + 1; p < 4; p += 1)
                            {
                                if (v.buttonEnabled[j * 4 + p])
                                {
                                    hasRight = true;
                                }
                            }

                            if (!hasLeft && hasRight)
                            {
                                style = "ButtonLeft";
                            }
                            else if (hasLeft && hasRight)
                            {
                                style = "ButtonMid";
                            }
                            else if (hasLeft && !hasRight)
                            {
                                style = "ButtonRight";
                            }
                            else if (!hasLeft && !hasRight)
                            {
                                style = "Button";
                            }
                        }

                        if (GUILayout.Button(v.buttonText[j * 4 + k], style, GUILayout.MinWidth(60.0f)))
                        {
                            foreach (object t in targets)
                            {
                                MethodInfo m = t.GetType().GetMethod(v.buttonCallback[j * 4 + k],
                                                                     BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic);

                                if (m != null)
                                {
                                    m.Invoke(target, null);
                                }
                            }
                        }

                        if (!v.buttonCondense[j] && !alignRight)
                        {
                            GUILayout.FlexibleSpace();
                        }
                    }
                }

                GUILayout.Space(4.0f);

                if (!(v.labelEnabled[j] && buttonLine))
                {
                    GUILayout.FlexibleSpace();
                }

                GUILayout.EndHorizontal();
            }

            if (j < v.numSpace - 1)
            {
                GUILayout.Space(space / v.numSpace);
            }
        }
        return(i);
    }
예제 #13
0
	void VectorScene(InspectorPlusVar v, string s, Transform t)
	{
		Vector3 val;
		
		if (s == typeof(Vector3).Name)
			val = (Vector3)GetTargetField(name);
		else 
			val = ((Vector2)GetTargetField(name));
		
		Vector3 newVal = Vector3.zero;
		Vector3 curVal;
		bool setVal = false;
		bool relative = v.relative;
		bool scale = v.scale;

		switch (v.vectorDrawType) {
		case InspectorPlusVar.VectorDrawType.Direction:
			curVal = relative ? val:val - t.position;
            float size = scale ? Mathf.Min(2.0f, Mathf.Sqrt(curVal.magnitude) / 2.0f) : 1.0f;
            size *= HandleUtility.GetHandleSize(t.position);
			Handles.ArrowCap (0, t.position, curVal != Vector3.zero ? Quaternion.LookRotation (val.normalized) : Quaternion.identity, size);
			break;

		case InspectorPlusVar.VectorDrawType.Point:
			curVal = relative ? val:t.position + val;
			Handles.SphereCap (0, curVal, Quaternion.identity, 0.1f);
			break;

		case InspectorPlusVar.VectorDrawType.PositionHandle:
			curVal = relative ? t.position + val:val;
			setVal = true;
			newVal = Handles.PositionHandle (curVal, Quaternion.identity) - (relative ? t.position : Vector3.zero);
			break;

		case InspectorPlusVar.VectorDrawType.Scale:
			setVal = true;
            curVal = relative ? t.localScale + val :val;
            newVal = Handles.ScaleHandle(curVal, t.position + v.offset, t.rotation, HandleUtility.GetHandleSize(t.position + v.offset)) - (relative ? t.localScale : Vector3.zero);
			break;
			
		case InspectorPlusVar.VectorDrawType.Rotation:
			setVal = true;
            curVal = relative ? val + t.rotation.eulerAngles : val;
			newVal = Handles.RotationHandle(Quaternion.Euler(curVal), t.position + v.offset).eulerAngles - (relative?t.rotation.eulerAngles:Vector3.zero);
			break;
		}
	
		if (setVal)
		{
			object newObjectVal = newVal;
			
			if (s==typeof(Vector2).Name)
				newObjectVal = (Vector2)newVal;
			else if (s == typeof(Quaternion).Name)
				newObjectVal = Quaternion.Euler(newVal);
						
			SetTargetField(name, newObjectVal);
		}
	}
예제 #14
0
	void TextGUI(SerializedProperty sp, InspectorPlusVar v)
	{
		if (v.textFieldDefault == "")
		{
			PropertyField(sp, name);
			return;
		}

		string focusName = "_focusTextField" + v.name;

		GUI.SetNextControlName(focusName);

		EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);

		EditorGUI.BeginChangeCheck();

		GUILayout.BeginHorizontal();
		EditorGUILayout.PrefixLabel(dispName);

		string newValue = "";

		newValue = !v.textArea ? EditorGUILayout.TextField("", sp.stringValue, GUILayout.Width(Screen.width)) : EditorGUILayout.TextArea(sp.stringValue, GUILayout.Width(Screen.width));

		if (GUI.GetNameOfFocusedControl() != focusName && !sp.hasMultipleDifferentValues && sp.stringValue == "")
		{
			GUI.color = new Color(0.7f, 0.7f, 0.7f);
			GUI.Label(GUILayoutUtility.GetLastRect(), v.textFieldDefault);
			GUI.color = Color.white;
		}
		
		GUILayout.FlexibleSpace();
		GUILayout.EndHorizontal();

		if (EditorGUI.EndChangeCheck())
			sp.stringValue = newValue;

		EditorGUI.EndProperty();
	}
예제 #15
0
    void TextureGUI(SerializedProperty sp, InspectorPlusVar v)
    {
        if (!v.largeTexture)
            PropertyField(sp, name);
        else
        {
            EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);

            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal();
            EditorGUILayout.PrefixLabel(dispName);
            var newValue = EditorGUILayout.ObjectField(sp.objectReferenceValue, typeof(Texture2D), false, GUILayout.Width(v.textureSize), GUILayout.Height(v.textureSize));
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            if (EditorGUI.EndChangeCheck())
                sp.objectReferenceValue = newValue;

            EditorGUI.EndProperty();
        }
    }
예제 #16
0
    int BoolField(SerializedProperty sp, InspectorPlusVar v)
    {
        if (v.toggleStart)
        {
            EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);

            EditorGUI.BeginChangeCheck();
            var newValue = EditorGUILayout.Toggle(dispName, sp.boolValue);
            
            if (EditorGUI.EndChangeCheck())
                sp.boolValue = newValue;
            
            EditorGUI.EndProperty();

            if (!sp.boolValue)
                return v.toggleSize;
        }
        else EditorGUILayout.PropertyField(sp, new GUIContent(dispName));

        return 0;
    }
예제 #17
0
	void IntField(SerializedProperty sp, InspectorPlusVar v)
	{
		if (v.limitType == InspectorPlusVar.LimitType.Min && !sp.hasMultipleDifferentValues)
			sp.intValue = Mathf.Max (v.iMin, sp.intValue);
		else if (v.limitType == InspectorPlusVar.LimitType.Max && !sp.hasMultipleDifferentValues)
			sp.intValue = Mathf.Min (v.iMax, sp.intValue);
		
		if (v.limitType == InspectorPlusVar.LimitType.Range)
		{
			if (!v.progressBar)
			{
                EditorGUI.BeginProperty(new Rect(0.0f, 0.0f, 0.0f, 0.0f), new GUIContent(), sp);
				EditorGUI.BeginChangeCheck ();

                var newValue = EditorGUI.IntSlider(GUILayoutUtility.GetRect(18.0f, 18.0f), new GUIContent(dispName), sp.intValue, v.iMin, v.iMax);
				
				if (EditorGUI.EndChangeCheck ())
					sp.intValue = newValue;
				EditorGUI.EndProperty ();
			}
			else {
				if (!sp.hasMultipleDifferentValues) {
					sp.intValue = Mathf.Clamp (sp.intValue, v.iMin, v.iMax);
					ProgressBar ((float)(sp.intValue - v.iMin) / v.iMax, dispName);
				} else
					ProgressBar ((float)(sp.intValue - v.iMin) / v.iMax, dispName);
			}
		}
        else EditorGUILayout.PropertyField(sp, new GUIContent(dispName));
	}
예제 #18
0
	void FloatField(SerializedProperty sp, InspectorPlusVar v)
	{
		if (v.limitType == InspectorPlusVar.LimitType.Min && !sp.hasMultipleDifferentValues)
			sp.floatValue = Mathf.Max (v.min, sp.floatValue);
		else if (v.limitType == InspectorPlusVar.LimitType.Max && !sp.hasMultipleDifferentValues)
			sp.floatValue = Mathf.Min (v.max, sp.floatValue);
		
		if (v.limitType == InspectorPlusVar.LimitType.Range) {
			if (!v.progressBar)
				EditorGUILayout.Slider (sp, v.min, v.max);
			else {
				if (!sp.hasMultipleDifferentValues) {
					sp.floatValue = Mathf.Clamp (sp.floatValue, v.min, v.max);
					ProgressBar ((sp.floatValue - v.min) / v.max, dispName);
				} else
					ProgressBar ((sp.floatValue - v.min) / v.max, dispName);
			}
		}
        else EditorGUILayout.PropertyField(sp, new GUIContent(dispName));
	}
    float ElementHeightCallback(int index)
    {
        InspectorPlusVar ipv = m_vars[index];

        return(EditorGUIUtility.singleLineHeight + 10.0f + ipv.space);
    }
예제 #20
0
    public override void OnInspectorGUI()
    {
        if (manager == null)
        {
            return;
        }

        if (tracker == null)
        {
            return;
        }

        tracker.UpdateFields();

        so.Update();
        RefreshVars();

        EditorGUIUtility.LookLikeControls(135.0f, 50.0f);

        for (int i = 0; i < properties.Length; i += 1)
        {
            InspectorPlusVar v = vars[i];

            if (v.active && properties[i] != null)
            {
                SerializedProperty sp = properties [i];
                string             s  = v.type;
                name     = v.name;
                dispName = v.dispName;

                GUI.enabled = v.canWrite;

                GUILayout.BeginHorizontal();

                if (v.toggleLevel != 0)
                {
                    GUILayout.Space(v.toggleLevel * 10.0f);
                }

                if (s == typeof(Vector2).Name)
                {
                    Vector2Field(sp);
                }
                else if (s == typeof(float).Name)
                {
                    FloatField(sp, v);
                }
                else if (s == typeof(int).Name)
                {
                    IntField(sp, v);
                }
                else if (s == typeof(Quaternion).Name)
                {
                    QuaternionField(sp);
                }
                else if (s == typeof(bool).Name)
                {
                    i += BoolField(sp, v);
                }
                else if (s == typeof(Texture2D).Name || s == typeof(Texture).Name)
                {
                    TextureGUI(sp, v);
                }
                else if (s == typeof(string).Name)
                {
                    TextGUI(sp, v);
                }
                else if (sp.isArray)
                {
                    ArrayGUI(sp, name);
                }
                else
                {
                    PropertyField(sp, name);
                }

                GUILayout.EndHorizontal();
                GUI.enabled = true;

                if (v.hasTooltip)
                {
                    Rect last = GUILayoutUtility.GetLastRect();
                    GUI.Label(last, new GUIContent("", v.tooltip));

                    Vector2 size = new GUIStyle().CalcSize(new GUIContent(GUI.tooltip));
                    tooltipRect = new Rect(Event.current.mousePosition.x + 4.0f, Event.current.mousePosition.y + 12.0f, 28.0f + size.x, 9.0f + size.y);

                    if (tooltipRect.width > 250.0f)
                    {
                        float delt = (tooltipRect.width - 250.0f);
                        tooltipRect.width  -= delt;
                        tooltipRect.height += size.y * Mathf.CeilToInt(delt / 250.0f);
                    }
                }
            }

            if (v.space == 0.0f)
            {
                continue;
            }

            float usedSpace = 0.0f;
            for (int j = 0; j < v.numSpace; j += 1)
            {
                bool buttonLine = false;
                for (int k = 0; k < 4; k += 1)
                {
                    if (v.buttonEnabled[j * 4 + k])
                    {
                        buttonLine = true;
                    }
                }
                if (v.labelEnabled [j] || buttonLine)
                {
                    usedSpace += 18.0f;
                }
            }


            if (v.space == 0.0f)
            {
                continue;
            }


            float space = Mathf.Max(0.0f, (v.space - usedSpace) / 2.0f);

            GUILayout.Space(space);

            for (int j = 0; j < v.numSpace; j += 1)
            {
                bool buttonLine = false;
                for (int k = 0; k < 4; k += 1)
                {
                    if (v.buttonEnabled[j * 4 + k])
                    {
                        buttonLine = true;
                    }
                }
                if (!v.labelEnabled[j] && !buttonLine)
                {
                    continue;
                }


                GUILayout.BeginHorizontal();
                if (v.labelEnabled[j])
                {
                    var boldItalic = new GUIStyle {
                        margin = new RectOffset(5, 5, 5, 5)
                    };

                    switch (v.labelAlign[j])
                    {
                    case 0:
                        boldItalic.alignment = TextAnchor.MiddleLeft;
                        break;

                    case 1:
                        boldItalic.alignment = TextAnchor.MiddleCenter;
                        break;

                    case 2:
                        boldItalic.alignment = TextAnchor.MiddleRight;
                        break;
                    }

                    if (v.labelBold[j] && v.labelItalic[j])
                    {
                        boldItalic.fontStyle = FontStyle.BoldAndItalic;
                    }
                    else if (v.labelBold[j])
                    {
                        boldItalic.fontStyle = FontStyle.Bold;
                    }
                    else if (v.labelItalic[j])
                    {
                        boldItalic.fontStyle = FontStyle.Italic;
                    }

                    GUILayout.Label(v.label[j], boldItalic);
                    boldItalic.alignment = TextAnchor.MiddleLeft;
                }
                bool alignRight = (v.labelEnabled[j] && buttonLine);

                if (!alignRight)
                {
                    GUILayout.EndHorizontal();
                    GUILayout.BeginHorizontal();
                }

                GUILayout.FlexibleSpace();
                for (int k = 0; k < 4; k += 1)
                {
                    if (v.buttonEnabled[j * 4 + k])
                    {
                        if (!v.buttonCondense[j] && !alignRight)
                        {
                            GUILayout.FlexibleSpace();
                        }

                        string style = "Button";
                        if (v.buttonCondense[j])
                        {
                            bool hasLeft  = false;
                            bool hasRight = false;
                            for (int p = k - 1; p >= 0; p -= 1)
                            {
                                if (v.buttonEnabled[j * 4 + p])
                                {
                                    hasLeft = true;
                                }
                            }
                            for (int p = k + 1; p < 4; p += 1)
                            {
                                if (v.buttonEnabled[j * 4 + p])
                                {
                                    hasRight = true;
                                }
                            }

                            if (!hasLeft && hasRight)
                            {
                                style = "ButtonLeft";
                            }
                            else if (hasLeft && hasRight)
                            {
                                style = "ButtonMid";
                            }
                            else if (hasLeft && !hasRight)
                            {
                                style = "ButtonRight";
                            }
                            else if (!hasLeft && !hasRight)
                            {
                                style = "Button";
                            }
                        }

                        if (GUILayout.Button(v.buttonText[j * 4 + k], style, GUILayout.MinWidth(60.0f)))
                        {
                            foreach (object t in targets)
                            {
                                MethodInfo m = t.GetType().GetMethod(v.buttonCallback[j * 4 + k], BindingFlags.Public | BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.NonPublic);
                                if (m != null)
                                {
                                    m.Invoke(target, null);
                                }
                            }
                        }

                        if (!v.buttonCondense[j] && !alignRight)
                        {
                            GUILayout.FlexibleSpace();
                        }
                    }
                }

                GUILayout.Space(4.0f);

                if (!(v.labelEnabled[j] && buttonLine))
                {
                    GUILayout.FlexibleSpace();
                }

                GUILayout.EndHorizontal();
            }

            GUILayout.Space(space);
        }


        if (!string.IsNullOrEmpty(GUI.tooltip))
        {
            GUI.color = new Color(1.0f, 1.0f, 1.0f, 1.0f);
            GUI.Box(tooltipRect, new GUIContent());
            EditorGUI.HelpBox(tooltipRect, GUI.tooltip, MessageType.Info);
            Repaint();
        }

        GUI.tooltip = "";

        so.ApplyModifiedProperties();
    }
예제 #21
0
    public override void OnInspectorGUI()
    {
        so.Update();
        RefreshVars();

        EditorGUIUtility.LookLikeControls(135.0f, 50.0f);

        for (int i = 0; i < properties.Length; i += 1)
        {
            InspectorPlusVar v = vars[i];

            if (v.active && properties[i] != null)
            {
                SerializedProperty sp = properties[i];
                string             s  = v.type;
                bool skip             = false;
                name     = v.name;
                dispName = v.dispName;

                GUI.enabled = v.canWrite;

                GUILayout.BeginHorizontal();

                if (v.toggleLevel != 0)
                {
                    GUILayout.Space(v.toggleLevel * 10.0f);
                }

                if (s == typeof(Vector2).Name)
                {
                    Vector2Field(sp);
                    skip = true;
                }
                if (s == typeof(float).Name)
                {
                    FloatField(sp, v);
                    skip = true;
                }
                if (s == typeof(int).Name)
                {
                    IntField(sp, v);
                    skip = true;
                }
                if (s == typeof(bool).Name)
                {
                    i   += BoolField(sp, v);
                    skip = true;
                }
                if (s == typeof(Texture2D).Name || s == typeof(Texture).Name)
                {
                    TextureGUI(sp, v);
                    skip = true;
                }
                if (s == typeof(string).Name)
                {
                    TextGUI(sp, v);
                    skip = true;
                }
                if (!skip)
                {
                    PropertyField(sp, name);
                }
                GUILayout.EndHorizontal();
                GUI.enabled = true;
            }
        }
        so.ApplyModifiedProperties();
    }
    public void DrawGUI()
    {
        float buttonWidth = 23.0f;

        UpdateFields();
        UpdateVarLevel();

        for (int i = 0; i < vars.Count; ++i)
        {
            InspectorPlusVar ipv = vars[i];
            EditorGUILayout.BeginHorizontal();

            GUILayout.Space(5.0f);

            GUILayout.BeginHorizontal(GUILayout.Width(370.0f));

            GUILayout.Space(ipv.toggleLevel * 15.0f);

            ipv.active   = GUILayout.Toggle(ipv.active, "");
            GUI.enabled  = ipv.active;
            ipv.dispName = GUILayout.TextField(ipv.dispName, GUILayout.Width(100.0f));
            GUILayout.Space(5.0f);
            GUI.enabled    = !ipv.fixedTip;
            ipv.hasTooltip = GUILayout.Toggle(ipv.hasTooltip, "");
            GUI.enabled    = ipv.hasTooltip && GUI.enabled;
            ipv.tooltip    = GUILayout.TextField(ipv.tooltip, GUILayout.MinWidth(100.0f));
            GUILayout.FlexibleSpace();
            GUI.enabled = true;

            GUILayout.EndHorizontal();

            GUI.enabled = (i - 1) >= 0;
            if (GUILayout.Button(arrowUp, "ButtonLeft", GUILayout.Width(buttonWidth), GUILayout.Height(20.0f)))
            {
                InspectorPlusVar temp = ipv;
                vars[i]     = vars[i - 1];
                vars[i - 1] = temp;
                UpdateTarget();
            }

            GUI.enabled = (i + 1) < vars.Count;
            if (GUILayout.Button(arrowDown, "ButtonRight", GUILayout.Width(buttonWidth), GUILayout.Height(20.0f)))
            {
                InspectorPlusVar temp = ipv;
                vars[i]     = vars[i + 1];
                vars[i + 1] = temp;
                UpdateTarget();
            }

            GUI.enabled  = true;
            ipv.canWrite = GUILayout.Toggle(ipv.canWrite, new GUIContent(""));

            ipv.DrawFieldGUI();

            if (!ipv.active)
            {
                GUI.enabled = true;
            }


            if (GUI.changed)
            {
                UpdateTarget();
                dirty = true;
            }
        }
    }
    public void UpdateFields()
    {
        if (EditorApplication.timeSinceStartup - lastTime < 1.0 || attachedType == null)
        {
            return;
        }

        //UpdateFilePath();
        int  count = -1;
        Type t     = attachedType;

        FieldInfo[]          fields        = t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
        List <string>        varsCollected = new List <string>();
        InspectorPlusSummary s             = new InspectorPlusSummary();

        s.ReadSummaries(filePath);

        foreach (FieldInfo fieldInfo in fields)
        {
            if (ignoredProperties.Contains(fieldInfo.Name))
            {
                continue;
            }

            if (fieldInfo.IsPrivate && !fieldInfo.IsDefined(typeof(SerializeField), false))
            {
                continue;
            }

            if (fieldInfo.IsDefined(typeof(HideInInspector), false))
            {
                continue;
            }

            ++count;
            varsCollected.Add(fieldInfo.Name);

            if (varsHad.Contains(fieldInfo.Name))
            {
                continue;
            }

            if (!first)
            {
                varsHad.Insert(count, fieldInfo.Name);
            }
            else
            {
                varsHad.Add(fieldInfo.Name);
            }

            InspectorPlusVar newVar = new InspectorPlusVar();
            newVar.name = fieldInfo.Name;
            newVar.SetDispName();
            newVar.type      = fieldInfo.FieldType.Name;
            newVar.isArray   = fieldInfo.FieldType.IsArray;
            newVar.classType = attachedType.Name;

            if (!first)
            {
                vars.Insert(count, newVar);
            }
            else
            {
                vars.Add(newVar);
            }
        }

        foreach (FieldInfo fieldInfo in fields)
        {
            string           newTooltip = s.GetSummary(fieldInfo.Name);
            InspectorPlusVar ipv        = vars.Find(delegate(InspectorPlusVar i) { return(i.name == fieldInfo.Name); });

            if (ipv == null)
            {
                continue;
            }

            if (fieldInfo.IsDefined(typeof(InspectorTip), false))
            {
                object[] tips = fieldInfo.GetCustomAttributes(typeof(InspectorTip), false);
                newTooltip = ((InspectorTip)tips[tips.Length - 1]).tip;
            }

            if (newTooltip != "")
            {
                ipv.hasTooltip = true;
                ipv.tooltip    = newTooltip;
                ipv.fixedTip   = true;
            }
            else
            {
                ipv.fixedTip = false;
            }
        }

        vars.RemoveAll(delegate(InspectorPlusVar v) { return(!varsCollected.Contains(v.name)); });
        varsHad.RemoveAll(delegate(string n) { return(!varsCollected.Contains(n)); });

        lastTime = EditorApplication.timeSinceStartup;
        first    = false;
    }
예제 #24
0
    void VectorScene(InspectorPlusVar v, string s, Transform t)
    {
        Vector3 val;

        if (s == typeof(Vector3).Name)
        {
            val = (Vector3)GetTargetField(name);
        }
        else
        {
            val = ((Vector2)GetTargetField(name));
        }

        Vector3 newVal = Vector3.zero;
        Vector3 curVal;
        bool    setVal   = false;
        bool    relative = v.relative;
        bool    scale    = v.scale;

        switch (v.vectorDrawType)
        {
        case InspectorPlusVar.VectorDrawType.Direction:
            curVal = relative ? val:val - t.position;
            float size = scale ? Mathf.Min(2.0f, Mathf.Sqrt(curVal.magnitude) / 2.0f) : 1.0f;
            size *= HandleUtility.GetHandleSize(t.position);
            Handles.ArrowCap(0, t.position, curVal != Vector3.zero ? Quaternion.LookRotation(val.normalized) : Quaternion.identity, size);
            break;

        case InspectorPlusVar.VectorDrawType.Point:
            curVal = relative ? val:t.position + val;
            Handles.SphereCap(0, curVal, Quaternion.identity, 0.1f);
            break;

        case InspectorPlusVar.VectorDrawType.PositionHandle:
            curVal = relative ? t.position + val:val;
            setVal = true;
            newVal = Handles.PositionHandle(curVal, Quaternion.identity) - (relative ? t.position : Vector3.zero);
            break;

        case InspectorPlusVar.VectorDrawType.Scale:
            setVal = true;
            curVal = relative ? t.localScale + val :val;
            newVal = Handles.ScaleHandle(curVal, t.position + v.offset, t.rotation, HandleUtility.GetHandleSize(t.position + v.offset)) - (relative ? t.localScale : Vector3.zero);
            break;

        case InspectorPlusVar.VectorDrawType.Rotation:
            setVal = true;
            curVal = relative ? val + t.rotation.eulerAngles : val;
            newVal = Handles.RotationHandle(Quaternion.Euler(curVal), t.position + v.offset).eulerAngles - (relative?t.rotation.eulerAngles:Vector3.zero);
            break;
        }

        if (setVal)
        {
            object newObjectVal = newVal;

            if (s == typeof(Vector2).Name)
            {
                newObjectVal = (Vector2)newVal;
            }
            else if (s == typeof(Quaternion).Name)
            {
                newObjectVal = Quaternion.Euler(newVal);
            }

            SetTargetField(name, newObjectVal);
        }
    }
    public void UpdateFields()
    {
		if (EditorApplication.timeSinceStartup - lastTime < 1.0 || attachedType == null)
            return;

        //UpdateFilePath();
        int count = -1;
        Type t = attachedType;
        FieldInfo[] fields = t.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
        List<string> varsCollected = new List<string>();
		InspectorPlusSummary s = new InspectorPlusSummary();
        s.ReadSummaries(filePath);

        foreach (FieldInfo fieldInfo in fields)
        {
            if (ignoredProperties.Contains(fieldInfo.Name))
                continue;

            if (fieldInfo.IsPrivate && !fieldInfo.IsDefined(typeof(SerializeField), false))
                continue;

            if (fieldInfo.IsDefined(typeof(HideInInspector), false))
                continue;

            ++count;
            varsCollected.Add(fieldInfo.Name);

            if (varsHad.Contains(fieldInfo.Name))
                continue;

            if (!first)
                varsHad.Insert(count, fieldInfo.Name);
            else
                varsHad.Add(fieldInfo.Name);

            InspectorPlusVar newVar = new InspectorPlusVar();
            newVar.name = fieldInfo.Name;
            newVar.SetDispName();
            newVar.type = fieldInfo.FieldType.Name;
            newVar.isArray = fieldInfo.FieldType.IsArray;
            newVar.classType = attachedType.Name;

            if (!first)
                vars.Insert(count, newVar);
            else
                vars.Add(newVar);
        }

        foreach (FieldInfo fieldInfo in fields)
        {
            string newTooltip = s.GetSummary(fieldInfo.Name);
            InspectorPlusVar ipv = vars.Find(delegate(InspectorPlusVar i) { return i.name == fieldInfo.Name; });

            if (ipv == null)
                continue;

            if (fieldInfo.IsDefined(typeof(InspectorTip), false))
            {
                object[] tips = fieldInfo.GetCustomAttributes(typeof(InspectorTip), false);
                newTooltip = ((InspectorTip)tips[tips.Length - 1]).tip;
            }

            if (newTooltip != "")
            {
                ipv.hasTooltip = true;
                ipv.tooltip = newTooltip;
                ipv.fixedTip = true;
            }
            else ipv.fixedTip = false;
        }

        vars.RemoveAll(delegate(InspectorPlusVar v) { return (!varsCollected.Contains(v.name)); });
        varsHad.RemoveAll(delegate(string n) { return (!varsCollected.Contains(n)); });
		
		lastTime = EditorApplication.timeSinceStartup;
        first = false;
    }