Exemplo n.º 1
0
                private void SetDefaultValue(SerializedProperty serializedInput)
                {
                    Type nodeInputType = SerializedPropertyUtils.GetSerializedPropertyType(serializedInput);
                    NodeGraphComponent nodeGraphComponent = (NodeGraphComponent)target;

                    //Default Transform nodes to this GameObject's Transform
                    if (nodeInputType == typeof(NodeGraphComponent.TransformInput))
                    {
                        DynamicTransformRef transformRef = nodeGraphComponent.transform;
                        SerializedProperty  valueProp    = serializedInput.FindPropertyRelative("_valueSource");
                        SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, transformRef);
                    }
                    //Default Material nodes to this GameObject's Renderer's material
                    else if (nodeInputType == typeof(NodeGraphComponent.MaterialInput))
                    {
                        Renderer renderer = nodeGraphComponent.GetComponent <Renderer>();

                        if (renderer != null)
                        {
                            DynamicMaterialRef materialRef = DynamicMaterialRef.InstancedMaterialRef(renderer);
                            SerializedProperty valueProp   = serializedInput.FindPropertyRelative("_valueSource");
                            SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, materialRef);
                        }
                    }
                    //Default GameObject nodes to this GameObject
                    else if (nodeInputType == typeof(NodeGraphComponent.GameObjectInput))
                    {
                        DynamicGameObjectRef gameObjectRef = nodeGraphComponent.gameObject;
                        SerializedProperty   valueProp     = serializedInput.FindPropertyRelative("_valueSource");
                        SerializedPropertyUtils.SetSerializedPropertyValue(valueProp, gameObjectRef);
                    }
                }
Exemplo n.º 2
0
            public static DynamicMaterialRef StaticMaterialRef(Material material)
            {
                DynamicMaterialRef dynamicMaterial = new DynamicMaterialRef
                {
                    _value = new MaterialRefProperty(material)
                };

                return(dynamicMaterial);
            }
Exemplo n.º 3
0
            public static DynamicMaterialRef InstancedMaterialRef(Renderer renderer, int materialIndex = 0)
            {
                DynamicMaterialRef dynamicMaterial = new DynamicMaterialRef();

                if (renderer != null)
                {
                    dynamicMaterial._value = new MaterialRefProperty(renderer.materials[materialIndex], materialIndex, renderer);
                }

                return(dynamicMaterial);
            }