public void HighlightObject(GameObject obj, bool highlighted, Color hlColor) { if (obj == null) { throw new NullReferenceException(); } bool alreadyHighlighted = highlightedObjects.ContainsKey(obj); UnhighlightAll(obj); // unhighlight all if (highlighted && !alreadyHighlighted) { MaterialMap origMaterialMap = new MaterialMap(); MaterialMap highlightMaterialMap = new MaterialMap(); RenderingUtility.CloneMaterials(obj, origMaterialMap, highlightMaterialMap); RenderingUtility.ChangeColor(obj, hlColor, true, true); highlightedObjects.Add(obj, origMaterialMap); } if (!highlighted && highlightedObjects.ContainsKey(obj)) { RenderingUtility.ReplaceMaterials(obj, highlightedObjects[obj]); highlightedObjects[obj].Clear(); highlightedObjects.Remove(obj); } }
private void CreateObjectAlias() { objectEntity = OriginalObject.GetComponentInParent <EntityData>(); anchorFace = objectEntity.anchorSide; coloredMaterial = RenderingUtility.CreateColoredMaterial(collisionPositionColor); aliasObject = Instantiate(OriginalObject); PhysicsUtility.SetColliderConvex(aliasObject, true); originalHeadingOffset = aliasObject.transform.eulerAngles.y; aliasObject.transform.rotation = Quaternion.identity; Bounds bounds = PhysicsUtility.GetColliderBounds(aliasObject); aliasObjBoundAnchor = MathUtility.GetBoundsFaceCenter(bounds, anchorFace) - aliasObject.transform.position; aliasObject.transform.SetParent(transform); currentHeadingOffset = 0;// aliasObject.transform.eulerAngles.y; collisionOffset = 0; RenderingUtility.ChangeLayerRecursive(aliasObject, "Ignore Raycast"); RenderingUtility.BackupMaterials(aliasObject, originalMaterialMap); RenderingUtility.ReplaceMaterials(aliasObject, coloredMaterial); collisionState = aliasObject.AddComponent <CollisionState>(); aliasObjectRigidbody = aliasObject.AddComponent <Rigidbody>(); aliasObjectRigidbody.useGravity = false; aliasObjectRigidbody.freezeRotation = true; aliasObjectRigidbody.drag = 1000; //rb.isKinematic = true; }
public void UnhighlightAll(GameObject excludedObj = null) { if (highlightedObjects.Count > 0) { MaterialMap origMaterialMap = null; foreach (var item in highlightedObjects) { if (item.Key == excludedObj && excludedObj != null) { origMaterialMap = item.Value; } if (item.Key != excludedObj && item.Key != null && item.Value != null) { RenderingUtility.ReplaceMaterials(item.Key, item.Value); } } highlightedObjects.Clear(); if (excludedObj != null && origMaterialMap != null) { highlightedObjects.Add(excludedObj, origMaterialMap); } } }