예제 #1
0
        private static void OnPrefabStageOpened(PrefabStage stage)
        {
            Preview p = stage.prefabContentsRoot.GetComponentInChildren <Preview>();

            if (p)
            {
                p.GenerateIcon();

                Debug.Log("Creating preview for weapon " + stage.prefabContentsRoot.name);

                AddressableAssetSettings settings = AddressableAssetSettingsDefaultObject.Settings;

                if (settings != null)
                {
                    string prefabGuid = AssetDatabase.AssetPathToGUID(stage.prefabAssetPath);
                    AddressableAssetEntry prefabEntry = settings.FindAssetEntry(prefabGuid);

                    if (prefabEntry == null)
                    {
                        Debug.LogError("Prefab entry not found for prefab " + stage.prefabAssetPath);
                        return;
                    }
                }
            }
            else
            {
                Debug.LogError("Preview component not found on weapon " + stage.prefabContentsRoot.name + ". Please make sure your prefab contains a Preview Script on a children GameObject.");
            }

            stage.ClearDirtiness();
            PrefabStage.prefabStageOpened -= OnPrefabStageOpened;
        }
예제 #2
0
        public override void OnInspectorGUI()
        {
            Preview preview = (Preview)target;

            EditorGUILayout.HelpBox("The dark blue arrow points towards the viewer.", MessageType.Info);

            if (GUILayout.Button("Align with camera"))
            {
                SceneView.RepaintAll();

                SceneView.lastActiveSceneView.camera.transform.position -= 2 * preview.transform.position;

                preview.transform.LookAt(-SceneView.lastActiveSceneView.camera.transform.position);
                SceneView.lastActiveSceneView.camera.transform.position += 2 * preview.transform.position;
            }
        }
예제 #3
0
        protected virtual void OnValidate()
        {
            if (!this.gameObject.activeInHierarchy)
            {
                return;
            }
            holderPoint = this.transform.Find("HolderPoint");
            if (!holderPoint)
            {
                holderPoint = new GameObject("HolderPoint").transform;
                holderPoint.SetParent(this.transform, false);
            }
            parryPoint = this.transform.Find("ParryPoint");
            if (!parryPoint)
            {
                parryPoint = new GameObject("ParryPoint").transform;
                parryPoint.SetParent(this.transform, false);
            }
            preview = this.GetComponentInChildren <Preview>();
            if (!preview && this.transform.Find("Preview"))
            {
                preview = this.transform.Find("Preview").gameObject.AddComponent <Preview>();
            }
            if (!preview)
            {
                preview = new GameObject("Preview").AddComponent <Preview>();
                preview.transform.SetParent(this.transform, false);
            }
            Transform whoosh = this.transform.Find("Whoosh");

            if (whoosh && !whoosh.GetComponent <WhooshPoint>())
            {
                whoosh.gameObject.AddComponent <WhooshPoint>();
            }

            if (!mainHandleRight)
            {
                foreach (HandleDefinition handleDefinition in this.GetComponentsInChildren <HandleDefinition>())
                {
                    if (handleDefinition.IsAllowed(Side.Right))
                    {
                        mainHandleRight = handleDefinition;
                        break;
                    }
                }
            }
            if (!mainHandleLeft)
            {
                foreach (HandleDefinition handleDefinition in this.GetComponentsInChildren <HandleDefinition>())
                {
                    if (handleDefinition.IsAllowed(Side.Left))
                    {
                        mainHandleLeft = handleDefinition;
                        break;
                    }
                }
            }
            if (!mainHandleRight)
            {
                mainHandleRight = this.GetComponentInChildren <HandleDefinition>();
            }
            if (useCustomCenterOfMass)
            {
                this.GetComponent <Rigidbody>().centerOfMass = customCenterOfMass;
            }
            else
            {
                this.GetComponent <Rigidbody>().ResetCenterOfMass();
            }
            if (customInertiaTensor)
            {
                if (customInertiaTensorCollider == null)
                {
                    customInertiaTensorCollider = new GameObject("InertiaTensorCollider").AddComponent <CapsuleCollider>();
                    customInertiaTensorCollider.transform.SetParent(this.transform, false);
                    customInertiaTensorCollider.radius    = 0.05f;
                    customInertiaTensorCollider.direction = 2;
                }
                customInertiaTensorCollider.enabled          = false;
                customInertiaTensorCollider.isTrigger        = true;
                customInertiaTensorCollider.gameObject.layer = 2;
            }
        }