static KeyValuePair<GUIContent, System.Action>[] GetButtonsData(PEPrefabScript prefabInstance, SerializedProperty prefabProperty, SerializedProperty instanceProperty)
		{
			var buttons = new KeyValuePair<GUIContent, System.Action>[] {
				new KeyValuePair<GUIContent, System.Action>(new GUIContent("Revert", "Revert property to prefab value"), () => 
				{
					if (prefabProperty == null)
						return;
					if (instanceProperty.propertyType == SerializedPropertyType.ObjectReference)
					{
						var link = prefabInstance.GetDiffWith().Links[prefabProperty.objectReferenceValue];
						if (link == null)
							instanceProperty.SetPropertyValue(prefabProperty.GetPropertyValue());
						else
						{
							var instanceLink = prefabInstance.Links[link];
							if (instanceLink != null)
								instanceProperty.SetPropertyValue(prefabInstance.Links[link].InstanceTarget);
							else
							{
								if (PEPrefs.DebugLevel > 0)
									Debug.Log("Link null");
								instanceProperty.SetPropertyValue(prefabProperty.GetPropertyValue());
							}
						}
					}
					else
					{
						instanceProperty.SetPropertyValue(prefabProperty.GetPropertyValue());
					}
					instanceProperty.serializedObject.ApplyModifiedProperties();
				}),
				new KeyValuePair<GUIContent, System.Action>(new GUIContent("Update", "Update changes"), () => EditorApplication.delayCall += prefabInstance.BuildModifications),
			};
			return buttons;
		}
        static internal void BuildModifications(this PEPrefabScript _this)
        {
            var type = PrefabUtility.GetPrefabType(_this.gameObject);

            if (type != PrefabType.ModelPrefab)
            {
                var diff = _this.GetDiffWith();
                if (diff == null)
                {
                    Debug.LogError(_this.name + " : " + "Diff Object is not exists");
                    return;
                }

                _this.Modifications.CalculateModifications(_this.GetDiffWith(), _this);
            }

            _this.InvokeOnBuildModifications();
        }
        static internal void GetProperties(this PEModifications.PropertyData _this, out SerializedProperty prefabProperty, out SerializedProperty objectProperty, PEPrefabScript script)
        {
            var couple = _this.UserData as PropertyCouple;

            if (couple == null)
            {
                couple = new PropertyCouple();
                if (couple.objectProperty == null)
                {
                    var so = new SerializedObject(_this.Object);

                    if (so != null)
                    {
                        couple.objectProperty = so.FindProperty(_this.PropertyPath);
                    }

                    if (couple.objectProperty == null)
                    {
                        if (PEPrefs.DebugLevel > 0)
                        {
                            Debug.Log(string.Format("Property {0} not found on Object {1}", _this.PropertyPath, _this.Object));
                        }
                    }
                }

                if (couple.prefabProperty == null)
                {
                    var prefabObject = script.Links.GetPrefabObject(script.GetDiffWith().gameObject, _this.Object);

                    if (prefabObject != null)
                    {
                        var so = new SerializedObject(prefabObject);
                        if (so != null)
                        {
                            couple.prefabProperty = so.FindProperty(_this.PropertyPath);
                        }
                    }
                    else
                    {
                        Debug.LogWarning("Prefab object for prefab property modifications is not found");
                    }
                }
            }

            prefabProperty = couple.prefabProperty;
            objectProperty = couple.objectProperty;
            _this.UserData = couple;
        }
        static KeyValuePair <GUIContent, System.Action>[] GetButtonsData(PEPrefabScript prefabInstance, SerializedProperty prefabProperty, SerializedProperty instanceProperty)
        {
            var buttons = new KeyValuePair <GUIContent, System.Action>[] {
                new KeyValuePair <GUIContent, System.Action>(new GUIContent("Revert", "Revert property to prefab value"), () =>
                {
                    if (prefabProperty == null)
                    {
                        return;
                    }
                    if (instanceProperty.propertyType == SerializedPropertyType.ObjectReference)
                    {
                        var link = prefabInstance.GetDiffWith().Links[prefabProperty.objectReferenceValue];
                        if (link == null)
                        {
                            instanceProperty.SetPropertyValue(prefabProperty.GetPropertyValue());
                        }
                        else
                        {
                            var instanceLink = prefabInstance.Links[link];
                            if (instanceLink != null)
                            {
                                instanceProperty.SetPropertyValue(prefabInstance.Links[link].InstanceTarget);
                            }
                            else
                            {
                                if (PEPrefs.DebugLevel > 0)
                                {
                                    Debug.Log("Link null");
                                }
                                instanceProperty.SetPropertyValue(prefabProperty.GetPropertyValue());
                            }
                        }
                    }
                    else
                    {
                        instanceProperty.SetPropertyValue(prefabProperty.GetPropertyValue());
                    }
                    instanceProperty.serializedObject.ApplyModifiedProperties();
                }),
                new KeyValuePair <GUIContent, System.Action>(new GUIContent("Update", "Update changes"), () => EditorApplication.delayCall += prefabInstance.BuildModifications),
            };

            return(buttons);
        }
Example #5
0
		static internal void GetProperties(this PEModifications.PropertyData _this, out SerializedProperty prefabProperty, out SerializedProperty objectProperty, PEPrefabScript script)
		{
			var couple = _this.UserData as PropertyCouple;
			if (couple == null)
			{
				couple = new PropertyCouple();
				if (couple.objectProperty == null)
				{
					var so = new SerializedObject(_this.Object);

					if (so != null)
						couple.objectProperty = so.FindProperty(_this.PropertyPath);

					if (couple.objectProperty == null)
					{
						if (PEPrefs.DebugLevel > 0)
							Debug.Log(string.Format("Property {0} not found on Object {1}", _this.PropertyPath, _this.Object));
					}
				}

				if (couple.prefabProperty == null)
				{
					var prefabObject = script.Links.GetPrefabObject(script.GetDiffWith().gameObject, _this.Object);

					if (prefabObject != null)
					{
						var so = new SerializedObject(prefabObject);
						if (so != null)
							couple.prefabProperty = so.FindProperty(_this.PropertyPath);
					}
					else
					{
						Debug.LogWarning("Prefab object for prefab property modifications is not found");
					}
				}
			}

			prefabProperty = couple.prefabProperty;
			objectProperty = couple.objectProperty;
			_this.UserData = couple;
		}
Example #6
0
	static IEnumerable<Object> GetRemovedObjects(Object go, PEPrefabScript prefabInstance)
	{
		foreach (var liif in prefabInstance.Modifications.RemovedObjects)
		{
			var instanceObj = prefabInstance.GetDiffWith().Links[liif];
			if (instanceObj == null)
				continue;

			var removedGO = instanceObj.InstanceTarget as GameObject;
			var removedComponent = instanceObj.InstanceTarget as Component;

			if (removedComponent is PEPrefabScript)
				continue;

			var remoteParent = (removedGO != null) ? (removedGO.transform.parent == null ? removedGO.transform.gameObject : removedGO.transform.parent.gameObject) : (removedComponent != null ? removedComponent.gameObject : null);

			var localLink = prefabInstance.Links[prefabInstance.GetDiffWith().Links[remoteParent]];
			if (localLink == null)
				continue;

			var localParent = localLink.InstanceTarget;

			if (localParent == go)
				yield return instanceObj.InstanceTarget;
		}
	}