Ejemplo n.º 1
0
    static void Create()
    {
        GameObject gameObject = new GameObject("Gear");
        GFGear     g          = (GFGear)gameObject.AddComponent(typeof(GFGear));
        GFGearGen  gg         = (GFGearGen)gameObject.AddComponent(typeof(GFGearGen));
        MeshFilter meshFilter = (MeshFilter)gameObject.GetComponent(typeof(MeshFilter));

        meshFilter.mesh = new Mesh();

        gg.Rebuild();

        gameObject.GetComponent <Renderer>().material = new Material(Shader.Find("Diffuse"));

        if (g.DrivenBy == null)
        {
            gg.alignTeethWithParent  = false;
            gg.alignRadiusWithParent = false;
        }

        GFGearGenEditor.Persist(gg);
    }
Ejemplo n.º 2
0
    override public void OnInspectorGUI()
    {
        //base.OnInspectorGUI();
        gearGen.Update();

        //RenderGUIRadiusProperties();
        EditorGUILayout.PropertyField(GearGenP("radius"));
        EditorGUILayout.PropertyField(GearGenP("innerRadius"));

        if (gearGenObject.innerRadius > 0f)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(GearGenP("innerMinVertexDistance"));
            EditorGUI.indentLevel--;
        }

        GearGenP("innerTeeth").boolValue = GearGenP("innerRadius").floatValue > GearGenP("radius").floatValue;

        EditorGUILayout.PropertyField(GearGenP("alignTeethWithParent"), new GUIContent("Align Teeth With Parent", ""));

        if (!gearGenObject.alignTeethWithParent)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.IntSlider(GearGenP("numberOfTeeth"), 2, 100, new GUIContent("Number Of Teeth", ""));
            EditorGUILayout.PropertyField(GearGenP("alignRadiusWithParent"), new GUIContent("Align Radius With Parent", ""));
            EditorGUI.indentLevel--;
        }

        toothParametersFoldout = EditorGUILayout.Foldout(toothParametersFoldout, new GUIContent("Tooth parameters", ""));
        if (toothParametersFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(GearGenP("tipLength"), new GUIContent("Tip Length", ""));
            RenderGUITipValleyProperties();
            EditorGUILayout.PropertyField(GearGenP("skew"), new GUIContent("Skew", ""));
            EditorGUI.indentLevel--;
        }


        EditorGUILayout.PropertyField(GearGenP("is3d"), new GUIContent("Is 3d", ""));
        EditorGUI.indentLevel++;
        if (gearGenObject.is3d)
        {
            EditorGUILayout.PropertyField(GearGenP("thickness"), new GUIContent("Thickness", ""));
            EditorGUILayout.PropertyField(GearGenP("fillCenter"), new GUIContent("Fill Center", ""));
            EditorGUILayout.PropertyField(GearGenP("fillOutside"), new GUIContent("Fill Outside", ""));
            EditorGUILayout.PropertyField(GearGenP("twistAngle"), new GUIContent("Twist Angle", ""));
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(GearGenP("twistOutside"), new GUIContent("Twist Outside", ""));
            EditorGUI.indentLevel--;
        }
        EditorGUI.indentLevel--;

        normalsFoldout = EditorGUILayout.Foldout(normalsFoldout, new GUIContent("Normals", ""));
        if (normalsFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(GearGenP("showNormals"), new GUIContent("Show Normals", ""));
            EditorGUILayout.PropertyField(GearGenP("splitVerticesAngle"), new GUIContent("Split Vertices Angle", ""));

            EditorGUI.indentLevel--;
        }

        uvFoldout = EditorGUILayout.Foldout(uvFoldout, new GUIContent("UV Coordinates", ""));
        if (uvFoldout)
        {
            EditorGUI.indentLevel++;
            EditorGUILayout.PropertyField(GearGenP("generateTextureCoordinates"), new GUIContent("Texture Coordinates", ""));
            if (gearGenObject.generateTextureCoordinates != GFGearGenTextureCoordinates.None)
            {
                EditorGUILayout.PropertyField(GearGenP("uvTiling"), new GUIContent("UV Tiling", ""));
                EditorGUILayout.PropertyField(GearGenP("uvOffset"), new GUIContent("UV Offset", ""));
            }
            EditorGUI.indentLevel--;
        }

        gearGen.ApplyModifiedProperties();

        if (gearGenObject.GetComponent <MeshFilter>().sharedMesh == null)
        {
            gearGenObject.Init();
        }
        // Reflect changes by regenerating gear
        if (GUI.changed)
        {
            gearGenObject.Rebuild();
        }

        string info = "";

        //		"Batching dynamic objects has certain overhead per vertex, so batching is applied only to meshes containing less than 900 vertex attributes in total.
        //If your shader is using Vertex Position, Normal and single UV, then you can batch up to 300 verts; whereas if your shader is using Vertex Position, Normal, UV0, UV1 and Tangent, then only 180 verts.
        //"900 per attribute / 4 attributes (pos + normal + UV + Tangent)"

        if (gearGenObject.numberOfVertices <= 900 / 4)
        {
            info += "[Dynamic batching (where available)]\r\n";
        }
        else
        if (gearGenObject.numberOfVertices <= 900 / 3)
        {
            info += "[Dynamic batching when not using bumpmap (where available)]\r\n";
        }

        info += "Number of vertices: " + gearGenObject.numberOfVertices + " vertices";
        info += "\r\n";
        info += "Number of faces: " + gearGenObject.numberOfFaces + " faces";
        info += "\r\n";
        info += "Removed by optimizer: " + gearGenObject.ggp.verticesRemoved + " vertices";
        info += "\r\n";

        EditorGUILayout.HelpBox(info, MessageType.Info, true);

        // GameObject has GFGear component ? Auto set the number of teeth
        if (gear != null)
        {
            gear.Update();
            GearP("numberOfTeeth").intValue = GearGenP("numberOfTeeth").intValue;
            gear.ApplyModifiedProperties();
        }
        GUILayout.Space(40);
        //DrawDefaultInspector();

        GFGearGenEditor.Persist(gearGenObject);
    }