private void _FindPrimitivesInFrustum()
    {
        m_inFrustumCount = 0;
        Vector3 cameraPos = m_camera.gameObject.transform.position;
        int     count     = m_primitives.Count;

        for (int i = 0; i < count; i++)
        {
            PrimitiveData primitive = m_primitives[i];

            if (primitive.Transform == null)
            {
                primitive.PrimitiveType = EFogVolumePrimitiveType.None;
            }
            if (primitive.PrimitiveType == EFogVolumePrimitiveType.None)
            {
                continue;
            }

            if (primitive.Primitive.IsPersistent)
            {
                Vector3 pos = primitive.Transform.position;
                primitive.SqDistance      = (pos - m_pointOfInterest).sqrMagnitude;
                primitive.Distance2Camera = (pos - cameraPos).magnitude;
                m_primitivesInFrustum[m_inFrustumCount++] = primitive;
            }
            else if (GeometryUtility.TestPlanesAABB(FrustumPlanes, m_primitives[i].Bounds))
            {
                Vector3 pos = primitive.Transform.position;
                primitive.SqDistance      = (pos - m_pointOfInterest).sqrMagnitude;
                primitive.Distance2Camera = (pos - cameraPos).magnitude;
                m_primitivesInFrustum[m_inFrustumCount++] = primitive;
            }
        }
    }
示例#2
0
        public IEnumerable <MonoBehaviour> SetReferencedData(PrimitiveData primitiveData, Table table, IMaterialProvider materialProvider, ITextureProvider textureProvider)
        {
            var mf = GetComponent <MeshFilter>();
            var playfieldMeshComponent = GetComponent <PlayfieldMeshComponent>();

            if (!mf || !playfieldMeshComponent)
            {
                return(Array.Empty <MonoBehaviour>());
            }

            var updatedComponents = new List <MonoBehaviour> {
                this
            };
            var mg   = new PrimitiveMeshGenerator(primitiveData);
            var mesh = mg
                       .GetTransformedMesh(table?.TableHeight ?? 0f, primitiveData.Mesh, Origin.Original, false)
                       .Transform(mg.TransformationMatrix(PlayfieldHeight));          // apply transformation to mesh, because this is the playfield
            var material = new PbrMaterial(
                table.GetMaterial(_playfieldMaterial),
                table.GetTexture(_playfieldImage)
                );

            MeshComponent <PrimitiveData, PrimitiveComponent> .CreateMesh(gameObject, mesh, material, "playfield_mesh", textureProvider, materialProvider);

            playfieldMeshComponent.AutoGenerate = false;

            updatedComponents.Add(playfieldMeshComponent);

            return(updatedComponents);
        }
示例#3
0
        private static Polygon CreatePolygonFromData(PrimitiveData data, float scale = 1)
        {
            try
            {
                var h = data.Bounds.Height * scale;
                var w = data.Bounds.Width * scale;

                var x = data.Bounds.X * scale;
                var y = data.Bounds.Y * scale;

                SKRect rect = SKRect.Create(new SKPoint((float)x, (float)y), new SKSize((float)w, (float)h));

                //System.Text.Json.JsonElement Points = (System.Text.Json.JsonElement)data.Parameters["Points"];

                List <Point> points = data.Points;
                //List<Point> points = System.Text.Json.JsonSerializer.Deserialize<List<Point>>(Points.ToString());
                for (int i = 0; i < points.Count; i++)
                {
                    points[i] = new Point(points[i].X * scale, points[i].Y * scale);
                }

                return(new Polygon(rect, points, (int)(data.BorderWidth * scale),
                                   SKColor.Parse(data.BorderColor).ToFormsColor(),
                                   SKColor.Parse(data.FillColor).ToFormsColor()));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
            public SingleData(XElement element)
            {
                Header = element.Attribute("Header").Value;
                var item = element.Elements().FirstOrDefault();

                PrimitiveInfo = new PrimitiveData(item);
            }
        // Converting WPF BitmapImage to and from Base64 using JpegBitmapEncoder fails for loading JPG files
        // https://stackoverflow.com/questions/40404625/converting-wpf-bitmapimage-to-and-from-base64-using-jpegbitmapencoder-fails-for
        //
        private FrameworkElement CreateImageData(PrimitiveData item)
        {
            // string -> byte[]
            var bytes = System.Convert.FromBase64String(item.Value);

            // byte[] -> BitmapImage
            using (var stream = new MemoryStream())
            {
                stream.Write(bytes, 0, bytes.Length);
                stream.Seek(0, SeekOrigin.Begin);

                try
                {
                    var bm = new BitmapImage();
                    bm.BeginInit();
                    bm.CreateOptions = BitmapCreateOptions.PreservePixelFormat;
                    bm.CacheOption   = BitmapCacheOption.OnLoad;
                    bm.StreamSource  = stream;
                    bm.EndInit();

                    return(CreateImageData(bm));
                }
                catch (Exception ex)
                {
                    var value   = $"※画像データは未対応です\r\n{ex.ToString()}";
                    var element = CreatePrimitiveElement(value);
                    var pItem   = new PrimitiveData(element);
                    return(CreatePrimitiveData(pItem));
                }
            }
        }
示例#6
0
        public static Primitive CreateFromData(PrimitiveData data, float scale = 1)
        {
            try
            {
                switch (data.Type)
                {
                case "Line":
                    return(CreateLineFromData(data, scale));

                case "Rectangle":
                    return(CreateRectangleFromData(data, scale));

                case "Ellipse":
                    return(CreateEllipseFromData(data, scale));

                case "Triangle":
                    return(CreatePolygonFromData(data, scale));

                case "Polygon":
                    return(CreatePolygonFromData(data, scale));

                default:
                    throw new Exception($"\"{data.Type}\" is invalid type primitive");
                }
            }
            catch (Exception ex)
            {
                throw new Exception("PrimitiveCreator:CreateFromData: " + ex.Message);
            }
        }
示例#7
0
        private static Line CreateLineFromData(PrimitiveData data, float scale = 1)
        {
            try
            {
                var h = data.Bounds.Height * scale;
                var w = data.Bounds.Width * scale;

                var x = data.Bounds.X * scale;
                var y = data.Bounds.Y * scale;


                //System.Text.Json.JsonElement StartPoint = (System.Text.Json.JsonElement)data.Parameters["StartPoint"];
                //System.Text.Json.JsonElement EndPoint = (System.Text.Json.JsonElement)data.Parameters["EndPoint"];

                var startX = data.Points[0].X * scale;
                var startY = data.Points[0].Y * scale;
                var endX   = data.Points[1].X * scale;
                var endY   = data.Points[1].Y * scale;

                SKPoint startPoint = new SKPoint((float)(data.Bounds.Right * scale - startX), (float)(data.Bounds.Bottom * scale - startY));
                SKPoint endPoint   = new SKPoint((float)(data.Bounds.Right * scale - endX), (float)(data.Bounds.Bottom * scale - endY));

                SKRect rect = SKRect.Create(new SKPoint((float)x, (float)y), new SKSize((float)w, (float)h));



                return(new Line(rect, startPoint, endPoint, (int)(data.BorderWidth * scale),
                                //SKColor.Parse(data.BorderColor).ToFormsColor());
                                Color.Black));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    private void _PrepareShaderArrays()
    {
        VisiblePrimitiveCount = 0;

        Quaternion fogVolumeRotation = m_fogVolume.gameObject.transform.rotation;

        for (int i = 0; i < MaxVisiblePrimitives; i++)
        {
            if (i >= m_inFrustumCount)
            {
                break;
            }

            PrimitiveData data     = m_primitivesInFrustum[i];
            Vector3       position = data.Transform.position;
            m_primitivePos[i] = gameObject.transform.InverseTransformPoint(position);
            m_primitiveTf[i].SetTRS(position,
                                    Quaternion.Inverse(data.Transform.rotation) * fogVolumeRotation,
                                    Vector3.one);
            m_primitiveScale[i] = data.Primitive.GetPrimitiveScale;
            m_primitiveData[i]  =
                new Vector4(data.PrimitiveType == EFogVolumePrimitiveType.Box ? 0.5f : 1.5f,
                            data.Primitive.IsSubtractive ? 1.5f : 0.5f,
                            0.0f,
                            0.0f);
            VisiblePrimitiveCount++;
        }
    }
示例#9
0
            public void Initialize(Model model, VisualScene scene, bool addBinormals = true, bool addTangents = true)
            {
                PrimitiveData data = null;

                if (_rig != null)
                {
                    if (_geoEntry != null)
                    {
                        data = DecodePrimitivesWeighted(scene, _bindMatrix, _geoEntry, _rig);
                    }
                    else if (_morphController != null)
                    {
                        data = DecodeMorphedPrimitivesWeighted(scene, _bindMatrix, _morphController, _rig);
                    }
                    else
                    {
                        throw new InvalidOperationException("No valid geometry or morph controller entry for object.");
                    }
                }
                else
                {
                    if (_geoEntry != null)
                    {
                        data = DecodePrimitivesUnweighted(_bindMatrix, _geoEntry);
                    }
                    else if (_morphController != null)
                    {
                        data = DecodeMorphedPrimitivesUnweighted(_bindMatrix, _morphController);
                    }
                    else
                    {
                        throw new InvalidOperationException("No valid geometry or morph controller entry for object.");
                    }
                }

                if (data == null)
                {
                    //Something went wrong and the mesh couldn't be created
                    return;
                }

                if (addBinormals || addTangents)
                {
                    data.GenerateBinormalTangentBuffers(0, 0, addBinormals, addTangents);
                }

                Material material = null;

                //var instanceMats = _inst?.BindMaterialElement?.TechniqueCommonElement?.InstanceMaterialElements;
                //if (instanceMats != null && instanceMats.Length > 0)
                //{
                //    var instanceMat = instanceMats[0];
                //    var colladaMaterial = instanceMat?.Target?.GetElement<LibraryMaterials.Material>(scene.Root);
                //    if (colladaMaterial != null)
                //        material = CreateMaterial(colladaMaterial);
                //}

                model.Children.Add(new SubMesh(_node.Name ?? _node.ID ?? _node.SID, data, material));
            }
            public void WhenSimpleState_PropertiesArePopulated()
            {
                var actual = (StateObjectData)PropertiesCollector.Collect(new State {
                    Number = 5
                });
                PrimitiveData numberData = (PrimitiveData)actual.Properties["Number"];

                Assert.That(numberData.Value, Is.EqualTo(5));
            }
        private TextBlock CreatePrimitiveData(PrimitiveData item)
        {
            Brush foreColor = (SolidColorBrush) new BrushConverter().ConvertFromString(item.ColorName);

            return(new TextBlock()
            {
                Text = item.Value, Foreground = foreColor, TextWrapping = TextWrapping.Wrap
            });
        }
示例#12
0
            public void WhenSameSourceSamePropertySameValue_ReturnsNull()
            {
                var source  = new PrimitiveData("tn", 1);
                var current = new PrimitiveObjectTreeItem(source.Value, null, "pn", source);
                var next    = new PrimitiveObjectTreeItem(source.Value, null, "pn", source);

                var actual = TreeComparer.FromPrimitive(current, next);

                Assert.That(actual, Is.Null);
            }
示例#13
0
            public void WhenDifferentSourceSamePropertyDifferentValue_DifferenceItemIsMarkedAsModified()
            {
                var currentSource = new PrimitiveData("tn", 1);
                var nextSource    = new PrimitiveData("tn", 2);
                var current       = new PrimitiveObjectTreeItem(currentSource.Value, null, "pn", currentSource);
                var next          = new PrimitiveObjectTreeItem(nextSource.Value, null, "pn", nextSource);

                var actual = TreeComparer.FromPrimitive(current, next);

                Assert.That(actual.DiffType, Is.EqualTo(DiffType.Modified));
            }
示例#14
0
            public void WhenDifferentSourceSamePropertyDifferentValue_ReturnsDifferenceItem()
            {
                var currentSource = new PrimitiveData("tn", 1);
                var nextSource    = new PrimitiveData("tn", 2);
                var current       = new PrimitiveObjectTreeItem(currentSource.Value, null, "pn", currentSource);
                var next          = new PrimitiveObjectTreeItem(nextSource.Value, null, "pn", nextSource);

                var actual = TreeComparer.FromPrimitive(current, next);

                Assert.That(actual, Is.Not.Null);
            }
示例#15
0
            public void WhenDifferentSourceSamePropertyDifferentValue_DifferenceItemContainsBothItems()
            {
                var currentSource = new PrimitiveData("tn", 1);
                var nextSource    = new PrimitiveData("tn", 2);
                var current       = new PrimitiveObjectTreeItem(currentSource.Value, null, "pn", currentSource);
                var next          = new PrimitiveObjectTreeItem(nextSource.Value, null, "pn", nextSource);

                var actual = TreeComparer.FromPrimitive(current, next);

                Assert.That(actual.Current, Is.SameAs(current));
                Assert.That(actual.Next, Is.SameAs(next));
            }
        private FrameworkElement CreateViewDataForPrimitive(XElement element)
        {
            var item = new PrimitiveData(element);

            item.TypeName = ToNormalString(item.TypeName);
            item.Value    = ToNormalString(item.Value);

            if (item.TypeName == "BitmapImage")
            {
                return(CreateImageData(item));
            }
            else
            {
                return(CreatePrimitiveData(item));
            }
        }
    public bool RemovePrimitive(Transform _primitiveToRemove)
    {
        int count = m_primitives.Count;

        for (int i = 0; i < count; i++)
        {
            PrimitiveData data = m_primitives[i];
            if (ReferenceEquals(m_primitives[i].Transform, _primitiveToRemove))
            {
                data.Reset();
                CurrentPrimitiveCount--;
                return(true);
            }
        }

        return(false);
    }
示例#18
0
        private static Elipse CreateEllipseFromData(PrimitiveData data, float scale = 1)
        {
            try
            {
                var h = data.Bounds.Height * scale;
                var w = data.Bounds.Width * scale;

                var x = data.Bounds.X * scale;
                var y = data.Bounds.Y * scale;

                return(new Elipse((int)x, (int)y, (int)w, (int)h, (int)(data.BorderWidth * scale),
                                  SKColor.Parse(data.BorderColor).ToFormsColor(),
                                  SKColor.Parse(data.FillColor).ToFormsColor()));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    private void _SortPrimitivesInFrustum()
    {
        bool finishedSorting = false;

        do
        {
            finishedSorting = true;
            for (int i = 0; i < m_inFrustumCount - 1; i++)
            {
                if (m_primitivesInFrustum[i].SqDistance > m_primitivesInFrustum[i + 1].SqDistance)
                {
                    PrimitiveData tempData = m_primitivesInFrustum[i];
                    m_primitivesInFrustum[i]     = m_primitivesInFrustum[i + 1];
                    m_primitivesInFrustum[i + 1] = tempData;
                    finishedSorting = false;
                }
            }
        }while (!finishedSorting);
    }
        public override void VisitStructDeclaration(StructDeclarationSyntax node)
        {
            var structSymbol = GetDeclaredSymbol(node) as INamedTypeSymbol;
            var attributes   = mFrontEnd.ParseAttributes(structSymbol);

            // If the type has a special primitive attribute then queue it up for processing
            foreach (var attribute in structSymbol.GetAttributes())
            {
                int priority      = 0;
                var attributeName = TypeAliases.GetFullTypeName(attribute.AttributeClass);
                if (PrimitiveAttributePriorities.TryGetValue(attributeName, out priority))
                {
                    var data = new PrimitiveData();
                    data.Priority     = priority;
                    data.Node         = node;
                    data.StructSymbol = structSymbol;
                    PrimitivesToProcess.Add(data);
                }
            }
        }
    private void _UpdateBounds()
    {
        int count = m_primitives.Count;

        for (int i = 0; i < count; i++)
        {
            PrimitiveData data = m_primitives[i];

            if (data.PrimitiveType == EFogVolumePrimitiveType.None)
            {
                continue;
            }

            if (data.Primitive == null)
            {
                RemovePrimitive(data.Transform);
                continue;
            }

            if (data.PrimitiveType == EFogVolumePrimitiveType.Box)
            {
                // Check if collider was removed by the user and add it again.
                if (data.Primitive.BoxColl == null)
                {
                    Debug.LogWarning("FogVolumePrimitive requires a collider.\nThe collider will be automatically created.");
                    data.Primitive.AddColliderIfNeccessary(EFogVolumePrimitiveType.Box);
                }
                data.Bounds = data.Primitive.BoxColl.bounds;
            }
            else if (data.PrimitiveType == EFogVolumePrimitiveType.Sphere)
            {
                // Check if collider was removed by the user and add it again.
                if (data.Primitive.SphereColl == null)
                {
                    Debug.LogWarning("FogVolumePrimitive requires a collider.\nThe collider will be automatically created.");
                    data.Primitive.AddColliderIfNeccessary(EFogVolumePrimitiveType.Sphere);
                }
                data.Bounds = data.Primitive.SphereColl.bounds;
            }
        }
    }
    public bool AddPrimitiveSphere(FogVolumePrimitive _sphere)
    {
        Assert.IsTrue(CurrentPrimitiveCount < MaxPrimitivesCount,
                      "The maximum amount of primitives is already reached!");

        int index = _FindFirstFreePrimitive();

        if (index != InvalidIndex)
        {
            PrimitiveData data = m_primitives[index];
            CurrentPrimitiveCount++;
            data.PrimitiveType = EFogVolumePrimitiveType.Sphere;
            data.Transform     = _sphere.transform;
            data.Renderer      = _sphere.GetComponent <Renderer>();
            data.Primitive     = _sphere;
            data.Bounds        = new Bounds(data.Transform.position, _sphere.GetPrimitiveScale);
            return(true);
        }

        return(false);
    }
示例#23
0
        public static PrimitiveData CreateData(VertexShaderDesc info, List <VertexPrimitive> lines, List <VertexPolygon> faces)
        {
            if (faces.Count > 0)
            {
                if (lines.Count > 0)
                {
                    WriteLine("Mesh has both lines and triangles. Only triangles will be shown in this case - PrimitiveData only supports lines OR triangles.");
                }

                return(PrimitiveData.FromTriangleList(info, faces.SelectMany(x => x.ToTriangles())));
            }
            else if (lines != null && lines.Count > 0)
            {
                return(PrimitiveData.FromLineList(info, lines.SelectMany(
                                                      x => x is VertexLineStrip strip ? strip.ToLines() : new VertexLine[] { (VertexLine)x })));
            }

            WriteLine("Mesh has no primitives.");

            return(null);//PrimitiveData.FromTriangles(VertexShaderDesc.JustPositions());
        }
示例#24
0
    public static void ResetAndPopulateDictionary()
    {
        if (_currentCSVTextAsset == null)
        {
            return;
        }
        _CSVDictionaries = new Dictionary <string, PrimitiveDataDictionary>();

        string[] rows = _currentCSVTextAsset.text.Split('\n');
        string[] keys = rows[0].Split(',');

        for (int r = 1; r < rows.Length; r++)
        {
            PrimitiveDataDictionary primitiveDataDictionary = new PrimitiveDataDictionary();
            string[] columns = rows[r].Split(',');

            for (int c = 0; c < columns.Length; c++)
            {
                string key = keys[c].Trim();
                string primitiveDataString = columns[c];

                bool   b;
                int    i;
                float  f;
                string s;

                b = primitiveDataString.ToLower().Equals("true");
                int.TryParse(primitiveDataString, out i);
                float.TryParse(primitiveDataString, out f);
                s = primitiveDataString.Trim();

                PrimitiveData primitiveData = new PrimitiveData(b, i, f, s);

                Debug.Log("DAN" + key + "DAN");
                primitiveDataDictionary.Add(key, primitiveData);
            }

            _CSVDictionaries.Add(columns[0], primitiveDataDictionary);
        }
    }
        public static void ValidatePrimitiveData(PrimitiveData data)
        {
            data.BackfacesEnabled.Should().Be(false);
            data.CollisionReductionFactor.Should().Be(0.6119f);
            data.CompressedIndices.Should().Be(53);
            data.CompressedVertices.Should().Be(135);
            data.DepthBias.Should().Be(0.1665f);
            data.DisableLightingBelow.Should().Be(0.0012f);
            data.DisableLightingTop.Should().BeInRange(0.019f, 0.02f);
            data.DisplayTexture.Should().Be(false);
            data.DrawTexturesInside.Should().Be(false);
            data.EdgeFactorUi.Should().Be(0.267f);
            data.Elasticity.Should().Be(0.3163f);
            data.ElasticityFalloff.Should().Be(0.53219f);
            data.Friction.Should().Be(0.36189f);
            data.HitEvent.Should().Be(false);
            data.Image.Should().Be("p1-beachwood");
            data.IsCollidable.Should().Be(true);
            data.IsReflectionEnabled.Should().Be(true);
            data.IsToy.Should().Be(false);
            data.IsVisible.Should().Be(true);
            data.Material.Should().Be("Playfield");
            data.MeshFileName.Should().Be("cube.obj");
            data.NormalMap.Should().Be("");
            data.NumIndices.Should().Be(36);
            data.NumVertices.Should().Be(24);
            data.OverwritePhysics.Should().Be(true);
            data.PhysicsMaterial.Should().Be("");
            data.Position.X.Should().Be(500.1f);
            data.Position.Y.Should().Be(500.2f);
            data.Position.Z.Should().Be(0.123f);
            data.RotAndTra[0].Should().Be(0.12f);
            data.RotAndTra[1].Should().Be(0.98f);
            data.RotAndTra[2].Should().Be(0.69f);
            data.RotAndTra[3].Should().Be(0.45f);
            data.RotAndTra[4].Should().Be(0.47f);
            data.RotAndTra[5].Should().Be(0.24f);
            data.RotAndTra[6].Should().Be(0.19f);
            data.RotAndTra[7].Should().Be(0.59f);
            data.RotAndTra[8].Should().Be(0.13f);
            data.Scatter.Should().Be(0.9815f);
            data.SideColor.Red.Should().Be(150);
            data.SideColor.Green.Should().Be(150);
            data.SideColor.Blue.Should().Be(150);
            data.Sides.Should().Be(4);
            data.Size.X.Should().Be(100.11f);
            data.Size.Y.Should().Be(100.22f);
            data.Size.Z.Should().Be(100.33f);
            data.StaticRendering.Should().Be(true);
            data.Threshold.Should().Be(2f);
            data.Use3DMesh.Should().Be(true);

            data.Mesh.Vertices[0].X.Should().Be(1f);
            data.Mesh.Vertices[0].Y.Should().Be(1f);
            data.Mesh.Vertices[0].Z.Should().Be(-1f);
            data.Mesh.Vertices[0].Nx.Should().Be(0f);
            data.Mesh.Vertices[0].Ny.Should().Be(1f);
            data.Mesh.Vertices[0].Nz.Should().Be(0f);
            data.Mesh.Vertices[0].Tu.Should().Be(0.375f);
            data.Mesh.Vertices[0].Tv.Should().Be(0f);
        }
        /// <summary>
        ///     Draws the data field.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="property"></param>
        /// <param name="label"></param>
        protected void DrawDataField(Rect position, SerializedProperty property, GUIContent label)
        {
            SerializedProperty useConstant = property.FindPropertyRelative("UseConstant");
            Event currentEvent             = Event.current;

            _mouseDragArea.x      = position.x;
            _mouseDragArea.y      = position.y;
            _mouseDragArea.width  = position.width;
            _mouseDragArea.height = EditorGUIUtility.singleLineHeight;

            if (_mouseDragArea.Contains(currentEvent.mousePosition))
            {
                if (currentEvent.type == EventType.DragUpdated)
                {
                    DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                    currentEvent.Use();
                }
                else if (currentEvent.type == EventType.DragPerform && DragAndDrop.objectReferences.Length > 0)
                {
                    Object             draggedObject     = DragAndDrop.objectReferences[0];
                    SerializedProperty referenceProperty = property.FindPropertyRelative("VariableType");
                    Type variableType = TypeExtensions.GetInstanceType(referenceProperty.type);

                    if (draggedObject.GetType().IsAssignableFrom(variableType))
                    {
                        referenceProperty.objectReferenceValue = draggedObject;
                        useConstant.boolValue = false;
                        property.serializedObject.ApplyModifiedProperties();
                    }

                    currentEvent.Use();

                    return;
                }
            }

            if (_labelContent == null)
            {
                _labelContent = new GUIContent(label.text, label.image, label.tooltip);
            }

            SerializedProperty displayValueChangedProperty = property.FindPropertyRelative("_displayValueChangedEvent");

            _displayValueChangedEvent = displayValueChangedProperty.boolValue;
            _isConstant             = useConstant.boolValue;
            label                   = EditorGUI.BeginProperty(position, GUIContent.none, property);
            _currentPosition        = EditorGUI.PrefixLabel(position, _labelContent);
            _positionWidth          = _currentPosition.width;
            _currentPosition.width  = _positionWidth * 0.2f;
            _currentPosition.height = EditorGUIUtility.singleLineHeight;

            EditorGUI.LabelField(position, label);

            _buttonsRect.x      = _currentPosition.x;
            _buttonsRect.y      = _currentPosition.y;
            _buttonsRect.width  = _buttonWidth;
            _buttonsRect.height = _currentPosition.height;

            if (GUI.Button(_buttonsRect, _rButtonContent))
            {
                _isConstant = false;
            }

            _buttonsRect.x += _buttonWidth;

            if (GUI.Button(_buttonsRect, _vButtonContent))
            {
                _isConstant = true;
            }

            if (_isConstant)
            {
                _buttonsRect.x     += _buttonWidth;
                _buttonsRect.width += 6f;

                // SerializedProperty persistentCalls =
                // property.FindPropertyRelative("OnConstantValueChanged._PersistentCalls");

                // Color originalColour = GUI.backgroundColor;

                // if (GUI.Button(_buttonsRect, $"E{persistentCalls.arraySize}"))
                // {
                // _displayValueChangedEvent = !_displayValueChangedEvent;
                // }

                // GUI.backgroundColor = originalColour;
            }

            _currentPosition.x    += _positionWidth * 0.28f;
            _currentPosition.width = _positionWidth * 0.72f;

            bool propertyIsArray = property.propertyPath.Contains("Array");

            if (_isConstant)
            {
                EditorGUI.BeginChangeCheck();

                EditorGUI.PropertyField(_currentPosition, property.FindPropertyRelative("ConstantValueType"),
                                        GUIContent.none);

                if (EditorGUI.EndChangeCheck())
                {
                    _invokeChangeEvent = true;
                }

                _lineHeight = propertyIsArray ? _lineHeight : 0f;
            }
            else
            {
                SerializedProperty referenceProperty = property.FindPropertyRelative("VariableType");

                bool  nullDetected  = false;
                Color currentColour = Color.white;

                if (referenceProperty.propertyType == SerializedPropertyType.ObjectReference)
                {
                    nullDetected = referenceProperty.objectReferenceValue == null;

                    if (nullDetected)
                    {
                        currentColour = GUI.color;
                    }
                }

                EditorGUI.PropertyField(_currentPosition, referenceProperty,
                                        GUIContent.none);

                if (nullDetected)
                {
                    GUI.color = currentColour;
                }

                if (!propertyIsArray)
                {
                    Type      dataType  = property.serializedObject.targetObject.GetType();
                    FieldInfo fieldData = dataType.GetField(property.propertyPath);

                    if (fieldData != null)
                    {
                        _dataValue = (DataField)fieldData.GetValue(property.serializedObject.targetObject);
                    }
                }

                PrimitiveData valueVariable = _dataValue?.GetVariable();
                object        valueData     = valueVariable != null?valueVariable.GetValueData() : null;

                if (valueData != null)
                {
                    _currentPosition.y     += EditorGUIUtility.singleLineHeight;
                    _lineHeight             = EditorGUIUtility.singleLineHeight;
                    _currentPosition.width -= 24f;

                    EditorGUI.LabelField(_currentPosition, valueData.ToString(),
                                         EditorStyles.toolbarButton);

                    _currentPosition.x    += _currentPosition.width + 2;
                    _currentPosition.width = 22f;

                    if (GUI.Button(_currentPosition, "→"))
                    {
                        Selection.activeObject = valueVariable;
                        EditorGUIUtility.PingObject(valueVariable);
                    }
                }
                else
                {
                    _lineHeight = propertyIsArray ? _lineHeight : 0f;
                }
            }

            if (_displayValueChangedEvent && _isConstant)
            {
                _currentPosition.x     = position.x;
                _currentPosition.y    += EditorGUIUtility.singleLineHeight;
                _currentPosition.width = position.width;
                EditorGUI.PropertyField(_currentPosition, property.FindPropertyRelative("OnConstantValueChanged"));
            }

            EditorGUI.EndProperty();

            if (GUI.changed)
            {
                useConstant.boolValue = _isConstant;
                displayValueChangedProperty.boolValue = _displayValueChangedEvent;
                property.serializedObject.ApplyModifiedProperties();

                if (_invokeChangeEvent)
                {
                    // object dataField = fieldInfo.GetValue(property.serializedObject.targetObject);
                    // object _event    = dataField.GetType().GetField("OnConstantValueChanged").GetValue(dataField);

                    // MethodInfo invokeMethod = _event.GetType().GetMethod("Invoke");
                    // invokeMethod.Invoke(_event, new[] {dataField.GetType().GetField("ConstantValueType").GetValue(dataField)});
                }
            }
        }
示例#27
0
        private static void ValidatePrimitiveData(PrimitiveData data)
        {
            Assert.Equal(false, data.BackfacesEnabled);
            Assert.Equal(0.6119f, data.CollisionReductionFactor);
            Assert.Equal(53, data.CompressedIndices);
            Assert.Equal(135, data.CompressedVertices);
            Assert.Equal(0.1665f, data.DepthBias);
            Assert.Equal(0.0012f, data.DisableLightingBelow);
            Assert.InRange(data.DisableLightingTop, 0.019f, 0.02f);
            Assert.Equal(false, data.DisplayTexture);
            Assert.Equal(false, data.DrawTexturesInside);
            Assert.Equal(0.267f, data.EdgeFactorUi);
            Assert.Equal(0.3163f, data.Elasticity);
            Assert.Equal(0.53219f, data.ElasticityFalloff);
            Assert.Equal(0.36189f, data.Friction);
            Assert.Equal(false, data.HitEvent);
            Assert.Equal("p1-beachwood", data.Image);
            Assert.Equal(true, data.IsCollidable);
            Assert.Equal(true, data.IsReflectionEnabled);
            Assert.Equal(false, data.IsToy);
            Assert.Equal(true, data.IsVisible);
            Assert.Equal("Playfield", data.Material);
            Assert.Equal("cube.obj", data.MeshFileName);
            Assert.Equal("", data.NormalMap);
            Assert.Equal(36, data.NumIndices);
            Assert.Equal(24, data.NumVertices);
            Assert.Equal(true, data.OverwritePhysics);
            Assert.Equal("", data.PhysicsMaterial);
            Assert.Equal(500.1f, data.Position.X);
            Assert.Equal(500.2f, data.Position.Y);
            Assert.Equal(0.123f, data.Position.Z);
            Assert.Equal(0.12f, data.RotAndTra[0]);
            Assert.Equal(0.98f, data.RotAndTra[1]);
            Assert.Equal(0.69f, data.RotAndTra[2]);
            Assert.Equal(0.45f, data.RotAndTra[3]);
            Assert.Equal(0.47f, data.RotAndTra[4]);
            Assert.Equal(0.24f, data.RotAndTra[5]);
            Assert.Equal(0.19f, data.RotAndTra[6]);
            Assert.Equal(0.59f, data.RotAndTra[7]);
            Assert.Equal(0.13f, data.RotAndTra[8]);
            Assert.Equal(0.9815f, data.Scatter);
            Assert.Equal(150, data.SideColor.Red);
            Assert.Equal(150, data.SideColor.Green);
            Assert.Equal(150, data.SideColor.Blue);
            Assert.Equal(4, data.Sides);
            Assert.Equal(100.11f, data.Size.X);
            Assert.Equal(100.22f, data.Size.Y);
            Assert.Equal(100.33f, data.Size.Z);
            Assert.Equal(true, data.StaticRendering);
            Assert.Equal(2f, data.Threshold);
            Assert.Equal(true, data.Use3DMesh);

            Assert.Equal(1f, data.Mesh.Vertices[0].X);
            Assert.Equal(1f, data.Mesh.Vertices[0].Y);
            Assert.Equal(-1f, data.Mesh.Vertices[0].Z);
            Assert.Equal(0f, data.Mesh.Vertices[0].Nx);
            Assert.Equal(1f, data.Mesh.Vertices[0].Ny);
            Assert.Equal(0f, data.Mesh.Vertices[0].Nz);
            Assert.Equal(0.375f, data.Mesh.Vertices[0].Tu);
            Assert.Equal(0f, data.Mesh.Vertices[0].Tv);
        }
示例#28
0
 public static PrimitiveObjectTreeItem FormatPrimitive(ObjectTreeItem parent, int depth, string propertyName, PrimitiveData source)
 {
     return(new PrimitiveObjectTreeItem(source.Value, parent, propertyName, source));
 }
 private object ToObject(PrimitiveData item)
 {
     return(ToObject(item.TypeName, item.Value));
 }
        private TextBlock CreatePrimitiveData(string typeName, string value, string colorName)
        {
            var item = new PrimitiveData(typeName, colorName, value);

            return(CreatePrimitiveData(item));
        }