Esempio n. 1
0
    public static void OnPostprocessScene()
    {
        if (EditorApplication.isPlayingOrWillChangePlaymode || !pb_Preferences_Internal.GetBool(pb_Constant.pbStripProBuilderOnBuild))
        {
            return;
        }

        foreach (pb_Object pb in GameObject.FindObjectsOfType(typeof(pb_Object)))
        {
            /**
             * Hide nodraw faces if present.  Don't call 'ToMesh' on objects that are statically batched since
             * batching runs pre-PostProcessScene and will break the combined mesh.
             */
            if (pb.containsNodraw && !pb.GetComponent <MeshRenderer>().isPartOfStaticBatch)
            {
                pb.ToMesh(true);
                pb.Refresh();
            }

            GameObject go = pb.gameObject;

            pb_Entity entity = pb.gameObject.GetComponent <pb_Entity>();

            if (entity.entityType == EntityType.Collider || entity.entityType == EntityType.Trigger)
            {
                go.GetComponent <MeshRenderer>().enabled = false;
            }

            GameObject.DestroyImmediate(pb);
            GameObject.DestroyImmediate(go.GetComponent <pb_Entity>());
        }
    }
Esempio n. 2
0
    public static Transform RaycastFaceCheck(Vector3 origin, Vector3 dir, float dist, Transform targetTransform)
    {
        RaycastHit hit;

        if (Physics.Raycast(origin, dir, out hit, dist))
        {
            // We've hit something.  Now check to see if it is a ProBuilder object,
            // and if so, make sure it's a visblocking brush.

            // if targetTransform isn't null, make sure that the hit object matches
            if (targetTransform != null)
            {
                if (hit.transform != targetTransform)
                {
                    return(null);
                }
            }

            pb_Entity ent = hit.transform.GetComponent <pb_Entity>();
            if (ent != null)
            {
                if (ent.entityType == ProBuilder.EntityType.Detail || ent.entityType == ProBuilder.EntityType.Occluder)
                {
                    return(hit.transform);                              // it's a brush, blocks vision, return true
                }
                else
                {
                    return(null);                               // not a vis blocking brush
                }
            }
        }

        // It ain't a ProBuilder object of the entity type Brush or Occluder (world brush)
        return(null);
    }
Esempio n. 3
0
		public void OnEnable()
		{
			ent = (pb_Entity)target;

			if(ent != null)
				pb = (pb_Object)ent.transform.GetComponent<pb_Object>();
			// if(ent.colliderType != pb_Entity.ColliderType.Upgraded) ent.GenerateCollisions();
		}
Esempio n. 4
0
        public void OnEnable()
        {
            ent = (pb_Entity)target;

            if (ent != null)
            {
                pb = (pb_Object)ent.transform.GetComponent <pb_Object>();
            }
            // if(ent.colliderType != pb_Entity.ColliderType.Upgraded) ent.GenerateCollisions();
        }
    static MonoScript _mono_pe;                                   ///< MonoScript assets

    /**
     * Load the pb_Object and pb_Entity classes to MonoScript assets.  Saves us from having to fall back on Reflection.
     */
    static void LoadMonoScript()
    {
        GameObject go = new GameObject();

        pb_Object pb = go.AddComponent <pb_Object>();
        pb_Entity pe = go.AddComponent <pb_Entity>();

        _mono_pb = MonoScript.FromMonoBehaviour(pb);
        _mono_pe = MonoScript.FromMonoBehaviour(pe);

        DestroyImmediate(go);
    }
Esempio n. 6
0
        static void Init()
        {
            pb_Object[] all = Resources.FindObjectsOfTypeAll <pb_Object>();

            Material ColliderMat = pb_Constant.ColliderMaterial;
            Material TriggerMat  = pb_Constant.TriggerMaterial;

            if (ColliderMat == null)
            {
                Debug.LogError("ProBuilder cannot find Collider material!  Make sure the Collider material asset is in \"Assets/ProCore/ProBuilder/Resources/Material\" folder.");
            }

            if (TriggerMat == null)
            {
                Debug.LogError("ProBuilder cannot find Trigger material!  Make sure the Trigger material asset is in \"Assets/ProCore/ProBuilder/Resources/Material\" folder.");
            }

            foreach (pb_Object pb in all)
            {
                pb_Entity ent = pb.gameObject.GetComponent <pb_Entity>();

                if (ent == null)
                {
                    ent = pb.gameObject.AddComponent <pb_Entity>();

                    MeshRenderer mr = pb.gameObject.GetComponent <MeshRenderer>();

                    if (mr != null)
                    {
                        Material mat = mr.sharedMaterial;

                        if (ColliderMat != null && mat == ColliderMat)
                        {
                            pb_Menu_Commands.MenuSetEntityType(new pb_Object[1] {
                                pb
                            }, EntityType.Collider);
                        }
                        else if (TriggerMat != null && mat == TriggerMat)
                        {
                            pb_Menu_Commands.MenuSetEntityType(new pb_Object[1] {
                                pb
                            }, EntityType.Trigger);
                        }
                    }
                }
            }
        }
        static MonoScript _mono_dummy;                                ///< MonoScript assets

        /**
         * Load the pb_Object and pb_Entity classes to MonoScript assets.  Saves us from having to fall back on Reflection.
         */
        static void LoadMonoScript()
        {
            GameObject go = new GameObject();

            pb_Object pb = go.AddComponent <pb_Object>();
            pb_Entity pe = go.GetComponent <pb_Entity>();

            if (pe == null)
            {
                pe = go.AddComponent <pb_Entity>();
            }
            pb_DummyScript du = go.AddComponent <pb_DummyScript>();

            _mono_pb    = MonoScript.FromMonoBehaviour(pb);
            _mono_pe    = MonoScript.FromMonoBehaviour(pe);
            _mono_dummy = MonoScript.FromMonoBehaviour(du);

            DestroyImmediate(go);
        }
Esempio n. 8
0
    public static void SetEntityType(EntityType newEntityType, GameObject target)
    {
        pb_Entity ent = target.GetComponent <pb_Entity>();

        if (ent == null)
        {
            ent = target.AddComponent <pb_Entity>();
        }

        pb_Object pb = target.GetComponent <pb_Object>();

        if (!ent || !pb)
        {
            return;
        }

        SetDefaultEditorFlags(target);

        switch (newEntityType)
        {
        case EntityType.Detail:
            SetBrush(target);
            break;

        case EntityType.Occluder:
            SetOccluder(target);
            break;

        case EntityType.Trigger:
            SetTrigger(target);
            break;

        case EntityType.Collider:
            SetCollider(target);
            break;

        case EntityType.Mover:
            SetDynamic(target);
            break;
        }

        ent.SetEntity(newEntityType);
    }
        public static void FixNoDraw()
        {
            pb_Object[] all = FindObjectsOfType(typeof(pb_Object)) as pb_Object[];

            for (int i = 0; i < all.Length; i++)
            {
                EditorUtility.DisplayProgressBar(
                    "Fixing NoDraw Flags",
                    "Working over " + all[i].id + ".",
                    ((float)i / all.Length));

                StaticEditorFlags flags = GameObjectUtility.GetStaticEditorFlags(all[i].gameObject);

                // if nodraw found
                if (all[i].containsNodraw)
                {
                    if ((flags & StaticEditorFlags.BatchingStatic) == StaticEditorFlags.BatchingStatic)
                    {
                        flags ^= StaticEditorFlags.BatchingStatic;
                        GameObjectUtility.SetStaticEditorFlags(all[i].gameObject, flags);
                    }
                }
                else
                {
                    pb_Entity ent = all[i].GetComponent <pb_Entity>();

                    // if nodraw not found, and entity type should be batching static
                    if (ent == null || ent.entityType != EntityType.Mover)
                    {
                        flags = flags | StaticEditorFlags.BatchingStatic;
                        GameObjectUtility.SetStaticEditorFlags(all[i].gameObject, flags);
                    }
                }
            }

            EditorUtility.ClearProgressBar();
            if (all.Length > 0)
            {
                EditorUtility.DisplayDialog("Fix GameObject Flags", "Successfully repaired StaticEditorFlags.", "Okay");
            }
        }
Esempio n. 10
0
        private static bool GetMeshForComponent(ModelExporter exporter, pb_Object component, FbxNode fbxNode)
        {
            Mesh mesh = new Mesh();

            Material[] materials = null;
            pb_MeshCompiler.Compile(component, ref mesh, out materials, m_FbxOptions.quads ? MeshTopology.Quads : MeshTopology.Triangles);
            exporter.ExportMesh(mesh, fbxNode, materials);
            UnityEngine.Object.DestroyImmediate(mesh);

            // since probuilder can't handle mesh assets that may be externally reloaded, just strip pb
            // stuff for now.
            pb_Entity entity = component.GetComponent <pb_Entity>();

            component.dontDestroyMeshOnDelete = true;
            UnityEngine.Object.DestroyImmediate(component);
            if (entity != null)
            {
                UnityEngine.Object.DestroyImmediate(entity);
            }

            return(true);
        }
 public pb_SerializableEntity(pb_Entity entity)
 {
     entityType = (int)entity.entityType;
 }
        public static void OnPostprocessScene()
        {
            Material invisibleFaceMaterial = (Material)Resources.Load("Materials/InvisibleFace");

            /**
             * Hide nodraw faces if present.
             */
            foreach (pb_Object pb in GameObject.FindObjectsOfType(typeof(pb_Object)))
            {
                if (pb.GetComponent <MeshRenderer>() == null)
                {
                    continue;
                }

                if (pb.GetComponent <MeshRenderer>().sharedMaterials.Any(x => x != null && x.name.Contains("NoDraw")))
                {
                    Material[] mats = pb.GetComponent <MeshRenderer>().sharedMaterials;

                    for (int i = 0; i < mats.Length; i++)
                    {
                        if (mats[i].name.Contains("NoDraw"))
                        {
                            mats[i] = invisibleFaceMaterial;
                        }
                    }

                    pb.GetComponent <MeshRenderer>().sharedMaterials = mats;
                }
            }

            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                return;
            }

            foreach (pb_Object pb in GameObject.FindObjectsOfType(typeof(pb_Object)))
            {
                GameObject go = pb.gameObject;

                pb_Entity entity = pb.gameObject.GetComponent <pb_Entity>();

                if (entity == null)
                {
                    continue;
                }

                if (entity.entityType == EntityType.Collider || entity.entityType == EntityType.Trigger)
                {
                    go.GetComponent <MeshRenderer>().enabled = false;
                }

                // clear hideflags on prefab meshes
                if (pb.msh != null)
                {
                    pb.msh.hideFlags = HideFlags.None;
                }

                if (!pb_Preferences_Internal.GetBool(pb_Constant.pbStripProBuilderOnBuild))
                {
                    return;
                }

                pb.dontDestroyMeshOnDelete = true;

                GameObject.DestroyImmediate(pb);
                GameObject.DestroyImmediate(go.GetComponent <pb_Entity>());
            }
        }
Esempio n. 13
0
 public void OnEnable()
 {
     ent = (pb_Entity)target;
     // if(ent.colliderType != pb_Entity.ColliderType.Upgraded) ent.GenerateCollisions();
 }
Esempio n. 14
0
 /**
  *	\brief Sets the EntityType for the passed gameObject.
  *	@param newEntityType The type to set.
  *	@param target The gameObject to apply the EntityType to.  Must contains pb_Object and pb_Entity components.  Method does contain null checks.
  */
 public static void SetEntityType(this pb_Entity pb, EntityType newEntityType)
 {
     SetEntityType(newEntityType, pb.gameObject);
 }
	public void OnEnable()
	{
		ent = (pb_Entity)target;
		// if(ent.colliderType != pb_Entity.ColliderType.Upgraded) ent.GenerateCollisions();
	}