public static string GetInterpolateFromAcceptable(string baseTypeString, ForgeAcceptableFieldTypes type) { string returnValue = string.Empty; switch (type) { case ForgeAcceptableFieldTypes.FLOAT: returnValue = "InterpolateFloat"; break; case ForgeAcceptableFieldTypes.VECTOR2: returnValue = "InterpolateVector2"; break; case ForgeAcceptableFieldTypes.VECTOR3: returnValue = "InterpolateVector3"; break; case ForgeAcceptableFieldTypes.VECTOR4: returnValue = "InterpolateVector4"; break; case ForgeAcceptableFieldTypes.QUATERNION: returnValue = "InterpolateQuaternion"; break; default: returnValue = "Interpolated<" + baseTypeString + ">"; break; } return(!string.IsNullOrEmpty(returnValue) ? returnValue : "Interpolated<object>"); }
public static bool IsInterpolatable(ForgeAcceptableFieldTypes type) { bool returnValue = false; switch (type) { case ForgeAcceptableFieldTypes.FLOAT: case ForgeAcceptableFieldTypes.VECTOR2: case ForgeAcceptableFieldTypes.VECTOR3: case ForgeAcceptableFieldTypes.VECTOR4: case ForgeAcceptableFieldTypes.QUATERNION: returnValue = true; break; case ForgeAcceptableFieldTypes.INT: case ForgeAcceptableFieldTypes.UINT: case ForgeAcceptableFieldTypes.BOOL: case ForgeAcceptableFieldTypes.BYTE: case ForgeAcceptableFieldTypes.CHAR: case ForgeAcceptableFieldTypes.DOUBLE: case ForgeAcceptableFieldTypes.LONG: case ForgeAcceptableFieldTypes.ULONG: case ForgeAcceptableFieldTypes.SHORT: case ForgeAcceptableFieldTypes.USHORT: returnValue = true; break; } return(returnValue); }
public void Render() { if (DELETED) { return; } if (!CanRender) { return; } GUILayout.BeginHorizontal(); FieldName = GUILayout.TextField(FieldName); FieldType = (ForgeAcceptableFieldTypes)EditorGUILayout.EnumPopup(FieldType, GUILayout.Width(75)); //if (FieldType == ForgeAcceptableFieldTypes.Unknown) //Unsupported //{ // Debug.LogError("Can't set the type to unknown (Not Allowed)"); // FieldType = AcceptableTypes.INT; //} if (ForgeClassFieldValue.IsInterpolatable(FieldType)) { GUI.color = Interpolate ? Color.white : Color.gray; if (GUILayout.Button("Interpolate", GUILayout.Width(100))) { Interpolate = !Interpolate; } if (Interpolate) { InterpolateValue = EditorGUILayout.FloatField(InterpolateValue, GUILayout.Width(50)); } else { InterpolateValue = ForgeNetworkingEditor.DEFAULT_INTERPOLATE_TIME; } } GUI.color = Color.white; Rect verticleButton = EditorGUILayout.BeginVertical("Button", GUILayout.Width(50), GUILayout.Height(10)); GUI.color = Color.red; if (GUI.Button(verticleButton, GUIContent.none)) { DELETED = true; } GUI.color = Color.white; GUILayout.BeginHorizontal(); //Center the icon EditorGUILayout.Space(); GUILayout.FlexibleSpace(); GUILayout.Label(ForgeNetworkingEditor.TrashIcon, GUILayout.Height(15)); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.EndVertical(); GUILayout.EndHorizontal(); }
public ForgeEditorField(string name = "", bool canRender = true, ForgeAcceptableFieldTypes type = ForgeAcceptableFieldTypes.BYTE, bool interpolate = false, float interpolateValue = 0f) { this.FieldName = name; this.FieldType = type; this.Interpolate = interpolate; this.InterpolateValue = interpolateValue; this.CanRender = canRender; }
public ForgeClassFieldValue() { FieldName = string.Empty; FieldValue = null; Interpolate = false; InterpolateValue = 0; FieldType = ForgeAcceptableFieldTypes.BYTE; }
public ForgeClassFieldValue(string name, object value, ForgeAcceptableFieldTypes type, bool interpolate, float interpolateValue) { this.FieldName = name; this.FieldValue = value; this.FieldType = type; this.Interpolate = interpolate; this.InterpolateValue = interpolateValue; }
public static bool IsInterpolatable(ForgeAcceptableFieldTypes type) { bool returnValue = false; switch (type) { case ForgeAcceptableFieldTypes.FLOAT: case ForgeAcceptableFieldTypes.VECTOR2: case ForgeAcceptableFieldTypes.VECTOR3: case ForgeAcceptableFieldTypes.VECTOR4: case ForgeAcceptableFieldTypes.QUATERNION: returnValue = true; break; } return(returnValue); }
public void Render() { if (!CanRender) { return; } GUILayout.BeginHorizontal(); FieldName = GUILayout.TextField(FieldName); FieldType = (ForgeAcceptableFieldTypes)EditorGUILayout.EnumPopup(FieldType, GUILayout.Width(75)); //if (FieldType == ForgeAcceptableFieldTypes.Unknown) //Unsupported //{ // Debug.LogError("Can't set the type to unknown (Not Allowed)"); // FieldType = AcceptableTypes.INT; //} if (!Snapshot) { if (ForgeClassFieldValue.IsInterpolatable(FieldType)) { GUI.color = Interpolate ? Color.white : Color.gray; if (GUILayout.Button("Interpolate", GUILayout.Width(100))) { Interpolate = !Interpolate; } if (Interpolate) { if (InterpolateValue == 0) { InterpolateValue = ForgeNetworkingEditor.DEFAULT_INTERPOLATE_TIME; } else { InterpolateValue = EditorGUILayout.FloatField(InterpolateValue, GUILayout.Width(50)); } } else { InterpolateValue = 0; //InterpolateValue = ForgeNetworkingEditor.DEFAULT_INTERPOLATE_TIME; } } } }
public void Render(Rect rect, bool isActive, bool isFocused) { if (!CanRender) { return; } rect.y += 2; Rect changingRect = new Rect(rect.x, rect.y, rect.width * 0.3f, EditorGUIUtility.singleLineHeight); FieldName = EditorGUI.TextField(changingRect, FieldName); changingRect.x += rect.width * 0.3f + 5; FieldType = (ForgeAcceptableFieldTypes)EditorGUI.EnumPopup(changingRect, FieldType); if (!Snapshot) { if (ForgeClassFieldValue.IsInterpolatable(FieldType)) { changingRect.x += rect.width * 0.3f + 10; changingRect.width = rect.width * 0.2f; Interpolate = EditorGUI.ToggleLeft(changingRect, " Interpolate", Interpolate); if (Interpolate) { if (InterpolateValue == 0) { InterpolateValue = ForgeNetworkingEditor.DEFAULT_INTERPOLATE_TIME; } else { changingRect.x += rect.width * 0.2f + 5; changingRect.width = rect.width * 0.3f; InterpolateValue = EditorGUI.FloatField(changingRect, InterpolateValue); } } else { InterpolateValue = 0; } } } }
public static ForgeClassFieldValue GetClassField(FieldInfo field, Type t, bool interpolate, float interpolateValue) { string name = field.Name.Replace("_", string.Empty); object value = null; //if (!t.IsAbstract) // value = field.GetValue(t); ForgeAcceptableFieldTypes type = ForgeAcceptableFieldTypes.BYTE; Type fieldType = field.FieldType; if (fieldType == typeof(int)) { type = ForgeAcceptableFieldTypes.INT; } else if (fieldType == typeof(uint)) { type = ForgeAcceptableFieldTypes.UINT; } else if (fieldType == typeof(bool)) { type = ForgeAcceptableFieldTypes.BOOL; } else if (fieldType == typeof(byte)) { type = ForgeAcceptableFieldTypes.BYTE; } else if (fieldType == typeof(char)) { type = ForgeAcceptableFieldTypes.CHAR; } else if (fieldType == typeof(double)) { type = ForgeAcceptableFieldTypes.DOUBLE; } else if (fieldType == typeof(float)) { type = ForgeAcceptableFieldTypes.FLOAT; } else if (fieldType == typeof(long)) { type = ForgeAcceptableFieldTypes.LONG; } else if (fieldType == typeof(ulong)) { type = ForgeAcceptableFieldTypes.ULONG; } else if (fieldType == typeof(short)) { type = ForgeAcceptableFieldTypes.SHORT; } else if (fieldType == typeof(ushort)) { type = ForgeAcceptableFieldTypes.USHORT; } else if (fieldType == typeof(Color)) { type = ForgeAcceptableFieldTypes.COLOR; } else if (fieldType == typeof(Quaternion)) { type = ForgeAcceptableFieldTypes.QUATERNION; } else if (fieldType == typeof(Vector2)) { type = ForgeAcceptableFieldTypes.VECTOR2; } else if (fieldType == typeof(Vector3)) { type = ForgeAcceptableFieldTypes.VECTOR3; } else if (fieldType == typeof(Vector4)) { type = ForgeAcceptableFieldTypes.VECTOR4; } //else if (fieldType == typeof(string)) // type = ForgeAcceptableFieldTypes.STRING; //Unsupported //else if (fieldType == typeof(object[])) // type = ForgeAcceptableFieldTypes.OBJECT_ARRAY; //Unsupported //else if (fieldType == typeof(byte[])) // type = ForgeAcceptableFieldTypes.BYTE_ARRAY; //else // type = ForgeAcceptableFieldTypes.Unknown; //Unsupported return(new ForgeClassFieldValue(name, value, type, interpolate, interpolateValue)); }
public static Type GetTypeFromAcceptable(ForgeAcceptableFieldTypes type) { switch (type) { case ForgeAcceptableFieldTypes.INT: return(typeof(int)); case ForgeAcceptableFieldTypes.UINT: return(typeof(uint)); case ForgeAcceptableFieldTypes.BOOL: return(typeof(bool)); case ForgeAcceptableFieldTypes.BYTE: return(typeof(byte)); case ForgeAcceptableFieldTypes.CHAR: return(typeof(char)); case ForgeAcceptableFieldTypes.DOUBLE: return(typeof(double)); case ForgeAcceptableFieldTypes.FLOAT: return(typeof(float)); case ForgeAcceptableFieldTypes.LONG: return(typeof(long)); case ForgeAcceptableFieldTypes.ULONG: return(typeof(ulong)); case ForgeAcceptableFieldTypes.SHORT: return(typeof(short)); case ForgeAcceptableFieldTypes.USHORT: return(typeof(ushort)); case ForgeAcceptableFieldTypes.COLOR: return(typeof(Color)); case ForgeAcceptableFieldTypes.QUATERNION: return(typeof(Quaternion)); case ForgeAcceptableFieldTypes.VECTOR2: return(typeof(Vector2)); case ForgeAcceptableFieldTypes.VECTOR3: return(typeof(Vector3)); case ForgeAcceptableFieldTypes.VECTOR4: return(typeof(Vector4)); //case ForgeAcceptableFieldTypes.STRING: //Unsupported // return typeof(string); //case ForgeAcceptableFieldTypes.OBJECT_ARRAY: //Unsupported // return typeof(object[]); //case ForgeAcceptableFieldTypes.BYTE_ARRAY: // return typeof(byte[]); default: return(null); } }