Пример #1
0
        public CarCRAnimationSampler(GameObject rootGameObject)
        {
            crAnimation_ = rootGameObject.GetComponent <CRAnimation>();

            CarEditorUtils.GetRenderersFromRoot(rootGameObject, out arrNormalMeshRenderer_, out arrSkinnedMeshRenderer_);
            AssignBodyIds();
        }
Пример #2
0
        public void AssignTmpAnimationController(GameObject rootGameObject)
        {
            CarEditorUtils.GetRenderersFromRoot(rootGameObject, out arrNormalMeshRenderer_, out arrSkinnedMeshRenderer_);

            crAnimation_ = rootGameObject.GetComponent <CRAnimation>();
            crAnimation_.LoadAnimation(true);
        }
Пример #3
0
        //----------------------------------------------------------------------------------
        private void SetBonesLocalScateToOneIfApproximatelyZero(SkinnedMeshRenderer smr)
        {
            Transform[] arrBone = smr.bones;
            if (arrBone != null)
            {
                foreach (Transform bone in arrBone)
                {
                    if (bone != null)
                    {
                        CarEditorUtils.SetLocalScaleToOneIfApproximatelyZero(bone);
                        listBoneTransformTmp_.Add(bone);
                    }
                }
            }

            Transform rootBone = smr.rootBone;

            if (rootBone != null)
            {
                CarEditorUtils.SetLocalScaleToOneIfApproximatelyZero(rootBone);
                listBoneTransformTmp_.Add(rootBone);
            }

            if (listBoneTransformTmp_.Count > 0)
            {
                listSkinnedGameObjectTmp_.Add(smr.gameObject);
            }
        }
Пример #4
0
        //----------------------------------------------------------------------------------
        private void SampleCaronteFX(GameObject go, out bool isVertexAnimated)
        {
            isVertexAnimated = false;
            if (!go.HasMesh())
            {
                return;
            }

            CRAnimation crAnimation = CarEditorUtils.GetFirstComponentInHierarhcy <CRAnimation>(go);

            if (crAnimation != null)
            {
                listBoneTransformTmp_.Clear();

                crAnimation.LoadAnimation(true);
                crAnimation.SetFrame(0.0f);

                isVertexAnimated = crAnimation.IsVertexAnimated(go);

                SkinnedMeshRenderer smr = go.GetComponent <SkinnedMeshRenderer>();
                if (smr != null)
                {
                    isVertexAnimated = true;
                    SetBonesLocalScateToOneIfApproximatelyZero(smr);
                }

                if (!listCRAnimation_.Contains(crAnimation))
                {
                    listCRAnimation_.Add(crAnimation);
                }
            }
        }
Пример #5
0
        public static void GetCaronteFxGameObjects(UnityEngine.Object[] arrObjectReference, out List <GameObject> listGameObject)
        {
            listGameObject = new List <GameObject>();
            int arrObjectReference_size = arrObjectReference.Length;

            for (int i = 0; i < arrObjectReference_size; i++)
            {
                GameObject go = arrObjectReference[i] as GameObject;
                if (go != null)
                {
                    if (go.IsInScene())
                    {
                        if (go.GetComponent <Caronte_Fx>() != null)
                        {
                            listGameObject.Add(go);
                        }
                        GameObject[] arrGameObject = CarEditorUtils.GetAllChildObjects(go, true);
                        foreach (GameObject childGo in arrGameObject)
                        {
                            if (childGo.GetComponent <Caronte_Fx>() != null)
                            {
                                listGameObject.Add(childGo);
                            }
                        }
                    }
                }
            }
        }
Пример #6
0
        public void SaveWeldResult()
        {
            if (!HasUnsavedWeldReferences())
            {
                EditorUtility.DisplayDialog("CaronteFX - Info", "There is not any mesh to save in assets.", "ok");
                return;
            }

            CarEditorUtils.SaveAnyUnsavedMeshInHierarchy(Data.WeldGameObject, false);
        } //Save weld result
Пример #7
0
        //SaveAssets
        private void SaveAssets()
        {
            if (!HasUnsavedTessellatorReferences())
            {
                EditorUtility.DisplayDialog("CaronteFX - Info", "There is not any mesh to save in assets.", "ok");
                return;
            }

            CarEditorUtils.SaveAnyUnsavedMeshInHierarchy(Data.NodeGO, false);
        } //Save tessellator result
Пример #8
0
        public void Weld()
        {
            GameObject[] arrGOtoWeld = FieldController.GetUnityGameObjects();

            int arrGOtoWeld_size = arrGOtoWeld.Length;

            if (arrGOtoWeld_size == 0)
            {
                EditorUtility.DisplayDialog("CaronteFX", "Input objects are mandatory", "Ok");
                return;
            }

            GameObject[] arrWeldedObject;
            Mesh[]       arrWeldedMesh;

            EditorUtility.DisplayProgressBar(Data.Name, "Welding...", 1.0f);
            CarGeometryUtils.WeldObjects(arrGOtoWeld, Data.Name, out arrWeldedObject, out arrWeldedMesh);
            EditorUtility.ClearProgressBar();

            if (CarVersionChecker.IsFreeVersion() && arrWeldedObject == null)
            {
                EditorUtility.DisplayDialog("CaronteFX - Free version", "CaronteFX Free version can only weld the meshes included in the example scenes and the unity primitives (cube, plane, sphere, etc.).", "Ok");
            }

            if (arrWeldedObject != null)
            {
                DeleteOldObjects();

                List <GameObject> listWeldedObjects = new List <GameObject>();
                listWeldedObjects.AddRange(arrWeldedObject);

                Bounds bounds = CarEditorUtils.GetGlobalBoundsWorld(listWeldedObjects);

                GameObject go = new GameObject(Data.Name + "_output");
                go.transform.position = bounds.center;

                foreach (GameObject weldedGO in listWeldedObjects)
                {
                    weldedGO.transform.parent = go.transform;
                }

                if (Data.WeldGameObject != null)
                {
                    go.transform.parent = Data.WeldGameObject.transform.parent;
                    Object.DestroyImmediate(Data.WeldGameObject);
                }

                Data.WeldGameObject = go;
                Data.ArrWeldedGO    = arrWeldedObject;
                Data.ArrWeldedMesh  = arrWeldedMesh;
                EditorUtility.SetDirty(Data);

                UnityEditor.Selection.activeGameObject = Data.WeldGameObject;
            }
        }
Пример #9
0
        public static void GetCaronteFxsRelations(Caronte_Fx caronteFx, out List <Tuple2 <Caronte_Fx, int> > listCaronteFx)
        {
            listCaronteFx = new List <Tuple2 <Caronte_Fx, int> >();
            GameObject go = caronteFx.gameObject;

            if (go.IsInScene())
            {
                GameObject[] arrChild = CarEditorUtils.GetAllGameObjectsInScene();
                AddRelations(go, arrChild, listCaronteFx);
            }
        }
Пример #10
0
        //-----------------------------------------------------------------------------------
        private bool FieldIsValidDragTarget()
        {
            UnityEngine.Object[] objects = DragAndDrop.objectReferences;

            if ((objects != null && CarEditorUtils.CheckIfAnySceneGameObjects(objects)))
            {
                return(true);
            }

            return(false);
        }
Пример #11
0
        public void Tessellate()
        {
            GameObject[] arrGOtoTessellate = FieldController.GetUnityGameObjects();

            GameObject[] arrGOTessellated;
            Mesh[]       arrMeshTessellated;

            if (arrGOtoTessellate.Length == 0)
            {
                EditorUtility.DisplayDialog("CaronteFX", "Please, first add some objects to tessellate to the field.", "Ok");
                return;
            }

            EditorUtility.DisplayProgressBar(Data.Name, "Tessellating...", 1.0f);
            CarGeometryUtils.TessellateObjects(arrGOtoTessellate, Data.MaxEdgeDistance, Data.LimitByMeshDimensions, out arrGOTessellated, out arrMeshTessellated);
            EditorUtility.ClearProgressBar();

            if (CarVersionChecker.IsFreeVersion() && arrGOTessellated == null)
            {
                EditorUtility.DisplayDialog("CaronteFX - Free version", "CaronteFX Free version can only tessellate the meshes included in the example scenes and the unity primitives (cube, plane, sphere, etc.).", "Ok");
            }

            if (arrGOTessellated != null)
            {
                DeleteOldObjects();

                List <GameObject> listGameObject = new List <GameObject>();
                listGameObject.AddRange(arrGOTessellated);

                Bounds     bounds = CarEditorUtils.GetGlobalBoundsWorld(listGameObject);
                GameObject nodeGO = new GameObject(Data.Name);

                nodeGO.transform.position = bounds.center;

                foreach (GameObject go in arrGOTessellated)
                {
                    go.transform.parent = nodeGO.transform;
                }

                if (Data.NodeGO != null)
                {
                    nodeGO.transform.parent = Data.NodeGO.transform.parent;
                    Object.DestroyImmediate(Data.NodeGO);
                }

                Data.NodeGO             = nodeGO;
                Data.ArrTessellatedGO   = arrGOTessellated;
                Data.ArrTessellatedMesh = arrMeshTessellated;

                EditorUtility.SetDirty(Data);

                Selection.activeGameObject = nodeGO;
            }
        }
Пример #12
0
        public void DrawAnimationFiles()
        {
            if (ac_.animationFileType == CRAnimation.AnimationFileType.CRAnimationAsset)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                var value = EditorGUILayout.ObjectField("Active animation", ac_.activeAnimation, typeof(CRAnimationAsset), false);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(ac_, "Change active animation");
                    ac_.activeAnimation = (CRAnimationAsset)value;
                    EditorUtility.SetDirty(ac_);
                }
                EditorGUILayout.EndHorizontal();

                CarEditorUtils.DrawInspectorList("Animation tracks", ac_.listAnimations, ac_, "Set Active", ChangeToAnimationTrack);

                EditorGUI.BeginDisabledGroup(EditorApplication.isPlayingOrWillChangePlaymode);
                if (GUILayout.Button("Convert animations to TextAssets"))
                {
                    bool ok = EditorUtility.DisplayDialog("CaronteFX - Convert animations to TextAssets", "Proceed to conversion?", "Yes", "No");
                    if (ok)
                    {
                        ConvertCRAnimationAssetsToTextAssets();
                    }
                }
                EditorGUI.EndDisabledGroup();
            }
            else if (ac_.animationFileType == CRAnimation.AnimationFileType.TextAsset)
            {
                EditorGUILayout.BeginHorizontal();
                EditorGUI.BeginChangeCheck();
                var value = EditorGUILayout.ObjectField("Active animation", ac_.activeAnimationText, typeof(TextAsset), false);
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(ac_, "Change active animation");
                    ac_.activeAnimationText = (TextAsset)value;
                    EditorUtility.SetDirty(ac_);
                }
                EditorGUILayout.EndHorizontal();

                CarEditorUtils.DrawInspectorList("Animation tracks", ac_.listAnimationsText, ac_, "Set Active", ChangeToAnimationTrack);

                if (GUILayout.Button("Convert animations to CRAnimationAssets"))
                {
                    bool ok = EditorUtility.DisplayDialog("CaronteFX - Convert animations to CRAnimationAssets", "Proceed to conversion?", "Yes", "No");
                    if (ok)
                    {
                        ConvertTextAssetsToCRAnimationAssets();
                    }
                }
            }
        }
Пример #13
0
        } // RenderGUI

        private bool HasHelperMeshReferences()
        {
            if (Data.HelperGO == null)
            {
                return(false);
            }

            if (!CarEditorUtils.IsAnyUnsavedMeshInHierarchy(Data.HelperGO))
            {
                return(false);
            }

            return(true);
        }
Пример #14
0
        } // RenderGUI

        private bool HasUnsavedTessellatorReferences()
        {
            if (Data.NodeGO == null)
            {
                return(false);
            }

            if (!CarEditorUtils.IsAnyUnsavedMeshInHierarchy(Data.NodeGO))
            {
                return(false);
            }

            return(true);
        }
Пример #15
0
        } // RenderGUI

        public bool HasUnsavedWeldReferences()
        {
            if (Data.WeldGameObject == null)
            {
                return(false);
            }

            if (CarEditorUtils.IsAnyUnsavedMeshInHierarchy(Data.WeldGameObject))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #16
0
        //----------------------------------------------------------------------------------
        private void SampleAnimationController(GameObject go)
        {
            if (!go.HasMesh())
            {
                return;
            }

            Animator animator = CarEditorUtils.GetFirstComponentInHierarhcy <Animator>(go);

            if (animator != null)
            {
                if (Data.UN_AnimationClip != null && Data.OverrideAnimationController)
                {
                    OverrideAnimatorController(animator);
                }
                animator.Update(0.0f);
            }
        }
Пример #17
0
        //-----------------------------------------------------------------------------------
        private void RegisterUnityGameObjectsInCaronte()
        {
            GameObject[] sceneObjects = CarEditorUtils.GetAllGameObjectsInScene();
            int          length       = sceneObjects.Length;

            for (int i = 0; i < length; ++i)
            {
                GameObject go = sceneObjects[i];
                CarEditorUtils.GetChildObjectsIds(go, listObjectsIds_);
                uint idCaronte;
                bool exists = goToIdCaronte_.TryGetByFirst(go, out idCaronte);
                if (!exists)
                {
                    idCaronte = GOManager.RegisterGameObject(go.name, go.GetInstanceID(), listObjectsIds_.ToArray());
                    goToIdCaronte_.Add(go, idCaronte);
                }
                else
                {
                    GOManager.ReregisterGameObject(idCaronte, go.name, go.GetInstanceID(), listObjectsIds_.ToArray());
                }
            }
        }
Пример #18
0
        public void AssignTmpAnimatorController(GameObject rootGameObject, AnimationClip animationClip, bool overrideAnimatorController)
        {
            CarEditorUtils.GetRenderersFromRoot(rootGameObject, out arrNormalMeshRenderer_, out arrSkinnedMeshRenderer_);
            animator_ = rootGameObject.GetComponent <Animator>();

            if (overrideAnimatorController)
            {
                animator_.runtimeAnimatorController = animatorSampler_;

                runtimeAnimationController_ = animator_.runtimeAnimatorController;
                ovrrAnimationController_    = new AnimatorOverrideController();

                ovrrAnimationController_.runtimeAnimatorController = runtimeAnimationController_;

                AnimationClip[] clips = ovrrAnimationController_.animationClips;
                foreach (AnimationClip animClip in clips)
                {
                    ovrrAnimationController_[animClip] = animationClip;
                }
                animator_.runtimeAnimatorController = ovrrAnimationController_;
            }
        }
Пример #19
0
    //-----------------------------------------------------------------------------------
    private void GenerateBodyBoxMeshes()
    {
      CarEditorUtils.GetListBoundsFromListGO( listBodyGOEnabledVisible_, listTmpBounds_ );
      CarBoxGenerator.GenerateBoxMeshes( listTmpBounds_, fxData_.listMeshBodyBoxesEnabledVisible_ );

      CarEditorUtils.GetListBoundsFromListGO( listBodyGODisabledVisible_, listTmpBounds_ );
      CarBoxGenerator.GenerateBoxMeshes( listTmpBounds_, fxData_.listMeshBodyBoxesDisabledVisible_ );

      if ( fxData_.DrawSleepingState )
      {
        CarEditorUtils.GetListBoundsFromListGO( listBodyGOSleeping_, listTmpBounds_ );
        CarBoxGenerator.GenerateBoxMeshes( listTmpBounds_, fxData_.listMeshBodyBoxesSleeping_ );
      }

      if ( fxData_.ShowInvisibles )
      {
        CarEditorUtils.GetListBoundsFromListGO( listBodyGOEnabledHide_, listTmpBounds_ );
        CarBoxGenerator.GenerateBoxMeshes( listTmpBounds_, fxData_.listMeshBodyBoxesEnabledHide_ );

        CarEditorUtils.GetListBoundsFromListGO( listBodyGODisabledHide_, listTmpBounds_ );
        CarBoxGenerator.GenerateBoxMeshes( listTmpBounds_, fxData_.listMeshBodyBoxesDisabledHide_ );
      }
    }
Пример #20
0
        void DoSubstitution()
        {
            Undo.RecordObject(rootObject_, "Substitute material in hierarchy");

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

            listGameObject.Add(rootObject_);
            GameObject[] arrGameObject = CarEditorUtils.GetAllChildObjectsWithGeometry(rootObject_, true);
            listGameObject.AddRange(arrGameObject);

            foreach (GameObject go in listGameObject)
            {
                Renderer rn = go.GetComponent <Renderer>();
                if (rn != null)
                {
                    Material[] arrMaterial   = rn.sharedMaterials;
                    bool       modifiedArray = false;
                    for (int i = 0; i < arrMaterial.Length; i++)
                    {
                        Material mat = arrMaterial[i];
                        if (mat == originalMaterial_)
                        {
                            modifiedArray  = true;
                            arrMaterial[i] = newMaterial_;
                        }
                    }

                    if (modifiedArray)
                    {
                        Undo.RecordObject(rn, "Change materials");
                        rn.sharedMaterials = arrMaterial;
                    }
                }
            }
            Undo.SetCurrentGroupName("Substitute material in hierarchy");
            Undo.CollapseUndoOperations(Undo.GetCurrentGroup());
        }
Пример #21
0
        //-----------------------------------------------------------------------------------
        public GameObject[] GetAnimationGameObjects <T>()
            where T : Component
        {
            List <GameObject> listGameObject = new List <GameObject>();

            List <GameObject> listBodyObjects = GetGameObjects();

            foreach (var go in listBodyObjects)
            {
                if (go.HasMesh())
                {
                    T animation = CarEditorUtils.GetFirstComponentInHierarhcy <T>(go);
                    if (animation != null)
                    {
                        GameObject animationGO = animation.gameObject;
                        if (!listGameObject.Contains(animationGO))
                        {
                            listGameObject.Add(animationGO);
                        }
                    }
                }
            }
            return(listGameObject.ToArray());
        }
Пример #22
0
 public CarAnimatorSampler(GameObject rootGameObject)
 {
     CarEditorUtils.GetRenderersFromRoot(rootGameObject, out arrNormalMeshRenderer_, out arrSkinnedMeshRenderer_);
     AssignBodyIds();
 }