示例#1
0
文件: Prefab.cs 项目: undue/duality
		/// <summary>
		/// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab.
		/// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it
		/// will be used for the Prefab.
		/// </summary>
		/// <param name="obj">The object to inject as Prefab root object.</param>
		public void Inject(GameObject obj)
		{
			// Dispose old content
			if (obj == null)
			{
				if (this.objTree != null)
				{
					this.objTree.Dispose();
					this.objTree = null;
				}
			}
			// Inject new content
			else
			{
				obj.OnSaving(true);
				if (this.objTree != null)
					obj.CopyTo(this.objTree);
				else
					this.objTree = obj.Clone();
				obj.OnSaved(true);

				this.objTree.BreakPrefabLink();

				// Prevent recursion
				foreach (GameObject child in this.objTree.ChildrenDeep)
				{
					if (child.PrefabLink != null && child.PrefabLink.Prefab == this)
					{
						child.BreakPrefabLink();
					}
				}
			}
		}
示例#2
0
		/// <summary>
		/// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab.
		/// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it
		/// will be used for the Prefab.
		/// </summary>
		/// <param name="obj">The object to inject as Prefab root object.</param>
		public void Inject(GameObject obj)
		{
			if (obj == null)
			{
				if (this.objTree != null)
				{
					this.objTree.Dispose();
					this.objTree = null;
				}
			}
			else
			{
				obj.OnSaving(true);
				this.objTree = obj.Clone();
				obj.OnSaved(true);

				this.objTree.Parent = null;
				this.objTree.prefabLink = null;

				// Prevent recursion
				foreach (GameObject child in this.objTree.ChildrenDeep)
					if (child.PrefabLink != null && child.PrefabLink.Prefab == this)
						child.BreakPrefabLink();
			}
		}
示例#3
0
        /// <summary>
        /// Discards previous data and injects the specified <see cref="GameObject"/> into the Prefab.
        /// The GameObject itsself will not be affected, instead a <see cref="GameObject.Clone"/> of it
        /// will be used for the Prefab.
        /// </summary>
        /// <param name="obj">The object to inject as Prefab root object.</param>
        public void Inject(GameObject obj)
        {
            // Dispose old content
            if (obj == null)
            {
                if (this.objTree != null)
                {
                    this.objTree.Dispose();
                    this.objTree = null;
                }
            }
            // Inject new content
            else
            {
                obj.OnSaving(true);
                if (this.objTree != null)
                {
                    obj.CopyTo(this.objTree);
                }
                else
                {
                    this.objTree = obj.Clone();
                }
                obj.OnSaved(true);

                this.objTree.Parent = null;
                this.objTree.BreakPrefabLink();

                // Prevent recursion
                foreach (GameObject child in this.objTree.ChildrenDeep)
                {
                    if (child.PrefabLink != null && child.PrefabLink.Prefab == this)
                    {
                        child.BreakPrefabLink();
                    }
                }
            }
        }