public MBEvent(MBEventType type, MBObject source, object context, object data) { Type = type; Source = source; Context = context; Data = data; }
public static MBObject PasteObject() { MBEditor.SnapshotScene("Paste Object"); MBObject obj=ClipboardObject; MBEmitter em = (obj is MBEmitter) ? (MBEmitter)obj : null; MBLayer emLayer = null; if (em) { // Handle Layers: // if Particlesystem changes, look for a layer with matching material // if found, let the emitter use this one. // otherwise, ask to create a new layer using the same material emLayer = em.Layer; if (em.ParticleSystem != MBEditor.SelectedParticleSystem && em.Layer) { Material layerMat=em.Layer.Material; emLayer=MBEditor.SelectedParticleSystem.FindLayer(layerMat); if (!emLayer) { if (EditorUtility.DisplayDialog("Assign Layer", "The material that this emitter's layer is using, isn't used by this particle system. Do you want to create a layer with that material?", "Yes", "No")) emLayer = MBEditor.SelectedParticleSystem.AddLayer(layerMat); } } } if (ClipboardActionPending == "cut") { if (em) em.Layer = emLayer; ClipboardObject.SetParent(MBEditor.SelectedObject); } else { // copy Vector3 localPos = ClipboardObject.transform.localPosition; obj = (MBObject)Object.Instantiate(ClipboardObject); obj.name = ClipboardObject.name; MBObject tgt = (MBEditor.SelectedObject is MBParameter) ? MBEditor.SelectedObject.Parent : MBEditor.SelectedObject; if (em) ((MBEmitter)obj).Layer = emLayer; obj.SetParent(tgt); obj.transform.localPosition = localPos; } SyncHierarchy(); ClipboardObject = null; ClipboardActionPending = ""; return obj; }
public static void CutObject() { ClipboardObject = MBEditor.SelectedObject; ClipboardActionPending = "cut"; }
/// <summary> /// Creates a clone of an existing emitter and adds it as a child of source /// </summary> /// <param name="source">the emitter to be cloned</param> /// <param name="parent">the parent of the new emitter</param> /// <returns>the new emitter</returns> public MBEmitter AddEmitter(MBEmitter source, MBObject parent) { MBEmitter em = null; if (source && parent.Matches(typeof(MBParticleSystem),typeof(MBAnchor),typeof(MBEmitter))) { if (parent is MBEmitter && ((MBEmitter)parent).IsTrail) return null; em = (MBEmitter)Object.Instantiate(source); // initialize em hierarchy em.SetParent(parent); em.mbReloadHierarchy(); em.Transform.position = parent.Transform.position; } return em; }
/// <summary> /// Creates a new empty emitter as a child of parent /// </summary> /// <param name="parent">the parent of the new emitter</param> /// <returns>the new emitter</returns> public MBEmitter AddEmitter(MBObject parent) { if (!parent.Matches(typeof(MBParticleSystem), typeof(MBAnchor), typeof(MBEmitter))) return null; if (parent is MBEmitter && ((MBEmitter)parent).IsTrail) return null; GameObject go = new GameObject("New Emitter"); MBEmitter em = go.AddComponent<MBEmitter>(); // initialize em hierarchy em.SetParent(parent); em.mbReloadHierarchy(); em.Transform.position = parent.Transform.position; em.Layer = ParticleSystem.Layer[0]; return em; }
/// <summary> /// Creates a clone of an existing anchor and adds it as a child of source /// </summary> /// <param name="source">the anchor to be cloned</param> /// <param name="parent">the new parent of the clone</param> /// <returns>the new anchor</returns> public MBAnchor AddAnchor(MBAnchor source, MBObject parent) { if (!parent.Matches(typeof(MBParticleSystem), typeof(MBEmitter), typeof(MBAnchor))) return null; if (parent is MBEmitter && ((MBEmitter)parent).IsTrail) return null; if (source) { MBAnchor anc = (MBAnchor)Object.Instantiate(source); // initialize hierarchy anc.SetParent(parent); anc.mbReloadHierarchy(); anc.Transform.position = parent.Transform.position; return anc; } else return null; }
/// <summary> /// Creates a new empty anchor as a child of parent /// </summary> /// <param name="parent">the parent of the new anchor</param> /// <returns>the new anchor</returns> public MBAnchor AddAnchor(MBObject parent) { if (!parent.Matches(typeof(MBParticleSystem),typeof(MBEmitter),typeof(MBAnchor))) return null; if (parent is MBEmitter && ((MBEmitter)parent).IsTrail) return null; GameObject go = new GameObject("Anchor"); MBAnchor anc = go.AddComponent<MBAnchor>(); // initialize hierarchy anc.SetParent(parent); anc.mbReloadHierarchy(); anc.Transform.position = parent.Transform.position; return anc; }
public override void SetParent(MBObject parent) { base.SetParent(parent); UpdateMaterial(); }
void FetchTree(MBObject obj, int indent) { // skip Parameters and EmitterTypes! if (obj.Matches(typeof(MBParameter),typeof(MBEmitterType))) return; // Add self mObjects.Add(obj); mIndent.Add(indent); // store Emitters in a additional list for easier access if (obj is MBEmitter) mEmitters.Add((MBEmitter)obj); // Get list of smart childs List<MBObject> childs = MBUtility.GetChildren<MBObject>(obj.transform, true, true); // Sort them in a nice order childs.Sort(); // Recursive call children foreach (MBObject sub in childs) FetchTree(sub, indent + 1); }
/// <summary> /// Sets a new parent for this object /// </summary> public virtual void SetParent(MBObject parent) { // Valid target? if ((parent is MBParameter) || (this is MBParameter && !(parent is MBEmitter))) { Debug.LogError(string.Format("Magical Box: '{0}' ({1}) can't be a child of '{2}' ({3}) !", name, GetType(), parent.name, parent.GetType())); return; } mTransform = null; if (mParent) mParent.Children.Remove(this); mParent = parent; if (parent) { transform.parent = parent.Transform; mParent.Children.Add(this); mParticleSystem = parent.ParticleSystem; } }
/*! @name Internal Public * Don't use them unless you know what you're doing */ //@{ /// <summary> /// Force this object and all child objects to refetch parent and reload/recache their stuff /// </summary> /// <remarks>This is used to update the cached hierarchy after changes were made</remarks> public virtual void mbReloadHierarchy() { mParticleSystem = null; mParent = null; mChildren = null; // cache/refetch now if (ParticleSystem) { } if (Parent) { } // Reload children foreach (MBObject obj in Children) obj.mbReloadHierarchy(); }