// NON-ADDITIVE IEnumerator LerpMesh(ArrayList parameterInfo) { MeshFilter selectionAsMeshFilter = (MeshFilter)m_Selection; // Set elapsed time to 0 float elapsed = 0f; string parameterName = (string)parameterInfo[1]; Mesh[] meshes = (Mesh[])parameterInfo[2]; Mesh target = meshes[Mathf.FloorToInt(Random.value * meshes.Length)]; MethodInfo getter = m_Selection.GetType().GetProperty(parameterName).GetGetMethod(); MethodInfo setter = selectionAsMeshFilter.GetType().GetProperty(parameterName).GetSetMethod(); // Get the current value of the parameter Mesh start = (Mesh)getter.Invoke(m_Selection, null); //m_ParameterText.text = m_Selection.GetType() + " " + m_Selection.name + " " + m_Selection.GetInstanceID() + "\n" + parameterName + ": " + startRotation; bool lerpingBack = false; bool lerpingForward = true; // Loop while the time has not yet elapsed while (elapsed < m_CurrentLerpTime) { // Track how much time passed in this loop elapsed += Time.deltaTime; if (elapsed >= m_CurrentLerpTime / 2 && lerpingForward) { setter.Invoke(m_Selection, new object[] { target }); lerpingForward = false; } if (m_Bounce && elapsed >= m_CurrentLerpTime && !lerpingBack) { elapsed = 0; target = start; lerpingBack = true; lerpingForward = true; } //m_ParameterText.text = m_Selection.transform.GetType() + " " + m_Selection.name + " " + m_Selection.GetInstanceID() + "\n" + parameterName + ": " + newRotation; // Yield until the next frame yield return(null); } m_LerpComplete = true; }
// Start is called before the first frame update void Start() { obj = ItemList.IL.GetItem(item); MeshFilter filter = gameObject.GetComponent <MeshFilter>(); MeshRenderer renderer = gameObject.GetComponent <MeshRenderer>(); MeshCollider collider = gameObject.GetComponent <MeshCollider>(); Debug.Assert(filter != null, gameObject.name + " expected to have a " + filter.GetType()); Debug.Assert(renderer != null, gameObject.name + " expected to have a " + renderer.GetType()); Debug.Assert(collider != null, gameObject.name + " expected to have a " + collider.GetType()); gameObject.GetComponent <MeshFilter>().sharedMesh = obj.staticMesh; gameObject.GetComponent <MeshRenderer>().sharedMaterial = obj.mat; gameObject.GetComponent <MeshCollider>().sharedMesh = obj.col; }
GameObject CreateMimic() { GameObject mimic = new GameObject("Mimic " + gameObject.name); mimic.AddComponent <Mimic>(); MeshFilter meshFilter = mimic.AddComponent <MeshFilter>(); FieldInfo[] fields = meshFilter.GetType().GetFields(); foreach (FieldInfo field in fields) { field.SetValue(meshFilter, field.GetValue(GetComponent <MeshFilter>())); } return(mimic); }
static public ComponentDetail CreateDetail(Object obj, AssetFinderWindow assetFinder) { GameObject go = obj as GameObject; List <DetailButton> detailButtonList = new List <DetailButton>(); if (assetFinder.assetType == MATERIALS) { foreach (Renderer renderer in go.GetComponents <Renderer>()) { foreach (Material mat in renderer.sharedMaterials) { if (mat == assetFinder.filterMaterial) { GUIContent guiContent = EditorGUIUtility.ObjectContent(renderer, typeof(Renderer)); guiContent.tooltip = renderer.GetType().Name; detailButtonList.Add(new DetailButton(guiContent)); break; } } } } else if (assetFinder.assetType == TEXTURES) { foreach (Renderer renderer in go.GetComponents <Renderer>()) { foreach (Material mat in renderer.sharedMaterials) { if (mat != null) { Material material = mat; //Second reference to material that won't change and will be used by the delegate. Shader s = material.shader; if (!s.name.StartsWith(assetFinder.shaderName)) { continue; } int propCount = ShaderUtil.GetPropertyCount(s); for (int i = 0; i < propCount; i++) { if (ShaderUtil.GetPropertyType(s, i) == ShaderUtil.ShaderPropertyType.TexEnv) { string propName = ShaderUtil.GetPropertyName(s, i); if ((assetFinder.materialPropertyName.Equals("") || assetFinder.materialPropertyName.Equals(propName)) && material.HasProperty(propName)) { Texture texture = material.GetTexture(propName); if (texture == assetFinder.filterTexture) { GUIContent guiContent = EditorGUIUtility.ObjectContent(renderer, typeof(Renderer)); guiContent.tooltip = material.name + "(" + propName + ")"; detailButtonList.Add(new DetailButton(EditorGUIUtility.ObjectContent(renderer, typeof(Renderer)), delegate() { EditorGUIUtility.PingObject(material); } )); break; } } } } } } } } else if (assetFinder.assetType == MESHES) { MeshFilter mf = go.GetComponent <MeshFilter>(); if (mf != null && mf.sharedMesh == assetFinder.filterMesh) { GUIContent guiContent = EditorGUIUtility.ObjectContent(mf, typeof(MeshFilter)); guiContent.tooltip = mf.GetType().Name; detailButtonList.Add(new DetailButton(guiContent)); } SkinnedMeshRenderer smr = go.GetComponent <SkinnedMeshRenderer>(); if (smr != null && smr.sharedMesh == assetFinder.filterMesh) { GUIContent guiContent = EditorGUIUtility.ObjectContent(smr, typeof(SkinnedMeshRenderer)); guiContent.tooltip = smr.GetType().Name; detailButtonList.Add(new DetailButton(guiContent)); } foreach (MeshCollider mc in go.GetComponents <MeshCollider>()) { if (mc.sharedMesh == assetFinder.filterMesh) { GUIContent guiContent = EditorGUIUtility.ObjectContent(mc, typeof(MeshCollider)); guiContent.tooltip = mc.GetType().Name; detailButtonList.Add(new DetailButton(guiContent)); } } } return(new ComponentDetail(go, detailButtonList.ToArray())); }