public ModelPreview(EditorModel model) { previewModel = model; // Preview texture int previewSize = ModelGUI.TextureSize * 2; Preview = new RenderTexture(previewSize, previewSize, 24); Preview.hideFlags = HideFlags.HideInInspector | HideFlags.DontSave; // Preview scene previewRoot = new GameObject(model.Name + "Preview"); previewRoot.transform.position = model.BlobModel.transform.position; model.BlobModel.transform.parent = previewRoot.transform; groundPlane = CreateGroundPlane(model.ModelBounds); groundPlane.transform.position = new Vector3(0, model.ModelBounds.min.y - model.ModelBounds.size.y * 0.01f, 0); groundPlane.transform.parent = previewRoot.transform; previewRoot.SetHideFlagsRecursively(HideFlags.HideAndDontSave); RenderPreview(); }
void OnSelectionChange() { // Rotating model may refer to a deselected models, so deselect it. // Since the user is selecting a model in a different window, we should // be fine. rotatingModel = null; // Add selected objects foreach(Object o in Selection.GetFiltered(typeof(GameObject), SelectionMode.Assets)) { if (AssetDatabase.IsMainAsset(o)) { GameObject asset = o as GameObject; if (!(models.ContainsKey(asset) || ignoredSelections.Contains(asset))) { EditorModel model = new EditorModel(asset); if (model.ICanHasShadow) { ModelGUI modelGUI = new ModelGUI(model); models[asset] = modelGUI; } else { ignoredSelections.Add(asset); model.Destroy(); } } } } // Destroy deselected object - TODO Can it be done in one pass for dictionaries? List<Object> toBeDestroyed = new List<Object>(); foreach (KeyValuePair<Object, ModelGUI> p in models) if (!Selection.Contains(p.Key)) toBeDestroyed.Add(p.Key); foreach (Object o in toBeDestroyed) { models[o].Destroy(); models.Remove(o); } Repaint(); }
public ModelGUI(EditorModel model) { Model = model; previewer = new ModelPreview(model); }