Ejemplo n.º 1
0
    /// <summary>
    /// place a loaded object
    /// </summary>
    /// <param name="parent"></param>
    /// <param name="prefab"></param>
    /// <param name="position"></param>
    /// <param name="orientation"></param>
    /// <param name="heightDetection"></param>
    /// <param name="meshName"></param>
    /// <param name="tagColliderToExclude"></param>
    /// <returns></returns>
    public GameObject CreateMeshFromObject(Transform parent, Object prefab, Vector3 position, Quaternion orientation, HEIGHT_DETECTION heightDetection, string meshName, string tagColliderToExclude = null)
    {
        if (heightDetection != HEIGHT_DETECTION.PLACE_AS_IS)
        {
            position = position + Vector3.up * 1000f;
        }

        if (!string.IsNullOrEmpty(tagColliderToExclude))
        {
            // check before
            RaycastHit hit;
            var        raHit = Physics.Raycast(position + new Vector3(0f, 100f, 0f), Vector3.down, out hit);
            if (raHit)
            {
                if (hit.transform.tag == tagColliderToExclude)
                {
                    return(null);
                }
            }
        }

        var inst = Instantiate(prefab as GameObject);

        inst.transform.position = position;
        inst.transform.rotation = orientation;
        inst.transform.SetParent(parent);
        inst.name = meshName;

        switch (heightDetection)
        {
        case HEIGHT_DETECTION.LOWER_POINT_AT_GROUND:
            LowerOnGround(inst);
            break;

        case HEIGHT_DETECTION.PIVOT_AT_GROUND:
            PivotOnGround(inst);
            break;
        }
        return(inst);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// create a mesh reading a prefab
    /// </summary>
    /// <param name="isStatic"></param>
    /// <param name="parent"></param>
    /// <param name="resourceName">resource name: if different from Default, try to use this, otherwise search Default</param>
    /// <param name="prefabName"></param>
    /// <param name="position"></param>
    /// <param name="orientation"></param>
    /// <param name="meshName"></param>
    /// <param name="tagColliderToExclude"></param>
    public GameObject CreateMeshFromPrefab(bool isStatic, Transform parent, string resourceName, string prefabName, Vector3 position, Quaternion orientation, HEIGHT_DETECTION heightDetection, string meshName, string tagColliderToExclude = null)
    {
        if (heightDetection != HEIGHT_DETECTION.PLACE_AS_IS)
        {
            position = position + Vector3.up * 100f;
        }

        if (!string.IsNullOrEmpty(tagColliderToExclude))
        {
            // check before
            if (NeedToBeExcluded(position, tagColliderToExclude))
            {
                return(null);
            }
        }

        var currentPath = $"{resourceName}/{prefabName}";
        var go_instance = Resources.Load <GameObject>(currentPath);

        if (resourceName != "Default" && go_instance == null)
        {
            currentPath = $"Default/{prefabName}";
            go_instance = Resources.Load <GameObject>(currentPath);
        }

        var inst = Instantiate(go_instance); //Resources.Load<GameObject>(currentPath));

        inst.transform.position = position;
        inst.transform.rotation = orientation;
        inst.transform.SetParent(parent);
        inst.name     = meshName == null ? prefabName : meshName;
        inst.isStatic = isStatic;

        switch (heightDetection)
        {
        case HEIGHT_DETECTION.LOWER_POINT_AT_GROUND:
            LowerOnGround(inst);
            break;

        case HEIGHT_DETECTION.PIVOT_AT_GROUND:
            PivotOnGround(inst);
            break;
        }
        return(inst);
    }
Ejemplo n.º 3
0
    public GameObject CreateMeshFromGameObject(bool isStatic, Transform parent, GameObject gameObject, Vector3 position, Quaternion orientation, HEIGHT_DETECTION heightDetection, string meshName, string tagColliderToExclude = null)
    {
        if (heightDetection != HEIGHT_DETECTION.PLACE_AS_IS)
        {
            position = position + Vector3.up * 100f;
        }

        if (!string.IsNullOrEmpty(tagColliderToExclude))
        {
            // check before
            var raHit = Physics.RaycastAll(position + new Vector3(0f, 100f, 0f), Vector3.down);
            if (raHit != null)
            {
                foreach (var hit in raHit)
                {
                    if (hit.transform.tag == tagColliderToExclude)
                    {
                        return(null);
                    }
                }
            }
        }

        var inst = Instantiate(gameObject); //Resources.Load<GameObject>(currentPath));

        inst.transform.position = position;
        inst.transform.rotation = orientation;
        inst.transform.SetParent(parent);
        inst.name     = meshName == null ? gameObject.name : meshName;
        inst.isStatic = isStatic;

        switch (heightDetection)
        {
        case HEIGHT_DETECTION.LOWER_POINT_AT_GROUND:
            LowerOnGround(inst);
            break;

        case HEIGHT_DETECTION.PIVOT_AT_GROUND:
            PivotOnGround(inst);
            break;
        }
        return(inst);
    }