protected void ActivateSelecetedRaycastCheckers(GameObject[] selectedGameObjects)
    {
        List <CS_RaycastChecker> raycastCheckersToRemoveFromInactiveList = new List <CS_RaycastChecker>();

        // cycle selected objects and get their raycast checkers
        foreach (GameObject goRaycastChecker in selectedGameObjects)
        {
            CS_RaycastChecker selectedRC = goRaycastChecker.GetComponent <CS_RaycastChecker>();
            // if the selected object is a raycast checker, activate it
            if (selectedRC)
            {
                // activate the raycast checker
                selectedRC.ActivateRaycastChecker(true);

                raycastCheckersToRemoveFromInactiveList.Add(selectedRC);
            }
        }

        // if raycast checkers are to be moved lists
        if (raycastCheckersToRemoveFromInactiveList.Count > 0)
        {
            foreach (CS_RaycastChecker activeRaycastChecker in raycastCheckersToRemoveFromInactiveList)
            {
                // if the raycast checker is in the inactive raycast checkers list
                if (inactiveRaycastCheckers.Contains(activeRaycastChecker))
                {
                    inactiveRaycastCheckers.Remove(activeRaycastChecker);
                }
            }

            raycastCheckersToRemoveFromInactiveList.Clear();
        }
    }
    protected void AddRaycastChecker(GameObject[] selectedGameObjects)
    {
        Debug.Log("Adding Raycast Checkers to all Currently Selected GameObjects");

        // cycle through selected game objects and add raycast checkers if possible
        foreach (GameObject obj in selectedGameObjects)
        {
            // check if object already has a raycast checker
            // look through children
            CS_RaycastChecker attachedRaycastChecker = obj.GetComponentInChildren <CS_RaycastChecker>();
            // doesnt contain a raycast checker in children
            if (attachedRaycastChecker == null)
            {
                // look through parents
                attachedRaycastChecker = obj.GetComponentInParent <CS_RaycastChecker>();

                // if object contains a raycast checker, move on
                if (attachedRaycastChecker)
                {
                    Debug.Log(obj.name + " Already contains a raycast checker");
                    break;
                }
            }
            // if object contains a raycast checker, move on
            else
            {
                Debug.Log(obj.name + " Already contains a raycast checker");
                break;
            }

            // check if object meets the criteria to work with the raycast checker
            // look for a camera
            Camera attachedCamera = obj.GetComponentInChildren <Camera>();
            // no attached camera in objects children
            if (attachedCamera == null)
            {
                attachedCamera = obj.GetComponentInParent <Camera>();
                // no camera attached to any of the objects parents contains a camera
                if (attachedCamera == null)
                {
                    Debug.Log(obj.name + " doesnt contain a camera, raycast checker will not be added");
                    break;
                }
            }

            // add raycast checker to the raycast checker
            CS_RaycastChecker newRC = obj.AddComponent <CS_RaycastChecker>();
            //newRC.SetupRaycastChecker()

            // add raycast checker to the list of raycast checkers
            raycastCheckers.Add(newRC);

            // if the application is running
            if (EditorApplicationRunning)
            {
                // link and setup the raycast checker
                viewToolManager.LinkAndSetupRaycastChecker(newRC);
            }
        }
    }
    protected void ActivateSelecetedRaycastCheckersNEW(GameObject[] selectedGameObjects)
    {
        List <CS_RaycastChecker> raycastCheckersToRemoveFromInactiveList = new List <CS_RaycastChecker>();

        // cycle selected objects and get their raycast checkers
        foreach (GameObject goRaycastChecker in selectedGameObjects)
        {
            CS_RaycastChecker selectedRC = goRaycastChecker.GetComponent <CS_RaycastChecker>();
            // if the selected object is a raycast checker, activate it
            if (selectedRC)
            {
                // serialize the raycast checker
                SerializedObject serializedRC = new SerializedObject(selectedRC);
                // get the raycaster active property
                SerializedProperty raycasterActiveProperty = serializedRC.FindProperty("raycasterActive");

                bool prevRCActiveValue = raycasterActiveProperty.boolValue;
                raycasterActiveProperty.boolValue = true; // activate the raycast checker

                // apply the serialized object property changes
                serializedRC.ApplyModifiedProperties();

                // if the editor is running
                if (EditorApplicationRunning)
                {
                    // if value has changed
                    if (prevRCActiveValue != raycasterActiveProperty.boolValue)
                    {
                        // clear the view mesh
                        selectedRC.ClearViewMesh();
                    }
                }

                raycastCheckersToRemoveFromInactiveList.Add(selectedRC);
            }
        }

        // if raycast checkers are to be moved lists
        if (raycastCheckersToRemoveFromInactiveList.Count > 0)
        {
            foreach (CS_RaycastChecker activeRaycastChecker in raycastCheckersToRemoveFromInactiveList)
            {
                // if the raycast checker is in the inactive raycast checkers list
                if (inactiveRaycastCheckers.Contains(activeRaycastChecker))
                {
                    inactiveRaycastCheckers.Remove(activeRaycastChecker);
                }
            }

            raycastCheckersToRemoveFromInactiveList.Clear();
        }
    }
Exemplo n.º 4
0
    public void LinkAndSetupRaycastChecker(CS_RaycastChecker raycastChecker)
    {
        // check if in the list of raycast checkers
        if (!raycastCheckers.Contains(raycastChecker))
        {
            // add to raycast checkers list
            raycastCheckers.Add(raycastChecker);
        }

        // setup the raycast checker
        raycastChecker.SetupRaycastChecker(this, currentRaycastCheckerIndex);
        currentRaycastCheckerIndex++;
    }
    protected void DeactivateSelectedRaycastCheckers(GameObject[] selectedGameObjects)
    {
        // cycle selected objects and get their raycast checkers
        foreach (GameObject goRaycastChecker in selectedGameObjects)
        {
            CS_RaycastChecker selectedRC = goRaycastChecker.GetComponent <CS_RaycastChecker>();
            // if the selected object is a raycast checker, activate it
            if (selectedRC)
            {
                // deactivate the raycast checker
                selectedRC.ActivateRaycastChecker(false);

                // if the selected raycast checker is not in the inactive raycast checker list, add it
                if (!inactiveRaycastCheckers.Contains(selectedRC))
                {
                    inactiveRaycastCheckers.Add(selectedRC);
                }
            }
        }
    }
    public void SetupViewMeshGenerator(CS_ViewToolManager vtManager, CS_RaycastChecker rChecker, Color mColor)
    {
        viewToolManager         = vtManager;
        toolUserSettings        = viewToolManager.ToolUserSettings;
        connectedRaycastChecker = rChecker;

        // get the mesh filter
        meshFilter = GetComponent <MeshFilter>();
        // create a new mesh
        mesh = new Mesh();

        // set the mesh to the mesh filter
        meshFilter.mesh = mesh;

        meshRenderer = GetComponent <MeshRenderer>();
        // set mesh transparency
        transparency = meshRenderer.material.color.a;
        // set the mesh color
        meshColor   = mColor;
        meshColor.a = transparency;
        meshRenderer.material.color = meshColor;

        // send some quick mesh data to make a triangle for testing
        Vector3[] testTriangleVerts = new Vector3[]
        {
            new Vector3(0.0f, 1.0f, 0.0f),
            new Vector3(0.0f, 1.0f, 1.0f),
            new Vector3(1.0f, 1.0f, 0.0f)
        };

        int[] testTriangleTris = new int[]
        {
            0, 1, 2
        };

        UpdateMesh(testTriangleVerts, testTriangleTris);
        ClearMesh();
    }
    protected void DeactivateSelectedRaycastCheckersNEW(GameObject[] selectedGameObjects)
    {
        // cycle selected objects and get their raycast checkers
        foreach (GameObject goRaycastChecker in selectedGameObjects)
        {
            CS_RaycastChecker selectedRC = goRaycastChecker.GetComponent <CS_RaycastChecker>();
            // if the selected object is a raycast checker, activate it
            if (selectedRC)
            {
                // serialize the raycast checker
                SerializedObject serializedRC = new SerializedObject(selectedRC);
                // get the raycaster active property
                SerializedProperty raycasterActiveProperty = serializedRC.FindProperty("raycasterActive");
                bool prevRCActiveValue = raycasterActiveProperty.boolValue;
                raycasterActiveProperty.boolValue = false;

                // if the selected raycast checker is not in the inactive raycast checker list, add it
                if (!inactiveRaycastCheckers.Contains(selectedRC))
                {
                    inactiveRaycastCheckers.Add(selectedRC);
                }

                // apply the serialized object property changes
                serializedRC.ApplyModifiedProperties();

                // if the editor is running
                if (EditorApplicationRunning)
                {
                    // if value has changed
                    if (prevRCActiveValue != raycasterActiveProperty.boolValue)
                    {
                        // clear the view mesh
                        selectedRC.ClearViewMesh();
                    }
                }
            }
        }
    }