예제 #1
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }

            Transform transform = internalProp.FindModelTransform(triggerTransform);

            if (transform != null)
            {
                triggerObject = transform.gameObject;
                if (triggerObject != null)
                {
                    ClickWatcher clickWatcher = triggerObject.GetComponent <ClickWatcher>();
                    if (clickWatcher == null)
                    {
                        clickWatcher = triggerObject.AddComponent <ClickWatcher>();
                    }

                    clickWatcher.AddMouseDownAction(() => OnMouseDown());
                    clickWatcher.AddMouseOverAction(() => OnMouseOver());
                    clickWatcher.AddMouseUpAction(() => OnMouseUp());
                }
            }
        }
예제 #2
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }

            foreach (IvaAction action in IvaActions)
            {
                // Events
                if (!String.IsNullOrEmpty(action.TriggerTransform))
                {
                    Transform transform = internalProp.FindModelTransform(action.TriggerTransform);
                    if (transform != null)
                    {
                        GameObject unlockTriggerObject = transform.gameObject;
                        if (unlockTriggerObject != null)
                        {
                            ClickWatcher clickWatcher = unlockTriggerObject.GetComponent <ClickWatcher>();
                            if (clickWatcher == null)
                            {
                                clickWatcher = unlockTriggerObject.AddComponent <ClickWatcher>();
                                clickWatcher.AddMouseDownAction(() => action.Toggle());
                            }
                        }
                    }
                    else
                    {
                        Debug.LogError("[FreeIVA] InteractiveIvaProp: Unable to find triggerTransform \"" + action.TriggerTransform +
                                       "\" for action \"" + action.Name + "\".");
                    }
                }

                // Animations
                Animation[] animations = internalProp.FindModelAnimators(action.AnimationName);
                if (animations == null || animations.Length == 0)
                {
                    Debug.LogError("[FreeIVA] InteractiveIvaProp: animationName " + action.AnimationName + " was not found for action \"" + action.Name + "\".");
                    return;
                }
                action.Animation = animations[0];
                AnimationState animationState = action.Animation[action.AnimationName];
                if (action.InvertState)
                {
                    action.IsActive = !action.IsActive;
                }
                if (action.ReverseAnimation)
                {
                    animationState.speed = -animationState.speed;
                }

                action.SetupAudio(internalProp.gameObject);
            }
        }
예제 #3
0
        public void Start()
        {
            if (HighLogic.LoadedSceneIsFlight == false)
            {
                return;
            }

            IvaGameObject = internalProp.gameObject;

            // Events
            if (!string.IsNullOrEmpty(unlockTriggerTransform))
            {
                Transform unlockTransform = internalProp.FindModelTransform(unlockTriggerTransform);
                if (unlockTransform != null)
                {
                    GameObject unlockTriggerObject = unlockTransform.gameObject;
                    if (unlockTriggerObject != null)
                    {
                        ClickWatcher clickWatcher = unlockTriggerObject.GetComponent <ClickWatcher>();
                        if (clickWatcher == null)
                        {
                            clickWatcher = unlockTriggerObject.AddComponent <ClickWatcher>();
                            clickWatcher.AddMouseDownAction(() => ToggleLock());
                        }
                    }
                }
                else
                {
                    Debug.LogError("[FreeIVA] PropHatchAnimated: Unable to find unlockTriggerTransform \"" + unlockTriggerTransform + "\".");
                }
            }
            if (!string.IsNullOrEmpty(openTriggerTransform))
            {
                Transform openTransform = internalProp.FindModelTransform(openTriggerTransform);
                if (openTransform != null)
                {
                    GameObject openTriggerObject = openTransform.gameObject;
                    if (openTriggerObject != null)
                    {
                        ClickWatcher clickWatcher = openTriggerObject.GetComponent <ClickWatcher>();
                        if (clickWatcher == null)
                        {
                            clickWatcher = openTriggerObject.AddComponent <ClickWatcher>();
                            clickWatcher.AddMouseDownAction(() => ToggleHatch());
                        }
                    }
                }
                else
                {
                    Debug.LogError("[FreeIVA] PropHatchAnimated: Unable to find unlockTriggerTransform \"" + openTriggerTransform + "\".");
                }
            }

            Collider[] colliders = IvaGameObject.GetComponentsInChildren <Collider>();
            foreach (Collider collider in colliders)
            {
                collider.material.bounciness = 0;
            }

            // Animations
            Animation[] unlockAnimations = internalProp.FindModelAnimators(unlockAnimationName);
            if (unlockAnimations == null || unlockAnimations.Length == 0)
            {
                Debug.LogError("[FreeIVA] PropHatchAnimated: unlockAnimationName " + unlockAnimationName + " was not found.");
                return;
            }
            unlockAnimation = unlockAnimations[0];
            AnimationState unlockAnimationState = unlockAnimation[unlockAnimationName];

            if (invertLockedState)
            {
                _isLocked = !_isLocked;
            }
            if (animationStartsUnlocked)
            {
                unlockAnimationState.speed = -unlockAnimationState.speed;
            }


            Animation[] openAnimations = internalProp.FindModelAnimators(openAnimationName);
            if (openAnimations == null || openAnimations.Length == 0)
            {
                Debug.LogError("[FreeIVA] PropHatchAnimated: openAnimationName " + openAnimationName + " was not found.");
                return;
            }
            openAnimation = openAnimations[0];
            AnimationState openAnimationState = openAnimation[openAnimationName];

            if (invertLockedState)
            {
                _isOpen = !_isOpen;
            }
            if (animationStartsOpened)
            {
                openAnimationState.speed = -openAnimationState.speed;
            }

            /*/ Depth mask disc
             *
             * TODO: Needs to be loaded from config properly.
             *
             * depthMaskObject = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
             * MonoBehaviour.Destroy(depthMaskObject.GetComponentCached<Collider>(ref depthMaskCollider));
             * if (part.internalModel == null)
             *  part.CreateInternalModel(); // TODO: Detect this in an event instead.
             * depthMaskObject.transform.parent = part.internalModel.transform;
             * depthMaskObject.layer = (int)Layers.InternalSpace;
             * depthMaskObject.transform.localScale = new Vector3(0.512f, 1, 0.512f); //depthMaskScale; TODO
             * depthMaskObject.transform.localPosition = new Vector3(0, 0, 0.643f); // depthMaskPosition; TODO
             * depthMaskObject.transform.localRotation = Quaternion.Euler(270, 0, 0); //depthMaskRotation; TODO
             * depthMaskObject.name = "Hatch Depth Mask";
             *
             * Shader depthMaskShader = Utils.GetDepthMask();
             * if (depthMaskShader != null)
             *  depthMaskObject.GetComponentCached<Renderer>(ref depthMaskRenderer).material.shader = depthMaskShader;
             * depthMaskObject.GetComponentCached<Renderer>(ref depthMaskRenderer).shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off;
             * ChangeMesh(depthMaskObject);*/

            //CreateDepthMask();
            SetupAudio();
        }