public bool OverridesWall(string textureName, GameObject gameObject, MeshRenderer mr) { if (!OverrideWallMaterials.ContainsKey(textureName)) { return(false); } MaterialOverride mo = OverrideWallMaterials [textureName]; //if (mo.layer != -1) //gameObject.layer = mo.layer; if (mo.material != null) { mr.material = mo.material; } else { mr.material = defaultMaterial; } if (mo.animation.textureFrames.Length > 0) { TextureAnimation anim = gameObject.AddComponent <TextureAnimation>(); anim.frames = mo.animation.textureFrames; anim.textureType = TextureAnimation.TextureType.Wall; anim.frameTime = mo.animation.frameTime; } return(true); }
public bool OverridesFlat(string textureName, GameObject gameObject, MeshRenderer mr) { if (!OverrideFlatMaterials.ContainsKey(textureName)) { return(false); } MaterialOverride mo = OverrideFlatMaterials [textureName]; if (mo.overrideName.Contains("NUKAGE")) { gameObject.layer = LayerMask.NameToLayer("NUKAGE"); } if (mo.material != null) { mr.material = mo.material; } else { mr.material = defaultMaterial; } if (mo.animation.textureFrames.Length > 0) { TextureAnimation anim = gameObject.AddComponent <TextureAnimation>(); anim.frames = mo.animation.textureFrames; anim.textureType = TextureAnimation.TextureType.Flat; anim.frameTime = mo.animation.frameTime; } return(true); }
/// <summary> /// Copy basic properties to another component (helper function to help with Cloning). /// </summary> /// <param name="copyTo">Other component to copy values to.</param> /// <returns>The object we are copying properties to.</returns> protected override BaseComponent CopyBasics(BaseComponent copyTo) { ModelRenderer other = copyTo as ModelRenderer; other.MaterialOverride = MaterialOverride.Clone(); other._entity.CopyMaterials(_entity.OverrideMaterialsDictionary); return(base.CopyBasics(other)); }
public BlockData() { this.blockPerm = "000000000000FFFF"; this.walkableData = new bool[] { true, true, true, true, true, true }; this.materialOverrides = new List <MaterialOverride>(); for (int ii = 16; ii < 64; ii++) { MaterialOverride materialOverride = new MaterialOverride(); materialOverride.voxelIndex = ii; materialOverride.material = "Materials/concrete"; materialOverrides.Add(materialOverride); } }
//TODO(andrew.theisen): can we avoid this SO update? private void ApplyToOverrideAsset(object index) { serializedObject.Update(); int intIndex = (int)index; SerializedProperty overrideListProp = serializedObject.FindProperty("overrideList"); SerializedProperty overrideProp = overrideListProp.GetArrayElementAtIndex(intIndex); SerializedProperty value = overrideProp.FindPropertyRelative("value"); SerializedProperty instanceProp = overrideProp.FindPropertyRelative("instanceOverride"); instanceProp.boolValue = false; serializedObject.ApplyModifiedProperties(); MaterialOverride overrideComponent = (target as MaterialOverride); SerializedObject assetSerializedObj = new SerializedObject(overrideComponent.overrideAsset); assetSerializedObj.Update(); SerializedProperty assetOverrideProp = assetSerializedObj.FindProperty("overrideList").GetArrayElementAtIndex(intIndex); assetOverrideProp.FindPropertyRelative("value").vector4Value = value.vector4Value; assetOverrideProp.FindPropertyRelative("instanceOverride").boolValue = false; assetSerializedObj.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); DrawDefaultInspector(); MaterialOverride overrideComponent = (target as MaterialOverride); if (overrideComponent != null) { MaterialOverrideAsset overrideAsset = overrideComponent.overrideAsset; if (overrideAsset != null) { SerializedObject assetObj = new SerializedObject(overrideAsset); assetObj.Update(); //TODO(atheisen): this just provides a way to edit the asset from the gameobject for convenience. we might actually want assets to be overridable as well SerializedProperty overrideListProp = assetObj.FindProperty("overrideList"); for (int i = 0; i < overrideListProp.arraySize; i++) { SerializedProperty overrideProp = overrideListProp.GetArrayElementAtIndex(i); string strName = overrideProp.FindPropertyRelative("name").stringValue; ShaderPropertyType type = (ShaderPropertyType)overrideProp.FindPropertyRelative("type").intValue; switch (type) { case (ShaderPropertyType.Color): { SerializedProperty colorProp = overrideProp.FindPropertyRelative("colorValue"); EditorGUILayout.PropertyField(colorProp, new GUIContent(strName)); break; } case (ShaderPropertyType.Vector): { SerializedProperty vector4Prop = overrideProp.FindPropertyRelative("vector4Value"); EditorGUILayout.PropertyField(vector4Prop, new GUIContent(strName)); break; } case (ShaderPropertyType.Float): { SerializedProperty floatProp = overrideProp.FindPropertyRelative("floatValue"); EditorGUILayout.PropertyField(floatProp, new GUIContent(strName)); break; } default: { Debug.Log("Property " + strName + " is of unsupported type " + type + " for material override."); break; } } } assetObj.ApplyModifiedProperties(); } } serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { Font defaultFont = EditorStyles.label.font; serializedObject.Update(); SerializedProperty assetProp = serializedObject.FindProperty("overrideAsset"); EditorGUILayout.PropertyField(assetProp, new GUIContent("Override Asset")); MaterialOverride overrideComponent = (target as MaterialOverride); if (overrideComponent != null) { MaterialOverrideAsset overrideAsset = overrideComponent.overrideAsset; if (overrideAsset != null) { SerializedProperty overrideListProp = serializedObject.FindProperty("overrideList"); for (int i = 0; i < overrideListProp.arraySize; i++) { SerializedProperty overrideProp = overrideListProp.GetArrayElementAtIndex(i); string displayName = overrideProp.FindPropertyRelative("displayName").stringValue; ShaderPropertyType type = (ShaderPropertyType)overrideProp.FindPropertyRelative("type").intValue; SerializedProperty instanceProp = overrideProp.FindPropertyRelative("instanceOverride"); Rect fieldRect = EditorGUILayout.GetControlRect(true, EditorGUIUtility.singleLineHeight); GUI.skin.font = defaultFont; if (instanceProp.boolValue) { DrawOverrideMargin(fieldRect); GUI.skin.font = EditorStyles.boldFont; } EditorGUI.BeginChangeCheck(); if (type == ShaderPropertyType.Color) { SerializedProperty colorProp = overrideProp.FindPropertyRelative("value"); Color color = new Color(colorProp.vector4Value.x, colorProp.vector4Value.y, colorProp.vector4Value.z, colorProp.vector4Value.w); Color newColor = EditorGUI.ColorField(fieldRect, new GUIContent(displayName), color); Vector4 vec4 = new Vector4(newColor.r, newColor.g, newColor.b, newColor.a); colorProp.vector4Value = vec4; } else if (type == ShaderPropertyType.Vector) { SerializedProperty vector4Prop = overrideProp.FindPropertyRelative("value"); Vector4 vec4 = vector4Prop.vector4Value; Vector4 newVec4 = EditorGUI.Vector4Field(fieldRect, new GUIContent(displayName), vec4); vector4Prop.vector4Value = newVec4; } else if (type == ShaderPropertyType.Float || type == ShaderPropertyType.Range) { SerializedProperty floatProp = overrideProp.FindPropertyRelative("value"); float f = floatProp.vector4Value.x; float newF = EditorGUI.FloatField(fieldRect, new GUIContent(displayName), f); floatProp.vector4Value = new Vector4(newF, 0.0f, 0.0f, 0.0f); } else { Debug.Log("Property " + displayName + " is of unsupported type " + type + " for material override."); } if (EditorGUI.EndChangeCheck()) { instanceProp.boolValue = true; } if (instanceProp.boolValue) { if (fieldRect.Contains(Event.current.mousePosition) && Event.current.type == EventType.ContextClick) { GenericMenu menu = new GenericMenu(); menu.AddItem(new GUIContent("Apply to MaterialOverride '" + overrideComponent.overrideAsset.name + "'"), false, ApplyToOverrideAsset, i); menu.AddItem(new GUIContent("Revert"), false, RevertGameobjectOverride, i); menu.ShowAsContext(); Event.current.Use(); } } } } } serializedObject.ApplyModifiedProperties(); }