コード例 #1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// GetMaterialListFromAGameObjectList
        /// # Merge mesh
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        static List <Material> GetMaterialListFromAGameObjectList(List <GameObject> gameObjectList)
        {
            // get mesh fiters
            List <MeshFilter> meshFilters = new List <MeshFilter> ();

            for (int i = 0; i < gameObjectList.Count; i++)
            {
                meshFilters.Add(BasicFunctions.GetMeshFilterInChilds(gameObjectList [i].transform));
            }

            // get material list
            List <Material> materials = new List <Material> ();

            foreach (MeshFilter mf in meshFilters)
            {
                MeshRenderer mr = mf.gameObject.GetComponent <MeshRenderer> ();

                materials.Add(mr.gameObject.GetComponent <Renderer> ().sharedMaterial);
            }

            return(materials);
        }
コード例 #2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// HandleObjectsMode
        /// # To insert objects in scene using mouse
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void HandleObjectsMode()
        {
            if ((GetEditorTimeDiff() > 0.1f) && EditorBasicFunctions.GetMouseButtonDown(0) && EditorBasicFunctions.GetInsertModeKeyPressed() && !GetDoingSomethingSpecial())
            {
                previousEditorTime = EditorApplication.timeSinceStartup;

                Ray        ray = HandleUtility.GUIPointToWorldRay(Event.current.mousePosition);
                RaycastHit hit;

                if (Physics.Raycast(ray, out hit))
                {
                    if (lastPrefabHitPoint.ToString() == hit.point.ToString())
                    {
                        //Debug.Log ("NOTE: same point duplicate -> lastPrefabHitPoint: " + lastPrefabHitPoint);
                    }
                    else
                    {
                        //Debug.Log ("lastPrefabHitPoint A: " + lastPrefabHitPoint);

                        lastPrefabHitPoint = hit.point;

                        //Debug.Log ("New Object");
                        //Debug.Log ("Hit position: " + hit.point);
                        //Debug.Log ("Collider Name: " + hit.collider.name);

                        GameObject actualObject = Instantiate(genericObject);

                        switch (pivotMode)
                        {
                        case cPivotMode.useOriginalPivot:
                        {
                            actualObject.transform.position = hit.point + extraNormalOffset * hit.normal;
                        }
                        break;

                        case cPivotMode.autoCalculate:
                        {
                            MeshFilter actualMeshFilter = BasicFunctions.GetMeshFilterInChilds(actualObject.transform);

                            if (actualMeshFilter == null)
                            {
                                actualObject.transform.position = hit.point + extraNormalOffset * hit.normal;
                            }
                            else
                            {
                                float pivotOffset = extraNormalOffset + 0.5f * (Mathf.Abs(actualMeshFilter.sharedMesh.bounds.max.y) + Mathf.Abs(actualMeshFilter.sharedMesh.bounds.min.y));

                                //Debug.Log ("pivotOffset: " + pivotOffset);
                                //Debug.Log ("max: " + actualMeshFilter.sharedMesh.bounds.max);
                                //Debug.Log ("min: " + actualMeshFilter.sharedMesh.bounds.min);
                                //Debug.Log ("Center: " + actualMeshFilter.sharedMesh.bounds.center);

                                actualObject.transform.position = hit.point + pivotOffset * hit.normal;
                            }
                        }
                        break;
                        }

                        actualObject.transform.localScale = Random.Range(objectScaleRange.x, objectScaleRange.y) * actualObject.transform.localScale;
                        actualObject.transform.rotation   = Quaternion.FromToRotation(Vector3.up, hit.normal);
                        actualObject.transform.Rotate(genericObject.transform.rotation.eulerAngles);
                        actualObject.transform.Rotate(Random.Range(objectRotationRangeX.x, objectRotationRangeX.y), Random.Range(objectRotationRangeY.x, objectRotationRangeY.y), Random.Range(objectRotationRangeZ.x, objectRotationRangeZ.y));

                        if (attachObjectToCollisionObject)
                        {
                            actualObject.transform.parent = hit.collider.transform;
                        }
                        else
                        {
                            GameObject objectsContainer = BasicFunctions.CreateContainerIfNotExists(BasicDefines.OBJECT_CONTAINER_NAME);
                            actualObject.transform.parent = objectsContainer.transform;
                        }

                        actualObject.AddComponent <GenericObject> ();

                        actualObject.name = actualObject.GetComponent <GenericObject> ().Generate(BasicDefines.OBJECT_BASE_NAME, GetSeedForInstancies(), true, genericObject.name);

                        actualObjectToForceSelect = actualObject.gameObject;
                    }
                }
            }
        }
コード例 #3
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// GetThumbnail
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public static Texture GetThumbnail(GameObject obj)
        {
            string actualTextureName = obj.name + "_" + "thumbnailforeditorwindow";

            // fist, look in the list
            for (int i = 0; i < thumbTextureList.Count; i++)
            {
                if (thumbTextureList[i] && (thumbTextureList[i].name == actualTextureName))
                {
                    //Debug.Log ("Is in the list, actualTextureName: " + actualTextureName);
                    return(thumbTextureList[i]);
                }
            }

            // if it is not in the list
            GameObject container = new GameObject();

            GameObject clone = GameObject.Instantiate(obj);

            clone.transform.position = 99999 * Vector3.one;

            Vector3 lookAtTarget = clone.transform.position;

            float offset = 0.3f * obj.transform.localScale.magnitude;

            MeshFilter actualMeshFilter = BasicFunctions.GetMeshFilterInChilds(clone.transform);

            if ((actualMeshFilter != null) && (actualMeshFilter.sharedMesh != null))
            {
                lookAtTarget = clone.transform.position + actualMeshFilter.sharedMesh.bounds.center;
                offset       = 0.75f * Vector3.Distance(actualMeshFilter.sharedMesh.bounds.max, actualMeshFilter.sharedMesh.bounds.min);
            }

            Camera actualCamera = container.gameObject.AddComponent <Camera>();

            actualCamera.farClipPlane       = offset + 10;
            actualCamera.nearClipPlane      = 0.1f;
            actualCamera.transform.position = 99999 * Vector3.one + (new Vector3(0, 0, offset));
            actualCamera.transform.LookAt(lookAtTarget);
            actualCamera.clearFlags      = CameraClearFlags.SolidColor;
            actualCamera.backgroundColor = Color.clear;

            Light actualLight = container.gameObject.AddComponent <Light>();

            actualLight.type = LightType.Directional;
            actualLight.transform.position = 99999 * Vector3.one + (new Vector3(0, 0, offset));
            actualLight.transform.LookAt(lookAtTarget);

            clone.transform.LookAt(actualCamera.transform);

            Texture actualThumb = RTImage(actualCamera);

            GameObject.DestroyImmediate(container, true);
            GameObject.DestroyImmediate(clone, true);


            if (actualThumb != null)
            {
                // put in the list
                actualThumb.name = actualTextureName;
                //Debug.Log ("Add new thumb to the list: " + actualThumb.name);
                thumbTextureList.Add(actualThumb);
            }


            return(actualThumb);
        }
コード例 #4
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Merge
        /// # Merge mesh
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        static GameObject SubMerge(List <GameObject> gameObjectList, string mergedObjectName, bool deleteOldObjects, bool colapse)
        {
            // create merged game object
            GameObject newGo = new GameObject(mergedObjectName);

            // get mesh fiters
            List <MeshFilter> meshFilters = new List <MeshFilter> ();

            for (int i = 0; i < gameObjectList.Count; i++)
            {
                meshFilters.Add(BasicFunctions.GetMeshFilterInChilds(gameObjectList [i].transform));
            }

            // get material list
            List <Material> materials = new List <Material> ();

            foreach (MeshFilter mf in meshFilters)
            {
                MeshRenderer mr = mf.gameObject.GetComponent <MeshRenderer> ();

                materials.Add(mr.gameObject.GetComponent <Renderer> ().sharedMaterial);
            }


            CombineInstance[] combine = new CombineInstance[meshFilters.Count];

            int x = 0;

            while (x < meshFilters.Count)
            {
                combine [x].mesh      = meshFilters [x].sharedMesh;
                combine [x].transform = meshFilters [x].transform.localToWorldMatrix;

                x++;
            }

            newGo.AddComponent <MeshFilter> ();
            newGo.GetComponent <MeshFilter> ().mesh            = new Mesh();
            newGo.GetComponent <MeshFilter> ().sharedMesh.name = "NewMesh";
            newGo.GetComponent <MeshFilter> ().sharedMesh.CombineMeshes(combine, colapse);


            // For MeshRenderer
            // Get / Create mesh renderer
            MeshRenderer meshRendererCombine = newGo.GetComponent <MeshRenderer> ();

            if (!meshRendererCombine)
            {
                meshRendererCombine = newGo.AddComponent <MeshRenderer> ();
            }

            // Assign materials
            meshRendererCombine.materials = materials.ToArray();


            // delete olds

            /*if (deleteOldObjects)
             * {
             *      foreach (GameObject go in gameObjectList)
             *      {
             *              GameObject.DestroyImmediate (go);
             *      }
             * }*/

            return(newGo);
        }