示例#1
0
    public static void SetStaticEditorFlagsRecursively(Transform current, UnityEditor.StaticEditorFlags flags, UnityEditor.StaticEditorFlags mask)
    {
        // set desired flags of current
        UnityEditor.StaticEditorFlags staticFlags = UnityEditor.GameObjectUtility.GetStaticEditorFlags(current.gameObject);
        staticFlags = (staticFlags & ~mask) | (flags & mask);
        UnityEditor.GameObjectUtility.SetStaticEditorFlags(current.gameObject, staticFlags);

        // recursively
        int numChildren = current.childCount;

        for (int i = 0; i < numChildren; ++i)
        {
            SetStaticEditorFlagsRecursively(current.GetChild(i), flags, mask);
        }
    }
示例#2
0
        public void WriteToGameObject(GameObject go, MeshRenderer mr)
        {
            mr.lightmapIndex     = lightmapIndex;
            mr.shadowCastingMode = shadowCastingMode;
            mr.receiveShadows    = receiveShadows;
            if (lightmapScale != 1)
            {
                SetLightmapScale(mr, lightmapScale);
            }

            mr.lightProbeUsage            = lightProbeUsage;
            mr.reflectionProbeUsage       = reflectionProbeUsage;
            mr.motionVectorGenerationMode = motionVectorGenerationMode;

            go.layer = layer;
#if UNITY_EDITOR
#if !UNITY_2017 && !UNITY_2018 && !UNITY_2019_1
            mr.receiveGI = receiveGI;
#endif
            staticEditorFlags &= ~UnityEditor.StaticEditorFlags.BatchingStatic;
            UnityEditor.GameObjectUtility.SetStaticEditorFlags(go, staticEditorFlags);
#endif
        }
示例#3
0
        public void ReadFromGameObject(int rootInstanceId, CombineConditionSettings combineConditions, bool copyBakedLighting, GameObject go, Transform t, MeshRenderer mr, Material mat)
        {
            matInstanceId     = (combineConditions.sameMaterial ? mat.GetInstanceID() : combineConditions.combineCondition.matInstanceId);
            lightmapIndex     = (copyBakedLighting ? mr.lightmapIndex : lightmapIndex = -1);
            shadowCastingMode = (combineConditions.sameShadowCastingMode ? mr.shadowCastingMode : combineConditions.combineCondition.shadowCastingMode);
            receiveShadows    = (combineConditions.sameReceiveShadows ? mr.receiveShadows : combineConditions.combineCondition.receiveShadows);
            lightmapScale     = (combineConditions.sameLightmapScale ? GetLightmapScale(mr) : combineConditions.combineCondition.lightmapScale);

            lightProbeUsage      = (combineConditions.sameLightProbeUsage ? mr.lightProbeUsage : combineConditions.combineCondition.lightProbeUsage);
            reflectionProbeUsage = (combineConditions.sameReflectionProbeUsage ? mr.reflectionProbeUsage : combineConditions.combineCondition.reflectionProbeUsage);
            probeAnchor          = (combineConditions.sameProbeAnchor ? mr.probeAnchor : combineConditions.combineCondition.probeAnchor);

            motionVectorGenerationMode = (combineConditions.sameMotionVectorGenerationMode ? mr.motionVectorGenerationMode : combineConditions.combineCondition.motionVectorGenerationMode);

            layer = (combineConditions.sameLayer ? go.layer : combineConditions.combineCondition.layer);
#if UNITY_EDITOR
#if !UNITY_2017 && !UNITY_2018 && !UNITY_2019_1
            receiveGI = (combineConditions.sameReceiveGI ? mr.receiveGI : combineConditions.combineCondition.receiveGI);
#endif
            staticEditorFlags = (combineConditions.sameStaticEditorFlags ? UnityEditor.GameObjectUtility.GetStaticEditorFlags(go) : combineConditions.combineCondition.staticEditorFlags);
#endif
            this.rootInstanceId = rootInstanceId;
            // Debug.Log(go.name + " " + shadowCastingMode);
        }
        void Update()
        {
            //Debug.DrawRay(transform.position, Vector3.down * 20f, Color.magenta);


            RaycastHit hit;

            // uncomment for mouse painting
            //if (Physics.Raycast(transform.position, Vector3.down, out hit))
            //if (Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition), out hit) /*&& Input.GetKeyDown(KeyCode.Space)*/)
            if (Physics.Raycast(transform.position + Vector3.up, Camera.main.transform.forward,
                                out hit) /*&& Input.GetKeyDown(KeyCode.Space)*/)
            {
#if UnityEditor
                //stored = hit.lightmapCoord;
                UnityEditor.StaticEditorFlags flags =
                    UnityEditor.GameObjectUtility.GetStaticEditorFlags(hit.transform.gameObject);

                if ((flags & UnityEditor.StaticEditorFlags.LightmapStatic) == 0)
                {
                    return;
                }

                Debug.DrawRay(transform.position + Vector3.up, (Camera.main.transform.forward * 5f), Color.magenta); // debug ray

                if (stored != hit.lightmapCoord)                                                                     // stop drawing on the same point
                {
                    Paint(hit.point, hit);
                    stored = hit.lightmapCoord;
                }

                Collider coll = hit.collider;
                return;

                /*
                 * //old code for rendertexture
                 * if (coll != null)
                 * {
                 *  if (!paintTextures.ContainsKey(coll)) // if there is already paint on the material, add to that
                 *  {
                 *      Renderer rend = hit.transform.GetComponent<Renderer>();
                 *      paintTextures.Add(coll, getWhiteRT());
                 *      rend.material.SetTexture("_PaintMap", paintTextures[coll]);
                 *
                 *
                 *  }
                 *  if (stored != hit.lightmapCoord) // stop drawing on the same point
                 *  {
                 *
                 *      ///
                 *
                 *
                 *
                 *      stored = hit.lightmapCoord;
                 *      Vector2 pixelUV = hit.lightmapCoord;
                 *      pixelUV.y *= resolution;
                 *      pixelUV.x *= resolution;
                 *
                 *      ///
                 *      //editorTexture2D.SetPixel((int)pixelUV.x, (int)pixelUV.y, Color.red);
                 *      //editorTexture2D.Apply();
                 *
                 *      //old//DrawTexture(paintTextures[coll], pixelUV.x, pixelUV.y);
                 *
                 *  }
                 * }*/
#endif
            }
        }