コード例 #1
0
        public void OnDrawGizmos()
        {
            if (MeshFilter.mesh == null)
            {
                MeshFilter.mesh = new Mesh();
            }

            if (Points == null || Points.Count < 3)
            {
                return;
            }

            VertList = new List <VertexDefinition>();

            float colorNum = 0f;

            var lastVert = new VertexDefinition(Points.First().position, ColorUtility.HsvtoRgb(0, .8f, 1f));

            foreach (var point in Points)
            {
                var thisVert = new VertexDefinition(point.position,
                                                    ColorUtility.HsvtoRgb(colorNum, .8f, 1f),
                                                    lastVert.Position,
                                                    point.position);

                colorNum += COLOR_MOD;
                VertList.Add(thisVert);
                lastVert.NextPosition = thisVert.Position;
                lastVert = thisVert;
            }

            // last point required here to complete triangle

            MeshFilter.mesh.Clear();

            MeshFilter.mesh.vertices = VertList.Select(vertex => vertex.Position).ToArray();
            MeshFilter.mesh.colors   = VertList.Select(vertex => vertex.Color).ToArray();
            MeshFilter.mesh.normals  = VertList.Select(vertex => vertex.NextPosition - vertex.Position).ToArray();
            MeshFilter.mesh.tangents = VertList.Select(vertex => (vertex.LastPosition - vertex.Position).ConvertToVector4()).ToArray();


            var indices = new List <int>();

            for (var i = 0; i < VertList.Count; i++)
            {
                indices.Add(i);
            }

            MeshFilter.mesh.SetIndices(indices.ToArray(), MeshTopology.LineStrip, 0);

            MeshFilter.mesh.UploadMeshData(false);
        }
コード例 #2
0
        protected override Color ColorLerp(MutableObject mutable, Color a, Color b, float proportion)
        {
            var endColor = b;

            if (DoApplyColorField.GetFirstValue(mutable))
            {
                endColor =
                    UsePreciseLerp.GetFirstValue(mutable)?
                    ColorUtility.SqrLerpColors(a, b, proportion):
                    a + (b - a) * proportion;
            }

            endColor.a = DoApplyAlphaField.GetFirstValue(mutable) ? a.a + (b.a - a.a) * proportion : b.a;

            return(endColor);
        }
コード例 #3
0
        protected override Color ColorLerp(MutableObject mutable, Color a, Color b, float proportion)
        {
            float H1, S1, V1;
            float H2, S2, V2;

            ColorUtility.RGBToHSV(a, out H1, out S1, out V1);
            ColorUtility.RGBToHSV(b, out H2, out S2, out V2);

            float endH = ApplyHLerpField.GetFirstValue(mutable) ? H1 + (H2 - H1) * proportion : H2;
            float endS = ApplySLerpField.GetFirstValue(mutable) ? S1 + (S2 - S1) * proportion : S2;
            float endV = ApplyVLerpField.GetFirstValue(mutable) ? V1 + (V2 - V1) * proportion : V2;

            Color endColor = ColorUtility.HsvtoRgb(endH, endS, endV);

            endColor.a = DoApplyAlphaField.GetFirstValue(mutable)?a.a + (b.a - a.a) * proportion:b.a;

            return(endColor);
        }
コード例 #4
0
ファイル: StringExtensions.cs プロジェクト: voidALPHA/cgc_viz
        public static bool StringToValueOfType(this string text, Type t, ref object result, bool errorMessages = false)
        {
            if (t == typeof(string))
            {
                result = text;
                return(true);
            }

            if (t == typeof(bool))
            {
                bool v;
                if (bool.TryParse(text, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to bool\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(int))
            {
                int v;
                if (Int32.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to integer\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(uint))
            {
                uint v;
                if (UInt32.TryParse(text, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to unsigned integer\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(long))
            {
                long v;
                if (long.TryParse(text, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to long integer\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(float))
            {
                float v;
                if (float.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out v))
                {
                    result = v;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to float\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(Color))
            {
                var colorValue = Color.magenta;
                if (ColorUtility.TryParse(text, ref colorValue))
                {
                    result = colorValue;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to color\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(Vector3))
            {
                var vector3Value = new Vector3();
                if (VectorUtility.TryParseVector(text, ref vector3Value))
                {
                    result = vector3Value;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to vector3\n");
                    }
                    return(false);
                }
            }

            if (t == typeof(Quaternion))
            {
                var quaternionValue = new Quaternion();
                if (QuaternionUtility.TryParseQuaternion(text, ref quaternionValue))
                {
                    result = quaternionValue;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to quaternion\n");
                    }
                    return(false);
                }
            }

            if (t.IsEnum)
            {
                // No TryParse until .NET 4...so we have to handle exceptions
                object value = null;
                var    valid = true;
                int    temp;
                if (Int32.TryParse(text, out temp))    // Check to see if it's just a number...then fail it.  (Enum.Parse allows it!)
                {
                    valid = false;
                }
                else
                {
                    try
                    {
                        value = Enum.Parse(t, text, true);
                    }
                    catch (Exception)
                    {
                        valid = false;
                    }
                }

                if (valid)
                {
                    result = value;
                    return(true);
                }
                else
                {
                    if (errorMessages)
                    {
                        Debug.Log("Error:  Cannot convert argument \"" + text + "\" to the required enum.  Valid enum values are:\n");
                        foreach (var val in Enum.GetValues(t))
                        {
                            Debug.Log("   " + val);
                        }
                    }
                    return(false);
                }
            }

            Debug.LogError("Error:  Argument type not yet supported.  Assigning \"\"");

            result = "";
            return(true);
        }