Esempio n. 1
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// AddNewWayPoint
        /// # Add a new part to car
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void AddNewWayPoint(bool useHit, RaycastHit hit)
        {
            //Debug.Log ("Add new wayPoint");

            GameObject wayPointsContainer = BasicFunctions.CreateContainerIfNotExists("_DECAL_WAYPOINTS");

            GameObject newWayPoint = GameObject.CreatePrimitive(PrimitiveType.Capsule);

            newWayPoint.transform.parent     = wayPointsContainer.transform;
            newWayPoint.transform.localScale = 0.2f * Vector3.one;
            newWayPoint.GetComponent <Renderer> ().sharedMaterial       = new Material(newWayPoint.GetComponent <Renderer> ().sharedMaterial);
            newWayPoint.GetComponent <Renderer> ().sharedMaterial.color = Color.yellow;

            newWayPoint.AddComponent <WayPoint> ();
            newWayPoint.GetComponent <WayPoint> ().index = GetWayPointLogicalIndex();

            newWayPoint.name = "Waypoint_" + newWayPoint.GetComponent <WayPoint> ().index;

            if (useHit)
            {
                newWayPoint.transform.position = hit.point;
                newWayPoint.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
                newWayPoint.GetComponent <WayPoint> ().hitNormal = hit.normal;
            }

            Selection.activeObject = newWayPoint;
        }
Esempio n. 2
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// CreateNewDecal
        /// # Create a new mesh decal in the scene
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public GenericMeshDecal CreateNewMeshDecal(Material decalMaterial, Transform parent, Vector3 point, Vector3 normal, float scaleMultiplier, Vector2 rotationRange, bool attachDecalToCollisionObject)
        {
            //print ("CreateNewDecal");

            GenericMeshDecal actualDecal = Instantiate(decalPrefab.gameObject).GetComponent <GenericMeshDecal> ();

            actualDecal.material             = decalMaterial;
            actualDecal.transform.position   = point + 0.001f * normal;
            actualDecal.transform.localScale = scaleMultiplier * actualDecal.transform.localScale;
            actualDecal.transform.rotation   = Quaternion.FromToRotation(Vector3.up, normal);

            if (attachDecalToCollisionObject)
            {
                actualDecal.transform.parent = parent;
            }
            else
            {
                GameObject decalsContainer = BasicFunctions.CreateContainerIfNotExists(BasicDefines.MESH_DECAL_CONTAINER_NAME);
                actualDecal.transform.parent = decalsContainer.transform;
            }

            actualDecal.rotationRange = rotationRange;

            actualDecal.name = "RunTimeDecal";

            actualDecal.UpdateDecallShape(true, false);


            return(actualDecal.GetComponent <GenericMeshDecal> ());
        }
Esempio n. 3
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Merge
        /// # Merge mesh
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public static void  Merge(List <GameObject> gameObjectListOriginal, string mergedObjectName, bool deleteOldObjects)
        {
            List <Material> distinctMaterialList = GetMaterialListFromAGameObjectList(gameObjectListOriginal).Distinct().ToList();


            List <GameObject> finalGameObjectList = new List <GameObject> ();

            //Debug.Log ("----------------------------------------------------");

            for (int i = 0; i < distinctMaterialList.Count; i++)
            {
                //Debug.Log (i + " -> distinctMaterialList -> " + distinctMaterialList [i].name);

                List <GameObject> subGameObjectList = new List <GameObject> ();

                for (int j = 0; j < gameObjectListOriginal.Count; j++)
                {
                    Material actualGameObjectMainMaterial = BasicFunctions.GetMainMaterial(gameObjectListOriginal [j].transform);

                    if (!actualGameObjectMainMaterial)
                    {
                        //Debug.Log ("Null material: " + gameObjectListOriginal [j].name);
                    }
                    else
                    {
                        if (distinctMaterialList [i] == actualGameObjectMainMaterial)
                        {
                            //Debug.Log (j + " -> merge: " + gameObjectListOriginal [j].name);
                            subGameObjectList.Add(gameObjectListOriginal [j]);
                        }
                        else
                        {
                            //Debug.Log (j + " -> not same material: " + actualGameObjectMainMaterial.name + " and distinct: " + distinctMaterialList [i]);
                        }
                    }
                }

                finalGameObjectList.Add(SubMerge(subGameObjectList, "sub_" + mergedObjectName, deleteOldObjects, true));
            }

            SubMerge(finalGameObjectList, mergedObjectName, deleteOldObjects, false);


            // delete olds
            foreach (GameObject go in finalGameObjectList)
            {
                GameObject.DestroyImmediate(go);
            }


            if (deleteOldObjects)
            {
                foreach (GameObject go in gameObjectListOriginal)
                {
                    GameObject.DestroyImmediate(go);
                }
            }
        }
Esempio n. 4
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// Update
        /// # Update the class
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void Update()
        {
            if (timerBetweenDistributions <= 0)
            {
                GameObject baseContainer = BasicFunctions.CreateContainerIfNotExists("_MEAT_PARTS");

                timerBetweenDistributions = Random.Range(1, 2);

                int index = Random.Range(0, meatPrefabs.Count);

                GameObject clone = Instantiate(meatPrefabs [index]);

                clone.transform.position = this.transform.position;
                //clone.GetComponent<Rigidbody> ().velocity = (-4 + 4 * Random.Range (0, 1)) * Vector3.one;


                Vector3 objectScale = clone.transform.localScale;

                objectScale.x *= Random.Range(0.5f, 2);

                if (index == 0)
                {
                    objectScale.y *= Random.Range(0.5f, 2);
                    objectScale.z *= Random.Range(0.5f, 2);
                }
                else
                {
                    objectScale.y = objectScale.x;
                    objectScale.z = objectScale.x;
                }

                clone.transform.localScale = objectScale;

                clone.transform.Rotate(Random.Range(0, 360) * Vector3.one);

                clone.transform.parent = baseContainer.transform;

                if (!clone.GetComponent <NotStainableObject> ())
                {
                    clone.AddComponent <NotStainableObject> ();
                }

                actualCloneList.Add(clone);

                if (actualCloneList.Count > 24)
                {
                    GameObject removable = actualCloneList [0];

                    actualCloneList.Remove(removable);
                    Destroy(removable);
                }
            }

            timerBetweenDistributions -= Time.deltaTime;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// BuildMesh
        /// # Creates decal's mesh and applys new texture coords
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public void BuildMesh(GenericMeshDecal decal)
        {
            MeshFilter filter = decal.GetComponent <MeshFilter> ();

            if (filter == null)
            {
                filter = decal.gameObject.AddComponent <MeshFilter> ();
            }

            if (decal.GetComponent <Renderer> () == null)
            {
                decal.gameObject.AddComponent <MeshRenderer> ();
            }

            decal.GetComponent <Renderer> ().material = decal.material;

            if (decal.material == null || decal.sprite == null)
            {
                filter.mesh = null;
                return;
            }

            affectedObjects = BasicFunctions.GetAllAffectedObjects(BasicFunctions.GetTransformBounds(decal.transform), decal.affectedLayers);

            foreach (GameObject go in affectedObjects)
            {
                if (!go.GetComponent <WayPoint> () && !go.GetComponent <GenericMeshDecal> ())
                {
                    BasicFunctions.BuildDecalForObject(decal, go);
                }
            }

            BasicFunctions.Push(decal.distanceFromHit);

            Mesh mesh = null;

            if (planarDecal)
            {
                mesh = CreatePlanarMesh(1, 1);
            }
            else
            {
                mesh = BasicFunctions.CreateMesh();
////				ModifyPlanarMesh (ref mesh, 1, 1);
            }

            if (mesh != null)
            {
                mesh.name   = "GenericPoly";
                filter.mesh = mesh;
            }
        }
Esempio n. 6
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// ClipPoly
        /// # Return clip poly for actual poly
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public static GenericPoly ClipPoly(GenericPoly actualPoly, Plane plane)
        {
            //Debug.Log ("ClipPoly");

            bool[] positive      = new bool[vertexNumber];
            int    positiveCount = 0;

            for (int i = 0; i < actualPoly.vertexList.Count; i++)
            {
                positive [i] = !plane.GetSide(actualPoly.vertexList [i]);

                if (positive [i])
                {
                    positiveCount++;
                }
            }

            if (positiveCount == 0)
            {
                return(null);
            }

            if (positiveCount == actualPoly.vertexList.Count)
            {
                return(actualPoly);
            }

            GenericPoly temporalPoly = new GenericPoly();

            for (int i = 0; i < actualPoly.vertexList.Count; i++)
            {
                int next = i + 1;
                next %= actualPoly.vertexList.Count;

                if (positive [i])
                {
                    temporalPoly.vertexList.Add(actualPoly.vertexList [i]);
                }

                if (positive [i] != positive [next])
                {
                    Vector3 v1 = actualPoly.vertexList [next];
                    Vector3 v2 = actualPoly.vertexList [i];

                    Vector3 v = BasicFunctions.LineCast(plane, v1, v2);
                    temporalPoly.vertexList.Add(v);
                }
            }

            return(temporalPoly);
        }
Esempio n. 7
0
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// LateUpdate
        /// # Update the rain
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void LateUpdate()
        {
            List <Particle> particleList = GetComponent <ParticleEmitter> ().particles.ToList();

            int[] livingParticleList = new int[particleList.Count];

            int particlesToKeep = 0;

            for (var i = 0; i < GetComponent <ParticleEmitter>().particleCount; i++)
            {
                Particle actualParticle = particleList [i];

                if (actualParticle.energy > energyLimit)
                {
                    actualParticle.color = Color.yellow;

                    particleList [i] = actualParticle;

                    if (splashPrefab)
                    {
                        GameObject rainContainer = BasicFunctions.CreateContainerIfNotExists("_RAIN");

                        Transform actualSplash = Instantiate(splashPrefab, particleList [i].position, Quaternion.identity) as Transform;

                        if (actualSplash)
                        {
                            actualSplash.parent = rainContainer.transform;
                        }
                    }
                }
                else
                {
                    livingParticleList [particlesToKeep++] = i;
                }
            }

            Particle[] keepParticles = new Particle[particlesToKeep];

            for (var j = 0; j < particlesToKeep; j++)
            {
                keepParticles [j] = particleList [livingParticleList [j]];
            }

            GetComponent <ParticleEmitter> ().particles = keepParticles;
        }
Esempio n. 8
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);
        }
Esempio n. 9
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;
                    }
                }
            }
        }
Esempio n. 10
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);
        }
Esempio n. 11
0
 ///////////////////////////////////////////////////////////////////////////////////////////////////////
 /// <summary>
 /// Start
 /// # Initialise all
 /// </summary>
 ///////////////////////////////////////////////////////////////////////////////////////////////////////
 void Start()
 {
     objectsContainer = BasicFunctions.CreateContainerIfNotExists("_OBJECTS");
 }
Esempio n. 12
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);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// DeleteAllAction
        /// # Handle "delete all" action
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void DeleteAllAction()
        {
            //Debug.Log("Delete All");

            bool   deleteMeshDecals      = false;
            bool   deleteProjectedDecals = false;
            bool   deleteObjects         = false;
            bool   doItByBaseName        = false;
            string baseName = "";

            switch (systemMode)
            {
            case cSystemMode.edition:
            {
                deleteMeshDecals      = true;
                deleteProjectedDecals = true;
                deleteObjects         = true;
            }
            break;

            case cSystemMode.meshDecals:
            {
                deleteMeshDecals = true;
                doItByBaseName   = true;
                baseName         = BasicDefines.MESH_DECAL_BASE_NAME;
            }
            break;

            case cSystemMode.projectedDecals:
            {
                deleteProjectedDecals = true;
                doItByBaseName        = true;
                baseName = BasicDefines.PROJECTED_DECAL_BASE_NAME;
            }
            break;

            case cSystemMode.objects:
            {
                deleteObjects  = true;
                doItByBaseName = true;
                baseName       = BasicDefines.OBJECT_BASE_NAME;
            }
            break;
            }

            if (deleteMeshDecals)
            {
                GenericDestroyable.DestroyAll(doItByBaseName, baseName);
                BasicFunctions.DestroyGameObjectByName(baseName);
            }

            if (deleteProjectedDecals)
            {
                GenericDestroyable.DestroyAll(doItByBaseName, baseName);
                BasicFunctions.DestroyGameObjectByName(baseName);
            }

            if (deleteObjects)
            {
                GenericDestroyable.DestroyAll(doItByBaseName, baseName);
                BasicFunctions.DestroyGameObjectByName(baseName);
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// HandleProjectedDecalsMode
        /// # To insert projected decals in scene using mouse
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void HandleProjectedDecalsMode()
        {
            if ((GetEditorTimeDiff() > 0.1f) && EditorBasicFunctions.GetMouseButtonDown(0) && EditorBasicFunctions.GetInsertModeKeyPressed() && !GetDoingSomethingSpecial())
            {
                previousEditorTime = EditorApplication.timeSinceStartup;

                //Debug.Log ("Event.current.mousePosition: " + Event.current.mousePosition);

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

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

                        lastProjectedDecalsHitPoint = hit.point;

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

                        GenericProjectorDecal actualProjectedDecal = Instantiate(projectedDecalPrefab.gameObject).GetComponent <GenericProjectorDecal> () as GenericProjectorDecal;
                        actualProjectedDecal.SetOldParameters(projectedDecalPrefab.transform.localScale, projectedDecalPrefab.GetComponent <Projector> ().orthographicSize, projectedDecalPrefab.GetComponent <Projector> ().aspectRatio);

                        //Debug.Log (actualProjectedDecal.material.mainTexture.name);

                        actualProjectedDecal.transform.position = hit.point + 0.3f * hit.normal;

                        Vector3 finalScale = Random.Range(actualProjectedDecal.scaleRange.x, actualProjectedDecal.scaleRange.y) * actualProjectedDecal.transform.localScale;

                        float textureAspectRatio = (float)actualProjectedDecal.material.mainTexture.width / (float)actualProjectedDecal.material.mainTexture.height;

                        finalScale.x = textureAspectRatio * finalScale.x;

                        actualProjectedDecal.transform.localScale = finalScale;

                        actualProjectedDecal.transform.LookAt(hit.point);

                        actualProjectedDecal.transform.Rotate(new Vector3(0, 0, Random.Range(actualProjectedDecal.rotationRange.x, actualProjectedDecal.rotationRange.y)));

                        actualProjectedDecal.name = actualProjectedDecal.Generate(BasicDefines.PROJECTED_DECAL_BASE_NAME, GetSeedForInstancies(), true, actualProjectedDecal.material.name);

                        //Debug.Log ("actualProjectedDecal.attachToCollisionObject: " + actualProjectedDecal.attachToCollisionObject);

                        if (actualProjectedDecal.attachToCollisionObject)
                        {
                            //Debug.Log ("Parent name: " + hit.collider.name);
                            actualProjectedDecal.transform.parent = hit.collider.transform;
                        }
                        else
                        {
                            GameObject decalsContainer = BasicFunctions.CreateContainerIfNotExists(BasicDefines.PROJECTED_DECAL_CONTAINER_NAME);
                            actualProjectedDecal.transform.parent = decalsContainer.transform;
                        }

                        actualProjectedDecal.UpdateShape();

                        actualObjectToForceSelect = actualProjectedDecal.gameObject;
                    }
                }
            }
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// DrawObjectlList
        /// # Draw actual selectable prefab list (looking inside it's folder) and handle dev's selections
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        public static GameObject DrawPrefabList(GameObject actualGameObject, Rect position)
        {
            // save actual gui color
            Color actualGuiColor = GUI.color;
            Color bgColor        = GUI.backgroundColor;

            GameObject selectedGameObject = actualGameObject;

            EditorGUILayout.Separator();

            // get actual prefab list
            bool redoTheList = false;

            for (int i = 0; i < prefabList.Count; i++)
            {
                if (AssetDatabase.GetAssetPath(prefabList [i]).Length < 2)
                {
                    redoTheList = true;
                }
            }

            if (redoTheList)
            {
                Debug.Log("Prefab deleted, redo prefab decal list");
            }

            if ((prefabList.Count <= 0) || redoTheList)
            {
                prefabList = EditorBasicFunctions.GetPrefabList();
            }

            // calculate paths
            List <string> localTotalGameObjectPathList = new List <string> ();

            for (int i = 0; i < prefabList.Count; i++)
            {
                string totalPath  = AssetDatabase.GetAssetPath(prefabList [i]);
                string actualPath = Path.GetDirectoryName(totalPath);

                int index = 0;

                for (int j = 0; j < actualPath.Length; j++)
                {
                    if (actualPath [j] == '/')
                    {
                        index = j;
                    }
                }

                string finalPath = actualPath.Substring(index + 1, actualPath.Length - index - 1);

                localTotalGameObjectPathList.Add(finalPath);
            }

            List <string> localGameObjectPathList = localTotalGameObjectPathList.Distinct().ToList();

            if (!showSystemFolders)
            {
                localGameObjectPathList.Remove("System");
            }

            //print ("------------------------------------------");
            //for (int i = 0; i < localGameObjectPathList.Count; i++)
            //{
            //print (localGameObjectPathList [i]);
            //}

            EditorGUILayout.Separator();
            GenericObject.actualFolderIndex = EditorGUILayout.Popup(GenericObject.actualFolderIndex, localGameObjectPathList.ToArray(), new GUILayoutOption[] { GUILayout.Width(0.81f * position.width) });

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();

            if (EditorBasicFunctions.GetEditorTextButton("Refresh", "Refresh the list, just in case", position))
            {
                RefreshLists();
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Separator();

            string selectedGameObjectPath = BasicDefines.NOT_DEFINED;

            if (localGameObjectPathList.Count > 0)
            {
                selectedGameObjectPath = localGameObjectPathList [GenericObject.actualFolderIndex];
            }


            // test some things
            int        numberOfObjectsPerLine = 4;
            int        cont  = 0;
            bool       begin = false;
            bool       actualSelectedElementIsInSelectedPathList = false;
            GameObject firstElementInActualPath = null;


            // draw objects in editor window
            for (int i = 0; i < Mathf.Ceil((float)prefabList.Count); i++)
            {
                if (localTotalGameObjectPathList [i] == selectedGameObjectPath)
                {
                    if (firstElementInActualPath == null)
                    {
                        firstElementInActualPath = prefabList [i];
                    }

                    if ((selectedGameObject == prefabList [i]))
                    {
                        actualSelectedElementIsInSelectedPathList = true;
                    }

                    if (cont % numberOfObjectsPerLine == 0)
                    {
                        GUILayout.BeginHorizontal();
                        begin = true;
                    }

                    Texture previsualization = BasicFunctions.GetThumbnail(prefabList [i]);

                    Texture unityPreview = AssetPreview.GetAssetPreview(actualGameObject);

                    if (unityPreview)
                    {
                        //previsualization = unityPreview;
                    }

                    if (actualGameObject == prefabList [i])
                    {
                        GUI.color           = new Color(1, 1, 1, 1);
                        GUI.backgroundColor = new Color(0.6f, 0.0f, 0.6f, 1f);
                    }
                    else
                    {
                        GUI.color           = new Color(1, 1, 1, 1f);
                        GUI.backgroundColor = new Color(1, 1, 1, 0.3f);
                    }

                    float buttonsScale = 0.94f * position.width / (numberOfObjectsPerLine + 0.3f);

                    bool selected = GUILayout.Button(new GUIContent(previsualization, prefabList [i].name), new GUILayoutOption[] {
                        GUILayout.Width(buttonsScale),
                        GUILayout.Height(buttonsScale)
                    });


                    if (selected)
                    {
                        selectedGameObject = prefabList [i];
                    }

                    if (cont % numberOfObjectsPerLine == numberOfObjectsPerLine - 1)
                    {
                        GUILayout.EndHorizontal();
                        begin = false;
                    }

                    cont++;
                }
            }

            if (!actualSelectedElementIsInSelectedPathList)
            {
                //print ("Change to firstElementInActualPath: " + firstElementInActualPath.name);
                selectedGameObject = firstElementInActualPath;
            }

            if (begin)
            {
                EditorGUILayout.EndHorizontal();
            }

            // restore Gui Color
            GUI.color           = actualGuiColor;
            GUI.backgroundColor = bgColor;


            //return selected game object
            return(selectedGameObject);
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        /// <summary>
        /// HandleMeshDecalsMode
        /// # To insert mesh decals in scene using mouse
        /// </summary>
        ///////////////////////////////////////////////////////////////////////////////////////////////////////
        void HandleMeshDecalsMode()
        {
            if ((GetEditorTimeDiff() > 0.1f) && EditorBasicFunctions.GetMouseButtonDown(0) && EditorBasicFunctions.GetInsertModeKeyPressed() && !GetDoingSomethingSpecial())
            {
                previousEditorTime = EditorApplication.timeSinceStartup;

                //Debug.Log ("Event.current.mousePosition: " + Event.current.mousePosition);

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

                //Debug.Log ("-----------------------------------------------------------");

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

                        lastMeshDecalsHitPoint = hit.point;

                        //Debug.Log ("hit.point: " + hit.point);
                        //Debug.Log ("lastMeshDecalsHitPoint B: " + lastMeshDecalsHitPoint);

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

                        bool setPlanarDecal = EditorBasicFunctions.planarMeshDecals;

                        if (hit.collider.GetComponent <Terrain> ())
                        {
                            //Debug.Log ("It's a terrain, set the decal as planar");
                            setPlanarDecal = true;
                        }

                        meshDecalPrefab.planarDecal    = setPlanarDecal;
                        meshDecalPrefab.comeFromEditor = setPlanarDecal;

                        GenericMeshDecal actualDecal = Instantiate(meshDecalPrefab.gameObject).GetComponent <GenericMeshDecal> ();
                        actualDecal.transform.position = hit.point;

                        meshDecalPrefab.comeFromEditor = false;

                        Vector3 finalScale = Random.Range(actualDecal.scaleRange.x, actualDecal.scaleRange.y) * actualDecal.transform.localScale;

                        float textureAspectRatio = (float)actualDecal.material.mainTexture.width / (float)actualDecal.material.mainTexture.height;

                        if (actualDecal.GetPlanar())
                        {
                            finalScale.x = 0.5f * finalScale.x;
                            finalScale.y = textureAspectRatio * finalScale.x;
                        }
                        else
                        {
                            finalScale.x = textureAspectRatio * finalScale.x;
                        }

                        //finalScale.y = finalScale.x;
                        //finalScale.z = finalScale.x;


                        actualDecal.transform.localScale = finalScale;

                        actualDecal.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);

                        actualDecal.name = actualDecal.Generate(BasicDefines.MESH_DECAL_BASE_NAME, GetSeedForInstancies(), true, actualDecal.material.name);

                        actualDecal.UpdateDecallShape(true, false);

                        //Debug.Log ("actualDecal.attachToCollisionObject: " + actualDecal.attachToCollisionObject);

                        if (actualDecal.attachToCollisionObject)
                        {
                            //Debug.Log ("Parent name: " + hit.collider.name);
                            actualDecal.transform.parent = hit.collider.transform;
                        }
                        else
                        {
                            GameObject decalsContainer = BasicFunctions.CreateContainerIfNotExists(BasicDefines.MESH_DECAL_CONTAINER_NAME);
                            actualDecal.transform.parent = decalsContainer.transform;
                        }

                        if (actualDecal.addCollider)
                        {
                            actualDecal.gameObject.AddComponent <MeshCollider> ();
                            //actualDecal.gameObject.GetComponent<MeshCollider> ().convex = true;
                        }

                        actualObjectToForceSelect = actualDecal.gameObject;
                    }
                }
            }
        }