示例#1
0
        public void Initialize(meshEchoType echoType)
        {
            // checks
            if (!GetComponent <MeshFilter>())
            {
                Destroy(gameObject);
                return;
            }
            if (!GetComponent <MeshRenderer>())
            {
                Destroy(gameObject);
                return;
            }
            parentMesh = (OSC_Mesh)this.GetComponentInParent(typeof(OSC_Mesh));
            if (parentMesh == null)
            {
                Destroy(gameObject);
                return;
            }
            if (!parentMesh.noClearTime && parentMesh.clearTime == 0.0f && parentMesh.traceTime == 0.0f)
            {
                Destroy(gameObject);
                return;
            }
            if (parentMesh.mesh == null)
            {
                Destroy(gameObject);
                return;
            }
            if (parentMesh.mesh.vertices.Length == 0)
            {
                Destroy(gameObject);
                return;
            }
            if (parentMesh.material == null)
            {
                Destroy(gameObject);
                return;
            }
            // setup
            mesh          = new Mesh();
            mesh.vertices = parentMesh.mesh.vertices;
            mesh.SetIndices(parentMesh.mesh.GetIndices(0), parentMesh.mesh.GetTopology(0), 0, false);
            GetComponent <MeshFilter>().mesh = mesh;

            material       = new Material(parentMesh.material.shader);
            material.color = parentMesh.material.color;
            GetComponent <MeshRenderer>().material = material;

            transform.position = parentMesh.transform.position;
            transform.rotation = parentMesh.transform.rotation;

            // setup specific types
            meshEcho = echoType;
            if (meshEcho == meshEchoType.noClearTime)
            {
                mesh.UploadMeshData(true);
            }
            else if (meshEcho == meshEchoType.clearTime)
            {
                mesh.UploadMeshData(true);
                clearTime = parentMesh.clearTime;
            }
            else if (meshEcho == meshEchoType.traceTime)
            {
                mesh.MarkDynamic();
                traceTime      = parentMesh.traceTime;
                initialAlpha   = parentMesh.alpha;
                currentColor   = material.color;
                material       = new Material(Shader.Find("Transparent/Diffuse"));
                material.color = currentColor;
                GetComponent <MeshRenderer>().material = material;
                startTime = MainSettingsVars.time;
            }
            else
            {
                Destroy(gameObject);
                return;
            }
            initialized = true;
        }
        public override void OnInspectorGUI()
        {
            OSC_Mesh monoTarget = (OSC_Mesh)target;

            // Show the editor controls.
            serializedObject.Update();

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(active, new GUIContent("Active", ""));
            if (EditorGUI.EndChangeCheck())
            {
                monoTarget.active = active.boolValue;
            }

            monoTarget.peaks = EditorGUILayout.IntSlider(new GUIContent("Peaks", ""), peaks.intValue, 0, MainSettingsVars.pointsLength);
            monoTarget.level = EditorGUILayout.Slider(new GUIContent("Level", ""), level.floatValue, 0, 1f);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(meshTopologySelect, new GUIContent("Topology", ""));
            if (EditorGUI.EndChangeCheck())
            {
                monoTarget.meshTopologySelect = (meshTopology)System.Enum.Parse(typeof(meshTopology), meshTopologySelect.enumValueIndex.ToString());
                if (MainSettingsVars.data.gui_enabled && MainSettingsVars.guiComponent != null)
                {
                    MainSettingsVars.guiComponent.guiGridMeshTopologyInt[monoTarget.meshNumber] = meshTopologySelect.enumValueIndex;
                }
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(meshColorSelect, new GUIContent("Color", ""));
            if (EditorGUI.EndChangeCheck())
            {
                monoTarget.meshColorSelect = (meshColor)System.Enum.Parse(typeof(meshColor), meshColorSelect.enumValueIndex.ToString());
                if (MainSettingsVars.data.gui_enabled && MainSettingsVars.guiComponent != null)
                {
                    MainSettingsVars.guiComponent.guiGridMeshColorInt[monoTarget.meshNumber] = meshColorSelect.enumValueIndex;
                }
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(meshShaderSelect, new GUIContent("Material", ""));
            if (EditorGUI.EndChangeCheck())
            {
                monoTarget.meshShaderSelect = (meshShader)System.Enum.Parse(typeof(meshShader), meshShaderSelect.enumValueIndex.ToString());
                if (MainSettingsVars.data.gui_enabled && MainSettingsVars.guiComponent != null)
                {
                    MainSettingsVars.guiComponent.guiGridMeshShaderInt[monoTarget.meshNumber] = meshShaderSelect.enumValueIndex;
                }
            }

            if (meshShaderSelect.enumValueIndex == 2)
            {
                EditorGUI.indentLevel++;
                monoTarget.alpha = EditorGUILayout.Slider(new GUIContent("Opacity", ""), alpha.floatValue, 0, 1f);
                EditorGUI.indentLevel--;
            }

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(randomX, new GUIContent("Random end point X", ""));
            if (EditorGUI.EndChangeCheck())
            {
                monoTarget.randomX = randomX.boolValue;
            }
            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(randomY, new GUIContent("Random end point Y", ""));
            if (EditorGUI.EndChangeCheck())
            {
                monoTarget.randomY = randomY.boolValue;
            }

            monoTarget.rotateSpeed = EditorGUILayout.Slider(new GUIContent("Rotate forward/back", ""), rotateSpeed.floatValue, -1f, 1f);
            monoTarget.smoothTime  = EditorGUILayout.Slider(new GUIContent("Smooth time (sec)", ""), smoothTime.floatValue, 0, 0.5f);
            monoTarget.clearTime   = EditorGUILayout.Slider(new GUIContent("Clear time (sec)", ""), clearTime.floatValue, 0, 30f);

            EditorGUI.BeginChangeCheck();
            EditorGUILayout.PropertyField(noClearTime, new GUIContent("No clear time", ""));
            if (EditorGUI.EndChangeCheck())
            {
                monoTarget.noClearTime = noClearTime.boolValue;
            }

            monoTarget.traceTime = EditorGUILayout.Slider(new GUIContent("Trace time (sec)", ""), traceTime.floatValue, 0, 2f);

            serializedObject.ApplyModifiedProperties();
            if (GUI.changed)
            {
                EditorUtility.SetDirty(target);
                // set data

                /*
                 * if (monoTarget.data != null) {
                 *      monoTarget.data.active = active.boolValue;
                 *      monoTarget.data.peaks = peaks.intValue;
                 *      monoTarget.data.level = level.floatValue;
                 *      monoTarget.data.meshTopologySelect = (meshTopology)System.Enum.Parse(typeof(meshTopology), meshTopologySelect.enumValueIndex.ToString());
                 *      monoTarget.data.meshColorSelect = (meshColor)System.Enum.Parse(typeof(meshColor), meshColorSelect.enumValueIndex.ToString());
                 *      monoTarget.data.meshShaderSelect = (meshShader)System.Enum.Parse(typeof(meshShader), meshShaderSelect.enumValueIndex.ToString());
                 *      monoTarget.data.alpha = alpha.floatValue;
                 *      monoTarget.data.randomX = randomX.boolValue;
                 *      monoTarget.data.randomY = randomY.boolValue;
                 *      monoTarget.data.rotateSpeed = rotateSpeed.floatValue;
                 *      monoTarget.data.smoothTime = smoothTime.floatValue;
                 *      monoTarget.data.clearTime = clearTime.floatValue;
                 *      monoTarget.data.noClearTime = noClearTime.boolValue;
                 *      monoTarget.data.traceTime = traceTime.floatValue;
                 * }
                 */
            }
        }